Shaders: leave out branches no lane takes before lowering (works around an out-of-memory pipeline creation) #172

Closed
adrianmjim wants to merge 5 commits from upstream-pr/172 into main
adrianmjim commented 2026-11-25 18:48:08 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T18:48:08Z.


The structure pass proves many branch conditions constant per lane: the console compiler's scalar mask tests, s_cbranch_vccz on exec & mask where every lane holds the mask, and so on. Lowering emitted them as br i1 true / br i1 false with both successors, so the code behind the side no lane takes stayed in the DXIL for the host compiler to remove.

emit() now turns such branches into jumps (Structured::one_way, ir::retarget). It then empties the blocks that become unreachable, reruns SSA renaming, SGPR spill forwarding, structure, I/O and resource tracking, and emits the result in the per-lane form. Some cases are left alone:

  • Loop back edges. If the side every lane takes is a loop's back edge, the branch stays. Lowering counts loop iterations, and at LOOP_LIMIT a lane leaves through the branch's other side. As a jump, it would leave the program instead.
  • Programs that do not lower as they are, unthreaded. emit() first runs the existing unthreaded emit of the program as it is, and prunes only if that succeeds. A program that needs threading is threaded exactly as before.
  • The console flow. If the program as it is asks for the console flow (lower::wants_console_flow, with the wider numeric-select test, which can only flag more programs), nothing is pruned. The pruned form is emitted without the console flow. If it would ask for it, that emit fails and the original is used. The console flow runs blocks that no lane reaches, so pruning should not change which form a program gets.

If anything on the pruned path fails, the program is emitted exactly as before.

Why

CS_ScreenProbes_ActivateRays_d60186e6 is the one compute program in the title's shaders.rpf whose host pipeline could not be created on an RX 7900 XT:

  • In a --pipelines run, CreateComputePipelineState returned E_OUTOFMEMORY.
  • Run alone, the process passed 20 GB private before it was stopped.

Its module on main is 1,152,156 bytes. Pruned, it is 236,444 bytes, it validates, and the pipeline is created (about 210 s and a 3.9 GB peak on an uncached compile).

This is a workaround, not a root-cause fix. CS_ScreenProbes_ActivateProbes has an even larger dead share (about 905 KB down to 153 KB) and compiles in under 10 s without this change. So dead code alone is not what the driver chokes on. Pruning brings ActivateRays under whatever the actual trigger is, which I have not found.

Tested

On an RX 7900 XT (Windows 11 build 26300, Rust 1.98.1, dxil.dll from Windows Kits 10.0.26100.0), on 000ffdd:

  • cargo test -p victory-shader --lib -- --test-threads=1: 271 passed, 0 failed, 6 ignored (main: 266, plus the 5 tests below).
  • New tests use synthetic GFX10 words only and run on the default adapter:
    • a branch no lane takes one way of is left out: the DXIL is smaller and validates, with the same per-lane results as unpruned;
    • a loop stopped at the iteration limit leaves through its exit: the same stored values pruned and unpruned (with the back edge made a jump, it stored nothing);
    • a program asking for the console flow only through dead code is emitted byte-identical to the unpruned path;
    • a program asking for the console flow only once pruned (its permutation was dead) is emitted as it is;
    • structure::a_branch_no_lane_takes_is_cut covers one_way and retarget.
    • Each of the first three fails when the corresponding exclusion is switched off locally. The "unthreaded first" rule has no unit test; the corpus run below shows its effect.
  • victory translate --validate --list --host-lanes 32-64 over the title's shaders.rpf: every count is the same as on main (VS/PS 14,247/14,247, CS 2,682/2,682, MS 8,694 of 8,765 emitted and validated, the same 195 + 71 refusals).
  • With a local, uncommitted per-program DXIL hash list:
    • 2,566 programs change (1,752 PS, 809 CS, 3 VS, 2 MS), and all of them validate.
    • Pipelines were created for every changed program (--pipelines) and for all 2,581 compute programs named CS_*, ActivateRays included.
    • 4 programs whose originals need threading keep main's output byte for byte.

Not tested

  • No game run. The game was not run here (no executable), so this shows only that the shaders translate, validate and create pipelines, not that they render the same. Equal results pruned and unpruned are shown for the synthetic test programs only.
  • Driver shader cache. Most pipeline creations in these runs probably hit the AMD driver's shader cache (a repeat of the same DXIL takes seconds). The ActivateRays timing above is from an uncached compile.
  • Other hardware. Only an AMD RDNA3 host (32-64 lanes) was used. The new GPU tests are Windows-only, like the other emit GPU tests.

Relation to #97

