shader: lower explicit mip texture loads at startup #1284

Manually merged
github merged 14 commits from gh-pr/1284/head into gh-pr/1284/base 2026-11-26 22:55:02 +00:00
Owner

@⁠Evan-Lowry on GitHub · 2026-11-24 06:44 UTC · original
Evan-Lowry:shader/startup-image-load-mip → main · +131 −5 · 5 files · 14 commits · merged 2026-11-24 10:17 UTC

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.

**@⁠Evan-Lowry** on GitHub · 2026-11-24 06:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1284) `Evan-Lowry:shader/startup-image-load-mip` → `main` · +131 −5 · 5 files · 14 commits · merged 2026-11-24 10:17 UTC 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:55:01 +00:00
github manually merged commit 4abd9db3a8 into gh-pr/1284/base 2026-11-26 22:55:02 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 07:03 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-24 07:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1284#issuecomment-7124569860) 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.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 06:55 UTC · original · reviewed

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.
**@⁠tedin7** on GitHub · 2026-11-24 06:55 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1284#pullrequestreview-6034926379) · **reviewed** 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`.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 10:10 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-11-24 10:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1284#pullrequestreview-6037301265) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.