startup: lower a typed buffer load of BUF_FMT_16_16_16_16_FLOAT #1692

Merged
triggered02 merged 4 commits from upstream-pr/1699 into main 2026-11-24 19:17:45 +00:00
triggered02 commented 2026-11-24 17:20:04 +00:00 (Migrated from github.com)

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


Fixes #1695. This is the second group from the loading-screen refusal census (#870): 5 of 29 shaders.

Change

The typed-load format table had the two-channel half-float form but not the four-channel one, so a load of BUF_FMT_16_16_16_16_FLOAT was refused. The format stores four binary16 channels in one 8-byte element — x and y in the first dword, z and w in the second — each converted with f16tof32:

tbuffer_load_format_xyz v[0:2], v0, s[20:23], 0 format:[BUF_FMT_16_16_16_16_FLOAT] idxen
  -> v0 = f16tof32(Load(a)); v1 = f16tof32(Load(a) >> 16); v2 = f16tof32(Load(a + 4))
tbuffer_load_format_xyzw ... same format
  -> also v3 = f16tof32(Load(a + 4) >> 16)

Test

The instruction bytes are constructed in the test from the field layout the checked-in decoder reads ( ools/disasm_rdna2.py, MTBUF branch) — no game-derived bytes, per the review on #1693 — then decoded and translated:

bytes decoded form covers
00203aea00000580 tbuffer_load_format_xyz … BUF_FMT_16_16_16_16_FLOAT real encoding from the cache
00203bea00000580 same, xyzw w from the high half of the second dword
002038ea00000580 same, x one channel only
00207aea00000580 numeric format the table does not name stays refused
00203aea00002580 tbuffer_load_format_d16_xyz stays refused (no lowering)
dev:     startup_gfx2hlsl_tbuffer_16f Passed 0.17 s
release: startup_gfx2hlsl_tbuffer_16f Passed 0.16 s
five neighbouring startup_gfx2hlsl tests still pass

Fail-first: removing the format entry fails the test with Unsupported: buffer format BUF_FMT_16_16_16_16_FLOAT.

Census A/B (local, aggregates only)

With the change, refusals whose reason is this format go 5 → 0. Those five shaders either translate or stop at the next refusal in their stream: the count of v_cndmask_b32_e64 v30, v29, -v29 rises 0 → 4, which is progress through the stream, not a regression.

What this does not establish

  • That the loading screen gets further — needs a run that visibly reaches it.
  • Other unnamed formats and the d16 forms are separate slices; the rest of the census is untouched.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6587462047 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:20:04Z. --- Fixes #1695. This is the second group from the loading-screen refusal census (#870): **5 of 29** shaders. ## Change The typed-load format table had the two-channel half-float form but not the four-channel one, so a load of `BUF_FMT_16_16_16_16_FLOAT` was refused. The format stores four binary16 channels in one 8-byte element — x and y in the first dword, z and w in the second — each converted with `f16tof32`: ``` tbuffer_load_format_xyz v[0:2], v0, s[20:23], 0 format:[BUF_FMT_16_16_16_16_FLOAT] idxen -> v0 = f16tof32(Load(a)); v1 = f16tof32(Load(a) >> 16); v2 = f16tof32(Load(a + 4)) tbuffer_load_format_xyzw ... same format -> also v3 = f16tof32(Load(a + 4) >> 16) ``` ## Test The instruction bytes are **constructed in the test** from the field layout the checked-in decoder reads ( ools/disasm_rdna2.py, MTBUF branch) — no game-derived bytes, per the review on #1693 — then decoded and translated: | bytes | decoded form | covers | |---|---|---| | `00203aea00000580` | `tbuffer_load_format_xyz … BUF_FMT_16_16_16_16_FLOAT` | real encoding from the cache | | `00203bea00000580` | same, `xyzw` | w from the high half of the second dword | | `002038ea00000580` | same, `x` | one channel only | | `00207aea00000580` | numeric format the table does not name | stays refused | | `00203aea00002580` | `tbuffer_load_format_d16_xyz` | stays refused (no lowering) | ``` dev: startup_gfx2hlsl_tbuffer_16f Passed 0.17 s release: startup_gfx2hlsl_tbuffer_16f Passed 0.16 s five neighbouring startup_gfx2hlsl tests still pass ``` Fail-first: removing the format entry fails the test with `Unsupported: buffer format BUF_FMT_16_16_16_16_FLOAT`. ## Census A/B (local, aggregates only) With the change, refusals whose reason is this format go **5 → 0**. Those five shaders either translate or stop at the next refusal in their stream: the count of `v_cndmask_b32_e64 v30, v29, -v29` rises 0 → 4, which is progress through the stream, not a regression. ## What this does not establish - That the loading screen gets further — needs a run that visibly reaches it. - Other unnamed formats and the `d16` forms are separate slices; the rest of the census is untouched. AI-assisted (Claude Code).
