shader: accept wave-uniform readfirstlane in pixel loops #3906

Manually merged
github merged 3 commits from github-bot/gh-3904 into gh-pr/3904/base 2026-12-03 04:46:33 +00:00 AGit
Owner

@⁠lukaslw-lab on GitHub · 2026-12-03 00:42 UTC · original
lukaslw-lab:shader/pixel-loop-readfirstlane → main · +181 −1 · 4 files · 3 commits · merged 2026-12-03 04:41 UTC

Change

The direct gfx1013 pixel compiler accepts v_readfirstlane_b32 inside a loop when the value is the same in every lane. Before, every such read was refused with graphics readfirstlane requires a wave-uniform reaching value. Inside a loop, a value's input dependencies are complete only after all blocks and back edges are emitted, and the uniform-value tracking skips loops.

  • The pixel path now records loop reads and checks them after finish_loop_dependencies(), as loop branch conditions already are. A read is accepted when its value depends on no stage input. Every loop branch has passed the varying check, so all lanes run the same trips.
  • Still refused: a value that depends on a pixel input, also one that becomes varying only on a later trip; a shader that uses a quad-coverage vote; a stage that binds a UAV.
  • Vertex loops and reads outside loops keep the existing rule.

Part of #3816 (row L1, claim). No overlap: the open pixel PRs that touch uniform_vector_values all keep !loop_dependencies.

Verification

Commit 03c365c04 (on 0b83a346b; the head fead4acd5 is the same change rebased without conflicts onto 2f2901cbd, rerun results will follow in a comment) on Windows 10 22H2 (build 19045), MSVC 19.52.37029, CMake 4.3.1, Python 3.13.7, DXC 1.9.2609.5. Draws need shader model 6.6, so both builds use OFFSCREEN_AGILITY_620_DIR (Agility SDK 1.620.2) and OFFSCREEN_WARP_DIR (WARP 1.0.22.0); D3D12 debug layer on. GPU: NVIDIA GeForce RTX 3080 Ti, driver 32.0.16.1047.

ctest --test-dir out\build\dev-agility --no-tests=error -R '^(native_pixel_(loop_|cmpx|compare_mask|dxil)|native_graphics_wqm_|native_direct_container$)'
100% tests passed, 0 tests failed out of 21
(same in out\build\release-agility: 21 of 21)

ctest --test-dir out\build\release-agility --no-tests=error -V -R '^native_pixel_loop_readfirstlane_'
translated: counter, joined-counter; refused: varying-source, varying-over-back-edge, written-in-a-lane-arm, stage-writes-a-uav
draw: counter: ok; draw: joined-counter: ok (warp and hardware)
100% tests passed, 0 tests failed out of 3

Negative control: with src/gfx1013_direct_graphics.inl from main (0b83a346b), native_pixel_loop_readfirstlane_controls fails at the first case: native compute +0xc: graphics readfirstlane requires a wave-uniform reaching value.

No capability skips. tests/bidi_controls_check.py and tests/docs_links_check.py pass. On the in-box Windows 10 runtime the draw tests of this family (this one, native_pixel_cmpx_if_else_warp, native_pixel_loop_entry_inputs_*) fail at PSO creation (Shader must be vs_6_2…), with and without this change.

Offline census: every distinct slot 86 pixel stage of the capture behind #3816 through compile_dxil gfx1013-mesh86-ps, main 72cc7c7f4 vs the same plus this change. Counts only, no shader bytes:

main this change
Translate 272 272
First refusal graphics readfirstlane requires a wave-uniform reaching value 332 10
First refusal unsupported wave64 scalar mask operation 0 322
Other first refusals unchanged unchanged

