Shaders: lower scalar quadmask instructions #1442
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1443"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Luizbc2 on 2026-11-24T18:02:36Z.
Summary
Implement
s_quadmask_b32ands_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_sccOn base
ffe310e, the added test fails withUnsupported { 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.
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=1gives 121 passed, 0 failed, 1 ignored.scalar_quad_masks_pack_nibbles_and_set_sccpasses on the hardware adapter and WARP.I also went through
quad_maskby hand:x | x >> 1, then>> 2masked with0x1111_1111, leaves each nibble's OR in its bottom bit.>> 3,>> 6and>> 12steps move bit4kto bitk.The expected values follow from this:
0x8000_0420gives0x86, and with0x0100_0001in the high dword the pair gives0x4186.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_b64lowering: packs one bit per group of four pixels via a nibble-fold (orwith >>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.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
e3fe5bfontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 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 --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).