shader: lower image_sample_b with a buffered bias #1373

Merged
tedin7 merged 1 commit from upstream-pr/1380 into main 2026-11-24 10:33:15 +00:00
tedin7 commented 2026-11-24 09:57:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:57:56Z.


Change

Adds image_sample_b (2D, single channel, explicit bias) to tools/sampled_coverage_aot.py. It lowers to tex{N}.SampleBias(samp,uv,{bias}).{channel}. The pixel shader this translator emits is a PS, where SampleBias is available. The bias must be a buffered float copied with v_mov_b32_e32 vN, sM into the first address register, like the level of image_sample_l. Refs the sampled-coverage translator work (#1350, merged).

Register order: the address list is v[bias:u] (bias, s, t), not v[u:bias]. The assembler cannot show this, because both orders print the same range. It was checked against LLVM's own lowering of the llvm.amdgcn.image.sample.b.2d intrinsic with llc-19 -mcpu=gfx1013. With the arguments passed in a different order, the bias argument lands in the first register of the address list. Only the bias-first order is accepted; a bias as the third register is refused.

Refused, as for image_sample_l: tfe, lwe, a16, d16, r128, unorm, glc, slc, dlc, multi-channel dmask, 3D, array, _o offsets, image_sample_b_cl, image_sample_c_b, a bias that is undefined, defined in another register, defined before the scalar load is waited for, a VOP3 move, an inline constant, a literal, a vector or special register source, or a non-float scalar.

AI-assisted. Two files of tooling plus docs: tools/sampled_coverage_aot.py, tests/sampled_coverage_check.py, docs/experiments.md. The disassembler already decodes image_sample_b, so it is untouched.

Verification

  • python3 -B tests/sampled_coverage_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM.so.19.1: exit 0 on this branch.
  • Same test file against origin/main's translator: fails (Unsupported coverage instruction image_sample_b).
  • Mutations of the new translator each fail the test: first-register rule changed to last, SampleBias replaced by SampleLevel, coordinates read from the first two registers.
  • tests/rdna2_tools_check.py (139 tests OK), tests/docs_links_check.py, tests/bidi_controls_check.py: pass.
  • LLVM 15 is not installed on this machine, so the LLVM 15 spelling was not checked here; the Windows workflow runs the binary step with LLVM 15.
  • Windows WARP readback not run by the author. Outside the pr preset: sampled_coverage_warp (needs offscreen_check).

Evidence and follow-up

  • Fixture is synthetic, assembled from source text in the test; no game data.
  • Limitation, as in #1350: the fixture renderer builds a single mip, so the bias cannot change the result on a GPU. The readback uses a bias word of 3 (mip 0 either way) and checks that a reference for the other texture fails. The bias value and opcode are checked at the translation level: the SampleBias argument is evaluated against distinct constants by a separate reader for each of four buffered words, and the biased program is told apart from the same registers read as implicit, zero-level and explicit-level samples.
  • A readback with a mip chain would need renderer work and can be a follow-up.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6579206202 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1380). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:57:56Z. --- ## Change Adds `image_sample_b` (2D, single channel, explicit bias) to `tools/sampled_coverage_aot.py`. It lowers to `tex{N}.SampleBias(samp,uv,{bias}).{channel}`. The pixel shader this translator emits is a PS, where `SampleBias` is available. The bias must be a buffered float copied with `v_mov_b32_e32 vN, sM` into the first address register, like the level of `image_sample_l`. Refs the sampled-coverage translator work (#1350, merged). Register order: the address list is `v[bias:u]` (bias, s, t), not `v[u:bias]`. The assembler cannot show this, because both orders print the same range. It was checked against LLVM's own lowering of the `llvm.amdgcn.image.sample.b.2d` intrinsic with `llc-19 -mcpu=gfx1013`. With the arguments passed in a different order, the bias argument lands in the first register of the address list. Only the bias-first order is accepted; a bias as the third register is refused. Refused, as for `image_sample_l`: tfe, lwe, a16, d16, r128, unorm, glc, slc, dlc, multi-channel dmask, 3D, array, `_o` offsets, `image_sample_b_cl`, `image_sample_c_b`, a bias that is undefined, defined in another register, defined before the scalar load is waited for, a VOP3 move, an inline constant, a literal, a vector or special register source, or a non-float scalar. AI-assisted. Two files of tooling plus docs: `tools/sampled_coverage_aot.py`, `tests/sampled_coverage_check.py`, `docs/experiments.md`. The disassembler already decodes `image_sample_b`, so it is untouched. ## Verification - `python3 -B tests/sampled_coverage_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM.so.19.1`: exit 0 on this branch. - Same test file against origin/main's translator: fails (`Unsupported coverage instruction image_sample_b`). - Mutations of the new translator each fail the test: first-register rule changed to last, `SampleBias` replaced by `SampleLevel`, coordinates read from the first two registers. - `tests/rdna2_tools_check.py` (139 tests OK), `tests/docs_links_check.py`, `tests/bidi_controls_check.py`: pass. - LLVM 15 is not installed on this machine, so the LLVM 15 spelling was not checked here; the Windows workflow runs the binary step with LLVM 15. - Windows WARP readback not run by the author. Outside the `pr` preset: `sampled_coverage_warp` (needs `offscreen_check`). ## Evidence and follow-up - Fixture is synthetic, assembled from source text in the test; no game data. - Limitation, as in #1350: the fixture renderer builds a single mip, so the bias cannot change the result on a GPU. The readback uses a bias word of 3 (mip 0 either way) and checks that a reference for the other texture fails. The bias value and opcode are checked at the translation level: the `SampleBias` argument is evaluated against distinct constants by a separate reader for each of four buffered words, and the biased program is told apart from the same registers read as implicit, zero-level and explicit-level samples. - A readback with a mip chain would need renderer work and can be a follow-up. ## 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.
tedin7 commented 2026-11-24 10:02:43 +00:00 (Migrated from github.com)

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


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

  • Debug (--preset dev): offscreen_check build 3.24s; ctest --preset dev -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure: 1/1 passed (11.55s)
  • Release /O2 (--preset release): offscreen_check build 0.77s; ctest --preset release -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure: 1/1 passed (11.11s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7128201428 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1380#issuecomment-7128201428). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T10:01:11Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `6963edab65a32b5ddd0f346c9de9f0d14386459b`: - **Debug (`--preset dev`)**: `offscreen_check` build `3.24s`; `ctest --preset dev -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure`: **1/1 passed** (`11.55s`) - **Release `/O2` (`--preset release`)**: `offscreen_check` build `0.77s`; `ctest --preset release -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure`: **1/1 passed** (`11.11s`)
chatgpt-codex-connector[bot commented 2026-11-24 10:02:43 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T10:01:20Z.


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-24T10:05:33.154088Z 6963eda 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:7128205172 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1380#issuecomment-7128205172). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T10:01:20Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6963edab65a32b5ddd0f346c9de9f0d14386459b","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-24T10:05:33.154088Z">2026-11-24T10:05:33.154088Z</relative-time> | `6963eda` | 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>
upstream-sync closed this pull request 2026-11-24 11:02:42 +00:00
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!1373
No description provided.