Shaders: lower s_quadmask_b32 and s_quadmask_b64 #87

Open
Ingenioeren wants to merge 1 commit from upstream-pr/87 into main
Ingenioeren commented 2026-11-25 10:11:21 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Ingenioeren on 2026-11-25T09:45:09Z.


What

s_quadmask_b32 and s_quadmask_b64 were refused (lower: Unsupported { what: "s_quadmask_b32" }). Now they are lowered following the RDNA 2 ISA: bit i of the result is set when any of source bits 4i..4i+3 is set (8 result bits for b32, 16 for b64), the high dword of the b64 result is 0, and SCC is whether the result is nonzero.

The lowering folds each nibble into its low bit and collects those bits into the low byte in 32-bit steps, so it does not need INT64.

Why

Upstream VIctory has lowered these since c3a04e2 ("Shaders: lower scalar quadmask instructions"). ztrx's history split off before that commit, so ztrx still refuses any program that uses them. This PR ports that lowering unchanged. Upstream added no test for it, so this PR also adds one.

How tested

I added a new synthetic test, emit::valu_tests::s_quadmask_folds_each_quad_into_one_bit. It builds GFX10 code in the test and uses no game shaders. It checks the b32 result, the b64 low and high dwords, and SCC for both forms (read through s_cselect_b32). Each check compares 10 inputs against a Rust reference, including 0, single bits at the dword edges, all ones, and bits spread across both dwords.

  • cargo test --locked --offline -p victory-shader s_quadmask:
    • before: fails with lower: Unsupported { offset: 36, what: "s_quadmask_b32" };
    • after: passes on both the hardware adapter and WARP (no "skipped" lines with --nocapture).
  • cargo test --locked --offline -p victory-shader: 209 passed, 2 failed. The two failures (emit::rect::tests::the_rectangle_stage_is_a_geometry_shader and rectangles_are_drawn_whole) also fail on main on this PC with its local dxil.dll, so they are unrelated.
  • cargo clippy --locked --offline -p victory-shader --all-targets: no warnings.
  • cargo run -p xtask -- policy --staged: asset policy: 2 files ok.
  • cargo fmt --check shows nothing for the lines this PR adds (the crate has other formatting differences on main, which this PR leaves alone).

Not tested: the test hardware was an AMD RX 6750 XT plus WARP, not an NVIDIA card. This is a code-level translation fix with no vendor-specific behaviour, but there was no NVIDIA run and no game run.

AI assistance: prepared with Claude Code, reviewed by Ingenioeren.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Zettrox/ztrx:issue:6601629108 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/87). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-25T09:45:09Z. --- ## What `s_quadmask_b32` and `s_quadmask_b64` were refused (`lower: Unsupported { what: "s_quadmask_b32" }`). Now they are lowered following the RDNA 2 ISA: bit `i` of the result is set when any of source bits `4i..4i+3` is set (8 result bits for b32, 16 for b64), the high dword of the b64 result is 0, and SCC is whether the result is nonzero. The lowering folds each nibble into its low bit and collects those bits into the low byte in 32-bit steps, so it does not need INT64. ## Why Upstream VIctory has lowered these since c3a04e2 ("Shaders: lower scalar quadmask instructions"). ztrx's history split off before that commit, so ztrx still refuses any program that uses them. This PR ports that lowering unchanged. Upstream added no test for it, so this PR also adds one. ## How tested I added a new synthetic test, `emit::valu_tests::s_quadmask_folds_each_quad_into_one_bit`. It builds GFX10 code in the test and uses no game shaders. It checks the b32 result, the b64 low and high dwords, and SCC for both forms (read through `s_cselect_b32`). Each check compares 10 inputs against a Rust reference, including 0, single bits at the dword edges, all ones, and bits spread across both dwords. - `cargo test --locked --offline -p victory-shader s_quadmask`: - **before:** fails with `lower: Unsupported { offset: 36, what: "s_quadmask_b32" }`; - **after:** passes on both the hardware adapter and WARP (no "skipped" lines with `--nocapture`). - `cargo test --locked --offline -p victory-shader`: 209 passed, 2 failed. The two failures (`emit::rect::tests::the_rectangle_stage_is_a_geometry_shader` and `rectangles_are_drawn_whole`) also fail on `main` on this PC with its local `dxil.dll`, so they are unrelated. - `cargo clippy --locked --offline -p victory-shader --all-targets`: no warnings. - `cargo run -p xtask -- policy --staged`: `asset policy: 2 files ok`. - `cargo fmt --check` shows nothing for the lines this PR adds (the crate has other formatting differences on `main`, which this PR leaves alone). **Not tested:** the test hardware was an AMD RX 6750 XT plus WARP, not an NVIDIA card. This is a code-level translation fix with no vendor-specific behaviour, but there was no NVIDIA run and no game run. AI assistance: prepared with Claude Code, reviewed by Ingenioeren. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
hamdog0203 commented 2026-11-25 12:07:13 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by hamdog0203 on 2026-11-25T11:51:39Z.


