Skip to content

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

Open
0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:shader/pixel-quad-dpp8-and-single-op-patterns
Open

0xkn0wh3r3 wants to merge 1 commit into
Marvisak:mainfrom
0xkn0wh3r3:shader/pixel-quad-dpp8-and-single-op-patterns

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

@fuzeofficlal

Copy link
Copy Markdown
Contributor

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 Shaders: a wave64 mask set by halves tests its high dword in lanes 32-63 (#2780) #2783.

@kotekompotek kotekompotek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: the intra-quad test (sel>>3i ^ i) & 4 == 0 is exactly 'selected lane shares lane i's bit 2' — stays in its 4-lane quad — and the two fast-path tables are right: broadcasts (0x00/55/AA/FF) → quadReadLaneAt at p&3; partner exchanges 0xB1/0x4E/0x1B → quadOp directions 0/1/2 via (p&3)-1; 0xE4 identity → x. Cross-quad DPP8 in PS correctly degrades to the cross_lane refusal rather than a wrong quad op, and differing per-quad permutations are safe since pattern: None for DPP8 keeps the per-lane src select path. The hardware helper-lane test at a triangle edge is the right coverage. LGTM.

JMAN730 added a commit to JMAN730/project-flamingo that referenced this pull request Nov 25, 2026
…on quad patterns take one

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@921d8d3
(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 <29156494+DexNom@users.noreply.github.com>
@0xkn0wh3r3
0xkn0wh3r3 force-pushed the shader/pixel-quad-dpp8-and-single-op-patterns branch from 2fee03c to 6e2215e Compare November 25, 2026 22:14
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
Airamek added a commit to Airamek/VIctory that referenced this pull request Nov 26, 2026
Port of the 0xkn0wh3r3 Marvisak#2817 delta onto this tree (hunk1, pixel quad reads
reaching helpers, is already landed; Marvisak#2817 does not apply cleanly). Only
the delta taken:

- quad_pick takes the quad permutation every quad uses: the identity
  returns the value, a broadcast of one lane is one QuadReadLaneAt, an
  exchange across x/y/diagonal is one QuadOp. ds_swizzle and DPP
  quad_perm call sites pass their constant patterns.
- DPP8 where every lane picks a lane of its own quad now takes the quad
  path (as quad_perm does) instead of being refused; DPP8 reading across
  quads stays refused.
- New quad_tests: every quad permutation through ds_swizzle/DPP plus an
  in-quad DPP8 translate and pass the DXIL validator, a cross-quad DPP8
  is refused, and broadcasts/exchanges read helper coordinates along a
  shared triangle edge (hardware/WARP where present, skipped otherwise).

Copy link
Copy Markdown
Owner

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

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::quad_tests: 2 passed, 0 failed (pixel_quad_swizzles_validate_and_dpp8_cannot_cross_quads and pixel_quad_reads_take_helper_coordinates_at_a_shared_triangle_edge pass on RTX 5090 hardware and WARP).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

Mdemets pushed a commit to Mdemets/project-flamingo that referenced this pull request Nov 26, 2026
…ke one quad operation

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. Such a DPP8 now counts as quad-local, as
quad_perm already does; DPP8 that reads across quads stays refused.

Quad reads (mesh programs here) 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.

Ported from Marvisak#2817 (2fee03c), itself from
DexNom/VIctory@921d8d3. Upstream also
routes pixel quad reads through quad operations so they reach helper
lanes (from a larger upstream accuracy commit this tree does not have);
that part and its GPU tests are not ported, so pixel quad-local reads
here still go through wave reads. The tests are new for this tree's
harness and run on every platform.

Co-authored-by: DexNom <29156494+DexNom@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants