RI::cmdSetRootData¶
What it does¶
RI::cmdSetRootData(cmd, data) sets the current pipeline's root data:
a small struct of values (such as descriptor heap slots and constants) that the shader
declares with EQ_ROOT_DATA and that subsequent dispatches and draws read. The bytes are
copied into the command list immediately, so you can modify or destroy the source data right
after the call.
The core function RI::cmdSetRootData takes raw bytes (std::span<const std::byte>). The
typed helper RI::Helpers::cmdSetRootData(cmd, value) takes
a trivially copyable value (not a pointer or std::span), forwards sizeof(value) bytes, and
checks at compile time that its size is a multiple of 4 and at most RI::kMaxRootDataSize
(256 bytes). To pass a struct to
RI::cmdSetRootData directly, view its bytes with std::as_bytes(std::span(&value, 1)).
Signature¶
// <RI/RI.hpp>, namespace RI
void cmdSetRootData(CommandList &cmd, std::span<const std::byte> data);
From the header: data is the pipeline's rootDataSize bytes (checked in validation builds, P24). Kept across draws and dispatches until set again. Typed values: RI::Helpers::cmdSetRootData (P107).
Example¶
The struct mirrors the shader's declaration:
#include <equine/root.hlsli>
// Root data: a few values set per dispatch with cmdSetRootData (P45).
// The C++ side declares the same struct.
struct Root {
uint inputSlot; // descriptor heap slots of the three buffers
uint outputSlot;
uint paramsSlot;
float scale;
uint count;
};
EQ_ROOT_DATA(Root, root);
// The C++ mirror of `Root` in the shader: same members, same order.
struct Root {
uint32 inputSlot;
uint32 outputSlot;
uint32 paramsSlot;
float scale;
uint32 count;
};
RI::cmdSetHeap(cmd, heap);
RI::cmdSetPipeline(cmd, pipeline);
RI::Helpers::cmdSetRootData(cmd, Root{.inputSlot = 0, .outputSlot = 1, .paramsSlot = 2, .scale = 3.0f, .count = kCount});
The same in native code¶
const Root root{.inputSlot = 0, .outputSlot = 1, .paramsSlot = 2, .scale = 3.0f, .count = kCount};
vkCmdPushConstants(cmd, pipelineLayout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(root), &root);
What to watch for: push constants are set with a pipeline layout and stage flags that
must match the layout's push-constant range. RI's ranges use VK_SHADER_STAGE_ALL.
Rules and errors¶
- Call
cmdSetRootDataaftercmdSetPipeline, because the data belongs to the current pipeline. Set it again after switching pipelines. - In validation builds,
data.size()must equal the current pipeline'spipeline.rootDataSize. A mismatch is reported as a programmer error (for example,programmer error: root data is 8 bytes, but the pipeline's shader declares 20 bytes). CallingcmdSetRootDatawhen the shader declares no root data (pipeline.rootDataSize == 0), or before any pipeline is set, is also a programmer error. - Keep the C++ struct members in the same order and layout as the HLSL struct; RI's shader
compile rule (
equine_add_shaders) uses D3D12's constant-buffer layout on both backends.