Skip to content

Shaders: LDS byte and half accesses - #571

Closed
SAitken91 wants to merge 5 commits into
Marvisak:mainfrom
SAitken91:shader/lds-bytes-halves
Closed

SAitken91 wants to merge 5 commits into
Marvisak:mainfrom
SAitken91:shader/lds-bytes-halves

Conversation

@SAitken91

Copy link
Copy Markdown
Contributor

ds_read_{u8,i8,u16,i16} and ds_write_{b8,b16}, with their _d16/_d16_hi forms, were refused ("an LDS read/write of bytes or halves"). That blocked 16 compute programs in shaders.rpf, mostly compute_graph_ops reductions and transposes.

Change

LDS is an array of dwords in the translation, so these accesses now work on the dword holding them, at bit 8 * (address & 3). They are naturally aligned, so they never straddle two dwords.

  • Reads shift and mask, or sign-extend for i8/i16. _d16 fills the register's low half and _d16_hi its high half, keeping the other half.
  • Writes clear the bits with an atomic and, then set them with an atomic or. Lanes writing other bytes of the same dword therefore keep their values, and as on the console, two lanes writing the same byte race. _d16_hi takes the data's high half.

Results

victory translate --validate shaders.rpf: compute validated 1670 → 1686 (all 16). Both errors are gone from the list.

Testing

  • cargo test -p victory-shader: 69 passed. Clippy and rustfmt are clean.
  • Not exercised at runtime.

This is independent of #539, #554, #563, #565 and #569.

Written with the help of Claude (AI).

🤖 Generated with Claude Code

@KoLolX3

KoLolX3 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Check on Linux, not Windows: pass. Head 6e981fb26 merged onto main d2a4bae1f (clean merge).

  • Native tests of the seven crates that build on Linux (core, formats, game, loader, pe, pipeline, shader): PR 92 passed, 7 failed, main 92 passed, 7 failed.
  • Windows cross type-check of the whole workspace (cargo xwin check --workspace --target x86_64-pc-windows-msvc, covers victory-gpu, victory-hle and the app): PR ok, main ok.
  • Tests this PR adds: 0 (so the native result only shows the existing tests still pass; the change itself is not covered by a test here).
  • rustfmt: unformatted hunks, PR 168, main 168.
  • Failing on main here as well (not this PR): 7 tests in victory-loader and victory-pe that parse their own test binary as a PE image, which is an ELF file on Linux.
  • Not run: victory-gpu / victory-hle tests and the game itself.

On: AMD Ryzen 7 5700, 62 GB RAM, Artix Linux 7.3.4-artix1-2, rustc 1.98.1 (the repo's pinned toolchain), cargo-xwin 0.24.1. No game data. Automated check only: the code itself was not reviewed.

@ghost ghost mentioned this pull request Nov 24, 2026
@ghost

ghost commented Nov 24, 2026

Copy link
Copy Markdown

Review note on head 6e981fb: for ds_read_*_d16 / _d16_hi, crates/victory-shader/src/emit/lower.rs:2135 keeps the destination's other half by reading its old value with inst.read(Reg::V(reg)), and falls back to 0 when that is None.

On main, ir.rs effects() (the Fields::Ds arm, around line 842) adds a ds_read destination only to the written registers, and Inst::read only searches the read list. So for these reads inst.read is always None and the kept half is always zeroed: a _d16 read clears the high 16 bits, a _d16_hi read clears the low 16.

#116 fixes this in effects():

if name.starts_with("ds_read") && name.contains("_d16") {
    regs(d, &mut r)?;
}

This PR would need the same, plus a test that writes a known value to the destination first and checks the other half survives.

Read-only review, nothing built. AI-assisted (Claude Code); the claim above was checked against this head and main at d2a4bae. Context: the triage in #366.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17:

  • Translation failures: 3,733 on main -> 3,717 with this PR (-16, all compute). "an LDS write of bytes or halves" (9) and "an LDS read of bytes or halves" (7) disappear; compute validated 1,670 -> 1,686, matching your numbers.
  • Validation: 185 modules rejected on both; no program that validated on main fails now.

AI-assisted.

@Dathinel

Dathinel commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up: the translated readback is now available. Claude Code ran the test on our Windows 11 machine using #571 at 6e981fb2 on base d2a4bae1 (test merge 16b4d6a). On both RTX 3050 Laptop and WARP, all 64 lanes agreed. With the first fixture the aligned value was 0x8281, but the crossing read returned 0x0082 (little-endian two-byte reference 0x9882). With complemented inputs, the aligned value was 0x7d7e and the crossing read was 0x007d (reference 0x677d). Both crossing results retained just the last byte of the first dword. This supplies the requested host measurement; the console alignment mode remains unknown.

One remaining distinction is a halfword read across a dword boundary. In the native RDNA2 experiment on #116, an odd-address ds_read_u16 read the two bytes at that address in the tested desktop HIP mode. Our translated readbacks used aligned halfwords.

If anyone already has this PR built on Windows with D3D12, could you report the translated result for one aligned control and one crossing read? In the synthetic test module, inside byte_and_halfword_reads, keep only the ds_read_u16 entry and replace for at in addresses(name) with for at in [0u32, 1]. The instruction adds 2. For the first fixture the effective byte addresses are 2 and 3, both inside the eight initialized bytes. The little-endian reference values are 0x8281 and 0x9882.

The setup and Cargo command are here. Filter on emit::vic13_lds::byte_and_halfword_reads to run just this test. The PR SHA, adapter, and result (or first assertion showing actual/expected) are enough. This would tell us how the translation compares with that measured desktop mode. The console's alignment mode remains an open question. AI-assisted.

SAitken91 added a commit to SAitken91/VIctory that referenced this pull request Nov 24, 2026
A 16-bit LDS access at byte 3 of a dword was taken as aligned: a read
returned only the dword's last byte (Dathinel's readback on Marvisak#571:
0x0082 for the reference 0x9882) and a write would have lost its high
byte. The next dword now joins in, as native RDNA2 reads an odd-address
ds_read_u16: reads shift the two dwords as one 64-bit value, writes
clear and set bits in both (no-ops on the next dword when nothing
straddles). The next index is clamped to the last LDS dword.

