compute: lower the MIMG gather4 variants #3606

Open
github-bot wants to merge 5 commits from github-bot/gh-3604 into main AGit
Owner

@⁠lambirou on GitHub · 2026-11-30 12:56 UTC · original
lambirou:compute/gather4-variants → main · +716 −48 · 6 files · 5 commits · open

Part of the MIMG slice (P6).

This extends the compute gather4 lowering from image_gather4_l to the twelve remaining forms: image_gather4_b, _b_cl, _b_cl_o, _b_o, _c_b, _c_b_cl, _c_b_cl_o, _c_b_o, _c_cl, _c_cl_o, _cl and _cl_o. The bias (b), depth compare (c), LOD clamp (cl) and texel offset (o) suffixes follow the RDNA 2 operand layout and reuse the existing GATHER_HLSL view, sampler and DMASK guards; the compare path uses the same depth-reference and result rules as the neighbouring sample-c forms.

Refusals: dynamic coordinates, offsets, bias or clamp values across lanes; a bias outside [-16, 15.99]; a clamp outside the view; a compare reference outside [0, 1]; a non-red DMASK for a comparison gather; a non-one-hot DMASK; a missing or moving sampler; and the existing view/sampler descriptor rules. The _CL mapping follows image_sample_cl (minimum LOD), as the neighbouring sample path does.

Tests

  • compute_store_aot_gfx1013_gather4_variants_warp and _hardware pass: 16 cases, 320 words compared per dispatch, 0 mismatch on WARP and the AMD Radeon RX 9060 XT (driver 32.0.32029.2010).
  • Four mutants each mismatch as predicted: bias ignored, LOD clamp dropped, offset axes swapped and the compare inverted.
  • compute_store_aot_gfx1013_gather4_l still passes on both adapters; pixel_aot_sample_clamp (4/4) and startup_image_sample_c_border (3/3) also pass.
  • form_coverage_check.py pins exactly the twelve forms and keeps the sample CL/O and BVH forms uncovered; docs_links_check.py passes.
  • Expected full table after the merge: 1,632/1,968 gfx1013 and 1,586/1,863 gfx1030 (measured baseline 1,620/1,574 plus these twelve).

Limits

The desktop model loads texels at a computed mip; it does not prove the console's native derived LOD. Coordinates, offset, bias and clamp must be uniform literals across lanes. The _CL meaning is not settled by a native run (LLVM/Mesa use minimum LOD, the ISA table describes an upper bound). No llvm-mc round-trip or console measurement was run.

AI-assisted.

**@⁠lambirou** on GitHub · 2026-11-30 12:56 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3604) `lambirou:compute/gather4-variants` → `main` · +716 −48 · 6 files · 5 commits · open Part of the MIMG slice (P6). This extends the compute `gather4` lowering from `image_gather4_l` to the twelve remaining forms: `image_gather4_b`, `_b_cl`, `_b_cl_o`, `_b_o`, `_c_b`, `_c_b_cl`, `_c_b_cl_o`, `_c_b_o`, `_c_cl`, `_c_cl_o`, `_cl` and `_cl_o`. The bias (b), depth compare (c), LOD clamp (cl) and texel offset (o) suffixes follow the RDNA 2 operand layout and reuse the existing `GATHER_HLSL` view, sampler and DMASK guards; the compare path uses the same depth-reference and result rules as the neighbouring sample-c forms. Refusals: dynamic coordinates, offsets, bias or clamp values across lanes; a bias outside [-16, 15.99]; a clamp outside the view; a compare reference outside [0, 1]; a non-red DMASK for a comparison gather; a non-one-hot DMASK; a missing or moving sampler; and the existing view/sampler descriptor rules. The `_CL` mapping follows `image_sample_cl` (minimum LOD), as the neighbouring sample path does. ## Tests - `compute_store_aot_gfx1013_gather4_variants_warp` and `_hardware` pass: 16 cases, 320 words compared per dispatch, 0 mismatch on WARP and the AMD Radeon RX 9060 XT (driver 32.0.32029.2010). - Four mutants each mismatch as predicted: bias ignored, LOD clamp dropped, offset axes swapped and the compare inverted. - `compute_store_aot_gfx1013_gather4_l` still passes on both adapters; `pixel_aot_sample_clamp` (4/4) and `startup_image_sample_c_border` (3/3) also pass. - `form_coverage_check.py` pins exactly the twelve forms and keeps the sample CL/O and BVH forms uncovered; `docs_links_check.py` passes. - Expected full table after the merge: **1,632/1,968** gfx1013 and **1,586/1,863** gfx1030 (measured baseline 1,620/1,574 plus these twelve). ## Limits The desktop model loads texels at a computed mip; it does not prove the console's native derived LOD. Coordinates, offset, bias and clamp must be uniform literals across lanes. The `_CL` meaning is not settled by a native run (LLVM/Mesa use minimum LOD, the ISA table describes an upper bound). No `llvm-mc` round-trip or console measurement was run. AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 12:57:23 +00:00
Author
Owner

@⁠lukaslw-lab on GitHub · 2026-12-01 02:22 UTC · original · requested changes

Reviewed 46d53f76 by reading the diff; not built or run.

Verdict: changes requested. The bias forms select a mip that zero derivatives cannot produce, and the fixture cannot see it because its reference uses the same formula.

  • MUST lod = max(bias, clamp) (compute_store_aot.py, GATHER_VARIANTS branch; docstring "the derivative LOD is zero") treats zero derivatives as LOD 0. Lane-uniform coordinates give a zero derivative, and the implicit LOD is then log2(0) = −∞. A finite bias leaves it at −∞, so the hardware clamps to the sampler's MIN_LOD (0 under check_gather_sampler), and only the _cl minimum can raise it. The pixel path leaves this to the hardware through SampleBias (pixel_aot.py:5881). Under that rule, the bias-1 rows (b_lod1_green, b_o_lod1, c_b_less, c_b_o_lod1) read mip 0, not 1; b_cl_bias_rounds (1.5, clamp 0) reads mip 0, not 2; and b_cl_bias_above_clamp (2, clamp 1) reads mip 1, not 2. Either refuse a bias that rounds above the clamp, or use level = round(clamp or 0). A desktop SampleBias run with uniform UV would settle the rule for RDNA 2 compute.
  • Context for the choice: a local cache of 4,352 slot 67 compute requests, decoded with disasm_rdna2 up to the last s_endpgm, contains none of the twelve forms. Seven decodes have reserved bits set, so they are data, not instructions. Refusing the bias forms costs nothing today.
  • SHOULD The [0, 1] reference guard applies only to a literal. A run-time reference (any is_word) passes unchecked into image_gather_compare_2d, so a value the literal path refuses translates when it is computed. Either refuse non-literal references or emit the same check.
  • SHOULD The fixture's gather4_variant_level repeats the translator's formula, so the 320-word match and the "bias ignored" mutant prove consistency, not the native LOD. Add a row whose expected mip comes from a desktop sampler instead.
  • Checked, no finding: operand order (offset, bias, reference, U, V, clamp); comparison direction reference OP texel with red-only DMASK; the offset helper adds the offset after floor, then clamps to the edge; the _l path is unchanged.

Tests: CI ran the lowering controls (Linux compute_store_check.py). It did not run compute_store_aot_gfx1013_gather4_variants_warp/_hardware, which are not in the pr filter.

