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

Open
github-bot wants to merge 1 commit from github-bot/gh-2097 into main AGit
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-25 04:50 UTC · original
geiyiliyabumo:feat/shader-v-qsad-mqsad → main · +218 −11 · 2 files · 1 commits · open

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).
**@⁠geiyiliyabumo** on GitHub · 2026-11-25 04:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2097) `geiyiliyabumo:feat/shader-v-qsad-mqsad` → `main` · +218 −11 · 2 files · 1 commits · open ## 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).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:43 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 05:05 UTC · original

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

**@⁠upipibi** on GitHub · 2026-11-25 05:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2097#issuecomment-7153440651) 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).
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-25 08:52 UTC · original

Offline measurement on a retail dump

Result: no count change against main.

I merged head 562b92eb 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).

**@⁠sinan-cmyk** on GitHub · 2026-11-25 08:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/2097#issuecomment-7157578254) ### Offline measurement on a retail dump **Result: no count change against `main`.** I merged head 562b92eb 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).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:36 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 10:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2097#issuecomment-7159934659) <!-- victory-triage v1 head=562b92ebc11a2996fafd438ec8f3bfc371f89391 verdict=merge-candidate at=2026-11-25T10:36:43Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 01:42 UTC · original

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 01:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2097#issuecomment-7180048582) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2097/head:github-bot/gh-2097'
git switch 'github-bot/gh-2097'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2097'
git switch 'github-bot/gh-2097'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2097'
git switch 'github-bot/gh-2097'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2097'
git switch 'main'
git merge --squash 'github-bot/gh-2097'
git switch 'main'
git merge --ff-only 'github-bot/gh-2097'
git switch 'main'
git merge 'github-bot/gh-2097'
git push origin 'main'
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!2097
No description provided.