Shaders: isolate cross-half LDS storage at each Wave32 exchange site #246

Merged
Barbital11111 merged 1 commit from upstream-pr/246 into main 2026-11-29 08:16:59 +00:00
Barbital11111 commented 2026-11-27 20:05:42 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Barbital11111 on 2026-11-27T20:05:42Z.


What

On an RTX 5090 D v2, an earlier build based on d12eb1b2 showed hard-edged 16×16 black tiles on outdoor surfaces. CS_DepthProcessingHBO (2f03a2df10503cef) wrote an invalid 0xff classification byte. The downstream CS_ShadowTileClassify (9991e29feaa26e3e) tests bit 1 and can skip the tile when its exception condition is inactive, leaving the cleared shadow mask at zero. The full indirect dispatch path was not traced for every visible block.

When a logical wave64 runs as two host wave32s, the group-barrier path gives successive exchanges the same LDS words. In the isolated HBO dispatch, the OR reduction read the wrong upper-half value. Changing the final image store from float to integer left all 14,400 classifications unchanged, including the 32 bad tiles.

Change

Allocate group-shared storage per static exchange site and per logical wave: one dword for a lane broadcast, two for a pair of partial results. This covers ballots, reductions and prefix sums through the common exchange path. Loop iterations still reuse their own site. Sites that would exceed the 32 KiB group budget use the existing scratch pair. The separate counter-based, double-buffered pair-meeting path keeps its existing ordering. After dead-code elimination, remove unreferenced group-shared globals and remap the surviving references, as the optimizer already does for constant tables.

Evidence on the earlier builds

  • Isolating the bitwise reductions corrected all 32 bad tiles in an isolated GPU dispatch. The full 14,400-byte classification image matched the reference byte for byte. In live play with that first-stage fix on the d12eb1b2-based build, the outdoor blocks were substantially reduced. A few remained.
  • With only the bitwise sites isolated, a CPU test that deliberately delayed a read until after the next site's write found 72,000 mismatches in 115,200 checks. With all static sites isolated it found zero. Both versions passed the ordered schedule. The delayed schedule is fault injection across a barrier; it does not identify which GPU instruction supplied the wrong value in the original dispatch.

Verification on 0cef07e9

  • This port was built on Windows x64 against upstream commit 0cef07e9d7.
  • Both synthetic regression tests failed with the expected assertions on the original implementation and passed with this patch.
  • Shader library test summary: test result: ok. 290 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 297.01s
  • shader-tests PASS
  • shader-clippy PASS
  • ci-clippy reported the same failing tests or lint diagnostics on clean main
  • ci-clippy-features reported the same failing tests or lint diagnostics on clean main
  • other-libraries reported the same failing tests or lint diagnostics on clean main
  • The pinned upstream library translated all 160 local inputs. All 160 passed SDK DXIL validation. The HBO output had eight distinct exchange arrays, with 0/115,200 delayed-read mismatches in the CPU address check.
  • The CLI package and replay tests were excluded locally. The game was not run on this upstream port.

#43 analyzes aliasing between the guest's LDS accesses. #104 and #118 constrain out-of-bounds guest LDS accesses. This change isolates the translator's own scratch for valid exchanges. #42 changes shared-memory optimization and barrier deduplication; the emitted-address regression is worth rerunning if both changes land. #108 fixes the choice of mask dword for upper-half lanes, a separate source of incorrect values.

