Shaders: keep empty-EXEC branches that can reactivate lanes #83

Open
github-bot wants to merge 5 commits from github-bot/gh-83 into main AGit
Owner

@⁠ryotdev on GitHub · 2026-11-24 21:20 UTC · original
ryotdev:codex/preserve-empty-exec → main · +946 −43 · 3 files · 5 commits · draft

An empty console wave can branch past a block that restores an earlier EXEC mask and writes to shared memory. Removing that branch lets the store run. The synthetic regression covers both a branch to an early return and a branch to a join.

Depends on #443 by @⁠AscilCH, included here with its original commit. The follow-up at 4bf38e3 applies its analysis to early returns as well as ordinary skips. A masked vector write can carry a previous full-wave temporary into a join. The analysis follows that value through masked writes and phis. A plain full-width conditional select or cross-row permutation can discard the old destination when all lanes are active and none of its explicit sources reads that destination.

The follow-up at 26c9647 handles a terminal empty-wave branch over workgroup barriers. A retired RDNA2 wave drops out of subsequent rendezvous. The new check permits it to walk the region with empty EXEC when every wave reaches the same gate, all paths visit the same barriers exactly once in order, and loops have bounded scalar counters. The original checks on side effects and EXEC restores still apply. AMD RDNA2 ISA, section 4.3

Verification on Windows 11, RTX 5070, driver 610.88

  • Compared all 2,689 compute inputs against main 310c6eb and previous draft 4bf38e3. Each revision emitted DXIL for the same 2,680. This follow-up changes exactly four outputs from the previous draft. All four match main byte-for-byte and use the regular 32-lane translation.
  • Replayed 39 distinct inputs, including all 20 outputs that previously differed from main, the original six reported here, and the fourteen lighting cases. Native compute pipelines created on main, previous draft, and current head were 39/39, 35/39, and 39/39. DXIL validation passed for all three. The four previously failing shadow classification pipelines now create on the RTX.
  • A handwritten 192-thread dispatch checks shared-memory exchange between two live console waves while the third retires. WARP and the hardware adapter each returned all 192 expected dwords with 128 live threads, and again with all threads inactive. Additional IR tests cover conditional, repeated and unreachable barriers, and an unbounded loop.
  • The Windows IR suite passed 11/11. The Linux shader library passed 176 tests with two ignored. Windows all-target, all-feature shader Clippy and the 169-file asset policy passed. The full Linux workspace check previously stopped on Windows-only loader imports.

The current head and main both reached the interactive jail checkpoint and responded to the same movement sequence on the RTX 5070. Both completed the observation with no host GPU failure and the same six unrelated compute pipeline refusals. None of the four regressions above appeared in either refusal set. At the prison window, both runs showed orange light on the character’s hair. The dark-hair image from the previous draft did not persist after repair. The fence also varied across repeated launches of the same main binary. Different geometry was still streaming during the timed window, so this comparison establishes neither a frame-rate gain nor visual parity.

AI-assisted implementation and testing. The public test fixtures are handwritten. Thanks to @⁠Xeltax for narrowing the original lighting example and @⁠YeokiNoewChi for reporting the native pipeline regression.

**@⁠ryotdev** on GitHub · 2026-11-24 21:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/83) `ryotdev:codex/preserve-empty-exec` → `main` · +946 −43 · 3 files · 5 commits · draft An empty console wave can branch past a block that restores an earlier EXEC mask and writes to shared memory. Removing that branch lets the store run. The synthetic regression covers both a branch to an early return and a branch to a join. **Depends on #443** by @⁠AscilCH, included here with its original commit. The follow-up at [4bf38e3](https://github.com/ryotdev/victory-gta6/commit/4bf38e3096582486eb476e085f1d0517b11fdb75) applies its analysis to early returns as well as ordinary skips. A masked vector write can carry a previous full-wave temporary into a join. The analysis follows that value through masked writes and phis. A plain full-width conditional select or cross-row permutation can discard the old destination when all lanes are active and none of its explicit sources reads that destination. The follow-up at [26c9647](https://github.com/ryotdev/victory-gta6/commit/26c9647e1ac7ebee1350ad84ae65aeb643af13ae) handles a terminal empty-wave branch over workgroup barriers. A retired RDNA2 wave drops out of subsequent rendezvous. The new check permits it to walk the region with empty EXEC when every wave reaches the same gate, all paths visit the same barriers exactly once in order, and loops have bounded scalar counters. The original checks on side effects and EXEC restores still apply. [AMD RDNA2 ISA, section 4.3](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) **Verification on Windows 11, RTX 5070, driver 610.88** - Compared all 2,689 compute inputs against main `310c6eb` and previous draft `4bf38e3`. Each revision emitted DXIL for the same 2,680. This follow-up changes exactly four outputs from the previous draft. All four match main byte-for-byte and use the regular 32-lane translation. - Replayed 39 distinct inputs, including all 20 outputs that previously differed from main, the original six reported here, and the fourteen lighting cases. Native compute pipelines created on main, previous draft, and current head were **39/39, 35/39, and 39/39**. DXIL validation passed for all three. The four previously failing shadow classification pipelines now create on the RTX. - A handwritten 192-thread dispatch checks shared-memory exchange between two live console waves while the third retires. WARP and the hardware adapter each returned all 192 expected dwords with 128 live threads, and again with all threads inactive. Additional IR tests cover conditional, repeated and unreachable barriers, and an unbounded loop. - The Windows IR suite passed 11/11. The Linux shader library passed 176 tests with two ignored. Windows all-target, all-feature shader Clippy and the 169-file asset policy passed. The full Linux workspace check previously stopped on Windows-only loader imports. The current head and main both reached the interactive jail checkpoint and responded to the same movement sequence on the RTX 5070. Both completed the observation with no host GPU failure and the same six unrelated compute pipeline refusals. None of the four regressions above appeared in either refusal set. At the prison window, both runs showed orange light on the character’s hair. The dark-hair image from the previous draft did **not** persist after repair. The fence also varied across repeated launches of the same main binary. Different geometry was still streaming during the timed window, so this comparison establishes neither a frame-rate gain nor visual parity. AI-assisted implementation and testing. The public test fixtures are handwritten. Thanks to @⁠Xeltax for narrowing the original lighting example and @⁠YeokiNoewChi for reporting the native pipeline regression.
In `ir::without_skips`, removing `s_cbranch_execz` causes waves with `EXEC == 0` to fall through and execute the skipped region `inside`. Previously `skipped()` exempted `Reg::S(126 | 127)` (`EXEC_LO`/`EXEC_HI`) from join-phi checks without verifying that `inside` keeps `EXEC == 0`, and did not check `inside` for EXEC-independent scalar side effects.