#97 adds opt-in clean-up passes over the finished bitcode (VICTORY_SHADER_OPT, off by default). Its FOLD pass also prunes constant branches, but it only sees branches the lowering already wrote as br i1 <constant>. This change works one stage earlier and is always on: it uses the structure pass's per-lane proof, and the loop-limit and console-flow cases stay explicit.

The two compose. #97 applies cleanly on top of this branch, and the combined tree passes all 295 victory-shader lib tests. On ActivateRays:

DXIL bytes validates
main 1,152,156 yes
this PR 236,444 yes
#97 alone, all passes 147,544 yes
both, all passes 120,216 yes

One thing for #97: with FOLD alone (VICTORY_SHADER_OPT=2) or 0x1e, this shader fails validation ("Instructions should not read uninitialized value"), with and without this PR. FOLD seems to need DEAD there.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5497192730 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T18:48:08Z. --- The structure pass proves many branch conditions constant per lane: the console compiler's scalar mask tests, `s_cbranch_vccz` on `exec & mask` where every lane holds the mask, and so on. Lowering emitted them as `br i1 true` / `br i1 false` with both successors, so the code behind the side no lane takes stayed in the DXIL for the host compiler to remove. `emit()` now turns such branches into jumps (`Structured::one_way`, `ir::retarget`). It then empties the blocks that become unreachable, reruns SSA renaming, SGPR spill forwarding, structure, I/O and resource tracking, and emits the result in the per-lane form. Some cases are left alone: - **Loop back edges.** If the side every lane takes is a loop's back edge, the branch stays. Lowering counts loop iterations, and at `LOOP_LIMIT` a lane leaves through the branch's other side. As a jump, it would leave the program instead. - **Programs that do not lower as they are, unthreaded.** `emit()` first runs the existing unthreaded emit of the program as it is, and prunes only if that succeeds. A program that needs threading is threaded exactly as before. - **The console flow.** If the program as it is asks for the console flow (`lower::wants_console_flow`, with the wider numeric-select test, which can only flag more programs), nothing is pruned. The pruned form is emitted without the console flow. If it would ask for it, that emit fails and the original is used. The console flow runs blocks that no lane reaches, so pruning should not change which form a program gets. If anything on the pruned path fails, the program is emitted exactly as before. ## Why `CS_ScreenProbes_ActivateRays_d60186e6` is the one compute program in the title's `shaders.rpf` whose host pipeline could not be created on an RX 7900 XT: - In a `--pipelines` run, `CreateComputePipelineState` returned `E_OUTOFMEMORY`. - Run alone, the process passed 20 GB private before it was stopped. Its module on `main` is 1,152,156 bytes. Pruned, it is 236,444 bytes, it validates, and the pipeline is created (about 210 s and a 3.9 GB peak on an uncached compile). **This is a workaround, not a root-cause fix.** `CS_ScreenProbes_ActivateProbes` has an even larger dead share (about 905 KB down to 153 KB) and compiles in under 10 s without this change. So dead code alone is not what the driver chokes on. Pruning brings ActivateRays under whatever the actual trigger is, which I have not found. ## Tested On an RX 7900 XT (Windows 11 build 26300, Rust 1.98.1, dxil.dll from Windows Kits 10.0.26100.0), on `000ffdd`: - `cargo test -p victory-shader --lib -- --test-threads=1`: 271 passed, 0 failed, 6 ignored (`main`: 266, plus the 5 tests below). - New tests use synthetic GFX10 words only and run on the default adapter: - a branch no lane takes one way of is left out: the DXIL is smaller and validates, with the same per-lane results as unpruned; - a loop stopped at the iteration limit leaves through its exit: the same stored values pruned and unpruned (with the back edge made a jump, it stored nothing); - a program asking for the console flow only through dead code is emitted byte-identical to the unpruned path; - a program asking for the console flow only once pruned (its permutation was dead) is emitted as it is; - `structure::a_branch_no_lane_takes_is_cut` covers `one_way` and `retarget`. - Each of the first three fails when the corresponding exclusion is switched off locally. The "unthreaded first" rule has no unit test; the corpus run below shows its effect. - `victory translate --validate --list --host-lanes 32-64` over the title's `shaders.rpf`: every count is the same as on `main` (VS/PS 14,247/14,247, CS 2,682/2,682, MS 8,694 of 8,765 emitted and validated, the same 195 + 71 refusals). - With a local, uncommitted per-program DXIL hash list: - 2,566 programs change (1,752 PS, 809 CS, 3 VS, 2 MS), and all of them validate. - Pipelines were created for every changed program (`--pipelines`) and for all 2,581 compute programs named `CS_*`, ActivateRays included. - 4 programs whose originals need threading keep `main`'s output byte for byte. ## Not tested - **No game run.** The game was not run here (no executable), so this shows only that the shaders translate, validate and create pipelines, not that they render the same. Equal results pruned and unpruned are shown for the synthetic test programs only. - **Driver shader cache.** Most pipeline creations in these runs probably hit the AMD driver's shader cache (a repeat of the same DXIL takes seconds). The ActivateRays timing above is from an uncached compile. - **Other hardware.** Only an AMD RDNA3 host (32-64 lanes) was used. The new GPU tests are Windows-only, like the other emit GPU tests. ## Relation to #97 #97 adds opt-in clean-up passes over the finished bitcode (`VICTORY_SHADER_OPT`, off by default). Its FOLD pass also prunes constant branches, but it only sees branches the lowering already wrote as `br i1 <constant>`. This change works one stage earlier and is always on: it uses the structure pass's per-lane proof, and the loop-limit and console-flow cases stay explicit. The two compose. #97 applies cleanly on top of this branch, and the combined tree passes all 295 victory-shader lib tests. On ActivateRays: | | DXIL bytes | validates | |---|---|---| | `main` | 1,152,156 | yes | | this PR | 236,444 | yes | | #97 alone, all passes | 147,544 | yes | | both, all passes | 120,216 | yes | One thing for #97: with FOLD alone (`VICTORY_SHADER_OPT=2`) or `0x1e`, this shader fails validation ("Instructions should not read uninitialized value"), with and without this PR. FOLD seems to need DEAD there.
copilot-pull-request-reviewer[bot] commented 2026-11-25 18:51:56 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T18:51:56Z.

