shader: lower mip-zero 2D gathers in the startup compute translator #2274

Merged
RavenCurseBurg merged 2 commits from upstream-pr/2282 into main 2026-11-25 10:07:44 +00:00
RavenCurseBurg commented 2026-11-25 09:47:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T09:47:48Z.


Refs #2274, item A, image_gather4_lz in the startup compute translator.

The compute stage now lowers a 2D mip-zero gather through the existing pixel-stage sampler and one-hot component checks. It verifies that all eight image descriptor words still identify one fixed table view before emitting the SRV and constant sampler bindings. A raw UAV records the four taps in the synthetic compute fixture. The runtime slot-67 binding work in #2274 B remains separate.

Verification

Windows 11 build 26100.9711, source 59a05959. The four 84-byte gfx1013 programs were assembled from the included source with LLVM 15.0.7. All four matched their pinned encodings. The original translator rejected the program with image_gather4_lz requires a pixel stage and four operands.

  • python -B tests/startup_compute_gather_lz_check.py passed for all four components. It also checked malformed masks, a missing or out-of-profile sampler, a missing, truncated or overwritten image descriptor, and using the same slot for the texture and raw output.
  • python -B tests/startup_compute_gather_lz_check.py --dispatch <dxc> <offscreen_check> warp and the same command with hardware passed on WARP 10.0.26100.9711 and a GeForce RTX 4060, driver 32.0.15.9579. Each backend passed five 320-word comparisons. The renderer was built from upstream ed96f498. This local run reported debug_layer=unavailable.
  • The expected first word of the green gather through a view starting at mip 1 was 3f1020e2. Dropping the gather produced 00000000, taking red produced 3f1020e0, binding mip 0 produced 3f0041e2, and swapping the outer taps produced 3f1010e2. Both devices produced exactly 4, 4, 4 and 2 mismatches.
  • A separate synthetic request through python -B tools/startup/gfx2hlsl.py --pending <cache> emitted the same CS HLSL and manifest as the fixture. Its compiled DXIL passed the mip-1 readback on both devices.
  • python -B tools/run_checks_parallel.py tests/startup_compute_gather_lz_check.py tests/startup_image_gather_lz_check.py tests/startup_gfx2hlsl_compute_check.py tests/startup_compute_translate_check.py tests/startup_gfx2hlsl_loop_constants_check.py tests/startup_image_gather_c_lz_check.py tests/docs_links_check.py passed 7/7. git diff --check passed.

To run the registered tests, build offscreen_check and run ctest --preset release --no-tests=error -R '^startup_compute_gather_lz(_warp|_hardware)?$' -V.

The assembly, texels and readback references are source-built repository fixtures under the MIT license. AI-assisted with Codex.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6601675802 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2282). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T09:47:48Z. --- Refs #2274, item A, `image_gather4_lz` in the startup compute translator. The compute stage now lowers a 2D mip-zero gather through the existing pixel-stage sampler and one-hot component checks. It verifies that all eight image descriptor words still identify one fixed table view before emitting the SRV and constant sampler bindings. A raw UAV records the four taps in the synthetic compute fixture. The runtime slot-67 binding work in #2274 B remains separate. ### Verification Windows 11 build 26100.9711, source `59a05959`. The four 84-byte gfx1013 programs were assembled from the included source with LLVM 15.0.7. All four matched their pinned encodings. The original translator rejected the program with `image_gather4_lz requires a pixel stage and four operands`. - `python -B tests/startup_compute_gather_lz_check.py` passed for all four components. It also checked malformed masks, a missing or out-of-profile sampler, a missing, truncated or overwritten image descriptor, and using the same slot for the texture and raw output. - `python -B tests/startup_compute_gather_lz_check.py --dispatch <dxc> <offscreen_check> warp` and the same command with `hardware` passed on WARP 10.0.26100.9711 and a GeForce RTX 4060, driver 32.0.15.9579. Each backend passed five 320-word comparisons. The renderer was built from [upstream ed96f498](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45585679164). This local run reported `debug_layer=unavailable`. - The expected first word of the green gather through a view starting at mip 1 was `3f1020e2`. Dropping the gather produced `00000000`, taking red produced `3f1020e0`, binding mip 0 produced `3f0041e2`, and swapping the outer taps produced `3f1010e2`. Both devices produced exactly 4, 4, 4 and 2 mismatches. - A separate synthetic request through `python -B tools/startup/gfx2hlsl.py --pending <cache>` emitted the same CS HLSL and manifest as the fixture. Its compiled DXIL passed the mip-1 readback on both devices. - `python -B tools/run_checks_parallel.py tests/startup_compute_gather_lz_check.py tests/startup_image_gather_lz_check.py tests/startup_gfx2hlsl_compute_check.py tests/startup_compute_translate_check.py tests/startup_gfx2hlsl_loop_constants_check.py tests/startup_image_gather_c_lz_check.py tests/docs_links_check.py` passed 7/7. `git diff --check` passed. To run the registered tests, build `offscreen_check` and run `ctest --preset release --no-tests=error -R '^startup_compute_gather_lz(_warp|_hardware)?$' -V`. The assembly, texels and readback references are source-built repository fixtures under the MIT license. AI-assisted with Codex.
tedin7 commented 2026-11-25 10:05:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T09:51:41Z.

