Shaders: LDS accesses past the program's allocation are not bounds-checked (patch + test, run on AMD) #1868

Closed
opened 2026-11-24 23:55:38 +00:00 by wwwwwwww3333333 · 4 comments
wwwwwwww3333333 commented 2026-11-24 23:55:38 +00:00 (Migrated from github.com)
Contributor

Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-24T23:55:38Z.


lower.rs (main 70564ae0) has this shortcut in the DS lowering:

shortcut: LDS addresses are taken as aligned to what they access and in bounds (out-of-bounds console accesses read 0 and drop writes).

On the host, an out-of-bounds index into the group-shared array is undefined behavior. On my card it isn't harmless: the write goes through and can be read back.

What I measured, with a new semantics test on main's lowering. Each thread writes its own dword, then writes b 512 bytes past it. The probe's LDS is 512 bytes, so that write is out of bounds. Reading the out-of-bounds dword back:

  • RX 6750 XT (RDNA2): returns b on 306 of 340 inputs. The out-of-bounds write was kept.
  • WARP: returns 0.

So the hardware adapter and WARP disagree, and neither is guaranteed.

Patch: each LDS dword access now carries "inside the program's LDS".

  • Reads select 0 when outside.
  • Stores, byte/half stores and atomics run only where the lane guard and inside hold.
  • Returning atomics give 0 outside; lanes EXEC leaves out keep the old register, as before.
  • The host index is clamped to 0 when outside, so it never leaves the array.

This covers dword reads and writes, read2/write2, byte/half reads and writes, and atomics. The address stays addr + offset wrapping at 32 bits. That matches LLVM, which on GFX7 and later folds a negative base plus an offset into one DS instruction (isDSOffsetLegal; only Southern Islands needs the sign bit clear). A comment now says so.

Results on 70564ae0, RX 6750 XT, Windows 11, Rust 1.98.1 MSVC. The new test lds_out_of_bounds_reads_zero_and_drops_writes has three probes:

  1. b32 write/read at +512 and +65532, and ds_read_i8 at +600.
    • Before the patch it fails on hardware (306/340); WARP is fine.
    • After the patch it passes on both.
  2. ds_write_b8 at +513, ds_read2_b32 with offset1 800 bytes, ds_add_rtn_u32 at +512, then a read through a base of own - 16 with offset 16 (32-bit wrap back inside).
  3. A returning atomic at +512 under a partial EXEC: active lanes get 0, inactive lanes keep their register.

Probes 2 and 3 already pass on main on this card; they pin the behavior. After the patch all three pass on hardware and WARP.

Other results:

  • lds_bytes_and_halves_match_the_hardware still passes.
  • victory-shader: 210 passed, 0 failed (main alone: 209).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

