shader: pin compressed EXP enable-mask decoding across all 16 raw EN values #428

Merged
abilliontokens merged 4 commits from upstream-pr/434 into main 2026-11-23 07:02:12 +00:00
abilliontokens commented 2026-11-22 02:42:37 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by abilliontokens on 2026-11-22T02:42:37Z.


Owner-requested decoding fixture for #361 (comment 7072921152). Stacked on #398, which stacks on #363; review the base PRs first.

Change

Generate the reference compressed export from source (exp mrt0 v16, v16, v17, v17 done compr vm assembles to 0f 1c 00 f8 10 11 00 00: EN is the low nibble of byte 0, byte 1 carries compr/done/vm, and the source VGPRs v16/v17 sit in bytes 4/5). Then independently replace only the four EN bits in the instruction word and exercise all 16 raw masks through the normal binary → disassemble → lower path.

The new check_exp_en_decoding runs as part of the CPU binary gate (tests/pixel_aot_check.py binary) and asserts, for every raw value:

  • Encoded mask: reassembling the disassembled text yields exactly the measured EN.
  • Unchanged source registers: an enabled channel prints its packed source VGPR (v16 for channels 0/1, v17 for channels 2/3) and a disabled channel prints off; raw EN=0x5 prints v16, off, v17, off.
  • Every bit outside EN: the re-encoded word matches the reference outside the EN nibble, with one measured exception — the assembler re-encodes the source-VGPR field of a fully disabled pair as zero.
  • LLVM round-trip: {0x0, 0x3, 0xC, 0xF} round-trip as masks; 0x3/0xC/0xF lower from the patched word identically to the normalized fixture and lower(return_write_mask=True) reports that mask. 0x0 round-trips byte-wise but enables no pair and stays refused.
  • Explicit rejection: every non-pair compressed mask is rejected by lowering with a targeted diagnostic (does not enable whole packed pairs) instead of the generic fall-through; the fixture pins that message. Form coverage counts only accepted programs, so non-pair compressed masks remain excluded.

Measured re-encodings, individually

raw EN 0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf
re-encoded 0x0 0x3 0x0 0x3 0xc 0xf 0xc 0xf 0x0 0x3 0x0 0x3 0xc 0xf 0xc 0xf

The rule is pair-first-operand presence: a packed pair survives reassembly exactly when its first operand (VSRC0/VSRC2) is enabled; the duplicated high-half operand never enables its pair. That is why 0x2 → 0x0 and 0xa → 0x0 (only the duplicated high-half operand is enabled, so the pair is lost) while 0x5 → 0xf (both first operands enabled). A pairwise OR over both operands of each pair would mispredict the first two as 0x3 and 0xf; the fixture asserts the measured values instead.

Evidence

  • Non-pair compressed masks are rejected by lowering and excluded from form coverage; no accepted form or recorded program changes.
  • Draw behavior for non-pair compressed masks remains deferred: enabling it needs either an ISA definition specific to gfx1013 compressed exports or native execution evidence identifying the channels actually written, then distinct RGBA source values, sentinels for unwritten channels and a negative control in a Windows draw.
  • #429's uncompressed path proceeds independently of this evidence.

Verification

LLVM 15.0.7 gfx1013 tools; no C++ changed.

out/pe-env/Scripts/python.exe -B tests/pixel_aot_check.py binary <llvm-mc> <objcopy> <LLVM-C.dll>   # pass (binary round trip + controls + decoding fixture)
out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py                                      # pass
ctest --test-dir out/build/dev-361dec --no-tests=error -R '^pixel_aot_warp$' --output-on-failure    # pass

CI covers the hardware draws.

