shader: lower gfx1013 compute image_gather4_l on a fixed-mip view #2250

Merged
roansystemlabs merged 1 commit from upstream-pr/2258 into main 2026-11-25 09:00:26 +00:00
roansystemlabs commented 2026-11-25 08:27:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-25T08:27:17Z.


Part of #2022.

Change

Item E: image_gather4_l in the compute translator (tools/compute_store_aot.py), as described in the claim comment. Today the compute path refuses every gather. This change lowers one narrow form and keeps the rest refused by name.

  • What is lowered. One 2D image_gather4_l on gfx1013, on the R32G32B32A32_FLOAT SRV at t0 that image_load_mip already uses, with a raw u0 output. The caller declares the visible mip count of the matching native and desktop views with --gather-mips <count> (Python: gather_mips=), as the pixel tool does for its gfx1030 gathers.
  • Sampler. The four sampler words must be constants in an aligned SGPR quad. They are checked with pixel_aot.check_gather_sampler (the profile of #1927 and the pixel gathers): normalized coordinates, clamp-to-edge in X and Y, bilinear XY, point mip, zero LOD bias, MIN_LOD 0 and MAX_LOD at or above the last visible mip.
  • LOD. The LOD must be a known integral binary32 value inside the view. With point mip filtering, that picks the same view-relative mip on both sides. A fractional, unknown, negative or out-of-view LOD is refused.
  • Result. One-hot DMASK picks the component. The four destination VGPRs get that component of the 2×2 footprint in (0,1), (1,1), (1,0), (0,0) order, through four Load calls at the view-relative mip, like gather_2d in pixel_aot.py. The scaled coordinate is clamped to [-1, size] before floor(). With clamp-to-edge this selects the same texels and keeps the float-to-int conversion in range.
  • NaN or infinite U/V. The invocation publishes no store, because no native result is established for that input. This follows the rule in the issue: a distinct outcome instead of a valid-looking one.
  • Refused by name, each with a test: the other gather forms (image_gather4, _lz, _b, _cl, _b_cl, _c_l, _c_lz, _l_o); cube, 2D array, 1D and 3D; NSA; unorm, a16, d16, glc; a non-one-hot DMASK; short destination or address ranges; an unverified or misaligned image descriptor; a non-constant or misaligned sampler; a gather under a lane guard; a second gather; a declared view with no gather; gfx1030; a UINT image; a UAV image output; a mip count outside 1 to 16.
  • v_mov_b32 of an inline float. LLVM prints a b32 move of 0x3f800000 as v_mov_b32_e32 v5, 1.0. The move now accepts the inline float spellings that the translator's float ALU already knows (FLOAT_INLINE). Any other decimal spelling is refused as before (Invalid literal move). Without this, an LOD of 1.0 or 2.0 could not be read.
  • Test runner. The image-load readback case (--compute-texture-case) now also accepts the existing RGBA32 FLOAT flag, and a new flag that binds the t0 SRV with MostDetailedMip = 1. Existing cases are unchanged.

Verification

Windows 11 26200, MSVC 19.44, dev preset, D3D12 debug layer on, DXC from Windows SDK 10.0.26100.0. Tested commit bed536b6 on main 67fcebd1.

python -B tests/compute_gather4_l_check.py
cmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -j 1 -R "^compute_store_aot_gfx1013_gather4_l_" -V
  • Readback. compute_store_aot_gfx1013_gather4_l_hardware passed on NVIDIA GeForce RTX 3070 (10de:2484, driver 32.0.16.2101), and compute_store_aot_gfx1013_gather4_l_warp on WARP 10.0.26100.9818. No capability skips, and debug_errors=0 debug_warnings=0 on every dispatch. Six programs, 320 words each, all equal to an independent CPU model:
    • LOD 0 red, LOD 1 green and LOD 2 blue on a full three-mip view;
    • LOD 0 alpha and LOD 1 red on a view with MostDetailedMip = 1;
    • in each of those five, 256 gathered words and 64 untouched sentinels;
    • U set to NaN: all 320 words untouched.
  • Negative controls. Each must exit 1 at the first word its own model predicts. All did on both adapters:
    • the gather at mip 0 instead of 1: 256 mismatches, word=0 expected=3f100002 actual=3f000002;
    • the first and last taps exchanged: 64 mismatches, word=64 expected=3f101002 actual=3f100002;
    • the MostDetailedMip = 1 program run on the full view: 256 mismatches, word=0 expected=3f200000 actual=3f100000;
    • the NaN program without its finite guard: 256 mismatches, word=0 expected=c5c5c5c5 actual=3f100002.
  • Repeat runs. Three runs of the two tests, all with identical result lines.
  • Debug layer absent. A wrapper that reports the debug layer as unavailable leaves the readback checks in force, and the test passes on both adapters. The debug-line check follows the neighbouring compute image tests.
  • CPU mode. The four lowered lines are pinned, and every refusal above is checked by message. Against the translator of main 1949b265, the fixture stops at Unsupported compute instruction: v_mov_b32_e32 v5, 1.0, and the LOD 0 program at Unsupported compute instruction: image_gather4_l .... I also removed each guard of the lowering in turn: 18 mutants, each turned the check red.
  • Binary mode. The Ubuntu LLVM 15 job runs python tests/compute_gather4_l_check.py --binary llvm-mc-15 llvm-objcopy-15 --llvm libLLVM-15.so.1. I ran the same mode locally with LLVM 15.0.7: the clang 15 integrated assembler stood in for llvm-mc, with llvm-objcopy and LLVM-C.dll from the same release. All six programs assemble for gfx1013. LLVM's disassembly equals the fixture text line for line, the decoded text lowers to the same HLSL, and the synthetic container CLI with --gather-mips 3 matches the text lowering.
  • Wider runs. ctest --preset dev --no-tests=error -j 1 -R "compute_" -V: every compute_store_aot_* test passed (152 of 152). The 10 other failures in that run need targets I had not built (d3d12x_compute_list_check.exe, the startup compute request client, cpu_shim_startup.exe), and each stopped on the missing file. -R "^offscreen_": 4/4. The CPU modes of compute_store_check, compute_load_format_check, compute_mimg_float_store_check, compute_mimg_float_store_d16_check, compute_image_atomics_gfx1013_check, compute_mimg_msaa_check, compute_mimg_image_uav_load_check and compute_desc_numeric_check pass. So do docs_links_check, bidi_controls_check and git diff --check.
  • Not run. The Ubuntu LLVM 15 job (the new test is added to it) and the release preset. Also not run: AMD and Intel GPUs, a real application dispatch, and Xbox hardware.

Evidence and follow-up

The six gfx1013 programs are written for this test, built from text in the test file, and MIT. No game files. Each builds U and V as 0.1875 × id − 0.15 for an 8×8 group, from the dispatch-thread ID with integer and binary32 ALU forms the translator already lowers. So the footprints cover both clamped edges, and every scaled coordinate stays at least 1/64 texel away from a tap boundary at each mip used (the model asserts this). Texels are distinct normal binary32 values for every mip, row, column and channel.

Semantics:

  • RDNA 2 ISA: MIMG address order (U, V, LOD), the gather DMASK and its four results, and the sampler descriptor fields.
  • LLVM 15: llvm.amdgcn.image.gather4.l.2d and the assembler syntax.
  • Direct3D: Gather returns the 2×2 footprint in the same (0,1), (1,1), (1,0), (0,0) order, and Load and GetDimensions take view-relative mips.

Assumptions: the caller binds matching native and desktop views and declares their mip count. Coordinates must select the same half-texel footprint under native texture-coordinate precision and desktop float arithmetic. Coordinates within 1/256 texel of a tap boundary, NaN payloads and denormal texels are not tested. As the issue says, this is not application coverage until it is used in a real dispatch.

docs/experiments.md documents the profile, the refusals and the commands. The test is registered in CMake (compute_store_aot_gfx1013_gather4_l_{hardware,warp}) and in the Ubuntu LLVM 15 job.

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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6600342755 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2258). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-25T08:27:17Z. --- Part of #2022. ## Change Item E: `image_gather4_l` in the compute translator (`tools/compute_store_aot.py`), as described in the claim comment. Today the compute path refuses every gather. This change lowers one narrow form and keeps the rest refused by name. - **What is lowered.** One 2D `image_gather4_l` on gfx1013, on the `R32G32B32A32_FLOAT` SRV at `t0` that `image_load_mip` already uses, with a raw `u0` output. The caller declares the visible mip count of the matching native and desktop views with `--gather-mips <count>` (Python: `gather_mips=`), as the pixel tool does for its gfx1030 gathers. - **Sampler.** The four sampler words must be constants in an aligned SGPR quad. They are checked with `pixel_aot.check_gather_sampler` (the profile of #1927 and the pixel gathers): normalized coordinates, clamp-to-edge in X and Y, bilinear XY, point mip, zero LOD bias, `MIN_LOD` 0 and `MAX_LOD` at or above the last visible mip. - **LOD.** The LOD must be a known integral binary32 value inside the view. With point mip filtering, that picks the same view-relative mip on both sides. A fractional, unknown, negative or out-of-view LOD is refused. - **Result.** One-hot DMASK picks the component. The four destination VGPRs get that component of the 2×2 footprint in `(0,1), (1,1), (1,0), (0,0)` order, through four `Load` calls at the view-relative mip, like `gather_2d` in `pixel_aot.py`. The scaled coordinate is clamped to `[-1, size]` before `floor()`. With clamp-to-edge this selects the same texels and keeps the float-to-int conversion in range. - **NaN or infinite U/V.** The invocation publishes no store, because no native result is established for that input. This follows the rule in the issue: a distinct outcome instead of a valid-looking one. - **Refused by name**, each with a test: the other gather forms (`image_gather4`, `_lz`, `_b`, `_cl`, `_b_cl`, `_c_l`, `_c_lz`, `_l_o`); cube, 2D array, 1D and 3D; NSA; `unorm`, `a16`, `d16`, `glc`; a non-one-hot DMASK; short destination or address ranges; an unverified or misaligned image descriptor; a non-constant or misaligned sampler; a gather under a lane guard; a second gather; a declared view with no gather; gfx1030; a UINT image; a UAV image output; a mip count outside 1 to 16. - **`v_mov_b32` of an inline float.** LLVM prints a b32 move of `0x3f800000` as `v_mov_b32_e32 v5, 1.0`. The move now accepts the inline float spellings that the translator's float ALU already knows (`FLOAT_INLINE`). Any other decimal spelling is refused as before (`Invalid literal move`). Without this, an LOD of 1.0 or 2.0 could not be read. - **Test runner.** The image-load readback case (`--compute-texture-case`) now also accepts the existing RGBA32 FLOAT flag, and a new flag that binds the `t0` SRV with `MostDetailedMip = 1`. Existing cases are unchanged. ## Verification Windows 11 26200, MSVC 19.44, `dev` preset, D3D12 debug layer on, DXC from Windows SDK 10.0.26100.0. Tested commit `bed536b6` on `main` `67fcebd1`. ```text python -B tests/compute_gather4_l_check.py cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -j 1 -R "^compute_store_aot_gfx1013_gather4_l_" -V ``` - **Readback.** `compute_store_aot_gfx1013_gather4_l_hardware` passed on NVIDIA GeForce RTX 3070 (`10de:2484`, driver 32.0.16.2101), and `compute_store_aot_gfx1013_gather4_l_warp` on WARP 10.0.26100.9818. No capability skips, and `debug_errors=0 debug_warnings=0` on every dispatch. Six programs, 320 words each, all equal to an independent CPU model: - LOD 0 red, LOD 1 green and LOD 2 blue on a full three-mip view; - LOD 0 alpha and LOD 1 red on a view with `MostDetailedMip = 1`; - in each of those five, 256 gathered words and 64 untouched sentinels; - U set to NaN: all 320 words untouched. - **Negative controls.** Each must exit 1 at the first word its own model predicts. All did on both adapters: - the gather at mip 0 instead of 1: 256 mismatches, `word=0 expected=3f100002 actual=3f000002`; - the first and last taps exchanged: 64 mismatches, `word=64 expected=3f101002 actual=3f100002`; - the `MostDetailedMip = 1` program run on the full view: 256 mismatches, `word=0 expected=3f200000 actual=3f100000`; - the NaN program without its finite guard: 256 mismatches, `word=0 expected=c5c5c5c5 actual=3f100002`. - **Repeat runs.** Three runs of the two tests, all with identical result lines. - **Debug layer absent.** A wrapper that reports the debug layer as unavailable leaves the readback checks in force, and the test passes on both adapters. The debug-line check follows the neighbouring compute image tests. - **CPU mode.** The four lowered lines are pinned, and every refusal above is checked by message. Against the translator of `main` `1949b265`, the fixture stops at `Unsupported compute instruction: v_mov_b32_e32 v5, 1.0`, and the LOD 0 program at `Unsupported compute instruction: image_gather4_l ...`. I also removed each guard of the lowering in turn: 18 mutants, each turned the check red. - **Binary mode.** The Ubuntu LLVM 15 job runs `python tests/compute_gather4_l_check.py --binary llvm-mc-15 llvm-objcopy-15 --llvm libLLVM-15.so.1`. I ran the same mode locally with LLVM 15.0.7: the clang 15 integrated assembler stood in for `llvm-mc`, with `llvm-objcopy` and `LLVM-C.dll` from the same release. All six programs assemble for gfx1013. LLVM's disassembly equals the fixture text line for line, the decoded text lowers to the same HLSL, and the synthetic container CLI with `--gather-mips 3` matches the text lowering. - **Wider runs.** `ctest --preset dev --no-tests=error -j 1 -R "compute_" -V`: every `compute_store_aot_*` test passed (152 of 152). The 10 other failures in that run need targets I had not built (`d3d12x_compute_list_check.exe`, the startup compute request client, `cpu_shim_startup.exe`), and each stopped on the missing file. `-R "^offscreen_"`: 4/4. The CPU modes of `compute_store_check`, `compute_load_format_check`, `compute_mimg_float_store_check`, `compute_mimg_float_store_d16_check`, `compute_image_atomics_gfx1013_check`, `compute_mimg_msaa_check`, `compute_mimg_image_uav_load_check` and `compute_desc_numeric_check` pass. So do `docs_links_check`, `bidi_controls_check` and `git diff --check`. - **Not run.** The Ubuntu LLVM 15 job (the new test is added to it) and the `release` preset. Also not run: AMD and Intel GPUs, a real application dispatch, and Xbox hardware. ## Evidence and follow-up The six gfx1013 programs are written for this test, built from text in the test file, and MIT. No game files. Each builds U and V as `0.1875 × id − 0.15` for an 8×8 group, from the dispatch-thread ID with integer and binary32 ALU forms the translator already lowers. So the footprints cover both clamped edges, and every scaled coordinate stays at least 1/64 texel away from a tap boundary at each mip used (the model asserts this). Texels are distinct normal binary32 values for every mip, row, column and channel. Semantics: - RDNA 2 ISA: MIMG address order (U, V, LOD), the gather DMASK and its four results, and the sampler descriptor fields. - LLVM 15: `llvm.amdgcn.image.gather4.l.2d` and the assembler syntax. - Direct3D: Gather returns the 2×2 footprint in the same `(0,1), (1,1), (1,0), (0,0)` order, and `Load` and `GetDimensions` take view-relative mips. Assumptions: the caller binds matching native and desktop views and declares their mip count. Coordinates must select the same half-texel footprint under native texture-coordinate precision and desktop float arithmetic. Coordinates within 1/256 texel of a tap boundary, NaN payloads and denormal texels are not tested. As the issue says, this is not application coverage until it is used in a real dispatch. `docs/experiments.md` documents the profile, the refusals and the commands. The test is registered in CMake (`compute_store_aot_gfx1013_gather4_l_{hardware,warp}`) and in the Ubuntu LLVM 15 job. ## 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.
upstream-sync closed this pull request 2026-11-25 09:04:04 +00:00
tedin7 commented 2026-11-25 09:04:05 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head bed536b6dbb39af3aa7fa9ba3a9795c23f6e98ba (comment only, no approval).

