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

Merged
lukaslw-lab merged 3 commits from upstream-pr/3904 into main 2026-12-03 04:41:56 +00:00
lukaslw-lab commented 2026-12-03 00:42:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-03T00:42:05Z.


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 #3814 (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 #3814 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 #3814 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 #3814): 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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5617422652 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3904). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-03T00:42:05Z. --- ## 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 #3814 (row L1, [claim](https://github.com/R0Y00/Xbox2Windows/issues/3814#issuecomment-7362014266)). 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 #3814 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 #3814 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 #3814): 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)
lukaslw-lab commented 2026-12-03 00:57:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-03T00:57:03Z.


Rerun on the PR head fead4acd5 (main 2f2901cbd, which adds #3839 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 #3839'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', '')). #3838 added a case that expects a v_readfirstlane_b32 after a wave-varying SCC branch to be refused; #3894, merged shortly before, accepts that read at a converged full-EXEC join. Main at 2f2901cbd has both.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7363778028 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3904#issuecomment-7363778028). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-03T00:57:03Z. --- Rerun on the PR head `fead4acd5` (main `2f2901cbd`, which adds #3839 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 #3839'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', '')`). #3838 added a case that expects a `v_readfirstlane_b32` after a wave-varying SCC branch to be refused; #3894, merged shortly before, accepts that read at a converged full-EXEC join. Main at `2f2901cbd` has both. AI-assisted.
R0Y00 commented 2026-12-03 01:53:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T01:53:13Z.

Review: COMMENTED


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 #3845. 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6162350247 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3904#pullrequestreview-6162350247). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T01:53:13Z. **Review:** COMMENTED --- 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 #3845. 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 commented 2026-12-03 01:56:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T01:56:22Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7364903990 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3904#issuecomment-7364903990). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T01:56:22Z. --- 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.
lukaslw-lab commented 2026-12-03 04:29:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-03T04:29:37Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7367707217 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3904#issuecomment-7367707217). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-03T04:29:37Z. --- 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.
R0Y00 commented 2026-12-03 04:36:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T04:36:45Z.

Review: APPROVED


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 #3840 and #3834. Windows build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, D3D12 debug layer enabled, no capability skips.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6163758978 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3904#pullrequestreview-6163758978). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T04:36:45Z. **Review:** APPROVED --- 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 #3840 and #3834. Windows build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, D3D12 debug layer enabled, no capability skips.
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
R0Y00/Xbox2Windows!3904
No description provided.