Shaders: lower v_sad_u8, v_msad_u8, v_sad_u16, and v_sad_u32 #1197

Closed
github-bot wants to merge 1 commit from gh-pr/1197/head into gh-pr/1197/base
Owner

@⁠DenRakEiw on GitHub · 2026-11-24 16:24 UTC · original
shader/v-sad-family → main · +152 −0 · 2 files · 1 commits · closed without merging

## Summary

Lowers RDNA2's unsigned sum-of-absolute-differences (SAD) instruction family in crates/victory-shader/src/emit/lower.rs:

  • v_sad_u8 (VOP3 0x15A): sum of 4 unsigned byte absolute differences + src2 accumulator.
  • v_msad_u8 (VOP3 0x171): masked 4-byte SAD — lanes where src0's byte is 0 contribute 0 regardless of src1 (while src1 == 0 is not skipped).
  • v_sad_u16 (VOP3 0x15C): sum of 2 unsigned 16-bit absolute differences + src2 accumulator.
  • v_sad_u32 (VOP3 0x15D): |src0 - src1| + src2 accumulator.
  • Supports VOP3 clamp (unsigned saturation to u32::MAX on accumulator overflow) across all four instructions, while rejecting invalid omod/abs/neg modifiers.

Tests

Added end-to-end synthetic GFX10 compute shader test v_sad_family_matches_rdna2 in crates/victory-shader/src/emit/valu_tests.rs (validated via dxil.dll and executed on both host GPU and WARP), covering:

  • v_sad_u8 (normal accumulation, u32 wraparound, and clamp saturation to u32::MAX)
  • v_msad_u8 (zero-masking on src0 bytes vs. non-masking on src1 == 0)
  • v_sad_u16 (normal accumulation and clamp saturation)
  • v_sad_u32 (normal accumulation, u32 wraparound, and clamp saturation)

Verification

  • cargo test -p victory-shader v_sad_family: passed on Windows 11 x64 / NVIDIA GeForce RTX 5090 (Blackwell) + WARP
  • cargo clippy -p victory-shader --all-targets: 0 warnings
  • cargo xtask policy: asset policy: 155 files ok

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-24 16:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/1197) `shader/v-sad-family` → `main` · +152 −0 · 2 files · 1 commits · closed without merging ## Summary Lowers RDNA2's unsigned sum-of-absolute-differences (SAD) instruction family in `crates/victory-shader/src/emit/lower.rs`: - **`v_sad_u8`** (VOP3 `0x15A`): sum of 4 unsigned byte absolute differences + `src2` accumulator. - **`v_msad_u8`** (VOP3 `0x171`): masked 4-byte SAD — lanes where `src0`'s byte is `0` contribute `0` regardless of `src1` (while `src1 == 0` is not skipped). - **`v_sad_u16`** (VOP3 `0x15C`): sum of 2 unsigned 16-bit absolute differences + `src2` accumulator. - **`v_sad_u32`** (VOP3 `0x15D`): `|src0 - src1|` + `src2` accumulator. - Supports VOP3 `clamp` (unsigned saturation to `u32::MAX` on accumulator overflow) across all four instructions, while rejecting invalid `omod`/`abs`/`neg` modifiers. ## Tests Added end-to-end synthetic GFX10 compute shader test `v_sad_family_matches_rdna2` in `crates/victory-shader/src/emit/valu_tests.rs` (validated via `dxil.dll` and executed on both host GPU and WARP), covering: - `v_sad_u8` (normal accumulation, `u32` wraparound, and `clamp` saturation to `u32::MAX`) - `v_msad_u8` (zero-masking on `src0` bytes vs. non-masking on `src1 == 0`) - `v_sad_u16` (normal accumulation and `clamp` saturation) - `v_sad_u32` (normal accumulation, `u32` wraparound, and `clamp` saturation) ## Verification - `cargo test -p victory-shader v_sad_family`: **passed** on Windows 11 x64 / **NVIDIA GeForce RTX 5090 (Blackwell)** + **WARP** - `cargo clippy -p victory-shader --all-targets`: **0 warnings** - `cargo xtask policy`: `asset policy: 155 files ok` AI-assisted (Gemini 4 Neon).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:23:18 +00:00
github-bot closed this pull request 2026-11-26 04:23:18 +00:00
Author
Owner

