Shaders: pixel DPP8 within a quad reads through quad operations; common quad patterns take one #2817

Open
github-bot wants to merge 1 commit from github-bot/gh-2817 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 21:19 UTC · original
0xkn0wh3r3:shader/pixel-quad-dpp8-and-single-op-patterns → main · +331 −7 · 3 files · 1 commits · open

What

DPP8 in pixel programs. dpp() counted only quad_perm as quad-local. A DPP8 in a pixel shader always went through cross_lane(false) and was refused ("a cross-lane operation outside compute"). That happened even when every lane picks a lane of its own quad, which quad reads can serve (helper lanes included). Such a DPP8 is now quad-local and takes the quad path, as quad_perm does. A DPP8 that reads across quads stays refused.

Single-op quad patterns. quad_pick read all four lanes with QuadReadLaneAt and selected among them. When the instruction gives a pattern that every quad uses (ds_swizzle quad mode, DPP quad_perm), common cases now lower to one operation:

  • identity [0,1,2,3]: no operation
  • broadcast of lane n (0x00, 0x55, 0xAA, 0xFF): one QuadReadLaneAt
  • exchange across x (0xB1), across y (0x4E) or the diagonal (0x1B): one QuadOp (opcode 123, directions 0/1/2)

Other patterns, and DPP8, keep the four-read selection.

Where it came from

Ported from DexNom's fork: the quad-pattern and DPP8 lowering is from DexNom/VIctory@921d8d3 ("Repair pixel quad sampling, …"), credited with Co-authored-by: DexNom. In their fork that commit is recorded under the author name "Codex".

I adapted the code to this tree. Here, helper-lane quad reads already exist (helpers_read), and cross_lane already accepts quad-local reads in pixel programs. That commit's other changes don't apply to this tree:

  • The cube-LOD log2/clamp fix: main already uses DXIL Log as base 2 and applies the clamp.
  • Ray buffer views and the sparse-texture page walk: these target code that only exists in their fork.

Tested

New emit/quad_tests.rs, reworked from that commit's tests for this tree's harness:

  • pixel_quad_swizzles_validate_and_dpp8_cannot_cross_quads: every quad permutation through ds_swizzle_b32 and DPP, and an in-quad DPP8 whose two quads use different permutations, translate and pass dxil.dll. A DPP8 where lane 0 reads lane 7 is refused. On current main the in-quad DPP8 is refused, so this test fails there.
  • pixel_quad_reads_take_helper_coordinates_at_a_shared_triangle_edge: two triangles share the diagonal of a 16×16 target. Each covers some pixels as helpers of the quads the diagonal crosses. Broadcasts and the three exchanges (by ds_swizzle_b32 and by DPP) must return the helper lanes' SV_Position coordinates. Checked on the hardware adapter (RTX 5070 Ti) and on WARP. As a check that the test catches mistakes, I temporarily mapped the exchange directions wrongly, and all 256 pixels then failed on both adapters.
  • cargo test -p victory-shader on Windows 11 with an RTX 5070 Ti: 300 passed. Four tests fail identically on unmodified main on this machine, so they're unrelated: heap_direct_texture_reads_mark_their_heap_index (access violation), two stride_tests heap-buffer reads and gathers_at_a_level_match_the_hardware.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.

