shader: lower explicit mip texture loads at startup #1277

Merged
Evan-Lowry merged 14 commits from upstream-pr/1284 into main 2026-11-24 10:17:00 +00:00
Evan-Lowry commented 2026-11-24 06:44:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Evan-Lowry on 2026-11-24T06:44:20Z.


The startup gfx1013 graphics translator rejects image_load_mip. Lower the 2D and 3D forms to HLSL Texture.Load using the final address register for the mip level. Preserve mip zero for ordinary image_load. Packed data, packed addresses, and fault-status forms remain unsupported.

Refs #1149. This is the startup graphics path, separate from the compute translator in #1265.

Validation

  • python -B tests/startup_image_load_mip_check.py --llvm-mc <llvm-mc> matched the synthetic gfx1013 instruction bytes.
  • python -B tests/startup_image_load_mip_check.py --draw <dxc> <offscreen_check> hardware and the equivalent warp run both matched all 64 pixels and 256 channels for mips 2 and 0 with zero error. The deliberate wrong-mip comparison failed at (0, 0).
  • The 3D nonconsecutive-address case was checked in translation and compilation. Draw coverage is 2D, using synthetic inputs.

AI-assisted with Codex.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6576249375 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1284). Originally posted by [Evan-Lowry](https://github.com/Evan-Lowry) on 2026-11-24T06:44:20Z. --- The startup gfx1013 graphics translator rejects `image_load_mip`. Lower the 2D and 3D forms to HLSL `Texture.Load` using the final address register for the mip level. Preserve mip zero for ordinary `image_load`. Packed data, packed addresses, and fault-status forms remain unsupported. Refs #1149. This is the startup graphics path, separate from the compute translator in #1265. **Validation** - `python -B tests/startup_image_load_mip_check.py --llvm-mc <llvm-mc>` matched the synthetic gfx1013 instruction bytes. - `python -B tests/startup_image_load_mip_check.py --draw <dxc> <offscreen_check> hardware` and the equivalent `warp` run both matched all 64 pixels and 256 channels for mips 2 and 0 with zero error. The deliberate wrong-mip comparison failed at (0, 0). - The 3D nonconsecutive-address case was checked in translation and compilation. Draw coverage is 2D, using synthetic inputs. AI-assisted with Codex.
tedin7 commented 2026-11-24 07:00:43 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed at c7afbf0ece7b1a82139ec4918f32aca7fac63560.

Verification

Linux (worktree from origin/main):

  • git diff --check origin/main...HEAD — clean
  • python -B tests/docs_links_check.py — passed (16 Markdown files, 284 links)
  • python -B tests/bidi_controls_check.py — passed (1063 tracked files)
  • python -B tests/startup_image_load_mip_check.py --llvm-mc /usr/bin/llvm-mc-19 — passed (2D packed, 3D NSA, 2D implicit, plus d16/a16/tfe negative controls)

Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at c7afbf0ece7b1a82139ec4918f32aca7fac63560:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target offscreen_check -- -j 6): 2.78s (configure 1.50s)
    • Test (ctest --preset dev -R 'startup_image_load_mip_controls|startup_image_load_mip_warp' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (0.40s: startup_image_load_mip_controls 0.16s, startup_image_load_mip_warp 0.33s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target offscreen_check -- -j 6): 0.34s (configure 1.45s)
    • Test (ctest --preset release -R 'startup_image_load_mip_controls|startup_image_load_mip_warp' --parallel 4 --no-tests=error --output-on-failure): 2/2 passed (0.39s: startup_image_load_mip_controls 0.16s, startup_image_load_mip_warp 0.32s)

Findings

  • tools/startup/gfx2hlsl.py lowers image_load_mip for 2D and 3D textures to Texture.Load(int3(x, y, mip)) / Texture.Load(int4(x, y, z, mip)) (including NSA non-consecutive coordinates), while keeping image_load at mip 0.
  • decode() rejects tfe (word0 & (1 << 16)) and a16 (word1 & (1 << 30)), and image() validates coordinate count (axes + 1), non-zero dmask, and allowed modifiers (dim:, dmask:, unorm, glc, slc, dlc), rejecting d16 and other unsupported modifiers.
  • tests/startup_image_load_mip_check.py verifies llvm-mc reassembly, translation outputs, negative controls (d16, a16, tfe), and WARP pixel-exact readbacks for mips 0 and 2 (plus wrong-mip rejection at (0, 0)).
  • Minor note (non-blocking): unorm is currently in the allowed modifier list for image_load_mip, even though Texture.Load always interprets coordinates as unnormalized integers; harmless if treated as a no-op, or could be rejected/ignored explicitly if unorm is unexpected on image_load_mip.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6034926379 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1284#pullrequestreview-6034926379). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T06:55:11Z. **Review:** COMMENTED --- Reviewed at `c7afbf0ece7b1a82139ec4918f32aca7fac63560`. ### Verification **Linux** (worktree from `origin/main`): - `git diff --check origin/main...HEAD` — clean - `python -B tests/docs_links_check.py` — passed (16 Markdown files, 284 links) - `python -B tests/bidi_controls_check.py` — passed (1063 tracked files) - `python -B tests/startup_image_load_mip_check.py --llvm-mc /usr/bin/llvm-mc-19` — passed (`2D packed`, `3D NSA`, `2D implicit`, plus `d16`/`a16`/`tfe` negative controls) **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP)** at `c7afbf0ece7b1a82139ec4918f32aca7fac63560`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target offscreen_check -- -j 6`): `2.78s` (configure `1.50s`) - Test (`ctest --preset dev -R 'startup_image_load_mip_controls|startup_image_load_mip_warp' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`0.40s`: `startup_image_load_mip_controls` `0.16s`, `startup_image_load_mip_warp` `0.33s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target offscreen_check -- -j 6`): `0.34s` (configure `1.45s`) - Test (`ctest --preset release -R 'startup_image_load_mip_controls|startup_image_load_mip_warp' --parallel 4 --no-tests=error --output-on-failure`): **2/2 passed** (`0.39s`: `startup_image_load_mip_controls` `0.16s`, `startup_image_load_mip_warp` `0.32s`) ### Findings - `tools/startup/gfx2hlsl.py` lowers `image_load_mip` for 2D and 3D textures to `Texture.Load(int3(x, y, mip))` / `Texture.Load(int4(x, y, z, mip))` (including NSA non-consecutive coordinates), while keeping `image_load` at mip `0`. - `decode()` rejects `tfe` (`word0 & (1 << 16)`) and `a16` (`word1 & (1 << 30)`), and `image()` validates coordinate count (`axes + 1`), non-zero `dmask`, and allowed modifiers (`dim:`, `dmask:`, `unorm`, `glc`, `slc`, `dlc`), rejecting `d16` and other unsupported modifiers. - `tests/startup_image_load_mip_check.py` verifies `llvm-mc` reassembly, translation outputs, negative controls (`d16`, `a16`, `tfe`), and WARP pixel-exact readbacks for mips 0 and 2 (plus wrong-mip rejection at `(0, 0)`). - **Minor note (non-blocking):** `unorm` is currently in the allowed modifier list for `image_load_mip`, even though `Texture.Load` always interprets coordinates as unnormalized integers; harmless if treated as a no-op, or could be rejected/ignored explicitly if `unorm` is unexpected on `image_load_mip`.
R0Y00 commented 2026-11-24 07:07:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:03:34Z.


I resolved the sole conflict locally against main after #1286 and reran the combined candidate. Both Linux checks should stay in .github/workflows/windows.yml: startup_translator_check.py from main, followed by startup_image_load_mip_check.py from this PR. LLVM 15 matched the gfx1013 words, the adjacent translator checks passed, and RTX 4060 Laptop and WARP each matched all 64 pixels at both levels. The deliberately wrong mip failed at the first pixel on both.

GitHub reports maintainer edits disabled on this branch. Please merge main into the PR branch and keep both workflow lines. The other changed files merged cleanly in the local candidate.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7124569860 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1284#issuecomment-7124569860). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T07:03:34Z. --- I resolved the sole conflict locally against main after #1286 and reran the combined candidate. Both Linux checks should stay in `.github/workflows/windows.yml`: `startup_translator_check.py` from main, followed by `startup_image_load_mip_check.py` from this PR. LLVM 15 matched the gfx1013 words, the adjacent translator checks passed, and RTX 4060 Laptop and WARP each matched all 64 pixels at both levels. The deliberately wrong mip failed at the first pixel on both. GitHub reports maintainer edits disabled on this branch. Please merge main into the PR branch and keep both workflow lines. The other changed files merged cleanly in the local candidate.
upstream-sync closed this pull request 2026-11-24 11:02:34 +00:00
R0Y00 commented 2026-11-24 11:02:34 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T10:10:55Z.

Review: APPROVED


Approved this head for explicit 2D/3D mip selection and the modifier rejection controls. Keep the upstream translator checks when integrating the CI change. The two-level readback was validated on hardware and WARP in the earlier combined review.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6037301265 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1284#pullrequestreview-6037301265). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T10:10:55Z. **Review:** APPROVED --- Approved this head for explicit 2D/3D mip selection and the modifier rejection controls. Keep the upstream translator checks when integrating the CI change. The two-level readback was validated on hardware and WARP in the earlier combined review.
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!1277
No description provided.