shader: lower explicit-LOD 2D image_gather4_l in gfx2hlsl #2307

Merged
Vladimir-Human merged 1 commit from upstream-pr/2315 into main 2026-11-25 12:50:51 +00:00
Vladimir-Human commented 2026-11-25 11:58:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vladimir-Human on 2026-11-25T11:58:38Z.


Refs #1802

Lower gfx1013 explicit-LOD 2D non-comparison image_gather4_l across pixel and compute stages in tools/startup/gfx2hlsl.py.

Semantics and design

  • RDNA 2 ISA / LLVM 15 (AMDGPU MIMG 0x44, dim:SQ_RSRC_IMG_2D): image_gather4_l takes four destination VGPRs, three contiguous address VGPRs (u, v, lod), an 8-register image descriptor, a 4-register constant sampler, and a one-hot component dmask (0x1/0x2/0x4/0x8).
  • Sampler & descriptor checks (Stage.gather_2d_setup): shares 2D gather setup with op_image_gather4_lz, validates constant sampler words via pixel_aot.check_gather_sampler (CLAMP_LAST_TEXEL in X/Y, normalized coordinates, zero MIN_LOD, point mip filter, zero bias, non-anisotropic XY), and keeps MIP_POINT_PRECLAMP (word 2 bit 28; Mesa gfx10-rsrc.json SQ_IMG_SAMP_WORD2) refused for _l. Compute stages enforce self.fixed_table_image(ops[2], name) (8-word fixed-table unmodified descriptor checks).
  • HLSL lowering (gather_2d_lod): D3D12 SM 5.1/6.0 Gather* only reads view mip zero (D3D11.3 functional spec §22.4.2), so gather_2d_lod checks uv and lod finiteness bitwise, queries view levels via GetDimensions, clamps lod to [0, MAX_LOD] (sampler word 1 bits 23:12, u4.8) and rounds (floor(lod + 0.5f)) within [0, levels - 1], and loads the four (0,1), (1,1), (1,0), (0,0) taps clamped to mip bounds. Non-finite inputs return zero without corrupting surrounding lanes/words.
  • Refused out-of-scope forms: _c_l, _b, _l_o, non-2D dims, non-one-hot dmask, a16, d16, tfe, unorm, r128, lwe, NSA addresses, out-of-bounds register ranges, non-constant/invalid samplers, and modified/unaligned/aliased cs image descriptors.

Verification (rebased commit 85f7cda9 on 209938b0)

  • Build: . .\tools\dev.ps1; cmake --preset release; cmake --build --preset release --target offscreen_check
  • Gather & D16 CTest suite (ctest --preset release --no-tests=error -j 1 -R "^startup_(compute_gather_l|compute_gather_lz|image_gather_lz|image_gather_c_lz|image_sample_l|compute_image_store_d16)(_warp|_hardware)?$" -V): 16/16 passed (0 skipped), including startup_compute_gather_l, startup_compute_gather_l_warp, and startup_compute_gather_l_hardware:
    • WARP: Microsoft Basic Render Driver (1414:008c, driver 10.0.26100.9818, Windows Build 26300.9974 (26H2), debug_layer=enabled, debug_errors=0 debug_warnings=0) — 13 positive compute cases (mip0_red..sampler_max_lod_0), 2 NaN cases, 4-lane dynamic LOD (cs_6_0), 6 compute mutants (dropped_gather, wrong_component, forced_mip_zero, wrong_first_mip, wrong_tap_order, ignored_max_lod), 2 pixel draws (DXC ps_6_0 + FXC ps_5_1 /WX), and 1 pixel mutant (forced_mip_zero) all passed (compared_words=320 mismatches=0, mutants failed as predicted).
    • Hardware: NVIDIA GeForce RTX 4070 SUPER (10de:2783, driver 32.0.16.2114, Windows Build 26300.9974 (26H2), debug_layer=enabled, debug_errors=0 debug_warnings=0) — identical full suite passed (0 debug errors/warnings, all mutants failed as predicted).
  • Compute entry/MBCNT regression (ctest --preset release --no-tests=error -j 1 -R "^startup_gfx2hlsl_compute"): 13/13 passed (0 skipped).
  • Pure-Python checks (tests/docs_links_check.py, tests/bidi_controls_check.py, tests/startup_tools_lint_check.py, tests/startup_translator_check.py, tests/startup_compute_gather_l_check.py, tests/startup_image_gather_lz_check.py, tests/startup_compute_gather_lz_check.py, tests/startup_image_sample_l_check.py, tests/startup_compute_image_store_d16_check.py, tests/startup_image_gather_c_lz_check.py, tests/startup_gfx2hlsl_refusals_check.py, tests/startup_gfx2hlsl_handler_arity_check.py, tests/startup_gfx2hlsl_compute_check.py, tests/startup_compute_translate_check.py, tests/startup_gfx2hlsl_b64_shift_check.py, tests/compute_gather4_l_check.py, tests/form_coverage_check.py, tests/shader_census_check.py): all passed.
  • Not tested locally: llvm-mc-15 is not installed on Windows, so --llvm-mc assembly round-trip was not executed locally (cross-checked via tools/disasm_rdna2.py and wired into .github/workflows/windows.yml pixel-binary).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6603957920 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2315). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-25T11:58:38Z. --- Refs #1802 Lower gfx1013 explicit-LOD 2D non-comparison `image_gather4_l` across pixel and compute stages in `tools/startup/gfx2hlsl.py`. ### Semantics and design - **RDNA 2 ISA / LLVM 15 (`AMDGPU` MIMG `0x44`, `dim:SQ_RSRC_IMG_2D`)**: `image_gather4_l` takes four destination VGPRs, three contiguous address VGPRs (`u, v, lod`), an 8-register image descriptor, a 4-register constant sampler, and a one-hot component `dmask` (`0x1`/`0x2`/`0x4`/`0x8`). - **Sampler & descriptor checks (`Stage.gather_2d_setup`)**: shares 2D gather setup with `op_image_gather4_lz`, validates constant sampler words via `pixel_aot.check_gather_sampler` (`CLAMP_LAST_TEXEL` in X/Y, normalized coordinates, zero `MIN_LOD`, point mip filter, zero bias, non-anisotropic XY), and keeps `MIP_POINT_PRECLAMP` (word 2 bit 28; Mesa `gfx10-rsrc.json` `SQ_IMG_SAMP_WORD2`) refused for `_l`. Compute stages enforce `self.fixed_table_image(ops[2], name)` (8-word fixed-table unmodified descriptor checks). - **HLSL lowering (`gather_2d_lod`)**: D3D12 SM 5.1/6.0 `Gather*` only reads view mip zero (D3D11.3 functional spec §22.4.2), so `gather_2d_lod` checks `uv` and `lod` finiteness bitwise, queries view levels via `GetDimensions`, clamps `lod` to `[0, MAX_LOD]` (sampler word 1 bits `23:12`, `u4.8`) and rounds (`floor(lod + 0.5f)`) within `[0, levels - 1]`, and loads the four `(0,1), (1,1), (1,0), (0,0)` taps clamped to mip bounds. Non-finite inputs return zero without corrupting surrounding lanes/words. - **Refused out-of-scope forms**: `_c_l`, `_b`, `_l_o`, non-2D dims, non-one-hot `dmask`, `a16`, `d16`, `tfe`, `unorm`, `r128`, `lwe`, NSA addresses, out-of-bounds register ranges, non-constant/invalid samplers, and modified/unaligned/aliased `cs` image descriptors. ### Verification (rebased commit `85f7cda9` on `209938b0`) - Build: `. .\tools\dev.ps1; cmake --preset release; cmake --build --preset release --target offscreen_check` - Gather & D16 CTest suite (`ctest --preset release --no-tests=error -j 1 -R "^startup_(compute_gather_l|compute_gather_lz|image_gather_lz|image_gather_c_lz|image_sample_l|compute_image_store_d16)(_warp|_hardware)?$" -V`): **16/16 passed** (0 skipped), including `startup_compute_gather_l`, `startup_compute_gather_l_warp`, and `startup_compute_gather_l_hardware`: - **WARP**: `Microsoft Basic Render Driver` (`1414:008c`, driver `10.0.26100.9818`, Windows Build `26300.9974` (`26H2`), `debug_layer=enabled`, `debug_errors=0 debug_warnings=0`) — 13 positive compute cases (`mip0_red`..`sampler_max_lod_0`), 2 NaN cases, 4-lane dynamic LOD (`cs_6_0`), 6 compute mutants (`dropped_gather`, `wrong_component`, `forced_mip_zero`, `wrong_first_mip`, `wrong_tap_order`, `ignored_max_lod`), 2 pixel draws (`DXC ps_6_0` + `FXC ps_5_1 /WX`), and 1 pixel mutant (`forced_mip_zero`) all passed (`compared_words=320 mismatches=0`, mutants failed as predicted). - **Hardware**: `NVIDIA GeForce RTX 4070 SUPER` (`10de:2783`, driver `32.0.16.2114`, Windows Build `26300.9974` (`26H2`), `debug_layer=enabled`, `debug_errors=0 debug_warnings=0`) — identical full suite passed (`0` debug errors/warnings, all mutants failed as predicted). - Compute entry/MBCNT regression (`ctest --preset release --no-tests=error -j 1 -R "^startup_gfx2hlsl_compute"`): **13/13 passed** (0 skipped). - Pure-Python checks (`tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/startup_tools_lint_check.py`, `tests/startup_translator_check.py`, `tests/startup_compute_gather_l_check.py`, `tests/startup_image_gather_lz_check.py`, `tests/startup_compute_gather_lz_check.py`, `tests/startup_image_sample_l_check.py`, `tests/startup_compute_image_store_d16_check.py`, `tests/startup_image_gather_c_lz_check.py`, `tests/startup_gfx2hlsl_refusals_check.py`, `tests/startup_gfx2hlsl_handler_arity_check.py`, `tests/startup_gfx2hlsl_compute_check.py`, `tests/startup_compute_translate_check.py`, `tests/startup_gfx2hlsl_b64_shift_check.py`, `tests/compute_gather4_l_check.py`, `tests/form_coverage_check.py`, `tests/shader_census_check.py`): all passed. - **Not tested locally**: `llvm-mc-15` is not installed on Windows, so `--llvm-mc` assembly round-trip was not executed locally (cross-checked via `tools/disasm_rdna2.py` and wired into `.github/workflows/windows.yml` `pixel-binary`). AI-assisted.
