开发者

Cost much memory when creating several vertex and index buffer

I met a very weird issue. When I create some very simple VertexBuffer and IndexBuffer in D3D, the memory consumption reported from TaskManager is huge.

I created 60000 index buffer via D3D CreateIndexBuffer method. Each index buffer contains 6 index (int) which represents two triangles. So, one index buffer will occupy 24 bytes. And total memory 开发者_开发百科consumption would be 24*60000 = 1,440,000. But task manager shows application 300MB memory increase!

I don't know how did D3D9 do the memory allocation internally, but this issues happens also in D3D10. Is this due to memory fragmentation?

This is under x86|bebug version, and d3d is release version, windows 7.


60000 index buffers? Why not just create 1 big index buffer? Switching all those index buffers will be slow as hell in itself.

On to the reason: There will be an overhead associated with every index buffer you create (Various bit of tracking information and bits of info the driver will use to optimise it) and 5K of memory seems quite reasonable to me for that overhead. 5K * 60000 is roughly 300 megs ...


You have to consider that there's much more going on that just storing 60000 sets of 6 ints. If you're maintaining pointers to all of these, as you should, that's another 4 bytes for each pointer. This isn't even considering the fact that there are several data members present in each vertex buffer keeping track of things like buffer type, number of elements, size/type of each element, whether the buffer is dynamic, read-only, write-only, etc..

You mentioned in another comment that it is read only and managed. Being managed means Direct3D is storing plenty of additional data about each buffer so that it can be destroyed, reconstructed, and refilled when necessary such as the device resetting.

As previously mentioned, the other concern is that you have 60000 index buffers each storing 6 indices to store 2 triangles. You could use 4 indices in a triangle fan or triangle strip. Besides that, I'm not entirely certain why you need 600000 sets of them. You can, in fact, have a single index buffer and index into it, as confusing as that may sound. You can instruct Direct3D to use, say, 6 indices starting at the 6 * nth index to draw the nth pair of triangles.

I digress though, as that is not the focus of your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