startup: keep the implicit LOD of a plain image_sample past a uniform join in gfx2hlsl #2691

Merged
tedin7 merged 6 commits from upstream-pr/2699 into main 2026-11-26 06:08:45 +00:00
tedin7 commented 2026-11-26 02:32:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:32:33Z.


Part of #1723

What this unblocks: a plain image_sample past a uniform branch or join in a pixel shader samples the mip the guest's derivatives pick, instead of always mip 0.

What changed

  • tools/startup/gfx2hlsl.py: after a block boundary a plain image_sample was lowered to SampleLevel(.., 0). It now lowers to the implicit-LOD Sample where the rule image_sample_b and image_get_lod already use holds: pixel stage, entry EXEC mask, wave-uniform control flow so far (uniform_cf), and no divergent back edge over the call (checked after the pass, like derivative_sites).
  • Everywhere else the call stays SampleLevel(.., 0) exactly as before. Nothing new is refused: a plain sample that translated before still translates.
  • tests/startup_image_sample_implicit_lod_check.py (registered as startup_image_sample_implicit_lod_controls): on the recorded c_lz fixture with the MIMG opcode set to image_sample: straight line, s_cbranch_scc0 and a uniform join give Sample; divergent EXEC, s_cbranch_vccz/vccnz/execz/execnz before the call, and a divergent back edge over it stay level 0.

Why it is correct
A plain image_sample takes its LOD from the coordinate derivatives of the pixel quad (RDNA 2 ISA, MIMG sample). HLSL Sample does the same. The quad runs the call together exactly when image_sample_b / image_get_lod are accepted today, so the same condition decides it here.

What stays level 0
Shaders whose EXEC is no longer the entry mask (for example the s_wqm bracket an LLVM-built pixel shader puts around a sample) and divergent control flow. Those need their own proof and are not changed here.