@⁠ghost on GitHub · 2026-11-24 16:34 UTC · original

Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head 8967035 on main ffe310e. Your report lists NVIDIA and WARP, so this adds AMD hardware.

  • v_sad_family_matches_rdna2 passes: v_sad_u8, v_msad_u8, v_sad_u16 and v_sad_u32, wrapping and clamp cases.
  • victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, stub_pipeline_is_created, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR).
  • No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement.

Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host.

AI-assisted (Claude Code, Claude Opus 5.5); no game data.

**@⁠ghost** on GitHub · 2026-11-24 16:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1197#issuecomment-7137891436) Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head `8967035` on main `ffe310e`. Your report lists NVIDIA and WARP, so this adds AMD hardware. - `v_sad_family_matches_rdna2` passes: v_sad_u8, v_msad_u8, v_sad_u16 and v_sad_u32, wrapping and clamp cases. - victory-shader lib tests: 120 passed, 1 failed, 1 ignored (main on the same host: 119/1/1). The one failure, `stub_pipeline_is_created`, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR). - No hangs. A pass means the translated DXIL gives these values on RDNA2 through vkd3d-proton/RADV; it isn't a console measurement. Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the new test fails without the fix on this host. AI-assisted (Claude Code, Claude Opus 5.5); no game data.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 18:00 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 8967035: cargo test -p victory-shader passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/Marvisak/VIctory/pull/1197#issuecomment-7140017793) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 8967035: `cargo test -p victory-shader` passes, 121 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

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

Automated triage for the maintainers. Closing because another open pull request covers the same change.

See #162. Lowers v_sad_u8, v_msad_u8, v_sad_u16 and v_sad_u32, which the title does not use. The clean #162 covers the same instructions plus v_sad_hi_u8.

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:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1197#issuecomment-7148655438) Automated triage for the maintainers. Closing because another open pull request covers the same change. See #162. Lowers v_sad_u8, v_msad_u8, v_sad_u16 and v_sad_u32, which the title does not use. The clean #162 covers the same instructions plus v_sad_hi_u8. 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

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-26 00:19 UTC · original

The close note asks for anything #162 missed. It landed the wrapping forms, and the integer output path still refuses clamp. I copied v_sad_family_matches_rdna2 unchanged from your 89670357 onto current main 63bcca43. The fixture fails to lower at its first clamped v_sad_u8 with integer output modifiers. On the exact 89670357 head the same test passes, including the clamped SAD/MSAD cases. Both runs used app-local WARP SM 6.6 and the DXIL validator.

The remaining difference is unsigned saturation of the final accumulation. For four differences of 255 and an accumulator of u32::MAX - 10, wrapping gives 1009; the original clamped case returns u32::MAX. The clamp forms are listed in the GFX1030 assembly reference.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-26 00:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/1197#issuecomment-7178644076) The close note asks for anything #162 missed. It landed the wrapping forms, and the integer output path still refuses `clamp`. I copied `v_sad_family_matches_rdna2` unchanged from your `89670357` onto current main `63bcca43`. The fixture fails to lower at its first clamped `v_sad_u8` with `integer output modifiers`. On the exact `89670357` head the same test passes, including the clamped `SAD`/`MSAD` cases. Both runs used app-local WARP SM 6.6 and the DXIL validator. The remaining difference is unsigned saturation of the final accumulation. For four differences of 255 and an accumulator of `u32::MAX - 10`, wrapping gives `1009`; the original clamped case returns `u32::MAX`. The `clamp` forms are listed in the [GFX1030 assembly reference](https://rocmdocs.amd.com/projects/llvm-project/en/latest/LLVM/llvm/html/AMDGPU/AMDGPUAsmGFX1030.html#vop3).

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!1197
No description provided.