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
SPOOKEXE added a commit to SPOOKEXE/victory-fork that referenced this pull request Nov 26, 2026
…port of upstream fxceless#262); shader names listed in a file (VICTORY_SHADER_NAMES); nothing held from the wide form by default
@pr0vId3nce

Copy link
Copy Markdown

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 added a commit to pr0vId3nce/VIctory-NVIDIA that referenced this pull request Nov 26, 2026
…ith no lane left

Port of DexNom/VIctory#71 (b27921645, pr0vId3nce) and its follow-up
b60997d11 onto this tree; the cause was found first in
fxceless/victory-fork#262.

The "without skips" and "without early-outs" forms drop `s_cbranch_execz`
skips and early-outs, so a region the console only enters with lanes left
also runs with none. A loop whose exit waits for some lane (a lane
compare's VCC, empty then) never ends there, and every lane walks it to the
iteration limit: in the particle light-atlas sprite and trail programs,
with the group barriers of the wave-wide form in the loop nest (a GPU hang
on 32-lane cards).

Such a skip, or an early-out to the program's end, is now kept when the
code left running with no lane holds a loop that may not end there
(`goes_round`). Here the early-out test is `early_out_continuation`, which
both forms use, so the far-jump early-out (`s_cbranch_execnz` past a far
jump to the end) is guarded too.

(cherry picked from commit b27921645)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

3 participants