Shaders: preserve a broadcast FP16 wave reduction across EXEC restore #3342

Open
github-bot wants to merge 1 commit from github-bot/gh-3342 into main AGit
Owner

@⁠draggygaggy-maker on GitHub · 2026-11-26 19:17 UTC · original
draggygaggy-maker:fix/shader-half-wave-broadcast → main · +109 −24 · 2 files · 1 commits · open

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.

#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

Check Result
Final synthetic fixture on the original classifier The scalar live-out translated; the broadcast live-out failed at guest offset 0x58, the consuming LDS store.
Same fixture on patched translator Passed. The variants produced byte-identical DXIL containers.
Microsoft DirectX Shader Compiler dxv on the emitted fixture Validation succeeded. Disassembly contained the wave reduction, lane-31 read and aligned groupshared store. No GPU execution was performed.
Existing resource_tracking integration suite 3 passed, 1 benchmark ignored.
Shader unit suite on Linux in a separate validation worktree 173 passed, 2 ignored. Three existing optional Windows validator calls required temporary cfg(windows) guards for the baseline's test module to compile on Linux. The guards are excluded from the patch.
Build and lint Release shader library built for Linux and the Windows MSVC target. Windows-target test type-check and all-target Clippy completed. The new integration test was formatted with the pinned rustfmt. Staged diff passed git diff --check.
Windows executable, driver and gameplay No native Windows game build or graphical A/B run was performed.

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.

**@⁠draggygaggy-maker** on GitHub · 2026-11-26 19:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3342) `draggygaggy-maker:fix/shader-half-wave-broadcast` → `main` · +109 −24 · 2 files · 1 commits · open 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 | Check | Result | |---|---| | Final synthetic fixture on the original classifier | The scalar live-out translated; the broadcast live-out failed at guest offset 0x58, the consuming LDS store. | | Same fixture on patched translator | Passed. The variants produced byte-identical DXIL containers. | | Microsoft DirectX Shader Compiler dxv on the emitted fixture | Validation succeeded. Disassembly contained the wave reduction, lane-31 read and aligned groupshared store. No GPU execution was performed. | | Existing resource_tracking integration suite | 3 passed, 1 benchmark ignored. | | Shader unit suite on Linux in a separate validation worktree | 173 passed, 2 ignored. Three existing optional Windows validator calls required temporary cfg(windows) guards for the baseline's test module to compile on Linux. The guards are excluded from the patch. | | Build and lint | Release shader library built for Linux and the Windows MSVC target. Windows-target test type-check and all-target Clippy completed. The new integration test was formatted with the pinned rustfmt. Staged diff passed git diff --check. | | Windows executable, driver and gameplay | No native Windows game build or graphical A/B run was performed. | 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:19:02 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 19:29 UTC · original · approved these changes

LGTM — verified on Windows against origin/main (63bcca4).

  • Factoring single(s, all) and reusing it in per_lane when all lanes share the same symbolic value cleanly preserves broadcast Sym::Half reductions 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 (including vector_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).

**@⁠Dukestar69** on GitHub · 2026-11-26 19:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/3342#pullrequestreview-6079546201) · **approved these changes** LGTM — verified on Windows against `origin/main` (`63bcca4`). - Factoring `single(s, all)` and reusing it in `per_lane` when all lanes share the same symbolic value cleanly preserves broadcast `Sym::Half` reductions 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 (including `vector_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).
Author
Owner

@⁠evan-kolberg on GitHub · 2026-11-26 19:44 UTC · original

The copy-before-EXEC-restore form now executes on physical M4 Pro hardware. I applied draggygaggy-maker’s exact classifier change to Mac main bf99e728 and extended the generated fixture with a same-lane LDS read into a 32-word UAV.

  • Mac main: copy after restore returned 32/32 exact words. Copy before restore hit the expected whole-wave translation refusal.
  • With #3342: both copy orders emitted byte-identical DXIL and returned 32/32 words of 0x001f5000 each on CrossOver 26.3 / D3DMetal 4.0 beta 3. The upper half preserves lane 31, and the lower half encodes the exact FP16 sum of the 32 generated inputs.

Prepared and tested with Codex.

**@⁠evan-kolberg** on GitHub · 2026-11-26 19:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/3342#issuecomment-7201911754) The copy-before-EXEC-restore form now executes on physical M4 Pro hardware. I applied draggygaggy-maker’s [exact classifier change](https://git.gtahub.st/github/Marvisak--VIctory/pulls/3342/commits/0ccef908012ccbd20409e7ce853582769762a67e) to Mac main `bf99e728` and extended the [generated fixture](https://github.com/Marvisak/VIctory/blob/0ccef908012ccbd20409e7ce853582769762a67e/crates/victory-shader/tests/half_wave_broadcast.rs#L8-L73) with a same-lane LDS read into a 32-word UAV. - **Mac main:** copy after restore returned 32/32 exact words. Copy before restore hit the expected whole-wave translation refusal. - **With #3342:** both copy orders emitted byte-identical DXIL and returned 32/32 words of `0x001f5000` each on CrossOver 26.3 / D3DMetal 4.0 beta 3. The upper half preserves lane 31, and the lower half encodes the exact FP16 sum of the 32 generated inputs. Prepared and tested with Codex.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 20:02 UTC · original · approved these changes

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-677 and crates/victory-shader/tests/half_wave_broadcast.rs:1-73; both half_wave_broadcast.rs (whole file) and the modified lines in wave.rs match rustfmt --edition 2024.
  • cargo run -p xtask -- policy (192 files ok) and cargo clippy --locked -p victory-shader --all-targets -- -D warnings (both default and --all-features) pass.
  • cargo test --locked -p victory-shader --test half_wave_broadcast passes under both VICTORY_WARP=0 and VICTORY_WARP=1, emitting byte-identical DXIL for copy-before and copy-after EXEC restore.
  • cargo test --locked -p victory-shader --lib emit::crosslane_tests passes 5 passed; 0 failed under both VICTORY_WARP=0 (6.24s: DPP8/DPP8FI 5/5, ds_swizzle 6/6, DPP16 18/18) and VICTORY_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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 20:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/3342#pullrequestreview-6079912153) · **approved these changes** 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-677` and `crates/victory-shader/tests/half_wave_broadcast.rs:1-73`; both `half_wave_broadcast.rs` (whole file) and the modified lines in `wave.rs` match `rustfmt --edition 2024`. - `cargo run -p xtask -- policy` (`192 files ok`) and `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (both default and `--all-features`) pass. - `cargo test --locked -p victory-shader --test half_wave_broadcast` passes under both `VICTORY_WARP=0` and `VICTORY_WARP=1`, emitting byte-identical DXIL for copy-before and copy-after `EXEC` restore. - `cargo test --locked -p victory-shader --lib emit::crosslane_tests` passes `5 passed; 0 failed` under both `VICTORY_WARP=0` (`6.24s`: DPP8/DPP8FI 5/5, ds_swizzle 6/6, DPP16 18/18) and `VICTORY_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.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-26 20:10 UTC · original