Review: COMMENTED


Review of head 59a0595939bf0f0e4ceac077dbed856c5684ae09 (comment only, no approval).

Overlap check: #2258 (merged) is the compute_store_aot image_gather4_l path and #2250 (merged) is the pixel-stage image_gather4_c_lz path. This PR only widens op_image_gather4_lz in tools/startup/gfx2hlsl.py to the compute stage. It does not touch either. No duplicate. The CS descriptor guard is a copy of the buffer-store guard (tools/startup/gfx2hlsl.py around line 2140), so the two stay consistent.

Scope: 6 files, +164/-2. Title is neutral and the PR is MERGEABLE. At review time, the Linux and gfx1013 fixture jobs were green and "Build and test on Windows" was still pending.

Commands run locally (Linux):

  • python3 -B tests/startup_compute_gather_lz_check.py passed: "Four compute gather channels, manifest bindings and refusal controls passed".
  • python3 -B tests/startup_image_gather_lz_check.py passed. This is the sibling pixel gather, so no regression.
  • python3 -B tests/startup_gfx2hlsl_compute_check.py passed.
  • python3 tests/docs_links_check.py passed: 18 files, 436 links.
  • python3 tests/bidi_controls_check.py passed.
  • git diff --check origin/main...HEAD passed.

Logic: The lowering matches the existing pixel-stage GatherX at mip zero. The _lz and D3D Gather both read the bound view's first mip. The CS-only guard requires a fixed table descriptor, 8 consecutive words, the same symbol per word, and not modified. That is the right condition because the manifest binds the original table view. I found no P1.

Mutations (each reverted with git checkout -- .):

  1. I removed or desc_key(word) in self.pipe.modified from the CS guard. The test still passed.
  2. I replaced first[3] % 8 with False, which drops the alignment refusal. The test still passed.

Findings

  • P1: none.
  • P2 (tools/startup/gfx2hlsl.py:2589): No fixture exercises the pipe.modified branch. The "overwritten descriptor" control only reaches the self.sym mismatch, so a regression in the modified-descriptor refusal would go unnoticed. Suggest one control where the descriptor words are modified through the path at line 1658 and the gather is then refused.
  • P2 (tools/startup/gfx2hlsl.py:2583): No control reaches the first[3] % 8 refusal, which is a table offset that is not a multiple of 8. Suggest one control with a misaligned table offset.
  • Nit: the refusal text now reads "pixel or compute stage". The sibling image_gather4_c_lz still says "pixel stage". That is correct today, but keep it in mind if it is widened later.

