Jump to content

  • Log In with Google      Sign In   
  • Create Account


Map and instancing questions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 gnomgrol   Members   -  Reputation: 559

Like
0Likes
Like

Posted 09 August 2012 - 12:54 PM

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!

Sponsor:

#2 MJP   Moderators   -  Reputation: 10209

Like
1Likes
Like

Posted 09 August 2012 - 05:18 PM

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.

#3 gnomgrol   Members   -  Reputation: 559

Like
0Likes
Like

Posted 10 August 2012 - 01:26 AM

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, 10 August 2012 - 03:53 AM.


#4 MJP   Moderators   -  Reputation: 10209

Like
0Likes
Like

Posted 10 August 2012 - 12:22 PM

Yes, your buffer can be larger than the number of elements that you actually use in a draw call.

#5 gnomgrol   Members   -  Reputation: 559

Like
0Likes
Like

Posted 11 August 2012 - 07:15 AM

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.

#6 MJP   Moderators   -  Reputation: 10209

Like
0Likes
Like

Posted 11 August 2012 - 01:02 PM

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?

#7 gnomgrol   Members   -  Reputation: 559

Like
0Likes
Like

Posted 11 August 2012 - 01:59 PM

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.

#8 MJP   Moderators   -  Reputation: 10209

Like
1Likes
Like

Posted 11 August 2012 - 07:27 PM

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.

#9 gnomgrol   Members   -  Reputation: 559

Like
0Likes
Like

Posted 12 August 2012 - 01:39 PM

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, 12 August 2012 - 01:39 PM.


#10 MJP   Moderators   -  Reputation: 10209

Like
0Likes
Like

Posted 13 August 2012 - 11:41 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS