Skip to content

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

Closed
DenRakEiw wants to merge 1 commit into
Marvisak:mainfrom
DenRakEiw:shader/v-sad-family
Closed

DenRakEiw wants to merge 1 commit into
Marvisak:mainfrom
DenRakEiw:shader/v-sad-family

Conversation

@DenRakEiw

Copy link
Copy Markdown

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).

@ghost

ghost commented Nov 24, 2026

Copy link
Copy Markdown

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.

@Zipettte

Copy link
Copy Markdown

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).

@Marvisak

Copy link
Copy Markdown
Owner

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 Marvisak closed this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants