Skip to content

RI::setName, RI::cmdBeginMarker, RI::cmdEndMarker

What it does

Object names and command markers are always on, in every build, including release builds.

  • Names at creation: nine creation descriptors have name as their last field (BufferDesc, TextureDesc, TextureViewDesc, ComputePipelineDesc, GraphicsPipelineDesc, WorkGraphDesc, DescriptorHeapDesc, QueryPoolDesc, and SwapchainDesc), and allocateMemory, createCommandList, and createAccelerationStructure take name as their last argument. GPU debuggers and captures (RenderDoc, PIX, Nsight), native validation layers, and RI's own use-after-destroy messages in validation builds display these names. RI copies the string during the call, so a temporary string is fine. The default is an empty std::string_view, which skips naming. When a swapchain has a non-empty name, its images are named <name> [i] (zero-based index i), both at creation and after resizeSwapchain.
  • RI::setName(device, object, name) renames an existing object on the device thread. It accepts Memory, Buffer, Texture, TextureView, DescriptorHeap, QueryPool, Pipeline, and CommandList.
  • RI::cmdBeginMarker(cmd, name) and RI::cmdEndMarker(cmd) open and close a named region of commands in a capture. Regions can nest, and every region opened in a command list must be closed in that same command list before cmdEnd.

Names are UTF-8. Each naming call costs a driver call, so name objects once at creation and rename only when the name must change.

Signature

// <RI/RI.hpp>, namespace RI
void setName(Device &device, const Memory &memory, std::string_view name);
void setName(Device &device, const Buffer &buffer, std::string_view name);
void setName(Device &device, const Texture &texture, std::string_view name);
void setName(Device &device, const TextureView &view, std::string_view name);
void setName(Device &device, const DescriptorHeap &heap, std::string_view name);
void setName(Device &device, const QueryPool &pool, std::string_view name);
void setName(Device &device, const Pipeline &pipeline, std::string_view name);
void setName(Device &device, const CommandList &cmd, std::string_view name);

From the header: Names shown by debuggers, captures (RenderDoc, PIX, Nsight) and validation messages. Always on, in every build.

// <RI/RI.hpp>, namespace RI
void cmdBeginMarker(CommandList &cmd, std::string_view name);

From the header: A named region of commands in captures; regions nest and close in the same command list.

// <RI/RI.hpp>, namespace RI
void cmdEndMarker(CommandList &cmd);

Example

// Names appear in RenderDoc, PIX, Nsight and in validation messages. Give
// them at creation: in the desc, or as the last argument where there is none.
RI::Memory memory = RI::allocateMemory(device, RI::MemoryKind::eGPU, 1 << 20, nullptr, "scene memory");
RI::Buffer particles = RI::createBuffer(
    device, memory, 0, {.size = 4096, .usage = RI::BufferUsage::eCopyDst, .name = "particles"});
RI::CommandList cmd = RI::createCommandList(device, "frame commands");
// setName renames, for example a command list reused for another pass.
RI::setName(device, cmd, "frame 1 commands");
// Regions group commands in a capture; they nest, and each closes in the
// command list that opened it.
RI::cmdBeginMarker(cmd, "particles");
RI::cmdBeginMarker(cmd, "reset");
RI::cmdClearBuffer(cmd, particles, 0);
RI::cmdEndMarker(cmd);
RI::cmdEndMarker(cmd);

The same in native code

// Regions group commands in a capture; they nest, and each closes in the
// command list that opened it.
RI::cmdBeginMarker(cmd, "particles");
RI::cmdBeginMarker(cmd, "reset");
RI::cmdClearBuffer(cmd, particles, 0);
RI::cmdEndMarker(cmd);
RI::cmdEndMarker(cmd);
void nameBuffer(VkInstance instance, VkDevice device, VkBuffer buffer, const char *name) {
    const auto setName = reinterpret_cast<PFN_vkSetDebugUtilsObjectNameEXT>(
        vkGetInstanceProcAddr(instance, "vkSetDebugUtilsObjectNameEXT"));
    const VkDebugUtilsObjectNameInfoEXT info{.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
                                             .objectType = VK_OBJECT_TYPE_BUFFER,
                                             .objectHandle = reinterpret_cast<uint64_t>(buffer),
                                             .pObjectName = name};
    setName(device, &info);
}
void labelled(VkInstance instance, VkCommandBuffer commands) {
    const auto begin = reinterpret_cast<PFN_vkCmdBeginDebugUtilsLabelEXT>(
        vkGetInstanceProcAddr(instance, "vkCmdBeginDebugUtilsLabelEXT"));
    const auto end = reinterpret_cast<PFN_vkCmdEndDebugUtilsLabelEXT>(
        vkGetInstanceProcAddr(instance, "vkCmdEndDebugUtilsLabelEXT"));
    const VkDebugUtilsLabelEXT label{.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_LABEL_EXT, .pLabelName = "particles"};
    begin(commands, &label);
    // ... commands ...
    end(commands);
}

What to watch for: VK_EXT_debug_utils is an instance extension, so its functions come from vkGetInstanceProcAddr, and the instance must enable it.

void nameResource(ID3D12Resource *resource) { resource->SetName(L"particles"); }
void labelled(ID3D12GraphicsCommandList *list) {
    const wchar_t *name = L"particles";
    list->BeginEvent(0, name, static_cast<UINT>((std::wcslen(name) + 1) * sizeof(wchar_t)));
    // ... commands ...
    list->EndEvent();
}

What to watch for: SetName takes UTF-16. Markers are PIX events; without the PIX headers, calling ID3D12GraphicsCommandList::BeginEvent with metadata 0 and a null-terminated UTF-16 string (size in bytes, including the null terminator) produces the format PIX and other tools read.

How RI does it

  • Vulkan: RI enables VK_EXT_debug_utils on every device's instance. It uses vkSetDebugUtilsObjectNameEXT for object names (a texture's name also goes to its whole-texture view, a descriptor heap's name to its pool and both descriptor sets, and an acceleration structure's name to its backing buffer) and vkCmdBeginDebugUtilsLabelEXT / vkCmdEndDebugUtilsLabelEXT for markers.
  • D3D12: RI converts names from UTF-8 to UTF-16 and calls ID3D12Object::SetName (a pipeline's or work graph's name also goes to its root signature, and a descriptor heap's name to both its resource and sampler heaps). Texture views are descriptors on D3D12 rather than objects, so naming a TextureView does nothing. Markers are PIX events (BeginEvent / EndEvent).

Rules and errors

  • Calling cmdEndMarker when no marker region is open triggers a programmer error in validation builds: cmdEndMarker: no marker region is open (P53).
  • Leaving a marker region open when cmdEnd is called triggers a programmer error in validation builds: cmdEnd: 1 marker region(s) left open; close each with cmdEndMarker (P53).