Repository navigation
Added Conditional Rendering Extension - #272
HirunaVishwamith wants to merge 2 commits into
Conversation
GCC 11 -Werror=maybe-uninitialized reads alignment before the first resource sets it.
VK uses VK_EXT_conditional_rendering. D3D12 uses SetPredication. A zero 64-bit predicate skips draws, dispatches, and CmdClearAttachments. D3D11, Metal, WebGPU, and NONE leave the feature disabled.
|
D3D12 correctness blocker: conditional rendering also suppresses operations that should remain unconditional Reviewed at CommandBufferD3D12.hpp:1716 enables native This differs from the PR’s intended contract: copies and storage clears remain unconditional. Vulkan buffer copies are explicitly unaffected by conditional rendering. Reproduced on the unchanged PRUsing the public NRI API on an RTX 4080, with NRI and native validation enabled:
All four zero/nonzero and inverted/non-inverted combinations were tested: Vulkan always executes the copy; D3D12 skips it whenever the predicate rejects the scope. Both backends reported zero validation errors for these probes. Implicit rendering operations are affected tooThe same enabled predication reaches existing internal operations:
These implications follow from the implementation and native command semantics; the GPU reproduction above specifically tested buffer copies. Please preserve the intended conditional command set on D3D12, including unconditional internal load clears and resolves. This may require suspending/restoring predication around the relevant native operations while preserving the intended predicate semantics. Alternatively, narrow the permitted scopes explicitly and enforce those restrictions in Validation. Both reviewers retain NoGo for this behavioral issue. API/layout changes requiring recompilation are acceptable and are not part of this finding. |
|
Following up on the D3D12/Vulkan behavior discrepancy: the native calls themselves are correct. The clean solution is to tighten the NRI usage contract and enforce it in Validation, keeping the proposed API and thin backend mappings. Suggested contract:
For graphics: CmdBeginRendering(...); // Unconditional attachment load operations
CmdBeginConditionalRendering(...);
CmdDraw(...);
CmdClearAttachments(...); // Conditional explicit clear
CmdEndConditionalRendering(...);
CmdEndRendering(...); // Unconditional attachment resolvesFor compute: CmdBeginConditionalRendering(...);
CmdDispatch(...);
CmdEndConditionalRendering(...);
CmdCopyBuffer(...); // Outside the conditional scopeValidation can use the active-scope flag already introduced to reject the disallowed operations and rendering boundaries. The public documentation should enumerate the supported conditional commands rather than relying on broad wildcards. Add focused coverage for both legal sequences and rejection of copies, storage clears, resolves, rendering boundaries, nesting, and unclosed scopes. This avoids hidden backend state management. Automatically suspending/restoring D3D12 predication is less attractive: D3D12 snapshots the predicate at With these restrictions, attachment load clears and automatic resolves execute outside the conditional scope, and the D3D12/Vulkan discrepancy is excluded by the NRI contract. No extra API parameters or backend emulation are needed. |
|
Naming suggestion: use In NRI, “rendering” denotes graphics rendering, as in “Predication” describes conditional GPU execution without implying graphics or a rendering instance. It is concise and fits the proposed explicit begin/end usage contract. For consistency, rename the associated capability and flags too:
|
|
|
Thanks for the update @dzhdanNV . I'll fix those. |
|
After looking into the implementation more closely and thinking about the gains and maintenance cost: I'm cancelling this PR, sorry. Inefficient GPU Execution: Obsolete Architecture: Poor Portability & Maintenance Overhead: |
This adds conditional rendering so a draw, dispatch, or
CmdClearAttachmentscan be skipped based on a value in a buffer.The predicate is a 64-bit value at an 8-byte-aligned offset. A value of 0 skips the commands; any other value runs them.
invertedflips that test. Vulkan reads only the low 32 bits, so the high 32 bits must stay 0. Begin and end must be in the same command buffer, both inside or both outside rendering. Nesting is not allowed. Copies, clears, and barriers are not skipped.Public API
features.conditionalRenderingBufferUsageBits::CONDITIONAL_RENDERINGAccessBits::CONDITIONAL_RENDERINGStageBits::CONDITIONAL_RENDERINGCmdBeginConditionalRendering/CmdEndConditionalRenderingBackends
VK_EXT_conditional_rendering.SetPredicationand reports the feature as supported.inverted = falsemaps toD3D12_PREDICATION_OP_EQUAL_ZERO, so a zero predicate skips.Validation checks the recording state, the feature flag, a graphics or compute queue, buffer usage, the 8-byte range, nesting, and that begin and end are both inside or both outside rendering.
There is also a one-line GCC 11 fix:
MemoryHeap::alignmentis initialized to 0. Without it,-Werror=maybe-uninitializedfails the Linux Release build.Testing
Tested on an RTX 3050 Laptop GPU (Vulkan 1.4.312, driver 580.159.03) with NRI validation on. A compute dispatch writes 42 only when the predicate says to run:
1 << 32, not inverted → result stays 0 (Vulkan sees the low 32 bits as 0)All four cases passed. D3D12, D3D11, Metal, and WebGPU were not compiled on this machine.