Shaders: lower RDNA 2 quad-byte SAD instructions to DXIL #1661

Open
THE-PRO-GAME wants to merge 1 commit from upstream-pr/1662 into main
THE-PRO-GAME commented 2026-11-24 20:34:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by THE-PRO-GAME on 2026-11-24T20:34:04Z.


Base branch Marvisak/VIctory:main at ffe310eb2098e52169f4c44db5ffdabf43a72622.
Head review/rdna2-qsad at e8bbc120b6d87efeffd68701cafa6dd7413cc6fa.

Changes

Lower v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8. These instructions compute four overlapping unsigned byte sums of absolute differences and add each to its corresponding accumulator. The masked forms exclude positions where the reference byte is zero. The lowering preserves isolated 16-bit or 32-bit accumulation, the CLMP saturation rule and EXEC predication for every destination dword. AMD RDNA 2 ISA §12.12 · AMD RDNA 2 ISA §6.5

This commit uses DXIL i32 arithmetic and the existing VALU operand and write paths. The original compute fixtures check window order, register pairs, expanded constants, boundary values and inactive lanes in guest Wave32 and Wave64.

Individual validation

  • cargo test --workspace --locked passed 347 tests. The --all-features run passed 351. Both had zero failures and six ignored tests.
  • Strict workspace Clippy with --all-targets --locked -- -D warnings passed with default and all features. All five targeted QSAD tests passed.
  • Microsoft DXIL Validator (dxv v1.9.2609) accepted all 16 emitted containers. D3D12 WARP and an NVIDIA GeForce RTX 3060 each matched the CPU reference for 64 dispatches across guest Wave32 and Wave64.
  • To reproduce the synthetic tests on a Windows D3D12 SM 6.6 system, run cargo test -p victory-shader --locked qsad -- --nocapture. Set VICTORY_DXIL to the full path to Microsoft's dxil.dll to select the validator explicitly. Microsoft DXC release

Joint validation

A separate local integration check combined both commits and exercised all six instructions in one synthetic compute shader. The test chains GLOBAL ADDTID reads through the three SAD instructions into LDS ADDTID, then reads the resulting dwords back after a group barrier. Inactive lanes keep their original destination values. The mixed shader matched the CPU reference for two cases per guest wave width on each backend.

The local merge kept both decoder tests as separate functions after resolving an overlap at their insertion point. The mixed-shader fixture is local to the integration check.

The combined targeted run passed all 11 tests. Microsoft dxv v1.9.2609 accepted 28 containers. WARP and the RTX 3060 each matched the CPU reference for 82 dispatches, including four mixed-shader dispatches. The integrated workspace reported 353 passing tests with default features and 357 with all features, with zero failures and six ignored tests in each run. Strict Clippy passed for both configurations. The existing Xbox SDK differential tests returned early on this host.

PRs #162 and #1197 cover ordinary SAD and MSAD. PR #1614 adds a general adapter differential fuzzer. The recent upstream review found no proposal that lowers these three quad forms. PR #162 · PR #1197 · PR #1614

Test scope and remaining validation

Execution verification used original synthetic compute shaders and a CPU reference derived from the public ISA. WARP and the RTX 3060 ran the translated DXIL. Native RDNA 2 execution in Wave32 and Wave64 remains pending, including a comparison of the masked and clamped cases against the same reference. Graphics stages and retail shader coverage were outside the test scope. VIctory asset policy

