shader: unpack A16 coordinates for startup image loads #1847

Merged
avt0m4t48 merged 2 commits from upstream-pr/1854 into main 2026-11-24 19:56:19 +00:00
avt0m4t48 commented 2026-11-24 19:38:38 +00:00 (Migrated from github.com)

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


The startup pixel translator currently reads two full-width VGPRs for a plain 2D image load with A16 set. The source-built fixture packs x=1 and y=2 into one register and puts 63 in the next register so the two layouts cannot accidentally agree.

Decode the two unsigned halves, preserve full-width mip-zero behavior, and refuse D16 results and TFE status layouts explicitly. Advance both the runtime and offline shader cache keys so older translations are regenerated.

Verification on Linux:

  • python3 -B tests/startup_image_load_mip_check.py --llvm-mc /tmp/scarlett-tools.7m6eFM/root/usr/bin/llvm-mc-19 passed on the rebased patch. The A16 regression failed before the fix. LLVM 15 also reproduced the fixture bytes on the original topic base.
  • DXC compiled and its validator accepted the generated pixel shader. The DXIL loads coordinates (1, 2) at mip 0.
  • The portable CI Python checks exited zero on the original topic base. Windows D3D12 execution and title behavior remain unverified.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6589886091 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1854). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-24T19:38:38Z. --- The startup pixel translator currently reads two full-width VGPRs for a plain 2D image load with A16 set. The source-built fixture packs x=1 and y=2 into one register and puts 63 in the next register so the two layouts cannot accidentally agree. Decode the two unsigned halves, preserve full-width mip-zero behavior, and refuse D16 results and TFE status layouts explicitly. Advance both the runtime and offline shader cache keys so older translations are regenerated. Verification on Linux: - `python3 -B tests/startup_image_load_mip_check.py --llvm-mc /tmp/scarlett-tools.7m6eFM/root/usr/bin/llvm-mc-19` passed on the rebased patch. The A16 regression failed before the fix. LLVM 15 also reproduced the fixture bytes on the original topic base. - DXC compiled and its validator accepted the generated pixel shader. The DXIL loads coordinates (1, 2) at mip 0. - The portable CI Python checks exited zero on the original topic base. Windows D3D12 execution and title behavior remain unverified.
upstream-sync closed this pull request 2026-11-24 20:01:03 +00:00
tedin7 commented 2026-11-24 20:01:04 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of 56bd3bd1 (merge base 5f16bc20; origin/main is now 8a61ae06). Comment only, not an approval.

Verdict

No P1 or P2 found. The A16 lowering matches the encoding it claims to model, and the tests that matter kill my mutants. Three P3 notes below. Clean-room and title-neutral: the fixture is synthetic (x=1, y=2 packed in v0, 63 in v1), no game files, dumps or titles.

What I checked

  • A16 packing: for a plain 2D image_load, x is the low and y the high unsigned half of one VGPR, so r0.Load(int3(v0 & 0xffffu, v0 >> 16, 0)) is the right shape. The d3d12_draw.inl and gfx2hlsl.py revision strings are both bumped to -5 and the test pins that the key changed.
  • Refusals: d16, tfe and a16 on 3D are refused with Unsupported, and a16 is not accepted for image_load_mip. dmask and dim handling are unchanged for the accepted path.
  • Disassembler: the one-register count applies only to image_load + 2D + a16, so other MIMG ops keep their old address count.

P3: scope of the stricter check

The modifier allow-list (dim:, dmask:, unorm, glc, slc, dlc, plus a16 when packed) used to apply only to image_load_mip. It now applies to every plain image_load, and an empty dmask is refused too. That is stricter, and I think correct (r128, lwe and tfe were silently read as plain loads), but the description only mentions d16/tfe. A capture that carries one of those bits will now stop with Unsupported instead of translating. Worth one sentence in the description or docs.

P3: guards not pinned by the test