Verification:

  • python3 tests/startup_image_sample_implicit_lod_check.py: passes on this branch; on origin/main (fa189d2ef) it fails at the branch case (SampleLevel(.., 0)).
  • Sibling checks, unchanged and passing: startup_image_sample_b_check.py, startup_gfx2hlsl_image_get_lod_check.py, startup_image_sample_lod_check.py, startup_inline_sampler_check.py, startup_image_sample_c_check.py.
  • All 107 tests/startup_gfx2hlsl*check*.py and tests/startup_*pixel*check*.py run on this branch and on origin/main: identical pass/fail (the same 2 draw checks, startup_gfx2hlsl_export_null_draw_check.py and startup_gfx2hlsl_mul24_align_draw_check.py, fail on both without the Windows draw runner).
  • GPU readback of the new path: tests/startup_image_sample_b_check.py (draw, registered as startup_image_sample_b_warp / _hardware) now draws the recorded array fixture with a uniform join before a plain image_sample. It must read mip 1 (the implicit LOD from the derivatives); the mip-0 expectation, what SampleLevel(.., 0) reads, must fail on the readback (negative control).
  • Win2025 (head 904f21e6 plus the commit that adds that readback, default 5-slot pool), python3 x2w_pipe.py win2025 2699 --patch <diff> --no-skip-build --regex 'startup_image_sample_b|startup_image_sample_implicit_lod|startup_gfx2hlsl_image_get_lod|startup_image_sample_lod|startup_inline_sampler': dev 10/10 and release 10/10 passed (startup_image_sample_b_warp / _hardware, startup_image_sample_lod_warp / _hardware, startup_inline_sampler_warp / _hardware and the controls). An earlier run without a fresh build failed at the existing sample_b and sample_lod draws with "Expected one inline sampler in the image 3D draw" (a stale draw executable on the node, also in the untouched sample_lod draw); startup_image_sample_implicit_lod_controls passed in that run (11/11 controls and inline-sampler tests), and the rerun's slot did not list it.
  • Commands to paste: cmake --build --preset dev --target offscreen_check then ctest --preset dev --no-tests=error -R '^(startup_image_sample_b|startup_image_sample_implicit_lod|startup_image_sample_lod)' -V.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6618236242 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:32:33Z. --- Part of #1723 What this unblocks: a plain `image_sample` past a uniform branch or join in a pixel shader samples the mip the guest's derivatives pick, instead of always mip 0. What changed - `tools/startup/gfx2hlsl.py`: after a block boundary a plain `image_sample` was lowered to `SampleLevel(.., 0)`. It now lowers to the implicit-LOD `Sample` where the rule `image_sample_b` and `image_get_lod` already use holds: pixel stage, entry EXEC mask, wave-uniform control flow so far (`uniform_cf`), and no divergent back edge over the call (checked after the pass, like `derivative_sites`). - Everywhere else the call stays `SampleLevel(.., 0)` exactly as before. Nothing new is refused: a plain sample that translated before still translates. - `tests/startup_image_sample_implicit_lod_check.py` (registered as `startup_image_sample_implicit_lod_controls`): on the recorded `c_lz` fixture with the MIMG opcode set to `image_sample`: straight line, `s_cbranch_scc0` and a uniform join give `Sample`; divergent EXEC, `s_cbranch_vccz/vccnz/execz/execnz` before the call, and a divergent back edge over it stay level 0. Why it is correct A plain `image_sample` takes its LOD from the coordinate derivatives of the pixel quad (RDNA 2 ISA, MIMG sample). HLSL `Sample` does the same. The quad runs the call together exactly when `image_sample_b` / `image_get_lod` are accepted today, so the same condition decides it here. What stays level 0 Shaders whose EXEC is no longer the entry mask (for example the `s_wqm` bracket an LLVM-built pixel shader puts around a sample) and divergent control flow. Those need their own proof and are not changed here. Verification: - `python3 tests/startup_image_sample_implicit_lod_check.py`: passes on this branch; on `origin/main` (fa189d2ef) it fails at the `branch` case (`SampleLevel(.., 0)`). - Sibling checks, unchanged and passing: `startup_image_sample_b_check.py`, `startup_gfx2hlsl_image_get_lod_check.py`, `startup_image_sample_lod_check.py`, `startup_inline_sampler_check.py`, `startup_image_sample_c_check.py`. - All 107 `tests/startup_gfx2hlsl*check*.py` and `tests/startup_*pixel*check*.py` run on this branch and on `origin/main`: identical pass/fail (the same 2 draw checks, `startup_gfx2hlsl_export_null_draw_check.py` and `startup_gfx2hlsl_mul24_align_draw_check.py`, fail on both without the Windows draw runner). - GPU readback of the new path: `tests/startup_image_sample_b_check.py` (draw, registered as `startup_image_sample_b_warp` / `_hardware`) now draws the recorded array fixture with a uniform join before a plain `image_sample`. It must read mip 1 (the implicit LOD from the derivatives); the mip-0 expectation, what `SampleLevel(.., 0)` reads, must fail on the readback (negative control). - Win2025 (head 904f21e6 plus the commit that adds that readback, default 5-slot pool), `python3 x2w_pipe.py win2025 2699 --patch <diff> --no-skip-build --regex 'startup_image_sample_b|startup_image_sample_implicit_lod|startup_gfx2hlsl_image_get_lod|startup_image_sample_lod|startup_inline_sampler'`: dev 10/10 and release 10/10 passed (`startup_image_sample_b_warp` / `_hardware`, `startup_image_sample_lod_warp` / `_hardware`, `startup_inline_sampler_warp` / `_hardware` and the controls). An earlier run without a fresh build failed at the existing sample_b and sample_lod draws with "Expected one inline sampler in the image 3D draw" (a stale draw executable on the node, also in the untouched sample_lod draw); `startup_image_sample_implicit_lod_controls` passed in that run (11/11 controls and inline-sampler tests), and the rerun's slot did not list it. - Commands to paste: `cmake --build --preset dev --target offscreen_check` then `ctest --preset dev --no-tests=error -R '^(startup_image_sample_b|startup_image_sample_implicit_lod|startup_image_sample_lod)' -V`. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 03:03:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:02:40Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9cc7c38305

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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067982577 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#pullrequestreview-6067982577). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T03:02:40Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `9cc7c38305` <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>
tedin7 commented 2026-11-26 03:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:48:33Z.


Ready for review, @MasterDomino.