Left as is: the alignment part of the shortcut (a b32 access at an address that isn't a multiple of 4). On RDNA2 that depends on whether unaligned mode is set, and I found nothing saying which mode the console runs in, so I didn't guess.

Patch against 70564ae0
diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs
index 65bd8f22..92a2628e 100644
--- a/crates/victory-shader/src/emit/lower.rs
+++ b/crates/victory-shader/src/emit/lower.rs
@@ -3013,17 +3013,31 @@ impl<'a> Lower<'a> {
             return Err("LDS the program does not allocate");
         }
         let a = self.vgprs(inst, addr.as_ref().ok_or("an LDS address")?, 1)?[0];
-        // shortcut: LDS addresses are taken as aligned to what they access
-        // and in bounds (out-of-bounds console accesses read 0 and drop
-        // writes).
-        let dword = |l: &mut Self, bytes: u32| -> V {
+        // shortcut: LDS addresses are taken as aligned to what they access.
+        // The address is `addr + offset` in 32 bits (it wraps: LLVM folds a
+        // base below 0 and an offset on GFX7 and later). Each dword comes
+        // with whether it lies inside the program's LDS:
+        // out-of-bounds console accesses read 0 and drop writes, and the
+        // host index is clamped so it never leaves the group-shared array.
+        let dword = |l: &mut Self, bytes: u32| -> (V, V) {
             let c = l.cur;
             let o = l.s.m.i32(bytes);
             let at = l.s.m.bin(c, Bin::Add, a, o);
             let two = l.s.m.i32(2);
             let index = l.s.m.bin(c, Bin::LShr, at, two);
+            let n = l.s.m.i32(l.s.lds_dwords);
+            let inside = l.s.m.cmp(c, pred::IULT, index, n);
+            let zero = l.s.m.i32(0);
+            let index = l.s.m.select(c, inside, index, zero);
             let lds = l.s.lds();
-            l.s.m.element(c, lds, index)
+            (l.s.m.element(c, lds, index), inside)
+        };
+        // A lane accesses when its guard holds and the dword is inside.
+        let on = |l: &mut Self, inside: V| -> V {
+            match guard {
+                Some(g) => l.s.m.bin(l.cur, Bin::And, g, inside),
+                None => inside,
+            }
         };
         let width = |n: &str| match n.rsplit('_').next() {
             Some("b64") => 2,
@@ -3057,8 +3071,10 @@ impl<'a> Lower<'a> {
                     _ => return Err("an LDS read of bytes or halves"),
                 };
                 let reg = dst_reg.ok_or("an LDS read result")?;
-                let p = dword(self, offset);
+                let (p, inside) = dword(self, offset);
                 let x = self.s.m.load(c, p);
+                let zero = self.s.m.i32(0);
+                let x = self.s.m.select(c, inside, x, zero);
                 let sh = self.lds_shift(a, offset);
                 let x = self.s.m.bin(c, Bin::LShr, x, sh);
                 let left = self.s.m.i32(32 - bits);
@@ -3093,8 +3109,10 @@ impl<'a> Lower<'a> {
             let mut n = 0;
             for (off, w) in elements {
                 for k in 0..w {
-                    let p = dword(self, off + 4 * k);
+                    let (p, inside) = dword(self, off + 4 * k);
                     let x = self.s.m.load(self.cur, p);
+                    let zero = self.s.m.i32(0);
+                    let x = self.s.m.select(self.cur, inside, x, zero);
                     self.write(inst, Reg::V(reg + n), x, guard);
                     n += 1;
                 }
@@ -3131,8 +3149,9 @@ impl<'a> Lower<'a> {
                 let part = self.s.m.bin(c, Bin::Shl, mask, sh);
                 let ones = self.s.m.i32(u32::MAX);
                 let keep = self.s.m.bin(c, Bin::Xor, part, ones);
-                let p = dword(self, offset);
-                let at = self.begin_guarded(guard);
+                let (p, inside) = dword(self, offset);
+                let g = on(self, inside);
+                let at = self.begin_guarded(Some(g));
                 use super::bitcode::Rmw;
                 self.s.m.atomic(self.cur, Rmw::And, p, keep);
                 self.s.m.atomic(self.cur, Rmw::Or, p, set);
@@ -3146,12 +3165,13 @@ impl<'a> Lower<'a> {
                     stores.push((off + 4 * k as u32, x));
                 }
             }
-            let at = self.begin_guarded(guard);
             for (off, x) in stores {
-                let p = dword(self, off);
+                let (p, inside) = dword(self, off);
+                let g = on(self, inside);
+                let at = self.begin_guarded(Some(g));
                 self.s.m.store(self.cur, p, x);
+                self.end_guarded(at, &[]);
             }
-            self.end_guarded(at, &[]);
             return Ok(());
         }
         // Atomics: the old value returns with `_rtn`.
@@ -3184,8 +3204,16 @@ impl<'a> Lower<'a> {
             Some((_, v)) => self.i32_of(v).unwrap_or(self.s.m.i32(0)),
             None => self.s.m.i32(0),
         };
-        let p = dword(self, offset);
-        let at = self.begin_guarded(guard);
+        let (p, inside) = dword(self, offset);
+        // Lanes the guard leaves out keep the old register; lanes outside
+        // the LDS read 0.
+        let zero = self.s.m.i32(0);
+        let outside = match guard {
+            Some(g) => self.s.m.select(self.cur, g, zero, outside),
+            None => zero,
+        };
+        let g = on(self, inside);
+        let at = self.begin_guarded(Some(g));
         let r = match rmw {
             Some(op) => self.s.m.atomic(self.cur, op, p, v0),
             // Compare with data0, store data1.
diff --git a/crates/victory-shader/src/emit/semantics_tests.rs b/crates/victory-shader/src/emit/semantics_tests.rs
index 3b9f8d23..c954a9cd 100644
--- a/crates/victory-shader/src/emit/semantics_tests.rs
+++ b/crates/victory-shader/src/emit/semantics_tests.rs
@@ -3008,3 +3008,50 @@ fn lds_bytes_and_halves_match_the_hardware() {
         }),
     ]));
 }