Review: COMMENTED


The unthreaded-success gate lacks a regression test confirming that a program which fails unthreaded emission but succeeds after threading preserves byte-identical output.

1 open issue
What changed in this PR

This PR removes branches that no shader lane takes before DXIL lowering, reducing generated code to work around excessive host compiler memory use during pipeline creation.

Changes:

  • Detects constant per-lane branches, removes unreachable code, and rebuilds shader analyses.
  • Preserves loop-limit exits, console-flow behavior, and the existing fallback when pruning cannot safely apply.
  • Adds synthetic tests for pruning, equivalent GPU results, and compatibility exclusions.
File Description
crates/​victory-shader/​src/​structure.rs Identifies one-way lane branches and tests branch retargeting.
crates/​victory-shader/​src/​ir.rs Retargets branches, empties unreachable blocks, and rebuilds SSA.
crates/​victory-shader/​src/​emit/​prune_tests.rs Tests pruning results, loop exits, and console-flow exclusions.
crates/​victory-shader/​src/​emit/​mod.rs Integrates guarded pruning while preserving the original emission fallback.
crates/​victory-shader/​src/​emit/​lower.rs Exposes a conservative console-flow eligibility check.

Review effort: Balanced

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6063211823 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#pullrequestreview-6063211823). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T18:51:56Z. **Review:** COMMENTED --- <!-- ccr-overview-v2 --> ### 🟡 Changes recommended The unthreaded-success gate lacks a regression test confirming that a program which fails unthreaded emission but succeeds after threading preserves byte-identical output. <details open> <summary><strong>1 open issue</strong></summary> - <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/low-v2-light.png" alt="Low severity" width="62" height="18" align="texttop"></picture> [Add regression test for unthreaded emission compatibility](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#discussion_r4699433965) · New </details> <details> <summary><strong>What changed in this PR</strong></summary> This PR removes branches that no shader lane takes before DXIL lowering, reducing generated code to work around excessive host compiler memory use during pipeline creation. **Changes:** - Detects constant per-lane branches, removes unreachable code, and rebuilds shader analyses. - Preserves loop-limit exits, console-flow behavior, and the existing fallback when pruning cannot safely apply. - Adds synthetic tests for pruning, equivalent GPU results, and compatibility exclusions. | File | Description | | ---- | ----------- | | `crates/​victory-shader/​src/​structure.rs` | Identifies one-way lane branches and tests branch retargeting. | | `crates/​victory-shader/​src/​ir.rs` | Retargets branches, empties unreachable blocks, and rebuilds SSA. | | `crates/​victory-shader/​src/​emit/​prune_tests.rs` | Tests pruning results, loop exits, and console-flow exclusions. | | `crates/​victory-shader/​src/​emit/​mod.rs` | Integrates guarded pruning while preserving the original emission fallback. | | `crates/​victory-shader/​src/​emit/​lower.rs` | Exposes a conservative console-flow eligibility check. | </details> <sub>Review effort: Balanced</sub>
Copilot commented 2026-11-25 18:51:56 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Copilot on 2026-11-25T18:51:56Z.

Code review location: crates/victory-shader/src/emit/mod.rs; line 339

@@ -330,7 +332,103 @@ pub fn emit(
     res: &resource::Resources,
     target: Target,
 ) -> Result<HostShader, ShaderError> {
-    let original = emit_program(c, native, p, st, io, res, target);
+    let original = emit_program(c, native, p, st, io, res, target, true);
+    // Pruned only where the program lowers as it is, unthreaded: what the
+    // console flow check below looks at is then the program emitted.
+    if original.is_ok()
+        && let Some(made) = emit_without_dead_branches(c, native, p, st, io, res, target)

The unthreaded-success gate has no regression test: the new tests cover pruning and both console-flow exclusions, while threading.rs tests only the IR transformation. Please add a synthetic program with a prunable branch that fails unthreaded emission but succeeds after threading, and assert that emit() stays byte-identical to emit_threaded(..., true). This would protect the compatibility rule currently checked only by the external shader corpus.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4699433965 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#discussion_r4699433965). Originally posted by [Copilot](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T18:51:56Z. **Code review location:** `crates/victory-shader/src/emit/mod.rs`; line 339 ~~~~diff @@ -330,7 +332,103 @@ pub fn emit( res: &resource::Resources, target: Target, ) -> Result<HostShader, ShaderError> { - let original = emit_program(c, native, p, st, io, res, target); + let original = emit_program(c, native, p, st, io, res, target, true); + // Pruned only where the program lowers as it is, unthreaded: what the + // console flow check below looks at is then the program emitted. + if original.is_ok() + && let Some(made) = emit_without_dead_branches(c, native, p, st, io, res, target) ~~~~ --- The unthreaded-success gate has no regression test: the new tests cover pruning and both console-flow exclusions, while `threading.rs` tests only the IR transformation. Please add a synthetic program with a prunable branch that fails unthreaded emission but succeeds after threading, and assert that `emit()` stays byte-identical to `emit_threaded(..., true)`. This would protect the compatibility rule currently checked only by the external shader corpus.
KernelSmoker commented 2026-11-25 18:57:51 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by KernelSmoker on 2026-11-25T18:57:51Z.


Independent verification on PR head bfe84ee (Bazzite Linux 45 x86_64, Rust 1.98.1, NVIDIA RTX 3090 driver 620.73.04):

  • Linux cargo test --locked -p victory-shader: 186 passed, 0 failed, 6 ignored (lib, including structure::tests::a_branch_no_lane_takes_is_cut) + 3 passed, 0 failed, 1 ignored (tests/resource_tracking.rs).
  • Windows GNU victory-shader test binary run under GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0 on NVIDIA RTX 3090 (32-lane warp):
    • emit::prune_tests (--test-threads=1): 4 passed, 0 failed (a_branch_no_lane_takes_one_way_of_is_left_out, a_loop_stopped_at_the_iteration_limit_leaves_through_its_exit, a_program_asking_for_the_console_flow_is_emitted_as_it_is, a_program_asking_for_the_console_flow_only_pruned_is_emitted_as_it_is).
  • cargo check --workspace --all-targets --locked --target x86_64-pc-windows-gnu: passed.

No game run or shaders.rpf corpus translation was performed here; this verifies the Linux unit tests and the 4 synthetic GPU execution tests on NVIDIA RTX 3090.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7171638717 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7171638717). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-25T18:57:51Z. --- Independent verification on PR head `bfe84ee` (Bazzite Linux 45 x86_64, Rust 1.98.1, NVIDIA RTX 3090 driver 620.73.04): - Linux `cargo test --locked -p victory-shader`: **186 passed, 0 failed, 6 ignored** (lib, including `structure::tests::a_branch_no_lane_takes_is_cut`) + **3 passed, 0 failed, 1 ignored** (`tests/resource_tracking.rs`). - Windows GNU `victory-shader` test binary run under GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0 on **NVIDIA RTX 3090** (32-lane warp): - `emit::prune_tests` (`--test-threads=1`): **4 passed, 0 failed** (`a_branch_no_lane_takes_one_way_of_is_left_out`, `a_loop_stopped_at_the_iteration_limit_leaves_through_its_exit`, `a_program_asking_for_the_console_flow_is_emitted_as_it_is`, `a_program_asking_for_the_console_flow_only_pruned_is_emitted_as_it_is`). - `cargo check --workspace --all-targets --locked --target x86_64-pc-windows-gnu`: passed. No game run or `shaders.rpf` corpus translation was performed here; this verifies the Linux unit tests and the 4 synthetic GPU execution tests on NVIDIA RTX 3090.
adrianmjim commented 2026-11-25 19:06:32 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T19:06:32Z.

