fix: clamp shader heap indices to the host's view-heap cap (NVIDIA) #2185
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!2185
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2185"
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?
@thedanmaor on GitHub · 2026-11-25 07:18 UTC · original
DID-Software-Solutions:fix/nvidia-heap-clamp→main· +433 −80 · 12 files · 11 commits · openProblem
NVIDIA caps shader-visible CBV/SRV/UAV heaps at 10^6 slots. The world uses title slots past that (1,236,191 and up;
title slot past the host heapwarnings), and translated shaders clamp only belowHEAP_VIEWS(2^21), so on NVIDIA the run ends with device removed (DXGI_ERROR_INVALID_CALL). Removing the pre-built pipeline library did not change that.Change
host::createprobes aHEAP_VIEWSshader-visible heap. Where it is refused,emit::set_heap_views(PORTABLE_VIEWS)sets the clamp to the cap.heap_handleandbuffer_guardclamp belowemit::heap_views(), and the null buffer views move toemit::null_buffer_view()(the cap's last slots).descriptor::host: on a capped host, the heap isviewsslots. Title slots come first, thenMIN_DYNAMICdynamic slots, then the null views. Title slots past that read as null (a shortcut: drawing may be missing or wrong).heap_views()keys the shader cache and the pipeline-library tag, so AMD and NVIDIA translations never mix.host_shadercreates the host device first, so the probe runs before any translation. As a resultvictory translate(including--cachewarming) now creates a D3D12 device (GPU or WARP) before it translates; it did not need one before.Hosts that take a 2^21 heap (AMD) are unchanged.
Later commits on this branch
b66fb0f). The per-slot view-addresses table held only a capped heap's kept title slots (934461). Shaders read it through an unbounded root SRV at indices up to 999999, so reads went up to ~524 KB past the buffer and hung the BVH traversalf607780aa8e502d0. The strides, marks and view-address tables now shareindexed_slots(). Heap-direct title indices past the kept slots go to the null last slot (title_guard).heap_viewsslots unless the title fits under it, and the uncapped fallback keeps room for the dynamic and null slots.docs/gpu-hang-investigation.mdrecords the cause and the eight leads ruled out.Checks
victory-gpuandvictory-shader.victory-gpulib tests: 145 pass, including the newper_slot_tables_cover_every_index_a_shader_reads.victory-shaderlib tests: 248 pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
@kotekompotek on GitHub · 2026-11-25 07:45 UTC · original
Reviewed the mechanism end-to-end — it is sound, and complementary to the remapping PRs rather than a duplicate.
Why it stops the removal: on main, translated shaders clamp below
HEAP_VIEWS(2M) but NVIDIA's heap is ≤1M, so indices 1M..2M index past the heap and fault the device. Clamping to the probed cap means those indices are never emitted; past-cap title slots read null. #2121/#2189 make those slots actually work (paging/recycling); this makes the device survive until then. Landing this first would get NVIDIA users to menus, with remapping as the follow-up for correct content.Verified in the code:
translate --cacheon NVIDIA keys entries under the 1M clamp becausehost_shadercreates the host device (and runs the probe) before translating — ordering is correct, though it does meanvictory translatenow creates a D3D12 device (WARP or GPU) even when invoked only for cache warming; worth a line in the PR description since translate previously did not need a device.OnceLockin emit is set-once: any translation that readsheap_views()beforehost::createprobes locks in 2M.host_shadercovers the run/cache paths; anything else translating first (e.g. a future call site) would silently disable the fix. A debug_assert or a comment at everyheap_views()producer might help future contributors not break the ordering.pairs_end/null views moved belowheap_views()correctly; on a capped heap pairs still get room past the dynamic range since the heap is exactly 1M.Tests on NVIDIA: the 3
victory-shaderfailures you list are pre-existing environment assumptions, same class asvictory-gpu'sdynamic_slots_are_held_until_released/lists_share_a_table.../a_texture_written_in_one_format...which also fail on any heap-capped host — worth a separate test PR, not a blocker here.@sinan-cmyk on GitHub · 2026-11-25 07:52 UTC · original
Offline measurement on a retail dump
Result: no count change against
main.I merged head 4d91d9d2 onto
main940d32f(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 23,918 onmain, 23,918 with this PR.No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.
No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@thedanmaor on GitHub · 2026-11-25 12:05 UTC · original
Update (8d5eaaa): the heap cap from 4d91d9d never took effect.
use_shader_cachehashedheap_views()before the host was created, which locked the OnceLock at 2M, so the 1M heap was never created on the GTX 1660. The host is now created first. Log check:host view heap capped at 1000000 count=1245184 kept=934461.Result: the MMU fault (nvlddmkm event 13) is gone.
Still open, and separate from this: with the heap in place the title renders far more, and about 10 s in the device is removed with DXGI_ERROR_INVALID_CALL (0x887A0001). DRED breadcrumbs are empty, and turning off depth twins doesn't change it. Diagnosing it needs the D3D12 debug layer (Graphics Tools), which this machine doesn't have.
Pre-existing, not from this PR: 3 victory-shader hardware tests fail on this GPU (stride_tests x2, synthetic gathers). The test host in emit/host.rs still uses the 2M
HEAP_VIEWS.🤖 Generated with Claude Code
https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
@thedanmaor on GitHub · 2026-11-25 12:30 UTC · original
GTX 1660 Super (6 GB): what is left after the heap cap
The heap cap fixes the MMU fault. The title now runs about 10 s on hardware, then the device is removed with
DXGI_ERROR_INVALID_CALL(0x887A0001). DRED has no breadcrumbs, and the debug layer is not installed.Cause: local VRAM overcommit. I polled
IDXGIAdapter3::QueryVideoMemoryInfoevery 50 ms during a run (--console series-x):--console series-swas removed once at 2.5 GB used (sampled every 0.5 s, so a short spike may have been missed). The next run crashed on startup instead, so this is still open.Fix options (not in this PR):
SetResidencyPriority/MakeResident/Evictor D3D12MA-style budgeting.Other findings
E_INVALIDARG, on hardware and on WARP (430+), with or without the cap. This predates this PR and leaves most dispatches unrun.a_heap_buffer_read_by_element_takes_the_views_stridegathers_at_a_level_match_the_hardwareStructureByteStride > 0, kept as-is bybuffer_srv). That handle/descriptor mismatch is undefined behaviour. WARP tolerates it; NVIDIA does not.a_heap_buffer_read_where_no_buffer_view_is_reads_zerosneeds a 2^21-slot heap. NVIDIA caps heaps at 10^6, so the test now skips hardware where the heap is refused (9252c34).🤖 Generated with Claude Code
https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
@Marvisak on GitHub · 2026-11-25 13:28 UTC · original · edited 2026-11-26 00:15 UTC
Automated triage for the maintainers.
This pull request conflicts with
main(conflicting files:crates/victory-gpu/src/descriptor/host.rs). It will be reviewed once it is rebased ontomain.Generated by Claude Code
@devilbytes on GitHub · 2026-11-25 14:36 UTC · original
Test report on NVIDIA: which part of this PR fixes which test (for the split the triage asks for)
Tested on: NVIDIA GeForce RTX 5060 8 GB, driver 616.56 (32.0.16.1656); AMD Ryzen 7 9700X; Windows 11 Pro 26300; rustc 1.98.1 (msvc). Base: main
940d32f. Each row iscargo test --workspace --no-fail-faston that commit, with nothing changed locally.On main, 5 tests fail on this card:
940d32fWhat this shows:
hardware view heaps stop below HEAP_VIEWS; skipped). It does not run on this card. #2461 gives the same result as the heap-cap commits.a_heap_buffer_read_by_element_takes_the_views_strideandgathers_at_a_level_match_the_hardware. Without it they fail the same way on both 9252c34 and #2461. The stride test reads[101, 104, 107, ...](stride 3) and then zeros, where[200, 201, 202, ...]is expected:So if the PR is split, the heap-cap part alone leaves two NVIDIA failures, and the raw-view part is the one that fixes them. These are test-suite results only. I did not run the title.
@xiaotu030202 on GitHub · 2026-11-25 15:35 UTC · original
A third data point for the ceiling this PR is built on. I closed #2315 (my own patch for the same mismatch) after the triage there showed it turned a clamp into a refusal; this PR's runtime probe is the shape that works, so the measurement belongs here instead of in a diff.
Direct
CreateDescriptorHeapon an RTX 5070 Ti, driver 32.0.16.2140, Windows 11 22631Shader-visible CBV/SRV/UAV, one heap per size, no debug layer:
1,000,000 is exact and it is a hard wall — 1,000,000 succeeds, 1,048,576 does not, and the failure is
E_OUTOFMEMORYrather thanE_INVALIDARG. That distinction may matter for how you detect it: @Dathinel's run on an RTX 3050 with the debug layer on gotE_INVALIDARGinstead, with the layer naming "the limit for shader visible view heaps is 1000000". So the code is not stable across debug-layer state on the same class of hardware — worth treating "the heap did not fit" as any failure fromCreateDescriptorHeap, not as one specificHRESULT.The sampler ceiling is a different number entirely: 2,048 takes, 4,096 does not. If
indexed_slots()feeds the sampler path too, that one is not 1,000,000.The two-sided table, from the closed PR
For the invariant "the bound must not exceed the slots the heap actually got", both directions are violated on
main:new(false, 4)new(false, 1_245_184)main(my machine, RTX 5070 Ti)main(@Dathinel, RTX 3050)main(WARP Tier 3, @andrewpozdnakov7-jpg)NoneThe
Nonerow is why I closed it: a title declaring 1,236,191 slots (#2185's figure) got no view heap at all wheremaincaps at 1,000,000. A fixed constant cannot satisfy the invariant in both directions because the slot count is a property of the driver and the binding tier — which is the argument for what this PR does.What I did not test
A shader reading past the cap on any head — same gap @Dathinel reported. My numbers are all
CreateDescriptorHeap; I never ran the device-removal case end to end, and that is the consequence that actually matters.@Dathinel on GitHub · 2026-11-25 16:53 UTC · original
Follow-up to the error-code question above: I reran the direct
CreateDescriptorHeapprobe on the RTX 3050 Laptop (driver 610.62, Windows 11 26200, binding tier 3) without the debug layer (victory-gpubuilt withoutdiagnostics; the probe prints that the device has noID3D12InfoQueue), onmain67e8ae1.So on this card the code is
E_INVALIDARGwith and without the layer; theE_OUTOFMEMORYon the RTX 5070 Ti is a driver or generation difference, not a debug-layer one. The conclusion for the probe stands either way: treat any failure of the large heap as "did not fit" rather than matching one HRESULT. The ceiling itself is the same, exactly 1,000,000.AI-assisted; synthetic probe only.
@thedanmaor on GitHub · 2026-11-25 20:25 UTC · original
Rebased onto main
13f91ca(head3417025). Conflicts indescriptor/host.rs,draw.rs,emit/mod.rsand README resolved. Upstream's 16-byte-per-slot view-address table is now sized byindexed_slots()too (indexed_slots(count) * 16).cargo test -p victory-gpu -p victory-shaderpasses, clippy is clean,xtask policyis ok.Review points:
CreateDescriptorHeapfailure counts as "did not fit" (@xiaotu030202, @Dathinel). The probe already matchedErr(_), not one HRESULT. A comment now says so.indexed_slots(). Strides and marks are view-heap only (!sampler), and the sampler heap is stillcount.max(HEAP_SAMPLERS)withHEAP_SAMPLERS = 2048, matching the ceiling you measured.heap_views()ordering (@kotekompotek). There is now a doc note onheap_views()and a comment at the probe: the first read locks the value, so the host must probe before any translation or cache key. A lateset_heap_viewsis still logged as an error. I left out adebug_assert, because tests that translate before creating a host would panic on capped hardware.translatenow creates a D3D12 device. This is noted in the PR description.🤖 Generated with Claude Code
https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.