translate --validate on shaders.rpf unchanged (compute 1686 validated
with this PR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SAitken91

Copy link
Copy Markdown
Contributor Author

@TrashTalker3460 thanks for the careful read. I checked it on this head: ir.rs already makes every VGPR write also read the register's old value (effects(), the if vector block: "Lanes disabled in EXEC keep the old value"), and DS instructions take that path, so inst.read(Reg::V(reg)) is Some for ds_read_u16_d16 / _d16_hi. A quick IR test (ds_read_u16_d16 v2 / _d16_hi v3) passes without the effects() change, so the kept half isn't zeroed here. Happy to add that test if it's useful.

@Dathinel thanks for the readback — that one was a real gap: I had assumed halves never straddle. Pushed d27cb78: a 16-bit access at byte 3 now uses the next dword too (reads shift the two dwords as one 64-bit value; writes clear and set bits in both, no-ops on the next dword when nothing straddles; the next index is clamped to the last LDS dword). It matches the odd-address ds_read_u16 behaviour measured on native RDNA2; the console's alignment mode is still an open question. Validation is unchanged (compute 1686). If you can rerun your crossing fixture on d27cb78, the expected values would be 0x9882 / 0x677d.

@Dathinel

Copy link
Copy Markdown
Contributor

Confirmed on your exact head d27cb78960ed. The same ds_read_u16 fixture now returns 0x9882 and 0x677d at byte 3, on both the RTX 3050 Laptop and WARP. On 6e981fb2 the corresponding results were 0x0082 and 0x007d. The aligned control at byte 2 still returns 0x8281 and 0x7d7e. All 64 lanes agreed in every dispatch.

I reran cargo test --frozen -p victory-shader --features host --lib emit::vic13_lds::byte_and_halfword_reads -- --exact --nocapture with the same synthetic module on Windows 11. This verifies the crossing read against the measured desktop RDNA2 behavior. Thanks for fixing it. AI-assisted.

@slint6614-dev

Copy link
Copy Markdown

Measured on the full retail shader pack (26,503 containers) with victory translate --validate --pipelines (pipelines created on an AMD RX 9070, Windows 11, dxil.dll from SDK 10.0.26100). Counts are emitted / validated / pipelines. This PR was merged locally with current main c7a5f49 first (main: VS/PS 12224 / 12148, CS 1440 / 1417, MS 8163 / 8101; it includes #612).

CS 1456 / 1433 (+16 validated): all 7 "LDS read of bytes or halves" and 9 "LDS write of bytes or halves" refusals are gone, and the 16 programs validate. VS/PS and MS unchanged. Same result as #101 on the same pack.

@akimfomin

akimfomin commented Nov 24, 2026 •

Copy link
Copy Markdown

I reran two focused LDS regressions on d27cb78960ed using synthetic D3D12 compute shaders. Both passed on an RTX 4070 Ti SUPER and WARP. Both failed with the previous emitter.

  • Signed and unsigned D16_HI byte loads at offsets 0–3 extend into the high half while retaining the destination’s low half.
  • The halfword crossing case complements Dathinel’s ds_read_u16 check: ds_read_u16_d16_hi at byte 3, with LDS words 0xAB123456 and 0xDEADCDBE and initial destination 0xCAFE1357, returned 0xBEAB1357.

PortBridge surfaced XCL #544 for the partial-destination cases and Continued #507 for the single-writer fixture correction. Would these be useful in your valu_tests.rs harness?

Test-only patch for d27cb78
--- a/crates/victory-shader/src/emit/valu_tests.rs
+++ b/crates/victory-shader/src/emit/valu_tests.rs
@@ -13,6 +13,7 @@
 use crate::{io, ir, resource, structure};
 
 const S_ENDPGM: u32 = 0xBF81_0000;
+const S_WAITCNT_ALL: u32 = 0xBF8C_0000;
 
 /// SOP1 `s_mov_b32 sdst, src0`.
 const fn s_mov_b32(sdst: u8, src0: u8) -> u32 {
@@ -49,6 +50,14 @@
     ]
 }
 
+/// GFX10 LDS instruction with a single byte offset.
+const fn ds(op: u8, offset: u16, addr: u8, data: u8, dst: u8) -> [u32; 2] {
+    [
+        0xD800_0000 | (op as u32) << 18 | offset as u32,
+        addr as u32 | (data as u32) << 8 | (dst as u32) << 24,
+    ]
+}
+
 /// MUBUF `buffer_store_dword vdata, off, s[srsrc:srsrc+3], 0 offset:byte_off`.
 const fn buffer_store_dword(vdata: u8, srsrc: u8, byte_off: u16) -> [u32; 2] {
     [
@@ -69,6 +78,10 @@
 /// 4 dwords of root constants in `s0..s3`, runs `body` (leaving its result in
 /// `v0`), and stores `v0` to dword 0 of the raw UAV at heap index 0.
 fn build_valu_cs(body: &[u32]) -> HostShader {
+    build_test_cs(body, 0)
+}
+
+fn build_test_cs(body: &[u32], lds_blocks: u32) -> HostShader {
     let mut words = Vec::new();
     // s[4:5] = descriptor table address (heap index 0 -> byte offset 0).
     words.push(s_mov_b32(5, 0x80)); // inline constant 0
@@ -116,7 +129,7 @@
             slot: 1,
         }],
         io: StageIo::Cs(ComputeIo {
-            rsrc2: 5 << 1, // 5 user SGPRs: s0..s4
+            rsrc2: (lds_blocks << 15) | (5 << 1), // 512 bytes of LDS per block, user SGPRs s0..s4
             threads: [1, 1, 1],
         }),
         code,
@@ -203,6 +216,46 @@
     assert!(ran > 0, "neither hardware nor WARP SM 6.6 device available");
 }
 
+#[test]
+fn lds_d16_hi_reads_keep_the_low_half() {
+    // The same LDS byte must zero- or sign-extend depending on the opcode.
+    let cases = [
+        [0x817F_80FE, 0xCAFE_1357, 0, 0],
+        [0x817F_80FE, 0xCAFE_1357, 1, 0],
+        [0x817F_80FE, 0xCAFE_1357, 2, 0],
+        [0x817F_80FE, 0xCAFE_1357, 3, 0],
+    ];
+    // Exactly one thread writes LDS, as in the Continued #507 fixture correction.
+    for (op, expected) in [
+        (0xA3, [0x00FE_1357, 0x0080_1357, 0x007F_1357, 0x0081_1357]),
+        (0xA5, [0xFFFE_1357, 0xFF80_1357, 0x007F_1357, 0xFF81_1357]),
+    ] {
+        let mut body = vec![vop1(1, 5, 0x80), vop1(1, 0, vgpr(2))];
+        body.extend(ds(0x0D, 0, 5, 1, 0)); // ds_write_b32
+        body.push(S_WAITCNT_ALL);
+        body.extend(ds(op, 0, 3, 0, 0)); // byte offset in v3
+        body.push(S_WAITCNT_ALL);
+        let shader = build_test_cs(&body, 1);
+        run_cases(&shader, &cases, |backend, i, _, got| {
+            assert_eq!(got, expected[i], "{backend}: opcode {op:#x}, byte {i}");
+        });
+    }
+}
+
+#[test]
+fn lds_read_u16_d16_hi_spans_adjacent_dwords() {
+    let mut body = vec![vop1(1, 5, 0x80), vop1(1, 0, vgpr(3))];
+    body.extend(ds(0x0D, 0, 5, 1, 0));
+    body.extend(ds(0x0D, 4, 5, 2, 0));
+    body.push(S_WAITCNT_ALL);
+    body.extend(ds(0xA7, 3, 5, 0, 0)); // ds_read_u16_d16_hi, byte offset 3
+    body.push(S_WAITCNT_ALL);
+    let shader = build_test_cs(&body, 1);
+    run_cases(&shader, &[[0xAB12_3456, 0xDEAD_CDBE, 0xCAFE_1357, 0]], |backend, _, _, got| {
+        assert_eq!(got, 0xBEAB_1357, "{backend}: misaligned halfword read");
+    });
+}
+
 fn is_f16_nan(bits: u16) -> bool {
     (bits & 0x7FFF) > 0x7C00
 }

AI-assisted with Codex.

@alexander-src alexander-src left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVIDIA Blackwell (--validate --pipelines) verification and code review of d27cb78 merged cleanly onto main 8e79c80:

  • Setup: Windows 11 26200, NVIDIA GeForce RTX 5090 (driver 621.24), Rust 1.98.1 (x86_64-pc-windows-msvc), Windows SDK 10.0.26100.0 dxil.dll.
  • CI checks:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: pass
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: pass
    • cargo test -p victory-shader --locked -- --test-threads=1: 89 passed, 0 failed, 1 ignored
  • Full retail corpus (victory translate --validate --pipelines, 26,599 containers / 26,148 programs):
    • Clears all 16 sub-dword LDS refusals (an LDS write of bytes or halves 9 → 0, an LDS read of bytes or halves 7 → 0).
    • Compute: 1,440 / 1,417 / 1,121 → 1,456 (+16) / 1,433 (+16) / 1,123 (+2) (all 16 newly emitted programs validate with dxil.dll; the 2 Wave32 programs create PSOs on RTX 5090, while the other 14 are Wave64 and hit NVIDIA's 32-lane wave limit as expected). VS/PS and MS are unchanged; zero regressions.

One edge-case bug in the straddling-halfword path (crates/victory-shader/src/emit/lower.rs):

When a 16-bit access lands at byte 3 of the final LDS dword (index == lds_dwords - 1, byte == 3, sh == 24), n = select(past, last, index + 1) clamps q back onto p (&lds[last]):

  • Write (ds_write_b16): the second loop iteration (q, true) has mv = 0x0000_00FF and xv = (x >> 8) & 0xFF, so atomicrmw and/or on q == p overwrites byte 0 of lds[last] with the high byte instead of dropping the out-of-bounds byte.
  • Read (ds_read_u16/i16): hi = load(q) reads byte 0 of lds[last] into the upper byte of the result instead of 0.

Masking hi on read (select(past, 0, hi)) and masking (mv, xv) to (0, 0) when past is true on write (reusing the past predicate already computed at line 289) fixes both cases cleanly.

AI-assisted code review and local verification on this machine; no game data.

SAitken91 added a commit to SAitken91/VIctory that referenced this pull request Nov 24, 2026
alexander-src's Marvisak#571 review: when a 16-bit access sits at byte 3 of the
final LDS dword, the clamped "next dword" is that same dword, so a read
took byte 0 as its high byte and a write overwrote byte 0. The next
dword's part is now dropped there: a read sees 0 in its high byte, and
the write's mask and data for the next dword are 0, as out-of-bounds
LDS accesses read 0 and drop writes.

translate --validate on shaders.rpf unchanged (CS 1686 on d2a4bae).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SAitken91

Copy link
Copy Markdown
Contributor Author

@alexander-src confirmed and fixed in ce45c67: at byte 3 of the last LDS dword the clamped next dword is the same dword, so the read now zeroes its high byte (select(past, 0, hi)) and the write's mask and data for the next dword are 0 when past, matching out-of-bounds LDS behaviour. Validation unchanged (CS 1686 on d2a4bae). @akimfomin thanks for the extra D16_HI / crossing regressions.

@MrCloudy2

Copy link
Copy Markdown

Tester result: +2 of 339 previously failing world programs now emit (compute 32 → 34 of 272; the two that logged an LDS write of bytes or halves is not supported). Merged together with #160 and #539 the gains add up exactly: vertex/pixel 11, compute 41.

How measured: 339 shader containers from my own 1.0.2.1 copy, the distinct programs that logged shader does not translate in two world runs, each matched to its container by the BLAKE3 VIctory logs. Each PR was merged on its own onto one base: main 8e79c80 + #151 #190 #454 #493 #579 + #177's key fix + the wave64 stack via #439. I then ran victory translate <folder> (diag build, CPU only) and compared DXIL emitted per stage against the base (vertex/pixel 0 of 25, compute 32 of 272, mesh 0 of 13). Linux, Proton-CachyOS wine, cross-built with xwin, RTX 3060 host (only matters for the wave64 part of the base). Translation counts only, not image correctness. AI-assisted (Claude Code).

adamdotpy asked (Marvisak#571) for a case where the destination of a
ds_read_u16_d16_hi is neither the data nor the address register. v6 is
loaded from v4 first; the read fills v6's high half from LDS and keeps
its own low half (ir.rs makes every VGPR write also read the old value).
Passes on an RX 6950 XT; WARP refuses group-shared programs here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@SAitken91

Copy link
Copy Markdown
Contributor Author

@adamdotpy thanks for the careful pass. Added the case you asked for in 8ad9d9f: lds_d16_hi_keeps_the_destinations_own_low_half reads ds_read_u16_d16_hi into v6 (loaded from v4 first), with v2 in the data field and v5 as the address; v6 ends up v4.lo | lds.lo << 16, passing on an RX 6950 XT. The kept half does come from the destination: ir.rs effects() ends with "lanes disabled in EXEC keep the old value", which adds every VGPR write to the read set, DS included — so inst.read(Reg::V(dst)) is Some (TrashTalker3460 raised the same point earlier; an IR test confirmed it). On your second experiment: with v3 = 0xCCBBAA99 as the preload and 0x44332211 in the LDS dword, 0x2211aa99 is the expected result (kept 0xaa99, read 0x2211), so I think the preload/expectation was what differed rather than the emitter. The lds_dwords - 1 is guarded: an LDS access in a program that allocates none is refused earlier ("LDS the program does not allocate").

@adamdotpy

Copy link
Copy Markdown

Verified 8ad9d9f here (Windows 11 / Rust 1.98.1, isolated target dir): cargo test -p victory-shader --lib 124 passed / 1 ignored, with lds_d16_hi_keeps_the_destinations_own_low_half running on the hardware GPU and passing; clippy --all-targets --all-features --locked -D warnings clean.

Point by point:

The destination-register question — you were right and my review was wrong, and here is the evidence. I re-read ir.rs::effects() and missed its tail: after the per-fields match, for every vector instruction it does r.extend(w.iter().filter(|w| matches!(w, Reg::V(_)))) under the comment "Lanes disabled in EXEC keep the old value". So every VGPR write, DS destinations included, is also in the read set, and inst.read(Reg::V(dst)) is Some — the kept half does come from the destination's own previous value by construction, not by the tests' coincidence. My "effects() declares dst only as written" claim was based on the DS arm alone and is corrected here; the new test pins it empirically anyway (destination v6 preloaded from v4, data field v2, expected v4.lo | lds.lo << 16, which differs from v2's half in every case row, so a data-field read would fail).

My 0x2211aa99 experiment — agreed, that was my expectation being wrong, not the emitter: with the LDS dword 0x44332211 and the kept half 0xaa99 (v3's low half, i.e. the destination's preload did land), 0x2211aa99 is exactly kept-from-destination plus read-from-LDS. I had the read half backwards in my expected value. With the tail of effects() in view, that run was consistent with correct behaviour all along.

lds_dwords - 1 — noted, guarded by the earlier "LDS the program does not allocate" refusal. My saturating_sub suggestion was belt-and-braces for a case that cannot be reached; no change needed.

The straddle and two-atomics points stand as reviewed. With this test added, the LDS half of the branch has both the hardware readbacks from other machines and a host-execution case where the destination is distinct from the data field — nothing left open from my side on #571.

simnJS pushed a commit to MiamiGame/XTP that referenced this pull request Nov 24, 2026
ds_read_{u8,i8,u16,i16} and ds_write_{b8,b16} were refused ("an LDS
read/write of bytes or halves"), with their _d16/_d16_hi forms. LDS is
an array of dwords here; such an access now works on the dword holding
it, at bit 8 * (address & 3):

- reads shift and mask, or sign-extend the i8/i16 forms; _d16 fills the
  register's low half (_d16_hi its high half) and keeps the other;
- writes clear the bits with an atomic and, then set them with an
  atomic or, so lanes writing other bytes of the same dword keep
  theirs; _d16_hi takes the data's high half;
- a half at byte 3 straddles into the next dword, as RDNA2 reads an
  unaligned half (a tester's readback on hardware); past the last LDS
  dword that part reads 0 and is not written.

XTP adaptation: in emit/lower/lds.rs (S0b), in a method of its own.
Review: upstream joined the two dwords as one 64-bit value for every
16-bit access, which made each program with a half access require
64-bit integer operations, and issued the next dword's clear and set
(no-op atomics) even where nothing straddles. Here the straddling half
is put together with 32-bit shifts selected at byte 3, and the next
dword's two atomics run only in the lanes whose half straddles inside
LDS. Left as a shortcut: two lanes writing different values to the same
byte in one instruction leave the bits of both (the console keeps one
lane's).

Tests (upstream had none): hand-assembled programs over two console
waves (a group of one would declare its wave size, which WARP does not
run), translated, validated and run on the test GPU against an LDS of
bytes worked out on the CPU, one GPU test at a time (the lock of
emit/valu_tests.rs): byte and half writes (and _d16_hi) that
share dwords and straddle them, at the last LDS byte too, and every
read form at every byte position.

Survey (shaders.rpf, any host, every translation validated): 23,371 ->
23,387 translated, the 16 programs that stopped at byte or half LDS
accesses (9 writes, 7 reads), all accepted by dxil.dll; none lost, no
translation that existed changed.

Ported from Marvisak/VIctory#571 (head ce45c678b9fe78d0a25f7d68ff2e69910a3e7d4e) by SAitken91
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
simnJS added a commit to MiamiGame/XTP that referenced this pull request Nov 24, 2026
…difiers, packed rows

An independent review of the shader-images delivery (f93bf8e, commits
7e26f66..fca8769) found one translation bug and smaller ones.

1. Compute samples taking their level from their quad (VIctory #180's
   quad gradients, and #160's sampleCmp with implicit derivatives) used
   the wrong quad in a group whose X and Y are both even. The console's
   quad is four consecutive thread ids (its lanes follow the thread
   order). The host's there is a 2 x 2 block of SV_GroupThreadID (SM 6.6
   compute derivatives, which quad reads follow): in numthreads(8,4,1)
   the lane at (0,0) took its "down" neighbour from (0,1), flat id 8,
   not 2. On WARP, lane 0 of the new test sampled level 2 instead of 0.
   A compute program with such samples now declares its group as one
   row of X*Y*Z threads, so the host uses SM 6.6's 1D quads (four
   consecutive SV_GroupIndex). The console's thread ids come from the
   flat id, x fastest; with console lanes, from the relabelled one. A
   group whose size is not a multiple of 4 has no such row, so its
   implicit samples are refused ("an implicit-derivative sample in a
   compute group of a size not a multiple of 4"; none in the pack).
2. VOP3 interpolations (v_interp_p1ll_f16, v_interp_p2_f16) refused only
   abs/neg. A clamp, an output modifier and op_sel were dropped, among
   them the clamp on the computed-barycentric path. The clamp now
   saturates the result, before the f16 conversion (the same result in
   [0, 1]). A clamp on a first half that the host's interpolation
   replaces is refused. So are omod, op_sel (bit 3 writes the
   destination's high half), and any modifier on such a first half.
3. When a packed 16-bit pixel input inferred its second row, it skipped
   the rows the pixel metadata names. Vertex outputs, whose metadata
   names none, do not skip them, so the two stages could pair different
   rows. Both now follow one rule (packed_partners: the next 16-bit row
   no entry names, taken in row order). A second row the pixel metadata
   names that the rule does not give is refused.
4. Tests: the barycentric "values" test read I + J, which passes with I
   and J swapped. It now reads I alone (channel y), J alone (z), then
   both. The LDS half-write test never put two lanes' halves in one
   dword. A new test writes halves side by side, aligned and straddling
   at byte 3, across the two console waves.

Credit correction: Marvisak/VIctory#571 (LDS byte and half accesses,
ported in a391436 from SAitken91's pull request) has head d24c6e4. The
pull request was force-pushed, and a391436's message names ce45c678.

Tests, the 2D one failing before its fix: a GPU test on WARP of plain,
biased, clamped and offset samples in an 8 x 4 group. Before the fix,
lane 0 of both cases sampled level 2 instead of 0; it passes now.
Translation tests: such groups are declared 32x1x1 (with console lanes
too, validated); explicit levels and gradients keep 8x4x1; a group of 6
is refused. The interpolation modifiers are applied or refused, with
host and computed barycentrics. Pixel and vertex rows pair alike. The
LDS and barycentric tests are as described in 4.

Survey (shaders.rpf, any host, every translation validated): 24,243
translated before and after, none lost or gained, 24,085 accepted by
dxil.dll in both runs. 23 compute translations change (their group is
declared as one row), all accepted before and after. No pixel, vertex
or mesh translation changes: no program of the pack has a VOP3
interpolation modifier, or a named second row the rule does not give.

Co-authored-by: Claude <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
A 16-bit LDS access at byte 3 of a dword was taken as aligned: a read
returned only the dword's last byte (Dathinel's readback on #571:
0x0082 for the reference 0x9882) and a write would have lost its high
byte. The next dword now joins in, as native RDNA2 reads an odd-address
ds_read_u16: reads shift the two dwords as one 64-bit value, writes
clear and set bits in both (no-ops on the next dword when nothing
straddles). The next index is clamped to the last LDS dword.

translate --validate on shaders.rpf unchanged (compute 1686 validated
with this PR).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
alexander-src's #571 review: when a 16-bit access sits at byte 3 of the
final LDS dword, the clamped "next dword" is that same dword, so a read
took byte 0 as its high byte and a write overwrote byte 0. The next
dword's part is now dropped there: a read sees 0 in its high byte, and
the write's mask and data for the next dword are 0, as out-of-bounds
LDS accesses read 0 and drop writes.

translate --validate on shaders.rpf unchanged (CS 1686 on 3645c69).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Daniel333313131

Copy link
Copy Markdown

Translation census for this PR and the two others that lower byte and half LDS accesses (#116, #101). Each was merged alone onto main ffe310e.

Setup: release build, victory translate <dump>/shaders.rpf --list (26,084 programs, no --validate, no --pipelines), Windows 11, RX 7900 XTX.

head vertex/pixel compute mesh
main ffe310e 12,231 1,441 of 2,582 8,214
#571 8ad9d9f 12,231 1,457 (+16) 8,214
#116 c853a6a 12,231 1,457 (+16) 8,214
#101 9fbd7e9 12,231 1,457 (+16) 8,214
  • All three give the same census numbers: "an LDS write of bytes or halves" (9) and "an LDS read of bytes or halves" (7) are gone as first refusals, and 16 more compute programs are emitted.
  • So one of the three is probably enough. Which one is right is a question for hardware tests, not this census. None of the three was run in game.

AI use: Claude Code (Claude Opus 5.5) merged and built the commits, ran the census, compared the outputs and wrote this comment. The numbers come from the runs above.

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers. Closing because this change is already in main, or main has since replaced the code it patches.

LDS byte and half accesses. In main since today (lower.rs:3044-3141). Same as #116.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.