Shaders: a loop retry that still needs 64 lanes leaves widen its blocks (fixes #539) #560

Open
github-bot wants to merge 2 commits from github-bot/gh-560 into main AGit
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 00:55 UTC · original
kibagami-nc:fix/loop-retry-keeps-wider-needs → main · +281 −3 · 3 files · 2 commits · open

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, and 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, and emit refused the program with "no wave32 lowering for this wave64 program".

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, 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.

#539

#539 shows the same error from 64d4931 on. Compute program 926c46bab3b86bd6, first bound in dives, translates on f3534e6 and no longer does on 64d4931, and the scene under water is not drawn. The comment above scene_kernel names CS_TransmissionVolumetricsSubmerged as a program that only translates on 32-lane hosts through widen (29 branches).

Checked in game by the reporter of #539 (comment below), on their RTX 3070 with the same save and the same dive:

  • 926c46bab3b86bd6 translates again;
  • there are no more "shader does not translate" or "dropped … compute 926c46bab3b86bd6" lines;
  • the scene under water is drawn.

One leftover they saw: under a pier, square screen tiles switch for a moment between the water's haze and the unhazed scene. Whether that is this program's widened form or something separate is open.

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. widen ends at Some(64), and with VICTORY_WAVE_WHY=1 the log shows the retry taken. 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.
  • New emit::lds_loop_tests, written by ghptc, who reproduced the failure independently (see the comment below; added in f629b52):
    • 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. Without the fix it fails with "no wave32 lowering for this wave64 program".
    • 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: 291 passed, 5 ignored (the new tests included).
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings, and the same with --all-features: no warnings.

Workspace-wide cargo clippy --workspace -- -D warnings already stops on lints main has (see #425, #265 and #86). This change adds no warning.

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

No game files, dumps or extracted data are included.

**@⁠kibagami-nc** on GitHub · 2026-11-28 00:55 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560) `kibagami-nc:fix/loop-retry-keeps-wider-needs` → `main` · +281 −3 · 3 files · 2 commits · open ## 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, and 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, and `emit` refused the program with "no wave32 lowering for this wave64 program". 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`, 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. ## #539 #539 shows the same error from 64d4931 on. Compute program `926c46bab3b86bd6`, first bound in dives, translates on f3534e6 and no longer does on 64d4931, and the scene under water is not drawn. The comment above `scene_kernel` names `CS_TransmissionVolumetricsSubmerged` as a program that only translates on 32-lane hosts through `widen` (29 branches). **Checked in game by the reporter of #539** (comment below), on their RTX 3070 with the same save and the same dive: - `926c46bab3b86bd6` translates again; - there are no more "shader does not translate" or "dropped … compute 926c46bab3b86bd6" lines; - the scene under water is drawn. One leftover they saw: under a pier, square screen tiles switch for a moment between the water's haze and the unhazed scene. Whether that is this program's widened form or something separate is open. ## 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`.** `widen` ends at `Some(64)`, and with `VICTORY_WAVE_WHY=1` the log shows the retry taken. 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. - New `emit::lds_loop_tests`, written by ghptc, who reproduced the failure independently (see the comment below; added in f629b52): - **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. Without the fix it fails with "no wave32 lowering for this wave64 program". - **`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`: 291 passed, 5 ignored (the new tests included). - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`, and the same with `--all-features`: no warnings. Workspace-wide `cargo clippy --workspace -- -D warnings` already stops on lints `main` has (see #425, #265 and #86). This change adds no warning. The shader cache key (`env!("VICTORY_TRANSLATOR")`) follows the translator's source, so translations cached before this change are made again. No game files, dumps or extracted data are included.
Since 64d4931, emit_program translates a console wave64 compute program a
second time with its loop branches taken by each host wave together, and
gives that translation when it needs no wider waves than the first. One
that still asks for 64 lanes on a host of 32-lane waves was taken too, and
the blocks the first lowering had named (lower::take_needs) were dropped
with it. widen, which takes the per-lane branches around those blocks
wave-wide until the program fits 32-lane waves, then saw none, stopped at
waves of 64, and the program was refused: "no wave32 lowering for this
wave64 program".

The retry is now given only when it fits the host (too_wide, shared with
the refusal in emit); otherwise the first translation and its named
blocks are kept, as when the retry fails.

Likely the cause of #539: from 64d4931 on, a compute program first bound
in dives no longer translates with that error, and the scene under water
is not drawn.

Test: a_loop_retry_that_still_needs_64_lanes_leaves_the_widening_its_blocks,
a wave64 program with a per-lane loop and an LDS exchange between the two
host waves inside a per-lane if. Before: widen ends at waves of 64. After:
waves of 32, and on a 32-lane card the results match the console's.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 00:55:40 +00:00
Author
Owner

@⁠ghptc on GitHub · 2026-11-28 01:13 UTC · original

@⁠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))]
**@⁠ghptc** on GitHub · 2026-11-28 01:13 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560#issuecomment-7231513233) @⁠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>
Author
Owner

@⁠CuteBooty on GitHub · 2026-11-28 01:14 UTC · original

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.

**@⁠CuteBooty** on GitHub · 2026-11-28 01:14 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/560#issuecomment-7231521801) 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.
github-bot changed title from Shaders: a loop retry that still needs 64 lanes leaves widen its blocks (likely #539) to Shaders: a loop retry that still needs 64 lanes leaves widen its blocks (fixes #539) 2026-11-28 01:29:56 +00:00
A second fixture for the loop retry fix, written by ghptc and posted on
this pull request. A synthetic wave64 tile program (64 threads) exchanges
LDS values with the opposite half of the console wave inside a lane-varying
loop, then stores an 8 x 8 RGBA32F texture; a control program does the same
without the exchange. It goes through emit() with the submerged kernel's
selector (only the digest is shared; the instructions are synthetic).

- split_wave_lds_loop: translates on a 32-lane host. Without the fix it
  fails with "no wave32 lowering for this wave64 program".
- tile_pixels_match_the_console_wave (ignored: needs a 32-lane SM 6.6
  card): every channel's bits match a CPU model of the console wave,
  for both programs. 64 of 64 pixels on an RTX 5070 Ti.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/560/head:github-bot/gh-560'
git switch 'github-bot/gh-560'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-560'
git switch 'github-bot/gh-560'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-560'
git switch 'github-bot/gh-560'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-560'
git switch 'main'
git merge --squash 'github-bot/gh-560'
git switch 'main'
git merge --ff-only 'github-bot/gh-560'
git switch 'main'
git merge 'github-bot/gh-560'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.