shader: lower explicit-level image sampling in sampled coverage #1343

Merged
tedin7 merged 1 commit from upstream-pr/1350 into main 2026-11-24 09:25:47 +00:00
tedin7 commented 2026-11-24 08:57:29 +00:00 (Migrated from github.com)

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


Change

Lowers image_sample_l (explicit level of detail) in tools/sampled_coverage_aot.py to SampleLevel(samp,uv,<level>). The level is the third address register, v[u:lod], and must be a register copied by v_mov_b32_e32 vN, sM from a buffered float that the program loaded and waited for. Inline constants, literals, vector or special-register sources, non-float scalars, the VOP3 move and a level that was never defined are refused, as are the sample forms already refused for image_sample and image_sample_lz (tfe, lwe, a16, d16, r128, unorm, glc, slc, dlc, multi-channel dmask, 3D, 2D array, da, offset variants). docs/experiments.md is updated. No existing lowering changes.

This work was AI-assisted.

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 Linux (LLVM 19; LLVM 15 not available locally).
  • python3 -B tests/rdna2_tools_check.py: 138 tests OK (18 skipped).
  • Negative control: the same test run against tools/sampled_coverage_aot.py from origin/main fails (Unsupported coverage instruction v_mov_b32_e32). Mutating the new lowering to ignore the level, to emit the implicit Sample, or to read the level from the wrong address register each makes the controls fail.
  • Not run: the WARP readback (no Windows adapter here). The fixture repeats the first readback with an image_sample_l program whose level word is 3 (past the single mip, so it clamps to mip 0).

PR outside --preset pr: sampled_coverage_warp.

Evidence and follow-up

  • Fixtures are source-built synthetic programs, assembled with llvm-mc for gfx1013.
  • The CPU reference reads the emitted SampleLevel argument against distinct constants and requires it to equal the buffered word the load addresses, for four words and both textures; image_sample_lz and the implicit opcode must not read that word.
  • Missing: a readback with a real mip chain. The fixture renderer builds a single mip, so the mip selected by an explicit level is checked at the translation level only. Follow-up: give the sampled coverage renderer a mip chain of distinct alpha values.

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:6578174328 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1350). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T08:57:29Z. --- ## Change Lowers `image_sample_l` (explicit level of detail) in `tools/sampled_coverage_aot.py` to `SampleLevel(samp,uv,<level>)`. The level is the third address register, `v[u:lod]`, and must be a register copied by `v_mov_b32_e32 vN, sM` from a buffered float that the program loaded and waited for. Inline constants, literals, vector or special-register sources, non-float scalars, the VOP3 move and a level that was never defined are refused, as are the sample forms already refused for `image_sample` and `image_sample_lz` (`tfe`, `lwe`, `a16`, `d16`, `r128`, `unorm`, `glc`, `slc`, `dlc`, multi-channel `dmask`, 3D, 2D array, `da`, offset variants). `docs/experiments.md` is updated. No existing lowering changes. This work was AI-assisted. ## 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 Linux (LLVM 19; LLVM 15 not available locally). - `python3 -B tests/rdna2_tools_check.py`: 138 tests OK (18 skipped). - Negative control: the same test run against `tools/sampled_coverage_aot.py` from origin/main fails (`Unsupported coverage instruction v_mov_b32_e32`). Mutating the new lowering to ignore the level, to emit the implicit `Sample`, or to read the level from the wrong address register each makes the controls fail. - Not run: the WARP readback (no Windows adapter here). The fixture repeats the first readback with an `image_sample_l` program whose level word is 3 (past the single mip, so it clamps to mip 0). PR outside `--preset pr`: `sampled_coverage_warp`. ## Evidence and follow-up - Fixtures are source-built synthetic programs, assembled with `llvm-mc` for gfx1013. - The CPU reference reads the emitted `SampleLevel` argument against distinct constants and requires it to equal the buffered word the load addresses, for four words and both textures; `image_sample_lz` and the implicit opcode must not read that word. - Missing: a readback with a real mip chain. The fixture renderer builds a single mip, so the mip selected by an explicit level is checked at the translation level only. Follow-up: give the sampled coverage renderer a mip chain of distinct alpha values. ## 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 09:04:48 +00:00 (Migrated from github.com)

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


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

  • Debug (--preset dev): offscreen_check build 5.22s; ctest --preset dev -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure: 1/1 passed (11.06s)
  • Release /O2 (--preset release): offscreen_check build 3.06s; ctest --preset release -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure: 1/1 passed (10.78s)
<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7126875589 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1350#issuecomment-7126875589). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T09:02:15Z. --- Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit `7f3b070f43d3a8d1f9eecac38e59320d61df52ba`: - **Debug (`--preset dev`)**: `offscreen_check` build `5.22s`; `ctest --preset dev -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure`: **1/1 passed** (`11.06s`) - **Release `/O2` (`--preset release`)**: `offscreen_check` build `3.06s`; `ctest --preset release -R '^sampled_coverage_warp$' --no-tests=error --output-on-failure`: **1/1 passed** (`10.78s`)
chatgpt-codex-connector[bot commented 2026-11-24 09:04:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T09:02:25Z.


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-24T09:08:02.557275Z 7f3b070 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:7126879250 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1350#issuecomment-7126879250). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T09:02:25Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"7f3b070f43d3a8d1f9eecac38e59320d61df52ba","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-24T09:08:02.557275Z">2026-11-24T09:08:02.557275Z</relative-time> | `7f3b070` | 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 10:02:26 +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!1343
No description provided.