Code review location: crates/victory-shader/src/emit/mod.rs; line 339

@@ -330,7 +332,103 @@ pub fn emit(
     res: &resource::Resources,
     target: Target,
 ) -> Result<HostShader, ShaderError> {
-    let original = emit_program(c, native, p, st, io, res, target);
+    let original = emit_program(c, native, p, st, io, res, target, true);
+    // Pruned only where the program lowers as it is, unthreaded: what the
+    // console flow check below looks at is then the program emitted.
+    if original.is_ok()
+        && let Some(made) = emit_without_dead_branches(c, native, p, st, io, res, target)

Added in 891a7ad: a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned (GPU-free, in emit/prune_tests.rs).

The program is ONE_WAY (one branch no lane takes one way of) followed by a uniform fork on the group's x: one way sets m0 and a flag, and the join reads m0 only where the flag is set. As it is, the join takes m0 from both ways, from the other as the hardware left it, so emit_program(.., true) fails with Unsupported { what: "a hardware SGPR input" } (the error 3 of the 4 programs of the title's archive that meet this check hit). Threading sends the fork's other way past the read, and emit_threaded(.., true) lowers it.

The test asserts that emit() returns the same HostShader as emit_threaded(.., true), and that emit_without_dead_branches would have given a different program (it prunes, then threads the pruned form). With the check replaced by true the test fails. cargo test -p victory-shader --lib -- --test-threads=1: 272 passed, 0 failed, 6 ignored (RX 7900 XT, Windows 11).

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4699591590 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#discussion_r4699591590). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T19:06:32Z. **Code review location:** `crates/victory-shader/src/emit/mod.rs`; line 339 ~~~~diff @@ -330,7 +332,103 @@ pub fn emit( res: &resource::Resources, target: Target, ) -> Result<HostShader, ShaderError> { - let original = emit_program(c, native, p, st, io, res, target); + let original = emit_program(c, native, p, st, io, res, target, true); + // Pruned only where the program lowers as it is, unthreaded: what the + // console flow check below looks at is then the program emitted. + if original.is_ok() + && let Some(made) = emit_without_dead_branches(c, native, p, st, io, res, target) ~~~~ --- Added in `891a7ad`: `a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned` (GPU-free, in `emit/prune_tests.rs`). The program is `ONE_WAY` (one branch no lane takes one way of) followed by a uniform fork on the group's x: one way sets m0 and a flag, and the join reads m0 only where the flag is set. As it is, the join takes m0 from both ways, from the other as the hardware left it, so `emit_program(.., true)` fails with `Unsupported { what: "a hardware SGPR input" }` (the error 3 of the 4 programs of the title's archive that meet this check hit). Threading sends the fork's other way past the read, and `emit_threaded(.., true)` lowers it. The test asserts that `emit()` returns the same `HostShader` as `emit_threaded(.., true)`, and that `emit_without_dead_branches` would have given a different program (it prunes, then threads the pruned form). With the check replaced by `true` the test fails. `cargo test -p victory-shader --lib -- --test-threads=1`: 272 passed, 0 failed, 6 ignored (RX 7900 XT, Windows 11).
adrianmjim commented 2026-11-25 19:06:34 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T19:06:34Z.


Thanks @KernelSmoker, good to have it on a 32-lane NVIDIA card. Since then 891a7ad adds one test, a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned, for the check that prunes only programs that lower unthreaded. It needs no GPU, so the Linux run covers it too, if you rerun.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7171830738 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7171830738). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T19:06:34Z. --- Thanks @KernelSmoker, good to have it on a 32-lane NVIDIA card. Since then `891a7ad` adds one test, `a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned`, for the check that prunes only programs that lower unthreaded. It needs no GPU, so the Linux run covers it too, if you rerun.
KernelSmoker commented 2026-11-25 19:16:41 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by KernelSmoker on 2026-11-25T19:16:41Z.