Not tested

  • I haven't run the game or the title's shader archive: not how many shaders the DPP8 change recovers, and not the speed of the single-op patterns.
  • Not tested on an AMD GPU. Mesh programs also use quad_pick and now get the same fast paths, but this PR doesn't add a mesh-shader test.
  • Rebased onto main after #1582 landed. The pattern is passed into #1582's paths, and the inactive-source masking still applies after the quad read. The #1582 crosslane_tests pass with this change on the RTX 5070 Ti, including its inactive-source checks for ds_swizzle, DPP16 and DPP8.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 21:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2817) `0xkn0wh3r3:shader/pixel-quad-dpp8-and-single-op-patterns` → `main` · +331 −7 · 3 files · 1 commits · open ## What **DPP8 in pixel programs.** `dpp()` counted only `quad_perm` as quad-local. A DPP8 in a pixel shader always went through `cross_lane(false)` and was refused ("a cross-lane operation outside compute"). That happened even when every lane picks a lane of its own quad, which quad reads can serve (helper lanes included). Such a DPP8 is now quad-local and takes the quad path, as `quad_perm` does. A DPP8 that reads across quads stays refused. **Single-op quad patterns.** `quad_pick` read all four lanes with `QuadReadLaneAt` and selected among them. When the instruction gives a pattern that every quad uses (ds_swizzle quad mode, DPP `quad_perm`), common cases now lower to one operation: - identity `[0,1,2,3]`: no operation - broadcast of lane n (`0x00`, `0x55`, `0xAA`, `0xFF`): one `QuadReadLaneAt` - exchange across x (`0xB1`), across y (`0x4E`) or the diagonal (`0x1B`): one `QuadOp` (opcode 123, directions 0/1/2) Other patterns, and DPP8, keep the four-read selection. ## Where it came from Ported from DexNom's fork: the quad-pattern and DPP8 lowering is from [DexNom/VIctory@921d8d3](https://github.com/DexNom/VIctory/commit/921d8d3b43b44f3a6ca4b44095edd3c4baf10a87) ("Repair pixel quad sampling, …"), credited with `Co-authored-by: DexNom`. In their fork that commit is recorded under the author name "Codex". I adapted the code to this tree. Here, helper-lane quad reads already exist (`helpers_read`), and `cross_lane` already accepts quad-local reads in pixel programs. That commit's other changes don't apply to this tree: - The cube-LOD log2/clamp fix: main already uses DXIL `Log` as base 2 and applies the clamp. - Ray buffer views and the sparse-texture page walk: these target code that only exists in their fork. ## Tested New `emit/quad_tests.rs`, reworked from that commit's tests for this tree's harness: - `pixel_quad_swizzles_validate_and_dpp8_cannot_cross_quads`: every quad permutation through `ds_swizzle_b32` and DPP, and an in-quad DPP8 whose two quads use different permutations, translate and pass `dxil.dll`. A DPP8 where lane 0 reads lane 7 is refused. On current main the in-quad DPP8 is refused, so this test fails there. - `pixel_quad_reads_take_helper_coordinates_at_a_shared_triangle_edge`: two triangles share the diagonal of a 16×16 target. Each covers some pixels as helpers of the quads the diagonal crosses. Broadcasts and the three exchanges (by `ds_swizzle_b32` and by DPP) must return the helper lanes' `SV_Position` coordinates. Checked on the hardware adapter (RTX 5070 Ti) and on WARP. As a check that the test catches mistakes, I temporarily mapped the exchange directions wrongly, and all 256 pixels then failed on both adapters. - `cargo test -p victory-shader` on Windows 11 with an RTX 5070 Ti: 300 passed. Four tests fail identically on unmodified main on this machine, so they're unrelated: `heap_direct_texture_reads_mark_their_heap_index` (access violation), two `stride_tests` heap-buffer reads and `gathers_at_a_level_match_the_hardware`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. ## Not tested - I haven't run the game or the title's shader archive: not how many shaders the DPP8 change recovers, and not the speed of the single-op patterns. - Not tested on an AMD GPU. Mesh programs also use `quad_pick` and now get the same fast paths, but this PR doesn't add a mesh-shader test. - Rebased onto main after #1582 landed. The pattern is passed into #1582's paths, and the inactive-source masking still applies after the quad read. The #1582 `crosslane_tests` pass with this change on the RTX 5070 Ti, including its inactive-source checks for ds_swizzle, DPP16 and DPP8.
A pixel program's DPP8 was always a cross-lane operation outside
compute, so a shader using one was refused, even where every lane picks
a lane of its own quad (the case quad reads can serve, helper lanes
included). Such a DPP8 now takes the quad path, as quad_perm already
does; DPP8 that reads across quads stays refused.

Quad reads (pixel and mesh programs) read each of the four lanes and
selected among them. A pattern every quad uses alike now takes one
operation: the identity none, a broadcast of one lane one
QuadReadLaneAt, and an exchange across x, across y or the diagonal one
QuadOp.

New tests (emit/quad_tests.rs): every quad permutation through
ds_swizzle_b32 and DPP, and an in-quad DPP8, translate and pass the DXIL
validator, and a cross-quad DPP8 is refused; two triangles sharing a
diagonal, drawn on the hardware adapter and WARP, read helper lanes'
coordinates through broadcasts and exchanges as the console's whole-quad
mode does.

Ported from DexNom/VIctory@921d8d3b43
(recorded there under the author name "Codex"), whose quad-pattern
lowering this is; the tests are reworked from that commit's for this
tree's harness, the exchange case added.