WARP verification of head 0ccef908012ccbd20409e7ce853582769762a67e (control: main 63bcca43).

A review on this head (Dukestar69) already ran the wave unit tests, the integration test, clippy and xtask policy, but not on WARP and not against a control. This report adds the control comparison.

New tests present at head: wave::tests::vector_half_reductions_require_every_term_and_the_same_high_half (unit) and a_half_reduction_copied_before_exec_restore_reaches_the_lds_store (tests/half_wave_broadcast.rs).

test (own process) main + test head
a_half_reduction_copied_before_exec_restore_reaches_the_lds_store FAIL: broadcast live-out: Unsupported { offset: 88, what: "a whole-wave section step the simulation does not follow" } pass
vector_half_reductions_require_every_term_and_the_same_high_half pass pass

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): VICTORY_WARP=1, VICTORY_D3D12_WARP=1, VICTORY_DXIL = Windows SDK 10.0.26100.0 x64\dxil.dll, toolchain 1.98.1, -j 4. Head and control are separate checkouts with separate target dirs. Control = main 63bcca43c6a00a758510398fa43096ce7e4f7df0 plus only the PR's new/changed test code (no source change).

Suites (cargo test -j 4 --locked -p victory-shader --lib, -p victory-gpu --lib): victory-gpu lib 231 passed / 0 failed / 1 ignored on head and control. victory-shader lib has the same 4 failures on head and control, all in emit::synthetic_tests and independent of this PR: a_mask_joined_with_data_at_a_uniform_loop_is_its_number, permutes_mask_high_address_bits_and_divergent_branches and permutes_read_the_lane_named_and_zero_from_lanes_left_out (no pipeline for a wave of 32, a WARP limitation), and gathers_at_a_level_match_the_hardware (lane-4 gather values differ on WARP). Re-running one of them alone in its own process fails the same way on main and on the head, so they are deterministic on WARP, not flaky. No flakes seen in the PR's tests.

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).

**@⁠oni-swr** on GitHub · 2026-11-26 20:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/3342#issuecomment-7202380760) WARP verification of head `0ccef908012ccbd20409e7ce853582769762a67e` (control: main `63bcca43`). A review on this head (Dukestar69) already ran the wave unit tests, the integration test, clippy and `xtask policy`, but not on WARP and not against a control. This report adds the control comparison. **New tests present at head**: `wave::tests::vector_half_reductions_require_every_term_and_the_same_high_half` (unit) and `a_half_reduction_copied_before_exec_restore_reaches_the_lds_store` (`tests/half_wave_broadcast.rs`). | test (own process) | main + test | head | |---|---|---| | `a_half_reduction_copied_before_exec_restore_reaches_the_lds_store` | FAIL: `broadcast live-out: Unsupported { offset: 88, what: "a whole-wave section step the simulation does not follow" }` | pass | | `vector_half_reductions_require_every_term_and_the_same_high_half` | pass | pass | 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): `VICTORY_WARP=1`, `VICTORY_D3D12_WARP=1`, `VICTORY_DXIL` = Windows SDK 10.0.26100.0 `x64\dxil.dll`, toolchain 1.98.1, `-j 4`. Head and control are separate checkouts with separate target dirs. Control = main `63bcca43c6a00a758510398fa43096ce7e4f7df0` plus only the PR's new/changed test code (no source change). **Suites** (`cargo test -j 4 --locked -p victory-shader --lib`, `-p victory-gpu --lib`): victory-gpu lib 231 passed / 0 failed / 1 ignored on head and control. victory-shader lib has the same 4 failures on head and control, all in `emit::synthetic_tests` and independent of this PR: `a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `permutes_mask_high_address_bits_and_divergent_branches` and `permutes_read_the_lane_named_and_zero_from_lanes_left_out` (`no pipeline for a wave of 32`, a WARP limitation), and `gathers_at_a_level_match_the_hardware` (lane-4 gather values differ on WARP). Re-running one of them alone in its own process fails the same way on main and on the head, so they are deterministic on WARP, not flaky. No flakes seen in the PR's tests. 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).
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3342/head:github-bot/gh-3342'
git switch 'github-bot/gh-3342'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3342'
git switch 'github-bot/gh-3342'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3342'
git switch 'github-bot/gh-3342'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3342'
git switch 'main'
git merge --squash 'github-bot/gh-3342'
git switch 'main'
git merge --ff-only 'github-bot/gh-3342'
git switch 'main'
git merge 'github-bot/gh-3342'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3342
No description provided.