Skip to content

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

Open
xADEL wants to merge 1 commit into
fxceless:mainfrom
xADEL:shader/keep-execz-over-vcc-loops
Open

xADEL wants to merge 1 commit into
fxceless:mainfrom
xADEL:shader/keep-execz-over-vcc-loops

Conversation

@xADEL

@xADEL xADEL commented Nov 24, 2026

Copy link
Copy Markdown

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
@Aniseto

Aniseto commented Nov 24, 2026

Copy link
Copy Markdown

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

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.

PiloteCode added a commit to PiloteCode/victory-fork that referenced this pull request Nov 25, 2026
…am: 25,953 of 25,953), fxceless#196 loop exits with the host wave, fxceless#262 execz skips over loops, fxceless#213 a missing child is a miss, fxceless#788, fxceless#806, fxceless#748, fxceless#817 translate --hashes and translate-diff, fxceless#820, fxceless#694 one queue per test host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants