Advertisement

DirectX 12 Command Lists

Started by June 13, 2024 09:01 AM
3 comments, last by KielanT 4 months, 3 weeks ago

Hi,

I'm working on a DirectX 12 Renderer, I am bit stuck and lacking understanding of command lists. To create meshes I know that you need to reset the command list, create the mesh and then close and execute the command list. Which is what I do when I initialise my renderer, but sometimes during runtime, I need to create a mesh, so I need to reset, close and execute the command list, is this the right approach or do I need a separate command list for mesh creation and then add it to the main command list? or is there a better way?

Any examples and help further understanding command lists would be really appreciated.

Thank you

None

KielanT said:
or do I need a separate command list for mesh creation and then add it to the main command list? or is there a better way?

Ideally you want to control everything the GPU should do every frame with persistent command lists, meaning they stay on GPU and don't need to be regenerated on CPU each frame.
The advantage is, contrary to higher level APIs where we many had draw calls causing a lot of CPU - GPU communication, we now only have to say ‘execute this command list which you already have in VRAM’.

But not every task has to be repeated each frame. To upload meshes or textures for example, we don't need a persistent command buffer. We need it only once, so it's fine to generate it on an the fly, executing it and then throwing it away.
The same works for rendering as well ofc., and it's not necessarily inefficient.
Engines which do this a lot, can usually benefit from multi threaded command buffer generation, for example.
While engines which do mostly GPU driven rendering won't cause a CPU load at all, beside things like streaming.

So it may depend on which of those two options you aim for.
GPU driven surely is the higher goal, but it's also harder to do, considering you'll need to implement things like frustum and occlusion culling entirely on GPU.

Advertisement

KielanT said:
I am bit stuck and lacking understanding of command lists

Command lists are just what they sound like - lists of commands. The GPU hardware consumes these commands, so it is how you direct the hardware to do things. You use this to set various bits of GPU state, tell it to execute shader code ("issue a draw call"), or copy memory between system RAM and VRAM. These things don't happen ‘immediately’. Instead, you build up a list of commands and then you submit the command list to the GPU for it to execute asynchronously.

When you say “To create meshes”, there's a number of different parts that are worth breaking down. The main part that involve command lists is copying the geometry memory from system RAM to VRAM. It's much faster for a GPU to read data out of VRAM rather than needing to issue requests over the system bus to retrieve the data from system RAM, so this is done once ahead of time, and then later when you want to draw something using that mesh you can have the GPU fetch it from where you copied it into VRAM.

Does that help clear it up a bit?

Thank you @joej and @RDragon1

None

This topic is closed to new replies.

Advertisement