victory-shader: lower a16 biased image samples and sub-dword LDS access #996
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/996"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by bartikele on 2026-11-24T14:47:20Z.
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.
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T14:54:50Z.
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
c188c02:cargo test -p victory-shaderpasses, 122 passed / 0 failed, includinglds_byte_and_half_read_write_lower. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).Tested with AI assistance (Claude).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T15:41:45Z.
Review: COMMENTED
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 atwhole, 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 toatomic 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 fullds_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. Hardwareds_write_b8has 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.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T16:21:31Z.
Review: CHANGES_REQUESTED
Tested
38e9db08on Windows 11, RTX 5070, MSVC:cargo test -p victory-shader -- --test-threads=1passes (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.hi. Ford16 && !hiit writes the bare 16-bit result, so the upper half becomes zero.hiarm does, and write(old & 0xFFFF0000) | (r & 0xFFFF).The a16 bias is decoded as an f32 (
lower.rs:6045-6046, with the new comment at:5712).self.as_float(bias)reinterprets the whole dword as an f32, which gives a near-zero denormal or junk instead of the bias.*a16, mask the dword to its low 16 bits and pass it throughlegacyF16ToF32, the same asto_floatdoes for coordinates.Smaller points:
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).
Imported from Marvisak/VIctory. Originally posted by bartikele on 2026-11-24T17:18:41Z.
Thanks @mercuryVM and @catminou4 for the thorough review! Updated
shader-a16-bias-and-lds-subdwordwith the following fixes:ds_read_{u8,i8,u16}_d16: now preserves bits31:16ofvdstviaself.low_half(inst, reg, r), matching the_hipath.a16image_sample_bbias: masks the bias VGPR to its low 16 bits (& 0xFFFF) and decodes it vialegacyF16ToF32(to_float) when*a16is set, and indexesbiasatusize::from(offset_word).firstnow usesname.starts_with("image_sample_b")to matchwhole.Regarding
@catminou4's note onds_write_b8/b16: DXILgroupshared uint[]has no byte-granular store intrinsic, soatomicAnd+atomicOris the closest lowering available today.Re-verified with
cargo clippy -p victory-shader --all-targets --locked -- -D warnings,cargo test -p victory-shader --locked, andcargo xtask policy.Imported from Marvisak/VIctory. Originally posted by bartikele on 2026-11-24T20:40:38Z.
Updated \ds_write_{b8,b16}{,_d16_hi}\ in \
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:29:51Z.
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.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.
Imported from Marvisak/VIctory. Originally posted by bartikele on 2026-11-25T13:21:44Z.
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:Pull request closed