No stage gained or lost; this change clears the refusal and exposes the next one. In the stages I disassembled, that is s_cselect_b64 sN, exec, 0 inside the loop (row L2 on the #3816 board).

Evidence and follow-up

  • Fixture: source-built gfx1013 words in a synthetic pixel container (native_direct_container_check.patched_pixel), MIT. Two loops are drawn on an 8×2 target, each checked against its trip count; a wrong trip count is the mismatch control for each draw. Four refusals plus a positive control: the same loop with the UAV store but no readfirstlane translates.
  • Assumption: a value without stage-input dependencies is the same in all lanes once every loop branch is uniform. Loads from a view the stage may write break this, hence the UAV refusal.
  • Follow-up (open on #3816): L2, the s_cselect_b64 sN, exec, 0 select in a loop; L3, in a loop every phi at a CMPX-arm merge counts as varying, also for registers the arm does not write. That also blocks loop counters that cross such an arm.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC.

🤖 Generated with Claude Code

**@⁠lukaslw-lab** on GitHub · 2026-12-03 00:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3904) `lukaslw-lab:shader/pixel-loop-readfirstlane` → `main` · +181 −1 · 4 files · 3 commits · merged 2026-12-03 04:41 UTC ## Change The direct gfx1013 pixel compiler accepts `v_readfirstlane_b32` inside a loop when the value is the same in every lane. Before, every such read was refused with `graphics readfirstlane requires a wave-uniform reaching value`. Inside a loop, a value's input dependencies are complete only after all blocks and back edges are emitted, and the uniform-value tracking skips loops. - The pixel path now records loop reads and checks them after `finish_loop_dependencies()`, as loop branch conditions already are. A read is accepted when its value depends on no stage input. Every loop branch has passed the varying check, so all lanes run the same trips. - Still refused: a value that depends on a pixel input, also one that becomes varying only on a later trip; a shader that uses a quad-coverage vote; a stage that binds a UAV. - Vertex loops and reads outside loops keep the existing rule. Part of #3816 (row L1, [claim](https://git.gtahub.st/github/R0Y00--Xbox2Windows/issues/3816)). No overlap: the open pixel PRs that touch `uniform_vector_values` all keep `!loop_dependencies`. ## Verification Commit `03c365c04` (on `0b83a346b`; the head `fead4acd5` is the same change rebased without conflicts onto `2f2901cbd`, rerun results will follow in a comment) on Windows 10 22H2 (build 19045), MSVC 19.52.37029, CMake 4.3.1, Python 3.13.7, DXC 1.9.2609.5. Draws need shader model 6.6, so both builds use `OFFSCREEN_AGILITY_620_DIR` (Agility SDK 1.620.2) and `OFFSCREEN_WARP_DIR` (WARP 1.0.22.0); D3D12 debug layer on. GPU: NVIDIA GeForce RTX 3080 Ti, driver 32.0.16.1047. ctest --test-dir out\build\dev-agility --no-tests=error -R '^(native_pixel_(loop_|cmpx|compare_mask|dxil)|native_graphics_wqm_|native_direct_container$)' 100% tests passed, 0 tests failed out of 21 (same in out\build\release-agility: 21 of 21) ctest --test-dir out\build\release-agility --no-tests=error -V -R '^native_pixel_loop_readfirstlane_' translated: counter, joined-counter; refused: varying-source, varying-over-back-edge, written-in-a-lane-arm, stage-writes-a-uav draw: counter: ok; draw: joined-counter: ok (warp and hardware) 100% tests passed, 0 tests failed out of 3 Negative control: with `src/gfx1013_direct_graphics.inl` from `main` (`0b83a346b`), `native_pixel_loop_readfirstlane_controls` fails at the first case: `native compute +0xc: graphics readfirstlane requires a wave-uniform reaching value`. No capability skips. `tests/bidi_controls_check.py` and `tests/docs_links_check.py` pass. On the in-box Windows 10 runtime the draw tests of this family (this one, `native_pixel_cmpx_if_else_warp`, `native_pixel_loop_entry_inputs_*`) fail at PSO creation (`Shader must be vs_6_2…`), with and without this change. **Offline census**: every distinct slot 86 pixel stage of the capture behind #3816 through `compile_dxil gfx1013-mesh86-ps`, main `72cc7c7f4` vs the same plus this change. Counts only, no shader bytes: | | main | this change | |---|---:|---:| | Translate | 272 | 272 | | First refusal `graphics readfirstlane requires a wave-uniform reaching value` | 332 | 10 | | First refusal `unsupported wave64 scalar mask operation` | 0 | 322 | | Other first refusals | unchanged | unchanged | No stage gained or lost; this change clears the refusal and exposes the next one. In the stages I disassembled, that is `s_cselect_b64 sN, exec, 0` inside the loop (row L2 on the #3816 board). ## Evidence and follow-up - Fixture: source-built gfx1013 words in a synthetic pixel container (`native_direct_container_check.patched_pixel`), MIT. Two loops are drawn on an 8×2 target, each checked against its trip count; a wrong trip count is the mismatch control for each draw. Four refusals plus a positive control: the same loop with the UAV store but no readfirstlane translates. - Assumption: a value without stage-input dependencies is the same in all lanes once every loop branch is uniform. Loads from a view the stage may write break this, hence the UAV refusal. - Follow-up (open on #3816): L2, the `s_cselect_b64 sN, exec, 0` select in a loop; L3, in a loop every phi at a CMPX-arm merge counts as varying, also for registers the arm does not write. That also blocks loop counters that cross such an arm. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. _AI-assisted: prepared with Claude Code; the commands and results above were run on the author's PC._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A pixel loop that carries its counter over the back edge reads it with
v_readfirstlane_b32. Inside a loop the value's input dependencies are known
only after every block is emitted, so the read was always refused. Check
these reads after the loop dependencies are complete, as loop branch
conditions are. Refuse a quad-coverage vote and stages that bind a UAV.

Part of #3814.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-03 00:42:30 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-03 00:57 UTC · original

Rerun on the PR head fead4acd5 (main 2f2901cbd, which adds #3841 to the pixel path), same host and builds as in the description:

Check Result
ctest … -R '^(native_pixel_(loop_|cmpx|compare_mask|dxil|waterfall)|native_graphics_wqm_|native_direct_container$)', dev-agility 24 of 24 passed
same, release-agility 24 of 24 passed
pixel census, main 2f2901cbd vs this head 272 → 272 translate, 0 gained, 0 lost; the same 322 move to unsupported wave64 scalar mask operation

The 24 now include #3841's native_pixel_waterfall_w6_{controls,warp,hardware}; the waterfall stages are unchanged by this PR.

The failing Windows CI test, native_mesh_entry_registers_ir, is not from this change: this PR touches no mesh file, and it fails the same way locally at this head (AssertionError: ('wave-varying-branch', '')). #3840 added a case that expects a v_readfirstlane_b32 after a wave-varying SCC branch to be refused; #3896, merged shortly before, accepts that read at a converged full-EXEC join. Main at 2f2901cbd has both.

AI-assisted.

**@⁠lukaslw-lab** on GitHub · 2026-12-03 00:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3904#issuecomment-7363778028) Rerun on the PR head `fead4acd5` (main `2f2901cbd`, which adds #3841 to the pixel path), same host and builds as in the description: | Check | Result | |---|---| | `ctest … -R '^(native_pixel_(loop_\|cmpx\|compare_mask\|dxil\|waterfall)\|native_graphics_wqm_\|native_direct_container$)'`, dev-agility | 24 of 24 passed | | same, release-agility | 24 of 24 passed | | pixel census, main `2f2901cbd` vs this head | 272 → 272 translate, 0 gained, 0 lost; the same 322 move to `unsupported wave64 scalar mask operation` | The 24 now include #3841's `native_pixel_waterfall_w6_{controls,warp,hardware}`; the waterfall stages are unchanged by this PR. The failing Windows CI test, `native_mesh_entry_registers_ir`, is not from this change: this PR touches no mesh file, and it fails the same way locally at this head (`AssertionError: ('wave-varying-branch', '')`). #3840 added a case that expects a `v_readfirstlane_b32` after a wave-varying SCC branch to be refused; #3896, merged shortly before, accepts that read at a converged full-EXEC join. Main at `2f2901cbd` has both. AI-assisted.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 01:53 UTC · original · reviewed

Independently verified c5e1d5e4 with MSVC Debug on Windows 11 build 26300. ctest --preset dev --no-tests=error -j 1 -R "^native_pixel_loop_(readfirstlane|entry_inputs)_(controls|warp|hardware)$": 6/6 passed, no skips. WARP and RTX 4060 Laptop (616.56) drew both counter cases and the existing entry-input cases. Removing only the deferred dependency check admitted varying-source and failed the control, and the restored compiler passed. Main has now picked up #3847. The trial merge has one hunk at the variable declarations: retain both vcc_skip_joins/vcc_skip_saves/vcc_skip_restores from main and loop_first_lane_reads from this PR. Please rerun this selection after rebasing.

**@⁠R0Y00** on GitHub · 2026-12-03 01:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3904#pullrequestreview-6162350247) · **reviewed** Independently verified c5e1d5e4 with MSVC Debug on Windows 11 build 26300. ctest --preset dev --no-tests=error -j 1 -R "^native_pixel_loop_(readfirstlane|entry_inputs)_(controls|warp|hardware)$": 6/6 passed, no skips. WARP and RTX 4060 Laptop (616.56) drew both counter cases and the existing entry-input cases. Removing only the deferred dependency check admitted varying-source and failed the control, and the restored compiler passed. Main has now picked up #3847. The trial merge has one hunk at the variable declarations: retain both vcc_skip_joins/vcc_skip_saves/vcc_skip_restores from main and loop_first_lane_reads from this PR. Please rerun this selection after rebasing.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 01:56 UTC · original

I also trial-merged c5e1d5e4 with main at 06251bd5. Keeping both sets of declarations resolved the only conflict. MSVC Debug, ctest --preset dev --no-tests=error -j 1 -R "^(native_pixel_loop_(readfirstlane|entry_inputs)(controls|warp|hardware)|native_pixel_varying_vcc_branch(controls|warp|hardware))$": 9/9 on the combined tree, including WARP and RTX 4060 Laptop, zero skips. The trial was local.

**@⁠R0Y00** on GitHub · 2026-12-03 01:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3904#issuecomment-7364903990) I also trial-merged c5e1d5e4 with main at 06251bd5. Keeping both sets of declarations resolved the only conflict. MSVC Debug, ctest --preset dev --no-tests=error -j 1 -R "^(native_pixel_loop_(readfirstlane|entry_inputs)_(controls|warp|hardware)|native_pixel_varying_vcc_branch_(controls|warp|hardware))$": 9/9 on the combined tree, including WARP and RTX 4060 Laptop, zero skips. The trial was local.
github-bot changed target branch from main to gh-pr/3904/base 2026-12-03 04:45:54 +00:00
github manually merged commit f5a822a337 into gh-pr/3904/base 2026-12-03 04:46:33 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-03 04:29 UTC · original

Merged main (430552934) into the branch as f5a822a33, keeping both declaration sets at the conflict as you described; the PR diff against main is unchanged (4 files, +181/−1).

Build Your selection (native_pixel_loop_(readfirstlane|entry_inputs)_*, native_pixel_varying_vcc_branch_*), -j 1 Pixel group (native_pixel_(loop_|cmpx|compare_mask|dxil|waterfall|varying), native_graphics_wqm_, native_direct_container)
dev-agility (Debug) 9 of 9 passed 27 of 27 passed
release-agility 9 of 9 passed 27 of 27 passed

Windows 10 build 19045, WARP 1.0.22.0 and RTX 3080 Ti (32.0.16.1047), Agility SDK 1.620.2, no skips.

AI-assisted.

**@⁠lukaslw-lab** on GitHub · 2026-12-03 04:29 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3904#issuecomment-7367707217) Merged `main` (`430552934`) into the branch as `f5a822a33`, keeping both declaration sets at the conflict as you described; the PR diff against `main` is unchanged (4 files, +181/−1). | Build | Your selection (`native_pixel_loop_(readfirstlane\|entry_inputs)_*`, `native_pixel_varying_vcc_branch_*`), `-j 1` | Pixel group (`native_pixel_(loop_\|cmpx\|compare_mask\|dxil\|waterfall\|varying)`, `native_graphics_wqm_`, `native_direct_container`) | |---|---|---| | dev-agility (Debug) | 9 of 9 passed | 27 of 27 passed | | release-agility | 9 of 9 passed | 27 of 27 passed | Windows 10 build 19045, WARP 1.0.22.0 and RTX 3080 Ti (32.0.16.1047), Agility SDK 1.620.2, no skips. AI-assisted.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 04:36 UTC · original · approved these changes

Re-reviewed f5a822a3 with main 368a045d. The merge resolution retains both the existing varying-VCC declarations and the loop first-lane records. The current diff still applies the input-dependency, quad-vote and UAV refusal after loop dependencies settle. My earlier dependency-check mutation applies to the same guard, which is unchanged in this revision. MSVC Debug ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^native_pixel_(loop_(readfirstlane|entry_inputs)|varying_vcc_branch|masked_region_alu|exec_writelane_vcc)_(controls|warp|hardware)$' passed 15/15 on the combined tree, including #3842 and #3836. Windows build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, D3D12 debug layer enabled, no capability skips.

**@⁠R0Y00** on GitHub · 2026-12-03 04:36 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3904#pullrequestreview-6163758978) · **approved these changes** Re-reviewed `f5a822a3` with `main` `368a045d`. The merge resolution retains both the existing varying-VCC declarations and the loop first-lane records. The current diff still applies the input-dependency, quad-vote and UAV refusal after loop dependencies settle. My earlier dependency-check mutation applies to the same guard, which is unchanged in this revision. MSVC Debug `ctest --preset dev --no-tests=error -j 1 --output-on-failure -R '^native_pixel_(loop_(readfirstlane|entry_inputs)|varying_vcc_branch|masked_region_alu|exec_writelane_vcc)_(controls|warp|hardware)$'` passed 15/15 on the combined tree, including #3842 and #3836. Windows build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, D3D12 debug layer enabled, no capability skips.
This discussion has been locked. Commenting is limited to contributors.
No description provided.