shader: format the v_readfirstlane_b32 SGPR and reject the VOP3A word #772

Merged
FZNull merged 1 commit from upstream-pr/778 into main 2026-11-23 03:10:48 +00:00
FZNull commented 2026-11-23 02:37:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T02:37:48Z.


Summary

tools/disasm_rdna2.py formatted every VOP1 destination as a VGPR, so the #746 bytes decoded as v_readfirstlane_b32 v2, v0 instead of v_readfirstlane_b32 s2, v0. The VOP1 path now formats that destination through decode_s_reg(vdst); the source stays a VGPR.

The proposed VOP3A word from the issue also decoded as a valid instruction (v_readfirstlane_b32 v2, v0). On gfx1013 this operation only exists as the 32-bit VOP1, so the VOP3A path now returns a distinct unsupported-encoding record, v_readfirstlane_b32 <unsupported VOP3A encoding>. It consumes exactly eight bytes and is neither recognized nor supported by the scanner, so no instruction reaches a lowerer. The following s_endpgm still decodes at +8.

Fixes #746. Disassembler and tests only; the pixel_aot lowering belongs to #765.

Maintainer confirmation and how this follows it

R0Y00 on #765: "LLVM 15 on gfx1013 confirmed the VOP1 SGPR destination and rejected the _e64 spelling and the proposed VOP3A bytes. Please keep the VOP1 fix and make the invalid VOP3A record consume exactly eight bytes without handing an instruction to the lowerer. Keep a following s_endpgm in both controls."

  • kept the VOP1 decode_s_reg fix, re-verified against LLVM here;
  • the invalid VOP3A record consumes exactly 8 bytes and is a distinct unsupported-encoding record;
  • both controls keep a following s_endpgm, and the VOP3A control shows it at offset 8;
  • no lowering change.

LLVM round trip

LLVM 21.1.8 here (-triple=amdgcn--amdpal -mcpu=gfx1013); R0Y00 confirmed the same with LLVM 15.

$ echo 'v_readfirstlane_b32 s2, v0' | llvm-mc ... -show-encoding
	v_readfirstlane_b32 s2, v0              ; encoding: [0x00,0x05,0x04,0x7e]
$ disassemble 00 05 04 7e
	v_readfirstlane_b32 s2, v0

The alignment stream

v_readfirstlane_b32 s2, v0
v_mov_b32_e32 v0, v1
s_endpgm

assembles to [0x00,0x05,0x04,0x7e], [0x01,0x03,0x00,0x7e], [0x00,0x00,0x81,0xbf], and disassembling those bytes returns the three instructions at +0/+4/+8.

The same target assembles no other shape:

$ echo 'v_readfirstlane_b32_e64 s2, v0' | llvm-mc ...
error: e64 variant of this instruction is not supported
$ echo 'v_readfirstlane_b32 v2, v0' | llvm-mc ...
error: invalid operand for instruction
$ echo 'v_readfirstlane_b32 s2, s0' | llvm-mc ...
error: invalid operand for instruction
$ disassemble 02 00 82 d5 00 01 00 00
warning: invalid instruction encoding

Tests

python -B tests/rdna2_tools_check.py
Ran 59 tests in 1.691s
OK (skipped=1)

The skip is the existing test_llvm_comparison, which needs LLVM_LIB; its fixture list now contains v_readfirstlane_b32 s2, v0, so the LLVM 15 gfx1013 CI job exercises the same round trip.

ctest --test-dir out/build/dev --no-tests=error -R 'rdna2_tools|pixel_aot_' -V
100% tests passed out of 35
Total Test time (real) = 281.25 sec

test_vop1_readfirstlane_b32_destination_is_an_sgpr covers:

  • VOP1 0005047e -> v_readfirstlane_b32 s2, v0 (SGPR destination, VGPR source preserved);
  • VOP1 control 0005047e 000081bf -> records at +0 and +4, following s_endpgm visible;
  • alignment control 0005047e 0103007e 000081bf -> +0/+4/+8;
  • negative control 0103047e -> v_mov_b32_e32 v2, v1;
  • VOP3A control 020082d500010000 000081bf -> distinct unsupported-encoding record at +0, length 8, is_opcode_recognized and is_instruction_supported both false, and s_endpgm at +8.

Two mutants were checked: reverting the whole change fails on the VOP1 assertion, and dropping only the VOP3A hunk fails on the unsupported-record assertion.

