victory-shader: lower a16 biased image samples and sub-dword LDS access #996

Closed
github-bot wants to merge 5 commits from gh-pr/996/head into gh-pr/996/base
Owner

@⁠bartikele on GitHub · 2026-11-24 14:47 UTC · original
bartikele:shader-a16-bias-and-lds-subdword → main · +166 −14 · 1 files · 5 commits · closed without merging

Adds DXIL lowering in \ ictory-shader\ for:

  • \image_sample_b\ with \16: keeps offset, bias, and comparison reference unpacked (32-bit dwords) while unpacking coordinates from \whole\ onward as 16-bit pairs.
  • Sub-dword LDS access (\ds_read_{u8,i8,u16,i16}, \ds_write_{b8,b16}): extracts/sign-extends bytes and halves on read, and performs race-free \tomicrmw and\ + \tomicrmw or\ on the containing 32-bit LDS dword on write. Includes unit test \lds_byte_and_half_read_write_lower.

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.

**@⁠bartikele** on GitHub · 2026-11-24 14:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/996) `bartikele:shader-a16-bias-and-lds-subdword` → `main` · +166 −14 · 1 files · 5 commits · closed without merging Adds DXIL lowering in \ ictory-shader\ for: - \image_sample_b\ with \16\: keeps offset, bias, and comparison reference unpacked (32-bit dwords) while unpacking coordinates from \whole\ onward as 16-bit pairs. - Sub-dword LDS access (\ds_read_{u8,i8,u16,i16}\, \ds_write_{b8,b16}\): extracts/sign-extends bytes and halves on read, and performs race-free \tomicrmw and\ + \tomicrmw or\ on the containing 32-bit LDS dword on write. Includes unit test \lds_byte_and_half_read_write_lower\. 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\.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:16:30 +00:00
github-bot closed this pull request 2026-11-26 04:16:30 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 14:54 UTC · original

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-shader passes, 122 passed / 0 failed, including lds_byte_and_half_read_write_lower. Workspace baseline on main (ffe310e) was green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 14:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/996#issuecomment-7135153225) 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-shader` passes, 122 passed / 0 failed, including `lds_byte_and_half_read_write_lower`. Workspace baseline on main (ffe310e) was green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠bartikele on GitHub · 2026-11-24 17:18 UTC · original

Thanks @⁠mercuryVM and @⁠catminou4 for the thorough review! Updated shader-a16-bias-and-lds-subdword with the following fixes:

  1. Low-half ds_read_{u8,i8,u16}_d16: now preserves bits 31:16 of vdst via self.low_half(inst, reg, r), matching the _hi path.
  2. a16 image_sample_b bias: masks the bias VGPR to its low 16 bits (& 0xFFFF) and decodes it via legacyF16ToF32 (to_float) when *a16 is set, and indexes bias at usize::from(offset_word).
  3. Consistency: first now uses name.starts_with("image_sample_b") to match whole.

Regarding @catminou4's note on ds_write_b8/b16: DXIL groupshared uint[] has no byte-granular store intrinsic, so atomicAnd + atomicOr is the closest lowering available today.

Re-verified with cargo clippy -p victory-shader --all-targets --locked -- -D warnings, cargo test -p victory-shader --locked, and cargo xtask policy.

**@⁠bartikele** on GitHub · 2026-11-24 17:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/996#issuecomment-7139002779) Thanks @⁠mercuryVM and @⁠catminou4 for the thorough review! Updated `shader-a16-bias-and-lds-subdword` with the following fixes: 1. **Low-half `ds_read_{u8,i8,u16}_d16`**: now preserves bits `31:16` of `vdst` via `self.low_half(inst, reg, r)`, matching the `_hi` path. 2. **`a16` `image_sample_b` bias**: masks the bias VGPR to its low 16 bits (`& 0xFFFF`) and decodes it via `legacyF16ToF32` (`to_float`) when `*a16` is set, and indexes `bias` at `usize::from(offset_word)`. 3. **Consistency**: `first` now uses `name.starts_with("image_sample_b")` to match `whole`. Regarding `@catminou4`'s note on `ds_write_b8/b16`: DXIL `groupshared uint[]` has no byte-granular store intrinsic, so `atomicAnd` + `atomicOr` is the closest lowering available today. Re-verified with `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`, `cargo test -p victory-shader --locked`, and `cargo xtask policy`.
Author
Owner

@⁠bartikele on GitHub · 2026-11-24 20:40 UTC · original

Updated \ds_write_{b8,b16}{,_d16_hi}\ in \

**@⁠bartikele** on GitHub · 2026-11-24 20:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/996#issuecomment-7143907489) Updated \ds_write_{b8,b16}{,_d16_hi}\ in \
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:29 UTC · original

Automated triage for the maintainers. Closing because this change is already in main, or main has 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.

**@⁠Marvisak** on GitHub · 2026-11-25 00:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/996#issuecomment-7148569882) Automated triage for the maintainers. Closing because this change is already in `main`, or `main` has 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.
Author
Owner

@⁠bartikele on GitHub · 2026-11-25 13:21 UTC · original

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:

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo test -p victory-shader --locked lds_byte_and_half_read_write_lower: passed
  • cargo test -p victory-shader --locked lds_bytes_and_halves_match_the_hardware: passed
  • cargo xtask policy: 182 files ok
**@⁠bartikele** on GitHub · 2026-11-25 13:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/996#issuecomment-7163665849) 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: - cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean - cargo test -p victory-shader --locked lds_byte_and_half_read_write_lower: passed - cargo test -p victory-shader --locked lds_bytes_and_halves_match_the_hardware: passed - cargo xtask policy: 182 files ok

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!996
No description provided.