Repository navigation
GPU: the heap clamp bound must fit what D3D12 gives - #2315
xiaotu030202 wants to merge 1 commit into
Conversation
`victory-shader` clamps every heap index a translated shader computes to
`HEAP_VIEWS - 1`, and `victory-gpu` must give it a heap that has those
slots. The two disagreed.
`HEAP_VIEWS` was `1 << 21` (2,097,152). D3D12 takes 1,000,000 descriptors
in a shader-visible CBV/SRV/UAV heap on every resource binding tier and
refuses one more with `E_OUTOFMEMORY` — measured on an RTX 5070 Ti, where
every size up to 1,000,000 succeeds and 1,048,576 fails:
view 1000000 -> OK
view 1048576 -> FAIL 0x8007000E (E_OUTOFMEMORY)
view 2097152 -> FAIL 0x8007000E
So the first request, `make((count + DYNAMIC).max(views))`, could never
succeed on any device. Every host fell into the fallback, which asked for
`count + MIN_DYNAMIC` (65,536 + the title's) and got it — a heap smaller
than the index shaders were still allowed to name. A shader that read one
past it removed the device (`0x887A0005`, and one test then took the whole
test process down with `STATUS_STACK_BUFFER_OVERRUN`).
The comment on that fallback blamed NVIDIA; it was every vendor. The world
runs in Marvisak#59 (a device removal on an RX 9070 XT) are the same shape.
Three changes, all in the one place the geometry is decided:
- `HEAP_VIEWS` is `1 << 19`. The bound has to share D3D12's 1,000,000 with
the slots kept past it, not take the whole ceiling.
- `PAIR_RESERVE` (`1 << 16`) replaces `MIN_DYNAMIC`: the slots
`HostHeap::pair` hands a host copy's two views. Without a reserve, a heap
that exactly reaches the clamp bound sends every pair to a dynamic slot,
which the clamp can then reach. `extra` counts the dynamic slots alone,
so `pairs` starts past them and has room to the end.
- A `const` assertion holds the invariant: the clamp bound, the dynamic
slots and the pair reserve together must fit in `PORTABLE_VIEWS`.
A test, `the_clamp_bound_fits_in_a_host_heap`, asserts the heap the device
actually gives holds every index the clamp reaches — the thing that was
false.
Measured on Windows 11, RTX 5070 Ti, Rust 1.98.1 (pinned), before → after,
single-threaded:
descriptor:: 9 passed, 1 FAILED -> 11 passed
memory:: 2 passed, 1 FAILED -> 3 passed
draw:: 1 passed, 4 FAILED -> 4 passed, 1 FAILED
victory-shader (unchanged: 245 passed, 2 failed)
The remaining two are other faults, unchanged by this: `draw`'s
`a_texture_written_in_one_format_reads_in_another_through_a_placed_view`
fails the same way with this patch stashed, and `victory-shader`'s
`stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride` and
`synthetic_tests::gathers_at_a_level_match_the_hardware` compare against
RDNA2 results a GeForce does not reproduce. Both stashed-and-rerun the
same, so they are not from here; the last two would need an AMD card to
judge and are worth their own report.
|
The NVIDIA ceiling is reproducible on the reported setup. Tier 3 also permits larger shader-visible view heaps when the driver accepts them, per the D3D12 Resource Binding specification. I ran the same synthetic fixture on app-local WARP Tier 3. A direct
The same assertion passes on main and #2177 and fails on this PR. The early AI-assisted. Synthetic tests only. |
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:
- Functionally fixes both pre-existing NVIDIA view-heap baseline failures (
#1744):descriptor::host::tests6/6 passed on RTX 5090 and 6/6 on WARP, andmemory::tests3/3 passed on RTX 5090. cargo xtask policy: 183 files ok.- Clippy blocker (
cargo clippy -p victory-gpu --all-targets -- -D warnings):Wrapping that assertion inerror: this assertion has a constant value --> crates\victory-gpu\src\descriptor\host.rs:1532:9 | 1532 | / assert!( 1533 | | victory_shader::emit::HEAP_VIEWS <= PORTABLE_VIEWS, 1534 | | "HEAP_VIEWS is past what D3D12 gives a shader-visible heap" 1535 | | ); | |_________^ | = help: consider moving this into a const block: `const { assert!(..) }` = note: `-D clippy::assertions-on-constants` implied by `-D warnings`const { assert!(...); }will makeclippy --all-targets -- -D warningspass cleanly.
AI-assisted (Gemini 4 Neon).
catminou4
left a comment
There was a problem hiding this comment.
Tested locally: merged into main 940d32f, cargo test -p victory-shader --locked on macOS arm64 — 144 passed, 0 failed, 2 ignored (Windows-gated hardware execution tests not run here). Approving the shader side — heap clamp bound fits what D3D12 gives. GPU side Windows-only, static.
What this fixes
victory-shaderclamps every heap index a translated shader computes toHEAP_VIEWS - 1, andvictory-gpuhas to give it a heap holding those slots. The two disagreed, and the gap removed the host device.HEAP_VIEWSwas1 << 21— 2,097,152. D3D12 takes 1,000,000 descriptors in a shader-visible CBV/SRV/UAV heap on every resource binding tier and refuses one more. Measured on an RTX 5070 Ti, creating a shader-visible view heap at each size:So the first request in
HostHeap::new:could never succeed — on any device, from any vendor. Every host fell into the fallback, which asked for
count + MIN_DYNAMIC(65,536 + the title's) and got it: a heap of 65,540 slots in thehost()test heap. Translated shaders still clamped to2^21 - 1, so a shader reading a computed index past what the heap held handed the GPU a descriptor that did not exist. That is0x887A0005(DXGI_ERROR_DEVICE_REMOVED), and once the device was gone every later test in the process failed — one of them then took the whole test binary down withSTATUS_STACK_BUFFER_OVERRUN.The fallback's comment blamed NVIDIA:
It was every vendor; the comment was written from an AMD card, where the fallback path also gets taken but the tests that exercise it are the ones gated on hardware this project was developed against. It is also the same shape as #59 (device removal while loading the world on an RX 9070 XT).
What changed
Three things, all where the heap geometry is decided:
crates/victory-shader/src/emit/shader.rs—HEAP_VIEWSis1 << 19. The clamp bound cannot take the whole 1,000,000 ceiling: the slots kept past it need room too.crates/victory-gpu/src/descriptor/host.rsMIN_DYNAMICbecomesPAIR_RESERVE(1 << 16): the slotsHostHeap::pairhands a host copy's two views. This was a real second bug the first fix exposed — with a heap that exactly reaches the clamp bound, every pair went to a dynamic slot, andmemory::tests::lists_share_a_table_and_copies_keep_their_viewscaught it (pairs = (2, 4), wanting>= 1 << 18).extracounts the dynamic slots alone, sopairsstarts past them and has room to the end of the heap.max(clamp bound, title count) + PAIR_RESERVE + DYNAMIC, capped atPORTABLE_VIEWS— and falls back to the same size minus the dynamic range, never below the clamp bound.A
constassertion holds the invariant that was violated:Tests
New:
the_clamp_bound_fits_in_a_host_heap— asks the device for a real heap and assertsNumDescriptors >= HEAP_VIEWS. That is exactly the property that was false, and it fails on the old code.Measured here (Windows 11, RTX 5070 Ti, Rust 1.98.1 pinned,
--test-threads=1), before → after:descriptor::memory::draw::victory-shaderindirect::,list::,host::,pipeline::,device::,queue::,query::,fence::,frame::,dxgi::,bindless::,object::,primitive::,resource::are all green.What is left, and why it is not here
Two failures remain and neither comes from this patch — I stashed it and re-ran to confirm:
draw::tests::a_texture_written_in_one_format_reads_in_another_through_a_placed_viewfails atCreateRootSignaturewith0x887A0005on its own, isolated, with the patch stashed as well. It does not touch the heap geometry (it builds its ownSlots::new(4)and a fixed root signature).victory-shader'sstride_tests::a_heap_buffer_read_by_element_takes_the_views_strideandsynthetic_tests::gathers_at_a_level_match_the_hardwarecompare shader output against RDNA2 hardware results. On a GeForce the first returns 11 of 32 lanes' worth (left: [101..131, 0, 0, ...],right: [200..231]). Both fail identically with the patch stashed. Judging them needs an AMD card, and they deserve their own issue rather than a patch from here.I could not run the title (no game files), so this is not evidence that the world now renders. What it does establish is that a host heap can now hold every index the translator is allowed to name, and that the tests which check it pass — including on NVIDIA, where they could not before.
Environment
Windows 11, Ryzen 7 9800X3D, RTX 5070 Ti (driver 32.0.16.2140), MSVC 14.44.35207, Windows SDK 10.0.26100.0,
VICTORY_DXILpointed at that SDK'sdxil.dll.