Skip to content

RI::createCommandList, RI::destroyCommandList, RI::resetCommandList

What it does

A command list records GPU work such as copies, draws, dispatches, and barriers. Each recording call writes its native command immediately, and nothing executes on the GPU until you submit the list.

  • RI::createCommandList(device, name) creates an empty command list with its own native command memory (a Vulkan command pool or a D3D12 command allocator). The optional name labels the list in GPU debuggers and validation messages.
  • RI::resetCommandList(cmd) discards the recorded commands so the list can be recorded again. Call it only after the list's last submission has finished (its timeline point is reached).
  • RI::destroyCommandList(device, cmd) destroys the command list and its native command memory, and resets cmd to {}. Call it only after the list's last submission has finished.

A typical command list lifecycle is: create the list once, then repeat cmdBegin, record commands, cmdEnd, submit once, wait for its timeline point, and resetCommandList.

Signature

// <RI/RI.hpp>, namespace RI
CommandList createCommandList(Device &device, std::string_view name = {});
// <RI/RI.hpp>, namespace RI
void destroyCommandList(Device &device, CommandList &cmd);
// <RI/RI.hpp>, namespace RI
void resetCommandList(CommandList &cmd);

From the header: Only once the list's last submission is reached (P56).

// <RI/RI.hpp>, namespace RI
struct CommandList {
    // internal: backend-private state (not part of the API)
};
  • D3D12 header: One command list with its own allocator (P56). Record, submit once, wait for its timeline point, then reset and reuse.
  • Vulkan header: One command list with its own native pool (P56). Record, submit once, wait for its timeline point, then reset and reuse.

Example

RI::CommandList cmd = RI::createCommandList(device);

Recording it again after its point is reached:

// The list's timeline point is reached, so it may be reset and recorded again.
RI::resetCommandList(cmd);
RI::cmdBegin(cmd);
RI::cmdSetHeap(cmd, heap);
RI::cmdSetPipeline(cmd, pipeline);
RI::Helpers::cmdSetRootData(cmd, Root{.inputSlot = 0, .outputSlot = 1, .paramsSlot = 2, .scale = 2.0f, .count = kCount});
RI::cmdDispatch(cmd, (kCount + 63) / 64, 1, 1);
RI::cmdEnd(cmd);
const RI::TimelinePoint again = RI::submit(queue, cmd);

The same in native code

RI::CommandList cmd = RI::createCommandList(device);
// A pool per command buffer, so resetting the pool resets just this list.
const VkCommandPoolCreateInfo commandPoolInfo{.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
                                              .queueFamilyIndex = queueFamily};
VkCommandPool commandPool = VK_NULL_HANDLE;
check(vkCreateCommandPool(device, &commandPoolInfo, nullptr, &commandPool), "vkCreateCommandPool");
const VkCommandBufferAllocateInfo commandInfo{.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
                                              .commandPool = commandPool,
                                              .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
                                              .commandBufferCount = 1};
VkCommandBuffer cmd = VK_NULL_HANDLE;
check(vkAllocateCommandBuffers(device, &commandInfo, &cmd), "vkAllocateCommandBuffers");
// Only after the GPU is done with it: resets every command buffer of the pool.
check(vkResetCommandPool(device, commandPool, 0), "vkResetCommandPool");

What to watch for: command buffers are allocated from pools, and resetting a pool resets all of its buffers. One pool per list keeps lists independent.

// The allocator owns the command memory; the list records into it.
ComPtr<ID3D12CommandAllocator> allocator;
check(device->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator)),
      "CreateCommandAllocator");
ComPtr<ID3D12GraphicsCommandList7> cmd; // version 7: enhanced barriers
check(device->CreateCommandList1(0, D3D12_COMMAND_LIST_TYPE_DIRECT, D3D12_COMMAND_LIST_FLAG_NONE,
                                 IID_PPV_ARGS(&cmd)),
      "CreateCommandList1"); // created closed
// Only after the GPU is done with it: the allocator's memory is reused.
check(allocator->Reset(), "ID3D12CommandAllocator::Reset");
check(cmd->Reset(allocator.Get(), nullptr), "ID3D12GraphicsCommandList::Reset");
check(cmd->Close(), "ID3D12GraphicsCommandList::Close");

What to watch for: the allocator owns the memory, and the list records into it. Resetting the allocator while the GPU is still executing the list is undefined behaviour.

Rules and errors

  • Reset or destroy a list only after its last submission's timeline point is reached. In validation builds, calling resetCommandList or destroyCommandList earlier reports a programmer error (for example: resetting a command list the GPU may still be executing: wait for its timeline point (value 3) first; the queue has reached 2).
  • Calling resetCommandList, destroyCommandList, or cmdBegin on an already-destroyed command list reports a programmer error in validation builds.
  • A recorded list is submitted once; there is no resubmission in this version.
  • Create, record, reset, and destroy command lists on the device thread (the thread that called createDevice), because RI objects are not thread-safe. Calling any of these functions from another thread reports a programmer error in validation builds.
  • cmdBegin clears the list's bound state (descriptor heap, pipeline, and root data), so set them again in each recording.