NVIDIA: reserve the null clamp slot in every capped view heap and key shader cache by cap #20
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Zettrox/ztrx. Originally posted by rivaldodev on 2026-11-25T03:24:24Z.
Reserves the shader's null clamp slot in every view heap on capped hosts (e.g. NVIDIA's 1,000,000-slot view heap limit) and includes the host view heap cap in the shader cache fingerprint.
What changed
crates/victory-gpu/src/descriptor/host.rs:view_heap_layout(count, extra, null_slot)sizing helper so capped and uncapped heap arithmetic can be unit-tested without D3D12 initialization.null + 1slots and limits title slots tonull - DYNAMIC, keeping the clamp slot strictly past both title and dynamic allocations.HostHeap::new()that previously mutatedview_heap_limitafter a failed large allocation.probe_view_limit()establishes the cap once before shader translation or heap creation; subsequent allocation failures now fail explicitly rather than invalidating previously translated shaders or cache keys.HostHeap::new()now returnsNoneiffill_null()fails instead of returning an uninitialized heap, and only records the range inGPU_RANGESafterfill_null()succeeds.heap_sizing_keeps_the_clamp_slot_past_title_and_dynamic_slotsalongside the hardware testview_heaps_keep_the_clamp_slot_null.crates/victory-gpu/src/shader_cache.rs:probe_view_limit()and hashesview_heap_limit()into the build fingerprint so cached translations match the host's heap cap (and documents the host-probe side effect).crates/victory-shader/src/emit/{shader.rs,mod.rs}:view_heap_limit().Tests
cargo clippy -p victory-gpu -p victory-shader --no-deps --all-targets --locked— clean on changed files.cargo test -p victory-gpu --lib --locked— 112 passed, 0 failed, 1 ignored (including both the pure sizing test and the hardware clamp-slot test).Split per review feedback: the automatic divergent barrier policy has been moved to a separate draft PR.
Imported from Zettrox/ztrx. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T03:24:34Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from Zettrox/ztrx. Originally posted by kaayzouee on 2026-11-25T03:27:41Z.
Code review — Request changes
Reviewed commit
23e2eab. No equivalent fix was found in the target repository’s available pull request history.The capped-heap sizing arithmetic is sound. Allocating null + 1 slots and limiting the title count to null - DYNAMIC correctly keeps dynamic allocations below the clamp slot. Using the actual allocated size for GPU-range diagnostics is also correct.
However, there are several correctness concerns.
In shader_cache.rs, the build fingerprint is computed once through OnceLock, incorporating the cap determined by the initial probe.
However, HostHeap::new() still changes the global cap when a subsequent larger allocation fails.
A host can successfully allocate the 1,000,001-slot probe heap but fail a larger allocation. If the fallback succeeds, the global cap changes from zero to 999,999.
Consequently:
The late fallback predates this PR, but directly conflicts with the newly introduced cache and heap consistency requirements.
Please establish one immutable heap policy before shader translation and heap allocation. If a subsequent allocation cannot satisfy that policy, fail explicitly rather than silently changing the translation assumptions.
HostHeap::new() logs errors returned by fill_null() but still returns Some(h).
If creation of the CPU staging descriptor heap fails, the reserved clamp slot and padded region may remain uninitialized.
Microsoft’s documentation explicitly warns that accessing uninitialized descriptor memory can cause undefined behavior, including device resets:
https://learn.microsoft.com/en-us/windows/win32/direct3d12/setting-descriptor-heaps
Heap creation should fail if null initialization cannot be completed, or use a verified fallback initialization method.
Additionally, null_view() creates a null Texture2D SRV. This is not a universally compatible null descriptor for all CBV/SRV/UAV accesses.
Both limitations predate this PR, but they undermine its stated clamp-slot safety guarantee. Descriptor type compatibility should be documented or addressed separately.
The extracted barrier_mode() is readable, preserves explicit overrides, and does not alter translation-added meeting barriers.
However, D3D12 group synchronization is a thread-group requirement, not a wave-width requirement.
The new predicate still permits potentially divergent group barriers in a wave32 shader with a 64-thread group running on wave32 hardware.
Microsoft documents divergent group synchronization as undefined behavior:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/groupmemorybarrierwithgroupsync
This is an existing limitation retained by the new automatic mode, rather than a newly introduced regression.
Conversely, removing group synchronization preserves memory fences but removes the inter-thread rendezvous. These are not semantically equivalent.
The GPU regression test demonstrates successful dispatch completion but does not exercise LDS producer-consumer communication across the barrier. It therefore does not establish memory synchronization correctness.
Please document automatic mode as a targeted compatibility workaround and consider adding producer-consumer regression tests.
Verdict
Request changes, primarily because the late heap-cap fallback can invalidate shader cache assumptions and because failed null initialization does not prevent heap creation.
The underlying arithmetic fix is good. The automatic barrier workaround is promising, but its semantic limitations should be explicit.
Static review only. I inspected the changed code, surrounding implementations, repository-wide PR search results, and Microsoft API documentation. The reported Windows/GPU tests and allocation failure scenarios were not independently reproduced.
⸻
This is an automated message, if you believe this is incorrect, please reply with the relevant technical context or a reproducible counterexample so the finding can be reassessed.
Imported from Zettrox/ztrx. Originally posted by rivaldodev on 2026-11-25T03:59:39Z.
Addressed the review feedback in
a850e49:HostHeap::new()that previously mutatedview_heap_limitmid-run on a failed large allocation.probe_view_limit()now establishes the cap once; subsequent allocation failures fail explicitly.fill_null()error:HostHeap::new()now returnsNoneiffill_null()fails and only records the range inGPU_RANGESafter null initialization succeeds.view_heap_layout(count, extra, null_slot)and addedheap_sizing_keeps_the_clamp_slot_past_title_and_dynamic_slots.cargo test -p victory-gpu --lib --lockedpasses (112 passed, 0 failed, 1 ignored). Ready for re-review.Imported from Zettrox/ztrx. Originally posted by futurepro62 on 2026-11-25T06:38:39Z.
Full-suite run on Windows, since this PR has no test report yet. Tested exact head
a850e49(on its base90b529f).Tested
rust-toolchain.toml), DXC + dxil.dll 1.9.2602.17, debug.cargo test --workspace --locked: 498 passed, 0 failed, 7 ignored (main90b529fon this machine: 496 passed, 0 failed, 7 ignored).cargo clippy --workspace --all-targets --locked -- -D warnings(the CI lint step): passed.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings(the CI lint step): passed.heap_sizing_keeps_the_clamp_slot_past_title_and_dynamic_slots,view_heaps_keep_the_clamp_slot_null.Not tested
AI use
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.