Shaders: isolate cross-half LDS storage at each Wave32 exchange site #246
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/246"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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
d12eb1b2showed hard-edged 16×16 black tiles on outdoor surfaces.CS_DepthProcessingHBO(2f03a2df10503cef) wrote an invalid0xffclassification byte. The downstreamCS_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
d12eb1b2-based build, the outdoor blocks were substantially reduced. A few remained.Verification on
0cef07e90cef07e9d7.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
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 reportsWaveLaneCountMin/Max32-32, so no 64-lane host ran.24133eecb, merged onto maind4b5d5170(--no-ff, clean, no conflicts). The PR's base is0cef07e9, 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 still24133eecband main stilld4b5d5170when 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_resultlowers the program with the host wave pinned to 32 (TEST_HOST_WAVE), disassembles the DXIL withdxc -dumpbin, and replays the stores and loads on a CPU map. It runs no dispatch.only_reachable_exchange_arrays_survive_and_their_uses_are_remappedis 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
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) ifdxc.exeis not found next to the newest SDKdxil.dllor atVICTORY_PC_DXC. That line was not printed in any run, because the Windows SDK 10.0.26100dxc.exewas 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 ofHost::newand 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.VICTORY_WARP=1The temporary dispatch test below opened these two adapters. It resolves
device.GetAdapterLuid()throughEnumAdapterByLuidand printsGetDesc1and theD3D12_OPTIONS1wave lane counts:Host::newfalse10de:24840x0true1414:008c0x2(software)Negative control A: main's
lower.rs, PR's testsgit checkout d4b5d5170 -- crates/victory-shader/src/emit/lower.rs. This keeps the PR'sopt.rsandmod.rs(dump_dxilhas to bepub(super)for the test to build). It builds, with the same single warning as main.VICTORY_WARP=1, 3 runs: 1 passed, 1 failed, 0 ignored each.All six runs failed the same way, at
wave64_tests.rs:269:On main's code, both lane broadcasts (
v_readlaneof 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 onlower.rs.Negative control B: main's
drop_unused_tables, PR'slower.rsI reverse-applied the PR's two non-test
opt.rshunks (the call and the function body) and kept its test.only_reachable_..._remappedpanics atopt.rs:2867withleft: 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_readlaneof lanes 5 and 40, the wave OR ofv0, thenv0. I removed it before the lib suites.lower.rs)[5, 40, 63, 0], lane 63[5, 40, 63, 63]The parameter is incorrect., a 4-lane adapter)lower.rs)opt.rs)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)d4b5d5170: 350 passed, 0 failed, 8 ignored (320 s).d4b5d5170: 348 passed, 0 failed, 8 ignored (314 s).The PR adds no compiler warnings. The one warning in both builds, unused
colour, is main's (lower.rs:13896on main,:13922on 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
git merge-treeof #246 against the 61 other open PRs that changeopt.rs,lower.rs,emit/mod.rsorwave64_tests.rs. Only #822 conflicts, at one site inlower.rs: thev_readlaneexchange. #246 replacesexchange_pair(slot)withexchange_storage(self.cur, slot, 1)there. #822 adds anif self.local { return Err(...) }guard just before it. The conflict is mechanical; the guard and the new storage call can both stay.git merge-treeis clean.git merge-treewith #246.drop_unused_tables,exchange_pair, or the new exchange storage.0cef07e9). I did not check them.Not tested
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.