Sign in to follow this  
Anand Baumunk

Map and instancing questions

Recommended Posts

Anand Baumunk    699
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!

Share this post


Link to post
Share on other sites
MJP    19754
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.

Share this post


Link to post
Share on other sites
Anand Baumunk    699
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? Edited by gnomgrol

Share this post


Link to post
Share on other sites
Anand Baumunk    699
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.

Share this post


Link to post
Share on other sites
MJP    19754
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.

Share this post


Link to post
Share on other sites
Anand Baumunk    699
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. Edited by gnomgrol

Share this post


Link to post
Share on other sites
MJP    19754
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this