tedin7 commented 2026-11-25 12:01:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:00:42Z.

Review: COMMENTED


Review of head 85f7cda962acbb215ceeb7a3299de337edcbc5a0 (comment only, no approval).

Summary: No P1. Two P2 and two nits. The lowering looks right. Tap order (0,1),(1,1),(1,0),(0,0) matches D3D Gather. The _l opcode is refused for MIP_POINT_PRECLAMP. Non-finite inputs return zero. The mip is clamped to the view levels. CI Windows jobs were still pending when I looked.

Commands run locally (Linux, in a worktree at the head SHA):

  • git diff --stat origin/main...HEAD: 7 files, +532/-12
  • python3 -B tests/startup_compute_gather_l_check.py: "image_gather4_l compute and pixel controls passed"
  • python3 -B tests/startup_image_gather_lz_check.py: passed
  • python3 -B tests/startup_compute_gather_lz_check.py: passed
  • python3 tests/docs_links_check.py: 448 links ok
  • python3 tests/bidi_controls_check.py: no bidi controls
  • git diff --check origin/main...HEAD: clean

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

  • Dropping the MIP_POINT_PRECLAMP refusal (gfx2hlsl.py gather_2d_setup): killed by the Linux test.
  • Tap order (0,1) to (1,1), floor(lod+0.5) to floor(lod), and removing the lod non-finite guard: all three SURVIVE on Linux. The Linux run has no --dispatch, so only string and refusal checks run. The --dispatch list does have cases for each (frac_lod_down/up, nan_lod, tap compare via reference()), so they should die on Windows. I did not run the Windows pipeline. I am relying on the pending CI jobs "Build and test on Windows" and "Assemble and translate gfx1013 fixtures", and I did not see them finish.

Findings

  • P2 tools/startup/gfx2hlsl.py (gather_2d_lod helper): the mip is chosen by round-to-nearest floor(lod + 0.5), matching the point-mip-filter rule. That is a D3D-spec-based choice and is not measured on console hardware. docs/experiments.md does not say so. Please state it as unmeasured, as the sibling gather_2d_profile_words docstring does.
  • P2 tests/startup_compute_gather_l_check.py: the Linux-only path is string-based for the rounding, tap order and non-finite guard. Those behaviors are only protected when --dispatch runs (WARP/hardware CTest). Make sure a Windows WARP run passes before moving to Ready.
  • nit tools/startup/gfx2hlsl.py: uses_gather_2d_lod = False is set on the class and again in both __init__ methods. One place is enough.
  • nit tests/startup_image_gather_lz_check.py: the comment says _l is lowered "by their own tests". Name startup_compute_gather_l_check.py for clarity.

