startup: lower a compressed export whose unused channel pair is 'off' #1693

Closed
github-bot wants to merge 1 commit from gh-pr/1693/head into gh-pr/1693/base
Owner

@⁠triggered02 on GitHub · 2026-11-24 17:14 UTC · original
triggered02:startup/exp-off → main · +133 −1 · 4 files · 1 commits · closed without merging

Fixes #1674. This is the corrected slice; the earlier PR #1681 fixed the wrong path and was closed.

Change

A compr export packs two channels into each source register; an export that writes only some channels spells the unwritten pair off. The translator evaluated that token as an operand and refused the whole translation:

before: exp mrt0 v0, v0, off, off done compr vm  -> REFUSED: operand 'off'
after:  same bytes lower; channels 2/3 contribute zero, 0/1 still read v0

Both pairs are handled, not just the common one: exp mrt4 off, off, v83, v83 done compr (a real encoding from the same cache) zeroes channels 0/1 and reads 2/3.

Test

Starts from encoded instructions, decodes them, then translates — the shape matters, because the closed PR tested hand-written assembly through Stage.one, which the decoder never produces, so it verified a branch real bytes cannot reach.

bytes decoded form covers
031c00f800808080 exp mrt0 v0, v0, off, off done compr vm off in the second pair
4cccb1f9d1537dd9 exp mrt4 off, off, v83, v83 done compr off in the first pair
131c00f81b808080 exp mrt1 v27, v27, off, off done compr vm a second MRT target

Refusals kept: compressed export into an integer MRT (packed-integer data), and an export with an explicit en: mask — the parser does not read that mask yet, and exporting all four channels would silently disagree with it.

dev:     startup_gfx2hlsl_export_off Passed 0.15 s
release: startup_gfx2hlsl_export_off Passed 0.15 s
five neighbouring startup_gfx2hlsl tests still pass

Fail-first: reverting the two lines fails the test with Unsupported: operand 'off'.

Census re-run (local, aggregates only)

Over the same 29 refused cache entries with the change applied: 7 x ok — the seven exp ... off, off shaders now translate, and no operand 'off' refusal remains.

What this does not establish

  • That the loading screen gets further. That needs a run that visibly reaches it; the census above is local and counts only.
  • The other 22 refusals are untouched (largest remaining: tbuffer_load_format_xyz with BUF_FMT_16_16_16_16_FLOAT, 5; v_cvt_f32_i32 with mul:2, 5).
  • The en: mask form is its own slice.

AI-assisted (Claude Code).

**@⁠triggered02** on GitHub · 2026-11-24 17:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1693) `triggered02:startup/exp-off` → `main` · +133 −1 · 4 files · 1 commits · closed without merging Fixes #1674. This is the corrected slice; the earlier PR #1681 fixed the wrong path and was closed. ## Change A `compr` export packs two channels into each source register; an export that writes only some channels spells the unwritten pair `off`. The translator evaluated that token as an operand and refused the whole translation: ``` before: exp mrt0 v0, v0, off, off done compr vm -> REFUSED: operand 'off' after: same bytes lower; channels 2/3 contribute zero, 0/1 still read v0 ``` Both pairs are handled, not just the common one: `exp mrt4 off, off, v83, v83 done compr` (a real encoding from the same cache) zeroes channels 0/1 and reads 2/3. ## Test Starts from **encoded instructions**, decodes them, then translates — the shape matters, because the closed PR tested hand-written assembly through `Stage.one`, which the decoder never produces, so it verified a branch real bytes cannot reach. | bytes | decoded form | covers | |---|---|---| | `031c00f800808080` | `exp mrt0 v0, v0, off, off done compr vm` | off in the second pair | | `4cccb1f9d1537dd9` | `exp mrt4 off, off, v83, v83 done compr` | off in the first pair | | `131c00f81b808080` | `exp mrt1 v27, v27, off, off done compr vm` | a second MRT target | Refusals kept: compressed export into an integer MRT (packed-integer data), and an export with an explicit `en:` mask — the parser does not read that mask yet, and exporting all four channels would silently disagree with it. ``` dev: startup_gfx2hlsl_export_off Passed 0.15 s release: startup_gfx2hlsl_export_off Passed 0.15 s five neighbouring startup_gfx2hlsl tests still pass ``` Fail-first: reverting the two lines fails the test with `Unsupported: operand 'off'`. ## Census re-run (local, aggregates only) Over the same 29 refused cache entries with the change applied: **7 x ok** — the seven `exp ... off, off` shaders now translate, and no `operand 'off'` refusal remains. ## What this does not establish - That the loading screen gets further. That needs a run that visibly reaches it; the census above is local and counts only. - The other 22 refusals are untouched (largest remaining: `tbuffer_load_format_xyz` with `BUF_FMT_16_16_16_16_FLOAT`, 5; `v_cvt_f32_i32` with `mul:2`, 5). - The `en:` mask form is its own slice. AI-assisted (Claude Code).
Fixes #1674. A `compr` export packs two channels into each source register, and an export that writes only
some channels spells the unwritten pair `off`. The translator evaluated that token as an operand and refused
the whole translation with `operand 'off'`, which was the largest single group - 7 of 29 - of refused shaders
in the first main-game loading-screen cache (#870).

  before: exp mrt0 v0, v0, off, off done compr vm  -> REFUSED: operand 'off'
  after:  the same export lowers, with channels 2/3 contributing zero and 0/1 read from v0

Both pairs are handled, not just the common one: `exp mrt4 off, off, v83, v83 done compr` (a real encoding
from the same cache) zeroes channels 0/1 and reads 2/3.

The test starts from encoded instructions and goes through decode(), then the translator:
031c00f800808080 (off in the second pair), 4cccb1f9d1537dd9 (off in the first pair, from the cache) and
131c00f81b808080 (a second MRT target). That shape matters: an earlier attempt at this group tested hand-written
assembly through Stage.one, which the decoder never produces, so it verified a branch real bytes cannot reach.

Refusals kept: a compressed export into an integer MRT stays refused (packed-integer data), and an export with
an explicit `en:` mask stays refused - the parser does not read that mask yet, and exporting all four channels
would silently disagree with it.

  dev:     startup_gfx2hlsl_export_off Passed 0.15 s
  release: startup_gfx2hlsl_export_off Passed 0.15 s
  five neighbouring startup_gfx2hlsl tests still pass

Fail-first: reverting the two lines fails the test with "Unsupported: operand 'off'".

Census re-run over the same cache with the change: 7 more shaders translate ("7 x ok"), and no `operand 'off'`
refusal is left. That is 7 of the 29 refused entries; the other groups are untouched (see #870).

What this does not establish: that the loading screen now gets further - that needs a run that visibly reaches
it, and the aggregate censuses above are local only. The `en:` mask form and the other groups are separate
slices.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 23:26:33 +00:00
github-bot closed this pull request 2026-11-26 23:26:33 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 17:14 UTC · original · edited 2026-11-24 17:17 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-24T17:17:58.376663Z 8b949e2 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 17:14 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1693#issuecomment-7138909564) · edited 2026-11-24 17:17 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"8b949e2b855d836428a4c1d4deeea896d07236d0","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-24T17:17:58.376663Z">2026-11-24T17:17:58.376663Z</relative-time> | `8b949e2` | 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>
@ -0,0 +79,4 @@
# 3. The mirror case: off in the first pair and real registers in the second (a real encoding from the same
# cache). The fix must handle either pair, not just the one the common case uses.
asm, emitted = translate_bytes("4cccb1f9d1537dd9")
Author
Owner

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

P1 Badge Replace cache-derived bytes with permitted fixture input

The comments identify this test vector (and the companion at line 89) as real encodings from the first main-game loading-screen cache, so the regression test uses game-cache data rather than a source-built or synthetic fixture, or a public sample with a known revision and license. Assemble equivalent instructions from checked-in source or use a permitted sample instead.

AGENTS.md reference: AGENTS.md:L26-L27

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 17:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1693#discussion_r4683809096) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Replace cache-derived bytes with permitted fixture input** The comments identify this test vector (and the companion at line 89) as real encodings from the first main-game loading-screen cache, so the regression test uses game-cache data rather than a source-built or synthetic fixture, or a public sample with a known revision and license. Assemble equivalent instructions from checked-in source or use a permitted sample instead. AGENTS.md reference: [AGENTS.md:L26-L27](https://github.com/R0Y00/Xbox2Windows/blob/8b949e2b855d836428a4c1d4deeea896d07236d0/AGENTS.md#L26-L27) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -954,0 +954,4 @@
# those channels are not written, so they contribute zero instead of being evaluated as an
# operand; the disassembler spells it that way for an export that writes only some channels.
a = '0u' if vals[0] == 'off' else self.u(vals[0])
b = '0u' if vals[2] == 'off' else self.u(vals[2])
Author
Owner

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

P2 Badge Preserve channels disabled by a compressed export

When one pair is off, this substitutes zero but the translator still emits a full float4 MRT assignment; hlsl_ps() declares all four components and pipeline_for() defaults to D3D12_COLOR_WRITE_ENABLE_ALL when no blend state is recovered. Such draws therefore overwrite the disabled render-target channels with zero instead of leaving them untouched; carry the pair's write mask into the translated PSO or keep refusing this form.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 17:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1693#discussion_r4683809106) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Preserve channels disabled by a compressed export** When one pair is `off`, this substitutes zero but the translator still emits a full `float4` MRT assignment; `hlsl_ps()` declares all four components and `pipeline_for()` defaults to `D3D12_COLOR_WRITE_ENABLE_ALL` when no blend state is recovered. Such draws therefore overwrite the disabled render-target channels with zero instead of leaving them untouched; carry the pair's write mask into the translated PSO or keep refusing this form. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠triggered02 on GitHub · 2026-11-24 17:21 UTC · original

Acknowledging both findings. The P2 changes the right outcome for this PR, so I am closing it rather than patching around it.

P2 — zeroing a disabled pair is not safe here. You are right that the translator emits a full float4 and that pipeline_for() falls back to D3D12_COLOR_WRITE_ENABLE_ALL. I checked the runtime side: src/startup_stubs/state_block_blend.h states plainly that "CB_TARGET_MASK has not been located, so every target keeps all four channels". So the disconnected channels are not masked at the PSO, and writing zeros into them overwrites whatever the target held — exactly the corruption you describe. Carrying the pair's mask into the translated PSO is the real fix, and that is a runtime plumbing change (export mask into the manifest, consumed where the write mask is set), not a two-line lowering change.

Per your "or keep refusing this form": the refusal stays. I am recording the mask plumbing as the slice that unblocks it rather than landing a lowering that changes what a draw does.

P1 — cache-derived bytes. Correct, and it applies to my tests generally: citing them as "real encodings from the cache" is exactly the prohibited input. The replacement for the still-open typed-buffer-load PR (#1699) is a synthetic encoder in the test that builds the instruction bytes field by field from the documented MTBUF layout and then decodes them; I will re-push that before it draws the same finding. For this PR the test goes away with it.

Thanks for reading the call chain rather than the diff — the en/write-mask interaction is the kind of thing a passing fixture hides, and this fixture passed in both presets.

AI-assisted (Claude Code).

**@⁠triggered02** on GitHub · 2026-11-24 17:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1693#issuecomment-7139066848) Acknowledging both findings. The P2 changes the right outcome for this PR, so I am **closing it** rather than patching around it. **P2 — zeroing a disabled pair is not safe here.** You are right that the translator emits a full `float4` and that `pipeline_for()` falls back to `D3D12_COLOR_WRITE_ENABLE_ALL`. I checked the runtime side: `src/startup_stubs/state_block_blend.h` states plainly that "CB_TARGET_MASK has not been located, so every target keeps all four channels". So the disconnected channels are not masked at the PSO, and writing zeros into them overwrites whatever the target held — exactly the corruption you describe. Carrying the pair's mask into the translated PSO is the real fix, and that is a runtime plumbing change (export mask into the manifest, consumed where the write mask is set), not a two-line lowering change. Per your "or keep refusing this form": the refusal stays. I am recording the mask plumbing as the slice that unblocks it rather than landing a lowering that changes what a draw does. **P1 — cache-derived bytes.** Correct, and it applies to my tests generally: citing them as "real encodings from the cache" is exactly the prohibited input. The replacement for the still-open typed-buffer-load PR (#1699) is a synthetic encoder in the test that builds the instruction bytes field by field from the documented MTBUF layout and then decodes them; I will re-push that before it draws the same finding. For this PR the test goes away with it. Thanks for reading the call chain rather than the diff — the `en`/write-mask interaction is the kind of thing a passing fixture hides, and this fixture passed in both presets. AI-assisted (Claude Code).
Author
Owner

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8b949e2b85

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

@⁠tedin7 on GitHub · 2026-11-24 17:19 UTC · original · reviewed

Peer review at head 8b949e2b855d836428a4c1d4deeea896d07236d0 (clean-room, title-neutral, no blocking findings).

Code & Semantics Review

  • tools/startup/gfx2hlsl.py: In Stage.export(), when 'compr' in flags, vals[0] and vals[2] now map 'off' to '0u' before f16tof32(...) unpacking, matching the existing uncompressed off handling ('0.0' / '0u').
    • Both channel pairs (off in vals[2:4] and off in vals[0:2]) are handled symmetrically, done and vm flags continue to be processed via re.fullmatch + exec guard, and o.<target> still receives a complete float4 initialization.
    • Packed-integer compr exports (uint/int) remain rejected with Unsupported, and partial-pair en: masks (e.g. en:0xb) remain rejected rather than silently exporting all four channels.
  • tests/startup_gfx2hlsl_export_off_check.py: Exercises G.decode() -> Stage.one() on real 8-byte encodings for both pair positions, multiple MRT targets, and both refusal boundaries.
  • CMakeLists.txt & docs/experiments.md: CTest registration and documentation match the implementation.

Verification Executed

Linux:

  • echo "0x03,0x1c,0x00,0xf8,0x00,0x80,0x80,0x80" | llvm-mc-19 -disassemble -triple=amdgcn-amd-amdhsa -mcpu=gfx1030 -> exp mrt0 v0, v0, off, off done compr vm
  • python3 -B tests/startup_gfx2hlsl_export_off_check.py -> PASS (10/10 checks)
  • for f in tests/startup_gfx2hlsl_*_check.py; do python3 -B "$f"; done -> all 5 startup_gfx2hlsl_* check scripts passed (bit_alu, capture, export_off, sdwa, smem_offset).

Local Mutation Check (Linux):

  • Mutated tools/startup/gfx2hlsl.py ('0u' -> '1u' on vals[0] == 'off'), ran python3 -B tests/startup_gfx2hlsl_export_off_check.py -> failed as expected (first pair zero, second pair from v83: MISMATCH, exit code 1). Restored with git checkout -- . and verified clean git status --short.

Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at 8b949e2b855d836428a4c1d4deeea896d07236d0:

  • Debug (--preset dev): ctest --preset dev -R '^startup_gfx2hlsl_' --parallel 4 --no-tests=error --output-on-failure -> 7/7 passed (6.52s, including startup_gfx2hlsl_export_off 0.19s).
  • Release /O2 (--preset release): ctest --preset release -R '^startup_gfx2hlsl_' --parallel 4 --no-tests=error --output-on-failure -> 7/7 passed (6.07s, including startup_gfx2hlsl_export_off 0.20s).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-24 17:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1693#pullrequestreview-6044042640) · **reviewed** Peer review at head `8b949e2b855d836428a4c1d4deeea896d07236d0` (clean-room, title-neutral, no blocking findings). ### Code & Semantics Review - [`tools/startup/gfx2hlsl.py`](https://github.com/R0Y00/Xbox2Windows/blob/8b949e2b855d836428a4c1d4deeea896d07236d0/tools/startup/gfx2hlsl.py#L950-L959): In `Stage.export()`, when `'compr' in flags`, `vals[0]` and `vals[2]` now map `'off'` to `'0u'` before `f16tof32(...)` unpacking, matching the existing uncompressed `off` handling (`'0.0'` / `'0u'`). - Both channel pairs (`off` in `vals[2:4]` and `off` in `vals[0:2]`) are handled symmetrically, `done` and `vm` flags continue to be processed via `re.fullmatch` + `exec` guard, and `o.<target>` still receives a complete `float4` initialization. - Packed-integer `compr` exports (`uint`/`int`) remain rejected with `Unsupported`, and partial-pair `en:` masks (e.g. `en:0xb`) remain rejected rather than silently exporting all four channels. - [`tests/startup_gfx2hlsl_export_off_check.py`](https://github.com/R0Y00/Xbox2Windows/blob/8b949e2b855d836428a4c1d4deeea896d07236d0/tests/startup_gfx2hlsl_export_off_check.py): Exercises `G.decode()` -> `Stage.one()` on real 8-byte encodings for both pair positions, multiple MRT targets, and both refusal boundaries. - [`CMakeLists.txt`](https://github.com/R0Y00/Xbox2Windows/blob/8b949e2b855d836428a4c1d4deeea896d07236d0/CMakeLists.txt#L1610-L1612) & [`docs/experiments.md`](https://github.com/R0Y00/Xbox2Windows/blob/8b949e2b855d836428a4c1d4deeea896d07236d0/docs/experiments.md#L5618-L5627): CTest registration and documentation match the implementation. ### Verification Executed **Linux:** - `echo "0x03,0x1c,0x00,0xf8,0x00,0x80,0x80,0x80" | llvm-mc-19 -disassemble -triple=amdgcn-amd-amdhsa -mcpu=gfx1030` -> `exp mrt0 v0, v0, off, off done compr vm` - `python3 -B tests/startup_gfx2hlsl_export_off_check.py` -> `PASS` (10/10 checks) - `for f in tests/startup_gfx2hlsl_*_check.py; do python3 -B "$f"; done` -> all 5 `startup_gfx2hlsl_*` check scripts passed (`bit_alu`, `capture`, `export_off`, `sdwa`, `smem_offset`). **Local Mutation Check (Linux):** - Mutated `tools/startup/gfx2hlsl.py` (`'0u'` -> `'1u'` on `vals[0] == 'off'`), ran `python3 -B tests/startup_gfx2hlsl_export_off_check.py` -> failed as expected (`first pair zero, second pair from v83: MISMATCH`, exit code 1). Restored with `git checkout -- .` and verified clean `git status --short`. **Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at `8b949e2b855d836428a4c1d4deeea896d07236d0`:** - **Debug (`--preset dev`)**: `ctest --preset dev -R '^startup_gfx2hlsl_' --parallel 4 --no-tests=error --output-on-failure` -> **7/7 passed** (`6.52s`, including `startup_gfx2hlsl_export_off` `0.19s`). - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^startup_gfx2hlsl_' --parallel 4 --no-tests=error --output-on-failure` -> **7/7 passed** (`6.07s`, including `startup_gfx2hlsl_export_off` `0.20s`). AI-assisted; commands listed were executed locally.

Pull request closed

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