Repository navigation
Shaders: track uniform LDS reads and exact operand widths in lane_uniform (#16) - #36
adriaespii wants to merge 1 commit into
Conversation
| Operand::Vector { reg, dwords } => { | ||
| // every dword of the operand the instruction reads (not the old value | ||
| // of a higher-numbered destination register that IR keeps for guards) | ||
| let end = reg.saturating_add(dwords); |
There was a problem hiding this comment.
For a legal source pair v[254:255], the exclusive end is 256. The u8 addition saturates to 255 and drops the high word. A shift that copies a per-lane v255 into its low result then gets classified as wave-uniform. A single-word read of a uniform v255 also fails the proof in the other direction.
I put a cherry-pickable fix and a hand-written regression test directly on top of your PR. It checks each decoded source dword, including the last register. The varying-high-word case fails on this head. With the fix, both the varying and constant cases pass, and the shader library suite passes 172 tests with 2 ignored. Fix and regression test
I also ran the builder through the offline translator with VICTORY_HOST_WAVE=32 and DXIL validation. Main at 4e17478 emitted and validated 49/52 compute programs. This PR reached 52/52, and all 52 outputs remained byte-identical after the fix. This measures shader generation and validation. GPU execution, lighting and frame times remain untested here.
AI-assisted review and test.
|
Verified at
The change adds one test for 113 lines in One thing I can check here that a wave64 host cannot: whether the wave64 path is unchanged for programs that were already correct. If the diff can perturb uniform tracking on a 64-lane host, the 26 698-program corpus is the place to see it — I have that translate run on disk and can diff the emitted containers before/after this patch on this machine (~10 min, no game). Say the word and I will post the count. |
…form Fixes two gaps in lane_uniform that prevented wave-uniform VGPRs (such as the BVH builder's prefix-sum loop in fxceless#16) from lowering v_readfirstlane_b32 on 32-lane hosts without a cross-half exchange: - Handle unguarded non-d16 ds_read* instructions when their address VGPR is already wave-uniform. - Bound Operand::Vector reads to reg..reg + dwords in u16 (so operands ending at v255 are not truncated by u8 saturation, and the old value of a higher-numbered destination register kept for EXEC guards no longer poisons uniformity); also check all dwords of Operand::Scalar in u16. Part of fxceless#16. Assisted-by: Antigravity (Gemini 4 Neon)
d964ec7 to
87d674f
Compare
|
Thanks for the great catch and for verifying the 52/52 builder translation + DXIL validation @ryotdev! Fixed in
AI use: Antigravity (Gemini 4 Neon) applied the fix, wrote the regression test, and ran clippy/tests. |
|
Thanks for checking on Linux @rostaddotcc! To clarify both points:
AI use: Antigravity (Gemini 4 Neon) drafted this reply. |
|
NVIDIA test of this PR at Setup: RTX 3080 Ti 12 GB, driver 32.0.16.1742; Ryzen 7 7800X3D; 32 GB; Windows 11 Pro 26300; Rust 1.98.1 MSVC, release. Tree: fork
The title then crashes 7–14 s later in the prologue — the #16 crash, which also happens on a 64-lane RX 9070 XT without this PR, so it is outside this PR's scope; details and a write-back trace in #16. Written with Claude Code (Claude Opus 5.5); the runs are mine. |
|
Merged onto main 90228a7 and ran No change: every failure count is the same as main, and no new reason appears. So no regression in translation. What this PR changes at run time isn't covered by this check. |
|
Build check only: this PR merges cleanly on main c96b4f2 and the integration build of eight PRs (#115 #66 #36 #144 #147 #141 #139 #130) compiles (diagnostics profile). In the game, that combo was run alone 3 times (900 s, |
Addresses the
v_readfirstlane_b32wave-uniformity gap reported in #16 (part 1) without needing an opt-in override flag.What changed
In
crates/victory-shader/src/emit/lower.rs(lane_uniform):ds_read*, excluding_d16): whends_read*(gds: false, no guard) reads from a VGPR address already insame, mark its destination register(s) as wave-uniform._d16forms are excluded because they preserve the other half of the destination VGPR.Operand::Vectorread range: filterinst.readsbyreg..reg + dwordsinstead ofx >= reg. Becauseir.rsincludes the previous value of the destination VGPR ininst.reads(for EXEC guards),x >= regswept up the old uninitialized/per-lane destination register wheneverdst > src(e.g.v_add_nc_u32 v8, s17, v2) and poisoned uniformity. Also check alldwordsforOperand::Scalar.first_lane_read_of_uniform_lds_load_lowers_on_wave32): verifies underTEST_HOST_WAVE = 32that a divergentds_read_b32from a uniform address +v_add_nc_u32+v_readfirstlane_b32lowers cleanly, while the same shader with a per-lane address (v0) is still refused witha first-lane read where not every lane runs.Tested
x86_64-pc-windows-msvc)cargo clippy --workspace --all-targets -- -D warnings: 0 warningscargo test --workspace: 496 passed, 0 failed, 7 ignored (victory-shader: 211 passed, 0 failed, 2 ignored)Not tested
XboxBvhBuilder.dllshaders or live game runs (no game files on this machine)AI use
lane_uniformbugs, wrote the fix and unit test, and ranclippyand the workspace test suite.