Shaders: keep s_cbranch_execz over loops that cannot exit when EXEC is 0 #262

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

@⁠xADEL on GitHub · 2026-11-24 23:02 UTC · original
xADEL:shader/keep-execz-over-vcc-loops → main · +254 −2 · 2 files · 1 commits · open

Problem

ir::without_skips (both deep = false and deep = true) and ir::without_early_outs strip s_cbranch_execz even when the guarded region contains a loop exited via a non-zero lane mask (e.g. v_cmp_* + s_cbranch_vccz / s_cbranch_vccnz, s_cbranch_execz / s_cbranch_execnz, or s_cbranch_scc0 / s_cbranch_scc1 fed by an s_and* with EXEC or VCC).

When an empty wave (EXEC == 0) or inactive lane falls through into such a loop, every vector compare writes 0 (masked by EXEC), so the zero-mask branch stays on the loop cycle until the synthetic 4,096-iteration guard fires:

  • On latch-based loops (like the outer light loop in ptfx_CS_lightAtlas_Sprite / _Trail), hitting the synthetic guard executes ret void, silently dropping stores after the loop.
  • Under VICTORY_WAVE_WIDE=1 on 32-lane hosts, every empty wave falls into the loop and runs ~4,096 iterations × dozens of wave-wide group barriers (the hang that forced VICTORY_WAVE_WIDE off by default in e9765a7).

Complementary to #83 and #196: #83 keeps s_cbranch_execz when the skipped region reactivates EXEC, and #196 uses WaveActiveAnyTrue for active-wave vcc loop exits; when EXEC == 0 across the whole wave, vcc is 0 in every lane so even a wave-wide WaveActiveAnyTrue cannot exit and the s_cbranch_execz guard itself must be kept.

What is in it

  • crates/victory-shader/src/ir.rs:
    • Add has_empty_exec_loop (with reaches_within, reachable_from, scc_zero_under_empty_exec) and refuse to strip s_cbranch_execz in without_early_outs and without_skips whenever the guarded region contains a mask-branch whose zero-mask edge stays on a cycle within that region.
    • Scalar-counted loops (e.g. s_cmp_lg_u32 + s_cbranch_scc1) are still stripped as before.
    • Add unit test without_skips_keeps_execz_over_vcc_loops_and_strips_scalar_loops covering vccz, vccnz, early-out vccz, and scalar loops.
  • crates/victory-shader/src/emit/wave64_tests.rs:
    • Add without_skips_keeps_execz_guard_over_vcc_loop (validates DXIL with dxil.dll and dispatches on wave32 hardware under both per-lane and wave-wide lowering for empty, partial active/inactive, and full waves).

Tested

  • Hardware: Windows 11 x64, Intel Core i5-12450HX, 24 GB RAM, NVIDIA GeForce RTX 3050 6GB Laptop GPU (driver 32.0.16.2124, wave32, SM 6.6) + Intel(R) UHD Graphics (32.0.101.7026), Windows SDK 10.0.26100.0 (dxil.dll active).
  • Standalone on this branch (bbfe426):
    • cargo xtask policy -> 169 files ok
    • cargo clippy --workspace --all-targets --locked -- -D warnings -> 0 warnings
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings -> 0 warnings
    • cargo test --locked -p victory-shader --lib without_skips -> 2 passed, 0 failed (note: on this hybrid laptop without the adapter-selection PR, adapter 0 is Intel UHD Graphics which rejects WaveSize(32) compute pipelines so hardware dispatch skips there)
    • cargo test --locked -p victory-shader --lib wave64_tests -> 6 passed, 0 failed
    • cargo test --locked -p xtask -> 4 passed, 0 failed
  • On RTX 3050 6GB (combined locally with adapter selection so hardware wave32 tests execute on NVIDIA):
    • cargo test --workspace --locked -> 500 passed, 0 failed, 7 ignored (verified without_skips_keeps_execz_guard_over_vcc_loop failed with left: 0, right: 7 without the ir.rs fix and passed all 8 per-lane + wave-wide hardware dispatches with it).
    • Offline translate --validate --pipelines with VICTORY_HOST_MAX_WAVE=32 VICTORY_WAVE_WIDE=1 on RTX 3050:
      • All 4 ptfx_CS_lightAtlas_* shaders (2561af9577c47289, c06aa62112ffba4c, cabb87599722e59a, e8f6ae0597846841) and 14 CS_ShadowRenderTiled* shaders: 18/18 emitted, dxil.dll-validated, and created D3D12 pipelines; inspected disassembled DXIL for 2561af9577c47289 and c06aa62112ffba4c and confirmed the outer light loop now keeps its wave-wide s_cbranch_execz guard.
      • XboxBvhBuilder.dll (VICTORY_HOST_WAVE=32): 49/52 emitted, 49/49 validated, 49/49 pipelines (unchanged baseline).

