RI::cmdSetHeap¶
What it does¶
RI::cmdSetHeap(cmd, heap) binds a descriptor heap to cmd so that
shaders in subsequent draws and dispatches on that command list can index it (via
ResourceDescriptorHeap[slot] or SamplerDescriptorHeap[slot]).
Call cmdSetHeap before the first cmdSetPipeline in each
recording; you normally only need to call it once per recording. The heap stays set when you
change pipelines: RI rebinds whatever the backend needs
(RI keeps its own implicit state).
Signature¶
From the header: Before the first cmdSetPipeline of the list (P94 (10)).
Example¶
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¶
// The same order as RI's rule: the heap first, then the pipeline.
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipelineLayout, 0, 1, &heap, 0, nullptr);
What to watch for: vkCmdBindDescriptorSets takes a VkPipelineLayout. Pipeline
layouts that differ in push-constant size are not compatible, so RI rebinds the heap's
descriptor sets whenever a pipeline with a different layout is set.
ID3D12DescriptorHeap *heaps[] = {viewHeap.Get(), samplerHeap.Get()};
cmd->SetDescriptorHeaps(2, heaps); // before the root signature that indexes them
What to watch for: SetDescriptorHeaps takes both heaps (resource views and samplers)
in one call, and must be called before SetComputeRootSignature or
SetGraphicsRootSignature for any root signature that indexes the heaps directly.
Rules and errors¶
- The heap comes before the pipeline, on every backend. D3D12 requires descriptor heaps
to be bound before any root signature that indexes them directly (with
D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXEDorD3D12_ROOT_SIGNATURE_FLAG_SAMPLER_HEAP_DIRECTLY_INDEXED), so RI enforces this order on every backend. In validation builds, callingcmdSetPipelinewithout a heap set is a programmer error:cmdSetPipeline: set a descriptor heap with cmdSetHeap first (D3D12 needs the heaps bound before a root signature that indexes them). - Switching to another heap later in the same command list is allowed. When you do, RI rebinds any active compute or graphics root signatures on D3D12, or binds the new heap's descriptor sets for any active pipeline layouts on Vulkan, so the new heap takes effect.
- In validation builds, passing a destroyed
heapis a programmer error.