# Juliet\src\Graphics\D3D12\D3D12CommandList ## Source Files - Header: `Juliet\src\Graphics\D3D12\D3D12CommandList.h` - Source: `Juliet\src\Graphics\D3D12\D3D12CommandList.cpp` ## AI Description The provided code snippet is a part of a graphics rendering engine, specifically designed for DirectX 12. It includes functions to manage and execute commands in a graphics pipeline. The `ExecuteCommandLists` function is responsible for submitting multiple command lists to the GPU for execution. Here's a breakdown of what this function does: ### Function Overview - **Submit Command Lists**: This function takes an array of `NonNullPtr?CommandList?` objects, each representing a command list that needs to be executed. - **Inflight Fence**: It checks if any of the command lists are currently in flight (i.e., they have been submitted but not yet completed). - **Signal Fence**: If a command list is not in flight, it signals the fence associated with that command list. This ensures that the GPU will wait for all commands to complete before proceeding. - **Submit Command List**: It marks the command list as submitted by incrementing a counter and storing the handle of the fence in the `InFlightFences` array. - **Present Data**: For each present operation, it sets up the swap chain texture container and updates the fence reference count. - **Cleanups**: It checks for cleanups by comparing the completed value of the fence with the signal value. If they match, it cleanses the command list. - **Index Buffer**: It sets the index buffer for rendering operations. - **Push Constants**: It sets push constants for shaders. - **Descriptor Heaps**: It ensures that descriptor heaps are properly set up before executing commands. ### Key Points 1. **Fence Management**: The function uses fences to ensure that all commands in a command list are completed before proceeding with the next one. 2. **Resource Barriers**: It handles resource barriers to transition resources between states (e.g., from `GENERIC_READ` to `INDEX_BUFFER`). 3. **Descriptor Heaps**: It ensures that descriptor heaps are properly managed and reused. 4. **Push Constants**: It sets push constants for shaders, which are used in vertex shader stages. ### Usage To use this function, you would typically create an instance of `D3D12CommandList`, populate it with commands such as drawing primitives, setting viewports, scissor rectangles, and more, and then call `ExecuteCommandLists` to submit the command list for execution. ```cpp // Create a command list NonNullPtr?CommandList? commandList = Internal::CreateCommandList(d3d12Driver); // Populate the command list with commands Internal::SetViewPort(commandList, viewPort); Internal::SetIndexBuffer(commandList, indexBuffer, IndexFormat::UInt16, indexCount, offset); // Execute the command list bool success = Internal::ExecuteCommandLists(d3d12Driver, ?commandList); ``` This setup ensures that all commands in a command list are executed efficiently and correctly, leveraging DirectX 12's features for efficient resource management and ## Symbols ### Namespace `Juliet::D3D12` #### Classes, Structs & Unions - `struct D3D12CommandListBaseData` - `struct D3D12CopyCommandListData` - `struct D3D12GraphicsCommandListData` - `struct D3D12PresentData` - `struct D3D12CommandList` #### Functions & Methods - `extern CommandList* AcquireCommandList(NonNullPtr driver, QueueType queueType)` - `extern bool SubmitCommandLists(NonNullPtr commandList)` - `extern void SetViewPort(NonNullPtr commandList, const GraphicsViewPort& viewPort)` - `extern void SetScissorRect(NonNullPtr commandList, const Rectangle& rectangle)` - `extern void SetBlendConstants(NonNullPtr commandList, FColor blendConstants)` - `extern void SetBlendConstants(NonNullPtr commandList, FColor blendConstants)` - `extern void SetStencilReference(NonNullPtr commandList, uint8 reference)` - `extern void SetIndexBuffer(NonNullPtr commandList, NonNullPtr buffer, IndexFormat format, size_t indexCount, index_t offset)` - `extern void SetPushConstants(NonNullPtr commandList, ShaderStage stage, uint32 rootParameterIndex, uint32 numConstants, const void* constants)` ### Namespace `Juliet::D3D12::Internal` #### Functions & Methods - `extern void SetDescriptorHeaps(NonNullPtr commandList)` - `extern void DestroyCommandList(NonNullPtr commandList)` - `extern bool CleanCommandList(NonNullPtr driver, NonNullPtr commandList, bool cancel)` - `extern void TrackGraphicsPipeline(NonNullPtr commandList, NonNullPtr pipeline)` - `extern void TrackTexture(NonNullPtr commandList, NonNullPtr texture)`