shader: lower image_sample_l and image_sample_b in gfx2hlsl (Part of #1723) #2045

Closed
github-bot wants to merge 4 commits from gh-pr/2045/head into gh-pr/2045/base
Owner

@⁠tedin7 on GitHub · 2026-11-24 23:37 UTC · original
tedin7:x2w-r21-sample-lb → main · +242 −5 · 3 files · 4 commits · closed without merging

Part of #1723

What this unblocks: startup pixel shaders that use biased sampling (image_sample_b) now translate to SampleBias instead of stopping at "Unsupported".

image_sample_l was already lowered on main, so this change adds only image_sample_b.

Change

  • tools/startup/gfx2hlsl.py: image_sample_b shares the image_sample_l address handling. The bias is the last address register (after u, v and the slice or z). It becomes Texture.SampleBias(sampler, uv, bias).
    • The bias needs the implicit level, so outside straight-line pixel code with a known active lane it is refused by name. It is never sampled at level zero with the bias dropped.
    • Only dim, dmask and cache-policy bits (glc, slc, dlc) are accepted. unorm, a16, tfe, lwe, d16, r128, an empty dmask, 1D and cube are refused. Refusal messages name the real opcode.
    • The image_sample_l messages are unchanged.
  • tests/startup_image_sample_b_check.py, registered in CMakeLists.txt as startup_image_sample_b: reuses the recorded image_sample_l stages with only the MIMG opcode changed (0x24 to 0x25). It checks the bias register for 2D, NSA, 3D and 2D array, and the refusals.

Verification

Run on the Linux worker (Python only, no GPU):

  • python3 -B tests/startup_image_sample_b_check.py on origin/main: fails (Unsupported: image_sample_b).
  • Same command with this change: startup_image_sample_b_check: ok.
  • python3 -B tests/startup_image_sample_l_check.py: PASS.
  • python3 -B tests/startup_image_sample_c_check.py, startup_image_sample_a16_check.py, startup_image_gather_lz_check.py, startup_sampler_heap_check.py: PASS.

Not run: Win2025 GPU/D3D12 commands. The new test is Python only, and tests/pixel_sample_lod_check.py already covers the bias on D3D12 for the other translator.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 23:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045) `tedin7:x2w-r21-sample-lb` → `main` · +242 −5 · 3 files · 4 commits · closed without merging Part of #1723 What this unblocks: startup pixel shaders that use biased sampling (`image_sample_b`) now translate to `SampleBias` instead of stopping at "Unsupported". `image_sample_l` was already lowered on main, so this change adds only `image_sample_b`. ## Change - `tools/startup/gfx2hlsl.py`: `image_sample_b` shares the `image_sample_l` address handling. The bias is the last address register (after u, v and the slice or z). It becomes `Texture.SampleBias(sampler, uv, bias)`. - The bias needs the implicit level, so outside straight-line pixel code with a known active lane it is refused by name. It is never sampled at level zero with the bias dropped. - Only dim, dmask and cache-policy bits (glc, slc, dlc) are accepted. unorm, a16, tfe, lwe, d16, r128, an empty dmask, 1D and cube are refused. Refusal messages name the real opcode. - The `image_sample_l` messages are unchanged. - `tests/startup_image_sample_b_check.py`, registered in `CMakeLists.txt` as `startup_image_sample_b`: reuses the recorded `image_sample_l` stages with only the MIMG opcode changed (0x24 to 0x25). It checks the bias register for 2D, NSA, 3D and 2D array, and the refusals. ## Verification Run on the Linux worker (Python only, no GPU): - `python3 -B tests/startup_image_sample_b_check.py` on `origin/main`: fails (`Unsupported: image_sample_b`). - Same command with this change: `startup_image_sample_b_check: ok`. - `python3 -B tests/startup_image_sample_l_check.py`: PASS. - `python3 -B tests/startup_image_sample_c_check.py`, `startup_image_sample_a16_check.py`, `startup_image_gather_lz_check.py`, `startup_sampler_heap_check.py`: PASS. Not run: Win2025 GPU/D3D12 commands. The new test is Python only, and `tests/pixel_sample_lod_check.py` already covers the bias on D3D12 for the other translator. AI-assisted; commands listed were executed locally.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:52:02 +00:00
github-bot closed this pull request 2026-11-26 23:52:02 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:37 UTC · original · edited 2026-11-24 23:42 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-24T23:42:24.692144Z f97aa96 PR opened
ℹ️ 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 23:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#issuecomment-7147619899) · edited 2026-11-24 23:42 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"f97aa96eaf16704e9362a8a0d2e2f266d0027f20","has_any_findings":true,"has_unresolved_findings":true,"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-24T23:42:24.692144Z">2026-11-24T23:42:24.692144Z</relative-time> | `f97aa96` | PR opened | <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>
Author
Owner

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

P1 Badge Read the image_sample_b bias from the first address register

For gfx1013 image_sample_b, the address layout is (bias, u, v[, z/slice]), not coordinates followed by bias; the existing lowering in tools/pixel_aot.py:4507–4514 also uses this order. The new plain fixture should therefore sample (v1, v2) with bias v0, but this shared extraction emits (v0, v1) with bias v2. Newly accepted shaders consequently sample the wrong coordinates and mip, including the NSA, 3D, and array forms. Extract the first component for 'b' while retaining the last for 'l', and correct the new test assertions that currently enforce the wrong order.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#discussion_r4688109976) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Read the image_sample_b bias from the first address register** For gfx1013 `image_sample_b`, the address layout is `(bias, u, v[, z/slice])`, not coordinates followed by bias; the existing lowering in `tools/pixel_aot.py:4507–4514` also uses this order. The new `plain` fixture should therefore sample `(v1, v2)` with bias `v0`, but this shared extraction emits `(v0, v1)` with bias `v2`. Newly accepted shaders consequently sample the wrong coordinates and mip, including the NSA, 3D, and array forms. Extract the first component for `'b'` while retaining the last for `'l'`, and correct the new test assertions that currently enforce the wrong order. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -1894,2 +1906,4 @@
self.image(ops, mods, 'l')
def op_image_sample_b(self, ops, mods):
self.image(ops, mods, 'b')
Author
Owner

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

