startup: lower explicit-LOD image_sample_l to SampleLevel in gfx2hlsl #1258

Manually merged
github merged 5 commits from gh-pr/1258/head into gh-pr/1258/base 2026-11-26 22:53:06 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:44 UTC · original
tedin7:x2w-gfx2hlsl-image-sample-l-explicit-lod → main · +296 −3 · 7 files · 5 commits · merged 2026-11-24 06:09 UTC

Change

Lowers the gfx1013 image_sample_l form (explicit level of detail) in tools/startup/gfx2hlsl.py to tex.SampleLevel(smp, uv, level) for 2D and 3D textures. The level is the last address register (third for contiguous 2D, fourth for 3D, last element of an NSA list). Offset (_o), compare, gather, cube and unorm forms are refused with an Unsupported message. Previously the translator refused every image_sample_l. No related open issue or PR found (checked sample/gfx2hlsl in open PRs).

AI-assisted.

Verification

  • python3 -B tests/startup_image_sample_l_check.py: passes with the change; on origin/main it fails (Unsupported: image_sample_l).
  • python3 -B tests/startup_image_sample_l_check.py binary llvm-mc-19: fixture words match (CI runs it with llvm-mc-15).
  • Negative controls, each fails the check: level replaced by 0; implicit Sample instead of SampleLevel; level taken from the third register in every form (fails on the NSA and 3D fixtures).
  • python3 -B tests/startup_sampler_heap_check.py, tests/startup_uniform_lane_check.py, tests/docs_links_check.py: pass.
  • Not run: any Windows, WARP or hardware run.

PR fuori preset pr: ctest -R "^startup_image_sample_l$" on the Windows node (pure Python translation check, no GPU).

Evidence and follow-up

  • Fixtures are source-built gfx1013 assembly, original to this repo; words are checked against llvm-mc.
  • The level selection is verified on the generated HLSL text only. Open: a WARP readback that samples an explicit mip level different from the implicit one (needs a new offscreen_check mode with a coloured-mip texture).
  • Docs: docs/experiments.md, docs/startup-runtime.md.

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.
**@⁠tedin7** on GitHub · 2026-11-24 05:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258) `tedin7:x2w-gfx2hlsl-image-sample-l-explicit-lod` → `main` · +296 −3 · 7 files · 5 commits · merged 2026-11-24 06:09 UTC ## Change Lowers the gfx1013 `image_sample_l` form (explicit level of detail) in `tools/startup/gfx2hlsl.py` to `tex.SampleLevel(smp, uv, level)` for 2D and 3D textures. The level is the last address register (third for contiguous 2D, fourth for 3D, last element of an NSA list). Offset (`_o`), compare, gather, cube and `unorm` forms are refused with an `Unsupported` message. Previously the translator refused every `image_sample_l`. No related open issue or PR found (checked `sample`/`gfx2hlsl` in open PRs). AI-assisted. ## Verification - `python3 -B tests/startup_image_sample_l_check.py`: passes with the change; on origin/main it fails (`Unsupported: image_sample_l`). - `python3 -B tests/startup_image_sample_l_check.py binary llvm-mc-19`: fixture words match (CI runs it with llvm-mc-15). - Negative controls, each fails the check: level replaced by 0; implicit `Sample` instead of `SampleLevel`; level taken from the third register in every form (fails on the NSA and 3D fixtures). - `python3 -B tests/startup_sampler_heap_check.py`, `tests/startup_uniform_lane_check.py`, `tests/docs_links_check.py`: pass. - Not run: any Windows, WARP or hardware run. PR fuori preset pr: `ctest -R "^startup_image_sample_l$"` on the Windows node (pure Python translation check, no GPU). ## Evidence and follow-up - Fixtures are source-built gfx1013 assembly, original to this repo; words are checked against llvm-mc. - The level selection is verified on the generated HLSL text only. Open: a WARP readback that samples an explicit mip level different from the implicit one (needs a new `offscreen_check` mode with a coloured-mip texture). - Docs: `docs/experiments.md`, `docs/startup-runtime.md`. ## 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:53:04 +00:00
github manually merged commit 7fb2c8938b into gh-pr/1258/base 2026-11-26 22:53:06 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:47 UTC · original · edited 2026-11-24 06:07 UTC

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-24T06:07:59.120253Z 7fb2c89 Manual request
ℹ️ 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#issuecomment-7123272098) · edited 2026-11-24 06:07 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7fb2c8938b2b1991a04c8fb317f3a1ea1114e64a","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-24T06:07:59.120253Z">2026-11-24T06:07:59.120253Z</relative-time> | `7fb2c89` | Manual request | <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>
@ -683,0 +689,4 @@
# layout and are refused by name.
for m in mods:
if not (m.startswith(('dim:', 'dmask:')) or m in ('dlc', 'glc', 'slc')):
raise Unsupported('image_sample_l modifier %s' % m)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:52 UTC · original

