shader: lower image_sample_d and document image_sample_c_d refusal in gfx2hlsl (Part of #1723) #2082

Manually merged
github merged 8 commits from gh-pr/2082/head into gh-pr/2082/base 2026-11-26 23:55:00 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-25 00:04 UTC · original
tedin7:x2w-r22-sample-d → main · +398 −3 · 5 files · 8 commits · merged 2026-11-25 23:49 UTC

Part of #1723

What this unblocks: gradient texture samples (image_sample_d) in startup shaders now lower to HLSL SampleGrad instead of stopping translation.

Lowering (tools/startup/gfx2hlsl.py):

  • image_sample_d takes ddx, then ddy (one register per axis each), then the coordinates: 2D = 6 registers, 2D array = 7 (slice last), 3D = 9 (a contiguous volume range is padded to 16 and trimmed to 9).
  • Emits Texture.SampleGrad(sampler, uv, ddx, ddy).
  • Refused by name: 1D, wrong address counts, empty dmask, and any modifier other than dim, dmask, glc, slc, dlc (for example tfe, a16, offsets).
  • image_sample_c_d is refused by name: it needs SampleCmpGrad, which is shader model 6.8 (same reason as image_sample_c_l).

Test: tests/startup_image_sample_d_check.py, registered as startup_image_sample_d in CMakeLists.txt. Fixture words come from llvm-mc and are re-checked by binary <llvm-mc>.

Verification:

  • Linux (not the Win2025 gate): python3 -B tests/startup_image_sample_d_check.py passes.
  • Linux: python3 -B tests/startup_image_sample_d_check.py binary /usr/bin/llvm-mc-19 passes (fixture words match).
  • Linux: startup_image_sample_l_check.py and startup_image_gather_lz_check.py still pass.
  • The new test fails on origin/main (no image_sample_d lowering).
  • Win2025 commands: NOT run. The new test is Python only; the Win2025 build and ctest -R startup_image_sample_d still need to be run.
**@⁠tedin7** on GitHub · 2026-11-25 00:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082) `tedin7:x2w-r22-sample-d` → `main` · +398 −3 · 5 files · 8 commits · merged 2026-11-25 23:49 UTC Part of #1723 What this unblocks: gradient texture samples (`image_sample_d`) in startup shaders now lower to HLSL `SampleGrad` instead of stopping translation. Lowering (`tools/startup/gfx2hlsl.py`): - `image_sample_d` takes ddx, then ddy (one register per axis each), then the coordinates: 2D = 6 registers, 2D array = 7 (slice last), 3D = 9 (a contiguous volume range is padded to 16 and trimmed to 9). - Emits `Texture.SampleGrad(sampler, uv, ddx, ddy)`. - Refused by name: 1D, wrong address counts, empty dmask, and any modifier other than `dim`, `dmask`, `glc`, `slc`, `dlc` (for example `tfe`, `a16`, offsets). - `image_sample_c_d` is refused by name: it needs `SampleCmpGrad`, which is shader model 6.8 (same reason as `image_sample_c_l`). Test: `tests/startup_image_sample_d_check.py`, registered as `startup_image_sample_d` in `CMakeLists.txt`. Fixture words come from llvm-mc and are re-checked by `binary <llvm-mc>`. Verification: - Linux (not the Win2025 gate): `python3 -B tests/startup_image_sample_d_check.py` passes. - Linux: `python3 -B tests/startup_image_sample_d_check.py binary /usr/bin/llvm-mc-19` passes (fixture words match). - Linux: `startup_image_sample_l_check.py` and `startup_image_gather_lz_check.py` still pass. - The new test fails on `origin/main` (no `image_sample_d` lowering). - Win2025 commands: NOT run. The new test is Python only; the Win2025 build and `ctest -R startup_image_sample_d` still need to be run.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:54:58 +00:00
github manually merged commit a40406ccbe into gh-pr/2082/base 2026-11-26 23:55:00 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:04 UTC · original · edited 2026-11-25 00:11 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-25T00:11:56.238904Z 23dc249 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-25 00:04 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#issuecomment-7148106465) · edited 2026-11-25 00:11 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"23dc24916e4fc5b16c05767c8a8990aacb9b5444","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-25T00:11:56.238904Z">2026-11-25T00:11:56.238904Z</relative-time> | `23dc249` | 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>
@ -5094,2 +5119,4 @@
self.image(ops, mods, 'b')
def op_image_sample_d(self, ops, mods):
self.image(ops, mods, 'd')
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:11 UTC · original

P1 Badge Document the new startup gradient-sampling capability

Adding image_sample_d support changes the startup translator's public capabilities, but neither the README nor docs/experiments.md is updated. The capability-documentation requirement in AGENTS.md calls for an update when this happens. Document the supported dimensions, refused forms and exact reproduction commands, distinguishing the verified Python translation checks from unverified D3D12 readback, so contributors can discover and reproduce the new capability without relying on the commit message or test source.

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

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#discussion_r4688389878) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the new startup gradient-sampling capability** Adding `image_sample_d` support changes the startup translator's public capabilities, but neither the README nor `docs/experiments.md` is updated. The capability-documentation requirement in `AGENTS.md` calls for an update when this happens. Document the supported dimensions, refused forms and exact reproduction commands, distinguishing the verified Python translation checks from unverified D3D12 readback, so contributors can discover and reproduce the new capability without relying on the commit message or test source. AGENTS.md reference: [AGENTS.md:L211-L212](https://github.com/R0Y00/Xbox2Windows/blob/23dc24916e4fc5b16c05767c8a8990aacb9b5444/AGENTS.md#L211-L212) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -4945,0 +4965,4 @@
if how == 'd':
axes = len(grads[0])
dx, dy = ['float%d(%s)' % (axes, ', '.join(self.f(r) for r in g)) for g in grads]
call = '%s.SampleGrad(%s, %s, %s, %s)' % (tex, smp, uv, dx, dy)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:11 UTC · original

