Repository navigation
Shaders: preserve a broadcast FP16 wave reduction across EXEC restore - #3342
draggygaggy-maker wants to merge 1 commit into
Conversation
Dukestar69
left a comment
There was a problem hiding this comment.
LGTM — verified on Windows against origin/main (63bcca4).
- Factoring
single(s, all)and reusing it inper_lanewhen all lanes share the same symbolic value cleanly preserves broadcastSym::Halfreductions across EXEC restore while still requiring every lane and a uniform high half. cargo test -p victory-shader --lib emit::wave:: -- --test-threads=1: all passed (includingvector_half_reductions_require_every_term_and_the_same_high_half).cargo test -p victory-shader --test half_wave_broadcast -- --test-threads=1: passed.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.cargo xtask policy: 192 files ok.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
|
The copy-before-EXEC-restore form now executes on physical M4 Pro hardware. I applied draggygaggy-maker’s exact classifier change to Mac main
Prepared and tested with Codex. |
fuzeofficlal
left a comment
There was a problem hiding this comment.
Looks good to me — extracting single(s, all) and reusing it in per_lane handles broadcast Sym::Half wave reductions identically to Sym::Red, preserving the packed low-half reduction + uniform high-half source lane across EXEC restore while still rejecting incomplete waves and mixed high-half lanes.
Verified locally on Windows 11 with head 0ccef908 cleanly merged onto main (63bcca43):
- Audited
crates/victory-shader/src/emit/wave.rs:610-677andcrates/victory-shader/tests/half_wave_broadcast.rs:1-73; bothhalf_wave_broadcast.rs(whole file) and the modified lines inwave.rsmatchrustfmt --edition 2024. cargo run -p xtask -- policy(192 files ok) andcargo clippy --locked -p victory-shader --all-targets -- -D warnings(both default and--all-features) pass.cargo test --locked -p victory-shader --test half_wave_broadcastpasses under bothVICTORY_WARP=0andVICTORY_WARP=1, emitting byte-identical DXIL for copy-before and copy-afterEXECrestore.cargo test --locked -p victory-shader --lib emit::crosslane_testspasses5 passed; 0 failedunder bothVICTORY_WARP=0(6.24s: DPP8/DPP8FI 5/5, ds_swizzle 6/6, DPP16 18/18) andVICTORY_WARP=1(0.03s, cleanly skipping 32-lane wave tests).
Non-blocking observation: just like existing per_lane Sym::Red / Shape::Value paths, if an outer s_cbranch_execz conditionally skips the block containing a whole-wave reduction+broadcast on narrowed EXEC and later restores EXEC, per-lane lowering at the join phi can still retain pre-branch values on lanes that were inactive at the branch.
|
WARP verification of head A review on this head (Dukestar69) already ran the wave unit tests, the integration test, clippy and New tests present at head:
The integration test catches the real bug on main (the translation failure at the LDS store described in the PR) and passes at head. The unit test is a negative guard: it also passes on main, so it only protects against the refactor widening acceptance (an incomplete contributor set or differing high-half source lane stays rejected for Wave32 and Wave64). It does not reproduce the bug. victory-shader lib: head 299 passed / 4 failed (the unrelated four below); control 299 passed / 7 failed (the same four plus the three scalar-load tests of #3351 and #3349 that sat in the shared control checkout). Setup (Windows 11, no physical GPU): Suites ( Synthetic tests only; no game files, dumps, shader names or hashes. Test report only, no code changes. Claimed on #1633. AI use: Claude Code (Claude Sonnet 5.5). |
|
NVIDIA full-suite run, to go with the reports above by fuzeofficlal, oni-swr, since none of them names a GPU run. Tested exact head Tested
Not tested
AI use
|
A compute shader can read a complete FP16 reduction from lane 31 into an SGPR and broadcast that dword into a VGPR before restoring EXEC. VIctory's whole-wave simulation retains the reduction, its contributor mask and the lane supplying the upper 16 bits. When the VGPR is used after the restore, the vector classifier drops this otherwise representable result. Translation then fails at the consumer. Moving the copy immediately after the restore already translates.
Use the existing scalar classification rule when every symbolic vector lane agrees. The full contributor mask check still applies, and equality includes the source of the upper half. Continue using the existing DXIL lowering for the supported case. The change adds no GPU operation to the already supported equivalent shader, device synchronization, descriptors or resource allocations.
The integration regression uses synthetic Wave32 GFX10 instructions with a live LDS store. It compares the entire output shader for the two placements of the same register copy. Additional unit cases cover incomplete contributor sets and differing high-half source lanes for Wave32 and Wave64.
Related work
#1568's FP16 reduction fixture restores EXEC before copying the SGPR result into a VGPR and compares the low 16 bits. The new regression also moves the copy before the restore, keeps the vector live through an LDS store, and compares both complete DXIL containers. #2493 tests inline FP16 constants and inspects the scalar result. #3187 tests discovery past an unmatched saveexec and also checks the scalar result. #1486 tracks lane provenance for cross-lane reads. These are complementary to the vector classification change here.
Validation
The original scalar lowering sums FP16 inputs in FP32 and rounds once. This patch inherits that existing arithmetic and compute-stage restriction. No change to GPU timing or graphics memory was measured.
Prepared with Codex 6.2 ASTRA.