**@⁠lukaslw-lab** on GitHub · 2026-12-01 02:22 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3604#pullrequestreview-6124055669) · **requested changes** Reviewed `46d53f76` by reading the diff; not built or run. **Verdict: changes requested.** The bias forms select a mip that zero derivatives cannot produce, and the fixture cannot see it because its reference uses the same formula. - **MUST** `lod = max(bias, clamp)` (`compute_store_aot.py`, `GATHER_VARIANTS` branch; docstring "the derivative LOD is zero") treats zero derivatives as LOD 0. Lane-uniform coordinates give a zero derivative, and the implicit LOD is then log2(0) = −∞. A finite bias leaves it at −∞, so the hardware clamps to the sampler's MIN_LOD (0 under `check_gather_sampler`), and only the `_cl` minimum can raise it. The pixel path leaves this to the hardware through `SampleBias` (`pixel_aot.py:5881`). Under that rule, the bias-1 rows (`b_lod1_green`, `b_o_lod1`, `c_b_less`, `c_b_o_lod1`) read mip 0, not 1; `b_cl_bias_rounds` (1.5, clamp 0) reads mip 0, not 2; and `b_cl_bias_above_clamp` (2, clamp 1) reads mip 1, not 2. Either refuse a bias that rounds above the clamp, or use `level = round(clamp or 0)`. A desktop `SampleBias` run with uniform UV would settle the rule for RDNA 2 compute. - Context for the choice: a local cache of 4,352 slot 67 compute requests, decoded with `disasm_rdna2` up to the last `s_endpgm`, contains none of the twelve forms. Seven decodes have reserved bits set, so they are data, not instructions. Refusing the bias forms costs nothing today. - **SHOULD** The [0, 1] reference guard applies only to a literal. A run-time `reference` (any `is_word`) passes unchecked into `image_gather_compare_2d`, so a value the literal path refuses translates when it is computed. Either refuse non-literal references or emit the same check. - **SHOULD** The fixture's `gather4_variant_level` repeats the translator's formula, so the 320-word match and the "bias ignored" mutant prove consistency, not the native LOD. Add a row whose expected mip comes from a desktop sampler instead. - Checked, no finding: operand order (offset, bias, reference, U, V, clamp); comparison direction `reference OP texel` with red-only DMASK; the offset helper adds the offset after `floor`, then clamps to the edge; the `_l` path is unchanged. Tests: CI ran the lowering controls (Linux `compute_store_check.py`). It did not run `compute_store_aot_gfx1013_gather4_variants_warp`/`_hardware`, which are not in the `pr` filter.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-02 19:09 UTC · original · reviewed

I checked the current 3f3f4479 after the branch update. The gather path still derives lod with max(bias, clamp), so the earlier zero-derivative concern remains. #3616 and #3619 carry this change as a dependency. Please fix or explicitly refuse the unsupported bias case in #3606 first and add a mip-distinguishing control, independent of that LOD expression. The current trial merge into 521318af also conflicts in tests/form_coverage_check.py; please keep both main's coverage and the gather entries.

**@⁠R0Y00** on GitHub · 2026-12-02 19:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3604#pullrequestreview-6157128375) · **reviewed** I checked the current `3f3f4479` after the branch update. The gather path still derives `lod` with `max(bias, clamp)`, so the earlier zero-derivative concern remains. #3616 and #3619 carry this change as a dependency. Please fix or explicitly refuse the unsupported bias case in #3606 first and add a mip-distinguishing control, independent of that LOD expression. The current trial merge into `521318af` also conflicts in `tests/form_coverage_check.py`; please keep both main's coverage and the gather entries.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 06:52 UTC · original · requested changes

The offset helpers in tools/compute_store_aot.py clamp scaled to [-1, dimensions] before adding the signed texel offset. The PR's CPU model and the helper comment apply the offset before clamping the final taps. These differ for finite coordinates outside the texture when a positive offset moves the footprint back toward the view.