Not tested

  • Live in-world playtest with VICTORY_WAVE_WIDE=1 enabled (kept off by default per e9765a7).
  • Full shaders.rpf corpus translation sweep.

AI use

Written and verified with Antigravity (model name not exposed in the agent environment).

**@⁠xADEL** on GitHub · 2026-11-24 23:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/262) `xADEL:shader/keep-execz-over-vcc-loops` → `main` · +254 −2 · 2 files · 1 commits · open ## Problem `ir::without_skips` (both `deep = false` and `deep = true`) and `ir::without_early_outs` strip `s_cbranch_execz` even when the guarded region contains a loop exited via a non-zero lane mask (e.g. `v_cmp_*` + `s_cbranch_vccz` / `s_cbranch_vccnz`, `s_cbranch_execz` / `s_cbranch_execnz`, or `s_cbranch_scc0` / `s_cbranch_scc1` fed by an `s_and*` with `EXEC` or `VCC`). When an empty wave (`EXEC == 0`) or inactive lane falls through into such a loop, every vector compare writes `0` (masked by `EXEC`), so the zero-mask branch stays on the loop cycle until the synthetic 4,096-iteration guard fires: - On latch-based loops (like the outer light loop in `ptfx_CS_lightAtlas_Sprite` / `_Trail`), hitting the synthetic guard executes `ret void`, silently dropping stores after the loop. - Under `VICTORY_WAVE_WIDE=1` on 32-lane hosts, every empty wave falls into the loop and runs ~4,096 iterations × dozens of wave-wide group barriers (the hang that forced `VICTORY_WAVE_WIDE` off by default in `e9765a7`). Complementary to #83 and #196: #83 keeps `s_cbranch_execz` when the skipped region reactivates `EXEC`, and #196 uses `WaveActiveAnyTrue` for active-wave `vcc` loop exits; when `EXEC == 0` across the whole wave, `vcc` is 0 in every lane so even a wave-wide `WaveActiveAnyTrue` cannot exit and the `s_cbranch_execz` guard itself must be kept. ## What is in it - **`crates/victory-shader/src/ir.rs`**: - Add `has_empty_exec_loop` (with `reaches_within`, `reachable_from`, `scc_zero_under_empty_exec`) and refuse to strip `s_cbranch_execz` in `without_early_outs` and `without_skips` whenever the guarded region contains a mask-branch whose zero-mask edge stays on a cycle within that region. - Scalar-counted loops (e.g. `s_cmp_lg_u32` + `s_cbranch_scc1`) are still stripped as before. - Add unit test `without_skips_keeps_execz_over_vcc_loops_and_strips_scalar_loops` covering `vccz`, `vccnz`, early-out `vccz`, and scalar loops. - **`crates/victory-shader/src/emit/wave64_tests.rs`**: - Add `without_skips_keeps_execz_guard_over_vcc_loop` (validates DXIL with `dxil.dll` and dispatches on wave32 hardware under both per-lane and wave-wide lowering for empty, partial active/inactive, and full waves). ## Tested - **Hardware:** Windows 11 x64, Intel Core i5-12450HX, 24 GB RAM, NVIDIA GeForce RTX 3050 6GB Laptop GPU (driver `32.0.16.2124`, wave32, SM 6.6) + Intel(R) UHD Graphics (`32.0.101.7026`), Windows SDK `10.0.26100.0` (`dxil.dll` active). - **Standalone on this branch (`bbfe426`):** - `cargo xtask policy` -> `169 files ok` - `cargo clippy --workspace --all-targets --locked -- -D warnings` -> 0 warnings - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` -> 0 warnings - `cargo test --locked -p victory-shader --lib without_skips` -> 2 passed, 0 failed (note: on this hybrid laptop without the adapter-selection PR, adapter 0 is Intel UHD Graphics which rejects `WaveSize(32)` compute pipelines so hardware dispatch skips there) - `cargo test --locked -p victory-shader --lib wave64_tests` -> 6 passed, 0 failed - `cargo test --locked -p xtask` -> 4 passed, 0 failed - **On RTX 3050 6GB (combined locally with adapter selection so hardware wave32 tests execute on NVIDIA):** - `cargo test --workspace --locked` -> **500 passed, 0 failed, 7 ignored** (verified `without_skips_keeps_execz_guard_over_vcc_loop` failed with `left: 0, right: 7` without the `ir.rs` fix and passed all 8 per-lane + wave-wide hardware dispatches with it). - Offline `translate --validate --pipelines` with `VICTORY_HOST_MAX_WAVE=32 VICTORY_WAVE_WIDE=1` on RTX 3050: - All 4 `ptfx_CS_lightAtlas_*` shaders (`2561af9577c47289`, `c06aa62112ffba4c`, `cabb87599722e59a`, `e8f6ae0597846841`) and 14 `CS_ShadowRenderTiled*` shaders: 18/18 emitted, `dxil.dll`-validated, and created D3D12 pipelines; inspected disassembled DXIL for `2561af9577c47289` and `c06aa62112ffba4c` and confirmed the outer light loop now keeps its wave-wide `s_cbranch_execz` guard. - `XboxBvhBuilder.dll` (`VICTORY_HOST_WAVE=32`): 49/52 emitted, 49/49 validated, 49/49 pipelines (unchanged baseline). ## Not tested - Live in-world playtest with `VICTORY_WAVE_WIDE=1` enabled (kept off by default per `e9765a7`). - Full `shaders.rpf` corpus translation sweep. ## AI use Written and verified with Antigravity (model name not exposed in the agent environment).
ir::without_skips and ir::without_early_outs stripped s_cbranch_execz
even when the guarded region contained a loop exited via a non-zero lane
mask (v_cmp_* + s_cbranch_vccz / s_cbranch_vccnz, s_cbranch_execz /
s_cbranch_execnz, or s_cbranch_scc0 / s_cbranch_scc1 from an AND with
EXEC or VCC).