Re-verified updated PR head 891a7ad (Bazzite Linux 45 x86_64, Rust 1.98.1, NVIDIA RTX 3090):

  • Windows GNU victory-shader test binary under GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0 on NVIDIA RTX 3090:
    • emit::prune_tests (--test-threads=1): 5 passed, 0 failed, including the new a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned.
  • Linux cargo test --locked -p victory-shader: 186 passed, 0 failed, 6 ignored (lib) + 3 passed, 0 failed, 1 ignored (resource_tracking).
  • Quick heads-up: mod prune_tests; in crates/victory-shader/src/emit/mod.rs:101 is gated by #[cfg(all(test, windows))], so a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned does not currently run on Linux (0 matched when filtering for it on Linux). Gating only the GPU-running tests/helpers inside prune_tests.rs with #[cfg(windows)] would let the non-GPU tests run on Linux too.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7172073578 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7172073578). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-25T19:16:41Z. --- Re-verified updated PR head `891a7ad` (Bazzite Linux 45 x86_64, Rust 1.98.1, NVIDIA RTX 3090): - Windows GNU `victory-shader` test binary under GE-Proton 10-34 / Wine 10.0 / vkd3d-proton 3.0.0 on **NVIDIA RTX 3090**: - `emit::prune_tests` (`--test-threads=1`): **5 passed, 0 failed**, including the new `a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned`. - Linux `cargo test --locked -p victory-shader`: **186 passed, 0 failed, 6 ignored** (lib) + **3 passed, 0 failed, 1 ignored** (`resource_tracking`). - Quick heads-up: `mod prune_tests;` in `crates/victory-shader/src/emit/mod.rs:101` is gated by `#[cfg(all(test, windows))]`, so `a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned` does not currently run on Linux (0 matched when filtering for it on Linux). Gating only the GPU-running tests/helpers inside `prune_tests.rs` with `#[cfg(windows)]` would let the non-GPU tests run on Linux too.
adrianmjim commented 2026-11-25 19:20:04 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T19:20:04Z.


Thanks, you're right: I claimed the Linux run would cover it and it didn't. 7304965 builds prune_tests everywhere (#[cfg(test)]); only the GPU runs (one runs() helper, None off Windows, as without an SM 6.6 device) and the DXIL validator stay Windows only. So on Linux all five tests now run their translation checks, including a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned, which needs no GPU at all.

Checked here on Windows (RX 7900 XT): cargo test -p victory-shader --lib -- --test-threads=1 272 passed, 0 failed, 6 ignored; the five prune tests pass with the GPU runs. I have no Linux target installed, so I checked the off-Windows path by building it on Windows with the two cfgs swapped: the five pass, the two GPU runs report skipped, and no new warnings. A Linux run of the new head would confirm it for real.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7172151138 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7172151138). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T19:20:04Z. --- Thanks, you're right: I claimed the Linux run would cover it and it didn't. `7304965` builds `prune_tests` everywhere (`#[cfg(test)]`); only the GPU runs (one `runs()` helper, `None` off Windows, as without an SM 6.6 device) and the DXIL validator stay Windows only. So on Linux all five tests now run their translation checks, including `a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned`, which needs no GPU at all. Checked here on Windows (RX 7900 XT): `cargo test -p victory-shader --lib -- --test-threads=1` 272 passed, 0 failed, 6 ignored; the five prune tests pass with the GPU runs. I have no Linux target installed, so I checked the off-Windows path by building it on Windows with the two `cfg`s swapped: the five pass, the two GPU runs report skipped, and no new warnings. A Linux run of the new head would confirm it for real.
KernelSmoker commented 2026-11-25 19:24:13 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by KernelSmoker on 2026-11-25T19:24:13Z.


Confirmed on Linux at PR head 7304965 (Bazzite Linux 45 x86_64, Rust 1.98.1):

  • cargo test --locked -p victory-shader prune_tests -- --nocapture: 5 passed, 0 failed (the two GPU runs print no D3D12 host off Windows; skipped, all 5 translation checks including a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned run and pass, and no new warnings in prune_tests.rs).
  • Full cargo test --locked -p victory-shader: 191 passed, 0 failed, 6 ignored (lib) + 3 passed, 0 failed, 1 ignored (tests/resource_tracking.rs).
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7172245566 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7172245566). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-25T19:24:13Z. --- Confirmed on Linux at PR head `7304965` (Bazzite Linux 45 x86_64, Rust 1.98.1): - `cargo test --locked -p victory-shader prune_tests -- --nocapture`: **5 passed, 0 failed** (the two GPU runs print `no D3D12 host off Windows; skipped`, all 5 translation checks including `a_program_that_lowers_only_threaded_is_emitted_threaded_not_pruned` run and pass, and no new warnings in `prune_tests.rs`). - Full `cargo test --locked -p victory-shader`: **191 passed, 0 failed, 6 ignored** (lib) + **3 passed, 0 failed, 1 ignored** (`tests/resource_tracking.rs`).
adrianmjim commented 2026-11-25 23:30:24 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T23:30:24Z.


Update after main moved to 4f62c2a, which changes what this PR is for.

The out-of-memory case is gone on main. The clean-up passes (ae75a66, on by default) bring CS_ScreenProbes_ActivateRays from 1,152,156 to 147,544 bytes of DXIL on their own, and the pipeline is created. Without VICTORY_RAYS, 6986a57 also leaves that program out in the game. So the description's "Why" no longer holds as written.

What pruning still changes on top of the passes. Measured over shaders.rpf with translate --validate --list --host-lanes 32-64, 4f62c2a against 4f62c2a + this branch, with the passes on and every program's DXIL hashed and dumped:

  • 693 of 25,623 programs change: 599 pixel, 89 compute, 3 vertex and 2 mesh. Every one of them still validates, and every one whose size changes gets smaller. The validated counts and refusals are the same on both.
  • The total is small: about 65 KB less DXIL. ActivateRays gives 27 KB of it, going from 147,544 to 120,216 bytes (−18.5%).
  • What the passes leave behind, in compute programs: the cross-lane join code that the lowering emits for a dead predecessor (join_scalars: a rank, WaveActiveMax, a select per scalar). In ActivateRays there are 986 waveActiveOp calls as it is and 405 pruned. The passes fold the branch but keep those calls.
  • What the passes leave behind, in pixel programs: module-level declarations that come from the dead code (samplers, an SRV, SV_Barycentrics and its feature flag, interpolation modes). For example, ptfx PS_Transmission_alphathreshold_mv_uvdistort goes from 6,328 to 3,632 bytes. Pruning also changes the pixel input signature there (those inputs become linear, and SV_Barycentrics is gone), but only for inputs that the live code doesn't read.
  • The cost: a program with a forward one-way branch is lowered and optimised twice, once as it is (the original.is_ok() check) and once pruned.
  • The pipeline: creating ActivateRays on an RX 7900 XT with a cold driver cache took 168 s against 195 s and about 2.9 GB against 3.1 GB of peak memory. That is one run each, on a loaded machine, with a diagnostics build whose loop limit was changed so the driver cache was cold, and the times include translation. So read it only as "somewhat less".

The tests. Merged with 4f62c2a, three of the prune tests failed. The FOLD pass alone makes the unpruned module of those small programs byte-identical to the pruned one, and with the passes off they all pass. The branch now merges main (no conflicts) and dc66cba does two things:

  • The one-way, loop and threaded tests compare what the lowering makes, with the passes off. A #[cfg(test)] per-thread override of shader_opt() does this; production is unchanged.
  • A new test checks with the passes on that pruning still changes the module. It uses a scalar taken from the group id, so a later fold of wave operations on constants would not remove the difference.

cargo test -p victory-shader --lib -- --test-threads=1: 284 passed, 0 failed, 6 ignored. Two mutations were checked:

  • turning pruning off fails the one-way, loop, threaded and new tests;
  • replacing the original.is_ok() check with true fails the threaded test.

So this is now a smaller and somewhat cheaper-to-compile module for about 700 programs, not a fix for a pipeline that could not be created. Whether that is worth a second lowering for those programs is your call. I'm fine closing it if not.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7177654774 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7177654774). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T23:30:24Z. --- Update after `main` moved to `4f62c2a`, which changes what this PR is for. **The out-of-memory case is gone on `main`.** The clean-up passes (`ae75a66`, on by default) bring `CS_ScreenProbes_ActivateRays` from 1,152,156 to 147,544 bytes of DXIL on their own, and the pipeline is created. Without `VICTORY_RAYS`, `6986a57` also leaves that program out in the game. So the description's "Why" no longer holds as written. **What pruning still changes on top of the passes.** Measured over `shaders.rpf` with `translate --validate --list --host-lanes 32-64`, `4f62c2a` against `4f62c2a` + this branch, with the passes on and every program's DXIL hashed and dumped: - **693 of 25,623 programs change:** 599 pixel, 89 compute, 3 vertex and 2 mesh. Every one of them still validates, and every one whose size changes gets smaller. The validated counts and refusals are the same on both. - **The total is small:** about 65 KB less DXIL. `ActivateRays` gives 27 KB of it, going from 147,544 to 120,216 bytes (−18.5%). - **What the passes leave behind, in compute programs:** the cross-lane join code that the lowering emits for a dead predecessor (`join_scalars`: a rank, `WaveActiveMax`, a select per scalar). In `ActivateRays` there are 986 `waveActiveOp` calls as it is and 405 pruned. The passes fold the branch but keep those calls. - **What the passes leave behind, in pixel programs:** module-level declarations that come from the dead code (samplers, an SRV, `SV_Barycentrics` and its feature flag, interpolation modes). For example, `ptfx` `PS_Transmission_alphathreshold_mv_uvdistort` goes from 6,328 to 3,632 bytes. Pruning also changes the pixel input signature there (those inputs become linear, and `SV_Barycentrics` is gone), but only for inputs that the live code doesn't read. - **The cost:** a program with a forward one-way branch is lowered and optimised twice, once as it is (the `original.is_ok()` check) and once pruned. - **The pipeline:** creating `ActivateRays` on an RX 7900 XT with a cold driver cache took 168 s against 195 s and about 2.9 GB against 3.1 GB of peak memory. That is one run each, on a loaded machine, with a diagnostics build whose loop limit was changed so the driver cache was cold, and the times include translation. So read it only as "somewhat less". **The tests.** Merged with `4f62c2a`, three of the prune tests failed. The `FOLD` pass alone makes the unpruned module of those small programs byte-identical to the pruned one, and with the passes off they all pass. The branch now merges `main` (no conflicts) and `dc66cba` does two things: - The one-way, loop and threaded tests compare what the lowering makes, with the passes off. A `#[cfg(test)]` per-thread override of `shader_opt()` does this; production is unchanged. - A new test checks with the passes on that pruning still changes the module. It uses a scalar taken from the group id, so a later fold of wave operations on constants would not remove the difference. `cargo test -p victory-shader --lib -- --test-threads=1`: 284 passed, 0 failed, 6 ignored. Two mutations were checked: - turning pruning off fails the one-way, loop, threaded and new tests; - replacing the `original.is_ok()` check with `true` fails the threaded test. So this is now a smaller and somewhat cheaper-to-compile module for about 700 programs, not a fix for a pipeline that could not be created. Whether that is worth a second lowering for those programs is your call. I'm fine closing it if not.
MamaLeVrai commented 2026-11-26 00:18:13 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by MamaLeVrai on 2026-11-26T00:18:13Z.