Mutants run one at a time against tests/startup_image_load_mip_check.py --llvm-mc llvm-mc-19:

  • killed: packed path off, >> 16 changed to >> 8, low-half mask dropped, Python key revision reverted, disassembler one-register rule dropped, unsupported-modifier check dropped.
  • survived: dropping (packed_2d and len(cs) != 1) from wrong_address. No case feeds an a16 load a two-register address, so that refusal is untested.
  • Not tested at all: the C++ revision in d3d12_draw.inl agreeing with the Python pipeline_key string. Only the Python side is asserted. They match here (git grep x2w-startup-shader-), but a later bump of one would pass CI.

P3: no NSA a16 case

The disassembler sets the address count to 1 for a16 loads whatever the encoding. I did not build an NSA-encoded a16 load, so I cannot say whether it decodes sensibly.

Commands run (Linux, Python 3.14.8, llvm-mc-19 for the fixture bytes)

  • python -B tests/startup_image_load_mip_check.py --llvm-mc llvm-mc-19: passes; also passes without --llvm-mc.
  • The other 36 tests that import gfx2hlsl or disasm_rdna2, run with no arguments on this SHA and on origin/main: identical exit codes everywhere (the ones that exit 1 do so on both, because they need DXC or extra arguments). rdna2_tools_check.py: OK (skipped=18).
  • python -B tests/docs_links_check.py: Self-test passed. Checked 18 Markdown files and 370 links.
  • python -B tests/bidi_controls_check.py: Self-test passed. Checked 1324 tracked source, script and build/CI files: no bidirectional controls.
  • git diff --check origin/main...HEAD: clean.
  • All mutations reverted with git checkout -- ..

Not run

Windows D3D12 execution, DXC validation of the generated shader, and CI's llvm-mc-15 (I used 19). Whether hardware reads A16 loads the way the translation assumes is not something Linux checks.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046181989 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1854#pullrequestreview-6046181989). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:45:04Z. **Review:** COMMENTED --- Review of `56bd3bd1` (merge base `5f16bc20`; `origin/main` is now `8a61ae06`). Comment only, not an approval. ## Verdict No P1 or P2 found. The A16 lowering matches the encoding it claims to model, and the tests that matter kill my mutants. Three P3 notes below. Clean-room and title-neutral: the fixture is synthetic (x=1, y=2 packed in v0, 63 in v1), no game files, dumps or titles. ## What I checked - A16 packing: for a plain 2D `image_load`, x is the low and y the high unsigned half of one VGPR, so `r0.Load(int3(v0 & 0xffffu, v0 >> 16, 0))` is the right shape. The `d3d12_draw.inl` and `gfx2hlsl.py` revision strings are both bumped to `-5` and the test pins that the key changed. - Refusals: `d16`, `tfe` and `a16` on 3D are refused with `Unsupported`, and `a16` is not accepted for `image_load_mip`. dmask and dim handling are unchanged for the accepted path. - Disassembler: the one-register count applies only to `image_load` + 2D + a16, so other MIMG ops keep their old address count. ## P3: scope of the stricter check The modifier allow-list (`dim:`, `dmask:`, `unorm`, `glc`, `slc`, `dlc`, plus `a16` when packed) used to apply only to `image_load_mip`. It now applies to every plain `image_load`, and an empty dmask is refused too. That is stricter, and I think correct (r128, lwe and tfe were silently read as plain loads), but the description only mentions d16/tfe. A capture that carries one of those bits will now stop with `Unsupported` instead of translating. Worth one sentence in the description or docs. ## P3: guards not pinned by the test Mutants run one at a time against `tests/startup_image_load_mip_check.py --llvm-mc llvm-mc-19`: - killed: packed path off, `>> 16` changed to `>> 8`, low-half mask dropped, Python key revision reverted, disassembler one-register rule dropped, unsupported-modifier check dropped. - survived: dropping `(packed_2d and len(cs) != 1)` from `wrong_address`. No case feeds an `a16` load a two-register address, so that refusal is untested. - Not tested at all: the C++ `revision` in `d3d12_draw.inl` agreeing with the Python `pipeline_key` string. Only the Python side is asserted. They match here (`git grep x2w-startup-shader-`), but a later bump of one would pass CI. ## P3: no NSA a16 case The disassembler sets the address count to 1 for a16 loads whatever the encoding. I did not build an NSA-encoded a16 load, so I cannot say whether it decodes sensibly. ## Commands run (Linux, Python 3.14.8, llvm-mc-19 for the fixture bytes) - `python -B tests/startup_image_load_mip_check.py --llvm-mc llvm-mc-19`: passes; also passes without `--llvm-mc`. - The other 36 tests that import `gfx2hlsl` or `disasm_rdna2`, run with no arguments on this SHA and on `origin/main`: identical exit codes everywhere (the ones that exit 1 do so on both, because they need DXC or extra arguments). `rdna2_tools_check.py`: OK (skipped=18). - `python -B tests/docs_links_check.py`: Self-test passed. Checked 18 Markdown files and 370 links. - `python -B tests/bidi_controls_check.py`: Self-test passed. Checked 1324 tracked source, script and build/CI files: no bidirectional controls. - `git diff --check origin/main...HEAD`: clean. - All mutations reverted with `git checkout -- .`. ## Not run Windows D3D12 execution, DXC validation of the generated shader, and CI's `llvm-mc-15` (I used 19). Whether hardware reads A16 loads the way the translation assumes is not something Linux checks. AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-24 20:01:04 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Re-review of the new head 5b46e98e (one commit on top of 56bd3bd1, which I reviewed earlier; merge base 5f16bc20, origin/main is now dd753176 and git merge-tree merges cleanly). Comment only, not an approval.

