Skip to content

fix: clamp shader heap indices to the host's view-heap cap (NVIDIA) - #2185

Open
thedanmaor wants to merge 5 commits into
Marvisak:mainfrom
DID-Software-Solutions:fix/nvidia-heap-clamp
Open

thedanmaor wants to merge 5 commits into
Marvisak:mainfrom
DID-Software-Solutions:fix/nvidia-heap-clamp

Conversation

@thedanmaor

Copy link
Copy Markdown

Problem

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 heap warnings), and translated shaders clamp only below HEAP_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::create probes a HEAP_VIEWS shader-visible heap. Where it is refused, emit::set_heap_views(PORTABLE_VIEWS) sets the clamp to the cap.
  • heap_handle and buffer_guard clamp below emit::heap_views(), and the null buffer views move to emit::null_buffer_view() (the cap's last slots).
  • descriptor::host: on a capped host, the heap is views slots. Title slots come first, then MIN_DYNAMIC dynamic 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_shader creates the host device first, so the probe runs before any translation.
  • README: a note about NVIDIA.

Hosts that take a 2^21 heap (AMD) are unchanged.

Checks

  • Release build and clippy are clean.
  • victory-gpu lib tests: 143 pass. The shader-cache key test now covers the heap size.
  • victory-shader lib tests: 244 pass. 3 fail on an NVIDIA machine (stride_tests ×2 need a 2^21 heap; gathers_at_a_level_match_the_hardware). They fail the same way on main.
  • Not yet confirmed in a live world run on NVIDIA.

🤖 Generated with Claude Code

NVIDIA caps shader-visible CBV/SRV/UAV heaps at 10^6 slots; the world
indexes past that (slot 1,236,191 and up), and with shaders clamping only
below HEAP_VIEWS (2^21) the device was removed (DXGI_ERROR_INVALID_CALL).

The host probes a HEAP_VIEWS heap at device creation; where it is refused,
emit::set_heap_views(PORTABLE_VIEWS) makes translated shaders clamp below
the cap and put the null buffer views at its last slots. The capped host
heap keeps the title slots below the dynamic range; title slots past it
read null. The heap size keys the shader cache and the pipeline library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu — 143 passed, 0 failed (2 ignored) on NVIDIA RTX 5090 (resolves both 1M view-heap cap failures on main 940d32f)
  • cargo clippy -p victory-gpu -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean clamping of shader heap indices to the host's view-heap cap with cache-key inclusion. (Note for triage: overlaps #2177 and #2121 on the NVIDIA 1M view-heap cap.)

AI-assisted (Gemini 4 Neon).

@kotekompotek

Copy link
Copy Markdown

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 --cache on NVIDIA keys entries under the 1M clamp because host_shader creates the host device (and runs the probe) before translating — ordering is correct, though it does mean victory translate now 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.
  • The OnceLock in emit is set-once: any translation that reads heap_views() before host::create probes locks in 2M. host_shader covers 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 every heap_views() producer might help future contributors not break the ordering.
  • pairs_end/null views moved below heap_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-shader failures you list are pre-existing environment assumptions, same class as victory-gpu's dynamic_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

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 4d91d9d onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. Shader heap indices clamped to the host's view-heap cap — bounds safety for heap indexing; mixed docs+gpu+shader.

use_shader_cache hashed heap_views() before the host was made, so the
OnceLock locked at HEAP_VIEWS (2M) and the GTX 1660's 1M cap never took:
no shader-visible view heap, and shaders indexed past it (MMU fault,
nvlddmkm event 13). Make the host first; set_heap_views now reports
whether the cap applied, and the host logs if it came too late.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
@thedanmaor

Copy link
Copy Markdown
Author

Update (8d5eaaa): the heap cap from 4d91d9d never took effect. use_shader_cache hashed heap_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

…op below HEAP_VIEWS

NVIDIA caps shader-visible view heaps at 10^6 slots; the test host's
View::NullBuffers needs HEAP_VIEWS (2^21), so the hardware run failed
with E_INVALIDARG instead of testing anything. WARP still runs it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
@thedanmaor

Copy link
Copy Markdown
Author

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::QueryVideoMemoryInfo every 50 ms during a run (--console series-x):

TEMPBUDGET local 4989/4817 MB ...
TEMPBUDGET local 4989/4865 MB nonlocal 1836/48286 MB
host GPU device removed after a submission of 1 lists
  • Usage climbs from 1.8 GB to 5 GB within 10 s. That is above the OS budget, with no eviction.
  • Under WARP the same scene holds about 4.6 GB of host textures: 1527 of them, many 3840x2160.
  • The heap cap is not the cause. On WARP with a hardware-identical cap (forced), the title ran 2.5 min without removal.
  • --console series-s was 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):

  • Residency management, via SetResidencyPriority / MakeResident / Evict or D3D12MA-style budgeting.
  • Free released title textures sooner. One log line: "a title texture was released while a list not yet reset names its host copy".
  • Report a clear error when over budget.

Other findings

  • 89 compute pipelines are refused on every run with E_INVALIDARG, on hardware and on WARP (430+), with or without the cap. This predates this PR and leaves most dispatches unrun.
  • Two victory-shader tests fail on NVIDIA only:
    • a_heap_buffer_read_by_element_takes_the_views_stride
    • gathers_at_a_level_match_the_hardware
    • Cause: the emitter reads heap-indexed buffers through raw-buffer handles, but the host heap holds the title's structured views (StructureByteStride > 0, kept as-is by buffer_srv). That handle/descriptor mismatch is undefined behaviour. WARP tolerates it; NVIDIA does not.
    • With the test views switched to raw, both tests pass on the 1660. This is a real runtime bug for titles that read structured buffers by heap index. It needs either raw host views (16-byte aligned starts) or structured handles in the emitter. Out of scope here.
  • a_heap_buffer_read_where_no_buffer_view_is_reads_zeros needs 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

222dmx222 and others added 2 commits November 25, 2026 14:55
Translated shaders read every structured buffer through a raw handle at
index * stride + offset. NVIDIA reads a structured view through a raw
handle wrongly. So structured views with a stride that is a multiple of 4
are now made as R32_TYPELESS raw views, with their range scaled to
4-byte words. Their host copy starts on 16 bytes, which is the raw-view
alignment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
…oval)

The GTX 1660 has no typed UAV support for B5G5R5A1_UNORM (86).
CreateUnorderedAccessView on an 86 texture removed the device with
DXGI_ERROR_INVALID_CALL about 8 s into the title. Only cross-family casts
were checked. Now every unordered view's final format is checked: the
title's format, or the texture's own. If the host cannot store to it, the
slot stays null.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YN3qACnpWeybNLkKL5h5jr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants