GPU: the heap clamp bound must fit what D3D12 gives #2315
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2315
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2315/head"
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?
@xiaotu030202 on GitHub · 2026-11-25 10:27 UTC · original
xiaotu030202:gpu/heap-clamp-bound-fits-host→main· +103 −20 · 2 files · 1 commits · closed without mergingWhat 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.`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 #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.@andrewpozdnakov7-jpg on GitHub · 2026-11-25 10:42 UTC · original
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
CreateDescriptorHeapsucceeded with 1,000,001 and 2,097,152 shader-visible CBV/SRV/UAV descriptors on all three heads. The VIctory entry point behaved differently:HostHeap::new(false, 4)HostHeap::new(false, 1_245_184)940d32f43aa1b2None1a3261fThe same assertion passes on main and #2177 and fails on this PR. The early
least > PORTABLE_VIEWSreturn replaces a successful larger allocation on this device. A capability probe with a capped fallback, as in #2177, addresses the NVIDIA ceiling while preserving the successful Tier 3 path here.AI-assisted. Synthetic tests only.
@Dathinel on GitHub · 2026-11-25 14:55 UTC · original
Hardware data point for the heap ceiling on NVIDIA Ampere, with the D3D12 debug layer on (
--features diagnostics,VICTORY_D3D12_DEBUG=1; the probe requiredID3D12InfoQueue). RTX 3050 Laptop, driver 610.62, resource binding tier 3, Windows 11 26200.Direct shader-visible
CreateDescriptorHeap: views 1,000,000 OK; 1,000,001 / 1,048,576 / 2,097,152 fail with0x80070057, with the layer saying "the limit for shader visible view heaps is 1000000". Samplers 2,049 OK, 4,096 fail (layer: limit 4080). With the layer on, the code is E_INVALIDARG rather than the E_OUTOFMEMORY in the description; I did not run without it.HostHeap::newon the same card, one synthetic probe per head:new(false, 4)new(false, 1_245_184)940d32f43aa1b2None9518df8d15c68bSo on NVIDIA hardware main's mismatch is real (clamp above the heap in both cases), and this PR closes it for small titles. But a title that declares more than the ceiling now gets no view heap at all, where main, #2185 and #2177 cap it at 1,000,000. That matches the WARP result above. I did not test a shader read past the cap on any head.
AI-assisted; synthetic probe only. Probe source available on request.
@Marvisak on GitHub · 2026-11-25 15:26 UTC · original
Automated triage for the maintainers.
Proposed close. Thanks for the measurements; the mismatch on NVIDIA is real (the clamp bound is above the heap the host gives), but this fix makes things worse elsewhere:
HostHeap::newindescriptor/host.rsnow returnsNone(no view heap at all) whenevermax(count, HEAP_VIEWS) + PAIR_RESERVE > PORTABLE_VIEWS, i.e. for any title heap above about 934K slots, wheremaincaps it at 1,000,000. The title is reported to use slots past 1,236,191 (#2185), so it would lose its heap entirely; two contributors reproduced this here, on WARP and an RTX 3050 (new(false, 1_245_184)givesNone).HEAP_VIEWSto1 << 19for everyone clamps reachable title indices on hosts that work today.shader.rsandhost.rsgo against the repo's short-docs rule.#2177 and #2185 address the same ceiling with a runtime probe and a capped fallback that keeps the larger Tier 3 path; please continue there, or rework this to probe the host instead of fixing a smaller constant. CI: not run.
This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.
Generated by Claude Code
@xiaotu030202 on GitHub · 2026-11-25 15:35 UTC · original
The triage is right on all three points, and I am closing this rather than reworking it.
I checked each claim against the diff before agreeing:
Noneinstead of a heap.HostHeap::newindescriptor/host.rsdoes:A title declaring 1,245,184 slots gets
least = 1,245,184 + 65,536 > 1,000,000, so it takes that branch and the process runs with no view heap at all.maincaps the heap at 1,000,000 and keeps going. The WARP result and @Dathinel's RTX 3050 result are both that branch, and I had not run either case.HEAP_VIEWS = 1 << 19is a global loss. It was1 << 21= 2,097,152. On a Tier 3 driver that really does hand out 2,097,152 (WARP, per the table above), shaders can now name only a quarter of what the heap holds — so this "fix" clamps reachable indices on hosts that work today. That is worse than the mismatch it was aimed at.The comments. Fair.
shader.rsandhost.rsboth carry multi-paragraph rationale that belongs in a PR description, not in the tree.What I still think was worth measuring, and where it belongs.
The invariant this PR was trying to state is:
On
mainthat is violated in both directions —new(false, 4)returns 65,540 slots against a bound of 2,097,152 — which is the NVIDIA fault I measured. But a fixed bound cannot satisfy it, because the number of slots is a runtime property of the driver and the binding tier. #2177 and #2185 set the bound from the heap at runtime, which is the only shape that satisfies it, and their own tables show a 1,000,000 heap with 934,461 and 844,349 title slots kept where mine returnsNone.So I am not reworking this: a third runtime probe would duplicate #2177/#2185 rather than add to them, and that is the same mistake I made earlier on this account — opening a patch for something two other PRs had already covered.
Where the measurement goes. My original number (1,048,576 →
E_OUTOFMEMORY0x8007000E on an RTX 5070 Ti) is now confirmed three ways — @andrewpozdnakov7-jpg on WARP Tier 3, @Dathinel on Ampere with the debug layer naming the 1,000,000 limit explicitly, and this triage — so it needs no PR to be useful. I will put the invariant and the two-sided table on #2185 as a comment rather than a diff.Thanks for reading it closely enough to find the regression; a synthetic-only patch that turns a clamp into a refusal should not have been opened without running the above-ceiling case, and I did not run it.
Pull request closed