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

Open
Koaio wants to merge 1 commit from upstream-pr/3476 into main
Koaio commented 2026-11-27 06:17:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Koaio on 2026-11-27T06:17:58Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5522203623 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3476). Originally posted by [Koaio](https://github.com/Koaio) on 2026-11-27T06:17:58Z. --- 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.
oni-swr commented 2026-11-27 06:48:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-27T06:48:30Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7211865413 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3476#issuecomment-7211865413). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-27T06:48:30Z. --- **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 commented 2026-11-27 08:34:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by AurumCarlos on 2026-11-27T08:34:27Z.

Review: COMMENTED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6085442511 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3476#pullrequestreview-6085442511). Originally posted by [AurumCarlos](https://github.com/AurumCarlos) on 2026-11-27T08:34:27Z. **Review:** COMMENTED --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3476:upstream-pr/3476'
git switch 'upstream-pr/3476'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3476'
git switch 'upstream-pr/3476'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3476'
git switch 'upstream-pr/3476'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3476'
git switch 'main'
git merge --squash 'upstream-pr/3476'
git switch 'main'
git merge --ff-only 'upstream-pr/3476'
git switch 'main'
git merge 'upstream-pr/3476'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!3476
No description provided.