Windows: I did not run x2w_pipe.py win2025. The PR body already reports WARP and hardware dispatch results on Win2025 for these exact fixtures, and the Windows CI job is pending. The Linux checks above cover the Python-side logic.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055298752 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2282#pullrequestreview-6055298752). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T09:51:41Z. **Review:** COMMENTED --- Review of head `59a0595939bf0f0e4ceac077dbed856c5684ae09` (comment only, no approval). **Overlap check:** #2258 (merged) is the `compute_store_aot` `image_gather4_l` path and #2250 (merged) is the pixel-stage `image_gather4_c_lz` path. This PR only widens `op_image_gather4_lz` in `tools/startup/gfx2hlsl.py` to the compute stage. It does not touch either. No duplicate. The CS descriptor guard is a copy of the buffer-store guard (`tools/startup/gfx2hlsl.py` around line 2140), so the two stay consistent. **Scope:** 6 files, +164/-2. Title is neutral and the PR is MERGEABLE. At review time, the Linux and gfx1013 fixture jobs were green and "Build and test on Windows" was still pending. **Commands run locally (Linux):** - `python3 -B tests/startup_compute_gather_lz_check.py` passed: "Four compute gather channels, manifest bindings and refusal controls passed". - `python3 -B tests/startup_image_gather_lz_check.py` passed. This is the sibling pixel gather, so no regression. - `python3 -B tests/startup_gfx2hlsl_compute_check.py` passed. - `python3 tests/docs_links_check.py` passed: 18 files, 436 links. - `python3 tests/bidi_controls_check.py` passed. - `git diff --check origin/main...HEAD` passed. **Logic:** The lowering matches the existing pixel-stage `GatherX` at mip zero. The `_lz` and D3D Gather both read the bound view's first mip. The CS-only guard requires a fixed table descriptor, 8 consecutive words, the same symbol per word, and not modified. That is the right condition because the manifest binds the original table view. I found no P1. **Mutations** (each reverted with `git checkout -- .`): 1. I removed `or desc_key(word) in self.pipe.modified` from the CS guard. The test **still passed**. 2. I replaced `first[3] % 8` with `False`, which drops the alignment refusal. The test **still passed**. **Findings** - P1: none. - P2 (`tools/startup/gfx2hlsl.py:2589`): No fixture exercises the `pipe.modified` branch. The "overwritten descriptor" control only reaches the `self.sym` mismatch, so a regression in the modified-descriptor refusal would go unnoticed. Suggest one control where the descriptor words are modified through the path at line 1658 and the gather is then refused. - P2 (`tools/startup/gfx2hlsl.py:2583`): No control reaches the `first[3] % 8` refusal, which is a table offset that is not a multiple of 8. Suggest one control with a misaligned table offset. - Nit: the refusal text now reads "pixel or compute stage". The sibling `image_gather4_c_lz` still says "pixel stage". That is correct today, but keep it in mind if it is widened later. **Windows:** I did not run `x2w_pipe.py win2025`. The PR body already reports WARP and hardware dispatch results on Win2025 for these exact fixtures, and the Windows CI job is pending. The Linux checks above cover the Python-side logic. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-25 10:05:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:01:08Z.

Review: COMMENTED


Re-review of head 8d382c4cc3f02db0f4595fb338edf4ff10f265eb (comment only, no approval).

Delta since 59a0595: one commit, test-only (tests/startup_compute_gather_lz_check.py, +28). No change to tools/startup/gfx2hlsl.py.

Previous P2s: both resolved.

  • Modified-descriptor refusal (tools/startup/gfx2hlsl.py:2589): the new check_image_provenance control re-loads the table slot, then ORs into word 41 or 46, and expects modified image descriptor. A positive control (duplicate load, no change) still produces srv 0 tex2d table 1 0.
  • Misaligned table offset (tools/startup/gfx2hlsl.py:2585): a s[12:27] load makes the gather start at word 4 and straddle two descriptors, which is refused with fixed table image descriptor. The s[8:23] positive control lands on byte offset 32 and the manifest shows srv 0 tex2d table 1 32 and uav 0 table 1 64.

CI: Linux checks, gfx1013 fixtures and Windows build/test are all pass. PR is MERGEABLE and not a draft. Title is neutral.

Commands run locally (Linux):

  • python3 -B tests/startup_compute_gather_lz_check.py passed.
  • python3 -B tests/startup_image_gather_lz_check.py passed.
  • python3 -B tests/startup_gfx2hlsl_compute_check.py passed.
  • python3 -B tests/docs_links_check.py passed (18 files, 436 links).
  • python3 -B tests/bidi_controls_check.py passed.
  • git diff --check origin/main...HEAD passed.

Mutations (each reverted with git checkout -- .):

  1. Removed or desc_key(word) in self.pipe.modified at line 2589: the test now fails with accepted, expected a refusal naming 'modified image descriptor'. Killed.
  2. Removed or first[3] % 8 at line 2585: the test now fails with accepted, expected a refusal naming 'fixed table image descriptor'. Killed.

Findings

  • P1: none.
  • P2: none.
  • Nit: llvm-mc is not on my PATH, so the byte-for-byte assemble(...) == words cross-check inside encoded() was skipped here. The tests run on the hex words alone. CI assembles them, and that job is green.

Windows: I did not run x2w_pipe.py win2025. This head changes only a Python test, and the shader code is unchanged since the head the PR body reports on Win2025. The Windows CI job is green.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055445336 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2282#pullrequestreview-6055445336). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:01:08Z. **Review:** COMMENTED --- Re-review of head `8d382c4cc3f02db0f4595fb338edf4ff10f265eb` (comment only, no approval). **Delta since `59a0595`:** one commit, test-only (`tests/startup_compute_gather_lz_check.py`, +28). No change to `tools/startup/gfx2hlsl.py`. **Previous P2s: both resolved.** - Modified-descriptor refusal (`tools/startup/gfx2hlsl.py:2589`): the new `check_image_provenance` control re-loads the table slot, then ORs into word 41 or 46, and expects `modified image descriptor`. A positive control (duplicate load, no change) still produces `srv 0 tex2d table 1 0`. - Misaligned table offset (`tools/startup/gfx2hlsl.py:2585`): a `s[12:27]` load makes the gather start at word 4 and straddle two descriptors, which is refused with `fixed table image descriptor`. The `s[8:23]` positive control lands on byte offset 32 and the manifest shows `srv 0 tex2d table 1 32` and `uav 0 table 1 64`. **CI:** Linux checks, gfx1013 fixtures and Windows build/test are all pass. PR is MERGEABLE and not a draft. Title is neutral. **Commands run locally (Linux):** - `python3 -B tests/startup_compute_gather_lz_check.py` passed. - `python3 -B tests/startup_image_gather_lz_check.py` passed. - `python3 -B tests/startup_gfx2hlsl_compute_check.py` passed. - `python3 -B tests/docs_links_check.py` passed (18 files, 436 links). - `python3 -B tests/bidi_controls_check.py` passed. - `git diff --check origin/main...HEAD` passed. **Mutations** (each reverted with `git checkout -- .`): 1. Removed `or desc_key(word) in self.pipe.modified` at line 2589: the test now fails with `accepted, expected a refusal naming 'modified image descriptor'`. Killed. 2. Removed `or first[3] % 8` at line 2585: the test now fails with `accepted, expected a refusal naming 'fixed table image descriptor'`. Killed. **Findings** - P1: none. - P2: none. - Nit: `llvm-mc` is not on my PATH, so the byte-for-byte `assemble(...) == words` cross-check inside `encoded()` was skipped here. The tests run on the hex words alone. CI assembles them, and that job is green. **Windows:** I did not run `x2w_pipe.py win2025`. This head changes only a Python test, and the shader code is unchanged since the head the PR body reports on Win2025. The Windows CI job is green. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 10:05:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T09:58:38Z.


Addressed both P2s in 8d382c4c. The original gather registers remain byte-for-byte intact while a separate load of the same table slot is changed through s_or_b32. The controls cover both four-word halves of the image. Removing only the pipe.modified check now accepts a case that must refuse.

The alignment control uses a 16-dword load and puts the gather's first SGPR at loaded word 4, across the boundary between the two image descriptors. With the alignment predicate removed this incorrectly translates. Its positive counterpart starts at word 8, and the manifest identifies the SRV at table byte offset 32 and the output at byte offset 64. I ran both suggested mutations independently and confirmed the new tests fail for their respective reasons. The LLVM CI path reassembles the added instructions.

The exact-head Windows CTest run for 59a05959 also completed. The normal control and WARP test passed with D3D12 debug enabled and zero errors and warnings. A GeForce RTX 4060 repeated all five positive readbacks and four negative controls locally; this machine reported the debug layer unavailable.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7159056084 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2282#issuecomment-7159056084). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T09:58:38Z. --- Addressed both P2s in `8d382c4c`. The original gather registers remain byte-for-byte intact while a separate load of the same table slot is changed through `s_or_b32`. The controls cover both four-word halves of the image. Removing only the `pipe.modified` check now accepts a case that must refuse. The alignment control uses a 16-dword load and puts the gather's first SGPR at loaded word 4, across the boundary between the two image descriptors. With the alignment predicate removed this incorrectly translates. Its positive counterpart starts at word 8, and the manifest identifies the SRV at table byte offset 32 and the output at byte offset 64. I ran both suggested mutations independently and confirmed the new tests fail for their respective reasons. The LLVM CI path reassembles the added instructions. The [exact-head Windows CTest run for 59a05959](https://github.com/RavenCurseBurg/Xbox2Windows/actions/runs/45589081631/job/139118194507) also completed. The normal control and WARP test passed with D3D12 debug enabled and zero errors and warnings. A GeForce RTX 4060 repeated all five positive readbacks and four negative controls locally; this machine reported the debug layer unavailable.
upstream-sync closed this pull request 2026-11-25 11:02:17 +00:00
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!2274
No description provided.