A passing fixture supports the behavior under test; full-game startup remains unverified.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6551110314 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/778). Originally posted by [FZNull](https://github.com/FZNull) on 2026-11-23T02:37:48Z. --- ## Summary `tools/disasm_rdna2.py` formatted every VOP1 destination as a VGPR, so the #746 bytes decoded as `v_readfirstlane_b32 v2, v0` instead of `v_readfirstlane_b32 s2, v0`. The VOP1 path now formats that destination through `decode_s_reg(vdst)`; the source stays a VGPR. The proposed VOP3A word from the issue also decoded as a valid instruction (`v_readfirstlane_b32 v2, v0`). On `gfx1013` this operation only exists as the 32-bit VOP1, so the VOP3A path now returns a distinct unsupported-encoding record, `v_readfirstlane_b32 <unsupported VOP3A encoding>`. It consumes exactly eight bytes and is neither recognized nor supported by the scanner, so no instruction reaches a lowerer. The following `s_endpgm` still decodes at +8. Fixes #746. Disassembler and tests only; the `pixel_aot` lowering belongs to #765. ## Maintainer confirmation and how this follows it R0Y00 on #765: *"LLVM 15 on `gfx1013` confirmed the VOP1 SGPR destination and rejected the `_e64` spelling and the proposed VOP3A bytes. Please keep the VOP1 fix and make the invalid VOP3A record consume exactly eight bytes without handing an instruction to the lowerer. Keep a following `s_endpgm` in both controls."* - kept the VOP1 `decode_s_reg` fix, re-verified against LLVM here; - the invalid VOP3A record consumes exactly 8 bytes and is a distinct unsupported-encoding record; - both controls keep a following `s_endpgm`, and the VOP3A control shows it at offset 8; - no lowering change. ## LLVM round trip LLVM 21.1.8 here (`-triple=amdgcn--amdpal -mcpu=gfx1013`); R0Y00 confirmed the same with LLVM 15. ```text $ echo 'v_readfirstlane_b32 s2, v0' | llvm-mc ... -show-encoding v_readfirstlane_b32 s2, v0 ; encoding: [0x00,0x05,0x04,0x7e] $ disassemble 00 05 04 7e v_readfirstlane_b32 s2, v0 ``` The alignment stream ```text v_readfirstlane_b32 s2, v0 v_mov_b32_e32 v0, v1 s_endpgm ``` assembles to `[0x00,0x05,0x04,0x7e]`, `[0x01,0x03,0x00,0x7e]`, `[0x00,0x00,0x81,0xbf]`, and disassembling those bytes returns the three instructions at +0/+4/+8. The same target assembles no other shape: ```text $ echo 'v_readfirstlane_b32_e64 s2, v0' | llvm-mc ... error: e64 variant of this instruction is not supported $ echo 'v_readfirstlane_b32 v2, v0' | llvm-mc ... error: invalid operand for instruction $ echo 'v_readfirstlane_b32 s2, s0' | llvm-mc ... error: invalid operand for instruction $ disassemble 02 00 82 d5 00 01 00 00 warning: invalid instruction encoding ``` ## Tests ```text python -B tests/rdna2_tools_check.py Ran 59 tests in 1.691s OK (skipped=1) ``` The skip is the existing `test_llvm_comparison`, which needs `LLVM_LIB`; its fixture list now contains `v_readfirstlane_b32 s2, v0`, so the LLVM 15 `gfx1013` CI job exercises the same round trip. ```text ctest --test-dir out/build/dev --no-tests=error -R 'rdna2_tools|pixel_aot_' -V 100% tests passed out of 35 Total Test time (real) = 281.25 sec ``` `test_vop1_readfirstlane_b32_destination_is_an_sgpr` covers: - VOP1 `0005047e` -> `v_readfirstlane_b32 s2, v0` (SGPR destination, VGPR source preserved); - VOP1 control `0005047e 000081bf` -> records at +0 and +4, following `s_endpgm` visible; - alignment control `0005047e 0103007e 000081bf` -> +0/+4/+8; - negative control `0103047e` -> `v_mov_b32_e32 v2, v1`; - VOP3A control `020082d500010000 000081bf` -> distinct unsupported-encoding record at +0, length 8, `is_opcode_recognized` and `is_instruction_supported` both false, and `s_endpgm` at +8. Two mutants were checked: reverting the whole change fails on the VOP1 assertion, and dropping only the VOP3A hunk fails on the unsupported-record assertion. A passing fixture supports the behavior under test; full-game startup remains unverified. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:44:44 +00:00
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!772
No description provided.