P2 Badge Reject packed A16 addresses before lowering

For a valid gfx1013 image_sample_l ... a16 instruction, the MIMG decoder in tools/disasm_rdna2.py currently omits the a16 modifier and reports a full-float address range, so this guard accepts the unsupported encoding. I reproduced a source address of v[0:1] ... a16 producing SampleLevel(q0, float2(F(v0), F(v1)), F(v2)): the packed FP16 coordinates are interpreted as FP32, and an unrelated register supplies the LOD. The parent commit rejects this instruction, whereas the new handler silently generates incorrect sampling code. Expose and reject the A16 modifier, or check its encoding bit before accepting this lowering, until packed addresses are implemented.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#discussion_r4676051509) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reject packed A16 addresses before lowering** For a valid gfx1013 `image_sample_l ... a16` instruction, the MIMG decoder in `tools/disasm_rdna2.py` currently omits the `a16` modifier and reports a full-float address range, so this guard accepts the unsupported encoding. I reproduced a source address of `v[0:1] ... a16` producing `SampleLevel(q0, float2(F(v0), F(v1)), F(v2))`: the packed FP16 coordinates are interpreted as FP32, and an unrelated register supplies the LOD. The parent commit rejects this instruction, whereas the new handler silently generates incorrect sampling code. Expose and reject the A16 modifier, or check its encoding bit before accepting this lowering, until packed addresses are implemented. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -683,0 +689,4 @@
# layout and are refused by name.
for m in mods:
if not (m.startswith(('dim:', 'dmask:')) or m in ('dlc', 'glc', 'slc')):
raise Unsupported('image_sample_l modifier %s' % m)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:54 UTC · original

Fixed in 544a0cb6

**@⁠tedin7** on GitHub · 2026-11-24 05:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#discussion_r4676062810) Fixed in 544a0cb6
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:54 UTC · original

Fixed in 544a0cb6: the MIMG decoder now prints a16 (word 1 bit 30), and image_sample_l refuses it. New fixture check fails on the old decoder, passes now. @⁠codex review

**@⁠tedin7** on GitHub · 2026-11-24 05:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#issuecomment-7123383648) Fixed in 544a0cb6: the MIMG decoder now prints a16 (word 1 bit 30), and image_sample_l refuses it. New fixture check fails on the old decoder, passes now. @⁠codex review
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:54 UTC · original

Verified on Windows Server 2025 (Build 26100, MSVC 14.44) at commit 5275bb337ea25e177c0548133e4b3703d7a5603c:

  • cmake --preset dev + ctest --preset dev -R "^startup_image_sample_l$": 1/1 passed (0.16s)
  • cmake --preset release + ctest --preset release -R "^startup_image_sample_l$": 1/1 passed (0.15s)
  • python -B tests/startup_image_sample_l_check.py: exit 0
**@⁠tedin7** on GitHub · 2026-11-24 05:54 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#issuecomment-7123385307) Verified on Windows Server 2025 (Build 26100, MSVC 14.44) at commit `5275bb337ea25e177c0548133e4b3703d7a5603c`: - `cmake --preset dev` + `ctest --preset dev -R "^startup_image_sample_l$"`: 1/1 passed (0.16s) - `cmake --preset release` + `ctest --preset release -R "^startup_image_sample_l$"`: 1/1 passed (0.15s) - `python -B tests/startup_image_sample_l_check.py`: exit 0
@ -683,0 +689,4 @@
# layout and are refused by name.
for m in mods:
if not (m.startswith(('dim:', 'dmask:')) or m in ('dlc', 'glc', 'slc')):
raise Unsupported('image_sample_l modifier %s' % m)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:58 UTC · original

P2 Badge Reject TFE encodings before lowering explicit-LOD samples

For a valid image_sample_l ... dmask:0x1 ... tfe, the decoder still omits TFE (word 0 bit 16), so this modifier whitelist accepts an encoding whose extra status result is not modeled. A source-built gfx1013 sample with destination v[4:5] translates to an assignment to v4 only; a subsequent check of the status in v5 therefore reads its previous value instead of the sample status. The parent rejected this instruction. Expose and reject tfe, or inspect its encoding bit, until the extra result is lowered.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#discussion_r4676097633) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reject TFE encodings before lowering explicit-LOD samples** For a valid `image_sample_l ... dmask:0x1 ... tfe`, the decoder still omits TFE (word 0 bit 16), so this modifier whitelist accepts an encoding whose extra status result is not modeled. A source-built gfx1013 sample with destination `v[4:5]` translates to an assignment to `v4` only; a subsequent check of the status in `v5` therefore reads its previous value instead of the sample status. The parent rejected this instruction. Expose and reject `tfe`, or inspect its encoding bit, until the extra result is lowered. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -683,0 +689,4 @@
# layout and are refused by name.
for m in mods:
if not (m.startswith(('dim:', 'dmask:')) or m in ('dlc', 'glc', 'slc')):
raise Unsupported('image_sample_l modifier %s' % m)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:59 UTC · original

Fixed in 30fa57b4

**@⁠tedin7** on GitHub · 2026-11-24 05:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#discussion_r4676105318) Fixed in 30fa57b4
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:59 UTC · original

Fixed in 30fa57b4: the MIMG decoder now prints tfe (word 0 bit 16) and image_sample_l refuses it; new fixture fails on the old decoder. @⁠codex review

**@⁠tedin7** on GitHub · 2026-11-24 05:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#issuecomment-7123471429) Fixed in 30fa57b4: the MIMG decoder now prints tfe (word 0 bit 16) and image_sample_l refuses it; new fixture fails on the old decoder. @⁠codex review
@ -683,0 +689,4 @@
# layout and are refused by name.
for m in mods:
if not (m.startswith(('dim:', 'dmask:')) or m in ('dlc', 'glc', 'slc')):
raise Unsupported('image_sample_l modifier %s' % m)
Author
Owner

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

Fixed in 7fb2c893 (tfe plus every other unmodelled MIMG bit: lwe, d16, r128, unorm, reserved bits, non-2D/3D dims; one llvm-mc-built negative fixture each).

**@⁠tedin7** on GitHub · 2026-11-24 06:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#discussion_r4676128496) Fixed in 7fb2c893 (tfe plus every other unmodelled MIMG bit: lwe, d16, r128, unorm, reserved bits, non-2D/3D dims; one llvm-mc-built negative fixture each).
Author
Owner

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

AI-assisted update (7fb2c893): image_sample_l now refuses every MIMG bit and form the lowering does not model, and the disassembler decodes lwe from its real bit 17. Merged current main (SDWA and image-3d entries kept). Local checks: startup_image_sample_l_check.py (controls and llvm-mc-19 fixture words) and startup_gfx2hlsl_sdwa_check.py pass; the new negative fixtures fail on the previous code. @⁠codex review

**@⁠tedin7** on GitHub · 2026-11-24 06:03 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#issuecomment-7123531798) AI-assisted update (7fb2c893): image_sample_l now refuses every MIMG bit and form the lowering does not model, and the disassembler decodes lwe from its real bit 17. Merged current main (SDWA and image-3d entries kept). Local checks: startup_image_sample_l_check.py (controls and llvm-mc-19 fixture words) and startup_gfx2hlsl_sdwa_check.py pass; the new negative fixtures fail on the previous code. @⁠codex review
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 06:07 UTC · original

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 7fb2c8938b

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 06:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#issuecomment-7123616586) <!-- codex-review-receipt:v1 --> Codex Review: Didn't find any major issues. :rocket: **Reviewed commit:** `7fb2c8938b` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
Author
Owner

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

Verified on Windows Server 2025 (Build 26100, MSVC 14.44, D3D12 WARP) at 7fb2c893:

  • cmake --preset dev + ctest --preset dev -R "^(startup_image_sample_l|startup_gfx2hlsl_sdwa)$" — 2/2 PASS (startup_image_sample_l 0.16s, startup_gfx2hlsl_sdwa 0.39s)
  • cmake --preset release (/O2) + ctest --preset release -R "^(startup_image_sample_l|startup_gfx2hlsl_sdwa)$" — 2/2 PASS (startup_image_sample_l 0.17s, startup_gfx2hlsl_sdwa 0.41s)
  • python -B tests/startup_image_sample_l_check.py — exit 0
  • python -B tests/startup_gfx2hlsl_sdwa_check.py — exit 0 (PASS)
**@⁠tedin7** on GitHub · 2026-11-24 06:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#issuecomment-7123626383) Verified on Windows Server 2025 (Build 26100, MSVC 14.44, D3D12 WARP) at `7fb2c893`: - `cmake --preset dev` + `ctest --preset dev -R "^(startup_image_sample_l|startup_gfx2hlsl_sdwa)$"` — **2/2 PASS** (`startup_image_sample_l` `0.16s`, `startup_gfx2hlsl_sdwa` `0.39s`) - `cmake --preset release` (`/O2`) + `ctest --preset release -R "^(startup_image_sample_l|startup_gfx2hlsl_sdwa)$"` — **2/2 PASS** (`startup_image_sample_l` `0.17s`, `startup_gfx2hlsl_sdwa` `0.41s`) - `python -B tests/startup_image_sample_l_check.py` — **exit 0** - `python -B tests/startup_gfx2hlsl_sdwa_check.py` — **exit 0** (`PASS`)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:52 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5275bb337e

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#pullrequestreview-6034348567) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `5275bb337e` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:58 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 544a0cb6f6

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1258#pullrequestreview-6034403674) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `544a0cb6f6` <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". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This discussion has been locked. Commenting is limited to contributors.
No description provided.