Shaders: a root view read by index drops lanes whose index is out of range #3670

Open
ZeOs360 wants to merge 1 commit from upstream-pr/3670 into main
ZeOs360 commented 2026-11-28 05:10:34 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ZeOs360 on 2026-11-28T05:10:34Z.


What

A buffer descriptor that a program builds around a root SRV or UAV with idxen (num_records -1)
was translated as root address + index × stride, with no range check. With OOB_SELECT 0 or 1 (V#
dword 3 bits 28-29) the console checks the index against num_records first. An index of -1 is
therefore out of range there:

  • a store is dropped;
  • an atomic does nothing and returns 0;
  • a load reads 0.

The ray-tracing builder's pass 5552dac6a2b7a1fd stores through such indices (#3486): idxen
stores at 0x14cc, 0x1834, 0x1d3c and 0x213c, stride 4. Here the index wrapped to the record before
the root address instead. In a program that uses title memory, the 32-bit offset (-stride) went onto
the 48-bit root address, so that address is one stride short of 4 GiB past the root
(off=0xfffffffc in #3486). That region was then marked missed.

This PR adds the check in the root-view idxen arm of Lower::buffer:

  • lanes out of range leave the access's guard (stores, atomics, the title-memory marking);
  • their loaded dwords and atomic results are 0;
  • lanes outside the guard keep their registers as before.

Not covered:

  • modes 2 and 3 do not check the index and are unchanged;
  • mode 0's other check (offset ≥ stride) is still left out, marked shortcut:;
  • ADD_TID_ENABLE (dword 3 bit 23) is still not looked at in this arm (as before);
  • accesses with offen are not affected, such as that pass's atomic at 0x70c, which also reached
    off=0xfffffffc in some runs.

Other buffer accesses get no new code, and neither does a constant index in range. The modes follow
Mesa's GFX10 description (ac_descriptors.c: 0 = index ≥ NUM_RECORDS or offset ≥ STRIDE, 1 = index
≥ NUM_RECORDS, 2 = NUM_RECORDS = 0, 3 = offset ≥ NUM_RECORDS).

Tests

emit::memory_tests::root_views_by_index_drop_lanes_out_of_range: 32 lanes, index = lane − 1 (lane 0
at -1), a root UAV with stride 16, run through the host's view of a root UAV's copy and as title
memory:

  • a store, an atomic add with glc, and a load (into a register set to 0xdead first), with OOB_SELECT 1;
  • a store with OOB_SELECT 0;
  • through the copy only, a store with OOB_SELECT 3, which is not checked;
  • lane 2 outside the atomic's EXEC guard keeps its register.

It passes on an RX 7800 XT and on WARP, and failed before the change:

  • through the copy, lane 0 returned and loaded the record before the root;
  • as title memory, it marked a region past the root.

In-game (RX 7800 XT, with ray tracing through the open RT PRs #2098 #2118 #2703 #2841 #2810 #2501 on
top, 10-minute runs, counted with a local diagnostic that logs missed title-memory writes):

  • The pass's missed-write sites at off=0xfffffffc from those four stores went from 6, 8, 6 and 5 in
    four runs without this change to 0 with it.
  • The run with it still had the other 4 GiB writes of #3486 (46 sites), so the builder ran as before.
    Those come from a wave64 lane mask; #3023 (with #2836's change) fixes the ones that start early.
  • With that change, off=0xfffffffc sites were 0 in three runs (one ended at 5 minutes at a known
    title fault).
  • A later burst in a fourth run had 3: two at other idxen stores of the same pass (0x2e8c, 0x3198),
    which this check covers, and one at the pass's offen atomic (offset -4, not an index), which it
    does not.

So the check still matters there, and for any program that accesses index -1.

trustno1-coder/VIctory-NVIDIA#690 (@Machad3x) runs the same check (for OOB_SELECT 1) in their tree.

