gpu: translate image_load_mip on 2D arrays #1410

Merged
tedin7 merged 1 commit from upstream-pr/1417 into main 2026-11-24 11:17:09 +00:00
tedin7 commented 2026-11-24 11:02:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:02:24Z.


What

image_load_mip with dim:SQ_RSRC_IMG_2D_ARRAY is translated to Texture2DArray.Load(int4(x, y, slice, mip)) instead of being refused. The change in tools/startup/gfx2hlsl.py removes the explicit refusal (the method already had axes = 3, the address assembly and the len(cs) == axes + 1 check). Cube maps are still refused.

Test side: startup_image_2d_array_check.py gains translation controls and a draw of a two-slice, three-mip array; the shared draw fixture (tests/startup_image_3d.cpp) takes a mip-level count and a new --startup-image-2d-array-mips operation in tests/offscreen_check.cpp uses it. docs/startup-runtime.md is updated. src/startup_stubs/d3d12_draw.inl is not touched: it copies the view the program recorded (MipLevels included) and only falls back to MipLevels = 1 when no view was recorded, so a recorded array view with several mips is bound as recorded.

Why

The refusal was not a hardware finding. 3696ec96 merged the 2D array change (34f03603) and the explicit mip load change (03f8980b) from separate branches; each had verified only its own dimensions, and the merge refused the unverified combination. The 2D array docs already listed "an array with mip levels in image_load_mip" as not covered. A pixel stage that used it was skipped with every draw through its pipeline.

Tested

Run locally on Linux:

  • python3 -B tests/startup_image_2d_array_check.py (translation controls, refusals, mutant model), tests/startup_image_3d_check.py, tests/startup_image_load_mip_check.py, tests/startup_image_sample_l_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check: pass.
  • python3 -B tests/startup_image_2d_array_check.py binary llvm-mc-19 mip: the new fixture words (packed and NSA address) match llvm-mc 19 for gfx1013. binary llvm-mc-15 (what CI runs) is unchanged and passes without the new fixtures.
  • HLSL of every existing fixture, translated by the old and the new translator from the same tests: byte-identical (34 pipelines, same SHA-256 over HLSL and manifests).
  • The draw driver (check_draw_mips) was exercised with a stand-in compiler and renderer that evaluate the translated Load: all 6 (fixture, slice) cases and all 7 mutants behave as expected. This proves the Python driver and the mutant strings, not D3D.
  • tests/startup_image_3d.cpp compiles (-fsyntax-only, mingw g++ C++20).

Windows (not run here):

ctest --preset dev --no-tests=error -R "^startup_image_2d_array_" -V
ctest --preset release --no-tests=error -R "^startup_image_2d_array_" -V
ctest --preset release --no-tests=error -R "^startup_image_(3d|load_mip|sample_l)_" -V

(ctest names: startup_image_2d_array_controls, startup_image_2d_array_warp, startup_image_2d_array_hardware; no new ctest entries, CI and CMake registration unchanged.)

Not run locally: D3D12, WARP, DXC, FXC, MSVC, offscreen_check.cpp compilation (needs generated headers), LLVM 15.

Unverified

  • The address order x, y, slice, mip is not read from a hardware manual here. Established: llvm-mc 19 accepts image_load_mip on SQ_RSRC_IMG_2D_ARRAY only with four address registers (three are rejected: "image address size does not match dim and a16"), and the 3D form (x, y, z, mip) and image_sample_l (coordinates, then level) already use the same coordinates-then-level order. Not established: that hardware reads slice before mip rather than the reverse; the draw test would show a swap on a real adapter.
  • That WARP and hardware return what the readback expects for the mip fixtures; the draw has not been run.
  • LLVM 15 acceptance of the new spelling: the new fixtures are only reassembled with the opt-in mip argument, and CI does not pass it. The encoded words are pinned.
  • mip one too high reads another valid cell by construction (no out-of-range load is relied on).
  • The address-count refusal is not reachable from encoded words (the decoder derives the count from the dimension); the control re-decodes the same words with a patched dimension table.

Left out

Cube maps (image_load_mip with SQ_RSRC_IMG_CUBE) are still refused with the same message ("image dimension SQ_RSRC_IMG_CUBE"); only a 2D array is added here.

AI-assisted (Claude Code); commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6580314114 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1417). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:02:24Z. --- ## What `image_load_mip` with `dim:SQ_RSRC_IMG_2D_ARRAY` is translated to `Texture2DArray.Load(int4(x, y, slice, mip))` instead of being refused. The change in `tools/startup/gfx2hlsl.py` removes the explicit refusal (the method already had `axes = 3`, the address assembly and the `len(cs) == axes + 1` check). Cube maps are still refused. Test side: `startup_image_2d_array_check.py` gains translation controls and a draw of a two-slice, three-mip array; the shared draw fixture (`tests/startup_image_3d.cpp`) takes a mip-level count and a new `--startup-image-2d-array-mips` operation in `tests/offscreen_check.cpp` uses it. `docs/startup-runtime.md` is updated. `src/startup_stubs/d3d12_draw.inl` is not touched: it copies the view the program recorded (`MipLevels` included) and only falls back to `MipLevels = 1` when no view was recorded, so a recorded array view with several mips is bound as recorded. ## Why The refusal was not a hardware finding. `3696ec96` merged the 2D array change (`34f03603`) and the explicit mip load change (`03f8980b`) from separate branches; each had verified only its own dimensions, and the merge refused the unverified combination. The 2D array docs already listed "an array with mip levels in image_load_mip" as not covered. A pixel stage that used it was skipped with every draw through its pipeline. ## Tested Run locally on Linux: - `python3 -B tests/startup_image_2d_array_check.py` (translation controls, refusals, mutant model), `tests/startup_image_3d_check.py`, `tests/startup_image_load_mip_check.py`, `tests/startup_image_sample_l_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check`: pass. - `python3 -B tests/startup_image_2d_array_check.py binary llvm-mc-19 mip`: the new fixture words (packed and NSA address) match llvm-mc 19 for gfx1013. `binary llvm-mc-15` (what CI runs) is unchanged and passes without the new fixtures. - HLSL of every existing fixture, translated by the old and the new translator from the same tests: byte-identical (34 pipelines, same SHA-256 over HLSL and manifests). - The draw driver (`check_draw_mips`) was exercised with a stand-in compiler and renderer that evaluate the translated Load: all 6 (fixture, slice) cases and all 7 mutants behave as expected. This proves the Python driver and the mutant strings, not D3D. - `tests/startup_image_3d.cpp` compiles (`-fsyntax-only`, mingw g++ C++20). Windows (not run here): ``` ctest --preset dev --no-tests=error -R "^startup_image_2d_array_" -V ctest --preset release --no-tests=error -R "^startup_image_2d_array_" -V ctest --preset release --no-tests=error -R "^startup_image_(3d|load_mip|sample_l)_" -V ``` (ctest names: `startup_image_2d_array_controls`, `startup_image_2d_array_warp`, `startup_image_2d_array_hardware`; no new ctest entries, CI and CMake registration unchanged.) Not run locally: D3D12, WARP, DXC, FXC, MSVC, `offscreen_check.cpp` compilation (needs generated headers), LLVM 15. ## Unverified - The address order x, y, slice, mip is not read from a hardware manual here. Established: llvm-mc 19 accepts `image_load_mip` on `SQ_RSRC_IMG_2D_ARRAY` only with four address registers (three are rejected: "image address size does not match dim and a16"), and the 3D form (x, y, z, mip) and `image_sample_l` (coordinates, then level) already use the same coordinates-then-level order. Not established: that hardware reads slice before mip rather than the reverse; the draw test would show a swap on a real adapter. - That WARP and hardware return what the readback expects for the mip fixtures; the draw has not been run. - LLVM 15 acceptance of the new spelling: the new fixtures are only reassembled with the opt-in `mip` argument, and CI does not pass it. The encoded words are pinned. - `mip one too high` reads another valid cell by construction (no out-of-range load is relied on). - The address-count refusal is not reachable from encoded words (the decoder derives the count from the dimension); the control re-decodes the same words with a patched dimension table. ## Left out Cube maps (`image_load_mip` with `SQ_RSRC_IMG_CUBE`) are still refused with the same message ("image dimension SQ_RSRC_IMG_CUBE"); only a 2D array is added here. AI-assisted (Claude Code); commands listed were executed locally.
upstream-sync closed this pull request 2026-11-24 12:02:51 +00:00
tedin7 commented 2026-11-24 12:03:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T11:06:36Z.


Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit 77d7a36c:

  • Debug (--preset dev): ctest --preset dev -R '^startup_image_2d_array_' --no-tests=error --output-on-failure — 3/3 passed (startup_image_2d_array_controls 0.22s, startup_image_2d_array_warp 3.49s, startup_image_2d_array_hardware 3.49s on WARP VM)
  • Release /O2 (--preset release): ctest --preset release -R '^startup_image_2d_array_' --no-tests=error --output-on-failure — 3/3 passed (startup_image_2d_array_controls 0.20s, startup_image_2d_array_warp 3.38s, startup_image_2d_array_hardware 3.40s on WARP VM)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129667521 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1417#issuecomment-7129667521). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T11:06:36Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `77d7a36c`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^startup_image_2d_array_' --no-tests=error --output-on-failure` — **3/3 passed** (`startup_image_2d_array_controls` 0.22s, `startup_image_2d_array_warp` 3.49s, `startup_image_2d_array_hardware` 3.49s on WARP VM) - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^startup_image_2d_array_' --no-tests=error --output-on-failure` — **3/3 passed** (`startup_image_2d_array_controls` 0.20s, `startup_image_2d_array_warp` 3.38s, `startup_image_2d_array_hardware` 3.40s on WARP VM)
chatgpt-codex-connector[bot commented 2026-11-24 12:03:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T11:06:43Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T11:10:08.907622Z 77d7a36 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7129670283 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1417#issuecomment-7129670283). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T11:06:43Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"77d7a36cad3d391b6215f25af2cd0a562139e1d6","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-24T11:10:08.907622Z">2026-11-24T11:10:08.907622Z</relative-time> | `77d7a36` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
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!1410
No description provided.