Co-authored-by: DexNom <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:14:58 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 21:30 UTC · original

Verified 2fee03ce on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll):

  • cargo xtask policy: 184 files ok; cargo clippy -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings.
  • RTX 5090 (emit::quad_tests, emit::diff_tests, emit::flow_tests): 8/8 passed (pixel helper-lane quad checks pass on both RTX 5090 and WARP with 0 pixel error across 256 pixels).
  • WARP + dxil.dll: 269 passed, 0 failed (3 ignored, 3 pre-existing hardware-only synthetic_tests filtered).
  • Code review: the within-quad check (0..8).all(|i| ((sel >> (3 * i)) ^ i) & 4 == 0) cleanly separates in-quad vs cross-quad DPP8 (cross-quad still rejected in pixel shaders), and quad_pick maps 0xE4, 0x00/0x55/0xAA/0xFF (quadReadLaneAt), and 0xB1/0x4E/0x1B (quadOp) accurately. (Tiny nit: quad_pick sets flags::WAVE_OPS before the 0xE4 identity early return, which is harmless.)
  • Clean git merge-tree against origin/main 13f91ca and #2783.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 21:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/2817#issuecomment-7175174914) Verified `2fee03ce` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`): - `cargo xtask policy`: 184 files ok; `cargo clippy -p victory-shader --all-targets -- -D warnings` (default & `--features host`): 0 warnings. - RTX 5090 (`emit::quad_tests`, `emit::diff_tests`, `emit::flow_tests`): 8/8 passed (pixel helper-lane quad checks pass on both RTX 5090 and WARP with 0 pixel error across 256 pixels). - WARP + `dxil.dll`: 269 passed, 0 failed (3 ignored, 3 pre-existing hardware-only `synthetic_tests` filtered). - Code review: the within-quad check `(0..8).all(|i| ((sel >> (3 * i)) ^ i) & 4 == 0)` cleanly separates in-quad vs cross-quad DPP8 (cross-quad still rejected in pixel shaders), and `quad_pick` maps `0xE4`, `0x00/0x55/0xAA/0xFF` (`quadReadLaneAt`), and `0xB1/0x4E/0x1B` (`quadOp`) accurately. (Tiny nit: `quad_pick` sets `flags::WAVE_OPS` before the `0xE4` identity early return, which is harmless.) - Clean `git merge-tree` against `origin/main` `13f91ca` and #2783.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 02:20 UTC · original

Automated triage for the maintainers.

In pixel programs, dpp() now treats a DPP8 whose every lane picks a lane of its own quad as quad-local, and serves it through quad reads. A DPP8 that crosses quads is still refused. quad_pick lowers the common quad patterns to one operation: identity, the four broadcasts through QuadReadLaneAt, and the X/Y/diagonal exchanges (0xB1/0x4E/0x1B) through QuadOp with directions 0/1/2. I checked the pattern-to-direction mapping and the DPP8 quad test (bit 2 of each 3-bit selector equal to bit 2 of its lane). Other patterns keep the four-read path. The new quad_tests.rs validates through dxil.dll.

CI: passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 02:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2817#issuecomment-7180715294) <!-- victory-triage v1 head=6e2215ee061877ec5956ad0f20f56f9d63baabed verdict=merge-candidate at=2026-11-26T02:20:43Z --> Automated triage for the maintainers. In pixel programs, `dpp()` now treats a DPP8 whose every lane picks a lane of its own quad as quad-local, and serves it through quad reads. A DPP8 that crosses quads is still refused. `quad_pick` lowers the common quad patterns to one operation: identity, the four broadcasts through `QuadReadLaneAt`, and the X/Y/diagonal exchanges (`0xB1`/`0x4E`/`0x1B`) through `QuadOp` with directions 0/1/2. I checked the pattern-to-direction mapping and the DPP8 quad test (bit 2 of each 3-bit selector equal to bit 2 of its lane). Other patterns keep the four-read path. The new `quad_tests.rs` validates through `dxil.dll`. CI: passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2817/head:github-bot/gh-2817'
git switch 'github-bot/gh-2817'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2817'
git switch 'github-bot/gh-2817'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2817'
git switch 'github-bot/gh-2817'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2817'
git switch 'main'
git merge --squash 'github-bot/gh-2817'
git switch 'main'
git merge --ff-only 'github-bot/gh-2817'
git switch 'main'
git merge 'github-bot/gh-2817'
git push origin 'main'
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!2817
No description provided.