Search code examples
c++directx-12

DirectX 12 - Command list questions


Trying to understand command lists. Well, command lists records my commands for rendering, but also binding resources, let's say a buffer with vertex data.

m_commandList->IASetVertexBuffers(0, 1, &m_vertexBufferView);

This records the binding of vertex buffer. What happends with the buffer at this moment ? What will happen if I change a content of this vertex buffer after recording it ? What will happen if i change the content of this vertex buffer after calling execute command list and gpu not finished it yet ?

I guess ExecuteCommandList is a asynchronous function call, am I right ? Does it execute all binding ( data transfer to gpu ) at once, or it executes commands one by one even all bindings ? Is the command list executed by a driver, or is is all sent to gpu ?

Well, becuase lack of good examples, I still have lots of questions. I would be happy, if you can answer few of them to make it clear.


Solution

  • With DirectX 12, synchronization is entirely the application's responsibility. You have to insert and check fences to make sure the GPU is done with your buffer before you modify it. For dynamic buffers, you need to do your own double/triple/n buffering.

    When you call ExecuteCommandList is just queues it up to the GPU. It will take some time before the GPU actually picks it up and then completes it.

    Be sure to check the DirectX Graphics Samples GitHub project. The samples there and the Mini Engine demo are good places to find example usage.

    This design makes DirectX 12 extremely powerful as it gives the application direct control over lots of things that were 'magic' in the Direct3D 11 Runtime. That said, the resulting API is much harder to actually use unless you are already a good enough graphics engineer that you could write the Direct3D 11 Runtime. Using Direct3D 11 API is still a fine choice for a project too.