Repository navigation
Conversation
|
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at c188c02: Tested with AI assistance (Claude). |
catminou4
left a comment
There was a problem hiding this comment.
Two features in one PR (a16 biased image samples + LDS sub-dword), both lowering-only tested on macOS (98 passed / 0 failed / 1 ignored after merge with ffe310e). The a16 packing fix looks careful — offset/bias/reference stay 32-bit, packed pairs start at whole, and the biased-sample refusal is lifted with the component math adjusted accordingly.
The LDS sub-dword writes concern me though, and it's the same pattern I flagged on #571: ds_write_b8/b16[_d16_hi] lowers to atomic And(clear) + atomic Or(value) on the containing dword. Two waves of the same workgroup writing the same byte (or one writing while another does a full ds_write_b32) can interleave between the And and the Or and produce an OR-mixture or a clobbered dword — LDS is per-workgroup but waves in a workgroup run concurrently, and nothing here serializes the pair. Hardware ds_write_b8 has byte-granular semantics the emulation doesn't quite reproduce. Before this lands I'd want either (a) a host-execution test on the Windows lane with two waves racing the same dword, or (b) a documented assumption that console shaders never do this (with the reason), or (c) the read-modify-write done in one guarded sequence if the ISA allows.
Also a triage note: the LDS sub-dword lowering overlaps the #632/#116/#101/#571 cluster — whichever lands first should subsume the others to avoid four divergent implementations of the same instructions.
mercuryVM
left a comment
There was a problem hiding this comment.
Tested 38e9db0 on Windows 11, RTX 5070, MSVC: cargo test -p victory-shader -- --test-threads=1 passes (122 passed, 1 ignored). I read the lowering by hand and found two bugs:
-
Low-half d16 LDS reads overwrite the high half (
crates/victory-shader/src/emit/lower.rs:2201-2212).ds_read_{u8,i8,u16}_d16writes only bits 15:0 of vdst and keeps bits 31:16, the mirror of the_hiforms.- The block merges with the old register only when
hi. Ford16 && !hiit writes the bare 16-bit result, so the upper half becomes zero. - Fix: read the old value, as the
hiarm does, and write(old & 0xFFFF0000) | (r & 0xFFFF). - The new test only checks that these forms lower, so it does not catch this.
-
The a16 bias is decoded as an f32 (
lower.rs:6045-6046, with the new comment at:5712).- Under A16 the bias does sit in its own dword, but that dword holds an f16 in its low half and nothing in the upper half. LLVM's AMDGPU legalizer documents this: "Bias is of type half but occupies full 32-bit".
self.as_float(bias)reinterprets the whole dword as an f32, which gives a near-zero denormal or junk instead of the bias.- Fix: when
*a16, mask the dword to its low 16 bits and pass it throughlegacyF16ToF32, the same asto_floatdoes for coordinates. - The offset and the comparison reference remain true 32-bit dwords, as the comment says.
Smaller points:
- A
ds_read_u16/ds_write_b16at a byte address withaddr & 3 == 3straddles two dwords. Here it reads or writes only the low byte of the field. RDNA requires 2-byte alignment for these, so this is probably fine, but a short note would help. wholeusesstarts_with("image_sample_b"), whilefirstusesname == "image_sample_b". Only the exact name reaches op 61 today, so this is harmless, but the two should agree.v_cvt_f32_f64_lowers_with_double_flaglooks unrelated to this PR's title.
AI-assisted (Claude Code).
|
Thanks @mercuryVM and @catminou4 for the thorough review! Updated
Regarding Re-verified with |
|
Updated \ds_write_{b8,b16}{,_d16_hi}\ in \ |
|
Automated triage for the maintainers. Closing because this change is already in Both halves are in main: a16 biased samples (image()) and sub-dword LDS accesses (ds()). 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. |
|
Rebased onto current main (940d32f), keeping main's image_bvh and �16 sample bias/offset handling while preserving the sub-dword LDS read/write lowering (ds_write_{b8,b16}{,d16_hi} via atomic cmpxchg loop and ds_read{u8,i8,u16,i16}{,_d16,_d16_hi}). Verified on 940d32f:
|
Adds DXIL lowering in \�ictory-shader\ for:
Verified with \cargo clippy -p victory-shader --all-targets --locked -- -D warnings, \cargo test -p victory-shader --locked\ (122 passed), \cargo xtask policy, and \�ictory translate --validate.