Added after the independent check: a WARP/hardware readback of the new path in startup_image_sample_b_check.py draw (plain image_sample after a uniform join reads mip 1; the mip-0 expectation must fail). Win2025 on head 904f21e6 plus that commit (9cc7c3830): dev 10/10 and release 10/10 passed with x2w_pipe.py win2025 2699 --patch <diff> --no-skip-build --regex <image sample tests>. Details are in the PR body.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181137686 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#issuecomment-7181137686). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:48:33Z. --- Ready for review, @MasterDomino. Added after the independent check: a WARP/hardware readback of the new path in `startup_image_sample_b_check.py` draw (plain `image_sample` after a uniform join reads mip 1; the mip-0 expectation must fail). Win2025 on head 904f21e6 plus that commit (9cc7c3830): dev 10/10 and release 10/10 passed with `x2w_pipe.py win2025 2699 --patch <diff> --no-skip-build --regex <image sample tests>`. Details are in the PR body. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 03:03:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T02:48:43Z.


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-26T03:02:43.205883Z 9cc7c38 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:7181140231 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#issuecomment-7181140231). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T02:48:43Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"9cc7c38305911cd54dd9500ea9a97ed317e8cabc","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-26T03:02:43.205883Z">2026-11-26T03:02:43.205883Z</relative-time> | `9cc7c38` | 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>
chatgpt-codex-connector[bot commented 2026-11-26 03:03:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T03:02:41Z.

Code review location: tools/startup/gfx2hlsl.py; line 2128

@@ -2116,6 +2116,23 @@ def emit(self, text):
                         self.sym.pop(107, None)
         self.lines.append(text)
 
+    def resolve_plain_samples(self):
+        """Writes each plain image_sample past a join into the blocks: the implicit-LOD Sample unless a divergent back
+        edge spans it (the same proof as image_sample_b / image_get_lod), else the level-0 call as before. It never
+        refuses: a plain sample that translated before still does."""
+        if not self.plain_samples:
+            return
+        choice = {}
+        for at, (level0, implicit) in self.plain_samples.items():
+            spanned = any(target <= at <= branch for target, branch in self.divergent_back_edges)
+            choice['X2W_PLAIN_SAMPLE<%x>' % at] = level0 if spanned else implicit

P2 Badge Account for forward divergent exits when checking loop safety

For a pixel loop shaped L: image_sample ...; ...; s_cbranch_vccnz exit; s_branch L, uniform_cf is still true when the sample is visited, and divergent_back_edges remains empty because the conditional edge is forward and the backward edge is unconditional. I reproduced this with a synthetic gfx1013 fixture containing a varying loop limit and UV updates: it now emits Sample where the parent emitted SampleLevel(..., 0). Since body() lowers the exit to a per-pixel pc branch, subsequent iterations can run on incomplete quads, making implicit derivatives undefined and mip selection unreliable. Check divergent CFG regions, including forward loop exits, before choosing the implicit call.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4703419293 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#discussion_r4703419293). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T03:02:41Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 2128 ~~~~diff @@ -2116,6 +2116,23 @@ def emit(self, text): self.sym.pop(107, None) self.lines.append(text) + def resolve_plain_samples(self): + """Writes each plain image_sample past a join into the blocks: the implicit-LOD Sample unless a divergent back + edge spans it (the same proof as image_sample_b / image_get_lod), else the level-0 call as before. It never + refuses: a plain sample that translated before still does.""" + if not self.plain_samples: + return + choice = {} + for at, (level0, implicit) in self.plain_samples.items(): + spanned = any(target <= at <= branch for target, branch in self.divergent_back_edges) + choice['X2W_PLAIN_SAMPLE<%x>' % at] = level0 if spanned else implicit ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Account for forward divergent exits when checking loop safety** For a pixel loop shaped `L: image_sample ...; ...; s_cbranch_vccnz exit; s_branch L`, `uniform_cf` is still true when the sample is visited, and `divergent_back_edges` remains empty because the conditional edge is forward and the backward edge is unconditional. I reproduced this with a synthetic gfx1013 fixture containing a varying loop limit and UV updates: it now emits `Sample` where the parent emitted `SampleLevel(..., 0)`. Since `body()` lowers the exit to a per-pixel `pc` branch, subsequent iterations can run on incomplete quads, making implicit derivatives undefined and mip selection unreliable. Check divergent CFG regions, including forward loop exits, before choosing the implicit call. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-26 04:04:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:47:49Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068285591 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#pullrequestreview-6068285591). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:47:49Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-26 04:04:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:48:48Z.


Independent re-check of the fix pushed after Ready (7ac50ab77, divergent_exit_loop), head 10c5bb0a4.

  • Counter-shapes: a divergent forward exit (vccnz/vccz/execz/execnz) with a loop closed by s_branch or by a uniform s_cbranch_scc* reads level 0; a loop whose exit and back edge are both uniform (scc proven by a compare) keeps the implicit-LOD Sample, so no precision is lost versus before the fix.
  • tests/startup_image_sample_implicit_lod_check.py fails on the parent of the fix (exit_7 reads Sample() and passes with it.
  • Win2025 (dev + release) on this head: x2w_pipe.py win2025 2699 --py-checks tests/startup_image_sample_implicit_lod_check.py --targets offscreen_check --regex 'startup_image_sample|implicit_lod|plain_sample': 19/19 passed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7182045467 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#issuecomment-7182045467). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:48:48Z. --- Independent re-check of the fix pushed after Ready (7ac50ab77, `divergent_exit_loop`), head 10c5bb0a4. - Counter-shapes: a divergent forward exit (vccnz/vccz/execz/execnz) with a loop closed by `s_branch` or by a uniform `s_cbranch_scc*` reads level 0; a loop whose exit and back edge are both uniform (scc proven by a compare) keeps the implicit-LOD `Sample`, so no precision is lost versus before the fix. - `tests/startup_image_sample_implicit_lod_check.py` fails on the parent of the fix (`exit_7` reads `Sample(`) and passes with it. - Win2025 (dev + release) on this head: `x2w_pipe.py win2025 2699 --py-checks tests/startup_image_sample_implicit_lod_check.py --targets offscreen_check --regex 'startup_image_sample|implicit_lod|plain_sample'`: 19/19 passed. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 04:04:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T03:47:49Z.

Code review location: tools/startup/gfx2hlsl.py; line 2128

@@ -2116,6 +2116,23 @@ def emit(self, text):
                         self.sym.pop(107, None)
         self.lines.append(text)
 
+    def resolve_plain_samples(self):
+        """Writes each plain image_sample past a join into the blocks: the implicit-LOD Sample unless a divergent back
+        edge spans it (the same proof as image_sample_b / image_get_lod), else the level-0 call as before. It never
+        refuses: a plain sample that translated before still does."""
+        if not self.plain_samples:
+            return
+        choice = {}
+        for at, (level0, implicit) in self.plain_samples.items():
+            spanned = any(target <= at <= branch for target, branch in self.divergent_back_edges)
+            choice['X2W_PLAIN_SAMPLE<%x>' % at] = level0 if spanned else implicit

Confirmed and fixed in 10c5bb0a4. A plain image_sample followed by a divergent forward exit (s_cbranch_vccnz / s_cbranch_execnz) in a loop closed by an unconditional s_branch back to it was lowered to Sample; it stays SampleLevel(.., 0) now. The loop-safety check (divergent_exit_loop) also looks at backward branches of any kind, unconditional ones included, that hold a wave-divergent branch.

Test: exit_7 and exit_9 cases in tests/startup_image_sample_implicit_lod_check.py (fail on the previous head with Sample, pass now). The existing straight/branch/join cases still lower to Sample.

Commands run:

  • python3 tests/startup_image_sample_implicit_lod_check.py, python3 tests/startup_image_sample_b_check.py
  • all tests/startup_gfx2hlsl_* scripts (same exit codes as before; the two *_draw_check scripts need a renderer argument)
  • Windows (WARP) on 10c5bb0a4: ctest --preset dev|release -R 'startup_image_sample|startup_gfx2hlsl_image' 24/24 on both presets

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4703668451 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#discussion_r4703668451). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T03:47:49Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 2128 ~~~~diff @@ -2116,6 +2116,23 @@ def emit(self, text): self.sym.pop(107, None) self.lines.append(text) + def resolve_plain_samples(self): + """Writes each plain image_sample past a join into the blocks: the implicit-LOD Sample unless a divergent back + edge spans it (the same proof as image_sample_b / image_get_lod), else the level-0 call as before. It never + refuses: a plain sample that translated before still does.""" + if not self.plain_samples: + return + choice = {} + for at, (level0, implicit) in self.plain_samples.items(): + spanned = any(target <= at <= branch for target, branch in self.divergent_back_edges) + choice['X2W_PLAIN_SAMPLE<%x>' % at] = level0 if spanned else implicit ~~~~ --- Confirmed and fixed in `10c5bb0a4`. A plain `image_sample` followed by a divergent forward exit (`s_cbranch_vccnz` / `s_cbranch_execnz`) in a loop closed by an unconditional `s_branch` back to it was lowered to `Sample`; it stays `SampleLevel(.., 0)` now. The loop-safety check (`divergent_exit_loop`) also looks at backward branches of any kind, unconditional ones included, that hold a wave-divergent branch. Test: `exit_7` and `exit_9` cases in `tests/startup_image_sample_implicit_lod_check.py` (fail on the previous head with `Sample`, pass now). The existing straight/branch/join cases still lower to `Sample`. Commands run: - `python3 tests/startup_image_sample_implicit_lod_check.py`, `python3 tests/startup_image_sample_b_check.py` - all `tests/startup_gfx2hlsl_*` scripts (same exit codes as before; the two `*_draw_check` scripts need a renderer argument) - Windows (WARP) on `10c5bb0a4`: `ctest --preset dev|release -R 'startup_image_sample|startup_gfx2hlsl_image'` 24/24 on both presets AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-26 06:02:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:54:34Z.


I resolved the main conflict in 05e3fdcd by sharing the DPP proof’s divergent-branch map. The control suites and FXC/DXC compilation pass for both a uniform join and a divergent loop exit. Before merging a change from explicit level zero to implicit LOD, please add one draw with distinct mip colors and derivatives that reliably choose a nonzero mip after the uniform join. The same shader with its generated Sample call forced to SampleLevel(..., 0) should read the mip-zero color. This will verify the behavior beyond the emitted call spelling.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7183914691 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#issuecomment-7183914691). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T05:54:34Z. --- I resolved the main conflict in 05e3fdcd by sharing the DPP proof’s divergent-branch map. The control suites and FXC/DXC compilation pass for both a uniform join and a divergent loop exit. Before merging a change from explicit level zero to implicit LOD, please add one draw with distinct mip colors and derivatives that reliably choose a nonzero mip after the uniform join. The same shader with its generated Sample call forced to SampleLevel(..., 0) should read the mip-zero color. This will verify the behavior beyond the emitted call spelling.
upstream-sync closed this pull request 2026-11-26 07:00:14 +00:00
R0Y00 commented 2026-11-26 07:00:14 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T06:08:33Z.

Review: APPROVED


The added CTest runs the generated gfx1013 pixel shader after a uniform join. A complete three-mip SRV and a nonzero-base SRV both selected physical mip 2 (RGBA words 3f020000). Forcing the otherwise identical Sample call to view-relative level zero selected physical mip 0 and physical mip 1 respectively (3c000000 and 3e840000). DXC and FXC both passed on Windows 11 build 26200, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. Debug warnings/errors were zero, and the Windows release configure registered the host and two draw checks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6069307678 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#pullrequestreview-6069307678). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T06:08:33Z. **Review:** APPROVED --- The added CTest runs the generated gfx1013 pixel shader after a uniform join. A complete three-mip SRV and a nonzero-base SRV both selected physical mip 2 (RGBA words 3f020000). Forcing the otherwise identical Sample call to view-relative level zero selected physical mip 0 and physical mip 1 respectively (3c000000 and 3e840000). DXC and FXC both passed on Windows 11 build 26200, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656. Debug warnings/errors were zero, and the Windows release configure registered the host and two draw checks.
MasterDomino commented 2026-11-26 07:00:27 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-26T06:25:12Z.


Post-merge note on #2699 (merged as 59218765), from a review that finished after the merge.

  1. Cache revision. This changed the HLSL of programs that already translate: a plain sample past a uniform branch or join went from SampleLevel(.., 0) to Sample(..), and the branch and join cases of the new check translate on the previous main. It landed at x2w-startup-shader-19, which #2708 had set four minutes earlier. Entries cached under 19 before this merge keep level 0 until the next graphics bump. #2723 and #2006 both need a bump to 20 anyway, so the first of them to land re-keys these entries too.
  2. @R0Y00's requested control. Locally, I replaced the generated .Sample( with .SampleLevel(..., 0) in the plain-join draw of startup_image_sample_b_check.py. WARP and the RX 9070 XT then read 3d800000,40400000,3f800000,00000000 (texel_cell(0, 0), the mip-0 colour), while the translated shader reads mip 1 (3e880000,3f800000,00000000,40000000). So the draw does tell the two apart, but the check's own negative control only flips the expectation. Adding that forced-level-0 shader to the check would pin it.
  3. Docs. The description says the s_wqm bracket stays level 0. After a uniform join, s_mov_b64 s[0:1], exec; s_wqm_b64 exec, exec; image_sample ...; s_and_b64 exec, exec, s[0:1] now emits Sample. That's fine, since WQM makes the derivatives valid, but the wording should match.

Checked and still level 0: divergent EXEC, a discard-style s_andn2_b64 exec, exec, vcc after the join, vcc/exec branches, divergent back edges, and divergent exits closed by s_branch or a uniform s_cbranch_scc0.

Pre-existing: the derivative_sites check for image_sample_b / image_get_lod still uses only divergent_back_edges, so the forward-exit loop shape Codex found likely applies to them as well.

Runs (Windows 11 build 26300; RX 9070 XT, driver 32.0.32029.2010; WARP 10.0.26100.9818): ctest --preset dev -R "startup_image_sample|startup_gfx2hlsl_image|startup_inline_sampler" -V 27/27 at 05e3fdcd.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7184410681 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2699#issuecomment-7184410681). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-26T06:25:12Z. --- Post-merge note on #2699 (merged as `59218765`), from a review that finished after the merge. 1. **Cache revision.** This changed the HLSL of programs that already translate: a plain sample past a uniform branch or join went from `SampleLevel(.., 0)` to `Sample(..)`, and the `branch` and `join` cases of the new check translate on the previous `main`. It landed at `x2w-startup-shader-19`, which #2708 had set four minutes earlier. Entries cached under `19` before this merge keep level 0 until the next graphics bump. #2723 and #2006 both need a bump to `20` anyway, so the first of them to land re-keys these entries too. 2. **@R0Y00's requested control.** Locally, I replaced the generated `.Sample(` with `.SampleLevel(..., 0)` in the plain-join draw of `startup_image_sample_b_check.py`. WARP and the RX 9070 XT then read `3d800000,40400000,3f800000,00000000` (`texel_cell(0, 0)`, the mip-0 colour), while the translated shader reads mip 1 (`3e880000,3f800000,00000000,40000000`). So the draw does tell the two apart, but the check's own negative control only flips the expectation. Adding that forced-level-0 shader to the check would pin it. 3. **Docs.** The description says the `s_wqm` bracket stays level 0. After a uniform join, `s_mov_b64 s[0:1], exec; s_wqm_b64 exec, exec; image_sample ...; s_and_b64 exec, exec, s[0:1]` now emits `Sample`. That's fine, since WQM makes the derivatives valid, but the wording should match. **Checked and still level 0:** divergent EXEC, a discard-style `s_andn2_b64 exec, exec, vcc` after the join, vcc/exec branches, divergent back edges, and divergent exits closed by `s_branch` or a uniform `s_cbranch_scc0`. **Pre-existing:** the `derivative_sites` check for `image_sample_b` / `image_get_lod` still uses only `divergent_back_edges`, so the forward-exit loop shape Codex found likely applies to them as well. Runs (Windows 11 build 26300; RX 9070 XT, driver 32.0.32029.2010; WARP 10.0.26100.9818): `ctest --preset dev -R "startup_image_sample|startup_gfx2hlsl_image|startup_inline_sampler" -V` 27/27 at `05e3fdcd`. AI-assisted; commands listed were executed locally.
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!2691
No description provided.