+
+/// DS `op` with both offset bytes: `offset0` | `offset1` << 8.
+fn ds_at(op: u32, vdst: u8, addr: u8, data: u8, offset: u16) -> [u32; 2] {
+    [
+        0xD800_0000 | op << 18 | u32::from(offset),
+        u32::from(vdst) << 24 | u32::from(data) << 8 | u32::from(addr),
+    ]
+}
+
+/// LDS accesses past the program's allocation (512 bytes here) read 0 and
+/// drop writes (RDNA2 ISA DS), for dwords, bytes, read2 and returning
+/// atomics; a dropped write must not land in bounds, an address that wraps
+/// at 32 bits back inside is inside, and lanes EXEC leaves out keep their
+/// registers. Each thread uses its
+/// own dword and the dword 512 bytes past it.
+#[test]
+fn lds_out_of_bounds_reads_zero_and_drops_writes() {
+    let inputs = pairs(U32_EDGES, &U32_EDGES[..10]);
+    let mut plain = vec![vop2(0x1A, 11, int(2), 0)];
+    plain.extend(ds_at(0x0D, 0, 11, 1, 0)); // ds_write_b32 [own], a
+    plain.extend(ds_at(0x0D, 0, 11, 2, 512)); // ds_write_b32 [own + 512], b
+    plain.extend(ds_at(0x36, 5, 11, 0, 0)); // ds_read_b32 v5, [own]
+    plain.extend(ds_at(0x36, 6, 11, 0, 512)); // ds_read_b32 v6, [own + 512]
+    plain.extend(ds_at(0x36, 7, 11, 0, 0xFFFC)); // ds_read_b32 v7, [own + 65532]
+    plain.extend(ds_at(0x39, 8, 11, 0, 600)); // ds_read_i8 v8, [own + 600]
+    let mut more = vec![vop2(0x1A, 11, int(2), 0)];
+    more.extend(ds_at(0x0D, 0, 11, 1, 0)); // ds_write_b32 [own], a
+    more.extend(ds_at(0x1E, 0, 11, 2, 513)); // ds_write_b8 [own + 513], b
+    more.extend(ds_at(0x37, 5, 11, 0, 200 << 8)); // ds_read2_b32 v[5:6], [own], [own + 800]
+    more.extend(ds_at(0x20, 7, 11, 2, 512)); // ds_add_rtn_u32 v7, [own + 512], b
+    // The address wraps at 32 bits, as LLVM's DS offset folding takes it
+    // on CI and later (a base below 0 plus the offset): own - 16 + 16.
+    more.push(vop2(0x25, 12, 208, 11)); // v_add_nc_u32 v12, -16, v11
+    more.extend(ds_at(0x36, 8, 12, 0, 16)); // ds_read_b32 v8, [own - 16 + 16]
+    // Lanes EXEC leaves out keep the old register; active lanes outside
+    // the LDS get 0 from a returning atomic.
+    let mut masked = vec![vop2(0x1A, 11, int(2), 0)];
+    masked.push(vopc(0xC4, v(1), 2)); // v_cmp_gt_u32 vcc, v1, v2
+    masked.push(sop1(0x3C, 20, VCC)); // s_and_saveexec_b32 s20, vcc
+    masked.extend(ds_at(0x20, 5, 11, 2, 512)); // ds_add_rtn_u32 v5, [own + 512], b
+    masked.push(sop1(0x03, 126, s(20)));
+    assert_clean(check(&[
+        probe(plain, inputs.clone(), INT, |i| vec![i[0], 0, 0, 0]),
+        probe(more, inputs.clone(), INT, |i| vec![i[0], 0, 0, i[0]]),
+        probe(masked, inputs, INT, |i| vec![if i[0] > i[1] { 0 } else { OLD }]),
+    ]));
+}

