ID3D12CommandQueue
The ID3D12CommandQueue interface represents a queue of commands that the GPU will execute. Command queues are created from an ID3D12Device and are associated with a specific command list type (direct, bundle, compute, copy).
Syntax
interface ID3D12CommandQueue : ID3D12Object
{
D3D12_COMMAND_QUEUE_DESC GetDesc();
void ExecuteCommandLists(
UINT NumCommandLists,
ID3D12CommandList* const* ppCommandLists);
void Signal(
ID3D12Fence* pFence,
UINT64 Value);
void Wait(
ID3D12Fence* pFence,
UINT64 Value);
// … additional methods omitted for brevity …
};
Members
| Member | Type | Description |
|---|---|---|
GetDesc | Method | Retrieves the properties of the command queue. |
ExecuteCommandLists | Method | Submits one or more command lists for execution. |
Signal | Method | Signals a fence after all previously submitted work completes. |
Wait | Method | Pauses execution of this queue until a fence reaches a specified value. |
Methods
| Method | Signature | Remarks |
|---|---|---|
GetDesc |
D3D12_COMMAND_QUEUE_DESC GetDesc(); |
Returns a D3D12_COMMAND_QUEUE_DESC that describes the queue. |
ExecuteCommandLists |
void ExecuteCommandLists(UINT NumCommandLists, ID3D12CommandList* const* ppCommandLists); |
Accepts an array of command list pointers. |
Signal |
void Signal(ID3D12Fence* pFence, UINT64 Value); |
Enqueues a signal operation that will set the fence to Value. |
Wait |
void Wait(ID3D12Fence* pFence, UINT64 Value); |
Blocks the queue until the fence reaches Value. |
Remarks
Command queues are the primary mechanism for submitting work to the GPU. Multiple queues can be created to enable parallel execution of different types of work. The ordering of work submitted to a single queue is FIFO. Synchronization between queues is achieved using ID3D12Fence objects.
When creating a command queue, the D3D12_COMMAND_QUEUE_DESC structure must specify the Type (e.g., D3D12_COMMAND_LIST_TYPE_DIRECT) and optional priority and flags.
Example
#include <d3d12.h>
#include <dxgi1_4.h>
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;
void CreateAndExecuteQueue(ComPtr<ID3D12Device> device)
{
D3D12_COMMAND_QUEUE_DESC qDesc = {};
qDesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
qDesc.Priority = D3D12_COMMAND_QUEUE_PRIORITY_NORMAL;
qDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
qDesc.NodeMask = 0;
ComPtr<ID3D12CommandQueue> cmdQueue;
device->CreateCommandQueue(&qDesc, IID_PPV_ARGS(&cmdQueue));
// Create a command allocator and list
ComPtr<ID3D12CommandAllocator> allocator;
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator));
ComPtr<ID3D12GraphicsCommandList> cmdList;
device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator.Get(), nullptr, IID_PPV_ARGS(&cmdList));
// Record commands (example clears a render target)
// ...
cmdList->Close();
ID3D12CommandList* ppLists[] = { cmdList.Get() };
cmdQueue->ExecuteCommandLists(1, ppLists);
// Signal a fence to know when GPU work is finished
ComPtr<ID3D12Fence> fence;
device->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence));
UINT64 fenceValue = 1;
cmdQueue->Signal(fence.Get(), fenceValue);
}