Verdict

All four points from my earlier review are addressed, each with a test that fails when the fix is removed. No new P1 or P2.

The earlier findings, one by one

  1. a16 with two address registers was untested. Now check_plain_load_layouts calls pipe.ps.image([..., '[v0, v1]', ...], [..., 'a16'], 'load') and requires Unsupported. Mutant: dropping (packed_2d and len(cs) != 1) from wrong_address now fails with A16 image load accepted two address registers.
  2. C++ and Python cache revisions were not compared. The test now reads revision[] from src/startup_stubs/d3d12_draw.inl and requires that the key built from it equals pipeline_key(). Mutants: C++ string back to -4, and drifted to -6: both fail with offline and desktop startup cache revisions differ.
  3. NSA-encoded a16 loads. disasm_rdna2.py now adds an invalid_nsa modifier when a packed 2D load carries an NSA extension, the translator refuses it by name, and the test patches a real encoding (0a0f00f000040440 01000000) to prove it. Mutant: removing the invalid_nsa marker fails with invalid_nsa image load accepted with unsupported layout.
  4. Wider modifier check. The docs now say plain loads refuse an empty dmask, r128, lwe, d16, tfe and reserved bits, and the test has one case for each (r128, lwe, reserved bit, dmask:0x0). Mutant: removing the unsupported-modifier check fails on d16.

Other mutants I ran, all killed: packed path off, >> 16 changed to >> 8, the disassembler one-register rule dropped.

Commands run (Linux, Python 3.14.8, llvm-mc-19)

  • python -B tests/startup_image_load_mip_check.py --llvm-mc llvm-mc-19: passes; also passes with no argument. tests/rdna2_tools_check.py: OK (skipped=18).
  • The 37 tests that import gfx2hlsl or disasm_rdna2, run on this head and on origin/main: identical exit codes for every one (those that exit 1 do so on both, they need DXC or extra arguments).
  • python -B tests/docs_links_check.py: Self-test passed. Checked 18 Markdown files and 370 links.
  • python -B tests/bidi_controls_check.py: Self-test passed. Checked 1324 tracked source, script and build/CI files: no bidirectional controls.
  • git diff --check origin/main...HEAD: clean. All mutations reverted with git checkout -- ..

Not run

