Shaders: lower scalar quadmask instructions #1443

Manually merged
github merged 2 commits from gh-pr/1443/head into gh-pr/1443/base 2026-11-26 04:31:54 +00:00
Owner

@⁠Luizbc2 on GitHub · 2026-11-24 18:02 UTC · original
Luizbc2:fix/rdna2-quadmask → main · +74 −0 · 2 files · 2 commits · merged 2026-11-25 00:22 UTC

Summary

Implement s_quadmask_b32 and s_quadmask_b64. The decoder recognizes both opcodes, but currently rejects shaders that use their result. Each instruction packs one bit for every nonzero four-bit group and sets SCC when the result is nonzero. The 64-bit form clears the high destination word. Both forms lower with 32-bit DXIL operations.

Semantics follow the AMD RDNA 2 ISA reference.

Reproduction and testing

cargo test --workspace --lib --locked --offline scalar_quad_masks_pack_nibbles_and_set_scc

On base ffe310e, the added test fails with Unsupported { offset: 48, what: "s_quadmask_b32" }. With the change, it passes DXIL validation and runs on Intel Iris Xe and WARP. The generated shaders check the zero case, sparse and full masks, input bits in the high word only, SCC, and a cleared high destination word.

The inputs are synthetic. AI-assisted with Codex.

**@⁠Luizbc2** on GitHub · 2026-11-24 18:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/1443) `Luizbc2:fix/rdna2-quadmask` → `main` · +74 −0 · 2 files · 2 commits · merged 2026-11-25 00:22 UTC ## Summary Implement `s_quadmask_b32` and `s_quadmask_b64`. The decoder recognizes both opcodes, but currently rejects shaders that use their result. Each instruction packs one bit for every nonzero four-bit group and sets SCC when the result is nonzero. The 64-bit form clears the high destination word. Both forms lower with 32-bit DXIL operations. Semantics follow the [AMD RDNA 2 ISA reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf). ## Reproduction and testing `cargo test --workspace --lib --locked --offline scalar_quad_masks_pack_nibbles_and_set_scc` On base `ffe310e`, the added test fails with `Unsupported { offset: 48, what: "s_quadmask_b32" }`. With the change, it passes DXIL validation and runs on Intel Iris Xe and WARP. The generated shaders check the zero case, sparse and full masks, input bits in the high word only, SCC, and a cleared high destination word. The inputs are synthetic. AI-assisted with Codex.
Reduce each group of four bits to one bit and preserve the scalar condition code.
Check both mask widths, the condition code and the zeroed upper destination.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:31:52 +00:00
github manually merged commit e3fe5bf94f into gh-pr/1443/base 2026-11-26 04:31:54 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 18:10 UTC · original

Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at e3fe5bf. cargo test -p victory-shader --lib -- --test-threads=1 gives 121 passed, 0 failed, 1 ignored. scalar_quad_masks_pack_nibbles_and_set_scc passes on the hardware adapter and WARP.

I also went through quad_mask by hand:

  • x | x >> 1, then >> 2 masked with 0x1111_1111, leaves each nibble's OR in its bottom bit.
  • The >> 3, >> 6 and >> 12 steps move bit 4k to bit k.
  • The b64 form puts the high dword's byte at bits 8-15 and writes 0 to the high destination.

The expected values follow from this: 0x8000_0420 gives 0x86, and with 0x0100_0001 in the high dword the pair gives 0x4186.

**@⁠marquezinii** on GitHub · 2026-11-24 18:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1443#issuecomment-7140271294) Ran on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at `e3fe5bf`. `cargo test -p victory-shader --lib -- --test-threads=1` gives 121 passed, 0 failed, 1 ignored. `scalar_quad_masks_pack_nibbles_and_set_scc` passes on the hardware adapter and WARP. I also went through `quad_mask` by hand: - `x | x >> 1`, then `>> 2` masked with `0x1111_1111`, leaves each nibble's OR in its bottom bit. - The `>> 3`, `>> 6` and `>> 12` steps move bit `4k` to bit `k`. - The b64 form puts the high dword's byte at bits 8-15 and writes 0 to the high destination. The expected values follow from this: `0x8000_0420` gives `0x86`, and with `0x0100_0001` in the high dword the pair gives `0x4186`.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 20:43 UTC · original

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

Result: no count change against main.

Offline. I merged head e3fe5bf 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 121, 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).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 20:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/1443#issuecomment-7143980715) ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count change against `main`.** **Offline.** I merged head e3fe5bf 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 121, 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 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!1443
No description provided.