P1 Badge Document the new startup biased-sampling capability

Adding image_sample_b support changes a public translator capability, but this commit updates neither README.md nor docs/experiments.md, contrary to the root AGENTS.md requirement. The startup experiment documentation does not record this new path's supported dimensions, straight-line pixel-stage restriction, reproduction command, or Python-only verification status. Update the relevant startup experiment section so contributors can discover and reproduce the capability without relying on the commit message.

AGENTS.md reference: AGENTS.md:L211-L212

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 23:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#discussion_r4688109982) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new startup biased-sampling capability** Adding `image_sample_b` support changes a public translator capability, but this commit updates neither `README.md` nor `docs/experiments.md`, contrary to the root `AGENTS.md` requirement. The startup experiment documentation does not record this new path's supported dimensions, straight-line pixel-stage restriction, reproduction command, or Python-only verification status. Update the relevant startup experiment section so contributors can discover and reproduce the capability without relying on the commit message. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/f97aa96eaf16704e9362a8a0d2e2f266d0027f20/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠denn0x on GitHub · 2026-11-25 00:26 UTC · original

The bias is read from the wrong address register.

  • What the sources say. RDNA 2 ISA section 8.2.5 orders the MIMG address as { offset } { bias } { z-compare } { derivative } { body }, with the bias "One Dword float". The coordinates are the body, so the bias is the FIRST address register. That differs from image_sample_l, where the level is the last one. (#2051 also cites LLVM 15's sample_b intrinsic argument order to the same effect.)
  • What the PR does. With this PR, image_sample_b v[4:7], v[0:2], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D becomes SampleBias(smp, float2(v0, v1), v2). The correct lowering is SampleBias(smp, float2(v1, v2), v0).
  • Why the test passes anyway. tests/startup_image_sample_b_check.py asserts the last-register reading (bias_register(...) == ('v0', 'v1', None, 'v2')), so it passes on the wrong semantics.
  • Overlap. #2051 covers the same item with the bias first, and also checks the NSA, array and 3D forms. I'd suggest keeping image_sample_l here only if it adds something #2051 and main do not already cover.
**@⁠denn0x** on GitHub · 2026-11-25 00:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#issuecomment-7148516114) The bias is read from the wrong address register. - **What the sources say.** RDNA 2 ISA section 8.2.5 orders the MIMG address as `{ offset } { bias } { z-compare } { derivative } { body }`, with the bias "One Dword float". The coordinates are the body, so the bias is the FIRST address register. That differs from `image_sample_l`, where the level is the last one. (#2051 also cites LLVM 15's `sample_b` intrinsic argument order to the same effect.) - **What the PR does.** With this PR, `image_sample_b v[4:7], v[0:2], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D` becomes `SampleBias(smp, float2(v0, v1), v2)`. The correct lowering is `SampleBias(smp, float2(v1, v2), v0)`. - **Why the test passes anyway.** `tests/startup_image_sample_b_check.py` asserts the last-register reading (`bias_register(...) == ('v0', 'v1', None, 'v2')`), so it passes on the wrong semantics. - **Overlap.** #2051 covers the same item with the bias first, and also checks the NSA, array and 3D forms. I'd suggest keeping `image_sample_l` here only if it adds something #2051 and main do not already cover.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:38 UTC · original

Fixed in 42becacd: image_sample_b now reads bias from the first address register per RDNA 2 ISA section 8.2.5, and the test was updated accordingly.

**@⁠tedin7** on GitHub · 2026-11-25 00:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#issuecomment-7148722931) Fixed in 42becacd: image_sample_b now reads bias from the first address register per RDNA 2 ISA section 8.2.5, and the test was updated accordingly.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:58 UTC · original

Fixed in fe23a5b3 (bias now read from the first address register; WARP draw test added in fff7d500, rebased on current main, push pending). Verified locally: tests/startup_image_sample_b_check.py and all startup_gfx2hlsl_*_check.py pass. AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 00:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#discussion_r4688736601) Fixed in fe23a5b3 (bias now read from the first address register; WARP draw test added in fff7d500, rebased on current main, push pending). Verified locally: tests/startup_image_sample_b_check.py and all startup_gfx2hlsl_*_check.py pass. AI-assisted; commands listed were executed locally.
@ -1894,2 +1906,4 @@
self.image(ops, mods, 'l')
def op_image_sample_b(self, ops, mods):
self.image(ops, mods, 'b')
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:58 UTC · original

Docs already cover this path in docs/experiments.md (startup section: image_sample_b, first-register bias, SampleBias lowering, 2D/single-channel/straight-line limits, refused forms). Nothing further needed in fff7d500. AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 00:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#discussion_r4688736835) Docs already cover this path in docs/experiments.md (startup section: image_sample_b, first-register bias, SampleBias lowering, 2D/single-channel/straight-line limits, refused forms). Nothing further needed in fff7d500. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 07:28 UTC · original

Closing as superseded: image_sample_b and image_sample_l are already on main via #2051.

**@⁠tedin7** on GitHub · 2026-11-25 07:28 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#issuecomment-7155893517) Closing as superseded: `image_sample_b` and `image_sample_l` are already on `main` via #2051.
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f97aa96eaf

ℹ️ 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 23:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2045#pullrequestreview-6049220939) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `f97aa96eaf` <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>

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.