Windows D3D12 execution, DXC validation of the generated shader, and CI's llvm-mc-15 (I used 19). Whether hardware reads A16 loads this way is not something Linux checks.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6046362598 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1854#pullrequestreview-6046362598). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T19:56:32Z. **Review:** COMMENTED --- Re-review of the new head `5b46e98e` (one commit on top of `56bd3bd1`, which I reviewed earlier; merge base `5f16bc20`, `origin/main` is now `dd753176` and `git merge-tree` merges cleanly). Comment only, not an approval. ## Verdict All four points from my earlier review are addressed, each with a test that fails when the fix is removed. No new P1 or P2. ## The earlier findings, one by one 1. **`a16` with two address registers was untested.** Now `check_plain_load_layouts` calls `pipe.ps.image([..., '[v0, v1]', ...], [..., 'a16'], 'load')` and requires `Unsupported`. Mutant: dropping `(packed_2d and len(cs) != 1)` from `wrong_address` now fails with `A16 image load accepted two address registers`. 2. **C++ and Python cache revisions were not compared.** The test now reads `revision[]` from `src/startup_stubs/d3d12_draw.inl` and requires that the key built from it equals `pipeline_key()`. Mutants: C++ string back to `-4`, and drifted to `-6`: both fail with `offline and desktop startup cache revisions differ`. 3. **NSA-encoded `a16` loads.** `disasm_rdna2.py` now adds an `invalid_nsa` modifier when a packed 2D load carries an NSA extension, the translator refuses it by name, and the test patches a real encoding (`0a0f00f000040440 01000000`) to prove it. Mutant: removing the `invalid_nsa` marker fails with `invalid_nsa image load accepted with unsupported layout`. 4. **Wider modifier check.** The docs now say plain loads refuse an empty `dmask`, `r128`, `lwe`, `d16`, `tfe` and reserved bits, and the test has one case for each (`r128`, `lwe`, reserved bit, `dmask:0x0`). Mutant: removing the unsupported-modifier check fails on `d16`. Other mutants I ran, all killed: packed path off, `>> 16` changed to `>> 8`, the disassembler one-register rule dropped. ## Commands run (Linux, Python 3.14.8, llvm-mc-19) - `python -B tests/startup_image_load_mip_check.py --llvm-mc llvm-mc-19`: passes; also passes with no argument. `tests/rdna2_tools_check.py`: OK (skipped=18). - The 37 tests that import `gfx2hlsl` or `disasm_rdna2`, run on this head and on `origin/main`: identical exit codes for every one (those that exit 1 do so on both, they need DXC or extra arguments). - `python -B tests/docs_links_check.py`: Self-test passed. Checked 18 Markdown files and 370 links. - `python -B tests/bidi_controls_check.py`: Self-test passed. Checked 1324 tracked source, script and build/CI files: no bidirectional controls. - `git diff --check origin/main...HEAD`: clean. All mutations reverted with `git checkout -- .`. ## Not run Windows D3D12 execution, DXC validation of the generated shader, and CI's `llvm-mc-15` (I used 19). Whether hardware reads A16 loads this way is not something Linux checks. AI-assisted; commands listed were executed locally.
avt0m4t48 commented 2026-11-24 20:01:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by avt0m4t48 on 2026-11-24T19:51:30Z.


Follow-up is in 5b46e98e. The docs now list the plain-load refusals. The regression checks the two-register lowering refusal and derives the expected offline key from the revision in the C++ runtime.

With llvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encoding, [v0] emitted the same 8 bytes as v0 and [v0,v1] failed the address-size check. The decoder had accepted a patched 12-byte instruction by discarding the extra address word. It now preserves that invalid encoding as invalid_nsa, which the startup lowering refuses. The new control reproduced the old acceptance before the fix.

The focused fixture passed with LLVM 15 and 19. The LLVM 15 disassembler suite passed 147 cases with one skip. Windows GPU execution of the A16 shader remains unverified.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7142687547 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1854#issuecomment-7142687547). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-24T19:51:30Z. --- Follow-up is in `5b46e98e`. The docs now list the plain-load refusals. The regression checks the two-register lowering refusal and derives the expected offline key from the revision in the C++ runtime. With `llvm-mc-19 -arch=amdgcn -mcpu=gfx1013 -show-encoding`, `[v0]` emitted the same 8 bytes as `v0` and `[v0,v1]` failed the address-size check. The decoder had accepted a patched 12-byte instruction by discarding the extra address word. It now preserves that invalid encoding as `invalid_nsa`, which the startup lowering refuses. The new control reproduced the old acceptance before the fix. The focused fixture passed with LLVM 15 and 19. The LLVM 15 disassembler suite passed 147 cases with one skip. Windows GPU execution of the A16 shader remains unverified.
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!1847
No description provided.