<!-- greyfinch-sync:Marvisak/VIctory:issue:6590871535 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1662). Originally posted by [THE-PRO-GAME](https://github.com/THE-PRO-GAME) on 2026-11-24T20:34:04Z. --- Base branch `Marvisak/VIctory:main` at `ffe310eb2098e52169f4c44db5ffdabf43a72622`. Head `review/rdna2-qsad` at `e8bbc120b6d87efeffd68701cafa6dd7413cc6fa`. ## Changes Lower `v_qsad_pk_u16_u8`, `v_mqsad_pk_u16_u8` and `v_mqsad_u32_u8`. These instructions compute four overlapping unsigned byte sums of absolute differences and add each to its corresponding accumulator. The masked forms exclude positions where the reference byte is zero. The lowering preserves isolated 16-bit or 32-bit accumulation, the `CLMP` saturation rule and EXEC predication for every destination dword. [AMD RDNA 2 ISA §12.12](https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf#page=185) · [AMD RDNA 2 ISA §6.5](https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf#page=56) This commit uses DXIL `i32` arithmetic and the existing VALU operand and write paths. The original compute fixtures check window order, register pairs, expanded constants, boundary values and inactive lanes in guest Wave32 and Wave64. ## Individual validation - `cargo test --workspace --locked` passed 347 tests. The `--all-features` run passed 351. Both had zero failures and six ignored tests. - Strict workspace Clippy with `--all-targets --locked -- -D warnings` passed with default and all features. All five targeted QSAD tests passed. - Microsoft DXIL Validator (`dxv` v1.9.2609) accepted all 16 emitted containers. D3D12 WARP and an NVIDIA GeForce RTX 3060 each matched the CPU reference for 64 dispatches across guest Wave32 and Wave64. - To reproduce the synthetic tests on a Windows D3D12 SM 6.6 system, run `cargo test -p victory-shader --locked qsad -- --nocapture`. Set `VICTORY_DXIL` to the full path to Microsoft's `dxil.dll` to select the validator explicitly. [Microsoft DXC release](https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.9.2609) ## Joint validation A separate local integration check combined both commits and exercised all six instructions in one synthetic compute shader. The test chains GLOBAL ADDTID reads through the three SAD instructions into LDS ADDTID, then reads the resulting dwords back after a group barrier. Inactive lanes keep their original destination values. The mixed shader matched the CPU reference for two cases per guest wave width on each backend. The local merge kept both decoder tests as separate functions after resolving an overlap at their insertion point. The mixed-shader fixture is local to the integration check. The combined targeted run passed all 11 tests. Microsoft `dxv` v1.9.2609 accepted 28 containers. WARP and the RTX 3060 each matched the CPU reference for 82 dispatches, including four mixed-shader dispatches. The integrated workspace reported 353 passing tests with default features and 357 with all features, with zero failures and six ignored tests in each run. Strict Clippy passed for both configurations. The existing Xbox SDK differential tests returned early on this host. ## Related work PRs #162 and #1197 cover ordinary SAD and MSAD. PR #1614 adds a general adapter differential fuzzer. The recent upstream review found no proposal that lowers these three quad forms. [PR #162](https://github.com/Marvisak/VIctory/pull/162) · [PR #1197](https://github.com/Marvisak/VIctory/pull/1197) · [PR #1614](https://github.com/Marvisak/VIctory/pull/1614) ## Test scope and remaining validation Execution verification used original synthetic compute shaders and a CPU reference derived from the public ISA. WARP and the RTX 3060 ran the translated DXIL. Native RDNA 2 execution in Wave32 and Wave64 remains pending, including a comparison of the masked and clamped cases against the same reference. Graphics stages and retail shader coverage were outside the test scope. [VIctory asset policy](https://github.com/Marvisak/VIctory/blob/main/docs/asset-policy.md)
catminou4 commented 2026-11-24 22:01:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T21:42:43Z.

Review: APPROVED


Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows.

RDNA2 quad-byte SAD instructions lowered: quad_sad/quad_sad_pair with build_valu_cs_with_outputs/run_cases_with_outputs harness checking per-case outputs on hardware/WARP.

<!-- greyfinch-sync:Marvisak/VIctory:review:6047880845 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1662#pullrequestreview-6047880845). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T21:42:43Z. **Review:** APPROVED --- Tested locally on macOS arm64 (rustc 1.98.1): PR head merged cleanly into current main (ffe310e), cargo test -p victory-shader --locked → 97 passed, 0 failed. Hardware/valu/waterfall execution tests are #[cfg(all(test, windows))] and run only on Windows. RDNA2 quad-byte SAD instructions lowered: quad_sad/quad_sad_pair with build_valu_cs_with_outputs/run_cases_with_outputs harness checking per-case outputs on hardware/WARP.
Marvisak commented 2026-11-25 02:06:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:33:47Z.


Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-shader/src/emit/lower.rs, crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149690484 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1662#issuecomment-7149690484). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:33:47Z. --- <!-- victory-triage v1 head=e8bbc120b6d87efeffd68701cafa6dd7413cc6fa verdict=needs-rebase at=2026-11-25T01:33:47Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-shader/src/emit/lower.rs`, `crates/victory-shader/src/emit/valu_tests.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
sinan-cmyk commented 2026-11-25 03:03:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-25T02:36:09Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count change against main.

Offline. I merged head e8bbc12 onto main ffe310e (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: 21,724 on main, 21,724 with this PR.

No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests: with the same merge, cargo test --locked -p victory-shader --lib passed 125, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150936470 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1662#issuecomment-7150936470). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-25T02:36:09Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head e8bbc12 onto `main` ffe310e (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: 21,724 on `main`, 21,724 with this PR. No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests:** with the same merge, `cargo test --locked -p victory-shader --lib` passed 125, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1662:upstream-pr/1662'
git switch 'upstream-pr/1662'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1662'
git switch 'upstream-pr/1662'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1662'
git switch 'upstream-pr/1662'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1662'
git switch 'main'
git merge --squash 'upstream-pr/1662'
git switch 'main'
git merge --ff-only 'upstream-pr/1662'
git switch 'main'
git merge 'upstream-pr/1662'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!1661
No description provided.