Reproduced on this exact head, with the existing gather4 variant fixture's source-built texture and CPU reference. Create image_gather4_b_o with bias=0, offset=(2, 0), then set tx=-3 after constructing the case. Both WARP and RTX 4060 Laptop disagree on 256/320 words; word 0 is 3f001020, expected 3f001000. Likewise image_gather4_c_b_o with bias=0, offset=(0, 2), reference=0.5, compare=1, ty=-3 disagrees on 128/320 words on both adapters; word 0 is 3f800000, expected zero. With floor(scaled)=-3, the offset gives -1; clamping early makes it +1. Adding the offset before the range-safety clamp in the generated HLSL returned 320/320 in both cases on both backends. Please preserve the offset before edge clamping in both helpers and add these returning-from-outside cases to the fixture.

The existing gather4_l and gather4_variants WARP/hardware CTests passed 4/4, including all four existing variant mutations, with no skips. Windows 11 build 26300, WARP 10.0.26100.9818, RTX 4060 Laptop 32.0.16.1656, debug layer enabled.

**@⁠R0Y00** on GitHub · 2026-12-03 06:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3604#pullrequestreview-6164975173) · **requested changes** The offset helpers in tools/compute_store_aot.py clamp scaled to [-1, dimensions] before adding the signed texel offset. The PR's CPU model and the helper comment apply the offset before clamping the final taps. These differ for finite coordinates outside the texture when a positive offset moves the footprint back toward the view. Reproduced on this exact head, with the existing gather4 variant fixture's source-built texture and CPU reference. Create image_gather4_b_o with bias=0, offset=(2, 0), then set tx=-3 after constructing the case. Both WARP and RTX 4060 Laptop disagree on 256/320 words; word 0 is 3f001020, expected 3f001000. Likewise image_gather4_c_b_o with bias=0, offset=(0, 2), reference=0.5, compare=1, ty=-3 disagrees on 128/320 words on both adapters; word 0 is 3f800000, expected zero. With floor(scaled)=-3, the offset gives -1; clamping early makes it +1. Adding the offset before the range-safety clamp in the generated HLSL returned 320/320 in both cases on both backends. Please preserve the offset before edge clamping in both helpers and add these returning-from-outside cases to the fixture. The existing gather4_l and gather4_variants WARP/hardware CTests passed 4/4, including all four existing variant mutations, with no skips. Windows 11 build 26300, WARP 10.0.26100.9818, RTX 4060 Laptop 32.0.16.1656, debug layer enabled.
Author
Owner

@⁠R0Y00 on GitHub · 2026-12-03 11:41 UTC · original

Independent result at 059b9d88: the gather translation controls and draw-mimg-gather4 passed on both WARP and RTX 4060 Laptop, with the D3D12 debug layer enabled. The new return-from-left and return-from-top inputs both matched all 320 words, with zero debug errors. Offsetting before clamping addresses my edge finding. The earlier bias/zero-derivative finding in #3606 is still open: the lowerer and the fixture still use max(bias, clamp), so the readbacks agree with that model but do not establish which mip the native operation selects. Please resolve that finding on this base before landing the stack.

**@⁠R0Y00** on GitHub · 2026-12-03 11:41 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3604#issuecomment-7377057445) Independent result at 059b9d88: the gather translation controls and draw-mimg-gather4 passed on both WARP and RTX 4060 Laptop, with the D3D12 debug layer enabled. The new return-from-left and return-from-top inputs both matched all 320 words, with zero debug errors. Offsetting before clamping addresses my edge finding. The earlier bias/zero-derivative finding in https://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/3606 is still open: the lowerer and the fixture still use max(bias, clamp), so the readbacks agree with that model but do not establish which mip the native operation selects. Please resolve that finding on this base before landing the stack.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3606/head:github-bot/gh-3604'
git switch 'github-bot/gh-3604'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3604'
git switch 'github-bot/gh-3604'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3604'
git switch 'github-bot/gh-3604'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3604'
git switch 'main'
git merge --squash 'github-bot/gh-3604'
git switch 'main'
git merge --ff-only 'github-bot/gh-3604'
git switch 'main'
git merge 'github-bot/gh-3604'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.