Unit tests only, no game files. AI-assisted (Claude wrote the patch; I ran it on my machine).

<!-- greyfinch-sync:Marvisak/VIctory:issue:6593881509 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/1870). Originally posted by [wwwwwwww3333333](https://github.com/wwwwwwww3333333) on 2026-11-24T23:55:38Z. --- `lower.rs` (main 70564ae0) has this shortcut in the DS lowering: > shortcut: LDS addresses are taken as aligned to what they access and in bounds (out-of-bounds console accesses read 0 and drop writes). On the host, an out-of-bounds index into the group-shared array is undefined behavior. On my card it isn't harmless: the write goes through and can be read back. **What I measured**, with a new semantics test on main's lowering. Each thread writes its own dword, then writes `b` 512 bytes past it. The probe's LDS is 512 bytes, so that write is out of bounds. Reading the out-of-bounds dword back: - RX 6750 XT (RDNA2): returns `b` on 306 of 340 inputs. The out-of-bounds write was kept. - WARP: returns 0. So the hardware adapter and WARP disagree, and neither is guaranteed. **Patch:** each LDS dword access now carries "inside the program's LDS". - Reads select 0 when outside. - Stores, byte/half stores and atomics run only where the lane guard *and* inside hold. - Returning atomics give 0 outside; lanes EXEC leaves out keep the old register, as before. - The host index is clamped to 0 when outside, so it never leaves the array. This covers dword reads and writes, read2/write2, byte/half reads and writes, and atomics. The address stays `addr + offset` wrapping at 32 bits. That matches LLVM, which on GFX7 and later folds a negative base plus an offset into one DS instruction (`isDSOffsetLegal`; only Southern Islands needs the sign bit clear). A comment now says so. **Results** on 70564ae0, RX 6750 XT, Windows 11, Rust 1.98.1 MSVC. The new test `lds_out_of_bounds_reads_zero_and_drops_writes` has three probes: 1. b32 write/read at +512 and +65532, and `ds_read_i8` at +600. - Before the patch it fails on hardware (306/340); WARP is fine. - After the patch it passes on both. 2. `ds_write_b8` at +513, `ds_read2_b32` with offset1 800 bytes, `ds_add_rtn_u32` at +512, then a read through a base of own - 16 with offset 16 (32-bit wrap back inside). 3. A returning atomic at +512 under a partial EXEC: active lanes get 0, inactive lanes keep their register. Probes 2 and 3 already pass on main on this card; they pin the behavior. After the patch all three pass on hardware and WARP. Other results: - `lds_bytes_and_halves_match_the_hardware` still passes. - victory-shader: 210 passed, 0 failed (main alone: 209). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. **Left as is:** the alignment part of the shortcut (a b32 access at an address that isn't a multiple of 4). On RDNA2 that depends on whether unaligned mode is set, and I found nothing saying which mode the console runs in, so I didn't guess. <details><summary>Patch against 70564ae0</summary> ```diff diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index 65bd8f22..92a2628e 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -3013,17 +3013,31 @@ impl<'a> Lower<'a> { return Err("LDS the program does not allocate"); } let a = self.vgprs(inst, addr.as_ref().ok_or("an LDS address")?, 1)?[0]; - // shortcut: LDS addresses are taken as aligned to what they access - // and in bounds (out-of-bounds console accesses read 0 and drop - // writes). - let dword = |l: &mut Self, bytes: u32| -> V { + // shortcut: LDS addresses are taken as aligned to what they access. + // The address is `addr + offset` in 32 bits (it wraps: LLVM folds a + // base below 0 and an offset on GFX7 and later). Each dword comes + // with whether it lies inside the program's LDS: + // out-of-bounds console accesses read 0 and drop writes, and the + // host index is clamped so it never leaves the group-shared array. + let dword = |l: &mut Self, bytes: u32| -> (V, V) { let c = l.cur; let o = l.s.m.i32(bytes); let at = l.s.m.bin(c, Bin::Add, a, o); let two = l.s.m.i32(2); let index = l.s.m.bin(c, Bin::LShr, at, two); + let n = l.s.m.i32(l.s.lds_dwords); + let inside = l.s.m.cmp(c, pred::IULT, index, n); + let zero = l.s.m.i32(0); + let index = l.s.m.select(c, inside, index, zero); let lds = l.s.lds(); - l.s.m.element(c, lds, index) + (l.s.m.element(c, lds, index), inside) + }; + // A lane accesses when its guard holds and the dword is inside. + let on = |l: &mut Self, inside: V| -> V { + match guard { + Some(g) => l.s.m.bin(l.cur, Bin::And, g, inside), + None => inside, + } }; let width = |n: &str| match n.rsplit('_').next() { Some("b64") => 2, @@ -3057,8 +3071,10 @@ impl<'a> Lower<'a> { _ => return Err("an LDS read of bytes or halves"), }; let reg = dst_reg.ok_or("an LDS read result")?; - let p = dword(self, offset); + let (p, inside) = dword(self, offset); let x = self.s.m.load(c, p); + let zero = self.s.m.i32(0); + let x = self.s.m.select(c, inside, x, zero); let sh = self.lds_shift(a, offset); let x = self.s.m.bin(c, Bin::LShr, x, sh); let left = self.s.m.i32(32 - bits); @@ -3093,8 +3109,10 @@ impl<'a> Lower<'a> { let mut n = 0; for (off, w) in elements { for k in 0..w { - let p = dword(self, off + 4 * k); + let (p, inside) = dword(self, off + 4 * k); let x = self.s.m.load(self.cur, p); + let zero = self.s.m.i32(0); + let x = self.s.m.select(self.cur, inside, x, zero); self.write(inst, Reg::V(reg + n), x, guard); n += 1; } @@ -3131,8 +3149,9 @@ impl<'a> Lower<'a> { let part = self.s.m.bin(c, Bin::Shl, mask, sh); let ones = self.s.m.i32(u32::MAX); let keep = self.s.m.bin(c, Bin::Xor, part, ones); - let p = dword(self, offset); - let at = self.begin_guarded(guard); + let (p, inside) = dword(self, offset); + let g = on(self, inside); + let at = self.begin_guarded(Some(g)); use super::bitcode::Rmw; self.s.m.atomic(self.cur, Rmw::And, p, keep); self.s.m.atomic(self.cur, Rmw::Or, p, set); @@ -3146,12 +3165,13 @@ impl<'a> Lower<'a> { stores.push((off + 4 * k as u32, x)); } } - let at = self.begin_guarded(guard); for (off, x) in stores { - let p = dword(self, off); + let (p, inside) = dword(self, off); + let g = on(self, inside); + let at = self.begin_guarded(Some(g)); self.s.m.store(self.cur, p, x); + self.end_guarded(at, &[]); } - self.end_guarded(at, &[]); return Ok(()); } // Atomics: the old value returns with `_rtn`. @@ -3184,8 +3204,16 @@ impl<'a> Lower<'a> { Some((_, v)) => self.i32_of(v).unwrap_or(self.s.m.i32(0)), None => self.s.m.i32(0), }; - let p = dword(self, offset); - let at = self.begin_guarded(guard); + let (p, inside) = dword(self, offset); + // Lanes the guard leaves out keep the old register; lanes outside + // the LDS read 0. + let zero = self.s.m.i32(0); + let outside = match guard { + Some(g) => self.s.m.select(self.cur, g, zero, outside), + None => zero, + }; + let g = on(self, inside); + let at = self.begin_guarded(Some(g)); let r = match rmw { Some(op) => self.s.m.atomic(self.cur, op, p, v0), // Compare with data0, store data1. diff --git a/crates/victory-shader/src/emit/semantics_tests.rs b/crates/victory-shader/src/emit/semantics_tests.rs index 3b9f8d23..c954a9cd 100644 --- a/crates/victory-shader/src/emit/semantics_tests.rs +++ b/crates/victory-shader/src/emit/semantics_tests.rs @@ -3008,3 +3008,50 @@ fn lds_bytes_and_halves_match_the_hardware() { }), ])); } + +/// DS `op` with both offset bytes: `offset0` | `offset1` << 8. +fn ds_at(op: u32, vdst: u8, addr: u8, data: u8, offset: u16) -> [u32; 2] { + [ + 0xD800_0000 | op << 18 | u32::from(offset), + u32::from(vdst) << 24 | u32::from(data) << 8 | u32::from(addr), + ] +} + +/// LDS accesses past the program's allocation (512 bytes here) read 0 and +/// drop writes (RDNA2 ISA DS), for dwords, bytes, read2 and returning +/// atomics; a dropped write must not land in bounds, an address that wraps +/// at 32 bits back inside is inside, and lanes EXEC leaves out keep their +/// registers. Each thread uses its +/// own dword and the dword 512 bytes past it. +#[test] +fn lds_out_of_bounds_reads_zero_and_drops_writes() { + let inputs = pairs(U32_EDGES, &U32_EDGES[..10]); + let mut plain = vec![vop2(0x1A, 11, int(2), 0)]; + plain.extend(ds_at(0x0D, 0, 11, 1, 0)); // ds_write_b32 [own], a + plain.extend(ds_at(0x0D, 0, 11, 2, 512)); // ds_write_b32 [own + 512], b + plain.extend(ds_at(0x36, 5, 11, 0, 0)); // ds_read_b32 v5, [own] + plain.extend(ds_at(0x36, 6, 11, 0, 512)); // ds_read_b32 v6, [own + 512] + plain.extend(ds_at(0x36, 7, 11, 0, 0xFFFC)); // ds_read_b32 v7, [own + 65532] + plain.extend(ds_at(0x39, 8, 11, 0, 600)); // ds_read_i8 v8, [own + 600] + let mut more = vec![vop2(0x1A, 11, int(2), 0)]; + more.extend(ds_at(0x0D, 0, 11, 1, 0)); // ds_write_b32 [own], a + more.extend(ds_at(0x1E, 0, 11, 2, 513)); // ds_write_b8 [own + 513], b + more.extend(ds_at(0x37, 5, 11, 0, 200 << 8)); // ds_read2_b32 v[5:6], [own], [own + 800] + more.extend(ds_at(0x20, 7, 11, 2, 512)); // ds_add_rtn_u32 v7, [own + 512], b + // The address wraps at 32 bits, as LLVM's DS offset folding takes it + // on CI and later (a base below 0 plus the offset): own - 16 + 16. + more.push(vop2(0x25, 12, 208, 11)); // v_add_nc_u32 v12, -16, v11 + more.extend(ds_at(0x36, 8, 12, 0, 16)); // ds_read_b32 v8, [own - 16 + 16] + // Lanes EXEC leaves out keep the old register; active lanes outside + // the LDS get 0 from a returning atomic. + let mut masked = vec![vop2(0x1A, 11, int(2), 0)]; + masked.push(vopc(0xC4, v(1), 2)); // v_cmp_gt_u32 vcc, v1, v2 + masked.push(sop1(0x3C, 20, VCC)); // s_and_saveexec_b32 s20, vcc + masked.extend(ds_at(0x20, 5, 11, 2, 512)); // ds_add_rtn_u32 v5, [own + 512], b + masked.push(sop1(0x03, 126, s(20))); + assert_clean(check(&[ + probe(plain, inputs.clone(), INT, |i| vec![i[0], 0, 0, 0]), + probe(more, inputs.clone(), INT, |i| vec![i[0], 0, 0, i[0]]), + probe(masked, inputs, INT, |i| vec![if i[0] > i[1] { 0 } else { OLD }]), + ])); +} ``` </details> Unit tests only, no game files. AI-assisted (Claude wrote the patch; I ran it on my machine).
wwwwwwww3333333 commented 2026-11-25 01:08:20 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by wwwwwwww3333333 on 2026-11-25T01:00:55Z.


Update: main has moved to 42363ab6, and the patch above still applies cleanly there (no changes needed). Re-run on that main, same card (RX 6750 XT, Windows 11, Rust 1.98.1 MSVC):

  • lds_out_of_bounds_reads_zero_and_drops_writes: passes.
  • victory-shader: 247 passed, 0 failed. Main alone: 246.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7149117885 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/1870#issuecomment-7149117885). Originally posted by [wwwwwwww3333333](https://github.com/wwwwwwww3333333) on 2026-11-25T01:00:55Z. --- Update: main has moved to 42363ab6, and the patch above still applies cleanly there (no changes needed). Re-run on that main, same card (RX 6750 XT, Windows 11, Rust 1.98.1 MSVC): - `lds_out_of_bounds_reads_zero_and_drops_writes`: passes. - victory-shader: 247 passed, 0 failed. Main alone: 246. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean.
jules47800 commented 2026-11-25 02:06:01 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by jules47800 on 2026-11-25T01:25:12Z.


Same fix as PR #1769 (opened earlier, mergeable). I ran your test on it. On RX 6600 XT + WARP it passes on #1769's head and on #1769 merged into main 42363ab. On main alone it fails with the same 306/340 you measured on the RX 6750 XT. Details are on #1769. Once #1769 lands this issue can close, ideally with your test added there.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149526216 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/1870#issuecomment-7149526216). Originally posted by [jules47800](https://github.com/jules47800) on 2026-11-25T01:25:12Z. --- Same fix as PR #1769 (opened earlier, mergeable). I ran your test on it. On RX 6600 XT + WARP it passes on #1769's head and on #1769 merged into main `42363ab`. On main alone it fails with the same 306/340 you measured on the RX 6750 XT. Details are on #1769. Once #1769 lands this issue can close, ideally with your test added there.
YaBulochka commented 2026-11-25 05:06:27 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by YaBulochka on 2026-11-25T05:02:14Z.


RADV/RDNA3 data point: the out-of-bounds LDS write is kept here on every workgroup, so the clamp in this patch is needed on Linux too.

Setup. Linux, Vulkan 1.4, RADV, Radeon RX 7600 (NAVI33, gfx1102). Minimal compute test: shared uint smem[128] (512 B, the program's allocation), 64 lanes per workgroup. Each lane writes its own dword, barrier(), then writes b at smem[128 + lane] (512..764 B, past the allocation), barrier(), and reads it back into an SSBO. 340 workgroups, each with its own b (0xDEAD0000 + wg).

Result:

workgroups: 340 | OOB write kept: 340 | read 0: 0 | mixed/other: 0
sample: wg0 lane0..3 = dead0000 dead0000 dead0000 dead0000

So on this host the out-of-bounds store lands and is read back, the same shape as the RX 6750 XT measurement (306/340), and not the WARP answer (0). Every one of the 340 kept it here, so it is not a flaky race in this run.

Compared with the report: same outcome as RDNA2 under the Windows driver, i.e. the "reads 0, drops writes" console shortcut is wrong on a second AMD platform, and the per-access "inside the program's LDS" guard this patch adds is what makes it defined.

Caveat, in fairness: this is a raw SPIR-V shared array with a dynamic index, not the exact lowering in lower.rs; a driver is free to change this, and none of it is guaranteed by the spec. But it is what the hardware does today, and the patch removes the dependence on it.

Harness is a ~150-line Vulkan compute program plus a 16-line GLSL shader; no title run. I can rerun it on the iGPU or on R16_SNORM-style variants if useful.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153390177 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/1870#issuecomment-7153390177). Originally posted by [YaBulochka](https://github.com/YaBulochka) on 2026-11-25T05:02:14Z. --- RADV/RDNA3 data point: the out-of-bounds LDS write is kept here on every workgroup, so the clamp in this patch is needed on Linux too. **Setup.** Linux, Vulkan 1.4, RADV, **Radeon RX 7600 (NAVI33, gfx1102)**. Minimal compute test: `shared uint smem[128]` (512 B, the program's allocation), 64 lanes per workgroup. Each lane writes its own dword, `barrier()`, then writes `b` at `smem[128 + lane]` (512..764 B, past the allocation), `barrier()`, and reads it back into an SSBO. 340 workgroups, each with its own `b` (`0xDEAD0000 + wg`). **Result:** ``` workgroups: 340 | OOB write kept: 340 | read 0: 0 | mixed/other: 0 sample: wg0 lane0..3 = dead0000 dead0000 dead0000 dead0000 ``` So on this host the out-of-bounds store lands and is read back, the same shape as the RX 6750 XT measurement (306/340), and not the WARP answer (0). Every one of the 340 kept it here, so it is not a flaky race in this run. Compared with the report: same outcome as RDNA2 under the Windows driver, i.e. the "reads 0, drops writes" console shortcut is wrong on a second AMD platform, and the per-access "inside the program's LDS" guard this patch adds is what makes it defined. Caveat, in fairness: this is a raw SPIR-V `shared` array with a dynamic index, not the exact lowering in `lower.rs`; a driver is free to change this, and none of it is guaranteed by the spec. But it is what the hardware does today, and the patch removes the dependence on it. Harness is a ~150-line Vulkan compute program plus a 16-line GLSL shader; no title run. I can rerun it on the iGPU or on `R16_SNORM`-style variants if useful.
Marvisak commented 2026-11-25 13:03:00 +00:00 (Migrated from github.com)
Author
Contributor

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T12:50:28Z.


Automated triage for the maintainers.

Confirmed in main (940d32f): the DS lowering in crates/victory-shader/src/emit/lower.rs (the dword helper of the LDS path) still takes LDS addresses as in bounds and indexes the group-shared array with no check, so an out-of-bounds console access is undefined behaviour on the host. The measurements agree: RX 6750 XT (306/340 kept), RX 6600 XT and RADV on an RX 7600 (340/340) keep the out-of-bounds write, while WARP reads 0.

The patch in the body is carried by open PRs: #1949 (this issue's change) and #1769 (opened earlier, same fix; your test passes on it). Please settle on one of them and add the lds_out_of_bounds_reads_zero_and_drops_writes test to it.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7162930618 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/issues/1870#issuecomment-7162930618). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T12:50:28Z. --- <!-- victory-issue-triage v1 verdict=confirmed seen=2026-11-25T05:02:14Z at=2026-11-25T12:50:15Z --> Automated triage for the maintainers. Confirmed in `main` (`940d32f`): the DS lowering in `crates/victory-shader/src/emit/lower.rs` (the `dword` helper of the LDS path) still takes LDS addresses as in bounds and indexes the group-shared array with no check, so an out-of-bounds console access is undefined behaviour on the host. The measurements agree: RX 6750 XT (306/340 kept), RX 6600 XT and RADV on an RX 7600 (340/340) keep the out-of-bounds write, while WARP reads 0. The patch in the body is carried by open PRs: #1949 (this issue's change) and #1769 (opened earlier, same fix; your test passes on it). Please settle on one of them and add the `lds_out_of_bounds_reads_zero_and_drops_writes` test to it. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
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
Marvisak/VIctory#1868
No description provided.