Clean-room: the description cites public ISA and spec sources only. Title is neutral. The PR is mergeable.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057212249 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2315#pullrequestreview-6057212249). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:00:42Z. **Review:** COMMENTED --- Review of head `85f7cda962acbb215ceeb7a3299de337edcbc5a0` (comment only, no approval). **Summary:** No P1. Two P2 and two nits. The lowering looks right. Tap order `(0,1),(1,1),(1,0),(0,0)` matches D3D Gather. The `_l` opcode is refused for MIP_POINT_PRECLAMP. Non-finite inputs return zero. The mip is clamped to the view levels. CI Windows jobs were still pending when I looked. **Commands run locally (Linux, in a worktree at the head SHA):** - `git diff --stat origin/main...HEAD`: 7 files, +532/-12 - `python3 -B tests/startup_compute_gather_l_check.py`: "image_gather4_l compute and pixel controls passed" - `python3 -B tests/startup_image_gather_lz_check.py`: passed - `python3 -B tests/startup_compute_gather_lz_check.py`: passed - `python3 tests/docs_links_check.py`: 448 links ok - `python3 tests/bidi_controls_check.py`: no bidi controls - `git diff --check origin/main...HEAD`: clean **Mutations (each reverted with `git checkout -- .`):** - Dropping the MIP_POINT_PRECLAMP refusal (`gfx2hlsl.py` `gather_2d_setup`): killed by the Linux test. - Tap order `(0,1)` to `(1,1)`, `floor(lod+0.5)` to `floor(lod)`, and removing the lod non-finite guard: all three SURVIVE on Linux. The Linux run has no `--dispatch`, so only string and refusal checks run. The `--dispatch` list does have cases for each (`frac_lod_down/up`, `nan_lod`, tap compare via `reference()`), so they should die on Windows. I did not run the Windows pipeline. I am relying on the pending CI jobs "Build and test on Windows" and "Assemble and translate gfx1013 fixtures", and I did not see them finish. **Findings** - P2 `tools/startup/gfx2hlsl.py` (`gather_2d_lod` helper): the mip is chosen by round-to-nearest `floor(lod + 0.5)`, matching the point-mip-filter rule. That is a D3D-spec-based choice and is not measured on console hardware. `docs/experiments.md` does not say so. Please state it as unmeasured, as the sibling `gather_2d_profile_words` docstring does. - P2 `tests/startup_compute_gather_l_check.py`: the Linux-only path is string-based for the rounding, tap order and non-finite guard. Those behaviors are only protected when `--dispatch` runs (WARP/hardware CTest). Make sure a Windows WARP run passes before moving to Ready. - nit `tools/startup/gfx2hlsl.py`: `uses_gather_2d_lod = False` is set on the class and again in both `__init__` methods. One place is enough. - nit `tests/startup_image_gather_lz_check.py`: the comment says `_l` is lowered "by their own tests". Name `startup_compute_gather_l_check.py` for clarity. Clean-room: the description cites public ISA and spec sources only. Title is neutral. The PR is mergeable. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-25 13:00:43 +00:00
tedin7 commented 2026-11-25 13:00:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:43:09Z.

Review: COMMENTED


Review of head 86ad18d189139549fed727c639d68640dd9211a7 (PR #2315).

Scope read: tools/startup/gfx2hlsl.py (gather_2d_setup, op_image_gather4_lz refactor, op_image_gather4_l, gather_2d_lod helper emit), tests/startup_compute_gather_l_check.py, CMake/CI wiring, docs.

Commands executed locally

  • git diff --stat origin/main...HEAD: 7 files, +532/-12.
  • git diff --check origin/main...HEAD: clean.
  • python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 452 links.
  • python3 tests/bidi_controls_check.py: self-test passed, 1616 files, no bidi controls.
  • python3 tests/startup_compute_gather_l_check.py: "image_gather4_l compute and pixel controls passed".
  • python3 tests/startup_image_gather_lz_check.py: passed (the _lz refactor into gather_2d_setup keeps its behaviour).
  • Win2025 (D3D12 WARP + hardware adapter, dev preset): x2w_pipe.py win2025 2315 --regex 'startup_(compute|image)_gather' --skip-release -> 12/12 passed, including startup_compute_gather_l, startup_compute_gather_l_warp, startup_compute_gather_l_hardware, and the existing _lz / _c_lz siblings (no regression). Release preset not run.
  • CI (gh pr checks): Windows build/test and Linux Python checks pass; "Assemble and translate gfx1013 fixtures" was still pending when I looked. PR is mergeable, title is neutral.

Mutation check (Linux)

  • Changed the LOD rounding (floor(lod+0.5) -> floor(lod)) and swapped one gather tap in the emitted HLSL. The Linux-only run of the check still passed in both cases. The Linux run only translates and string-checks the source. The numeric proof is the Windows WARP/hardware readback. I did not re-run these mutants on Win2025, so I can't say the readback kills them.

Findings

  • P1: none.
  • P2: none.
  • nit (tests/startup_compute_gather_l_check.py): the GPU readback (--dispatch) covers the compute stage only. The pixel stage is checked at translate level only, although both use the same gather_2d_lod helper. A pixel --draw readback case would close that gap. Not blocking, since the helper is shared.
  • nit (tools/startup/gfx2hlsl.py, gather_2d_setup): MIP_POINT_PRECLAMP is refused by OR-ing bit 28 into the profile words just for the _l path. A short comment on why this is refused for _l and not for _lz would help the next reader. The PR body already cites the source.

Semantics: address count (3 for u, v, lod), one-hot dmask, tap order (0,1), (1,1), (1,0), (0,0), NaN/Inf lanes returning zero, MAX_LOD clamp (u4.8) and clamping to view levels all match the PR description and the intended gather behaviour.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6057809272 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2315#pullrequestreview-6057809272). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T12:43:09Z. **Review:** COMMENTED --- Review of head `86ad18d189139549fed727c639d68640dd9211a7` (PR #2315). **Scope read:** `tools/startup/gfx2hlsl.py` (`gather_2d_setup`, `op_image_gather4_lz` refactor, `op_image_gather4_l`, `gather_2d_lod` helper emit), `tests/startup_compute_gather_l_check.py`, CMake/CI wiring, docs. **Commands executed locally** - `git diff --stat origin/main...HEAD`: 7 files, +532/-12. - `git diff --check origin/main...HEAD`: clean. - `python3 tests/docs_links_check.py`: self-test passed, 18 Markdown files, 452 links. - `python3 tests/bidi_controls_check.py`: self-test passed, 1616 files, no bidi controls. - `python3 tests/startup_compute_gather_l_check.py`: "image_gather4_l compute and pixel controls passed". - `python3 tests/startup_image_gather_lz_check.py`: passed (the `_lz` refactor into `gather_2d_setup` keeps its behaviour). - Win2025 (D3D12 WARP + hardware adapter, dev preset): `x2w_pipe.py win2025 2315 --regex 'startup_(compute|image)_gather' --skip-release` -> 12/12 passed, including `startup_compute_gather_l`, `startup_compute_gather_l_warp`, `startup_compute_gather_l_hardware`, and the existing `_lz` / `_c_lz` siblings (no regression). Release preset not run. - CI (`gh pr checks`): Windows build/test and Linux Python checks pass; "Assemble and translate gfx1013 fixtures" was still pending when I looked. PR is mergeable, title is neutral. **Mutation check (Linux)** - Changed the LOD rounding (`floor(lod+0.5)` -> `floor(lod)`) and swapped one gather tap in the emitted HLSL. The Linux-only run of the check still passed in both cases. The Linux run only translates and string-checks the source. The numeric proof is the Windows WARP/hardware readback. I did not re-run these mutants on Win2025, so I can't say the readback kills them. **Findings** - P1: none. - P2: none. - nit (`tests/startup_compute_gather_l_check.py`): the GPU readback (`--dispatch`) covers the compute stage only. The pixel stage is checked at translate level only, although both use the same `gather_2d_lod` helper. A pixel `--draw` readback case would close that gap. Not blocking, since the helper is shared. - nit (`tools/startup/gfx2hlsl.py`, `gather_2d_setup`): `MIP_POINT_PRECLAMP` is refused by OR-ing bit 28 into the profile words just for the `_l` path. A short comment on why this is refused for `_l` and not for `_lz` would help the next reader. The PR body already cites the source. **Semantics:** address count (3 for u, v, lod), one-hot dmask, tap order (0,1), (1,1), (1,0), (0,0), NaN/Inf lanes returning zero, MAX_LOD clamp (u4.8) and clamping to view levels all match the PR description and the intended gather behaviour. 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!2307
No description provided.