Shaders: lower scalar quadmask instructions #1442

Merged
Luizbc2 merged 2 commits from upstream-pr/1443 into main 2026-11-25 00:22:41 +00:00
Luizbc2 commented 2026-11-24 18:02:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Luizbc2 on 2026-11-24T18:02:36Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6588210925 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1443). Originally posted by [Luizbc2](https://github.com/Luizbc2) on 2026-11-24T18:02:36Z. --- ## 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.
marquezinii commented 2026-11-24 19:04:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T18:10:45Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140271294 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1443#issuecomment-7140271294). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T18:10:45Z. --- 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`.
catminou4 commented 2026-11-24 20:02:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T19:25:03Z.

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 → 96. GPU/valu execution tests are Windows-gated and were not run here.

s_quadmask_b32/s_quadmask_b64 lowering: packs one bit per group of four pixels via a nibble-fold (or with >>1, then fold distances 2/3/6/12 with keep masks — no 64-bit ops needed), b64 combines two 32-bit halves into the low/high dwords and sets SCC from nonzero. The valu test covers empty, sparse, full and cross-half patterns for both opcodes plus the high-dword-is-zero case (Windows-only); macOS 96 green. The fold constants check out against the ISA semantics.

<!-- greyfinch-sync:Marvisak/VIctory:review:6045876669 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1443#pullrequestreview-6045876669). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T19:25:03Z. **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` → 96. GPU/valu execution tests are Windows-gated and were not run here. `s_quadmask_b32`/`s_quadmask_b64` lowering: packs one bit per group of four pixels via a nibble-fold (`or` with >>1, then fold distances 2/3/6/12 with keep masks — no 64-bit ops needed), b64 combines two 32-bit halves into the low/high dwords and sets SCC from nonzero. The valu test covers empty, sparse, full and cross-half patterns for both opcodes plus the high-dword-is-zero case (Windows-only); macOS 96 green. The fold constants check out against the ISA semantics.
sinan-cmyk commented 2026-11-24 21:03:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T20:43:53Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7143980715 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1443#issuecomment-7143980715). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T20:43:53Z. --- ### 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).
upstream-sync closed this pull request 2026-11-25 01:06:33 +00:00
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!1442
No description provided.