Skip to content

GPU: clamp view-heap indices below what the host device takes (#3330) - #3476

Open
Koaio wants to merge 1 commit into
Marvisak:mainfrom
Koaio:fix/nvidia-view-heap-cap
Open

Koaio wants to merge 1 commit into
Marvisak:mainfrom
Koaio:fix/nvidia-view-heap-cap

Conversation

@Koaio

@Koaio Koaio commented Nov 27, 2026

Copy link
Copy Markdown

NVIDIA caps shader-visible view heaps at 10^6 slots, while translated shaders clamped their indices below HEAP_VIEWS (2^21): an index past the capped heap hung the device on entering the world.

The host device is probed at creation for a heap of HEAP_VIEWS; where it refuses one, shaders clamp below PORTABLE_HEAP_VIEWS (10^6) instead. The limit is part of the shader cache key. A capped heap keeps its last slots for the null buffer views and the clamped index, and a fallback heap is never smaller than the limit shaders index. Hosts that take 2^21 slots (AMD) are unchanged.

…ak#3330)

NVIDIA caps shader-visible view heaps at 10^6 slots, while translated
shaders clamped their indices below HEAP_VIEWS (2^21): an index past the
capped heap hung the device on entering the world.

The host device is probed at creation for a heap of HEAP_VIEWS; where it
refuses one, shaders clamp below PORTABLE_HEAP_VIEWS (10^6) instead. The
limit is part of the shader cache key. A capped heap keeps its last
slots for the null buffer views and the clamped index, and a fallback
heap is never smaller than the limit shaders index. Hosts that take
2^21 slots (AMD) are unchanged.

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

oni-swr commented Nov 27, 2026

Copy link
Copy Markdown

WARP test report (independent)

  • Setup: Windows 11, WARP software adapter (VICTORY_WARP=1, VICTORY_D3D12_WARP=1, victory-gpu with diagnostics), dxil.dll 10.0.26100 (Windows SDK). No physical GPU used.
  • Base: 63bcca4 (merge base on main). Head: 8fe7719f.
  • cargo test -p victory-shader -p victory-gpu:
victory-gpu victory-shader
base 246 pass / 0 fail / 1 ignored 298 pass / 4 fail / 3 ignored
head 246 pass / 0 fail / 1 ignored 298 pass / 4 fail / 3 ignored
  • New failures on head: none. The same 4 emit::synthetic_tests (lane-mask/permute/gather) fail on base and head under WARP, so they predate this PR. The changed the_key_covers_translator_encoding_and_settings and the heap tests pass.
  • Heap path: WARP's probe takes the full 2^21-slot heap (heap_views() = 2097152). So WARP covers only the uncapped path. The capped path (PORTABLE_HEAP_VIEWS, fallback heap branch) is not reached; doing so needs set_heap_views(1_000_000) before the first translation or a host that refuses the heap, so a test would need a code change.
  • Review:
    • The shader cache key includes the limit (key(..., heap_views()), with a test); host() runs first, so the value is set before hashing.
    • The fallback heap is max(count + MIN_DYNAMIC, views), so it is never below the limit.
    • Null views sit at views-2 (SRV) and views-3 (UAV), the clamp lands on views-1, and the capped branch limits title and dynamic slots to below views-3, so there is no collision.
    • Minor edge: if a heap succeeds with count + MIN_DYNAMIC between views-3 and views, the null views are skipped (null > count+extra fails) while shaders still read them, so they could land on a live slot. This needs about 10^6 title slots and is unlikely.

AI-assisted (Claude Sonnet 5.5).

@AurumCarlos AurumCarlos 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.

This is the same fix as #2461 (lhnizdo), which changes the same files and was marked a merge candidate after triage re-reviewed it on current main. Worth linking it and saying what this adds, or closing in its favour; several other open PRs target the same cap too (#2185, #2628, #2683…).

Two differences either way:

  1. The shader crate's test device isn't probed. set_heap_views is only called from victory_gpu::host::create. victory-shader's own create_device (emit/host.rs) never sets it, so in victory-shader tests heap_views() stays 2^21 and View::NullBuffers still asks for a 2^21-slot heap on NVIDIA; the stride/synthetic failures from #1835 stay. #2461 probes in that create_device as well.
  2. The new capped-heap comment only holds in the Err branch. With views at 10^6, make((count + MIN_DYNAMIC).max(views)) succeeds whenever count + MIN_DYNAMIC ≤ 10^6. A title heap of 934,462–934,464 slots then puts its last dynamic slots on 999,997–999,999 (null UAV, null SRV, clamp target), and the null > count + extra check skips writing the null views. Checking count + MIN_DYNAMIC > room before that make would cover it.

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.

3 participants