Shaders: keep s_cbranch_execz over loops that cannot exit when EXEC is 0 #262
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!262
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-262"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@xADEL on GitHub · 2026-11-24 23:02 UTC · original
xADEL:shader/keep-execz-over-vcc-loops→main· +254 −2 · 2 files · 1 commits · openProblem
ir::without_skips(bothdeep = falseanddeep = true) andir::without_early_outsstrips_cbranch_execzeven 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, ors_cbranch_scc0/s_cbranch_scc1fed by ans_and*withEXECorVCC).When an empty wave (
EXEC == 0) or inactive lane falls through into such a loop, every vector compare writes0(masked byEXEC), so the zero-mask branch stays on the loop cycle until the synthetic 4,096-iteration guard fires:ptfx_CS_lightAtlas_Sprite/_Trail), hitting the synthetic guard executesret void, silently dropping stores after the loop.VICTORY_WAVE_WIDE=1on 32-lane hosts, every empty wave falls into the loop and runs ~4,096 iterations × dozens of wave-wide group barriers (the hang that forcedVICTORY_WAVE_WIDEoff by default ine9765a7).Complementary to #83 and #196: #83 keeps
s_cbranch_execzwhen the skipped region reactivatesEXEC, and #196 usesWaveActiveAnyTruefor active-wavevccloop exits; whenEXEC == 0across the whole wave,vccis 0 in every lane so even a wave-wideWaveActiveAnyTruecannot exit and thes_cbranch_execzguard itself must be kept.What is in it
crates/victory-shader/src/ir.rs:has_empty_exec_loop(withreaches_within,reachable_from,scc_zero_under_empty_exec) and refuse to strips_cbranch_execzinwithout_early_outsandwithout_skipswhenever the guarded region contains a mask-branch whose zero-mask edge stays on a cycle within that region.s_cmp_lg_u32+s_cbranch_scc1) are still stripped as before.without_skips_keeps_execz_over_vcc_loops_and_strips_scalar_loopscoveringvccz,vccnz, early-outvccz, and scalar loops.crates/victory-shader/src/emit/wave64_tests.rs:without_skips_keeps_execz_guard_over_vcc_loop(validates DXIL withdxil.dlland dispatches on wave32 hardware under both per-lane and wave-wide lowering for empty, partial active/inactive, and full waves).Tested
32.0.16.2124, wave32, SM 6.6) + Intel(R) UHD Graphics (32.0.101.7026), Windows SDK10.0.26100.0(dxil.dllactive).bbfe426):cargo xtask policy->169 files okcargo clippy --workspace --all-targets --locked -- -D warnings-> 0 warningscargo clippy --workspace --all-targets --all-features --locked -- -D warnings-> 0 warningscargo 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 rejectsWaveSize(32)compute pipelines so hardware dispatch skips there)cargo test --locked -p victory-shader --lib wave64_tests-> 6 passed, 0 failedcargo test --locked -p xtask-> 4 passed, 0 failedcargo test --workspace --locked-> 500 passed, 0 failed, 7 ignored (verifiedwithout_skips_keeps_execz_guard_over_vcc_loopfailed withleft: 0, right: 7without their.rsfix and passed all 8 per-lane + wave-wide hardware dispatches with it).translate --validate --pipelineswithVICTORY_HOST_MAX_WAVE=32 VICTORY_WAVE_WIDE=1on RTX 3050:ptfx_CS_lightAtlas_*shaders (2561af9577c47289,c06aa62112ffba4c,cabb87599722e59a,e8f6ae0597846841) and 14CS_ShadowRenderTiled*shaders: 18/18 emitted,dxil.dll-validated, and created D3D12 pipelines; inspected disassembled DXIL for2561af9577c47289andc06aa62112ffba4cand confirmed the outer light loop now keeps its wave-wides_cbranch_execzguard.XboxBvhBuilder.dll(VICTORY_HOST_WAVE=32): 49/52 emitted, 49/49 validated, 49/49 pipelines (unchanged baseline).Not tested
VICTORY_WAVE_WIDE=1enabled (kept off by default pere9765a7).shaders.rpfcorpus translation sweep.AI use
Written and verified with Antigravity (model name not exposed in the agent environment).
@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.
The new
without_skips_keeps_execz_guard_over_vcc_looptest 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 testwithout_skips_keeps_execz_over_vcc_loops_and_strips_scalar_loopsalso passes. This adds an independent Blackwell wave32 run of the new tests atbbfe4261on main2119b0e.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.
@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_skipsandwithout_early_outsthere 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 fromPSV0): all 2,682 compute programs still validate, but compute programs that needWaveSize(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 aWaveSize(64)program gets no pipeline. Most of the cost comes from treating every VCC test and every innerexeczon 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_readfirstlanescalar. 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 ofc06aa62112ffba4cin 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.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.