Refs #361

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6537503380 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/434). Originally posted by [abilliontokens](https://github.com/abilliontokens) on 2026-11-22T02:42:37Z. --- Owner-requested decoding fixture for #361 (comment 7072921152). Stacked on #398, which stacks on #363; review the base PRs first. ## Change Generate the reference compressed export from source (`exp mrt0 v16, v16, v17, v17 done compr vm` assembles to `0f 1c 00 f8 10 11 00 00`: EN is the low nibble of byte 0, byte 1 carries compr/done/vm, and the source VGPRs v16/v17 sit in bytes 4/5). Then independently replace only the four EN bits in the instruction word and exercise all 16 raw masks through the normal binary → disassemble → lower path. The new `check_exp_en_decoding` runs as part of the CPU binary gate (`tests/pixel_aot_check.py binary`) and asserts, for every raw value: - **Encoded mask**: reassembling the disassembled text yields exactly the measured EN. - **Unchanged source registers**: an enabled channel prints its packed source VGPR (v16 for channels 0/1, v17 for channels 2/3) and a disabled channel prints `off`; raw EN=0x5 prints `v16, off, v17, off`. - **Every bit outside EN**: the re-encoded word matches the reference outside the EN nibble, with one measured exception — the assembler re-encodes the source-VGPR field of a fully disabled pair as zero. - **LLVM round-trip**: {0x0, 0x3, 0xC, 0xF} round-trip as masks; 0x3/0xC/0xF lower from the patched word identically to the normalized fixture and `lower(return_write_mask=True)` reports that mask. 0x0 round-trips byte-wise but enables no pair and stays refused. - **Explicit rejection**: every non-pair compressed mask is rejected by lowering with a targeted diagnostic (`does not enable whole packed pairs`) instead of the generic fall-through; the fixture pins that message. Form coverage counts only accepted programs, so non-pair compressed masks remain excluded. ### Measured re-encodings, individually | raw EN | 0x0 | 0x1 | 0x2 | 0x3 | 0x4 | 0x5 | 0x6 | 0x7 | 0x8 | 0x9 | 0xa | 0xb | 0xc | 0xd | 0xe | 0xf | |---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---| | re-encoded | 0x0 | 0x3 | 0x0 | 0x3 | 0xc | 0xf | 0xc | 0xf | 0x0 | 0x3 | 0x0 | 0x3 | 0xc | 0xf | 0xc | 0xf | The rule is **pair-first-operand presence**: a packed pair survives reassembly exactly when its first operand (VSRC0/VSRC2) is enabled; the duplicated high-half operand never enables its pair. That is why `0x2 → 0x0` and `0xa → 0x0` (only the duplicated high-half operand is enabled, so the pair is lost) while `0x5 → 0xf` (both first operands enabled). A pairwise OR over both operands of each pair would mispredict the first two as `0x3` and `0xf`; the fixture asserts the measured values instead. ## Evidence - Non-pair compressed masks are rejected by lowering and excluded from form coverage; no accepted form or recorded program changes. - Draw behavior for non-pair compressed masks remains deferred: enabling it needs either an ISA definition specific to gfx1013 compressed exports or native execution evidence identifying the channels actually written, then distinct RGBA source values, sentinels for unwritten channels and a negative control in a Windows draw. - #429's uncompressed path proceeds independently of this evidence. ## Verification LLVM 15.0.7 gfx1013 tools; no C++ changed. ``` out/pe-env/Scripts/python.exe -B tests/pixel_aot_check.py binary <llvm-mc> <objcopy> <LLVM-C.dll> # pass (binary round trip + controls + decoding fixture) out/pe-env/Scripts/python.exe -B tests/form_coverage_check.py # pass ctest --test-dir out/build/dev-361dec --no-tests=error -R '^pixel_aot_warp$' --output-on-failure # pass ``` CI covers the hardware draws. Refs #361
upstream-sync closed this pull request 2026-11-24 06:43:02 +00:00
R0Y00 commented 2026-11-24 06:49:03 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T06:44:51Z.


I pushed fd0d8cc after #398 landed, preserving the author’s full 16-value fixture. The local gfx1013 binary suite passed with LLVM 15.0.7. It checks the raw nibble, the disassembly/reassembly mapping and rejection during lowering of unsupported masks. The raw experiment does not establish native channel-write behavior for those masks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7093635036 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/434#issuecomment-7093635036). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T06:44:51Z. --- I pushed `fd0d8cc` after #398 landed, preserving the author’s full 16-value fixture. The local gfx1013 binary suite passed with LLVM 15.0.7. It checks the raw nibble, the disassembly/reassembly mapping and rejection during lowering of unsupported masks. The raw experiment does not establish native channel-write behavior for those masks.
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!428
No description provided.