Shaders: a loop retry that still needs 64 lanes leaves widen its blocks (02384a60fda6f2d0 translates) #560

Closed
kibagami-nc wants to merge 0 commits from upstream-pr/560 into main
kibagami-nc commented 2026-11-28 00:55:22 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T00:55:22Z.


Rebased on main (32ecacf). Main has fixed #539 in its own way since. In 8fc2254, emit translates a program once more, with no loop branches taken together, when the first try fails. That brought the underwater program back.

It did not bring back 02384a60fda6f2d0 (CS_DefragHeap_ComputeRelocations): starnotes-xj's run on 8fc2254 still refused it, and this PR makes it translate (see below). On 32ecacf, this PR's own test still fails without the change.

The problem

64d4931 added a retry in emit_program (crates/victory-shader/src/emit/mod.rs). A console wave64 compute program on a host of 32-lane waves is translated once more with its loop branches taken by each host wave together. That translation is given "if it needs no wider waves" than the first (w <= *wave).

When both translations still ask for 64 lanes, 64 <= 64 holds, so the retry was taken, and lower::take_needs() dropped the blocks the first lowering had named. Those blocks are what widen uses: it takes the per-lane branches around them wave-wide, again and again, until the program fits 32-lane waves. With nothing named, widen stopped at waves of 64.

emit_once then went on to its approximate forms. When those failed too, the program was refused with "no wave32 lowering for this wave64 program", unless main's second try, with no loop branches taken together, translated it.

This hits programs that have a per-lane loop and that need 64 lanes somewhere else, for instance an LDS exchange between the two host waves inside a per-lane if.

The change

The retry is given only when it fits the host. That check is too_wide, the same test as the refusal in emit_once, which now calls it. Otherwise the first translation and its named blocks are kept, exactly as when the retry fails.

Retries that do fit are given as before: 64 lanes to 32, or 32 to 32.

What it changes on main

ghptc's split_wave_lds_loop program, with VICTORY_WAVE_WHY=1, on 32ecacf:

  • Without the change. The first try ends with WAVE64-WIDE 0 branches taken wave-wide: [], goes on to local waves (APPROXIMATE, any mask): wave Some(64), and fails. Main's second try then finds WAVE64-WIDE 1 branches taken wave-wide: [B1(s_cbranch_execz)] and logs WAVE-LOOPS left out: the program translates without them.
  • With it. The first try finds the same form at once: WAVE64-WIDE 1 branches taken wave-wide: [B1(s_cbranch_execz)], then wave-wide branches: wave Some(32). There is no second try.

In the first try, the approximate local waves come after widen. So without the change, a program whose approximate form translates gets that form, and the second try never runs. With it, widen gets there first.

Tests

  • New emit::wave64_tests::a_loop_retry_that_still_needs_64_lanes_leaves_the_widening_its_blocks:
    • The program. A wave64 program of 64 threads. Each lane goes round a per-lane loop, then if ((t & 31) < s1) writes its sum to LDS and adds lane t ^ 32's, which is in the other host wave.
    • On main (32ecacf). It fails: the `if` taken wave-wide: waves of 32, left Some(64), right Some(32). With VICTORY_LOOPS_WAVE=0 (no retry) the same test passes.
    • With the fix. widen reaches Some(32). On an RTX 5070 Ti (32-lane waves) the output matches the console model for 4 sets of root constants, on 32ecacf too.
  • New emit::lds_loop_tests, written by ghptc, who reproduced the failure independently (see the comment below; the second commit):
    • The programs. A synthetic 8 × 8 tile exchanges LDS values with the opposite half of the console wave inside the loop, then writes an RGBA32F texture. A control program does the same without the exchange.
    • Through emit(). The tests go through emit() with the submerged kernel's selector.
    • split_wave_lds_loop. It translates on a 32-lane host, with no GPU needed. Before 8fc2254 it failed without the fix, with "no wave32 lowering for this wave64 program". On 32ecacf it passes either way, through main's second try (above).
    • tile_pixels_match_the_console_wave. It is ignored by default, because it needs a 32-lane SM 6.6 card. Every channel's bits match a CPU model of the console wave: 64 of 64 pixels for both programs on an RTX 5070 Ti.
  • cargo test -p victory-shader --locked: 338 passed, 7 ignored (the new tests included).
  • Clippy (workspace, --all-targets, default and --all-features): nothing in the changed lines. The two errors left are main's own: clippy::let_and_return in a test of emit/mod.rs, and clippy::manual_is_multiple_of at shadow.rs:1740.

The shader cache key (env!("VICTORY_TRANSLATOR")) follows the translator's source, so translations cached before this change are made again.

