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

Open
github-bot wants to merge 1 commit from github-bot/gh-3476 into main AGit
Owner

@⁠Koaio on GitHub · 2026-11-27 06:17 UTC · original
Koaio:fix/nvidia-view-heap-cap → main · +117 −45 · 7 files · 1 commits · open

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.

**@⁠Koaio** on GitHub · 2026-11-27 06:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3476) `Koaio:fix/nvidia-view-heap-cap` → `main` · +117 −45 · 7 files · 1 commits · open 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.
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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 06:23:14 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-27 06:48 UTC · original

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).

**@⁠oni-swr** on GitHub · 2026-11-27 06:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/3476#issuecomment-7211865413) **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).
Author
Owner

@⁠AurumCarlos on GitHub · 2026-11-27 08:34 UTC · original · reviewed

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.
**@⁠AurumCarlos** on GitHub · 2026-11-27 08:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/3476#pullrequestreview-6085442511) · **reviewed** 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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3476/head:github-bot/gh-3476'
git switch 'github-bot/gh-3476'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3476'
git switch 'github-bot/gh-3476'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3476'
git switch 'github-bot/gh-3476'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3476'
git switch 'main'
git merge --squash 'github-bot/gh-3476'
git switch 'main'
git merge --ff-only 'github-bot/gh-3476'
git switch 'main'
git merge 'github-bot/gh-3476'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3476
No description provided.