RI::cmdSetPipeline¶
What it does¶
RI::cmdSetPipeline(cmd, pipeline) selects the pipeline that subsequent commands run: a
compute pipeline for cmdDispatch, or a
graphics pipeline for cmdDraw inside a
rendering section. On D3D12, only one pipeline is active at a time
(graphics and compute share one slot), so after a dispatch you must set a graphics pipeline
again before drawing, and after a draw you must set a compute pipeline again before
dispatching.
The call also updates the active pipeline layout when it changes (setting the root signature on
D3D12, or rebinding the descriptor heap sets on Vulkan) and records the pipeline's
rootDataSize so cmdSetRootData can validate the size. For a graphics pipeline, it also
applies the pipeline's stencil.reference unless
cmdSetStencilReference has already overridden it in the current
rendering section.
You can switch pipelines as often as needed within a command list. After switching, call
cmdSetRootData again if the new pipeline uses root data, because each
pipeline expects its own root data.
Signature¶
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¶
What to watch for: binding a pipeline does not bind its descriptor sets or push constants;
those are bound separately using a VkPipelineLayout that is compatible with the
pipeline's layout.
What to watch for: the root signature and the pipeline state are set in separate calls. Setting a root signature invalidates the current root arguments (such as root constants), so RI sets a new root signature only when it differs from the current one.
Rules and errors¶
- Set the heap first:
cmdSetHeapmust come beforecmdSetPipelinein each recording, on every backend. In validation builds, a pipeline set with no heap is a programmer error:cmdSetPipeline: set a descriptor heap with cmdSetHeap first (D3D12 needs the heaps bound before a root signature that indexes them). - In validation builds, a destroyed pipeline is a programmer error.
- In a read-only depth section, a pipeline that
writes depth is a programmer error in validation builds:
cmdSetPipeline: the pipeline writes depth, but the rendering section's depth is read-only (P75). A pipeline writes depth wheneverdepth.writeistrue, even withdepth.testoff, since RI then tests withCompareOp::eAlways.