Advertisement

Handling World Transformations

Started by June 29, 2018 09:02 AM
2 comments, last by Amir_r_KB 6 years, 7 months ago

Hi everyone,

I think my question boils down to "How do i feed shaders?"

 

I was wondering what are the good strategies to store mesh transformation data [World matrices] to then be used in the shader for transforming vertices (performance being the priority ).

And i'm talking about a game scenario where there are quite a lot of both moving entities, and static ones, that aren't repeated enough to be worth instanced drawing.

 

So far i've only tried these naive methods :

DX11 :   

  -  Store transforms of ALL entities in a constant buffer  ( and give the entity an index to the buffer for later modification )

  - Or  store ONE transform in a constant buffer, and change it to the entity's transform before each drawcall.

Vulkan

 -  Use Push Constants to send entity's transform to the shader before each drawcall, and maybe use a separate Device_local uniform buffer for static entities?

 

Same question applies to lights. 

Any suggestions?

 

DX11 - I would do it the first way as it minimizes the number of buffer writes from the cpu to the gpu each frame.

Have an array in the constant buffer, with one element per object

Each array element is of a struct that contains any  "per object information" such as world matrix, color, texturenumber etc

If you have a large number of objects, the object element struct would instead be elements of a structured buffer, rather than using an array inside a constant buffer.

Nvidia dx12 do's and dont's recommends the array inside the constant buffer rather than as elements of a structured buffer if you are using it from the pixel shader.

 

In an ideal world you would also draw all of them together using a single draw command, rather than one draw per object, but that depends on how you do your vertexbuffer so may not be practical.

-----

Vulcan - I dont know Vulcan.

-----

DX 12 - If you are using executeindirect there is another option -

You can store your per object information in a structured buffer in elements of size 512 bytes (or increments of that). Then you draw all your objects with a single call to executeindirect, and each draw call within it sets a rootparameter to cause a constant buffer view start position to point to the correct position of your structured buffer. This allows the gpu to see the current object being drawn as a single constant buffer.

 

Advertisement
12 hours ago, CortexDragon said:

 

Thanks for help. I thought the first way might cause problems for open world games, but structured buffers can probably do the trick.

This topic is closed to new replies.

Advertisement