shader: extend lane-local lowering in masked pixel regions (Part of #3814) #3840

Merged
timbot103 merged 4 commits from upstream-pr/3840 into main 2026-12-03 04:32:01 +00:00
timbot103 commented 2026-12-02 08:30:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T08:30:58Z.


Part of #3814.

Summary

Extends lane-local lowering inside flattened masked pixel regions (GraphicsMaskRegions SAVEEXEC and CMPX partitions) so additional read-only and lane-local operations lower with select-predicated VGPR writes instead of refusing with masked graphics region requires lane-local vector arithmetic:

  • Accepts s_clause and all three v_fma_mix* forms (v_fma_mix_f32, v_fma_mixlo_f16, v_fma_mixhi_f16).
  • Accepts fixed-binding explicit-LOD/gradient texture operations (image_load, image_load_mip, image_sample_d, image_sample_l, image_sample_lz, image_sample_c_lz) and fixed-table buffer_load_dword / buffer_load_format loads, guarding inactive-lane buffer addresses to element 0 and recording the minimum required view size on the binding.
  • Accepts arm-local v_cmp_* vcc, ... (consumed by v_cndmask_b32), fixed-offset bound-table s_buffer_load_dword*, and numeric scalar ALU (s_movk_i32, s_mov_b32, s_add_u32, s_lshl_b32, s_cselect_b32), expiring every arm-written SGPR/VCC/SCC at the complement and restore boundaries and refusing any overwrite of the saved EXEC pair.
  • Tightens helper_result_unobserved to require alu.graphics_predicate == coverage_predicate so narrower flattened arms never drop the incoming-value select.

Verification

  • ctest --preset pr --no-tests=error --output-on-failure -R '^native_pixel_masked_region_alu_controls$': passed (16 accepted DXIL cases + 24 refusal controls).
  • Debug (out/build/dev) and Release (out/build/release): 15/15 passed in each build with zero skips, including 14 exact 8×2 GPU readback draws on both WARP (10.0.26100.9818) and NVIDIA GeForce RTX 5080 (32.0.16.2140) on Windows 11 (26200.9974), plus offscreen_check --self-test in both builds. Negative controls differed on the exact 6 inactive pixels starting at (0,0).
  • tests/bidi_controls_check.py, tests/docs_links_check.py, and git diff --check origin/main..HEAD passed with zero new /W4 warnings on edited lines.
  • Opened as Draft under #3514's 5-PR ready cap; ready to promote once a review slot opens.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5602749167 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T08:30:58Z. --- Part of #3814. ### Summary Extends lane-local lowering inside flattened masked pixel regions (`GraphicsMaskRegions` SAVEEXEC and CMPX partitions) so additional read-only and lane-local operations lower with `select`-predicated VGPR writes instead of refusing with `masked graphics region requires lane-local vector arithmetic`: - Accepts `s_clause` and all three `v_fma_mix*` forms (`v_fma_mix_f32`, `v_fma_mixlo_f16`, `v_fma_mixhi_f16`). - Accepts fixed-binding explicit-LOD/gradient texture operations (`image_load`, `image_load_mip`, `image_sample_d`, `image_sample_l`, `image_sample_lz`, `image_sample_c_lz`) and fixed-table `buffer_load_dword` / `buffer_load_format` loads, guarding inactive-lane buffer addresses to element `0` and recording the minimum required view size on the binding. - Accepts arm-local `v_cmp_* vcc, ...` (consumed by `v_cndmask_b32`), fixed-offset bound-table `s_buffer_load_dword*`, and numeric scalar ALU (`s_movk_i32`, `s_mov_b32`, `s_add_u32`, `s_lshl_b32`, `s_cselect_b32`), expiring every arm-written SGPR/VCC/SCC at the complement and restore boundaries and refusing any overwrite of the saved EXEC pair. - Tightens `helper_result_unobserved` to require `alu.graphics_predicate == coverage_predicate` so narrower flattened arms never drop the incoming-value `select`. ### Verification - `ctest --preset pr --no-tests=error --output-on-failure -R '^native_pixel_masked_region_alu_controls$'`: passed (16 accepted DXIL cases + 24 refusal controls). - Debug (`out/build/dev`) and Release (`out/build/release`): 15/15 passed in each build with zero skips, including 14 exact 8×2 GPU readback draws on both WARP (`10.0.26100.9818`) and NVIDIA GeForce RTX 5080 (`32.0.16.2140`) on Windows 11 (`26200.9974`), plus `offscreen_check --self-test` in both builds. Negative controls differed on the exact 6 inactive pixels starting at `(0,0)`. - `tests/bidi_controls_check.py`, `tests/docs_links_check.py`, and `git diff --check origin/main..HEAD` passed with zero new `/W4` warnings on edited lines. - Opened as Draft under `#3514`'s 5-PR ready cap; ready to promote once a review slot opens.
lukaslw-lab commented 2026-12-02 08:34:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T08:34:38Z.

Review: APPROVED


Reviewed 5c1c21d0 (draft) by reading the diff; not built or run.

Verdict: approve. Each newly flattened operation is safe to run for inactive lanes, and every scalar it writes expires where a skipped wave could differ. No MUST.

  • SHOULD Run a before/after ps86 census on f365f125. Besides the 344 targeted stages, pixel CMPX arms now go through flattened_op (gfx1013_direct_graphics.inl:1389), so VCC written in an arm now expires at the restore, where it used to stay readable. Expiring it is right, because the guest's v_cmp leaves 0 for lanes outside the arm. But a stage that read that VCC after the arm would now be refused, and the census would show whether any did.
  • NIT This also conflicts with #3829 in gfx1013_direct_graphics.inl, which makes #3829 conflict with four open pixel PRs. Merging #3829 last would keep that to one rebase.
  • Checked, no finding:
    • Speculation (:1002): images need a fixed descriptor (< 16) and either a texel load or an explicit-LOD or gradient sample with a constant sampler, so nothing depends on derivatives or another lane. A buffer read clamps an inactive lane's address to element 0 (gfx1013_direct_compute.inl:1060, :1086), and the binding's required size grows to cover it.
    • Scalars: only s_movk/s_mov/s_add_u32/s_lshl_b32/s_cselect on numeric operands, and fixed-offset s_buffer_load on a fixed descriptor. A write to the saved EXEC pair is refused. expire_arms (:1058) expires the first arm's writes at the complement and both arms' writes at the restore, SCC and VCC included.
    • helper_result_unobserved (:2156) now also requires the predicate to be the coverage predicate, so a narrower arm keeps its select.
    • masked-scalar was replaced by masked-scalar-escape: the scalar write is now accepted, and its later use outside the arm is refused. That is the intended change, not a weaker test.

Tests: _controls (16 cases, 24 refusals) is in the pr filter. The 14 WARP and hardware draws ran only locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6147218039 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#pullrequestreview-6147218039). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T08:34:38Z. **Review:** APPROVED --- Reviewed `5c1c21d0` (draft) by reading the diff; not built or run. **Verdict: approve.** Each newly flattened operation is safe to run for inactive lanes, and every scalar it writes expires where a skipped wave could differ. No MUST. - **SHOULD** Run a before/after `ps86` census on `f365f125`. Besides the 344 targeted stages, pixel CMPX arms now go through `flattened_op` (`gfx1013_direct_graphics.inl:1389`), so VCC written in an arm now expires at the restore, where it used to stay readable. Expiring it is right, because the guest's `v_cmp` leaves 0 for lanes outside the arm. But a stage that read that VCC after the arm would now be refused, and the census would show whether any did. - **NIT** This also conflicts with #3829 in `gfx1013_direct_graphics.inl`, which makes #3829 conflict with four open pixel PRs. Merging #3829 last would keep that to one rebase. - Checked, no finding: - Speculation (`:1002`): images need a fixed descriptor (`< 16`) and either a texel load or an explicit-LOD or gradient sample with a constant sampler, so nothing depends on derivatives or another lane. A buffer read clamps an inactive lane's address to element 0 (`gfx1013_direct_compute.inl:1060`, `:1086`), and the binding's required size grows to cover it. - Scalars: only `s_movk`/`s_mov`/`s_add_u32`/`s_lshl_b32`/`s_cselect` on numeric operands, and fixed-offset `s_buffer_load` on a fixed descriptor. A write to the saved EXEC pair is refused. `expire_arms` (`:1058`) expires the first arm's writes at the complement and both arms' writes at the restore, SCC and VCC included. - `helper_result_unobserved` (`:2156`) now also requires the predicate to be the coverage predicate, so a narrower arm keeps its `select`. - `masked-scalar` was replaced by `masked-scalar-escape`: the scalar write is now accepted, and its later use outside the arm is refused. That is the intended change, not a weaker test. Tests: `_controls` (16 cases, 24 refusals) is in the `pr` filter. The 14 WARP and hardware draws ran only locally.
lukaslw-lab commented 2026-12-02 10:34:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-12-02T10:34:38Z.


Census follow-up for the SHOULD in my review: f365f125 + this PR alone, same capture and method as #3814 (6,436 distinct pixel stages). Counts only. None lost, no validation failures.

Build Pixel translated Moved off masked graphics region requires lane-local vector arithmetic
f365f125 272 —
f365f125 + #3840 272 0 of 211

In a 100-stage sample of the 211, the refused instruction inside the arm is:

Instruction Stages
s_load_dwordx4 (descriptor load from a table) 58
image_sample_l on such a descriptor 16
s_mov_b64 sN, exec 12
s_load_dwordx8 6
s_add_i32 6

flattened_op accepts only s_buffer_load_dword* (SMEM op 8–12) and images on a fixed descriptor (< 16). Most real arms load their T# or V# from a bound table with s_load_dwordx4/x8 first, so that load (and an image on the descriptor it yields) is what blocks them.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7342673273 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#issuecomment-7342673273). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-12-02T10:34:38Z. --- Census follow-up for the SHOULD in my review: `f365f125` + this PR alone, same capture and method as #3814 (6,436 distinct pixel stages). Counts only. **None lost**, no validation failures. | Build | Pixel translated | Moved off `masked graphics region requires lane-local vector arithmetic` | |---|---:|---:| | `f365f125` | 272 | — | | `f365f125` + #3840 | 272 | **0 of 211** | In a 100-stage sample of the 211, the refused instruction inside the arm is: | Instruction | Stages | |---|---:| | `s_load_dwordx4` (descriptor load from a table) | 58 | | `image_sample_l` on such a descriptor | 16 | | `s_mov_b64 sN, exec` | 12 | | `s_load_dwordx8` | 6 | | `s_add_i32` | 6 | `flattened_op` accepts only `s_buffer_load_dword*` (SMEM op 8–12) and images on a fixed descriptor (`< 16`). Most real arms load their T# or V# from a bound table with `s_load_dwordx4/x8` first, so that load (and an image on the descriptor it yields) is what blocks them.
timbot103 commented 2026-12-02 22:58:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-02T22:58:43Z.


Merged main (67862ee4) into this branch (5d494243); the reviewed commit 133dddf0 is unchanged. The merge carries this PR's coverage tracking into main's shared enter_exact helper.

06238646 fixes an interaction with #3829, which is now on main. An exact pixel lane kill updated the active predicate but left the tracked coverage predicate stale. A later masked write then tried to merge with an undefined VGPR, and all three native_pixel_alpha_kill_* tests failed at coverage-then-kill with unsupported pixel entry VGPR 3. The kill now updates both predicates.

Tests, Windows 11 26200 with RTX 5080 and WARP:

  • native_pixel_|native_graphics_|native_direct_container passed 39/39 in Debug and 39/39 in Release, including the alpha-kill tests on both adapters.
  • The PR preset passed 6/6.
  • A full Debug build of every target, including native_compute_pack_refusal_check, succeeded.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7361405427 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#issuecomment-7361405427). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-02T22:58:43Z. --- Merged `main` (`67862ee4`) into this branch (`5d494243`); the reviewed commit `133dddf0` is unchanged. The merge carries this PR's coverage tracking into main's shared `enter_exact` helper. `06238646` fixes an interaction with #3829, which is now on main. An exact pixel lane kill updated the active predicate but left the tracked coverage predicate stale. A later masked write then tried to merge with an undefined VGPR, and all three `native_pixel_alpha_kill_*` tests failed at `coverage-then-kill` with `unsupported pixel entry VGPR 3`. The kill now updates both predicates. Tests, Windows 11 26200 with RTX 5080 and WARP: - `native_pixel_|native_graphics_|native_direct_container` passed 39/39 in Debug and 39/39 in Release, including the alpha-kill tests on both adapters. - The PR preset passed 6/6. - A full Debug build of every target, including `native_compute_pack_refusal_check`, succeeded.
timbot103 commented 2026-12-03 01:14:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by timbot103 on 2026-12-03T01:14:50Z.


Marked Ready for review now that the previous batch (#3832, #3838, #3839, #3844, #3847) has merged. This keeps us within 5 non-draft PRs per #3514. The branch merges cleanly into current main, and CI is green at this head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7364123440 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#issuecomment-7364123440). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T01:14:50Z. --- Marked Ready for review now that the previous batch (#3832, #3838, #3839, #3844, #3847) has merged. This keeps us within 5 non-draft PRs per #3514. The branch merges cleanly into current main, and CI is green at this head.
R0Y00 commented 2026-12-03 01:43:05 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Independent MSVC Debug on 06238646, Windows 11 build 26300: ctest --preset dev --no-tests=error -j 1 -R "^native_pixel_masked_region_alu_(controls|warp|hardware)$" passed 3/3, no skips. WARP and RTX 4060 Laptop (616.56) both ran with the debug layer enabled. Each matched all 16 pixels in each of 14 draws, and every wrong-reference control differed on the six inactive pixels.

One guard from this revision is still unpinned. In src/gfx1013_direct_graphics.inl:2454 I replaced "return straight && alu.graphics_predicate == coverage_predicate &&" with "return straight &&". The build succeeded and both controls and WARP still passed. The negative pixel references catch a changed output, but that edit never changes the existing cases. Please add a focused exact-coverage case that enters a narrower lane arm and writes a fresh VGPR outside the entry inputs. Check that vector_write cannot treat that narrower predicate as full coverage, using the preserved result or the expected refusal at the later read as the oracle.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6162252876 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#pullrequestreview-6162252876). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T01:43:05Z. **Review:** COMMENTED --- Independent MSVC Debug on 06238646, Windows 11 build 26300: ctest --preset dev --no-tests=error -j 1 -R "^native_pixel_masked_region_alu_(controls|warp|hardware)$" passed 3/3, no skips. WARP and RTX 4060 Laptop (616.56) both ran with the debug layer enabled. Each matched all 16 pixels in each of 14 draws, and every wrong-reference control differed on the six inactive pixels. One guard from this revision is still unpinned. In src/gfx1013_direct_graphics.inl:2454 I replaced "return straight && alu.graphics_predicate == coverage_predicate &&" with "return straight &&". The build succeeded and both controls and WARP still passed. The negative pixel references catch a changed output, but that edit never changes the existing cases. Please add a focused exact-coverage case that enters a narrower lane arm and writes a fresh VGPR outside the entry inputs. Check that vector_write cannot treat that narrower predicate as full coverage, using the preserved result or the expected refusal at the later read as the oracle.
R0Y00 commented 2026-12-03 02:11:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-03T02:11:19Z.


A source-built case now distinguishes the guard on 06238646. Use the existing masked-region pixel fixture's SV_Position.x input and v2 color export, with this body before the export:

be8a047e befe0a7e be8c047e befe040a
d404006a 0001ff00 40400000 be94246a bf880001
7e0802f2 befe0414 7e040304

It saves entry coverage, enters WQM, returns to exact coverage, and then uses SAVEEXEC to narrow coverage to x >= 3. The narrowed arm writes fresh v4, restores EXEC, and reads v4 into the color output on the wider coverage. With the guard, native_pixel_ir_dump refuses at +0x24 with "unsupported pixel entry VGPR 4". Removing only the coverage_predicate equality compiles and emits storeOutput. Restoring the guard returns the refusal. Please use this as a refusal control in the existing fixture.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7365182243 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#issuecomment-7365182243). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T02:11:19Z. --- A source-built case now distinguishes the guard on 06238646. Use the existing masked-region pixel fixture's SV_Position.x input and v2 color export, with this body before the export: be8a047e befe0a7e be8c047e befe040a d404006a 0001ff00 40400000 be94246a bf880001 7e0802f2 befe0414 7e040304 It saves entry coverage, enters WQM, returns to exact coverage, and then uses SAVEEXEC to narrow coverage to x >= 3. The narrowed arm writes fresh v4, restores EXEC, and reads v4 into the color output on the wider coverage. With the guard, native_pixel_ir_dump refuses at +0x24 with "unsupported pixel entry VGPR 4". Removing only the coverage_predicate equality compiles and emits storeOutput. Restoring the guard returns the refusal. Please use this as a refusal control in the existing fixture.
timbot103 commented 2026-12-03 04:08:36 +00:00 (Migrated from github.com)

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


Thanks @R0Y00. I added your case as the refusal control exact-narrowed-fresh-write in 9dd33de5. It is built from the fixture's own helpers, and they encode exactly your 12 words.

  • With the guard: ctest --preset dev --no-tests=error -R '^native_pixel_masked_region_alu_controls$' passes, and the case is refused with native compute +0x24: unsupported pixel entry VGPR 4.
  • With alu.graphics_predicate == coverage_predicate && removed from gfx1013_direct_graphics.inl:2454: the case compiles, and the test fails with AssertionError: ('exact-narrowed-fresh-write', ...).
  • With the guard restored: native_pixel_masked_region_alu_(controls|warp|hardware) pass 3/3 on WARP and the RTX 5080. Windows 11 build 26200.9974, MSVC Debug.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7367310823 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#issuecomment-7367310823). Originally posted by [timbot103](https://github.com/timbot103) on 2026-12-03T04:08:36Z. --- Thanks @R0Y00. I added your case as the refusal control `exact-narrowed-fresh-write` in `9dd33de5`. It is built from the fixture's own helpers, and they encode exactly your 12 words. - With the guard: `ctest --preset dev --no-tests=error -R '^native_pixel_masked_region_alu_controls$'` passes, and the case is refused with `native compute +0x24: unsupported pixel entry VGPR 4`. - With `alu.graphics_predicate == coverage_predicate &&` removed from `gfx1013_direct_graphics.inl:2454`: the case compiles, and the test fails with `AssertionError: ('exact-narrowed-fresh-write', ...)`. - With the guard restored: `native_pixel_masked_region_alu_(controls|warp|hardware)` pass 3/3 on WARP and the RTX 5080. Windows 11 build 26200.9974, MSVC Debug.
R0Y00 commented 2026-12-03 04:31:57 +00:00 (Migrated from github.com)

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

Review: APPROVED


Re-reviewed 9dd33de5 with main 0bb85d8f. The new exact-narrowed-fresh-write fixture addresses my earlier review. It is refused at +0x24 because fresh v4 is undefined outside the narrower arm. Removing only alu.graphics_predicate == coverage_predicate in helper_result_unobserved made that same case compile and fail the control. The one-line edit was local and restored. MSVC Debug ctest --preset dev --no-tests=error -j 1 -V -R '^native_pixel_masked_region_alu_(controls|warp|hardware)$' passed 3/3 on Windows build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the debug layer enabled and no skips. Both adapters matched all 16 pixels per draw and detected the inactive-lane reference mutation.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6163719241 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3840#pullrequestreview-6163719241). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-03T04:31:57Z. **Review:** APPROVED --- Re-reviewed `9dd33de5` with `main` `0bb85d8f`. The new `exact-narrowed-fresh-write` fixture addresses my earlier review. It is refused at +0x24 because fresh v4 is undefined outside the narrower arm. Removing only `alu.graphics_predicate == coverage_predicate` in `helper_result_unobserved` made that same case compile and fail the control. The one-line edit was local and restored. MSVC Debug `ctest --preset dev --no-tests=error -j 1 -V -R '^native_pixel_masked_region_alu_(controls|warp|hardware)$'` passed 3/3 on Windows build 26300, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, with the debug layer enabled and no skips. Both adapters matched all 16 pixels per draw and detected the inactive-lane reference mutation.
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!3840
No description provided.