When EXEC == 0 falls through into such a loop, vector compares always
write 0 so the zero-mask edge stays on the cycle until the synthetic
loop limit fires (4096 iterations), aborting before post-loop stores —
and under VICTORY_WAVE_WIDE=1 on ptfx_CS_lightAtlas_Sprite / _Trail,
spinning through thousands of wave-wide group barriers per empty wave.

Keep s_cbranch_execz whenever its guarded region contains a loop whose
zero-mask edge stays in the region, while continuing to strip skips over
scalar-counted loops. Add unit tests for all four CFG shapes and a
wave64 hardware/DXIL regression test covering both per-lane and
wave-wide lowering.

Assisted-by: Antigravity
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:39:28 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-11-24 23:47 UTC · original

Ran the new s_cbranch_execz tests and the full workspace at bbfe4261:

Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

cargo test -p victory-shader --lib without_skips_keeps_execz -- --test-threads=4 --nocapture
2 passed; 0 failed; 0 ignored      (exit 0)

cargo test -p victory-shader --lib -- --test-threads=4
212 passed; 0 failed; 2 ignored     (exit 0)

cargo test --workspace --no-fail-fast -- --test-threads=4
498 passed; 0 failed; 7 ignored     (exit 0)

The new without_skips_keeps_execz_guard_over_vcc_loop test passed on the RTX 5070 Ti for both per-lane and wave-wide lowering; the run did not print the "not run" message, so it dispatched on the SM 6.6 hardware device. The ir-side test without_skips_keeps_execz_over_vcc_loops_and_strips_scalar_loops also passes. This adds an independent Blackwell wave32 run of the new tests at bbfe4261 on main 2119b0e.

