startup: image_gather4 has no lowering and needs view/mip state the translator does not model #1795

Open
opened 2026-11-24 18:52:45 +00:00 by triggered02 · 8 comments
triggered02 commented 2026-11-24 18:52:45 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T18:52:45Z.


Census group at 2 refused shaders (#870). This issue records why it is not a straight port and what it needs, so a future slice starts from the constraint rather than from a misleadingly small patch.

Problem

image_gather4_lz v[8:11], v[4:5], s[16:23], s[40:43] dmask:0x1 dim:SQ_RSRC_IMG_2D
image_gather4_lz v[4:7], v[2:3], s[24:31], s[16:19] dmask:0x1 dim:SQ_RSRC_IMG_2D
-> REFUSED: image_gather4_lz

Stage.image() lowers image_sample, _lz, _l, image_load and image_load_mip; gathers are not handled at all.

Why it is not a port

tools/pixel_aot.py does lower gathers, but through machinery gfx2hlsl.py does not have:

  • A declared view with a mip count. image.lowering refuses an implicit-LOD gather unless the view has exactly one visible mip, and an _l gather unless the LOD is a known integer inside the view. gfx2hlsl has no notion of the image's mip count or declared view at all — it lowers from the descriptor registers only.
  • Sampler validation for gather. pixel_aot.py checks the sampler's filter and mip state against the gather mode (check_gather_sampler). gfx2hlsl binds samplers from constant words without a gather-specific check.
  • A trace of known coordinate values. The AOT path reads the coordinates' provenance (uv.x, alu…, params…) and the known LOD bits; gfx2hlsl translates instructions individually and has no such tracking.
  • A resource table for gather views (GATHER_RESOURCES, gather_compare_resources), which is generated per draw by the AOT path.

Deliverable

Lower image_gather4(_c)(_lz|_l) on 2D images, in a slice that first establishes how the translator learns the view's mip count:

  • either a declared mip count reaches Stage from the pipeline state (the way pixel AOT gets it) and the lowering refuses when it is unknown, or
  • the lowering is limited to the form the census shows and refuses everything else by name, with the mip-count question recorded honestly.

Then:

  • a one-hot dmask selects the component (1→red, 2→green, 4→blue, 8→alpha), as pixel_aot.py does; anything else is refused;
  • Texture2D.Gather* semantics: four texels returned into four consecutive destination registers;
  • a ctest that starts from synthetic encoded instructions, decodes, then translates, and pins both the accepted form and each refusal (multi-bit mask, unknown mip count, non-2D dimension);
  • docs/experiments.md records what is lowered and what is refused.

Done when

  • The census forms lower, or the issue is closed with the mip-count question answered and the forms refused by name with that reason.
  • No gather is lowered by guessing a level or a filter.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589078878 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T18:52:45Z. --- Census group at **2** refused shaders (#870). This issue records why it is not a straight port and what it needs, so a future slice starts from the constraint rather than from a misleadingly small patch. ## Problem ``` image_gather4_lz v[8:11], v[4:5], s[16:23], s[40:43] dmask:0x1 dim:SQ_RSRC_IMG_2D image_gather4_lz v[4:7], v[2:3], s[24:31], s[16:19] dmask:0x1 dim:SQ_RSRC_IMG_2D -> REFUSED: image_gather4_lz ``` `Stage.image()` lowers `image_sample`, `_lz`, `_l`, `image_load` and `image_load_mip`; gathers are not handled at all. ## Why it is not a port `tools/pixel_aot.py` does lower gathers, but through machinery `gfx2hlsl.py` does not have: - **A declared view with a mip count.** `image.lowering` refuses an implicit-LOD gather unless the view has exactly one visible mip, and an `_l` gather unless the LOD is a known integer inside the view. `gfx2hlsl` has no notion of the image's mip count or declared view at all — it lowers from the descriptor registers only. - **Sampler validation for gather.** `pixel_aot.py` checks the sampler's filter and mip state against the gather mode (`check_gather_sampler`). `gfx2hlsl` binds samplers from constant words without a gather-specific check. - **A trace of known coordinate values.** The AOT path reads the coordinates' provenance (`uv.x`, `alu…`, `params…`) and the known LOD bits; `gfx2hlsl` translates instructions individually and has no such tracking. - **A resource table for gather views** (`GATHER_RESOURCES`, `gather_compare_resources`), which is generated per draw by the AOT path. ## Deliverable Lower `image_gather4(_c)(_lz|_l)` on 2D images, in a slice that first establishes how the translator learns the view's mip count: - either a declared mip count reaches `Stage` from the pipeline state (the way pixel AOT gets it) and the lowering refuses when it is unknown, or - the lowering is limited to the form the census shows and refuses everything else by name, with the mip-count question recorded honestly. Then: - a one-hot `dmask` selects the component (`1`→red, `2`→green, `4`→blue, `8`→alpha), as `pixel_aot.py` does; anything else is refused; - `Texture2D.Gather*` semantics: four texels returned into four consecutive destination registers; - a ctest that starts from **synthetic** encoded instructions, decodes, then translates, and pins both the accepted form and each refusal (multi-bit mask, unknown mip count, non-2D dimension); - `docs/experiments.md` records what is lowered and what is refused. ## Done when - The census forms lower, or the issue is closed with the mip-count question answered and the forms refused by name with that reason. - No gather is lowered by guessing a level or a filter. AI-assisted (Claude Code).
avt0m4t48 commented 2026-11-24 21:27:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by avt0m4t48 on 2026-11-24T21:15:09Z.


I'll take the source-built 2D image_gather4_lz slice. RDNA2 documents the _lz form as fixed mip zero, and the Direct3D functional spec defines native gather at mip zero of the bound view. I'll check that against the startup SRV path, require a validated constant sampler, and verify all four gather outputs with encoded instructions and a synthetic texture. The implicit, explicit-LOD, and compare variants remain separate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7144681341 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7144681341). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-24T21:15:09Z. --- I'll take the source-built 2D `image_gather4_lz` slice. RDNA2 documents the `_lz` form as fixed mip zero, and the Direct3D functional spec defines native gather at mip zero of the bound view. I'll check that against the startup SRV path, require a validated constant sampler, and verify all four gather outputs with encoded instructions and a synthetic texture. The implicit, explicit-LOD, and compare variants remain separate.
R0Y00 commented 2026-11-24 22:01:06 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T21:56:30Z.


The fixed-mip 2D slice #1927 is on main. On the exact candidate, the nine source-built 64-pixel cases matched on WARP and RTX 4060 Laptop (32.0.16.1656), with zero debug warnings or errors. Each adapter detected the changed tap at pixel (0,0). A view starting at resource mip 1 matched its view-relative mip zero. The implicit, explicit-LOD, comparison and offset gathers remain open here.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7145592075 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7145592075). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T21:56:30Z. --- The fixed-mip 2D slice #1927 is on main. On the exact candidate, the nine source-built 64-pixel cases matched on WARP and RTX 4060 Laptop (32.0.16.1656), with zero debug warnings or errors. Each adapter detected the changed tap at pixel (0,0). A view starting at resource mip 1 matched its view-relative mip zero. The implicit, explicit-LOD, comparison and offset gathers remain open here.
ArnabSaga commented 2026-11-25 05:04:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ArnabSaga on 2026-11-25T04:27:31Z.


I'd like to take the source-built 2D image_gather4_c_lz slice. I'll verify the RDNA2 comparison-gather semantics against the existing fixed-mip implementation, including comparison-sampler compatibility, view-relative mip zero, and destination ordering. I'll add encoded instruction fixtures and synthetic texture tests with exact readback on WARP and physical hardware. Implicit-LOD, explicit-LOD, and offset gathers will remain separate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7152860500 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7152860500). Originally posted by [ArnabSaga](https://github.com/ArnabSaga) on 2026-11-25T04:27:31Z. --- I'd like to take the source-built 2D image_gather4_c_lz slice. I'll verify the RDNA2 comparison-gather semantics against the existing fixed-mip implementation, including comparison-sampler compatibility, view-relative mip zero, and destination ordering. I'll add encoded instruction fixtures and synthetic texture tests with exact readback on WARP and physical hardware. Implicit-LOD, explicit-LOD, and offset gathers will remain separate.
triggered02 commented 2026-11-26 04:04:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-26T03:21:52Z.


Status check on current main (7967c5af), because this issue is narrower than when it was filed:

Implemented now: image_gather4_lz, image_gather4_l, and image_gather4_c_lz all have handlers in ools/startup/gfx2hlsl.py (op_image_gather4_lz, op_image_gather4_l, op_image_gather4_c_lz), with the sampler addressing-mode contract documented at the top of the file ("gather4 only uses the addressing modes of the sampler"). ests/compute_gather4_l_check.py covers the explicit-LOD compute form.

Still refused: the plain image_gather4 (no explicit LOD) form � there is no op_image_gather4 handler, so the un-suffixed gather still refuses. That is not a missing table entry: an implicit-LOD gather needs the derivative/quad state the startup translator does not model, which is the same blocker the issue names.

Smallest next step if someone wants it: either (a) refuse it with the specific reason (needs the sample's implicit LOD) instead of a bare mnemonic, so the census separates it from missing handlers, or (b) lower it only where the caller proves a constant LOD from its own state. (a) is a small, self-contained change with a synthetic fixture; (b) needs the same view/mip-state proof this issue describes. Keeping this open for the un-suffixed form only.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181651722 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7181651722). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-26T03:21:52Z. --- Status check on current main (7967c5af), because this issue is narrower than when it was filed: Implemented now: image_gather4_lz, image_gather4_l, and image_gather4_c_lz all have handlers in ools/startup/gfx2hlsl.py (op_image_gather4_lz, op_image_gather4_l, op_image_gather4_c_lz), with the sampler addressing-mode contract documented at the top of the file ("gather4 only uses the addressing modes of the sampler"). ests/compute_gather4_l_check.py covers the explicit-LOD compute form. Still refused: the plain image_gather4 (no explicit LOD) form � there is no op_image_gather4 handler, so the un-suffixed gather still refuses. That is not a missing table entry: an implicit-LOD gather needs the derivative/quad state the startup translator does not model, which is the same blocker the issue names. Smallest next step if someone wants it: either (a) refuse it with the specific reason (needs the sample's implicit LOD) instead of a bare mnemonic, so the census separates it from missing handlers, or (b) lower it only where the caller proves a constant LOD from its own state. (a) is a small, self-contained change with a synthetic fixture; (b) needs the same view/mip-state proof this issue describes. Keeping this open for the un-suffixed form only.
R0Y00 commented 2026-11-26 05:02:28 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T04:47:54Z.


The diagnostic slice is on main in #2735 (434aa90d). Plain image_gather4 now reports that it needs the guest implicit mip level. Fixed-mip readbacks and a wrong-mip control still pass their checks. Keep this issue open for a mip-selection proof. A useful source-built comparison would give each mip distinct four-tap values, use a nonzero view base mip, and compare two cases where known derivatives select different levels. For the first implementation, the fixed-view path is suitable only where the caller can prove the guest-selected mip. Reusing the visible first mip without that proof would change the result.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182911333 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7182911333). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T04:47:54Z. --- The diagnostic slice is on main in #2735 (434aa90d). Plain image_gather4 now reports that it needs the guest implicit mip level. Fixed-mip readbacks and a wrong-mip control still pass their checks. Keep this issue open for a mip-selection proof. A useful source-built comparison would give each mip distinct four-tap values, use a nonzero view base mip, and compare two cases where known derivatives select different levels. For the first implementation, the fixed-view path is suitable only where the caller can prove the guest-selected mip. Reusing the visible first mip without that proof would change the result.
RonLogic commented 2026-11-27 13:21:58 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T13:21:58Z.


I’ll take the source-built mip-selection comparison suggested above. I’ll hold the sampled UV fixed at the checked pixel, vary the quad derivatives to select two known levels through an SRV starting at resource mip 1, and compare all four taps on WARP and RTX 4070. I’ll compare the selected-level path with the existing mip-zero gather as a negative control. This is a Windows differential fixture. The plain guest opcode will keep its refusal until its mip choice is proved.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7219388780 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7219388780). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-27T13:21:58Z. --- I’ll take the source-built mip-selection comparison suggested above. I’ll hold the sampled UV fixed at the checked pixel, vary the quad derivatives to select two known levels through an SRV starting at resource mip 1, and compare all four taps on WARP and RTX 4070. I’ll compare the selected-level path with the existing mip-zero gather as a negative control. This is a Windows differential fixture. The plain guest opcode will keep its refusal until its mip choice is proved.
RonLogic commented 2026-11-27 13:29:00 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by RonLogic on 2026-11-27T13:29:00Z.


The Windows differential is in #3065. With the two-level SRV based at resource mip 1, changing only the derivative picked different sets of four taps on both WARP and RTX 4070. The mip-zero substitution disagreed at all four taps in the second case. The fixture does not decide the native guest opcode’s mip selection; the remaining evidence is an RDNA comparison on matching inputs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7219531543 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7219531543). Originally posted by [RonLogic](https://github.com/RonLogic) on 2026-11-27T13:29:00Z. --- The Windows differential is in #3065. With the two-level SRV based at resource mip 1, changing only the derivative picked different sets of four taps on both WARP and RTX 4070. The mip-zero substitution disagreed at all four taps in the second case. The fixture does not decide the native guest opcode’s mip selection; the remaining evidence is an RDNA comparison on matching inputs.
R0Y00 commented 2026-11-27 15:14:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T15:14:46Z.


The Windows differential #3065 and direct explicit-LOD lowering #3068 are now on main. On WARP and RTX the two-level view produced both expected four-tap patterns, and the first-visible-mip control failed all four taps in the second case. For the native explicit opcode, Pixel passed on WARP and RTX, and four RTX Compute lanes chose resource mips 1, 2, 2, 2. WARP Compute returned a wave32 capability skip. This issue stays open for an RDNA readback of the plain guest opcode's implicit mip choice on matching inputs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7221814321 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/1802#issuecomment-7221814321). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T15:14:46Z. --- The Windows differential #3065 and direct explicit-LOD lowering #3068 are now on `main`. On WARP and RTX the two-level view produced both expected four-tap patterns, and the first-visible-mip control failed all four taps in the second case. For the native explicit opcode, Pixel passed on WARP and RTX, and four RTX Compute lanes chose resource mips 1, 2, 2, 2. WARP Compute returned a wave32 capability skip. This issue stays open for an RDNA readback of the plain guest opcode's implicit mip choice on matching inputs.
Sign in to join this conversation.
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#1795
No description provided.