Prepared with Claude Code (coordination) and OpenAI Codex (implementation).
🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5532459114 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/246). Originally posted by [Barbital11111](https://github.com/Barbital11111) on 2026-11-27T20:05:42Z. --- <!-- PR title: Shaders: isolate cross-half LDS storage at each Wave32 exchange site --> ## What On an RTX 5090 D v2, an earlier build based on `d12eb1b2` showed hard-edged 16×16 black tiles on outdoor surfaces. `CS_DepthProcessingHBO` (`2f03a2df10503cef`) wrote an invalid `0xff` classification byte. The downstream `CS_ShadowTileClassify` (`9991e29feaa26e3e`) tests bit 1 and can skip the tile when its exception condition is inactive, leaving the cleared shadow mask at zero. The full indirect dispatch path was not traced for every visible block. When a logical wave64 runs as two host wave32s, the group-barrier path gives successive exchanges the same LDS words. In the isolated HBO dispatch, the OR reduction read the wrong upper-half value. Changing the final image store from float to integer left all 14,400 classifications unchanged, including the 32 bad tiles. ## Change Allocate group-shared storage per static exchange site and per logical wave: one dword for a lane broadcast, two for a pair of partial results. This covers ballots, reductions and prefix sums through the common exchange path. Loop iterations still reuse their own site. Sites that would exceed the 32 KiB group budget use the existing scratch pair. The separate counter-based, double-buffered pair-meeting path keeps its existing ordering. After dead-code elimination, remove unreferenced group-shared globals and remap the surviving references, as the optimizer already does for constant tables. ## Evidence on the earlier builds - Isolating the bitwise reductions corrected all 32 bad tiles in an isolated GPU dispatch. The full 14,400-byte classification image matched the reference byte for byte. In live play with that first-stage fix on the `d12eb1b2`-based build, the outdoor blocks were substantially reduced. A few remained. - With only the bitwise sites isolated, a CPU test that deliberately delayed a read until after the next site's write found 72,000 mismatches in 115,200 checks. With all static sites isolated it found zero. Both versions passed the ordered schedule. The delayed schedule is fault injection across a barrier; it does not identify which GPU instruction supplied the wrong value in the original dispatch. ## Verification on `0cef07e9` <!-- upstream-verification --> - This port was built on Windows x64 against upstream commit 0cef07e9d766df48f0e95f13ce3bbbe2290fe9d3. - Both synthetic regression tests failed with the expected assertions on the original implementation and passed with this patch. - Shader library test summary: test result: ok. 290 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 297.01s - shader-tests PASS - shader-clippy PASS - ci-clippy reported the same failing tests or lint diagnostics on clean main - ci-clippy-features reported the same failing tests or lint diagnostics on clean main - other-libraries reported the same failing tests or lint diagnostics on clean main - The pinned upstream library translated all 160 local inputs. All 160 passed SDK DXIL validation. The HBO output had eight distinct exchange arrays, with 0/115,200 delayed-read mismatches in the CPU address check. - The CLI package and replay tests were excluded locally. The game was not run on this upstream port. <!-- /upstream-verification --> ## Related work #43 analyzes aliasing between the guest's LDS accesses. #104 and #118 constrain out-of-bounds guest LDS accesses. This change isolates the translator's own scratch for valid exchanges. #42 changes shared-memory optimization and barrier deduplication; the emitted-address regression is worth rerunning if both changes land. #108 fixes the choice of mask dword for upper-half lanes, a separate source of incorrect values. Prepared with Claude Code (coordination) and OpenAI Codex (implementation). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upipibi commented 2026-11-28 22:00:34 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by upipibi on 2026-11-28T22:00:34Z.


Tested on Ampere: RTX 3070 (10de:2484), driver 616.56, native Windows 11 Pro 10.0.26100, rustc 1.98.1. Debug test profile. The system WARP is the one that ships with Windows. Wave sizes tested: 32 lanes only. This card reports WaveLaneCountMin/Max 32-32, so no 64-lane host ran.

  • Head 24133eecb, merged onto main d4b5d5170 (--no-ff, clean, no conflicts). The PR's base is 0cef07e9, 337 commits behind main. The merge changes the same four files by the same amounts as the PR: opt.rs +28/-7, lower.rs +30/-4, mod.rs +4/-2, wave64_tests.rs +50. The head was still 24133eecb and main still d4b5d5170 when I finished.

The PR's two tests fail on main's code and pass with the PR, on any adapter. Neither one opens a device. a_later_half_wave_exchange_preserves_an_earlier_unread_result lowers the program with the host wave pinned to 32 (TEST_HOST_WAVE), disassembles the DXIL with dxc -dumpbin, and replays the stores and loads on a CPU map. It runs no dispatch. only_reachable_exchange_arrays_survive_and_their_uses_are_remapped is an optimizer unit test. So the hardware and WARP runs below measure the same CPU code, and the card makes no difference to them.

I also dispatched the test's program on the 3070 with a temporary test, on the PR's code and on main's. The 3070 gives the right values with both. It does not reproduce the bug in a real dispatch of this program. See below.

The tests

cargo test -p victory-shader --lib --locked -- --nocapture --test-threads=1 a_later_half_wave_exchange_preserves_an_earlier_unread_result only_reachable_exchange_arrays_survive
VICTORY_WARP=1 cargo test ...   # same command
  • Default, 3 runs: 2 passed, 0 failed, 0 ignored each (0.02 to 0.03 s).
  • VICTORY_WARP=1, 3 runs: 2 passed, 0 failed, 0 ignored each (0.02 s).

The DXIL test does not skip here. It returns early and passes (printing no DXC disassembler) if dxc.exe is not found next to the newest SDK dxil.dll or at VICTORY_PC_DXC. That line was not printed in any run, because the Windows SDK 10.0.26100 dxc.exe was found. A runner without dxc would pass this test without checking anything.

Adapters seen

To check that the tests open no device, I added a temporary eprintln! at the top of Host::new and ran the two tests once with each setting. It printed nothing in either. A dispatch test (a_sum_of_halves_over_the_wave_is_the_consoles_tree_bit_for_bit) printed it, so the print worked. I removed it afterwards.

run device opened by the PR's tests
default none
VICTORY_WARP=1 none

The temporary dispatch test below opened these two adapters. It resolves device.GetAdapterLuid() through EnumAdapterByLuid and prints GetDesc1 and the D3D12_OPTIONS1 wave lane counts:

Host::new adapter vendor:device flags wave lanes
false NVIDIA GeForce RTX 3070 10de:2484 0x0 32-32
true Microsoft Basic Render Driver 1414:008c 0x2 (software) 4-4

Negative control A: main's lower.rs, PR's tests

git checkout d4b5d5170 -- crates/victory-shader/src/emit/lower.rs. This keeps the PR's opt.rs and mod.rs (dump_dxil has to be pub(super) for the test to build). It builds, with the same single warning as main.

  • Default, 3 runs: 1 passed, 1 failed, 0 ignored each.
  • VICTORY_WARP=1, 3 runs: 1 passed, 1 failed, 0 ignored each.

All six runs failed the same way, at wave64_tests.rs:269:

assertion `left == right` failed
  left: [31, 31, 31, 63]
 right: [5, 40, 31, 63]

On main's code, both lane broadcasts (v_readlane of lanes 5 and 40) and the reduction's low partial share one LDS word. The test writes all three sites before it reads any of them, so both broadcasts read the reduction's 31. The optimizer test passed in all six runs. It does not depend on lower.rs.

Negative control B: main's drop_unused_tables, PR's lower.rs

I reverse-applied the PR's two non-test opt.rs hunks (the call and the function body) and kept its test.

  • Default, 3 runs: 2 passed, 1 failed, 0 ignored each (the third test is the dispatch test below).
  • only_reachable_..._remapped panics at opt.rs:2867 with left: 2, right: 1: both globals survive. The DXIL test passes, and the program still passes DXIL validation.

A real dispatch on the 3070 (temporary test)

I appended a temporary test to wave64_tests.rs. It lowers the PR's program in the same way, validates the DXIL, and dispatches it in one group of 64 threads, 20 times per adapter. Each lane's expected record is [5, 40, 63, lane]: v_readlane of lanes 5 and 40, the wave OR of v0, then v0. I removed it before the lib suites.

code 3070 WARP
merge (PR's lower.rs) 3 runs x 20 dispatches: 0 wrong, lane 0 [5, 40, 63, 0], lane 63 [5, 40, 63, 63] PSO refused (The parameter is incorrect., a 4-lane adapter)
control A (main's lower.rs) 3 runs x 20 dispatches: 0 wrong, same values PSO refused
control B (main's opt.rs) 3 runs x 20 dispatches: 0 wrong PSO refused

So on this card and driver, main's shared exchange words give the right result for this program. The barriers between the sites keep each read ahead of the next write. That fits the description, which calls the delayed schedule fault injection and says it "does not identify which GPU instruction supplied the wrong value in the original dispatch". The 5090 D v2's HBO dispatch was not available to me, so this says nothing about that shader.

cargo test -p victory-shader --lib --locked (default, once each)

  • PR merged onto d4b5d5170: 350 passed, 0 failed, 8 ignored (320 s).
  • Plain main d4b5d5170: 348 passed, 0 failed, 8 ignored (314 s).
  • The two extra passes are the new tests. There were no failures.

The PR adds no compiler warnings. The one warning in both builds, unused colour, is main's (lower.rs:13896 on main, :13922 on the merge).

CI

gh pr checks 246: no checks reported on the branch. I did not run clippy. The PR has no comments or reviews yet.

Overlap

  • #1138's triage map lists #246 under "64-lane programs refused on 32-lane cards". This PR does not change which programs are refused. It changes the LDS words of exchanges that already lower.
  • I ran git merge-tree of #246 against the 61 other open PRs that change opt.rs, lower.rs, emit/mod.rs or wave64_tests.rs. Only #822 conflicts, at one site in lower.rs: the v_readlane exchange. #246 replaces exchange_pair(slot) with exchange_storage(self.cur, slot, 1) there. #822 adds an if self.local { return Err(...) } guard just before it. The conflict is mechanical; the guard and the new storage call can both stay.
  • #1537 (pair meetings) changes the counter-based pair-meeting path, which #246 leaves as it is. git merge-tree is clean.
  • #348 and #733 are clean in git merge-tree with #246.
  • No open PR in that set adds or removes drop_unused_tables, exchange_pair, or the new exchange storage.
  • The PRs named in the description's Related work (#43, #104, #118, #42, #108) appear to be upstream numbers (the port is against upstream 0cef07e9). I did not check them.

Not tested

  • Native 64-lane hosts (this card has 32-lane waves only), AMD or Intel cards.
  • The HBO and shadow-classify shaders from the description, the game and any title capture.
  • Groups with more than one logical wave, and the fallback to the shared pair when a site would exceed the 32 KiB budget.
  • A real dispatch on WARP (it refuses the 32-lane pipeline).
  • Merging alongside #822.
  • VICTORY_SHADER_OPT, clippy, the release build, and the rest of the workspace.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246430579 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/246#issuecomment-7246430579). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-28T22:00:34Z. --- Tested on Ampere: RTX 3070 (`10de:2484`), driver 616.56, native Windows 11 Pro 10.0.26100, rustc 1.98.1. Debug test profile. The system WARP is the one that ships with Windows. Wave sizes tested: **32 lanes only**. This card reports `WaveLaneCountMin/Max` 32-32, so no 64-lane host ran. - Head `24133eecb`, merged onto main `d4b5d5170` (`--no-ff`, clean, no conflicts). The PR's base is `0cef07e9`, 337 commits behind main. The merge changes the same four files by the same amounts as the PR: `opt.rs` +28/-7, `lower.rs` +30/-4, `mod.rs` +4/-2, `wave64_tests.rs` +50. The head was still `24133eecb` and main still `d4b5d5170` when I finished. **The PR's two tests fail on main's code and pass with the PR, on any adapter. Neither one opens a device.** `a_later_half_wave_exchange_preserves_an_earlier_unread_result` lowers the program with the host wave pinned to 32 (`TEST_HOST_WAVE`), disassembles the DXIL with `dxc -dumpbin`, and replays the stores and loads on a CPU map. It runs no dispatch. `only_reachable_exchange_arrays_survive_and_their_uses_are_remapped` is an optimizer unit test. So the hardware and WARP runs below measure the same CPU code, and the card makes no difference to them. I also dispatched the test's program on the 3070 with a temporary test, on the PR's code and on main's. **The 3070 gives the right values with both.** It does not reproduce the bug in a real dispatch of this program. See below. **The tests** ``` cargo test -p victory-shader --lib --locked -- --nocapture --test-threads=1 a_later_half_wave_exchange_preserves_an_earlier_unread_result only_reachable_exchange_arrays_survive VICTORY_WARP=1 cargo test ... # same command ``` - Default, 3 runs: 2 passed, 0 failed, 0 ignored each (0.02 to 0.03 s). - `VICTORY_WARP=1`, 3 runs: 2 passed, 0 failed, 0 ignored each (0.02 s). The DXIL test does not skip here. It returns early and **passes** (printing `no DXC disassembler`) if `dxc.exe` is not found next to the newest SDK `dxil.dll` or at `VICTORY_PC_DXC`. That line was not printed in any run, because the Windows SDK 10.0.26100 `dxc.exe` was found. A runner without dxc would pass this test without checking anything. **Adapters seen** To check that the tests open no device, I added a temporary `eprintln!` at the top of `Host::new` and ran the two tests once with each setting. It printed nothing in either. A dispatch test (`a_sum_of_halves_over_the_wave_is_the_consoles_tree_bit_for_bit`) printed it, so the print worked. I removed it afterwards. | run | device opened by the PR's tests | |---|---| | default | none | | `VICTORY_WARP=1` | none | The temporary dispatch test below opened these two adapters. It resolves `device.GetAdapterLuid()` through `EnumAdapterByLuid` and prints `GetDesc1` and the `D3D12_OPTIONS1` wave lane counts: | `Host::new` | adapter | vendor:device | flags | wave lanes | |---|---|---|---|---| | `false` | NVIDIA GeForce RTX 3070 | `10de:2484` | `0x0` | 32-32 | | `true` | Microsoft Basic Render Driver | `1414:008c` | `0x2` (software) | 4-4 | **Negative control A: main's `lower.rs`, PR's tests** `git checkout d4b5d5170 -- crates/victory-shader/src/emit/lower.rs`. This keeps the PR's `opt.rs` and `mod.rs` (`dump_dxil` has to be `pub(super)` for the test to build). It builds, with the same single warning as main. - Default, 3 runs: **1 passed, 1 failed, 0 ignored each.** - `VICTORY_WARP=1`, 3 runs: **1 passed, 1 failed, 0 ignored each.** All six runs failed the same way, at `wave64_tests.rs:269`: ``` assertion `left == right` failed left: [31, 31, 31, 63] right: [5, 40, 31, 63] ``` On main's code, both lane broadcasts (`v_readlane` of lanes 5 and 40) and the reduction's low partial share one LDS word. The test writes all three sites before it reads any of them, so both broadcasts read the reduction's 31. The optimizer test passed in all six runs. It does not depend on `lower.rs`. **Negative control B: main's `drop_unused_tables`, PR's `lower.rs`** I reverse-applied the PR's two non-test `opt.rs` hunks (the call and the function body) and kept its test. - Default, 3 runs: **2 passed, 1 failed, 0 ignored each** (the third test is the dispatch test below). - `only_reachable_..._remapped` panics at `opt.rs:2867` with `left: 2`, `right: 1`: both globals survive. The DXIL test passes, and the program still passes DXIL validation. **A real dispatch on the 3070 (temporary test)** I appended a temporary test to `wave64_tests.rs`. It lowers the PR's program in the same way, validates the DXIL, and dispatches it in one group of 64 threads, 20 times per adapter. Each lane's expected record is `[5, 40, 63, lane]`: `v_readlane` of lanes 5 and 40, the wave OR of `v0`, then `v0`. I removed it before the lib suites. | code | 3070 | WARP | |---|---|---| | merge (PR's `lower.rs`) | 3 runs x 20 dispatches: 0 wrong, lane 0 `[5, 40, 63, 0]`, lane 63 `[5, 40, 63, 63]` | PSO refused (`The parameter is incorrect.`, a 4-lane adapter) | | control A (main's `lower.rs`) | 3 runs x 20 dispatches: 0 wrong, same values | PSO refused | | control B (main's `opt.rs`) | 3 runs x 20 dispatches: 0 wrong | PSO refused | So on this card and driver, main's shared exchange words give the right result for this program. The barriers between the sites keep each read ahead of the next write. That fits the description, which calls the delayed schedule fault injection and says it "does not identify which GPU instruction supplied the wrong value in the original dispatch". The 5090 D v2's HBO dispatch was not available to me, so this says nothing about that shader. **`cargo test -p victory-shader --lib --locked`** (default, once each) - PR merged onto `d4b5d5170`: 350 passed, 0 failed, 8 ignored (320 s). - Plain main `d4b5d5170`: 348 passed, 0 failed, 8 ignored (314 s). - The two extra passes are the new tests. There were no failures. The PR adds no compiler warnings. The one warning in both builds, unused `colour`, is main's (`lower.rs:13896` on main, `:13922` on the merge). **CI** `gh pr checks 246`: no checks reported on the branch. I did not run clippy. The PR has no comments or reviews yet. **Overlap** - #1138's triage map lists #246 under "64-lane programs refused on 32-lane cards". This PR does not change which programs are refused. It changes the LDS words of exchanges that already lower. - I ran `git merge-tree` of #246 against the 61 other open PRs that change `opt.rs`, `lower.rs`, `emit/mod.rs` or `wave64_tests.rs`. Only **#822** conflicts, at one site in `lower.rs`: the `v_readlane` exchange. #246 replaces `exchange_pair(slot)` with `exchange_storage(self.cur, slot, 1)` there. #822 adds an `if self.local { return Err(...) }` guard just before it. The conflict is mechanical; the guard and the new storage call can both stay. - #1537 (pair meetings) changes the counter-based pair-meeting path, which #246 leaves as it is. `git merge-tree` is clean. - #348 and #733 are clean in `git merge-tree` with #246. - No open PR in that set adds or removes `drop_unused_tables`, `exchange_pair`, or the new exchange storage. - The PRs named in the description's Related work (#43, #104, #118, #42, #108) appear to be upstream numbers (the port is against upstream `0cef07e9`). I did not check them. **Not tested** - Native 64-lane hosts (this card has 32-lane waves only), AMD or Intel cards. - The HBO and shadow-classify shaders from the description, the game and any title capture. - Groups with more than one logical wave, and the fallback to the shared pair when a site would exceed the 32 KiB budget. - A real dispatch on WARP (it refuses the 32-lane pipeline). - Merging alongside #822. - `VICTORY_SHADER_OPT`, clippy, the release build, and the rest of the workspace. AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.
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
trustno1-coder/VIctory-NVIDIA!246
No description provided.