1. Reject skipping regions containing EXEC-independent scalar side effects (`s_store_*`, `s_buffer_store_*`, `s_scratch_store_*`, `s_atomic_*`, `s_buffer_atomic_*`, `s_sendmsg`, `s_sendmsghalt`, `s_barrier`, `s_round_mode`, `s_denorm_mode`).
2. Compute a least fixpoint of values inside `inside` that may be nonzero when `EXEC` enters as `0` (seeded with external values other than the skip branch's own `EXEC` dwords), propagating zero through narrowing `v_cmpx_*`, `s_and*`/`s_andn2*`, `s_mov_b32`/`s_mov_b64`, and pure whole-wave sections (`s_or_saveexec`/`s_nand_saveexec` paired with an exact full-width restore). Reject if any `EXEC` write or phi inside `inside` (outside a pure whole-wave section) or incoming `EXEC` phi at `target` can become nonzero, or if a live VGPR phi at `target` takes a value written inside a whole-wave section.
3. Add synthetic unit tests verifying outer-EXEC restores, `s_or_b64`/`s_andn2_b64` EXEC widening, inner narrowing (still allowed), `s_sendmsg`, `s_barrier`, and `s_buffer_store_dword`.
Integrate the fixed-point analysis from #443. A write through an empty mask carries a previous full-wave temporary into its destination. Account for that carry and for proven all-lane full-dword overwrites when checking join values.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:35:53 +00:00
Author
Owner

@⁠adriaespii on GitHub · 2026-11-24 21:30 UTC · original

Independent test run on commit 7ed853a (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 498 passed, 0 failed, 7 ignored (victory-shader: 212 passed, 0 failed, 2 ignored; victory-gpu: 110 passed, 0 failed, 1 ignored)
  • Not tested: retail shader pack / live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

**@⁠adriaespii** on GitHub · 2026-11-24 21:30 UTC · [original](https://github.com/fxceless/victory-fork/pull/83#issuecomment-7145026711) Independent test run on commit `7ed853a` (AMD RDNA4): - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test --workspace`: 498 passed, 0 failed, 7 ignored (`victory-shader`: 212 passed, 0 failed, 2 ignored; `victory-gpu`: 110 passed, 0 failed, 1 ignored) - **Not tested:** retail shader pack / live game run (no game files on this machine) *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
Author
Owner

@⁠arminkhaleghirod on GitHub · 2026-11-24 21:42 UTC · original

Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080. Changes against main, by failure reason:

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.

**@⁠arminkhaleghirod** on GitHub · 2026-11-24 21:42 UTC · [original](https://github.com/fxceless/victory-fork/pull/83#issuecomment-7145285992) Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. Changes against main, by failure reason: 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.
Author
Owner

@⁠YeokiNoewChi on GitHub · 2026-11-25 00:37 UTC · original

RTX 3070 Ti 8 GB (32-lane waves), driver 621.x, Windows 11, fork main 4e17478 plus #23 #24 #25 #51 #52 #32 #58 #71, diag build, Series X.

With #83 on top, the driver refuses six more compute pipelines with E_INVALIDARG (0x80070057), so their dispatches are dropped:

  • 55679a0547649d0b InstanceCulling:CS_Tree_BatchCull
  • 89d08e561897d4e5 InstanceCulling:CS_Tree_BatchCull_ImposterOnly
  • 7168dd781ca7efb9 sr_tracing:CS_RayPrePass_Opaque_SSR
  • d2b169b82f67ec5b sr_tracing:CS_RayPrePass_Alpha
  • 1f1fbd86759b3da2 vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized
  • b96880482a17f632 vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Vectorized

Reproduced offline in seconds: VICTORY_TRANSLATE_ONLY=55679a0547649d0b,89d08e561897d4e5,1f1fbd86759b3da2,7168dd781ca7efb9 VICTORY_HOST_MAX_WAVE=32 victory translate --pipelines --list shaders.rpf gives "pipeline created" for all four without #83 and "pipeline: The parameter is incorrect." for all four with it. Reverting only #83 restores them (the other PRs in the stack are not involved; #79 was checked separately). The game run without #83 refuses the usual four (02384a60fda6f2d0, 2cc4c197ee29e291, 2da4beb386509b77, 369cbe906ea72764).

AI-assisted (Claude Code); counts and hashes only, nothing from the game.

**@⁠YeokiNoewChi** on GitHub · 2026-11-25 00:37 UTC · [original](https://github.com/fxceless/victory-fork/pull/83#issuecomment-7148704439) RTX 3070 Ti 8 GB (32-lane waves), driver 621.x, Windows 11, fork `main` 4e17478 plus #23 #24 #25 #51 #52 #32 #58 #71, diag build, Series X. With #83 on top, the driver refuses six more compute pipelines with `E_INVALIDARG` (0x80070057), so their dispatches are dropped: - `55679a0547649d0b` InstanceCulling:CS_Tree_BatchCull - `89d08e561897d4e5` InstanceCulling:CS_Tree_BatchCull_ImposterOnly - `7168dd781ca7efb9` sr_tracing:CS_RayPrePass_Opaque_SSR - `d2b169b82f67ec5b` sr_tracing:CS_RayPrePass_Alpha - `1f1fbd86759b3da2` vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Scalarized - `b96880482a17f632` vfx_proj_decal_vbuffer:CS_ProjDecalReduceClassification_Vectorized Reproduced offline in seconds: `VICTORY_TRANSLATE_ONLY=55679a0547649d0b,89d08e561897d4e5,1f1fbd86759b3da2,7168dd781ca7efb9 VICTORY_HOST_MAX_WAVE=32 victory translate --pipelines --list shaders.rpf` gives "pipeline created" for all four without #83 and "pipeline: The parameter is incorrect." for all four with it. Reverting only #83 restores them (the other PRs in the stack are not involved; #79 was checked separately). The game run without #83 refuses the usual four (`02384a60fda6f2d0`, `2cc4c197ee29e291`, `2da4beb386509b77`, `369cbe906ea72764`). AI-assisted (Claude Code); counts and hashes only, nothing from the game.
Author
Owner

@⁠justlovett0 on GitHub · 2026-11-25 03:23 UTC · original

Tested on Windows 10 (19044), RTX 3080 (32-lane waves), title build 1.0.2.1, release + diagnostics.

With this empty-EXEC guard plus #11 (restore parked lane-mask pairs a few instructions apart) and #77 (v_fma_mixlo/mixhi over an f16 first interpolation half), the IrradianceCache_Shade / IrradianceCache_ShadeSecondary compute shaders translate and bind in game — previously refused with "a wave reduction where not every lane runs". With the BVH builder left OFF, the static world renders lit (good world lighting) at ~390 ms/frame in a heavy scene.

Applying #11 alone previously removed world geometry for us; with this guard the geometry is preserved. So the guard appears necessary alongside #11's restore forward-search — the combination is what made the irradiance cache usable on this card. The remaining clothes/material lighting issue looks separate (the deferred-material pixel programs #77 addresses). Thanks — useful fix.

**@⁠justlovett0** on GitHub · 2026-11-25 03:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/83#issuecomment-7151865410) Tested on Windows 10 (19044), RTX 3080 (32-lane waves), title build 1.0.2.1, release + diagnostics. With this empty-EXEC guard plus #11 (restore parked lane-mask pairs a few instructions apart) and #77 (v_fma_mixlo/mixhi over an f16 first interpolation half), the `IrradianceCache_Shade` / `IrradianceCache_ShadeSecondary` compute shaders translate and bind in game — previously refused with "a wave reduction where not every lane runs". With the BVH builder left OFF, the static world renders lit (good world lighting) at ~390 ms/frame in a heavy scene. Applying #11 alone previously removed world geometry for us; with this guard the geometry is preserved. So the guard appears necessary alongside #11's restore forward-search — the combination is what made the irradiance cache usable on this card. The remaining clothes/material lighting issue looks separate (the deferred-material pixel programs #77 addresses). Thanks — useful fix.
Author
Owner

@⁠ryotdev on GitHub · 2026-11-25 03:44 UTC · original

@⁠YeokiNoewChi I reproduced the regression on an RTX 5070 (driver 610.88). All six programs validated on both revisions. Native pipeline creation was 6/6 on the original parent and 0/6 on 7ed853a.

I updated this branch at 4bf38e3. It retains the empty-EXEC store regression, reuses the region analysis from #443, and checks whether full-wave temporary values survive a later masked write. Native pipeline creation now passes 6/6 with approximate local-wave lowering disabled. The 14 lighting pipelines in #62 also validate and create successfully. I did not dispatch the six programs in this check.

I’ve left this in draft for independent testing of rendered output and broader shader coverage. Thanks for catching the difference between DXIL validation and actual pipeline creation.

**@⁠ryotdev** on GitHub · 2026-11-25 03:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/83#issuecomment-7152199819) @⁠YeokiNoewChi I reproduced the regression on an RTX 5070 (driver 610.88). All six programs validated on both revisions. Native pipeline creation was 6/6 on the original parent and 0/6 on 7ed853a. I updated this branch at 4bf38e3. It retains the empty-EXEC store regression, reuses the region analysis from #443, and checks whether full-wave temporary values survive a later masked write. Native pipeline creation now passes 6/6 with approximate local-wave lowering disabled. The 14 lighting pipelines in #62 also validate and create successfully. I did not dispatch the six programs in this check. I’ve left this in draft for independent testing of rendered output and broader shader coverage. Thanks for catching the difference between DXIL validation and actual pipeline creation.
Author
Owner

@⁠ryotdev on GitHub · 2026-11-25 04:14 UTC · original · edited 2026-11-25 04:29 UTC

Full compute comparison. I compared the emitted DXIL for all 2,689 compute containers in the local input index with the same 32-lane host settings. Both revisions emitted 2,680 programs. Exactly 20 outputs changed. All 20 validated on both builds. Main created all 20 native pipelines on the RTX 5070, and the draft created 16. The four regressions cover raster and ray-traced shadow classification. The original six and the separate fourteen lighting cases all passed on both builds. This remains blocked on the four native failures.

Keeping this in draft. A checkpoint run exposed two additional compute pipelines that regress between fork main 310c6eb and this branch at 4bf38e3. I collected the nine distinct compute inputs refused across the two runs, then tested exactly those same nine offline on each binary. Both validated all nine DXIL programs. On the RTX 5070 (driver 610.88), main created two native D3D12 pipelines and this branch created zero. The original six reported above still pass their targeted test.

Both new failures have an empty-EXEC branch to program termination that skips workgroup barriers. Main's translator removes that branch and emits wave32. This branch preserves it and emits wave64, which the adapter rejects. RDNA2 permits an early-exiting wave to leave the remaining waves to synchronize. Any fix here needs to preserve that behavior across the barriers and loops. AMD RDNA2 ISA, section 4.3

The visual difference is real. At the same stationary jail window, the bright orange highlight across the back of the character's head became dark. The median frame-time reading over 57 seconds was 455 ms on main and 415 ms on this branch at about 5,000 draws/frame in each. That is one ordered comparison on one GPU.

**@⁠ryotdev** on GitHub · 2026-11-25 04:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/83#issuecomment-7152653561) · edited 2026-11-25 04:29 UTC **Full compute comparison.** I compared the emitted DXIL for all 2,689 compute containers in the local input index with the same 32-lane host settings. Both revisions emitted 2,680 programs. Exactly 20 outputs changed. All 20 validated on both builds. Main created all 20 native pipelines on the RTX 5070, and the draft created 16. The four regressions cover raster and ray-traced shadow classification. The original six and the separate fourteen lighting cases all passed on both builds. This remains blocked on the four native failures. Keeping this in draft. A checkpoint run exposed two additional compute pipelines that regress between fork main `310c6eb` and this branch at `4bf38e3`. I collected the nine distinct compute inputs refused across the two runs, then tested exactly those same nine offline on each binary. Both validated all nine DXIL programs. On the RTX 5070 (driver 610.88), main created two native D3D12 pipelines and this branch created zero. The original six reported above still pass their targeted test. Both new failures have an empty-EXEC branch to program termination that skips workgroup barriers. Main's translator removes that branch and emits wave32. This branch preserves it and emits wave64, which the adapter rejects. RDNA2 permits an early-exiting wave to leave the remaining waves to synchronize. Any fix here needs to preserve that behavior across the barriers and loops. [AMD RDNA2 ISA, section 4.3](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) The visual difference is real. At the same stationary jail window, the bright orange highlight across the back of the character's head became dark. The median frame-time reading over 57 seconds was 455 ms on main and 415 ms on this branch at about 5,000 draws/frame in each. That is one ordered comparison on one GPU.
Author
Owner

@⁠ryotdev on GitHub · 2026-11-25 05:04 UTC · original · edited 2026-11-25 05:20 UTC

Updated the draft to 26c9647. All four shadow classification regressions are fixed in native pipeline creation on the RTX 5070. The full 2,689-input comparison found exactly four changed outputs from the previous draft, each identical to main. The handwritten 192-thread shared-memory test also passed on both WARP and hardware. I’ve added the three-revision results to the PR description.

Checkpoint follow-up: the repaired head and main both reached the interactive cell and responded to movement. The earlier dark-hair difference disappeared on the repaired head. Both logged the same six unrelated native compute refusals. The PR description records the comparison and its limits.

**@⁠ryotdev** on GitHub · 2026-11-25 05:04 UTC · [original](https://github.com/fxceless/victory-fork/pull/83#issuecomment-7153417981) · edited 2026-11-25 05:20 UTC Updated the draft to `26c9647`. All four shadow classification regressions are fixed in native pipeline creation on the RTX 5070. The full 2,689-input comparison found exactly four changed outputs from the previous draft, each identical to main. The handwritten 192-thread shared-memory test also passed on both WARP and hardware. I’ve added the three-revision results to the PR description. Checkpoint follow-up: the repaired head and main both reached the interactive cell and responded to movement. The earlier dark-hair difference disappeared on the repaired head. Both logged the same six unrelated native compute refusals. The PR description records the comparison and its limits.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/wave64_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-83'
git switch 'github-bot/gh-83'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-83'
git switch 'github-bot/gh-83'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-83'
git switch 'main'
git merge --squash 'github-bot/gh-83'
git switch 'main'
git merge --ff-only 'github-bot/gh-83'
git switch 'main'
git merge 'github-bot/gh-83'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.