Repository navigation
Conversation
|
Check on Linux, not Windows: pass. Head
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. |
|
Review note on head On #116 fixes this in 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 |
|
Tested offline against main
AI-assisted. |
|
Follow-up: the translated readback is now available. Claude Code ran the test on our Windows 11 machine using #571 at One remaining distinction is a halfword read across a dword boundary. In the native RDNA2 experiment on #116, an odd-address 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 The setup and Cargo command are here. Filter on |
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>
|
@TrashTalker3460 thanks for the careful read. I checked it on this head: @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 |
|
Confirmed on your exact head I reran |
|
Measured on the full retail shader pack (26,503 containers) with 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. |
|
I reran two focused LDS regressions on
PortBridge surfaced XCL #544 for the partial-destination cases and Continued #507 for the single-writer fixture correction. Would these be useful in your 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
left a comment
There was a problem hiding this comment.
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), Rust1.98.1(x86_64-pc-windows-msvc), Windows SDK10.0.26100.0dxil.dll. - CI checks:
cargo clippy --workspace --all-targets --locked -- -D warnings: passcargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passcargo 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 halves9 → 0,an LDS read of bytes or halves7 → 0). - Compute:
1,440 / 1,417 / 1,121→1,456 (+16) / 1,433 (+16) / 1,123 (+2)(all 16 newly emitted programs validate withdxil.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.
- Clears all 16 sub-dword LDS refusals (
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)hasmv = 0x0000_00FFandxv = (x >> 8) & 0xFF, soatomicrmw and/oronq == poverwrites byte 0 oflds[last]with the high byte instead of dropping the out-of-bounds byte. - Read (
ds_read_u16/i16):hi = load(q)reads byte 0 oflds[last]into the upper byte of the result instead of0.
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.
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>
|
@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 ( |
|
Tester result: +2 of 339 previously failing world programs now emit (compute 32 → 34 of 272; the two that logged How measured: 339 shader containers from my own 1.0.2.1 copy, the distinct programs that logged |
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>
|
@adamdotpy thanks for the careful pass. Added the case you asked for in 8ad9d9f: |
|
Verified Point by point: The destination-register question — you were right and my review was wrong, and here is the evidence. I re-read My
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. |
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>
…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>
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>
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>
|
Translation census for this PR and the two others that lower byte and half LDS accesses (#116, #101). Each was merged alone onto Setup: release build,
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. |
|
Automated triage for the maintainers. Closing because this change is already in 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. |
ds_read_{u8,i8,u16,i16}andds_write_{b8,b16}, with their_d16/_d16_hiforms, were refused ("an LDS read/write of bytes or halves"). That blocked 16 compute programs in shaders.rpf, mostlycompute_graph_opsreductions 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._d16fills the register's low half and_d16_hiits high half, keeping the other half._d16_hitakes 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.This is independent of #539, #554, #563, #565 and #569.
Written with the help of Claude (AI).
🤖 Generated with Claude Code