P2 Badge Honor the guest LOD cap for gradient texture samples

For a mipmapped SRV with a guest sampler capped to MAX_LOD = 0, this newly accepted path can silently sample a higher mip. The startup binding's decode_sampler() in src/startup_stubs/translated_sampler_bindings.h:30-45 ignores sampler word 1 and unconditionally sets desktop MaxLOD to D3D12_FLOAT32_MAX, while this lowering passes the gradients directly to SampleGrad without compensating for that cap. For example, sampler words (0, 0, 0x04000000, 0) are accepted even though gradients selecting mip 2 must still return mip 0. Preserve the guest LOD cap in the desktop sampler or refuse unsupported capped samplers before accepting this instruction.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 00:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#discussion_r4688389888) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Honor the guest LOD cap for gradient texture samples** For a mipmapped SRV with a guest sampler capped to `MAX_LOD = 0`, this newly accepted path can silently sample a higher mip. The startup binding's `decode_sampler()` in `src/startup_stubs/translated_sampler_bindings.h:30-45` ignores sampler word 1 and unconditionally sets desktop `MaxLOD` to `D3D12_FLOAT32_MAX`, while this lowering passes the gradients directly to `SampleGrad` without compensating for that cap. For example, sampler words `(0, 0, 0x04000000, 0)` are accepted even though gradients selecting mip 2 must still return mip 0. Preserve the guest LOD cap in the desktop sampler or refuse unsupported capped samplers before accepting this instruction. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -5094,2 +5119,4 @@
self.image(ops, mods, 'b')
def op_image_sample_d(self, ops, mods):
self.image(ops, mods, 'd')
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:02 UTC · original

Documented in README.md and docs/experiments.md (new section: supported dims, refused forms, repro commands, translation-check vs unverified D3D12 readback). Fixed in f889ef76 (branch rb2082, pending push).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#discussion_r4688768084) Documented in README.md and docs/experiments.md (new section: supported dims, refused forms, repro commands, translation-check vs unverified D3D12 readback). Fixed in f889ef76 (branch rb2082, pending push). AI-assisted; commands listed were executed locally.
@ -4945,0 +4965,4 @@
if how == 'd':
axes = len(grads[0])
dx, dy = ['float%d(%s)' % (axes, ', '.join(self.f(r) for r in g)) for g in grads]
call = '%s.SampleGrad(%s, %s, %s, %s)' % (tex, smp, uv, dx, dy)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 01:02 UTC · original

gfx2hlsl now refuses image_sample_d unless the sampler is constant with MAX_LOD 0xfff (uncapped); a capped sampler such as words (0,0,0x04000000,0) is refused, with a test. Fixed in f889ef76 (branch rb2082, pending push).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 01:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#discussion_r4688768255) gfx2hlsl now refuses image_sample_d unless the sampler is constant with MAX_LOD 0xfff (uncapped); a capped sampler such as words (0,0,0x04000000,0) is refused, with a test. Fixed in f889ef76 (branch rb2082, pending push). AI-assisted; commands listed were executed locally.
@ -5094,2 +5119,4 @@
self.image(ops, mods, 'b')
def op_image_sample_d(self, ops, mods):
self.image(ops, mods, 'd')
Author
Owner

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

Re-checked on current head e0cf1d3a: image_sample_d is documented in docs/experiments.md, and the guest MAX_LOD cap is honored with a test (e0cf1d3a). Resolving. AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 11:01 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#discussion_r4693923509) Re-checked on current head e0cf1d3a: `image_sample_d` is documented in docs/experiments.md, and the guest MAX_LOD cap is honored with a test (e0cf1d3a). Resolving. AI-assisted; commands listed were executed locally.
@ -4945,0 +4965,4 @@
if how == 'd':
axes = len(grads[0])
dx, dy = ['float%d(%s)' % (axes, ', '.join(self.f(r) for r in g)) for g in grads]
call = '%s.SampleGrad(%s, %s, %s, %s)' % (tex, smp, uv, dx, dy)
Author
Owner

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

Re-checked on current head e0cf1d3a: image_sample_d is documented in docs/experiments.md, and the guest MAX_LOD cap is honored with a test (e0cf1d3a). Resolving. AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 11:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#discussion_r4693924099) Re-checked on current head e0cf1d3a: `image_sample_d` is documented in docs/experiments.md, and the guest MAX_LOD cap is honored with a test (e0cf1d3a). Resolving. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-25 13:52 UTC · original

Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is.

We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here.

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-25 13:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2082#issuecomment-7164410130) Closing this PR for now to keep the Windows test queue short. Nothing is wrong with it and the branch stays as it is. We will reopen it once the queue is clear, re-run the Win2025 WARP checks at its head, and post the result here. AI-assisted; commands listed were executed locally.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 00:11 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 23dc24916e

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