Shaders: quad reads in a pixel program's lane branch see the lanes outside EXEC #244

Open
murillojndem wants to merge 2 commits from upstream-pr/244 into main
murillojndem commented 2026-11-30 16:37:39 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-30T16:37:39Z.


The translator turns a region that the console runs with EXEC narrowed into a per-lane branch on the host (structure.rs, LaneExit::Branch), so a lane outside EXEC is not there inside it. A DPP or ds_swizzle_b32 quad read in such a region that names one of those lanes is undefined in DXIL. On the RX 7900 XT it gave the value the branch would have computed in that lane; on WARP it gave 0 or garbage. The console reads the lane's register when the DPP fetches inactive lanes (FI), and without FI treats the lane as disabled (0 with bound_ctrl, no write without).

A pixel program with such a read is now translated a second time, with the EXEC branches around the read taken by whole quads through structure::structure_wide, as compute programs already are (widen). In wave_wide a pixel quad decides by quad reads of its lanes' conditions (quad_vote), which include helper lanes; the wave operations of SM 6.6 leave helpers out. The four lanes of the quad stay together, and the lanes outside EXEC run the region under their guards, as on the console.

The first translation stays whenever the second does not translate. That covers:

  • a branch on VCC or SCC around the read, where the console runs on in every lane of EXEC once one lane of the wave says so, which a quad alone cannot know;
  • a branch block that not every lane reaches (inside a loop, for example), where the four lanes would not all be there to vote;
  • an interpolation under EXEC in that form: the second half of a v_interp_p1/v_interp_p2 pair reads the first half's result and could not keep the register of a lane outside EXEC. This refusal stops the second translation at once.

VICTORY_QUAD_WIDE=0 keeps the old translation, and the switch is part of the shader cache key. The line "shaders from the cache and translated so far" also counts the pixel programs translated this way (quad_wide), in runs that translate them rather than take them from the cache.

Without FI the read is exact only together with #232, which treats a source lane outside EXEC by its guard; this change is what makes that lane present inside a lane branch.

The case was found through LloydNicholson/VIctory-Linux commit 933d51d6, which reports star flares in the bloom (PS_BreakableGlassNoCrack) and purple speckles on glossy surfaces from such reads on RADV, and replaces the read with the lane's own value. That symptom is not reproduced here; the tests below are synthetic.

Tests:

  • emit::dpp_lane_branch_tests::pixel_dpp_fetching_a_lane_outside_exec_in_a_lane_branch_reads_its_register: a pixel program narrows EXEC to the lanes of even x with s_and_saveexec_b32 and s_cbranch_execz, changes v2 inside the branch, and moves the odd-x neighbour's v2 with v_mov_b32_dpp quad_perm:[1,0,3,2] fi:1. It is drawn as one triangle over the target and as two triangles sharing the diagonal (quads with helper lanes), on WARP and the RX 7900 XT. On main, and with VICTORY_QUAD_WIDE=0, 128 of 256 pixels are wrong on both (the card gives x + 5 where the console gives x + 1); with this change it passes on both.
  • Without FI, with and without bound_ctrl, on a local merge of this branch with #232: all three variants pass on WARP and the card in both shapes; with VICTORY_QUAD_WIDE=0 they all fail.
  • victory-shader --lib through hw-run on the RX 7900 XT and WARP, on the revision before the review changes (which only narrow when a program is translated the second way): 238 passed, 2 failed, 4 ignored; the two failures are emit::rect::tests (rectangles_are_drawn_whole, the_rectangle_stage_is_a_geometry_shader), which fail on main too. On this revision a game was opened during the card run, so the suite ran on WARP only: 235 passed, 5 failed, 4 ignored; the failures are the same two rect tests and three valu_tests that ask for the hardware device and fail the same way on main in that mode (compute_pipeline failed). The new test ran on the card on this revision, before the game was opened.
  • Clippy with -D warnings, with and without --all-features, for victory-shader, victory-gpu and victory, and cargo xtask policy pass. rustfmt reports the same differences as on main. It merges without conflicts with my open PRs and test branches.

