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

Closed
triggered02 wants to merge 1 commit from upstream-pr/1693 into main
triggered02 commented 2026-11-24 17:14:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T17:14:42Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587364989 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1693). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:14:42Z. --- 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).
upstream-sync closed this pull request 2026-11-24 18:02:34 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 18:02:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:17:56Z.

Review: COMMENTED


💡 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".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044023827 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1693#pullrequestreview-6044023827). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:17:56Z. **Review:** COMMENTED --- <!-- 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>
tedin7 commented 2026-11-24 18:02:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:19:14Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044042640 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1693#pullrequestreview-6044042640). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:19:14Z. **Review:** COMMENTED --- 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.
chatgpt-codex-connector[bot commented 2026-11-24 18:02:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:14:56Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7138909564 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1693#issuecomment-7138909564). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:14:56Z. --- <!-- 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>
triggered02 commented 2026-11-24 18:02:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-11-24T17:21:15Z.


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).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7139066848 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1693#issuecomment-7139066848). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:21:15Z. --- 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).
chatgpt-codex-connector[bot commented 2026-11-24 18:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:17:56Z.

Code review location: tests/startup_gfx2hlsl_export_off_check.py; line 82

@@ -0,0 +1,114 @@
+"""Compressed export with `off` channels in tools/startup/gfx2hlsl.py (issue #1674).
+
+usage: startup_gfx2hlsl_export_off_check.py
+
+`compr` packs two channels into each source register. An export that writes only some channels spells the
+unwritten pair `off`, and the translator used to evaluate that token as an operand, refusing the whole
+translation with `Unsupported: operand 'off'`. That refusal accounted for the largest single group - 7 of 29 -
+of refused shaders in the first main-game loading-screen cache (#870).
+
+The cases start from encoded instructions and go through `decode()`, then the translator, because an
+injected-assembly test is exactly what made an earlier, wrong fix for this group look correct.
+"""
+import os
+import sys
+
+here = os.path.dirname(os.path.abspath(__file__))
+sys.path.insert(0, os.path.join(here, '..', 'tools'))
+sys.path.insert(0, os.path.join(here, '..', 'tools', 'startup'))
+import gfx2hlsl as G  # noqa: E402
+
+failures = []
+
+
+def check(label, condition, detail=''):
+    print(f"{label}: {'ok' if condition else 'MISMATCH'}")
+    if not condition:
+        failures.append(label)
+        if detail:
+            print('  ' + detail)
+
+
+class Pipeline:
+    """Just enough pipeline state for the export path: the MRT format and the flat-parameter offset."""
+
+    def __init__(self, kind='float'):
+        self.notes = set()
+        self.kind = kind
+
+    def mrt_kind(self, index):
+        return self.kind
+
+    def ud(self, source):
+        return 0
+
+
+class Stage(G.Stage):
+    """A Stage with no pipeline: enough state for a decoded instruction to be translated."""
+
+    def __init__(self, kind='float'):
+        self.lines, self.sym = [], {}
+        self.used_s, self.used_v, self.uniform_v = set(), set(), set()
+        self.exec_known = True
+        self.exports = {}
+        self.pipe = Pipeline(kind)
+
+    def descriptor(self, tok):
+        return ('buffer', tok)
+
+
+def translate_bytes(hexbytes, kind='float'):
+    """Decode the bytes the way the pipeline does, then translate every decoded instruction."""
+    decoded = G.decode(bytes.fromhex(hexbytes))
+    stage = Stage(kind)
+    for _offset, _size, name, asm in decoded:
+        stage.one(name, asm)
+    return [asm for _o, _s, _n, asm in decoded], ' '.join(stage.lines)
+
+
+# 1. The decoded text is what the rest of this test assumes; a decoder change should show up here first.
+asm, emitted = translate_bytes("031c00f800808080")
+check('decodes to a compressed export with off channels', asm == ['exp mrt0 v0, v0, off, off done compr vm'],
+      repr(asm))
+
+# 2. The off pair contributes zero and the written pair still comes from its register. Channels 0/1 are the
+#    two halves of v0; channels 2/3 are the unwritten pair.
+check('written pair comes from v0', 'f16tof32(v0)' in emitted and 'f16tof32(v0 >> 16)' in emitted, emitted)
+check('unwritten pair contributes zero', 'f16tof32(0u)' in emitted and 'f16tof32(0u >> 16)' in emitted, emitted)
+check('export target still written', 'o.mrt0' in emitted, emitted)
+
+# 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")

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4683809096 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1693#discussion_r4683809096). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:17:56Z. **Code review location:** `tests/startup_gfx2hlsl_export_off_check.py`; line 82 ~~~~diff @@ -0,0 +1,114 @@ +"""Compressed export with `off` channels in tools/startup/gfx2hlsl.py (issue #1674). + +usage: startup_gfx2hlsl_export_off_check.py + +`compr` packs two channels into each source register. An export that writes only some channels spells the +unwritten pair `off`, and the translator used to evaluate that token as an operand, refusing the whole +translation with `Unsupported: operand 'off'`. That refusal accounted for the largest single group - 7 of 29 - +of refused shaders in the first main-game loading-screen cache (#870). + +The cases start from encoded instructions and go through `decode()`, then the translator, because an +injected-assembly test is exactly what made an earlier, wrong fix for this group look correct. +""" +import os +import sys + +here = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, os.path.join(here, '..', 'tools')) +sys.path.insert(0, os.path.join(here, '..', 'tools', 'startup')) +import gfx2hlsl as G # noqa: E402 + +failures = [] + + +def check(label, condition, detail=''): + print(f"{label}: {'ok' if condition else 'MISMATCH'}") + if not condition: + failures.append(label) + if detail: + print(' ' + detail) + + +class Pipeline: + """Just enough pipeline state for the export path: the MRT format and the flat-parameter offset.""" + + def __init__(self, kind='float'): + self.notes = set() + self.kind = kind + + def mrt_kind(self, index): + return self.kind + + def ud(self, source): + return 0 + + +class Stage(G.Stage): + """A Stage with no pipeline: enough state for a decoded instruction to be translated.""" + + def __init__(self, kind='float'): + self.lines, self.sym = [], {} + self.used_s, self.used_v, self.uniform_v = set(), set(), set() + self.exec_known = True + self.exports = {} + self.pipe = Pipeline(kind) + + def descriptor(self, tok): + return ('buffer', tok) + + +def translate_bytes(hexbytes, kind='float'): + """Decode the bytes the way the pipeline does, then translate every decoded instruction.""" + decoded = G.decode(bytes.fromhex(hexbytes)) + stage = Stage(kind) + for _offset, _size, name, asm in decoded: + stage.one(name, asm) + return [asm for _o, _s, _n, asm in decoded], ' '.join(stage.lines) + + +# 1. The decoded text is what the rest of this test assumes; a decoder change should show up here first. +asm, emitted = translate_bytes("031c00f800808080") +check('decodes to a compressed export with off channels', asm == ['exp mrt0 v0, v0, off, off done compr vm'], + repr(asm)) + +# 2. The off pair contributes zero and the written pair still comes from its register. Channels 0/1 are the +# two halves of v0; channels 2/3 are the unwritten pair. +check('written pair comes from v0', 'f16tof32(v0)' in emitted and 'f16tof32(v0 >> 16)' in emitted, emitted) +check('unwritten pair contributes zero', 'f16tof32(0u)' in emitted and 'f16tof32(0u >> 16)' in emitted, emitted) +check('export target still written', 'o.mrt0' in emitted, emitted) + +# 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") ~~~~ --- **<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 -->
chatgpt-codex-connector[bot commented 2026-11-24 18:03:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T17:17:56Z.

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

@@ -950,7 +950,11 @@ def export(self, asm):
         if 'compr' in flags:
             if kind in ('uint', 'int'):
                 raise Unsupported('packed integer export %s' % name)
-            a, b = self.u(vals[0]), self.u(vals[2])
+            # A compressed export packs two channels into each source register. `off` in either pair means
+            # 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])

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 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4683809106 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1693#discussion_r4683809106). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:17:56Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 957 ~~~~diff @@ -950,7 +950,11 @@ def export(self, asm): if 'compr' in flags: if kind in ('uint', 'int'): raise Unsupported('packed integer export %s' % name) - a, b = self.u(vals[0]), self.u(vals[2]) + # A compressed export packs two channels into each source register. `off` in either pair means + # 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]) ~~~~ --- **<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 -->

Pull request closed

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!1686
No description provided.