AI-assisted: written by Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon;
the GPU tests and in-game runs were made on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5536924305 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3670). Originally posted by [ZeOs360](https://github.com/ZeOs360) on 2026-11-28T05:10:34Z. --- ## What A buffer descriptor that a program builds around a root SRV or UAV with `idxen` (num_records -1) was translated as root address + index × stride, with no range check. With OOB_SELECT 0 or 1 (V# dword 3 bits 28-29) the console checks the index against num_records first. An index of -1 is therefore out of range there: - a store is dropped; - an atomic does nothing and returns 0; - a load reads 0. The ray-tracing builder's pass `5552dac6a2b7a1fd` stores through such indices (#3486): `idxen` stores at 0x14cc, 0x1834, 0x1d3c and 0x213c, stride 4. Here the index wrapped to the record before the root address instead. In a program that uses title memory, the 32-bit offset (-stride) went onto the 48-bit root address, so that address is one stride short of 4 GiB past the root (`off=0xfffffffc` in #3486). That region was then marked missed. This PR adds the check in the root-view `idxen` arm of `Lower::buffer`: - lanes out of range leave the access's guard (stores, atomics, the title-memory marking); - their loaded dwords and atomic results are 0; - lanes outside the guard keep their registers as before. Not covered: - modes 2 and 3 do not check the index and are unchanged; - mode 0's other check (offset ≥ stride) is still left out, marked `shortcut:`; - ADD_TID_ENABLE (dword 3 bit 23) is still not looked at in this arm (as before); - accesses with `offen` are not affected, such as that pass's atomic at 0x70c, which also reached `off=0xfffffffc` in some runs. Other buffer accesses get no new code, and neither does a constant index in range. The modes follow Mesa's GFX10 description (`ac_descriptors.c`: 0 = index ≥ NUM_RECORDS or offset ≥ STRIDE, 1 = index ≥ NUM_RECORDS, 2 = NUM_RECORDS = 0, 3 = offset ≥ NUM_RECORDS). ## Tests `emit::memory_tests::root_views_by_index_drop_lanes_out_of_range`: 32 lanes, index = lane − 1 (lane 0 at -1), a root UAV with stride 16, run through the host's view of a root UAV's copy and as title memory: - a store, an atomic add with glc, and a load (into a register set to 0xdead first), with OOB_SELECT 1; - a store with OOB_SELECT 0; - through the copy only, a store with OOB_SELECT 3, which is not checked; - lane 2 outside the atomic's EXEC guard keeps its register. It passes on an RX 7800 XT and on WARP, and failed before the change: - through the copy, lane 0 returned and loaded the record before the root; - as title memory, it marked a region past the root. In-game (RX 7800 XT, with ray tracing through the open RT PRs #2098 #2118 #2703 #2841 #2810 #2501 on top, 10-minute runs, counted with a local diagnostic that logs missed title-memory writes): - The pass's missed-write sites at `off=0xfffffffc` from those four stores went from 6, 8, 6 and 5 in four runs without this change to 0 with it. - The run with it still had the other 4 GiB writes of #3486 (46 sites), so the builder ran as before. Those come from a wave64 lane mask; #3023 (with #2836's change) fixes the ones that start early. - With that change, `off=0xfffffffc` sites were 0 in three runs (one ended at 5 minutes at a known title fault). - A later burst in a fourth run had 3: two at other `idxen` stores of the same pass (0x2e8c, 0x3198), which this check covers, and one at the pass's `offen` atomic (offset -4, not an index), which it does not. So the check still matters there, and for any program that accesses index -1. trustno1-coder/VIctory-NVIDIA#690 (@Machad3x) runs the same check (for OOB_SELECT 1) in their tree. AI-assisted: written by Claude Code (Claude Opus 5.5) and reviewed by Gemini 4 Neon; the GPU tests and in-game runs were made on my machine.
ColorMeBoom commented 2026-11-28 07:07:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T07:07:13Z.


Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head 72d31b7 on 63bcca4.

  • root_views_by_index_drop_lanes_out_of_range passes on the hardware adapter and on WARP; neither was skipped.
  • Full victory-shader --lib --features host: 303 passed, 0 failed, 3 ignored.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7235728501 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3670#issuecomment-7235728501). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T07:07:13Z. --- Hardware run: RX 5700 XT (Navi 10, RDNA1, 32–64 lanes, driver 32.0.21045.29003, Windows 11 26200), head `72d31b7` on `63bcca4`. - `root_views_by_index_drop_lanes_out_of_range` passes on the hardware adapter and on WARP; neither was skipped. - Full `victory-shader --lib --features host`: 303 passed, 0 failed, 3 ignored. AI use: Claude Code (Claude Opus 5.5).
upipibi commented 2026-11-28 08:45:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-28T08:45:40Z.


NVIDIA row for this PR: it passes on Ampere.

RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head 72d31b7 on main 63bcca4 (fast-forward, clean).

  • root_views_by_index_drop_lanes_out_of_range: 1 passed, 0 failed, in 3 of 3 runs. It ran on both the hardware adapter and WARP: no "skipped" line.

  • cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index:

    • this PR: 299 passed, 3 failed, 3 ignored;
    • main 63bcca4: 298 passed, 3 failed, 3 ignored.

    The 3 failures are the same on both: stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride, stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and synthetic_tests::gathers_at_a_level_match_the_hardware. The skipped test crashes the binary on this card on both trees (0xc0000005, open issue #2571).

Not tested: a title run.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7236792083 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3670#issuecomment-7236792083). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-28T08:45:40Z. --- NVIDIA row for this PR: it passes on Ampere. RTX 3070 (desktop), driver 616.56, Windows 11 Pro 10.0.26100, debug. Head `72d31b7` on main `63bcca4` (fast-forward, clean). - `root_views_by_index_drop_lanes_out_of_range`: 1 passed, 0 failed, in 3 of 3 runs. It ran on both the hardware adapter and WARP: no "skipped" line. - `cargo test --locked -p victory-shader --lib -- --skip heap_direct_texture_reads_mark_their_heap_index`: - this PR: 299 passed, 3 failed, 3 ignored; - main `63bcca4`: 298 passed, 3 failed, 3 ignored. The 3 failures are the same on both: `stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride`, `stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros` and `synthetic_tests::gathers_at_a_level_match_the_hardware`. The skipped test crashes the binary on this card on both trees (`0xc0000005`, open issue #2571). Not tested: a title run. AI-assisted (Claude Code, Claude Opus 5.5).
pickles976 commented 2026-11-28 14:10:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-28T14:10:06Z.


Verified on physical RTX 4060 Laptop (8 GiB), NVIDIA 590.48.1, Linux 6.17 / Wine 11, 16 GiB system RAM.

Exact production head 72d31b7f563d9de79cca0e151283c97d27a82f71: root_views_by_index_drop_lanes_out_of_range passes 1/1, with both copy-backed and title-memory GPU dispatch/readback paths. Test-only strengthening requires the SDK DXIL validator and an actual NVIDIA adapter; the WARP-requested duplicate was excluded because Wine maps it to hardware here. No optional-device skip. Fresh intended-worktree compilation: 6.18 s; test: 1.38 s.

Also ran the same synthetic instructions/assertions on our existing dirty runtime integration (base 3ed7d725f6895fe1a235eb6fa8ff2485261ca151, including updated #2633 and prior disclosed memory/rendering fixes). Before your production change: 0/1 FAIL, copy-backed atomic returns and loads begins [4109,4110,...] rather than [0,0,...]. It stops at that first assertion, so this is not a separately observed title-memory-path failure. The test port only adds the current API's host_wave32: true field for this actual 32-lane host; it does not force a Wave64 title program to Wave32.

After porting only this PR's lower.rs correction into that same integration: 3/3 pass (root_views plus writes_through_views_mark_their_pages), including both paths of the new regression. Fresh compile 7.36 s, tests 2.21 s. Existing root descriptor addressing and GPU page-write marking remain covered. Peak sampled GPU use 175 MiB, minimum available RAM 10,716 MiB; external guards unchanged.

Important limits: these are synthetic shader dispatch/readbacks, not execution of the original BVH shader, a title run, or proof this fixes our NVIDIA Xid109 context-switch timeout. OOB_SELECT=0 offset-vs-stride and ADD_TID_ENABLE limitations remain as documented in the PR. The before/after integration is not a clean main comparison.

All GPU runs use the disclosed diagnostic vkd3d-proton 2576c0b4adfae4a+ build (relaxed XCL native-vtable assertions), DXVK NVIDIA masking disabled; not stock-vkd3d certification.

Reproduction: cargo test --locked --target x86_64-pc-windows-msvc -p victory-shader --lib -- root_views writes_through_views_mark_their_pages --nocapture --test-threads=1 through our Wine wrapper. Exact-head invocation selected only the new regression.

Local evidence:

  • verify-pr3670-root-index-nvidia-20261128T140605Z/
  • verify-mixed-root-index-control-20261128T140721Z/
  • verify-mixed-pr3670-root-bounds-20261128T140810Z/

No title assets or shader dumps attached. AI-assisted verification using OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7240466938 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3670#issuecomment-7240466938). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-28T14:10:06Z. --- Verified on physical RTX 4060 Laptop (8 GiB), NVIDIA 590.48.1, Linux 6.17 / Wine 11, 16 GiB system RAM. Exact production head `72d31b7f563d9de79cca0e151283c97d27a82f71`: `root_views_by_index_drop_lanes_out_of_range` passes 1/1, with both copy-backed and title-memory GPU dispatch/readback paths. Test-only strengthening requires the SDK DXIL validator and an actual NVIDIA adapter; the WARP-requested duplicate was excluded because Wine maps it to hardware here. No optional-device skip. Fresh intended-worktree compilation: 6.18 s; test: 1.38 s. Also ran the same synthetic instructions/assertions on our existing dirty runtime integration (base `3ed7d725f6895fe1a235eb6fa8ff2485261ca151`, including updated #2633 and prior disclosed memory/rendering fixes). Before your production change: 0/1 FAIL, copy-backed `atomic returns and loads` begins `[4109,4110,...]` rather than `[0,0,...]`. It stops at that first assertion, so this is not a separately observed title-memory-path failure. The test port only adds the current API's `host_wave32: true` field for this actual 32-lane host; it does not force a Wave64 title program to Wave32. After porting only this PR's `lower.rs` correction into that same integration: 3/3 pass (`root_views` plus `writes_through_views_mark_their_pages`), including both paths of the new regression. Fresh compile 7.36 s, tests 2.21 s. Existing root descriptor addressing and GPU page-write marking remain covered. Peak sampled GPU use 175 MiB, minimum available RAM 10,716 MiB; external guards unchanged. Important limits: these are synthetic shader dispatch/readbacks, not execution of the original BVH shader, a title run, or proof this fixes our NVIDIA Xid109 context-switch timeout. OOB_SELECT=0 offset-vs-stride and ADD_TID_ENABLE limitations remain as documented in the PR. The before/after integration is not a clean main comparison. All GPU runs use the disclosed diagnostic vkd3d-proton `2576c0b4adfae4a+` build (relaxed XCL native-vtable assertions), DXVK NVIDIA masking disabled; not stock-vkd3d certification. Reproduction: `cargo test --locked --target x86_64-pc-windows-msvc -p victory-shader --lib -- root_views writes_through_views_mark_their_pages --nocapture --test-threads=1` through our Wine wrapper. Exact-head invocation selected only the new regression. Local evidence: - `verify-pr3670-root-index-nvidia-20261128T140605Z/` - `verify-mixed-root-index-control-20261128T140721Z/` - `verify-mixed-pr3670-root-bounds-20261128T140810Z/` No title assets or shader dumps attached. AI-assisted verification using OpenAI Codex.
kilolimaVI commented 2026-11-28 21:55:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-28T21:55:58Z.


AMD Radeon 780M (RDNA3) + WARP, Windows 11, head 72d31b7. Before (main 63bcca4 + this PR's test): fails on the hardware adapter, lanes 0-1 return 4109 and 4110 where 0 is expected ("title memory false: atomic returns and loads"), the other 63 lanes match. After: passes, 5 of 5 runs. Full suite: 552 passed. AI-assisted (Claude).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246376994 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3670#issuecomment-7246376994). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-28T21:55:58Z. --- AMD Radeon 780M (RDNA3) + WARP, Windows 11, head `72d31b7`. Before (main `63bcca4` + this PR's test): fails on the hardware adapter, lanes 0-1 return 4109 and 4110 where 0 is expected ("title memory false: atomic returns and loads"), the other 63 lanes match. After: passes, 5 of 5 runs. Full suite: 552 passed. AI-assisted (Claude).
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/3670:upstream-pr/3670'
git switch 'upstream-pr/3670'

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/3670'
git switch 'upstream-pr/3670'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3670'
git switch 'upstream-pr/3670'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3670'
git switch 'main'
git merge --squash 'upstream-pr/3670'
git switch 'main'
git merge --ff-only 'upstream-pr/3670'
git switch 'main'
git merge 'upstream-pr/3670'
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!3670
No description provided.