Map and instancing questions

Started by
8 comments, last by MJP 11 years, 8 months ago
Hello guys,
I do have some questions on Mapping/Updating dynamic buffers.
Right now, I do have one buffer for multiple instances of an object which I am updating for each object with map() and then draw it. However, that is slowing everything down at lot and rendering the instancing useless.

Thing is, for the real instancing I would have to have one buffer for every instance, right? But having so much buffers in memory doesn't seem pretty smart either.
I could use one buffer for all instances, but I have to update the instancebuffer every frame (parts of it).
How can I do that, and how can I do it fast?

Thanks in advantage!
Advertisement
You need to use one buffer for all of your instance data, otherwise you won't be able to draw all of your instances in a single draw call (which kinda defeats the purpose). What you can do is put all of your instance data into a shared array in CPU memory, then whenever that changes you can update the entire instance data buffer with Map and DISCARD.
Thanks for your answer, a shared array is the way to go!

EDIT:
I just encountered a problem with this. The number of objects is changing! Can I use a buffer with the lenght of the maximum of objects and then just use the parts already filled?
Yes, your buffer can be larger than the number of elements that you actually use in a draw call.
I did come up with another question.
Can the instancebuffer somehow contain another buffer? I need to pass a per-Vertex-Buffer per instance too, but I can't figure out how to do this.
I don't think I understand your question...you want to have an entirely different vertex buffer for each instance? Could you explain what you're trying to do in a bit more detail?
I want to have two instancebuffers, one which applies per instance and one which applies per vertex (for each instance).
It's for my chunksystem. The mesh of every chunk is the same, but they are modified by a per vertex buffer for the height and one constantbuffer per chunk for the start X/Z coord.
I see now. Are you using D3D11? If you are, you can store your per-instance vertex data in a structured buffer. Otherwise you can store it in one or more typed buffers with the appropriate format. Then you can us SV_InstanceID and SV_VertexID in your vertex shader to fetch the appropriate vertex data, by doing index = SV_InstanceID * NumVertices + SV_VertexID.
I'm confused. I cut everything out and now I'm just drawing the x-z meshes with the instanced x-z offset per chunk. But the FPS are very very low (~10), drawing 256*256*6 * 30 indices for 30 chunks. Is it that a huge number that it is causing my application to drop that low in speed?? I am drawing it with DrawIndexedInstanced() and it's the only thing drawn. All vertices are visible and send to the GPU. How much indices per Frame are fine to send to GPU to remain good speed on a normal PC?

Structured Buffers seem to be fine for my problem.
It depends a lot on what sort of GPU you're targeting here and how much work you're doing per-vertex. According to your numbers you're rendering nearly 12m triangles per frame, which is definitely going to be too many for a lot of GPU's.

This topic is closed to new replies.

Advertisement