Shaders: pixel DPP8 within a quad reads through quad operations; common quad patterns take one #2815
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2817"
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 0xkn0wh3r3 on 2026-11-25T21:19:00Z.
What
DPP8 in pixel programs.
dpp()counted onlyquad_permas quad-local. A DPP8 in a pixel shader always went throughcross_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, asquad_permdoes. A DPP8 that reads across quads stays refused.Single-op quad patterns.
quad_pickread all four lanes withQuadReadLaneAtand selected among them. When the instruction gives a pattern that every quad uses (ds_swizzle quad mode, DPPquad_perm), common cases now lower to one operation:[0,1,2,3]: no operation0x00,0x55,0xAA,0xFF): oneQuadReadLaneAt0xB1), across y (0x4E) or the diagonal (0x1B): oneQuadOp(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), andcross_lanealready accepts quad-local reads in pixel programs. That commit's other changes don't apply to this tree:Logas base 2 and applies the clamp.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 throughds_swizzle_b32and DPP, and an in-quad DPP8 whose two quads use different permutations, translate and passdxil.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 (byds_swizzle_b32and by DPP) must return the helper lanes'SV_Positioncoordinates. 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-shaderon 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), twostride_testsheap-buffer reads andgathers_at_a_level_match_the_hardware.cargo clippy -p victory-shader --all-targets -- -D warnings: clean.Not tested
quad_pickand now get the same fast paths, but this PR doesn't add a mesh-shader test.crosslane_testspass with this change on the RTX 5070 Ti, including its inactive-source checks for ds_swizzle, DPP16 and DPP8.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T21:50:41Z.
Review: COMMENTED
Verified: the intra-quad test
(sel>>3i ^ i) & 4 == 0is 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 atp&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 thecross_lanerefusal rather than a wrong quad op, and differing per-quad permutations are safe sincepattern: Nonefor DPP8 keeps the per-lanesrcselect path. The hardware helper-lane test at a triangle edge is the right coverage. LGTM.Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T21:30:46Z.
Verified
2fee03ceon Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll):cargo xtask policy: 184 files ok;cargo clippy -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings.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).dxil.dll: 269 passed, 0 failed (3 ignored, 3 pre-existing hardware-onlysynthetic_testsfiltered).(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), andquad_pickmaps0xE4,0x00/0x55/0xAA/0xFF(quadReadLaneAt), and0xB1/0x4E/0x1B(quadOp) accurately. (Tiny nit:quad_picksetsflags::WAVE_OPSbefore the0xE4identity early return, which is harmless.)git merge-treeagainstorigin/main13f91caand #2783.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:31:15Z.
Review: APPROVED
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP,dxil.dllvalidator active):cargo test -p victory-shader --lib emit::quad_tests: 2 passed, 0 failed (pixel_quad_swizzles_validate_and_dpp8_cannot_cross_quadsandpixel_quad_reads_take_helper_coordinates_at_a_shared_triangle_edgepass 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).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T02:20:49Z.
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_picklowers the common quad patterns to one operation: identity, the four broadcasts throughQuadReadLaneAt, and the X/Y/diagonal exchanges (0xB1/0x4E/0x1B) throughQuadOpwith 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 newquad_tests.rsvalidates throughdxil.dll.CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-26T22:22:42Z.
One coverage detail from adapting this on a 4 GB RTX 3050 Laptop fork: the triangle-edge test in this PR draws ds_swizzle and DPP quad_perm. The asymmetric DPP8 case is validated, but its pixels are not read back.
We adapted the draw fixture to emit v_mov_b32_dpp8. With a four-lane WARP device (D3D12_OPTIONS1 reports min=max=4), selecting horizontal exchange for guest lanes 0–3 and identity for 4–7 produced exchange at all 256 pixels and no identity pixels. That is an observation on our downstream emitter. This device cannot demonstrate that both guest selector halves work. For the repeated-quad subset, we measured 1,024 correct DPP8 pixels per adapter on RTX 3050 Laptop and WARP, including a three-lane cycle and non-affine data.
Could someone with a different native wave width exercise an asymmetric DPP8 in the draw fixture and record which selector halves actually occurred? This would complement the existing validation and RTX 5090 report.
AI-assisted synthetic test and review.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T23:03:53Z.
Review: CHANGES_REQUESTED
Mapping
ds_swizzle_b32/ DPPquad_permbroadcasts andQuadOpexchanges cleanly reduces quad-op count and passes all 7quad_tests+crosslane_testson both RTX 5090 and WARP (lower.rsis522,153bytes,policyandclippypass).However, the new pixel DPP8 admission introduces a P1 correctness bug (plus two related DPP8 edge cases and a module-order nit):
crates/victory-shader/src/emit/lower.rs:5874-5877, 5892-5900):Checking
(0..8).all(|i| ((sel >> (3 * i)) ^ i) & 4 == 0)admits asymmetricdpp8encodings where lanes0..3and4..7use different 4-lane permutations (such as[3, 0, 2, 1, 4, 6, 5, 7]inquad_tests.rs:241), whiledpp()computesp = WaveGetLaneIndex() & 7(lower.rs:5892). DXIL pixel shaders preserve quad-local lane order (0..3), not host wave quad parity (WaveGetLaneIndex() & 4). An asymmetricdpp8can silently execute the wrong half's permutation depending on how the host rasterizer packs quads into a wave. Pixel DPP8 must require both halves of the 8-lane group to use the same 4-lane quad permutation (which also unlocks the single-opquad_pickfast path for symmetric broadcast/exchange DPP8 patterns).guard == None),src_lane_active(lower.rs:3139-3147) returnsNone, sodpp8(fi=0) skips zeroing reads from lanes outside the branch anddpp8_fi(fi=1) reads undefined values viaquadReadLaneAtinstead of the retained source VGPR.v_movrels_b32/v_movrelsd_b32(lower.rs:6143-6170) readinst.read(Reg::V(sreg + k))directly instead of consumingself.src0, ignoring DPP if reached.Minor nits:
crates/victory-shader/src/emit/mod.rs:212-215: please placemod quad_tests;alphabetically betweenmemory_testsandrect(quad_tests.rsitself passesrustfmt).quad_tests.rs: the GPU/WARP draw test only exercises DPP16quad_permandds_swizzle_b32, not DPP8 (fi=0/fi=1), andlower.rs:5878also admits DPP8 in mesh shaders (mesh_quad).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.