chatgpt-codex-connector[bot commented 2026-11-24 18:02:37 +00:00 (Migrated from github.com)

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

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 92f27f1287

ℹ️ 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:6044087620 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#pullrequestreview-6044087620). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:22:09Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `92f27f1287` <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:37 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 92f27f1287d424cbb8b8c9dd0b7eed63814b2c81 (1 commit on top of main; touches tools/startup/gfx2hlsl.py +4, the new test, CMakeLists.txt +3, docs/experiments.md +8).

Linux limits. Linux x86_64 only. I did not configure CMake or run ctest, so the startup_gfx2hlsl_tbuffer_16f registration is unexercised; I ran the check script directly with python3 -B. No Windows, no DXC or FXC, no GPU: the emitted HLSL was compared as text and never compiled or executed, so the half-float arithmetic is not proven numerically.

What I ran

  • python3 -B tests/startup_gfx2hlsl_tbuffer_16f_check.py: PASS.
  • llvm-mc-19 --disassemble -triple=amdgcn -mcpu=gfx1030 on the five byte strings: each decodes to exactly the text the test expects (xyz, xyzw, x with BUF_FMT_16_16_16_16_FLOAT; format:79 for the unnamed one; tbuffer_load_format_d16_xyz for the last).
  • Assembling those same instructions with llvm-mc-19 -show-encoding gives the identical bytes (00203aea00000580, 00203bea…, 002038ea…, 00207aea…).
  • git diff --check origin/main...HEAD: clean. tests/bidi_controls_check.py and tests/docs_links_check.py: pass.
  • Eight local mutations of the new table entry, each run against the test, then restored (git status clean): y shift 16 -> 8; z offset +4 -> +8; w without f16tof32; x read from the second dword; w read from the first dword; y masked with 65535 instead of shifted; asfloat instead of f16tof32; x without the U() wrapper. All eight FAIL. The channel layout in the table is correct against the format definition, and the test pins it.

Findings

  1. Blocking, repository rule. The test comment (line 77) and the docstring call 00203aea00000580 "a real encoding from the loading-screen cache", and the PR text repeats "first main-game loading-screen cache". AGENTS.md allows only source-built or synthetic fixtures and title-neutral wording, and the Codex P1 on this head raises the same point. The bytes need no cache: llvm-mc-19 reproduces all four from the assembly text (see above). Suggest saying "encoded with llvm-mc from the asm text", dropping the cache wording from the test, docs and PR body, and keeping #870 only as the issue reference.
  2. The test docstring says "issue #1675"; the issue is #1695 (the PR body and CMake comment have it right).
  3. Minor, not blocking. BUF_FMT_16_16_FLOAT goes through ldu, which handles an address that is not 4-aligned. The new entry uses plain Load(a) and Load(a + 4) like the 32-bit formats, which round the address down. For an 8-byte element at a multiple of 8 this is the same; with an odd offset: the two paths would differ. Worth a sentence saying the alignment is assumed.
  4. Minor. The assertions match the exact emitted strings (for example U(f16tof32(r0.Load(a)))), so a harmless rewrite of the same math would fail them. That matches the neighbouring tests, so I leave it to you.

Not verified: the "5 of 29" census and the A/B counts, which come from a local cache I cannot see.

AI-assisted review; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044119937 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#pullrequestreview-6044119937). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:24:05Z. **Review:** COMMENTED --- Review of head `92f27f1287d424cbb8b8c9dd0b7eed63814b2c81` (1 commit on top of main; touches `tools/startup/gfx2hlsl.py` +4, the new test, `CMakeLists.txt` +3, `docs/experiments.md` +8). **Linux limits.** Linux x86_64 only. I did not configure CMake or run `ctest`, so the `startup_gfx2hlsl_tbuffer_16f` registration is unexercised; I ran the check script directly with `python3 -B`. No Windows, no DXC or FXC, no GPU: the emitted HLSL was compared as text and never compiled or executed, so the half-float arithmetic is not proven numerically. **What I ran** - `python3 -B tests/startup_gfx2hlsl_tbuffer_16f_check.py`: PASS. - `llvm-mc-19 --disassemble -triple=amdgcn -mcpu=gfx1030` on the five byte strings: each decodes to exactly the text the test expects (xyz, xyzw, x with `BUF_FMT_16_16_16_16_FLOAT`; `format:79` for the unnamed one; `tbuffer_load_format_d16_xyz` for the last). - Assembling those same instructions with `llvm-mc-19 -show-encoding` gives the identical bytes (`00203aea00000580`, `00203bea…`, `002038ea…`, `00207aea…`). - `git diff --check origin/main...HEAD`: clean. `tests/bidi_controls_check.py` and `tests/docs_links_check.py`: pass. - Eight local mutations of the new table entry, each run against the test, then restored (`git status` clean): y shift 16 -> 8; z offset +4 -> +8; w without `f16tof32`; x read from the second dword; w read from the first dword; y masked with 65535 instead of shifted; `asfloat` instead of `f16tof32`; x without the `U()` wrapper. All eight FAIL. The channel layout in the table is correct against the format definition, and the test pins it. **Findings** 1. Blocking, repository rule. The test comment (line 77) and the docstring call `00203aea00000580` "a real encoding from the loading-screen cache", and the PR text repeats "first main-game loading-screen cache". AGENTS.md allows only source-built or synthetic fixtures and title-neutral wording, and the Codex P1 on this head raises the same point. The bytes need no cache: `llvm-mc-19` reproduces all four from the assembly text (see above). Suggest saying "encoded with llvm-mc from the asm text", dropping the cache wording from the test, docs and PR body, and keeping #870 only as the issue reference. 2. The test docstring says "issue #1675"; the issue is #1695 (the PR body and CMake comment have it right). 3. Minor, not blocking. `BUF_FMT_16_16_FLOAT` goes through `ldu`, which handles an address that is not 4-aligned. The new entry uses plain `Load(a)` and `Load(a + 4)` like the 32-bit formats, which round the address down. For an 8-byte element at a multiple of 8 this is the same; with an odd `offset:` the two paths would differ. Worth a sentence saying the alignment is assumed. 4. Minor. The assertions match the exact emitted strings (for example `U(f16tof32(r0.Load(a)))`), so a harmless rewrite of the same math would fail them. That matches the neighbouring tests, so I leave it to you. Not verified: the "5 of 29" census and the A/B counts, which come from a local cache I cannot see. AI-assisted review; commands listed were executed locally.
tedin7 commented 2026-11-24 18:02:37 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Follow-up review of head cd654de9a50d479d8a3bc22cacce47806012d434. My previous review was written against 92f27f1287d424cbb8b8c9dd0b7eed63814b2c81; the author pushed this commit while I was reviewing, so GitHub attached that review to the new head. Read it as a review of 92f27f12. This one replaces it for the current head.

Linux limits. Linux x86_64 only. No CMake configure and no ctest (the CMake registration is unexercised), no Windows, no DXC or FXC, no GPU. The emitted HLSL is compared as text and never compiled or run.

What changed since 92f27f12. Only tests/startup_gfx2hlsl_tbuffer_16f_check.py: the hard-coded cache byte strings are replaced by an encode_mtbuf() that builds each instruction from the MTBUF field layout, the docstring issue number is fixed (#1695), and a default-format case is added. The table entry in tools/startup/gfx2hlsl.py is unchanged.

What I ran on this head

  • python3 -B tests/startup_gfx2hlsl_tbuffer_16f_check.py: PASS. git diff --check origin/main...HEAD: clean.
  • encode_mtbuf() against llvm-mc-19 -triple=amdgcn -mcpu=gfx1030 -show-encoding: xyz, xyzw, x (format 71), xyz with format 127 and d16_xyz with format 71 all produce byte-identical output. The synthetic encoder matches the assembler, not only the repository's own decoder.
  • Five mutations of the table entry (y shift 16 -> 8; z offset +4 -> +8; w without f16tof32; w from the first dword; asfloat instead of f16tof32), each run and then restored: all FAIL, git status clean.

Findings

  1. Resolved: the game-derived fixture (AGENTS.md hard rule) and the issue-number typo.
  2. Remaining wording. The test docstring (line 8) and the PR text still say "first main-game loading-screen cache". AGENTS.md asks for title-neutral public wording; consider "the first startup shader cache" or just the #870 reference.
  3. Minor, not blocking. BUF_FMT_16_16_FLOAT reads through ldu, which handles an address that is not 4-aligned; the new entry uses plain Load(a) and Load(a + 4) like the 32-bit formats, which round down. Identical for an 8-byte element at a multiple of 8, different with an odd offset:. A sentence stating the assumption would be enough.
  4. Not verified: the "5 of 29" census and its A/B counts (local cache).

AI-assisted review; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6044130413 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#pullrequestreview-6044130413). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T17:24:46Z. **Review:** COMMENTED --- Follow-up review of head `cd654de9a50d479d8a3bc22cacce47806012d434`. My previous review was written against `92f27f1287d424cbb8b8c9dd0b7eed63814b2c81`; the author pushed this commit while I was reviewing, so GitHub attached that review to the new head. Read it as a review of 92f27f12. This one replaces it for the current head. **Linux limits.** Linux x86_64 only. No CMake configure and no `ctest` (the CMake registration is unexercised), no Windows, no DXC or FXC, no GPU. The emitted HLSL is compared as text and never compiled or run. **What changed since 92f27f12.** Only `tests/startup_gfx2hlsl_tbuffer_16f_check.py`: the hard-coded cache byte strings are replaced by an `encode_mtbuf()` that builds each instruction from the MTBUF field layout, the docstring issue number is fixed (#1695), and a default-format case is added. The table entry in `tools/startup/gfx2hlsl.py` is unchanged. **What I ran on this head** - `python3 -B tests/startup_gfx2hlsl_tbuffer_16f_check.py`: PASS. `git diff --check origin/main...HEAD`: clean. - `encode_mtbuf()` against `llvm-mc-19 -triple=amdgcn -mcpu=gfx1030 -show-encoding`: xyz, xyzw, x (format 71), xyz with format 127 and d16_xyz with format 71 all produce byte-identical output. The synthetic encoder matches the assembler, not only the repository's own decoder. - Five mutations of the table entry (y shift 16 -> 8; z offset +4 -> +8; w without `f16tof32`; w from the first dword; `asfloat` instead of `f16tof32`), each run and then restored: all FAIL, `git status` clean. **Findings** 1. Resolved: the game-derived fixture (AGENTS.md hard rule) and the issue-number typo. 2. Remaining wording. The test docstring (line 8) and the PR text still say "first main-game loading-screen cache". AGENTS.md asks for title-neutral public wording; consider "the first startup shader cache" or just the #870 reference. 3. Minor, not blocking. `BUF_FMT_16_16_FLOAT` reads through `ldu`, which handles an address that is not 4-aligned; the new entry uses plain `Load(a)` and `Load(a + 4)` like the 32-bit formats, which round down. Identical for an 8-byte element at a multiple of 8, different with an odd `offset:`. A sentence stating the assumption would be enough. 4. Not verified: the "5 of 29" census and its A/B counts (local cache). AI-assisted review; 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:20:18Z.


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:22:12.386927Z 92f27f1 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:7139043275 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#issuecomment-7139043275). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:20:18Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"92f27f1287d424cbb8b8c9dd0b7eed63814b2c81","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:22:12.386927Z">2026-11-24T17:22:12.386927Z</relative-time> | `92f27f1` | 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:24:02Z.


Already fixed in cd654de9, which is the current head of this branch — the review you posted is on 92f27f12.

What changed: the test no longer contains any cache-derived byte string. It builds each MTBUF instruction from the field layout the checked-in decoder reads (tools/disasm_rdna2.py, MTBUF branch) via a local encode_mtbuf(op, fmt, *, vdata, vaddr, srsrc, soffset, idxen, ...) helper, then calls decode() on the result and translates that. The same helper produces the two refusal cases. The PR body no longer claims any encoding comes from the cache.

Your point stands and I have recorded it as a rule for the rest of this work — the earlier PR that used cache bytes (#1693) was closed, and no test I open from here will embed game-derived data.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7139136411 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#issuecomment-7139136411). Originally posted by [triggered02](https://github.com/triggered02) on 2026-11-24T17:24:02Z. --- Already fixed in `cd654de9`, which is the current head of this branch — the review you posted is on `92f27f12`. What changed: the test no longer contains any cache-derived byte string. It builds each MTBUF instruction from the field layout the checked-in decoder reads (`tools/disasm_rdna2.py`, MTBUF branch) via a local `encode_mtbuf(op, fmt, *, vdata, vaddr, srsrc, soffset, idxen, ...)` helper, then calls `decode()` on the result and translates that. The same helper produces the two refusal cases. The PR body no longer claims any encoding comes from the cache. Your point stands and I have recorded it as a rule for the rest of this work — the earlier PR that used cache bytes (#1693) was closed, and no test I open from here will embed game-derived data.
R0Y00 commented 2026-11-24 18:02:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T17:38:39Z.


Thanks for replacing the byte strings with the field encoder. One issue on the current head: the new format still passes the computed byte address straight to ByteAddressBuffer.Load, which requires a 4-byte-aligned address. The existing 16_16_FLOAT path uses ldu because the dynamic stride and byte offset can produce a halfword-aligned address. The new path has no check that rules that out. Please use alignment-safe reads consistent with the existing half-float path, or prove and enforce a narrower address contract. A source-built GPU readback with a 2-mod-4 address and four distinct halves (including the second word's high half) should distinguish this from the aligned-only lowering. #1696 has a reusable readback harness. The clean final diff can land by squash so the earlier fixture commit stays out of main.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7139496235 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#issuecomment-7139496235). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T17:38:39Z. --- Thanks for replacing the byte strings with the field encoder. One issue on the current head: the new format still passes the computed byte address straight to ByteAddressBuffer.Load, which requires a 4-byte-aligned address. The existing 16_16_FLOAT path uses ldu because the dynamic stride and byte offset can produce a halfword-aligned address. The new path has no check that rules that out. Please use alignment-safe reads consistent with the existing half-float path, or prove and enforce a narrower address contract. A source-built GPU readback with a 2-mod-4 address and four distinct halves (including the second word's high half) should distinguish this from the aligned-only lowering. #1696 has a reusable readback harness. The clean final diff can land by squash so the earlier fixture commit stays out of main.
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:22:10Z.

Code review location: tests/startup_gfx2hlsl_tbuffer_16f_check.py; line 78

@@ -0,0 +1,111 @@
+"""Four-channel half-float typed buffer loads in tools/startup/gfx2hlsl.py (issue #1675).
+
+usage: startup_gfx2hlsl_tbuffer_16f_check.py
+
+`BUF_FMT_16_16_16_16_FLOAT` stores four binary16 channels in one 8-byte element: x and y in the first dword,
+z and w in the second. The format table had the two-channel form only, so a typed load of this format was
+refused with `buffer format BUF_FMT_16_16_16_16_FLOAT`; that refusal accounted for 5 of the 29 refused shaders
+in the first main-game loading-screen cache (#870).
+
+The cases start from encoded instructions and go through `decode()`, then the translator.
+"""
+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 a typed buffer load."""
+
+    def __init__(self):
+        self.resources, self.notes, self.modified = {}, set(), set()
+
+    def resource(self, key, kind):
+        entry = self.resources.setdefault(key, dict(index=len(self.resources), kind=kind))
+        return 'r%d' % entry['index']
+
+    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):
+        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()
+
+    def descriptor(self, tok):
+        return ('buffer', tok)
+
+
+def translate_bytes(hexbytes):
+    """Decode the bytes the way the pipeline does, then translate every decoded instruction."""
+    decoded = G.decode(bytes.fromhex(hexbytes))
+    stage = Stage()
+    for _offset, _size, name, asm in decoded:
+        stage.one(name, asm)
+    return [asm for _o, _s, _n, asm in decoded], ' '.join(stage.lines)
+
+
+def refused(hexbytes):
+    try:
+        translate_bytes(hexbytes)
+    except G.Unsupported:
+        return True
+    return False
+
+
+# 1. The decoded text is what the rest of this test assumes; a decoder change shows up here first.
+#    00203aea00000580 is a real encoding from the loading-screen cache.
+asm, emitted = translate_bytes("00203aea00000580")

P1 Badge Replace the game-cache instruction fixture

The preceding comment identifies this byte string as a real encoding from the loading-screen cache, so adding it to the test introduces game-derived dump data rather than a source-built, synthetic, or licensed public fixture. Please replace it with an allowed fixture before committing.

AGENTS.md reference: AGENTS.md:L21-L27

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4683863255 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#discussion_r4683863255). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T17:22:10Z. **Code review location:** `tests/startup_gfx2hlsl_tbuffer_16f_check.py`; line 78 ~~~~diff @@ -0,0 +1,111 @@ +"""Four-channel half-float typed buffer loads in tools/startup/gfx2hlsl.py (issue #1675). + +usage: startup_gfx2hlsl_tbuffer_16f_check.py + +`BUF_FMT_16_16_16_16_FLOAT` stores four binary16 channels in one 8-byte element: x and y in the first dword, +z and w in the second. The format table had the two-channel form only, so a typed load of this format was +refused with `buffer format BUF_FMT_16_16_16_16_FLOAT`; that refusal accounted for 5 of the 29 refused shaders +in the first main-game loading-screen cache (#870). + +The cases start from encoded instructions and go through `decode()`, then the translator. +""" +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 a typed buffer load.""" + + def __init__(self): + self.resources, self.notes, self.modified = {}, set(), set() + + def resource(self, key, kind): + entry = self.resources.setdefault(key, dict(index=len(self.resources), kind=kind)) + return 'r%d' % entry['index'] + + 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): + 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() + + def descriptor(self, tok): + return ('buffer', tok) + + +def translate_bytes(hexbytes): + """Decode the bytes the way the pipeline does, then translate every decoded instruction.""" + decoded = G.decode(bytes.fromhex(hexbytes)) + stage = Stage() + for _offset, _size, name, asm in decoded: + stage.one(name, asm) + return [asm for _o, _s, _n, asm in decoded], ' '.join(stage.lines) + + +def refused(hexbytes): + try: + translate_bytes(hexbytes) + except G.Unsupported: + return True + return False + + +# 1. The decoded text is what the rest of this test assumes; a decoder change shows up here first. +# 00203aea00000580 is a real encoding from the loading-screen cache. +asm, emitted = translate_bytes("00203aea00000580") ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Replace the game-cache instruction fixture** The preceding comment identifies this byte string as a real encoding from the loading-screen cache, so adding it to the test introduces game-derived dump data rather than a source-built, synthetic, or licensed public fixture. Please replace it with an allowed fixture before committing. AGENTS.md reference: [AGENTS.md:L21-L27](https://github.com/R0Y00/Xbox2Windows/blob/92f27f1287d424cbb8b8c9dd0b7eed63814b2c81/AGENTS.md#L21-L27) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
upstream-sync closed this pull request 2026-11-24 20:00:24 +00:00
tedin7 commented 2026-11-24 20:00:25 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 59471eeddaa8a37fea37caefdf49bc3a902d0ef6 (4 commits over main: 92f27f12, cd654de9, merge ea111d9a, 59471eed; touches tools/startup/gfx2hlsl.py +4, two tests, CMakeLists.txt +3, docs/experiments.md +10). My earlier reviews were on 92f27f12 and cd654de9; this one covers what changed since, mainly 59471eed.

Verdict: no blocking finding. The alignment point raised on the previous head is fixed in the lowering, and the new readback case is shaped to catch it.

Linux limits. Linux x86_64 only. No CMake configure and no ctest, no Windows, no DXC or FXC, no GPU. I could not run the pipeline's Windows helper from here, so the WARP and RTX 4060 Laptop results in the author's comment of 19:14Z are reported, not reproduced by me. The emitted HLSL is compared as text and not compiled.

What changed since cd654de9. The table entry now reads both packed dwords through ldu:
'BUF_FMT_16_16_16_16_FLOAT': (None, ['U(f16tof32(ldu({0}, a)))', 'U(f16tof32(ldu({0}, a) >> 16))', 'U(f16tof32(ldu({0}, a + 4)))', 'U(f16tof32(ldu({0}, a + 4) >> 16))'])
(tools/startup/gfx2hlsl.py:695-698). ldu is emitted in every prologue (gfx2hlsl.py:1245), so it is defined whenever the entry is used. For a & 3 == 2 both reads cross a dword boundary and ldu handles that; the second read at a + 4 has the same alignment as the first. Only the requested channels are loaded (x reads one ldu, xyz does not touch the high half of the second dword). The vertex-fetch fixture gains BUF_FMT_16_16_16_16_FLOAT with stride 18 and offset 10 (tests/startup_vertex_fetch_formats_check.py:49), so vertices alternate between address 2 mod 4 and 0 mod 4; the controls now require four distinct normal halves per vertex for every f16 format (lines 151-159) and a new mutation second dword aligned down (lines 125-126).

What I ran on this head (worktree at the exact SHA; git status clean after every mutation)

  • python3 -B tests/startup_gfx2hlsl_tbuffer_16f_check.py: PASS.
  • python3 -B tests/startup_vertex_fetch_formats_check.py controls: passed.
  • git diff --check origin/main...HEAD: clean. tests/docs_links_check.py: 17 files, 366 links. tests/bidi_controls_check.py: no bidirectional controls.
  • Three source mutations, each restored: second dword read at a + 8 instead of a + 4; the w channel without >> 16; the first dword read with Load(a & ~3u) instead of ldu. All three make startup_gfx2hlsl_tbuffer_16f_check.py exit 1. The controls mode of the vertex-fetch check is red only for the w-channel one (rc 1; the other two give rc 0), which is expected: the aligned-down and wrong-offset cases are decided by the GPU readback, which I did not run.

Findings

  1. P3, wording, still open from my previous review: docs/experiments.md (new paragraph) and the test docstring still say "first main-game loading-screen cache". AGENTS.md asks for title-neutral public text; "the first startup shader cache" or just "#870" would do.
  2. Not verified by me: the "5 of 29" census and the A/B counts (local cache), and the GPU result of startup_vertex_fetch_formats_{warp,hardware} on this SHA. If the author's 4/4 Windows Release run is the evidence, a line naming the SHA it ran on would close the loop (the comment says "I pushed 59471eed" and then reports the run, so it reads as this head).

Resolved since my last review: the unaligned-address assumption (previous finding 3).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6045789029 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#pullrequestreview-6045789029). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:19:42Z. **Review:** COMMENTED --- Review of head `59471eeddaa8a37fea37caefdf49bc3a902d0ef6` (4 commits over main: `92f27f12`, `cd654de9`, merge `ea111d9a`, `59471eed`; touches `tools/startup/gfx2hlsl.py` +4, two tests, `CMakeLists.txt` +3, `docs/experiments.md` +10). My earlier reviews were on `92f27f12` and `cd654de9`; this one covers what changed since, mainly `59471eed`. **Verdict: no blocking finding.** The alignment point raised on the previous head is fixed in the lowering, and the new readback case is shaped to catch it. **Linux limits.** Linux x86_64 only. No CMake configure and no `ctest`, no Windows, no DXC or FXC, no GPU. I could not run the pipeline's Windows helper from here, so the WARP and RTX 4060 Laptop results in the author's comment of 19:14Z are reported, not reproduced by me. The emitted HLSL is compared as text and not compiled. **What changed since `cd654de9`.** The table entry now reads both packed dwords through `ldu`: `'BUF_FMT_16_16_16_16_FLOAT': (None, ['U(f16tof32(ldu({0}, a)))', 'U(f16tof32(ldu({0}, a) >> 16))', 'U(f16tof32(ldu({0}, a + 4)))', 'U(f16tof32(ldu({0}, a + 4) >> 16))'])` (`tools/startup/gfx2hlsl.py:695-698`). `ldu` is emitted in every prologue (`gfx2hlsl.py:1245`), so it is defined whenever the entry is used. For `a & 3 == 2` both reads cross a dword boundary and `ldu` handles that; the second read at `a + 4` has the same alignment as the first. Only the requested channels are loaded (x reads one `ldu`, xyz does not touch the high half of the second dword). The vertex-fetch fixture gains `BUF_FMT_16_16_16_16_FLOAT` with stride 18 and offset 10 (`tests/startup_vertex_fetch_formats_check.py:49`), so vertices alternate between address `2 mod 4` and `0 mod 4`; the controls now require four distinct normal halves per vertex for every f16 format (lines 151-159) and a new mutation `second dword aligned down` (lines 125-126). **What I ran on this head** (worktree at the exact SHA; `git status` clean after every mutation) - `python3 -B tests/startup_gfx2hlsl_tbuffer_16f_check.py`: PASS. - `python3 -B tests/startup_vertex_fetch_formats_check.py controls`: passed. - `git diff --check origin/main...HEAD`: clean. `tests/docs_links_check.py`: 17 files, 366 links. `tests/bidi_controls_check.py`: no bidirectional controls. - Three source mutations, each restored: second dword read at `a + 8` instead of `a + 4`; the w channel without `>> 16`; the first dword read with `Load(a & ~3u)` instead of `ldu`. All three make `startup_gfx2hlsl_tbuffer_16f_check.py` exit 1. The `controls` mode of the vertex-fetch check is red only for the w-channel one (rc 1; the other two give rc 0), which is expected: the aligned-down and wrong-offset cases are decided by the GPU readback, which I did not run. **Findings** 1. P3, wording, still open from my previous review: `docs/experiments.md` (new paragraph) and the test docstring still say "first main-game loading-screen cache". AGENTS.md asks for title-neutral public text; "the first startup shader cache" or just "#870" would do. 2. Not verified by me: the "5 of 29" census and the A/B counts (local cache), and the GPU result of `startup_vertex_fetch_formats_{warp,hardware}` on this SHA. If the author's 4/4 Windows Release run is the evidence, a line naming the SHA it ran on would close the loop (the comment says "I pushed 59471eed" and then reports the run, so it reads as this head). Resolved since my last review: the unaligned-address assumption (previous finding 3). AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-24 20:01:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T19:14:05Z.


I pushed 59471eed. Both packed dwords use the existing alignment-safe loader. The vertex-fetch test now includes four distinct binary16 values at alternating aligned and halfword-aligned addresses. WARP and RTX 4060 Laptop matched the expected words, and aligning the second dword down changed the result as required. Windows Release passed the typed-buffer and vertex-format checks 4/4. This clean final diff will use squash so the superseded fixture commit stays out of main.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7141797839 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1699#issuecomment-7141797839). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-24T19:14:05Z. --- I pushed 59471eed. Both packed dwords use the existing alignment-safe loader. The vertex-fetch test now includes four distinct binary16 values at alternating aligned and halfword-aligned addresses. WARP and RTX 4060 Laptop matched the expected words, and aligning the second dword down changed the result as required. Windows Release passed the typed-buffer and vertex-format checks 4/4. This clean final diff will use squash so the superseded fixture commit stays out of main.
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!1692
No description provided.