Checked by others (before the rebase)

  • CuteBooty (RTX 3070, the card from #539): on 64d4931 with this PR, the underwater scene is drawn again. #539 is closed: main's 8fc2254 brings it back too.
  • ghptc (RTX 5070, Proton): reproduced the failure on their own and tested the fix. Their LDS tests are now part of this PR.
  • starnotes-xj (RTX 4060 Laptop), on main 8fc2254: 02384a60fda6f2d0 (vfx_triangleClip:CS_DefragHeap_ComputeRelocations) was refused on every run, with "no wave32 lowering for this wave64 program". With this PR it translates.
    • With the program no longer left out (#490, since closed), the faces came back in the cafe cutscene. On main it is still left out by default (VICTORY_LEAVE_OUT, for its cost: 11.85 ms a frame).
    • With the split-wave64 fallback off (VICTORY_WAVE_SPLIT=0), the translator alone still took it, so this PR is enough on its own for that program.

Not checked yet on 32ecacf: whether 02384a60fda6f2d0 is still refused there without this PR. I have asked in a comment below.

No game files, dumps or extracted data are included.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5535128275 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T00:55:22Z. --- **Rebased on main (32ecacf).** Main has fixed #539 in its own way since. In 8fc2254, `emit` translates a program once more, with no loop branches taken together, when the first try fails. That brought the underwater program back. It did not bring back `02384a60fda6f2d0` (`CS_DefragHeap_ComputeRelocations`): starnotes-xj's run on 8fc2254 still refused it, and this PR makes it translate (see below). On 32ecacf, this PR's own test still fails without the change. ## The problem 64d4931 added a retry in `emit_program` (`crates/victory-shader/src/emit/mod.rs`). A console wave64 compute program on a host of 32-lane waves is translated once more with its loop branches taken by each host wave together. That translation is given "if it needs no wider waves" than the first (`w <= *wave`). When both translations still ask for 64 lanes, `64 <= 64` holds, so the retry was taken, and `lower::take_needs()` dropped the blocks the first lowering had named. Those blocks are what `widen` uses: it takes the per-lane branches around them wave-wide, again and again, until the program fits 32-lane waves. With nothing named, `widen` stopped at waves of 64. `emit_once` then went on to its approximate forms. When those failed too, the program was refused with "no wave32 lowering for this wave64 program", unless main's second try, with no loop branches taken together, translated it. This hits programs that have a per-lane loop and that need 64 lanes somewhere else, for instance an LDS exchange between the two host waves inside a per-lane `if`. ## The change The retry is given only when it fits the host. That check is `too_wide`, the same test as the refusal in `emit_once`, which now calls it. Otherwise the first translation and its named blocks are kept, exactly as when the retry fails. Retries that do fit are given as before: 64 lanes to 32, or 32 to 32. ## What it changes on main ghptc's `split_wave_lds_loop` program, with `VICTORY_WAVE_WHY=1`, on 32ecacf: - **Without the change.** The first try ends with `WAVE64-WIDE 0 branches taken wave-wide: []`, goes on to `local waves (APPROXIMATE, any mask): wave Some(64)`, and fails. Main's second try then finds `WAVE64-WIDE 1 branches taken wave-wide: [B1(s_cbranch_execz)]` and logs `WAVE-LOOPS left out: the program translates without them`. - **With it.** The first try finds the same form at once: `WAVE64-WIDE 1 branches taken wave-wide: [B1(s_cbranch_execz)]`, then `wave-wide branches: wave Some(32)`. There is no second try. In the first try, the approximate local waves come after `widen`. So without the change, a program whose approximate form translates gets that form, and the second try never runs. With it, `widen` gets there first. ## Tests - New `emit::wave64_tests::a_loop_retry_that_still_needs_64_lanes_leaves_the_widening_its_blocks`: - **The program.** A wave64 program of 64 threads. Each lane goes round a per-lane loop, then `if ((t & 31) < s1)` writes its sum to LDS and adds lane `t ^ 32`'s, which is in the other host wave. - **On `main` (32ecacf).** It fails: ``the `if` taken wave-wide: waves of 32``, left `Some(64)`, right `Some(32)`. With `VICTORY_LOOPS_WAVE=0` (no retry) the same test passes. - **With the fix.** `widen` reaches `Some(32)`. On an RTX 5070 Ti (32-lane waves) the output matches the console model for 4 sets of root constants, on 32ecacf too. - New `emit::lds_loop_tests`, written by ghptc, who reproduced the failure independently (see the comment below; the second commit): - **The programs.** A synthetic 8 × 8 tile exchanges LDS values with the opposite half of the console wave *inside* the loop, then writes an RGBA32F texture. A control program does the same without the exchange. - **Through `emit()`.** The tests go through `emit()` with the submerged kernel's selector. - **`split_wave_lds_loop`.** It translates on a 32-lane host, with no GPU needed. Before 8fc2254 it failed without the fix, with "no wave32 lowering for this wave64 program". On 32ecacf it passes either way, through main's second try (above). - **`tile_pixels_match_the_console_wave`.** It is ignored by default, because it needs a 32-lane SM 6.6 card. Every channel's bits match a CPU model of the console wave: 64 of 64 pixels for both programs on an RTX 5070 Ti. - `cargo test -p victory-shader --locked`: 338 passed, 7 ignored (the new tests included). - Clippy (workspace, `--all-targets`, default and `--all-features`): nothing in the changed lines. The two errors left are main's own: `clippy::let_and_return` in a test of `emit/mod.rs`, and `clippy::manual_is_multiple_of` at `shadow.rs:1740`. The shader cache key (`env!("VICTORY_TRANSLATOR")`) follows the translator's source, so translations cached before this change are made again. ## Checked by others (before the rebase) - **CuteBooty** (RTX 3070, the card from #539): on 64d4931 with this PR, the underwater scene is drawn again. #539 is closed: main's 8fc2254 brings it back too. - **ghptc** (RTX 5070, Proton): reproduced the failure on their own and tested the fix. Their LDS tests are now part of this PR. - **starnotes-xj** (RTX 4060 Laptop), on main 8fc2254: `02384a60fda6f2d0` (`vfx_triangleClip:CS_DefragHeap_ComputeRelocations`) was refused on every run, with "no wave32 lowering for this wave64 program". With this PR it translates. - With the program no longer left out (#490, since closed), the faces came back in the cafe cutscene. On main it is still left out by default (`VICTORY_LEAVE_OUT`, for its cost: 11.85 ms a frame). - With the split-wave64 fallback off (`VICTORY_WAVE_SPLIT=0`), the translator alone still took it, so this PR is enough on its own for that program. **Not checked yet on 32ecacf:** whether `02384a60fda6f2d0` is still refused there without this PR. I have asked in a comment below. No game files, dumps or extracted data are included.
ghptc commented 2026-11-28 01:13:37 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by ghptc on 2026-11-28T01:13:37Z.


@kibagami-nc, I independently reproduced the shader translation failure and tested your fix at 52a4d0e33 on an RTX 5070 (driver 620.73.4, Proton Experimental, vkd3d-proton). Would you like to include the additional fixture in this PR? The test-only patch below applies to your head.

Your test calls widen() directly and checks a raw-buffer exchange after a lane-varying loop with four sets of constants. The additional fixture calls emit() with the existing submerged-kernel selector, exchanges LDS values inside the loop, then writes an 8 × 8 RGBA32F texture. It includes a control shader without the exchange. The translation test runs on Linux without a GPU. The opt-in D3D12 test checks the bits of every RGBA channel against a CPU model of the 64-lane console wave.

Revision Control tile In-loop exchange tile
f3534e6b0 64/64 pixels exact 64/64 exact
64d4931b3 64/64 exact Translation refused before PSO creation
Your PR at 52a4d0e33 64/64 exact 64/64 exact

The automated bisect identified 64d4931b3. Your own four-input test also executed on the card and passed. This confirms the translator regression and its repair for these synthetic shaders. The association with 926c46bab3b86bd6 and the underwater image in #539 still needs a same-save gameplay check on the reporter’s setup. The fixture shares the published selector digest and uses independently written instructions.

Test-only patch and reproduction commands

With the diff applied, run:

cargo test --locked -p victory-shader --lib -- --exact emit::lds_loop_tests::split_wave_lds_loop
# On a wave32-capable SM 6.6 D3D12 host
cargo test --locked -p victory-shader --lib -- --exact emit::lds_loop_tests::tile_pixels_match_the_console_wave --ignored --nocapture
diff --git a/crates/victory-shader/src/emit/lds_loop_tests.rs b/crates/victory-shader/src/emit/lds_loop_tests.rs
new file mode 100644
index 0000000..8ea4e03
--- /dev/null
+++ b/crates/victory-shader/src/emit/lds_loop_tests.rs
@@ -0,0 +1,157 @@
+//! One synthetic 8 × 8 tile. Each lane updates its pixel from the pixel in
+//! the opposite half of the console wave, until that lane's round count expires.
+
+use super::*;
+use crate::native::{ComputeIo, ResourceType, RootParam, StageIo, UsedResource};
+
+fn tile(shared_light: bool) -> NativeProgram {
+    let mut words = vec![
+        0xBE81_0380u32, // s_mov_b32 s1, 0
+        0xF40C_0200,
+        0xFA00_0000, // s_load_dwordx8 s[8:15], s[0:1], 0
+        0x7E04_0300, // v_mov_b32 v2, v0 (initial intensity)
+    ];
+    if shared_light {
+        words.extend_from_slice(&[
+            0x3402_0082, // v_lshlrev_b32 v1, 2, v0 (pixel byte offset)
+            0x3A06_00BF, // v_xor_b32 v3, 63, v0 (partner)
+            0x3406_0682, // v_lshlrev_b32 v3, 2, v3
+            0x2C0E_0084, // v_lshrrev_b32 v7, 4, v0
+            0x4A0E_0E81, // v_add_nc_u32 v7, 1, v7 (one to four rounds)
+            0x7E0A_0280, // v_mov_b32 v5, 0
+            0xBE90_047E, // s_mov_b64 s[16:17], exec
+            0x7DA8_0B07, // loop: v_cmpx_gt_u32 exec, v7, v5
+            0xBF88_0008, // s_cbranch_execz done
+            0xD834_0000,
+            0x0000_0201, // ds_write_b32 v1, v2
+            0xD8D8_0000,
+            0x0400_0003, // ds_read_b32 v4, v3
+            0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
+            0x4A04_0902, // v_add_nc_u32 v2, v2, v4
+            0x4A0A_0A81, // v_add_nc_u32 v5, 1, v5
+            0xBF82_FFF6, // s_branch loop
+            0xBEFE_0410, // done: s_mov_b64 exec, s[16:17]
+        ]);
+    }
+    words.extend_from_slice(&[
+        0x360C_0087, // v_and_b32 v6, 7, v0 (x)
+        0x2C0E_0083, // v_lshrrev_b32 v7, 3, v0 (y)
+        0x7E04_0D02, // v_cvt_f32_u32 v2, v2
+        0x1004_04FF,
+        0x3B00_0000, // v_mul_f32 v2, 1/512, v2 (red)
+        0x7E06_02F0, // v_mov_b32 v3, 0.5 (green)
+        0x7E08_0280, // v_mov_b32 v4, 0 (blue)
+        0x7E0A_02F2, // v_mov_b32 v5, 1.0 (alpha)
+        0xF020_1F08,
+        0x0002_0206, // image_store v[2:5], v[6:7], s[8:15] dmask:0xf 2D
+        0xBF81_0000, // s_endpgm
+    ]);
+    NativeProgram {
+        stage: HwStage::Cs,
+        wave64: true,
+        vgprs: 8,
+        layout: vec![RootParam {
+            root: RootType::Table,
+            table_offset_dwords: 0,
+            sgprs: 1,
+            base_register: 0,
+            user_data: 0,
+            slot: 0,
+        }],
+        used: vec![UsedResource {
+            kind: ResourceType::Uav,
+            root: RootType::Table,
+            table_offset_dwords: 0,
+            lower_bound: 0,
+            stride: 4,
+            dwords: 8,
+            user_data: 0,
+            slot: 0,
+        }],
+        io: StageIo::Cs(ComputeIo {
+            threads: [64, 1, 1],
+            rsrc2: (u32::from(shared_light) << 15) | (1 << 1),
+        }),
+        code: words.iter().flat_map(|w| w.to_le_bytes()).collect(),
+    }
+}
+
+fn translate_tile(shared_light: bool) -> Result<HostShader, ShaderError> {
+    let native = tile(shared_light);
+    // Exercise the existing widening policy for the 64-thread submerged kernel.
+    // Only the selection digest is shared. The instructions and IO above are synthetic.
+    let c = Container {
+        version: (1, 0),
+        parts: vec![],
+        digest: [
+            0xf1, 0xf1, 0x61, 0xe4, 0x7e, 0xef, 0xa3, 0x64, 0x69, 0x18, 0x39, 0xfd, 0x72, 0x06,
+            0xcc, 0xf6,
+        ],
+    };
+    let p = ir::build(&native.code, true, native.vgprs).unwrap();
+    let st = structure::structure(&p).unwrap();
+    let res = resource::track(&p, &native.layout, native.stage, Some(&st)).unwrap();
+    let io = io::raise(&p, &native).unwrap();
+    let previous = lower::TEST_HOST_WAVE.replace(Some(32));
+    let shader = emit(&c, &native, &p, &st, &io, &res);
+    lower::TEST_HOST_WAVE.set(previous);
+    shader
+}
+
+#[test]
+fn split_wave_lds_loop() {
+    translate_tile(true).expect("translate the LDS loop on a wave32 host");
+}
+
+#[cfg(windows)]
+#[test]
+#[ignore = "requires a wave32-capable D3D12 device (SM 6.6)"]
+fn tile_pixels_match_the_console_wave() {
+    use super::host::{Dispatch, Host, Root, View};
+
+    let _one = super::valu_tests::ONE_AT_A_TIME
+        .lock()
+        .unwrap_or_else(|e| e.into_inner());
+    let host = Host::new(false).expect("SM 6.6 D3D12 device");
+    for shared_light in [false, true] {
+        let shader = translate_tile(shared_light).unwrap();
+        let (root, pipeline) = host.compute_pipeline(&shader).expect("compute pipeline");
+        let out = host
+            .dispatch(
+                &root,
+                &pipeline,
+                &Dispatch {
+                    roots: vec![(
+                        0,
+                        Root::Constants(vec![0; shader.user_data_dwords().max(1) as usize]),
+                    )],
+                    views: &[View::TextureUav(8, 8)],
+                    samplers: &[],
+                    groups: [1, 1, 1],
+                },
+            )
+            .expect("dispatch and copy the texture back");
+
+        // Console lanes run in lockstep. All active lanes store before any reads.
+        let mut intensity: [u32; 64] = std::array::from_fn(|t| t as u32);
+        let mut lds = [0; 64];
+        let rounds = if shared_light { 4 } else { 0 };
+        for round in 0..rounds {
+            let first = 16 * round;
+            lds[first..].copy_from_slice(&intensity[first..]);
+            for t in first..64 {
+                intensity[t] += lds[t ^ 63];
+            }
+        }
+        assert_eq!(out[0].len(), 64 * 4);
+        for (t, rgba) in out[0].chunks_exact(4).enumerate() {
+            let expected = [intensity[t] as f32 / 512.0, 0.5, 0.0, 1.0];
+            assert_eq!(
+                rgba,
+                expected.map(f32::to_bits),
+                "pixel {t}, shared light {shared_light}"
+            );
+        }
+        eprintln!("64 RGBA32F pixels matched (shared light {shared_light})");
+    }
+}
diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs
index c9e689a..8752b8b 100644
--- a/crates/victory-shader/src/emit/mod.rs
+++ b/crates/victory-shader/src/emit/mod.rs
@@ -92,6 +92,8 @@ mod filter3d_tests;
 mod intersect_tests;
 #[cfg(all(windows, any(test, feature = "host")))]
 pub mod host;
+#[cfg(test)]
+mod lds_loop_tests;
 mod lower;
 mod own_bits;
 #[cfg(all(test, windows))]
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231513233 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560#issuecomment-7231513233). Originally posted by [ghptc](https://github.com/ghptc) on 2026-11-28T01:13:37Z. --- @kibagami-nc, I independently reproduced the shader translation failure and tested your fix at `52a4d0e33` on an RTX 5070 (driver 620.73.4, Proton Experimental, vkd3d-proton). Would you like to include the additional fixture in this PR? The test-only patch below applies to your head. Your test calls `widen()` directly and checks a raw-buffer exchange **after** a lane-varying loop with four sets of constants. The additional fixture calls `emit()` with the existing submerged-kernel selector, exchanges LDS values **inside** the loop, then writes an 8 × 8 RGBA32F texture. It includes a control shader without the exchange. The translation test runs on Linux without a GPU. The opt-in D3D12 test checks the bits of every RGBA channel against a CPU model of the 64-lane console wave. | Revision | Control tile | In-loop exchange tile | |---|---|---| | `f3534e6b0` | 64/64 pixels exact | 64/64 exact | | `64d4931b3` | 64/64 exact | Translation refused before PSO creation | | Your PR at `52a4d0e33` | 64/64 exact | 64/64 exact | The automated bisect identified `64d4931b3`. Your own four-input test also executed on the card and passed. This confirms the translator regression and its repair for these synthetic shaders. The association with `926c46bab3b86bd6` and the underwater image in #539 still needs a same-save gameplay check on the reporter’s setup. The fixture shares the published selector digest and uses independently written instructions. <details> <summary>Test-only patch and reproduction commands</summary> With the diff applied, run: ```sh cargo test --locked -p victory-shader --lib -- --exact emit::lds_loop_tests::split_wave_lds_loop # On a wave32-capable SM 6.6 D3D12 host cargo test --locked -p victory-shader --lib -- --exact emit::lds_loop_tests::tile_pixels_match_the_console_wave --ignored --nocapture ``` ```diff diff --git a/crates/victory-shader/src/emit/lds_loop_tests.rs b/crates/victory-shader/src/emit/lds_loop_tests.rs new file mode 100644 index 0000000..8ea4e03 --- /dev/null +++ b/crates/victory-shader/src/emit/lds_loop_tests.rs @@ -0,0 +1,157 @@ +//! One synthetic 8 × 8 tile. Each lane updates its pixel from the pixel in +//! the opposite half of the console wave, until that lane's round count expires. + +use super::*; +use crate::native::{ComputeIo, ResourceType, RootParam, StageIo, UsedResource}; + +fn tile(shared_light: bool) -> NativeProgram { + let mut words = vec![ + 0xBE81_0380u32, // s_mov_b32 s1, 0 + 0xF40C_0200, + 0xFA00_0000, // s_load_dwordx8 s[8:15], s[0:1], 0 + 0x7E04_0300, // v_mov_b32 v2, v0 (initial intensity) + ]; + if shared_light { + words.extend_from_slice(&[ + 0x3402_0082, // v_lshlrev_b32 v1, 2, v0 (pixel byte offset) + 0x3A06_00BF, // v_xor_b32 v3, 63, v0 (partner) + 0x3406_0682, // v_lshlrev_b32 v3, 2, v3 + 0x2C0E_0084, // v_lshrrev_b32 v7, 4, v0 + 0x4A0E_0E81, // v_add_nc_u32 v7, 1, v7 (one to four rounds) + 0x7E0A_0280, // v_mov_b32 v5, 0 + 0xBE90_047E, // s_mov_b64 s[16:17], exec + 0x7DA8_0B07, // loop: v_cmpx_gt_u32 exec, v7, v5 + 0xBF88_0008, // s_cbranch_execz done + 0xD834_0000, + 0x0000_0201, // ds_write_b32 v1, v2 + 0xD8D8_0000, + 0x0400_0003, // ds_read_b32 v4, v3 + 0xBF8C_C07F, // s_waitcnt lgkmcnt(0) + 0x4A04_0902, // v_add_nc_u32 v2, v2, v4 + 0x4A0A_0A81, // v_add_nc_u32 v5, 1, v5 + 0xBF82_FFF6, // s_branch loop + 0xBEFE_0410, // done: s_mov_b64 exec, s[16:17] + ]); + } + words.extend_from_slice(&[ + 0x360C_0087, // v_and_b32 v6, 7, v0 (x) + 0x2C0E_0083, // v_lshrrev_b32 v7, 3, v0 (y) + 0x7E04_0D02, // v_cvt_f32_u32 v2, v2 + 0x1004_04FF, + 0x3B00_0000, // v_mul_f32 v2, 1/512, v2 (red) + 0x7E06_02F0, // v_mov_b32 v3, 0.5 (green) + 0x7E08_0280, // v_mov_b32 v4, 0 (blue) + 0x7E0A_02F2, // v_mov_b32 v5, 1.0 (alpha) + 0xF020_1F08, + 0x0002_0206, // image_store v[2:5], v[6:7], s[8:15] dmask:0xf 2D + 0xBF81_0000, // s_endpgm + ]); + NativeProgram { + stage: HwStage::Cs, + wave64: true, + vgprs: 8, + layout: vec![RootParam { + root: RootType::Table, + table_offset_dwords: 0, + sgprs: 1, + base_register: 0, + user_data: 0, + slot: 0, + }], + used: vec![UsedResource { + kind: ResourceType::Uav, + root: RootType::Table, + table_offset_dwords: 0, + lower_bound: 0, + stride: 4, + dwords: 8, + user_data: 0, + slot: 0, + }], + io: StageIo::Cs(ComputeIo { + threads: [64, 1, 1], + rsrc2: (u32::from(shared_light) << 15) | (1 << 1), + }), + code: words.iter().flat_map(|w| w.to_le_bytes()).collect(), + } +} + +fn translate_tile(shared_light: bool) -> Result<HostShader, ShaderError> { + let native = tile(shared_light); + // Exercise the existing widening policy for the 64-thread submerged kernel. + // Only the selection digest is shared. The instructions and IO above are synthetic. + let c = Container { + version: (1, 0), + parts: vec![], + digest: [ + 0xf1, 0xf1, 0x61, 0xe4, 0x7e, 0xef, 0xa3, 0x64, 0x69, 0x18, 0x39, 0xfd, 0x72, 0x06, + 0xcc, 0xf6, + ], + }; + let p = ir::build(&native.code, true, native.vgprs).unwrap(); + let st = structure::structure(&p).unwrap(); + let res = resource::track(&p, &native.layout, native.stage, Some(&st)).unwrap(); + let io = io::raise(&p, &native).unwrap(); + let previous = lower::TEST_HOST_WAVE.replace(Some(32)); + let shader = emit(&c, &native, &p, &st, &io, &res); + lower::TEST_HOST_WAVE.set(previous); + shader +} + +#[test] +fn split_wave_lds_loop() { + translate_tile(true).expect("translate the LDS loop on a wave32 host"); +} + +#[cfg(windows)] +#[test] +#[ignore = "requires a wave32-capable D3D12 device (SM 6.6)"] +fn tile_pixels_match_the_console_wave() { + use super::host::{Dispatch, Host, Root, View}; + + let _one = super::valu_tests::ONE_AT_A_TIME + .lock() + .unwrap_or_else(|e| e.into_inner()); + let host = Host::new(false).expect("SM 6.6 D3D12 device"); + for shared_light in [false, true] { + let shader = translate_tile(shared_light).unwrap(); + let (root, pipeline) = host.compute_pipeline(&shader).expect("compute pipeline"); + let out = host + .dispatch( + &root, + &pipeline, + &Dispatch { + roots: vec![( + 0, + Root::Constants(vec![0; shader.user_data_dwords().max(1) as usize]), + )], + views: &[View::TextureUav(8, 8)], + samplers: &[], + groups: [1, 1, 1], + }, + ) + .expect("dispatch and copy the texture back"); + + // Console lanes run in lockstep. All active lanes store before any reads. + let mut intensity: [u32; 64] = std::array::from_fn(|t| t as u32); + let mut lds = [0; 64]; + let rounds = if shared_light { 4 } else { 0 }; + for round in 0..rounds { + let first = 16 * round; + lds[first..].copy_from_slice(&intensity[first..]); + for t in first..64 { + intensity[t] += lds[t ^ 63]; + } + } + assert_eq!(out[0].len(), 64 * 4); + for (t, rgba) in out[0].chunks_exact(4).enumerate() { + let expected = [intensity[t] as f32 / 512.0, 0.5, 0.0, 1.0]; + assert_eq!( + rgba, + expected.map(f32::to_bits), + "pixel {t}, shared light {shared_light}" + ); + } + eprintln!("64 RGBA32F pixels matched (shared light {shared_light})"); + } +} diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index c9e689a..8752b8b 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -92,6 +92,8 @@ mod filter3d_tests; mod intersect_tests; #[cfg(all(windows, any(test, feature = "host")))] pub mod host; +#[cfg(test)] +mod lds_loop_tests; mod lower; mod own_bits; #[cfg(all(test, windows))] ``` </details>
CuteBooty commented 2026-11-28 01:14:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by CuteBooty on 2026-11-28T01:14:20Z.


Tested on the card from #539: this brings the underwater scene back.

  • Build: 64d4931b3 + this PR's commit (52a4d0e33, cherry-picked) + the same local commits as in #539. Diagnostics profile, started with victory.exe run, Series S, 1920x1080, no DLSS, VICTORY_BUFFERS_AHEAD=0, all translator switches at their defaults.
  • PC: RTX 3070 8 GB (driver 621.24), Ryzen 7 5800X3D, 32 GB, Windows 11.
  • Same dive as in #539 ("Escort the bachelor party through the trench"), same save.

Log, same shader as in the issue:

01:05:29 INFO victory_gpu::pipeline: shader translated stage="compute" hash=926c46bab3b86bd6 user_data=2 samplers=6
01:07:26 INFO victory_gpu::pipeline: first bind pipeline=… stage="compute" size=29920 hash=926c46bab3b86bd6

No shader does not translate for it any more, no dropped … compute 926c46bab3b86bd6 lines, no ERROR lines, no device loss in the first seven minutes, with two dives. cargo test -p victory-shader wave64: 15 passed, including the new test.

What I see: under water the scene is drawn and looks decent most of the time. There is one leftover artifact, at its worst under a pier: for a moment, square screen tiles swap between the water's blue haze and the un-hazed scene, so sand and dark openings are cut out in blocks with stair-stepped edges. It depends on where I look: looking down at the sea floor the picture is clean; it gets far worse when looking level or up towards the surface. I can add screenshots of both (the worst frame I could catch, and a clean one of the floor). I do not know whether that is this shader's widened form or something separate; I never saw a working dive on 64d4931b3 to compare with.

One run, one card. Not tested: play, your release exe, DLSS or frame generation with this commit, Series X.

Measurements and this comment were prepared with an AI assistant (Claude Code); the run was played on my machine.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231521801 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560#issuecomment-7231521801). Originally posted by [CuteBooty](https://github.com/CuteBooty) on 2026-11-28T01:14:20Z. --- Tested on the card from #539: this brings the underwater scene back. - **Build:** `64d4931b3` + this PR's commit (`52a4d0e33`, cherry-picked) + the same local commits as in #539. Diagnostics profile, started with `victory.exe run`, Series S, 1920x1080, no DLSS, `VICTORY_BUFFERS_AHEAD=0`, all translator switches at their defaults. - **PC:** RTX 3070 8 GB (driver 621.24), Ryzen 7 5800X3D, 32 GB, Windows 11. - **Same dive as in #539** ("Escort the bachelor party through the trench"), same save. Log, same shader as in the issue: ``` 01:05:29 INFO victory_gpu::pipeline: shader translated stage="compute" hash=926c46bab3b86bd6 user_data=2 samplers=6 01:07:26 INFO victory_gpu::pipeline: first bind pipeline=… stage="compute" size=29920 hash=926c46bab3b86bd6 ``` No `shader does not translate` for it any more, no `dropped … compute 926c46bab3b86bd6` lines, no `ERROR` lines, no device loss in the first seven minutes, with two dives. `cargo test -p victory-shader wave64`: 15 passed, including the new test. What I see: under water the scene is drawn and looks decent most of the time. There is one leftover artifact, at its worst under a pier: for a moment, square screen tiles swap between the water's blue haze and the un-hazed scene, so sand and dark openings are cut out in blocks with stair-stepped edges. It depends on where I look: looking down at the sea floor the picture is clean; it gets far worse when looking level or up towards the surface. I can add screenshots of both (the worst frame I could catch, and a clean one of the floor). I do not know whether that is this shader's widened form or something separate; I never saw a working dive on `64d4931b3` to compare with. One run, one card. Not tested: `play`, your release exe, DLSS or frame generation with this commit, Series X. Measurements and this comment were prepared with an AI assistant (Claude Code); the run was played on my machine.
starnotes-xj commented 2026-11-28 07:24:08 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by starnotes-xj on 2026-11-28T07:24:08Z.


Confirmed on a 32-lane host, and this one has a visible effect.

Card: RTX 4060 Laptop 8 GB, Windows, GTA VI 1.0.2.1, latest main (55 commits, 8fc2254).

02384a60fda6f2d0 (vfx_triangleClip:CS_DefragHeap_ComputeRelocations) is the program that places the faces' meshes. With #490 (the launchers stop leaving it out) it started being compiled and was refused every run:

WARN victory_gpu::pipeline: shader does not translate; its pipelines' draws are dropped stage="compute" hash=02384a60fda6f2d0 error=... no wave32 lowering for this wave64 program is not supported

With this PR merged, the same run goes:

INFO victory_gpu::pipeline: shader translated stage="compute" hash=02384a60fda6f2d0 user_data=1 samplers=0
INFO victory_gpu::pipeline::host: host pipeline shaders=[compute 02384a60fda6f2d0]

and the faces come back in the cafe cutscene (a child and a man in a pink shirt, both black-headed before).

Attribution: I also merged #259 (the split-wave64 fallback), so to tell which one takes it I ran the translator on its own, with the fallback switched off:

$ VICTORY_WAVE_SPLIT=0 VICTORY_HOST_WAVE=32 victory translate <game dir> --warm hashes.txt --list
warm-up  1 hashes asked, 1 found: 1 translated now, 0 in the cache already, 0 do not translate; 80.7 s on 4 threads

So on this title #560 alone is enough — the split fallback is not reached for this program. The remaining refusal in a whole run is 6b82bc7d22016cb5 (the meshlet collector, which #101 names as still open).

Our save point with it: save-2026-11-28-faces in starnotes-xj/VIctory-NVIDIA.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7235915512 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560#issuecomment-7235915512). Originally posted by [starnotes-xj](https://github.com/starnotes-xj) on 2026-11-28T07:24:08Z. --- Confirmed on a 32-lane host, and this one has a visible effect. Card: RTX 4060 Laptop 8 GB, Windows, GTA VI 1.0.2.1, latest `main` (55 commits, `8fc2254`). `02384a60fda6f2d0` (`vfx_triangleClip:CS_DefragHeap_ComputeRelocations`) is the program that places the faces' meshes. With #490 (the launchers stop leaving it out) it started being compiled and was refused every run: ``` WARN victory_gpu::pipeline: shader does not translate; its pipelines' draws are dropped stage="compute" hash=02384a60fda6f2d0 error=... no wave32 lowering for this wave64 program is not supported ``` With this PR merged, the same run goes: ``` INFO victory_gpu::pipeline: shader translated stage="compute" hash=02384a60fda6f2d0 user_data=1 samplers=0 INFO victory_gpu::pipeline::host: host pipeline shaders=[compute 02384a60fda6f2d0] ``` and the faces come back in the cafe cutscene (a child and a man in a pink shirt, both black-headed before). Attribution: I also merged #259 (the split-wave64 fallback), so to tell which one takes it I ran the translator on its own, with the fallback switched off: ``` $ VICTORY_WAVE_SPLIT=0 VICTORY_HOST_WAVE=32 victory translate <game dir> --warm hashes.txt --list warm-up 1 hashes asked, 1 found: 1 translated now, 0 in the cache already, 0 do not translate; 80.7 s on 4 threads ``` So on this title **#560 alone is enough** — the split fallback is not reached for this program. The remaining refusal in a whole run is `6b82bc7d22016cb5` (the meshlet collector, which #101 names as still open). Our save point with it: `save-2026-11-28-faces` in starnotes-xj/VIctory-NVIDIA.
kibagami-nc commented 2026-11-28 19:37:15 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T19:37:15Z.


@starnotes-xj, this branch is now rebased on main 32ecacf (head 41bc85e).

Main has changed the translator 16 times since 8fc2254, #101 among them. So I can't tell from here whether 02384a60fda6f2d0 is still refused on 32ecacf without this PR.

Could you run your check from before once on 32ecacf alone, then once with this branch?

VICTORY_HOST_WAVE=32 victory translate <game dir> --warm hashes.txt --list

The two warm-up lines are enough. VICTORY_WAVE_SPLIT is no longer needed: #259 was closed, so main has no split fallback.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244680840 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560#issuecomment-7244680840). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T19:37:15Z. --- @starnotes-xj, this branch is now rebased on main 32ecacf (head 41bc85e). Main has changed the translator 16 times since 8fc2254, #101 among them. So I can't tell from here whether `02384a60fda6f2d0` is still refused on 32ecacf without this PR. Could you run your check from before once on 32ecacf alone, then once with this branch? ``` VICTORY_HOST_WAVE=32 victory translate <game dir> --warm hashes.txt --list ``` The two `warm-up` lines are enough. `VICTORY_WAVE_SPLIT` is no longer needed: #259 was closed, so main has no split fallback.
kibagami-nc commented 2026-11-28 19:49:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kibagami-nc on 2026-11-28T19:49:26Z.


This is in main since 41d9f62 ("Merge pull request #560", with 7c81ea6 keeping the wave64 test whole). It came from this PR's commits from before my rebase, 52a4d0e and f629b52. So I pointed the branch back at f629b52, and GitHub closed the PR on that push. Nothing of it is left out.

@starnotes-xj, no branch is needed for the check I asked for: main has the fix now. Run it on main 923e38c or later:

VICTORY_HOST_WAVE=32 victory translate <game dir> --warm hashes.txt --list

A "1 translated now" for 02384a60fda6f2d0 is all that's needed.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7244831002 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560#issuecomment-7244831002). Originally posted by [kibagami-nc](https://github.com/kibagami-nc) on 2026-11-28T19:49:26Z. --- This is in main since 41d9f62 ("Merge pull request #560", with 7c81ea6 keeping the wave64 test whole). It came from this PR's commits from before my rebase, 52a4d0e and f629b52. So I pointed the branch back at f629b52, and GitHub closed the PR on that push. Nothing of it is left out. @starnotes-xj, no branch is needed for the check I asked for: main has the fix now. Run it on main 923e38c or later: ``` VICTORY_HOST_WAVE=32 victory translate <game dir> --warm hashes.txt --list ``` A "1 translated now" for `02384a60fda6f2d0` is all that's needed.

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
trustno1-coder/VIctory-NVIDIA!560
No description provided.