Not tested: release profile, native wave64 (not available here), AMD/Intel GPUs, Wine, the full title.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-24 23:47 UTC · [original](https://github.com/fxceless/victory-fork/pull/262#issuecomment-7147791867) Ran the new s_cbranch_execz tests and the full workspace at bbfe4261: Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.98.1 (48a229cea 2026-09-01), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` cargo test -p victory-shader --lib without_skips_keeps_execz -- --test-threads=4 --nocapture 2 passed; 0 failed; 0 ignored (exit 0) cargo test -p victory-shader --lib -- --test-threads=4 212 passed; 0 failed; 2 ignored (exit 0) cargo test --workspace --no-fail-fast -- --test-threads=4 498 passed; 0 failed; 7 ignored (exit 0) ``` The new `without_skips_keeps_execz_guard_over_vcc_loop` test passed on the RTX 5070 Ti for both per-lane and wave-wide lowering; the run did not print the "not run" message, so it dispatched on the SM 6.6 hardware device. The ir-side test `without_skips_keeps_execz_over_vcc_loops_and_strips_scalar_loops` also passes. This adds an independent Blackwell wave32 run of the new tests at `bbfe4261` on main `2119b0e`. Not tested: release profile, native wave64 (not available here), AMD/Intel GPUs, Wine, the full title. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash 1017** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
Author
Owner

@⁠pr0vId3nce on GitHub · 2026-11-26 14:03 UTC · original

Some data on this from DexNom/VIctory on an RTX 4080 (32-lane waves). without_skips and without_early_outs there are identical to this repo's, so the same flaw is there.

This PR, ported unchanged to DexNom's main (shaders.rpf, VICTORY_HOST_MAX_WAVE=32, wave sizes from PSV0): all 2,682 compute programs still validate, but compute programs that need WaveSize(64) go from 29 to 56, and 89 programs change. With DexNom/VIctory#40 (the wave-wide form as a last resort) they go from 7 to 9. On NVIDIA a WaveSize(64) program gets no pipeline. Most of the cost comes from treating every VCC test and every inner execz on a cycle as a zero edge: in that tree, many exact 32-lane forms depend on dropping skips around waterfalls over EXEC and around counted loops.

A narrower guard keeps the same skips in front of the light-atlas loops, and costs nothing in that census (29 → 29, 21 programs change). It works out which masks are actually empty with no lane left (EXEC, lane compares and the scalar mask arithmetic on them), lets counted loops through, and still keeps the skip around a loop on a v_readfirstlane scalar. It is up for review as DexNom/VIctory#71, which credits this PR for the cause.

without_early_outs. Guarding it the same way cost 11 programs their 32-lane form in DexNom's tree (tree instance culling, shadow masks), so the DexNom PR leaves it out for now.

Runs (prologue save, VICTORY_WAVE_WIDE=1, DRED): unmodified DexNom main lost the device about 105 s in, 7 s after both light-atlas programs were first bound, with an indirect dispatch of c06aa62112ffba4c in flight. That matches what this PR describes. With the narrower guard it ran 306 s with no device loss, with both light-atlas programs bound for the last 3 minutes.

AI-assisted (Claude Code); measured on my machine. No game data: counts, hashes and log lines only.

**@⁠pr0vId3nce** on GitHub · 2026-11-26 14:03 UTC · [original](https://github.com/fxceless/victory-fork/pull/262#issuecomment-7194223087) Some data on this from DexNom/VIctory on an RTX 4080 (32-lane waves). `without_skips` and `without_early_outs` there are identical to this repo's, so the same flaw is there. **This PR, ported unchanged to DexNom's main** (`shaders.rpf`, `VICTORY_HOST_MAX_WAVE=32`, wave sizes from `PSV0`): all 2,682 compute programs still validate, but compute programs that need `WaveSize(64)` go from 29 to 56, and 89 programs change. With DexNom/VIctory#40 (the wave-wide form as a last resort) they go from 7 to 9. On NVIDIA a `WaveSize(64)` program gets no pipeline. Most of the cost comes from treating every VCC test and every inner `execz` on a cycle as a zero edge: in that tree, many exact 32-lane forms depend on dropping skips around waterfalls over EXEC and around counted loops. **A narrower guard** keeps the same skips in front of the light-atlas loops, and costs nothing in that census (29 → 29, 21 programs change). It works out which masks are actually empty with no lane left (EXEC, lane compares and the scalar mask arithmetic on them), lets counted loops through, and still keeps the skip around a loop on a `v_readfirstlane` scalar. It is up for review as DexNom/VIctory#71, which credits this PR for the cause. **`without_early_outs`.** Guarding it the same way cost 11 programs their 32-lane form in DexNom's tree (tree instance culling, shadow masks), so the DexNom PR leaves it out for now. **Runs** (prologue save, `VICTORY_WAVE_WIDE=1`, DRED): unmodified DexNom main lost the device about 105 s in, 7 s after both light-atlas programs were first bound, with an indirect dispatch of `c06aa62112ffba4c` in flight. That matches what this PR describes. With the narrower guard it ran 306 s with no device loss, with both light-atlas programs bound for the last 3 minutes. _AI-assisted (Claude Code); measured on my machine. No game data: counts, hashes and log lines only._
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/262/head:github-bot/gh-262'
git switch 'github-bot/gh-262'

Merge

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