Original Post
Hey all, I'm making a Dynamic VB class for my rendering library. Heres how it works at the moment: I create a CDynamicVB of 150 vertices. The renderer internally creates a IDirect3DVertexBuffer9 of 65535 vertices, and fills in the data members of the CDynamicVB to let it know that it has 150 vertices from this VB. I create another CDynamicVB of 500 vertices. The renderer knows theres space in the IDirect3DVertexBuffer9, so it fills in the data members of the CDynamicVB to let it know that it has 500 vertices from this VB. This continues until i run out of space in the VB, at which point i alloacte a new IDirect3DVertexBuffer9 and start allocating from that. When a CDynamicVB wants to lock, it locks the next availiable chunk of the IDirect3DVertexBuffer9. The first CDynamicVB would lock from vertex 0 -> 199 if it was locked first, and the second would lock from 0 -> 499 if it was locked first. If i lock CDynamicVB 1 from 0 -> 199, then the second will lock from 200 -> 699, and so on. This all wokrs fine, until i run out of space in the IDirect3DVertexBuffer9. If VB1 locks the range 65400 -> 65500, then VB2 needs to lock the VB, what do i do? At the moment, i lock the first 500 vertices with D3DLOCK_DISCARD, but that means that the vertices filled in by VB1s lock all get destroyed. If i just lock the first 500 vertices of the VB normally (with D3DLOCK_NOOVERWRITE) (assume that i know they're unused this frame), then isn't that a bit wasteful? I heard that the nVidia driver allocates up to 8 VBs when you ask for a dynamic VB, and it uses buffer renaming to optimize the performance by giving you a new VB when you lock with DISCARD, so just locking the same buffer over and over is wasteful isn't it? What about if i lock with DISCARD if its the first lock that frame? (assume that vertices in the VB will be only valid for one frame, not 2 or 3 frames) Would that get any more performance? I know i should try these and profile, but theres quite a few variables to change and profile with, and they'd require a fair bit of code restructuring. So, does anyone know what i should do to squeeze the most performance out of this system? Thanks for any replies, Steve