Skip to content

Shaders: lower v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8, and v_mqsad_u32_u8 in pure 32-bit DXIL - #2097

Open
geiyiliyabumo wants to merge 1 commit into
Marvisak:mainfrom
geiyiliyabumo:feat/shader-v-qsad-mqsad
Open

geiyiliyabumo wants to merge 1 commit into
Marvisak:mainfrom
geiyiliyabumo:feat/shader-v-qsad-mqsad

Conversation

@geiyiliyabumo

Copy link
Copy Markdown
Contributor

Summary

  • Lowers GFX10 VOP3 quad-SAD instructions v_qsad_pk_u16_u8 (0x172), v_mqsad_pk_u16_u8 (0x173), and v_mqsad_u32_u8 (0x175) in crates/victory-shader/src/emit/lower.rs using pure 32-bit DXIL without enabling Int64 / WIDE_OPS.
  • Uses per-dword SSA reads and guarded writes (handling overlapping accumulator/destination VGPRs safely), supports clamp (unsigned 16-bit saturation for pk_u16_u8 and unsigned 32-bit saturation for u32_u8), and rejects unsupported abs/neg/omod/op_sel modifiers.
  • Adds synthetic IR, DXIL-validation, and GPU execution tests in crates/victory-shader/src/emit/valu_tests.rs covering all 4 sliding windows across the src0_lo/src0_hi boundary, zero-reference masking vs unmasked behavior, modulo wraparound and saturation, overlapping destination/accumulator VGPRs, and verifying Int64 is not set.

Verification

  • cargo xtask policy: passed
  • cargo clippy -p victory-shader --tests -- -D warnings: passed
  • cargo test -p victory-shader --lib quad_sad_vop3 -- --test-threads=1 and sums_of_absolute_differences_lower with Microsoft dxil.dll: all passed on AMD Radeon RX 9060 XT (RDNA4) and Microsoft Basic Render Driver (WARP)
  • Zero game files or game-derived data used (synthetic tests only).

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC, with dxil.dll validator):

  • cargo test -p victory-shader --lib quad_sad — passed on both RTX 5090 hardware and VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean pure-32-bit DXIL lowering of v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8, and v_mqsad_u32_u8, verified end-to-end on hardware and WARP. Looks good.

AI-assisted (Gemini 4 Neon).

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at 562b92e. victory-shader: 246 passed, 3 failed, 3 ignored. The new quad_sad_vop3_tracks_register_dwords_and_rejects_modifiers and quad_sad_vop3_wraps_or_saturates_every_window pass. The 3 failures are #1744's NVIDIA failures on main. Same as main on this hardware.

Overlap, from reading: #1662 (open, conflicting with main) lowers the RDNA 2 quad-byte SAD instructions too, and #1672 (closed) had this PR's three.

AI-assisted (Claude Code).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally: macOS arm64, rustc 1.98.1, PR head merged into main 940d32f, cargo test -p victory-shader --locked.

144 passed / 0 failed / 2 ignored. v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8, v_mqsad... — quad/media saturating-add packing ops.

@sinan-cmyk

Copy link
Copy Markdown

Offline measurement on a retail dump

Result: no count change against main.

I merged head 562b92e onto main 940d32f (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 23,918 on main, 23,918 with this PR.

No program changes its failure reason. The count shows that the change rejects nothing on this data. It does not show whether the output is right.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Adds quad_sad in emit/lower.rs for v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8: four sliding byte windows over the 64-bit src0 against src1, with masking of zero reference bytes for the mqsad forms and 16-bit or 32-bit accumulators. It reads the accumulator dwords before the guarded writes, so overlapping destination and accumulator registers are safe. It refuses abs/neg/omod/op_sel. I checked the window layout against the register widths already in gfx10/fields.rs and recomputed the test SADs ([416, 684, 42, 526] unmasked, 321 for masked window 0). They match AMD's public RDNA ISA description, which would be worth citing. CI passes, and an independent NVIDIA run reports the new tests passing.

Minor: pair treats a float inline constant as a zero high dword. Overlaps the conflicting #1662, and the try_build_valu_cs change conflicts trivially with #2092.


Generated by Claude Code

@fuzeofficlal

Copy link
Copy Markdown
Contributor

Code review and RTX 5090 + WARP + DXIL verification at head 562b92ebc11a merged onto main (63bcca43c6a0):

  • 512 KiB file-size policy blocker (xtask):
    • Code merges cleanly, but crates/victory-shader/src/emit/lower.rs reaches 524,743 bytes (+455 B over the 524,288-byte limit), causing cargo xtask policy to fail (exit 1).
    • Note: the local pair closure inside quad_sad (lower.rs:6724-6733) duplicates existing self.src64_dwords(inst, k) (lower.rs:6855) — reusing src64_dwords or moving quad_sad/unsigned_abs_diff to a submodule under emit/lower/ will clear the 512 KiB gate cleanly with headroom.
  • Semantics & hardware results (lower.rs:6712-6805):
    • Properly rejects abs/neg/omod/opsel, handles 7-byte sliding windows across 64-bit sources, skips zero reference bytes on v_mqsad_*, saturates 16-bit packed (sum > 0xFFFF) and 32-bit (sum < acc) accumulators under v.clamp, and writes all destinations under guard (EXEC).
    • cargo clippy (default + --features diagnostics): 0 warnings; quad_sad (2/2, pure 32-bit without Int64), emit::lower::tests (33/33), and emit::semantics_tests (34/34 on both RTX 5090 and WARP, 1 ignored) all passed.

Lowering and GPU execution are solid — just needs moving out of lower.rs (and reusing src64_dwords) to satisfy the 512 KiB policy check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants