shader: prove uniform compute image_load for v_readfirstlane_b32 in gfx2hlsl #2840

Closed
R0D4X wants to merge 1 commit from upstream-pr/2848 into main
R0D4X commented 2026-11-26 13:29:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0D4X on 2026-11-26T13:29:15Z.


Part of #2644 (T5). Refs #2274, #1723.

Root Cause / Motivation

In tools/startup/gfx2hlsl.py, compute image_load and image_load_mip did not propagate uniformity to their destination VGPRs even when reading through a uniform read-only descriptor at uniform coordinates in an entry block with known exec. Downstream v_readfirstlane_b32 reads of those loaded channels were therefore refused with v_readfirstlane_b32 requires a proven uniform source.

Summary

  • Translator (tools/startup/gfx2hlsl.py):
    • Track self.has_image_writes (image_store* / image_atomic*) on the stage in Stage.translate().
    • Add Stage.uniform_image_load_dsts() and hook it in Stage.one() for compute (cs) image_load and image_load_mip in the entry block with known exec when not self.has_image_writes:
      • Verifies supported dimensions (SQ_RSRC_IMG_2D, SQ_RSRC_IMG_2D_ARRAY, SQ_RSRC_IMG_3D), non-empty dmask, allowed modifiers (refusing d16), exact coordinate count with every coordinate register proven uniform, an 8-SGPR static read-only table/root descriptor with consecutive descriptor words and no varying SGPRs, and exact destination register count matching popcount(dmask).
      • Marks only the exact destination VGPRs written by dmask in self.uniform_v (and clears stale uniform_expr entries for them).
    • Stages containing any image_store* or image_atomic* (even to a different descriptor), varying coordinates, unknown exec, pixel stages, or registers outside dmask stay refused.
  • Unit & Refusal Controls (tests/startup_gfx2hlsl_readfirstlane_uniform_check.py):
    • Add 7 accepted cases (2D dmask:0xf lanes 0 and 3, partial dmask:0x5, 2D_ARRAY, 3D, image_load_mip, a16) and 6 refusal controls (varying X/mip coordinate, stage with image_store to another descriptor, register outside dmask:0x5, unknown exec, pixel stage).
  • GPU Readback & Mutation Control (tests/startup_compute_dispatch_texture_check.py):
    • Add uniform_image_load: dispatches a translated compute shader through startup_stream_consumer (dispatch-sampled-2x1) that loads texel (1, 0) (red 1.0) via image_load, broadcasts it with v_readfirstlane_b32 s20, v12, and XORs s20 into Case A's output (320/320 words match).
    • Coordinate-mutation control: changing the uniform X coordinate from 1 to 0 reads texel (0, 0) (red 0.0) and differs at all 288 written words.

Before / After

  • Before: v_readfirstlane_b32 reading a VGPR loaded by a uniform compute image_load / image_load_mip was refused as unproven.
  • After: Uniform compute image_load / image_load_mip in stages with no image writes marks its exact dmask destination VGPRs as uniform, translating and matching GPU readback on WARP and hardware while keeping unsafe forms refused.

Verification

  • Commit under test: 2799020e (based on 8c9f168f)
  • Environment: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0, DXC 1.9.2602.17, D3D12 debug layer enabled
    • WARP: Microsoft Basic Render Driver (1414:008c), driver 10.0.26100.9818
    • Hardware: NVIDIA GeForce RTX 5080 (10de:2c02), driver 32.0.16.2124

Commands and measured results (0 failures, 0 skips):

  • Pure-Python, neighbor, link & bidi checks (git diff --check, startup_gfx2hlsl_readfirstlane_uniform_check.py, startup_gfx2hlsl_readfirstlane_recompute_check.py, startup_gfx2hlsl_readfirstlane_load_recompute_check.py, startup_compute_readfirstlane_check.py, startup_translator_check.py, docs_links_check.py, bidi_controls_check.py): PASS
  • ctest --preset dev --no-tests=error -j 1 -R '^(startup_tools_lint|startup_gfx2hlsl_readfirstlane_uniform|startup_compute_dispatch_texture_)' -V: 4/4 passed (debug layer: enabled, no error message on WARP and RTX 5080)
  • ctest --preset release --no-tests=error -j 1 -R '^(startup_gfx2hlsl_readfirstlane_uniform|startup_compute_dispatch_texture_)' -V: 3/3 passed (14.30 sec, debug layer: enabled, no error message on WARP and RTX 5080)
  • Live self-mutations (drop_image_load_hook, drop_has_image_writes_guard, drop_uniform_coord_check): 3/3 caught (rc=1) and reverted cleanly.

Evidence Scope

  • Verified locally: pure-Python unit and refusal controls, neighbor/lint/link/bidi checks, dev and release DXC cs_6_0 GPU dispatches + coordinate-mutation control on WARP and RTX 5080 with D3D12 debug layer enabled, and tools/disasm_rdna2.py decode of all spliced instruction words.
  • Not covered: dispatches that write to another image descriptor in the same stage (deliberately kept refused until cross-descriptor non-aliasing is proven).

AI-assisted; source-built fixtures only.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6627705573 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2848). Originally posted by [R0D4X](https://github.com/R0D4X) on 2026-11-26T13:29:15Z. --- Part of #2644 (T5). Refs #2274, #1723. ## Root Cause / Motivation In `tools/startup/gfx2hlsl.py`, compute `image_load` and `image_load_mip` did not propagate uniformity to their destination VGPRs even when reading through a uniform read-only descriptor at uniform coordinates in an entry block with known `exec`. Downstream `v_readfirstlane_b32` reads of those loaded channels were therefore refused with `v_readfirstlane_b32 requires a proven uniform source`. ## Summary - **Translator (`tools/startup/gfx2hlsl.py`):** - Track `self.has_image_writes` (`image_store*` / `image_atomic*`) on the stage in `Stage.translate()`. - Add `Stage.uniform_image_load_dsts()` and hook it in `Stage.one()` for compute (`cs`) `image_load` and `image_load_mip` in the entry block with known `exec` when `not self.has_image_writes`: - Verifies supported dimensions (`SQ_RSRC_IMG_2D`, `SQ_RSRC_IMG_2D_ARRAY`, `SQ_RSRC_IMG_3D`), non-empty `dmask`, allowed modifiers (refusing `d16`), exact coordinate count with every coordinate register proven uniform, an 8-SGPR static read-only `table`/`root` descriptor with consecutive descriptor words and no varying SGPRs, and exact destination register count matching `popcount(dmask)`. - Marks only the exact destination VGPRs written by `dmask` in `self.uniform_v` (and clears stale `uniform_expr` entries for them). - Stages containing any `image_store*` or `image_atomic*` (even to a different descriptor), varying coordinates, unknown `exec`, pixel stages, or registers outside `dmask` stay refused. - **Unit & Refusal Controls (`tests/startup_gfx2hlsl_readfirstlane_uniform_check.py`):** - Add 7 accepted cases (`2D dmask:0xf` lanes 0 and 3, partial `dmask:0x5`, `2D_ARRAY`, `3D`, `image_load_mip`, `a16`) and 6 refusal controls (varying X/mip coordinate, stage with `image_store` to another descriptor, register outside `dmask:0x5`, unknown `exec`, pixel stage). - **GPU Readback & Mutation Control (`tests/startup_compute_dispatch_texture_check.py`):** - Add `uniform_image_load`: dispatches a translated compute shader through `startup_stream_consumer` (`dispatch-sampled-2x1`) that loads texel `(1, 0)` (red `1.0`) via `image_load`, broadcasts it with `v_readfirstlane_b32 s20, v12`, and XORs `s20` into Case A's output (320/320 words match). - Coordinate-mutation control: changing the uniform X coordinate from `1` to `0` reads texel `(0, 0)` (red `0.0`) and differs at all 288 written words. ## Before / After - **Before:** `v_readfirstlane_b32` reading a VGPR loaded by a uniform compute `image_load` / `image_load_mip` was refused as unproven. - **After:** Uniform compute `image_load` / `image_load_mip` in stages with no image writes marks its exact `dmask` destination VGPRs as uniform, translating and matching GPU readback on WARP and hardware while keeping unsafe forms refused. ## Verification - Commit under test: `2799020e` (based on `8c9f168f`) - Environment: Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0`, DXC `1.9.2602.17`, D3D12 debug layer enabled - WARP: `Microsoft Basic Render Driver` (`1414:008c`), driver `10.0.26100.9818` - Hardware: `NVIDIA GeForce RTX 5080` (`10de:2c02`), driver `32.0.16.2124` Commands and measured results (0 failures, 0 skips): - Pure-Python, neighbor, link & bidi checks (`git diff --check`, `startup_gfx2hlsl_readfirstlane_uniform_check.py`, `startup_gfx2hlsl_readfirstlane_recompute_check.py`, `startup_gfx2hlsl_readfirstlane_load_recompute_check.py`, `startup_compute_readfirstlane_check.py`, `startup_translator_check.py`, `docs_links_check.py`, `bidi_controls_check.py`): **PASS** - `ctest --preset dev --no-tests=error -j 1 -R '^(startup_tools_lint|startup_gfx2hlsl_readfirstlane_uniform|startup_compute_dispatch_texture_)' -V`: **4/4 passed** (`debug layer: enabled, no error message` on WARP and RTX 5080) - `ctest --preset release --no-tests=error -j 1 -R '^(startup_gfx2hlsl_readfirstlane_uniform|startup_compute_dispatch_texture_)' -V`: **3/3 passed** (`14.30 sec`, `debug layer: enabled, no error message` on WARP and RTX 5080) - Live self-mutations (`drop_image_load_hook`, `drop_has_image_writes_guard`, `drop_uniform_coord_check`): **3/3 caught (`rc=1`)** and reverted cleanly. ## Evidence Scope - Verified locally: pure-Python unit and refusal controls, neighbor/lint/link/bidi checks, `dev` and `release` DXC `cs_6_0` GPU dispatches + coordinate-mutation control on WARP and RTX 5080 with D3D12 debug layer enabled, and `tools/disasm_rdna2.py` decode of all spliced instruction words. - Not covered: dispatches that write to another image descriptor in the same stage (deliberately kept refused until cross-descriptor non-aliasing is proven). AI-assisted; source-built fixtures only.
upstream-sync closed this pull request 2026-11-26 14:00:32 +00:00
tedin7 commented 2026-11-26 14:00:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T13:31:35Z.


@R0D4X thank you for this, and for the careful test cases.

This PR covers the same slice as the earlier #2842 by @stan495: compute image_load at uniform coordinates proven uniform for v_readfirstlane_b32 (#2644 T5). Both change the same uniformity proof in tools/startup/gfx2hlsl.py for the same instruction pair. The project keeps the older PR when two cover the same case, so I am closing this one in favour of #2842, which is in review now.

Some of your cases look like they are not in #2842 yet: the 2D-array image_load, the partial dmask:0x5 load, and the lane-3 readback. They would be welcome as a follow-up on top of #2842 once it lands, or as a suggestion in the #2842 thread. If you think this PR covers something #2842 does not, say so here and it can be reopened.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7193472037 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2848#issuecomment-7193472037). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T13:31:35Z. --- @R0D4X thank you for this, and for the careful test cases. This PR covers the same slice as the earlier #2842 by @stan495: compute `image_load` at uniform coordinates proven uniform for `v_readfirstlane_b32` (#2644 T5). Both change the same uniformity proof in `tools/startup/gfx2hlsl.py` for the same instruction pair. The project keeps the older PR when two cover the same case, so I am closing this one in favour of #2842, which is in review now. Some of your cases look like they are not in #2842 yet: the 2D-array `image_load`, the partial `dmask:0x5` load, and the lane-3 readback. They would be welcome as a follow-up on top of #2842 once it lands, or as a suggestion in the #2842 thread. If you think this PR covers something #2842 does not, say so here and it can be reopened. AI-assisted; commands listed were executed locally.

Pull request closed

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!2840
No description provided.