shader: lower image_gather4_c_lz in the direct C++ image path #2971

Manually merged
github merged 1 commit from gh-pr/2971/head into gh-pr/2971/base 2026-11-27 01:31:18 +00:00
Owner

@⁠legacy-code-archaeologist on GitHub · 2026-11-27 00:20 UTC · original
legacy-code-archaeologist:shader/direct-gather4-c-lz → cpp-migration · +169 −11 · 4 files · 1 commits · merged 2026-11-27 00:38 UTC

Change

image_io in src/gfx1013_direct_compute.inl now lowers image_gather4_c_lz (MIMG opcode 79) to DXIL textureGatherCmp (opcode 74). Before, the direct frontend refused it with direct image opcode or descriptor modifiers; the same program with image_sample_c_lz compiled. Refs #2969 (an image op of the instruction-coverage item in #2935). gfx2hlsl.py lowers this form as op_image_gather4_c_lz.

  • Form. 2D and 2D-array images with dmask 0x1. The address is the reference, then u and v (and the slice), as for the comparison samples of this path.
  • Call. Channel 0 (gather4_c compares the red component), with the reference as compare value.
  • Sampler. The constant comparison sampler under the existing sampler_index field checks, plus the base-level fix of image_gather4_lz: DXIL gathers have no LOD operand, so the static sampler is fixed to mip zero.
  • Refused by name. Other dmasks, cube and 3D images, image_gather4_c with implicit LOD, _c_l and _c_b. D16 is already refused at decode.
  • Wider than gfx2hlsl. gfx2hlsl.py takes this form only in pixel stages, on 2D images and with a bilinear comparison sampler. Here, compute stages, 2D arrays and the point filter of the existing comparison checks are accepted, as for the comparison samples of this path. A gather reads the same four texels whatever the filter (D3D11.3 gather rule; not measured on the console).

Verification

cpp-migration b260984f plus this commit, Windows 10.0.26100.9711, dev preset.

  • ctest --preset dev --no-tests=error -R '^native_gather_compare_warp$|^native_direct_container$|^native_graphics_comparison_pso_warp$': 3/3 passed.
    • native_gather_compare_warp creates the graphics pipeline on WARP (Microsoft Basic Render Driver 10.0.26100.9711). It runs cold and from the cache, with the comparison (COMPARISON_MIN_MAG_MIP_POINT, LESS) and regular point static samplers.
    • The same test checks the module with dxc -dumpbin. It has one textureGatherCmp with zero offsets and channel 0. Each float operand traces to its register: u from v1, v from v2, and the compare value from v0.
    • It checks the seven refusals by message, with an image_sample_c_lz control and a 2D array that compiles.
  • ctest --preset dev -R '^native_' -j 2: no new failures. The two failures are graphics PSO creations that return 0x80070057 on the NVIDIA Quadro M1000M (driver 32.0.15.7371) and failed the same way without this change in #2966's run: native_graphics_vertex_vcc_join_hardware and native_startup_request_cache_hardware. 11 tests skip (77) without SM 6.6 wave32, native_comparison_pso_warp included.
  • python -B tests/docs_links_check.py: ok.
  • Before the change, compile_dxil refused op 79 with the message above (e3670100). That run was a probe, not a revert of this commit.

Evidence and follow-up

All words are source-built. The programs reuse comparison_program() of tests/native_direct_container_check.py: clamp X/Y, point with TRUNC_COORD, LESS.

Not measured: the gather results are not read back on any device; the order of the four results is the DXIL order, the same assumption image_gather4 and image_gather4_lz already make here. The offset forms are not covered by the fixture.

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.

🤖 Generated with Claude Code

**@⁠legacy-code-archaeologist** on GitHub · 2026-11-27 00:20 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2971) `legacy-code-archaeologist:shader/direct-gather4-c-lz` → `cpp-migration` · +169 −11 · 4 files · 1 commits · merged 2026-11-27 00:38 UTC ## Change `image_io` in `src/gfx1013_direct_compute.inl` now lowers `image_gather4_c_lz` (MIMG opcode 79) to DXIL `textureGatherCmp` (opcode 74). Before, the direct frontend refused it with `direct image opcode or descriptor modifiers`; the same program with `image_sample_c_lz` compiled. Refs #2969 (an image op of the instruction-coverage item in #2935). `gfx2hlsl.py` lowers this form as `op_image_gather4_c_lz`. - **Form.** 2D and 2D-array images with `dmask` 0x1. The address is the reference, then u and v (and the slice), as for the comparison samples of this path. - **Call.** Channel 0 (gather4_c compares the red component), with the reference as compare value. - **Sampler.** The constant comparison sampler under the existing `sampler_index` field checks, plus the base-level fix of `image_gather4_lz`: DXIL gathers have no LOD operand, so the static sampler is fixed to mip zero. - **Refused by name.** Other dmasks, cube and 3D images, `image_gather4_c` with implicit LOD, `_c_l` and `_c_b`. D16 is already refused at decode. - **Wider than gfx2hlsl.** `gfx2hlsl.py` takes this form only in pixel stages, on 2D images and with a bilinear comparison sampler. Here, compute stages, 2D arrays and the point filter of the existing comparison checks are accepted, as for the comparison samples of this path. A gather reads the same four texels whatever the filter (D3D11.3 gather rule; not measured on the console). ## Verification `cpp-migration` `b260984f` plus this commit, Windows 10.0.26100.9711, `dev` preset. - `ctest --preset dev --no-tests=error -R '^native_gather_compare_warp$|^native_direct_container$|^native_graphics_comparison_pso_warp$'`: 3/3 passed. - `native_gather_compare_warp` creates the graphics pipeline on **WARP** (Microsoft Basic Render Driver 10.0.26100.9711). It runs cold and from the cache, with the comparison (`COMPARISON_MIN_MAG_MIP_POINT`, `LESS`) and regular point static samplers. - The same test checks the module with `dxc -dumpbin`. It has one `textureGatherCmp` with zero offsets and channel 0. Each float operand traces to its register: u from v1, v from v2, and the compare value from v0. - It checks the seven refusals by message, with an `image_sample_c_lz` control and a 2D array that compiles. - `ctest --preset dev -R '^native_' -j 2`: no new failures. The two failures are graphics PSO creations that return `0x80070057` on the NVIDIA Quadro M1000M (driver 32.0.15.7371) and failed the same way without this change in #2966's run: `native_graphics_vertex_vcc_join_hardware` and `native_startup_request_cache_hardware`. 11 tests skip (77) without SM 6.6 wave32, `native_comparison_pso_warp` included. - `python -B tests/docs_links_check.py`: ok. - Before the change, `compile_dxil` refused op 79 with the message above (`e3670100`). That run was a probe, not a revert of this commit. ## Evidence and follow-up All words are source-built. The programs reuse `comparison_program()` of `tests/native_direct_container_check.py`: clamp X/Y, point with TRUNC_COORD, LESS. **Not measured:** the gather results are not read back on any device; the order of the four results is the DXIL order, the same assumption `image_gather4` and `image_gather4_lz` already make here. The offset forms are not covered by the fixture. ## 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. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
image_io refused the comparison gather. It now lowers image_gather4_c_lz
(MIMG opcode 79) on 2D and 2D-array images with dmask 0x1 to DXIL
textureGatherCmp: channel 0, the reference (the first address dword) as
compare value, the constant comparison sampler under the existing field
checks, and the base-level sampler fix that image_gather4_lz uses.
Other dmasks, cube and 3D images, and the implicit-LOD, _c_l and _c_b
forms stay refused.

tests/native_gather_compare_check.py traces the module's operands to
their registers, checks seven refusals with an image_sample_c_lz
control, and creates the graphics pipeline of
native_graphics_comparison_pso_warp with the gather on WARP.

Refs #2969. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:31:17 +00:00
github manually merged commit 90424dbef9 into gh-pr/2971/base 2026-11-27 01:31:18 +00:00
Author
Owner

@⁠MasterDomino on GitHub · 2026-11-27 00:38 UTC · original · approved these changes

Review of head 90424dbe, tested merged onto cpp-migration 78a071ca (after #2964, #2966 and #2967). It auto-merges cleanly, and CI on the head is green. Approving and merging.

Code read:

  • Opcode 79 joins the gather and compare paths and lowers to textureGatherCmp.f32 (DXIL 74).
  • The arguments match the DXIL signature: u, v, then the slice for 2D arrays, offsets, channel 0, then the reference.
  • The static sampler gets the same fixed-to-mip-zero handling as image_gather4_lz (opcode 71).
  • 3D, other dmasks, and the _c, _c_l and _c_b forms stay refused by name.

Run: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010) plus WARP, release. ctest --preset release --no-tests=error -R '^native_' gives 51 tests, 50 passed and 1 skipped (77, native_comparison_pso_warp), including native_gather_compare_warp and native_graphics_comparison_pso_warp. The two graphics PSO failures from your Quadro M1000M run do not occur here, as I also noted on #2966.

Mutation here: passing 0.0 instead of the reference register fails native_gather_compare_warp on its argument check (['v1', 'v2', 'undef', 'undef', '0.000000e+00']). With it restored, it passes.

Gap, as you say: no device reads the gathered values back. The check pins the IR form and WARP pipeline creation, and the four-texel order is the same assumption image_gather4 and image_gather4_lz already make on this path. A readback through native_store_replay, with a depth texture and a reference that splits the four texels, would turn that assumption into a measurement for all three gathers. That would be a worthwhile follow-up.

AI-assisted; the commands above were run locally.

**@⁠MasterDomino** on GitHub · 2026-11-27 00:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2971#pullrequestreview-6082009150) · **approved these changes** Review of head `90424dbe`, tested merged onto `cpp-migration` `78a071ca` (after #2964, #2966 and #2967). It auto-merges cleanly, and CI on the head is green. Approving and merging. **Code read:** - Opcode 79 joins the gather and compare paths and lowers to `textureGatherCmp.f32` (DXIL 74). - The arguments match the DXIL signature: u, v, then the slice for 2D arrays, offsets, channel 0, then the reference. - The static sampler gets the same fixed-to-mip-zero handling as `image_gather4_lz` (opcode 71). - 3D, other dmasks, and the `_c`, `_c_l` and `_c_b` forms stay refused by name. **Run:** Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010) plus WARP, release. `ctest --preset release --no-tests=error -R '^native_'` gives 51 tests, 50 passed and 1 skipped (77, `native_comparison_pso_warp`), including `native_gather_compare_warp` and `native_graphics_comparison_pso_warp`. The two graphics PSO failures from your Quadro M1000M run do not occur here, as I also noted on #2966. **Mutation here:** passing `0.0` instead of the reference register fails `native_gather_compare_warp` on its argument check (`['v1', 'v2', 'undef', 'undef', '0.000000e+00']`). With it restored, it passes. **Gap, as you say:** no device reads the gathered values back. The check pins the IR form and WARP pipeline creation, and the four-texel order is the same assumption `image_gather4` and `image_gather4_lz` already make on this path. A readback through `native_store_replay`, with a depth texture and a reference that splits the four texels, would turn that assumption into a measurement for all three gathers. That would be a worthwhile follow-up. AI-assisted; the commands above were run locally.
This discussion has been locked. Commenting is limited to contributors.
No description provided.