RDNA2 result. Hardware: RX 6950 XT, Windows 11 build 26300, Rust 1.98.1. This PR (dc66cba) merged on main 4f62c2a. Command: cargo test --release -p victory-shader --lib, two runs.

  • main: 275 passed, 2 failed.
  • This PR: 282 passed, 2 failed. The PR's 7 new tests pass on this hardware. (One of the two runs ended without a result line. This test binary does that now and then on this machine, on main too.)

The 2 failures are the same on main: scalar_counted_in_a_divergent_loop_read_after_it and scalar_counted_in_nested_divergent_loops, the RDNA2 wave-size tests that #110 and #204 fix. So nothing regresses on this card. Not run in the game.

harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300

AI-assisted (Claude Code); no game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7178615072 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7178615072). Originally posted by [MamaLeVrai](https://github.com/MamaLeVrai) on 2026-11-26T00:18:13Z. --- RDNA2 result. Hardware: RX 6950 XT, Windows 11 build 26300, Rust 1.98.1. This PR (`dc66cba`) merged on `main` `4f62c2a`. Command: `cargo test --release -p victory-shader --lib`, two runs. - `main`: 275 passed, 2 failed. - This PR: **282 passed, 2 failed**. The PR's 7 new tests pass on this hardware. (One of the two runs ended without a result line. This test binary does that now and then on this machine, on `main` too.) The 2 failures are the same on `main`: `scalar_counted_in_a_divergent_loop_read_after_it` and `scalar_counted_in_nested_divergent_loops`, the RDNA2 wave-size tests that #110 and #204 fix. So nothing regresses on this card. Not run in the game. harness machine: rx6950xt-w11 | AMD Radeon RX 6950 XT (RDNA2), driver 32.0.21045.29003 | 32 GB RAM | Windows 11 build 26300 AI-assisted (Claude Code); no game data.
adrianmjim commented 2026-11-27 09:25:43 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-27T09:25:43Z.


Closing, since main is no longer the line being developed. On a-publier the clean-up passes are on as well, and this pruning would change 709 of 25,694 programs, all but 8 smaller, about 44 KB in total (CS_ScreenProbes_ActivateRays 119,148 → 106,264 bytes). The out-of-memory case that motivated it no longer happens. Not worth a second lowering per program for that. Thanks to everyone who tested it.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7214668879 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/172#issuecomment-7214668879). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-27T09:25:43Z. --- Closing, since `main` is no longer the line being developed. On `a-publier` the clean-up passes are on as well, and this pruning would change 709 of 25,694 programs, all but 8 smaller, about 44 KB in total (`CS_ScreenProbes_ActivateRays` 119,148 → 106,264 bytes). The out-of-memory case that motivated it no longer happens. Not worth a second lowering per program for that. Thanks to everyone who tested it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Belobug/VIctory-Belobug-AMD!172
No description provided.