Skip to content

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

Open
ryotdev wants to merge 1 commit into
fxceless:mainfrom
ryotdev:codex/preserve-empty-exec
Open

ryotdev wants to merge 1 commit into
fxceless:mainfrom
ryotdev:codex/preserve-empty-exec

Conversation

@ryotdev

@ryotdev ryotdev commented Nov 24, 2026

Copy link
Copy Markdown

An empty wave can skip an LDS store that the translated shader executes. If a comparison leaves no lanes active, s_cbranch_execz jumps over its body. Removing that branch lets a scalar s_mov_b64 exec, saved restore a nonempty mask and activate the store. The scalar values at the join can still agree, so the existing join check accepts the rewrite.

This changes both the early-out and skip-removal passes. They now check that each EXEC write in the skipped region preserves an empty mask. A nested save and restore can still be optimized when the restore reads the exact SSA value saved inside the region. This check covers lane reactivation. The save-and-mask semantics are in section 12.3 of the AMD RDNA 2 ISA reference.

Thanks to @Xeltax for narrowing #62 to a small set of compute programs. On the 14 lighting programs in that report, both builds produced 14/14 DXIL binaries that passed validation in 32-lane host mode. Eleven outputs stayed byte-identical. The three changed Cascades programs selected the existing approximate local-wave fallback. That establishes which translations changed. The visual impact needs a checkpoint comparison.

Tests

  • The hand-built GFX10 store regression fails on 4e17478 and passes here. It covers an early return, an external restore, an OR-save, and a safe nested restore. A second test takes a guarded vector write and a safe inner restore through the compute emitter.
  • VICTORY_HOST_WAVE=32 cargo test --offline --locked -p victory-shader --lib — 172 passed, 2 ignored.
  • Windows x64 diagnostics build passed. Native Windows DXIL validation used one translation job. The repository asset check passed for 169 files.

AI-assisted implementation and review. Tests use hand-built inputs.

@adriaespii

Copy link
Copy Markdown

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.

@arminkhaleghirod

Copy link
Copy Markdown

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.

@YeokiNoewChi

Copy link
Copy Markdown

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.

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.

4 participants