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

Manually merged
github merged 1 commit from gh-pr/778/head into gh-pr/778/base 2026-11-26 22:17:50 +00:00
Owner

@⁠FZNull on GitHub · 2026-11-23 02:37 UTC · original
FZNull:fix/readfirstlane-sgpr → main · +93 −0 · 2 files · 1 commits · merged 2026-11-23 03:10 UTC

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.

**@⁠FZNull** on GitHub · 2026-11-23 02:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/778) `FZNull:fix/readfirstlane-sgpr` → `main` · +93 −0 · 2 files · 1 commits · merged 2026-11-23 03:10 UTC ## 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.
decode_instruction formatted every VOP1 destination as a VGPR, so the
issue #746 bytes decoded as "v_readfirstlane_b32 v2, v0".  In VOP1 the
vdst field of v_readfirstlane_b32 is an SGPR number, and this target
assembles the operation only in that form.  LLVM 15 (maintainer's CI
confirmation in #746) and LLVM 21.1.8, both with
-triple=amdgcn--amdpal -mcpu=gfx1013, assemble the plain form to the
issue bytes and disassemble them back with an SGPR destination:

  v_readfirstlane_b32 s2, v0   ; encoding: [0x00,0x05,0x04,0x7e]
  -disassemble 00 05 04 7e     ; v_readfirstlane_b32 s2, v0

The same target rejects the other shapes:

  v_readfirstlane_b32_e64 s2, v0 -> e64 variant of this instruction is not supported
  v_readfirstlane_b32 v2, v0     -> invalid operand for instruction
  v_readfirstlane_b32 s2, s0     -> invalid operand for instruction

and llvm-mc reports the issue's VOP3A word 020082d500010000 as an invalid
instruction encoding.  The VOP3A path now returns a distinct
"v_readfirstlane_b32_unsupported" record with an "<unsupported VOP3A
encoding>" diagnostic.  It consumes exactly eight bytes and is neither
recognized nor supported by the scanner, so no instruction reaches a
lowerer, and the following s_endpgm still decodes at +8.  Both the VOP1
and the VOP3A controls keep a following s_endpgm.

python -B tests/rdna2_tools_check.py
  Ran 59 tests, OK (skipped=1)
ctest --no-tests=error -R 'rdna2_tools|pixel_aot_' -V
  100% tests passed out of 35

Fixes #746
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:17:48 +00:00
github manually merged commit 5d3a859a12 into gh-pr/778/base 2026-11-26 22:17:50 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.