Transcript ppt
Optimizing Geometry for Efficient Rendering Real Time Rendering Instructor: David Luebke Immediate Mode glBegin(GL_TRIANGLES); glVertex3f(…); glVertex3f(…); glVertex3f(…); glEnd(); – Easy, flexible, good match for early hardware – Slow on current hardware Bus-limited, API-limited Hard to parallelize with strict ordering semantics Immediate Mode: glVertex() How fast can you call glVertex3fv? On my laptop, 15M/sec Two conditional branches 13(+) memory accesses! Upwards of 800MB/sec to the memory system 695480A0 695480A1 695480A7 695480AE 695480B0 695480B6 695480BA 695480C1 695480C3 695480C5 695480C8 695480CB 695480CE 695480D0 695480D3 695480D8 695480DE 695480DF 695480E2 695480E8 695480EC 695480EE 695480F4 695480F7 695480FA 695480FD 69548103 69548106 69548109 6954810C 69548112 69548114 69548116 6954811C 69548121 69548122 push mov test je lea mov mov mov mov mov mov mov mov mov mov call pop ret mov mov mov mov mov add mov mov mov mov mov cmp ja xor mov call pop ret esi eax,fs:[00000BF0] byte ptr [eax+3F5Fh],10h 695480E2 edx,[eax+3640h] esi,dword ptr [esp+8] dword ptr [edx+0Ch],3F800000h ecx,dword ptr [esi] dword ptr [edx],ecx ecx,dword ptr [esi+4] esi,dword ptr [esi+8] dword ptr [edx+4],ecx ecx,eax dword ptr [edx+8],esi edx,3 dword ptr [eax+0BFA8h] esi 4 edx,dword ptr [eax+477F0h] esi,dword ptr [esp+8] ecx,dword ptr [esi] dword ptr [edx],0C2C00h dword ptr [edx+4],ecx edx,10h ecx,dword ptr [esi+4] dword ptr [eax+477F0h],edx esi,dword ptr [esi+8] dword ptr [edx-8],ecx dword ptr [edx-4],esi dword ptr [eax+477F4h],edx 69548121 edx,edx ecx,dword ptr [eax+477D0h] 6950EAE0 esi 4 Triangle Strips Ideally, approach 1 vertex/triangle – Implication: long strips better than short – Less T&L, less memory/bus bandwidth, less API function overhead Triangle fans: same idea Triangle strip subtleties – Switching direction – Degenerate triangles Display Lists Display lists were the solution – Compilation of rendering calls – Can be re-executed w/ a single call – Can include other display lists Potential savings: – Memory layout – API calls (less run-time error checking etc) – Even functional savings (e.g. folding matrices) Vertex Arrays List of vertices in an array – Separate – Interleaved – Can render from subarrays Compiled vertex arrays Indexed vertex arrays – Bandwidth – Vertex cache Vertex Cache What is the optimal way to render this mesh if you have an 8-vertex cache? Efficient Vertex Arrays Memory – System – AGP – Video VAR & VBO Locking semantics Fence semantics