Independent verification on NVIDIA RTX 4060 (8 GB, Wave32, driver 621.35) + WARP + Windows SDK dxil.dll (10.0.26100.0), Windows 11 x64 (26200.9974), rustc 1.98.1, audited at commit 9f920fcbae7cb4a64fd9432730f8763a8a98723f:

  • Code & security review: Clean 32-bit nibble-folding lowering for s_quadmask_b32 and s_quadmask_b64 in crates/victory-shader/src/emit/lower.rs with comprehensive synthetic tests in valu_tests.rs covering both dwords and SCC (no unsafe).
  • CI & hardware checks:
    • cargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)
    • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)
    • cargo test --locked -p victory-shader --lib s_quadmask -- --nocapture: s_quadmask_folds_each_quad_into_one_bit passed on both RTX 4060 and WARP + dxil.dll (no skipped backends)
    • cargo test --workspace --locked: the parallel workspace run hit the pre-existing WARP concurrency STATUS_ACCESS_VIOLATION (0xc0000005) in victory_gpu; re-running cargo test --workspace --locked -- --test-threads=1 passed cleanly across all crates (victory_gpu: 110 passed, 1 ignored; victory_shader: 211 passed, 2 ignored; xtask asset-policy: 4 passed)

Verified on NVIDIA Wave32 hardware and WARP via the workspace suite and synthetic tests (no game run performed).

<!-- greyfinch-sync:Zettrox/ztrx:comment:7161596376 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/87#issuecomment-7161596376). Originally posted by [hamdog0203](https://github.com/hamdog0203) on 2026-11-25T11:51:39Z. --- Independent verification on NVIDIA RTX 4060 (8 GB, Wave32, driver 621.35) + WARP + Windows SDK `dxil.dll` (`10.0.26100.0`), Windows 11 x64 (`26200.9974`), `rustc 1.98.1`, audited at commit `9f920fcbae7cb4a64fd9432730f8763a8a98723f`: - **Code & security review:** Clean 32-bit nibble-folding lowering for `s_quadmask_b32` and `s_quadmask_b64` in `crates/victory-shader/src/emit/lower.rs` with comprehensive synthetic tests in `valu_tests.rs` covering both dwords and `SCC` (no `unsafe`). - **CI & hardware checks:** - `cargo clippy --workspace --all-targets --locked -- -D warnings`: passed (0 warnings) - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings`: passed (0 warnings) - `cargo test --locked -p victory-shader --lib s_quadmask -- --nocapture`: `s_quadmask_folds_each_quad_into_one_bit` passed on both RTX 4060 and WARP + `dxil.dll` (no skipped backends) - `cargo test --workspace --locked`: the parallel workspace run hit the pre-existing WARP concurrency `STATUS_ACCESS_VIOLATION` (`0xc0000005`) in `victory_gpu`; re-running `cargo test --workspace --locked -- --test-threads=1` passed cleanly across all crates (`victory_gpu`: 110 passed, 1 ignored; `victory_shader`: 211 passed, 2 ignored; `xtask` asset-policy: 4 passed) Verified on NVIDIA Wave32 hardware and WARP via the workspace suite and synthetic tests (no game run performed).
Aniseto commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Aniseto on 2026-11-25T14:49:19Z.


Ran the new quadmask test at 9f920fc (clean PR head on main 90b529f):

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXIL validator 1.9.2609.5 (VICTORY_DXIL), debug build

Results

  • cargo test --locked -p victory-shader --lib s_quadmask -- --nocapture: 1 passed, 0 failed, 0 ignored, 212 filtered out (exit 0). No skip line with --nocapture.
  • cargo test --locked -p victory-shader --lib -- --test-threads=1: 211 passed, 0 failed, 2 ignored (exit 0). The two ignored are the benchmark and the strict-joins case; the rectangle tests pass here.

What this adds
The PR says it was tested on an AMD RX 6750 XT plus WARP, with no NVIDIA run. The other report in the thread covers an RTX 4060 (Ampere). This adds a Blackwell wave32 part on driver 32.0.16.2124 with DXIL validator 1.9.2609.5; s_quadmask_folds_each_quad_into_one_bit passes on the real adapter here.

Not tested
The title's shader pack, live pipeline creation, retail runs, the console compiler's DXC, release profile, RDNA2/RDNA4 and Intel GPUs.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7165867781 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/87#issuecomment-7165867781). Originally posted by [Aniseto](https://github.com/Aniseto) on 2026-11-25T14:49:19Z. --- Ran the new quadmask test at `9f920fc` (clean PR head on `main` `90b529f`): **System** - GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124 - CPU: Intel Core i5-12400F, 64 GB RAM - OS: Windows 11 Pro build 26200 x64 - Toolchain: Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXIL validator 1.9.2609.5 (`VICTORY_DXIL`), debug build **Results** - `cargo test --locked -p victory-shader --lib s_quadmask -- --nocapture`: 1 passed, 0 failed, 0 ignored, 212 filtered out (exit 0). No skip line with `--nocapture`. - `cargo test --locked -p victory-shader --lib -- --test-threads=1`: 211 passed, 0 failed, 2 ignored (exit 0). The two ignored are the benchmark and the strict-joins case; the rectangle tests pass here. **What this adds** The PR says it was tested on an AMD RX 6750 XT plus WARP, with no NVIDIA run. The other report in the thread covers an RTX 4060 (Ampere). This adds a Blackwell wave32 part on driver 32.0.16.2124 with DXIL validator 1.9.2609.5; `s_quadmask_folds_each_quad_into_one_bit` passes on the real adapter here. **Not tested** The title's shader pack, live pipeline creation, retail runs, the console compiler's DXC, release profile, RDNA2/RDNA4 and Intel GPUs. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash Free** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.
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/87:upstream-pr/87'
git switch 'upstream-pr/87'

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/87'
git switch 'upstream-pr/87'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/87'
git switch 'upstream-pr/87'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/87'
git switch 'main'
git merge --squash 'upstream-pr/87'
git switch 'main'
git merge --ff-only 'upstream-pr/87'
git switch 'main'
git merge 'upstream-pr/87'
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
Zettrox/ztrx!87
No description provided.