Limits:

  • Only s_cbranch_execz and s_cbranch_execnz branches are taken by quads; a quad read under a VCC or SCC branch keeps the old translation.
  • How many of the title's pixel programs this reaches is not counted here; the quad_wide count in the log shows it in a run that translates them.
  • A widened program runs the region in every lane of a quad that has one lane in EXEC, with guards on its writes. The cost was not measured.
  • The second translation repeats the first before it widens, one extra translation per such program when it is not in the cache.
  • A quad read in a loop header with its own per-lane exit is not caught: the header counts as a block every lane runs.

Generated with Claude Code

<!-- greyfinch-sync:DexNom/VIctory:issue:5569496334 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/244). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-30T16:37:39Z. --- The translator turns a region that the console runs with EXEC narrowed into a per-lane branch on the host (`structure.rs`, `LaneExit::Branch`), so a lane outside EXEC is not there inside it. A DPP or `ds_swizzle_b32` quad read in such a region that names one of those lanes is undefined in DXIL. On the RX 7900 XT it gave the value the branch would have computed in that lane; on WARP it gave 0 or garbage. The console reads the lane's register when the DPP fetches inactive lanes (FI), and without FI treats the lane as disabled (0 with bound_ctrl, no write without). A pixel program with such a read is now translated a second time, with the EXEC branches around the read taken by whole quads through `structure::structure_wide`, as compute programs already are (`widen`). In `wave_wide` a pixel quad decides by quad reads of its lanes' conditions (`quad_vote`), which include helper lanes; the wave operations of SM 6.6 leave helpers out. The four lanes of the quad stay together, and the lanes outside EXEC run the region under their guards, as on the console. The first translation stays whenever the second does not translate. That covers: - a branch on VCC or SCC around the read, where the console runs on in every lane of EXEC once one lane of the wave says so, which a quad alone cannot know; - a branch block that not every lane reaches (inside a loop, for example), where the four lanes would not all be there to vote; - an interpolation under EXEC in that form: the second half of a `v_interp_p1`/`v_interp_p2` pair reads the first half's result and could not keep the register of a lane outside EXEC. This refusal stops the second translation at once. `VICTORY_QUAD_WIDE=0` keeps the old translation, and the switch is part of the shader cache key. The line "shaders from the cache and translated so far" also counts the pixel programs translated this way (`quad_wide`), in runs that translate them rather than take them from the cache. Without FI the read is exact only together with #232, which treats a source lane outside EXEC by its guard; this change is what makes that lane present inside a lane branch. The case was found through LloydNicholson/VIctory-Linux commit 933d51d6, which reports star flares in the bloom (`PS_BreakableGlassNoCrack`) and purple speckles on glossy surfaces from such reads on RADV, and replaces the read with the lane's own value. That symptom is not reproduced here; the tests below are synthetic. Tests: - `emit::dpp_lane_branch_tests::pixel_dpp_fetching_a_lane_outside_exec_in_a_lane_branch_reads_its_register`: a pixel program narrows EXEC to the lanes of even x with `s_and_saveexec_b32` and `s_cbranch_execz`, changes v2 inside the branch, and moves the odd-x neighbour's v2 with `v_mov_b32_dpp quad_perm:[1,0,3,2] fi:1`. It is drawn as one triangle over the target and as two triangles sharing the diagonal (quads with helper lanes), on WARP and the RX 7900 XT. On main, and with `VICTORY_QUAD_WIDE=0`, 128 of 256 pixels are wrong on both (the card gives x + 5 where the console gives x + 1); with this change it passes on both. - Without FI, with and without bound_ctrl, on a local merge of this branch with #232: all three variants pass on WARP and the card in both shapes; with `VICTORY_QUAD_WIDE=0` they all fail. - victory-shader --lib through hw-run on the RX 7900 XT and WARP, on the revision before the review changes (which only narrow when a program is translated the second way): 238 passed, 2 failed, 4 ignored; the two failures are `emit::rect::tests` (`rectangles_are_drawn_whole`, `the_rectangle_stage_is_a_geometry_shader`), which fail on main too. On this revision a game was opened during the card run, so the suite ran on WARP only: 235 passed, 5 failed, 4 ignored; the failures are the same two rect tests and three `valu_tests` that ask for the hardware device and fail the same way on main in that mode (`compute_pipeline failed`). The new test ran on the card on this revision, before the game was opened. - Clippy with `-D warnings`, with and without `--all-features`, for victory-shader, victory-gpu and victory, and `cargo xtask policy` pass. rustfmt reports the same differences as on main. It merges without conflicts with my open PRs and test branches. Limits: - Only `s_cbranch_execz` and `s_cbranch_execnz` branches are taken by quads; a quad read under a VCC or SCC branch keeps the old translation. - How many of the title's pixel programs this reaches is not counted here; the `quad_wide` count in the log shows it in a run that translates them. - A widened program runs the region in every lane of a quad that has one lane in EXEC, with guards on its writes. The cost was not measured. - The second translation repeats the first before it widens, one extra translation per such program when it is not in the cache. - A quad read in a loop header with its own per-lane exit is not caught: the header counts as a block every lane runs. Generated with [Claude Code](https://claude.com/claude-code)
Zippp69 commented 2026-11-30 16:44:44 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Zippp69 on 2026-11-30T16:44:44Z.


Require at least one D3D12 readback in the regression test. Both backends can be skipped by Host::new, leaving failures empty. In that case the new test passes without drawing either triangle arrangement. Track whether a backend actually ran and require one readback, or report an explicit skip when the environment has no SM 6.6 device. This is a static test-coverage finding. Test

<!-- greyfinch-sync:DexNom/VIctory:comment:7285160698 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/244#issuecomment-7285160698). Originally posted by [Zippp69](https://github.com/Zippp69) on 2026-11-30T16:44:44Z. --- **Require at least one D3D12 readback in the regression test.** Both backends can be skipped by `Host::new`, leaving `failures` empty. In that case the new test passes without drawing either triangle arrangement. Track whether a backend actually ran and require one readback, or report an explicit skip when the environment has no SM 6.6 device. This is a static test-coverage finding. [Test](https://github.com/DexNom/VIctory/blob/bffebea55275cd5092d074265292981141de7d04/crates/victory-shader/src/emit/dpp_lane_branch_tests.rs#L53-L135)
murillojndem commented 2026-11-30 18:44:14 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by murillojndem on 2026-11-30T18:44:14Z.


Thanks, applied in 52332ea. left_lane_failures now counts the devices that drew and asserts that at least one did, the same check run_cases_on makes in valu_tests, so the test cannot pass without a readback.

With Host::new made to fail for both devices the test now fails with "no SM 6.6 device to draw on". Unchanged, it passes on WARP and on an RX 7900 XT, drawing on both. On the CI runner WARP opens: main's run_cases_on would otherwise fail its own ran > 0 check there, so the new assertion holds on CI too.

pixel_quad_broadcast_reads_helper_coordinates_at_shared_triangle_edge in main's helper_lane_tests.rs has the same loop without the count. This PR leaves it as main has it.

<!-- greyfinch-sync:DexNom/VIctory:comment:7288289312 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/244#issuecomment-7288289312). Originally posted by [murillojndem](https://github.com/murillojndem) on 2026-11-30T18:44:14Z. --- Thanks, applied in 52332ea. `left_lane_failures` now counts the devices that drew and asserts that at least one did, the same check `run_cases_on` makes in `valu_tests`, so the test cannot pass without a readback. With `Host::new` made to fail for both devices the test now fails with "no SM 6.6 device to draw on". Unchanged, it passes on WARP and on an RX 7900 XT, drawing on both. On the CI runner WARP opens: main's `run_cases_on` would otherwise fail its own `ran > 0` check there, so the new assertion holds on CI too. `pixel_quad_broadcast_reads_helper_coordinates_at_shared_triangle_edge` in main's `helper_lane_tests.rs` has the same loop without the count. This PR leaves it as main has it.
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/244:upstream-pr/244'
git switch 'upstream-pr/244'

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