Microsoft Docs

Command Lists

Command lists are a core feature of Direct3D 12 that enable applications to record GPU commands once and execute them multiple times. They improve CPU performance by reducing overhead associated with command submission.

Why Use Command Lists?

Creating a Command List

#include <d3d12.h>
#include <wrl/client.h>
using Microsoft::WRL::ComPtr;

ComPtr<ID3D12Device> device;
ComPtr<ID3D12CommandAllocator> allocator;
ComPtr<ID3D12GraphicsCommandList> commandList;

// Assume device is already created
device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator));
device->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, allocator.Get(), nullptr, IID_PPV_ARGS(&commandList));

// Record commands...
commandList->Close();

Recording Commands

Once a command list is opened, you can record any GPU operation supported by Direct3D 12:

Executing a Command List

ComPtr<ID3D12CommandQueue> commandQueue;

// Assume commandQueue is already created
ID3D12CommandList* ppCommandLists[] = { commandList.Get() };
commandQueue->ExecuteCommandLists(_countof(ppCommandLists), ppCommandLists);

Command List Lifecycle

StateDescription
OpenReady to record commands.
ClosedFinished recording, ready for execution.
ResetReturns to the Open state using a command allocator.

Best Practices

  1. Reuse command allocators: Reset them after GPU execution.
  2. Group related work: Keep a command list focused on a single logical task.
  3. Use multiple command lists for multithreaded recording.
  4. Avoid state changes inside a command list when possible.

Further Reading