Scope read: tools/compute_store_aot.py (gather lowering, GATHER_HLSL, gather_mips validation, float inline v_mov_b32), tests/compute_gather4_l_check.py, tests/compute_check.cpp, CMake/CI wiring, docs/experiments.md.

Commands executed locally (Linux, worktree at the PR head):

  • git diff --stat origin/main...HEAD: 7 files, +510/-12.
  • python3 tests/compute_gather4_l_check.py: translation controls passed (this mode runs the translation controls only; the llvm-mc and WARP readback modes were not available locally).
  • python3 tests/docs_links_check.py: self-test passed, 18 files, 429 links.
  • python3 tests/bidi_controls_check.py: no bidirectional controls in 1536 files.
  • git diff --check origin/main...HEAD: clean.
  • Mutations on the new logic, each reverted with git checkout -- .:
    • LOD bound < gather_mips changed to <= gather_mips: killed (Expected rejection: known integer LOD inside the view).
    • Component index hard-coded to 0u: killed by the translation controls.
    • Pre-floor clamp lower bound -1.0f changed to -4.0f: survives, but this is an equivalent mutant. After +1 and the clamp(.., 0, edge) the selected texels are the same. Not a test gap.

Findings

  • P1: none.
  • P2: none.
  • nit 1: the numeric behaviour (tap order, edge clamp, view-relative mip) is only checked by the WARP readback mode (--draw). On Linux only the string-level controls run. The PR therefore depends on the Windows CI jobs (Assemble and translate gfx1013 fixtures, Build and test on Windows), which were still pending when I looked. Please wait for those to be green before Ready.
  • nit 2: the fixed -0.5f offset and the "keep coordinates off tap boundaries" caveat are documented in docs/experiments.md. It would help to also say in the lower() docstring that this is a caller guarantee and is not checked in the translator.
  • nit 3: the isfinite early return is appended after all other staged steps, so any earlier staged step with a side effect would still run. Today staged steps are pure loads, so this is fine. A short comment would protect it from later changes.

Checked and fine: the gather mask is one-hot only and other image_gather4* forms are refused by name. The sampler goes through the shared pixel_aot.check_gather_sampler. The LOD must be a known integral float inside the view. gather_mips is validated as an int from 1 to 16 and requires exactly one gather. The result order (0,1), (1,1), (1,0), (0,0) matches gather_2d in pixel_aot.py. Title and body are neutral. The PR is mergeable.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6054159803 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2258#pullrequestreview-6054159803). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T08:30:51Z. **Review:** COMMENTED --- Review of head `bed536b6dbb39af3aa7fa9ba3a9795c23f6e98ba` (comment only, no approval). **Scope read:** `tools/compute_store_aot.py` (gather lowering, `GATHER_HLSL`, `gather_mips` validation, float inline `v_mov_b32`), `tests/compute_gather4_l_check.py`, `tests/compute_check.cpp`, CMake/CI wiring, `docs/experiments.md`. **Commands executed locally (Linux, worktree at the PR head):** - `git diff --stat origin/main...HEAD`: 7 files, +510/-12. - `python3 tests/compute_gather4_l_check.py`: `translation controls passed` (this mode runs the translation controls only; the llvm-mc and WARP readback modes were not available locally). - `python3 tests/docs_links_check.py`: self-test passed, 18 files, 429 links. - `python3 tests/bidi_controls_check.py`: no bidirectional controls in 1536 files. - `git diff --check origin/main...HEAD`: clean. - Mutations on the new logic, each reverted with `git checkout -- .`: - LOD bound `< gather_mips` changed to `<= gather_mips`: killed (`Expected rejection: known integer LOD inside the view`). - Component index hard-coded to `0u`: killed by the translation controls. - Pre-floor clamp lower bound `-1.0f` changed to `-4.0f`: survives, but this is an equivalent mutant. After `+1` and the `clamp(.., 0, edge)` the selected texels are the same. Not a test gap. **Findings** - P1: none. - P2: none. - nit 1: the numeric behaviour (tap order, edge clamp, view-relative mip) is only checked by the WARP readback mode (`--draw`). On Linux only the string-level controls run. The PR therefore depends on the Windows CI jobs (`Assemble and translate gfx1013 fixtures`, `Build and test on Windows`), which were still pending when I looked. Please wait for those to be green before Ready. - nit 2: the fixed `-0.5f` offset and the "keep coordinates off tap boundaries" caveat are documented in `docs/experiments.md`. It would help to also say in the `lower()` docstring that this is a caller guarantee and is not checked in the translator. - nit 3: the `isfinite` early return is appended after all other staged steps, so any earlier staged step with a side effect would still run. Today staged steps are pure loads, so this is fine. A short comment would protect it from later changes. **Checked and fine:** the gather mask is one-hot only and other `image_gather4*` forms are refused by name. The sampler goes through the shared `pixel_aot.check_gather_sampler`. The LOD must be a known integral float inside the view. `gather_mips` is validated as an int from 1 to 16 and requires exactly one gather. The result order (0,1), (1,1), (1,0), (0,0) matches `gather_2d` in `pixel_aot.py`. Title and body are neutral. The PR is mergeable. AI-assisted; commands listed were executed locally.
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!2250
No description provided.