shader: disasm_rdna2 formats v_readfirstlane_b32 destination as VGPR instead of SGPR #740

Closed
opened 2026-11-23 00:26:14 +00:00 by Ammmae0x · 4 comments
Ammmae0x commented 2026-11-23 00:26:14 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T00:26:14Z.


Commit or build

fd2486f (upstream/main)

Reproduction

Disassemble both the 32-bit VOP1 (0005047e) and 64-bit VOP3A (020082d500010000) encodings of v_readfirstlane_b32:

python -B -c "import sys; sys.path.insert(0, 'tools'); from disasm_rdna2 import disasm_rdna2; print('vop1:', disasm_rdna2(bytes.fromhex('0005047e'))[0]['assembly']); print('vop3a:', disasm_rdna2(bytes.fromhex('020082d500010000'))[0]['assembly'])"

Expected behavior

As documented in VOP1_OPS[0x02] (tools/disasm_rdna2.py:249: "Read first active lane into SGPR") and required by the RDNA 2 ISA and downstream lifters (tools/mesh_entry_aot.py:225-229), v_readfirstlane_b32 writes an SGPR (sdst), not a VGPR. Both encodings should format the destination via decode_s_reg(vdst):

vop1: v_readfirstlane_b32 s2, v0
vop3a: v_readfirstlane_b32 s2, v0

Acceptance criteria:

  • Update both VOP1 (tools/disasm_rdna2.py:1237-1241) and VOP3A (tools/disasm_rdna2.py:1706-1707) destination formatting to use decode_s_reg(vdst) when op_name is v_readfirstlane_b32 (or v_readfirstlane_b32_e64 / v_readfirstlane_b32).
  • Add regression tests for both VOP1 and VOP3A v_readfirstlane_b32 encodings in tests/rdna2_tools_check.py.

Observed behavior

decode_instruction unconditionally formats dst_str as f"v{vdst}" in both VOP1 (tools/disasm_rdna2.py:1237) and VOP3A (tools/disasm_rdna2.py:1706), producing a VGPR destination:

vop1: v_readfirstlane_b32 v2, v0
vop3a: v_readfirstlane_b32 v2, v0

Environment

Windows 10 Pro 24H2 (build 26100.7623), Python 3.11.15.

Checklist

  • I reproduced this on a source-built input.
  • I did not include game files, dumps, distribution links or credentials.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6549773579 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/746). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T00:26:14Z. --- ### Commit or build `fd2486f` (`upstream/main`) ### Reproduction Disassemble both the 32-bit VOP1 (`0005047e`) and 64-bit VOP3A (`020082d500010000`) encodings of `v_readfirstlane_b32`: ```powershell python -B -c "import sys; sys.path.insert(0, 'tools'); from disasm_rdna2 import disasm_rdna2; print('vop1:', disasm_rdna2(bytes.fromhex('0005047e'))[0]['assembly']); print('vop3a:', disasm_rdna2(bytes.fromhex('020082d500010000'))[0]['assembly'])" ``` ### Expected behavior As documented in `VOP1_OPS[0x02]` (`tools/disasm_rdna2.py:249`: `"Read first active lane into SGPR"`) and required by the RDNA 2 ISA and downstream lifters (`tools/mesh_entry_aot.py:225-229`), `v_readfirstlane_b32` writes an SGPR (`sdst`), not a VGPR. Both encodings should format the destination via `decode_s_reg(vdst)`: ```text vop1: v_readfirstlane_b32 s2, v0 vop3a: v_readfirstlane_b32 s2, v0 ``` **Acceptance criteria:** - Update both VOP1 (`tools/disasm_rdna2.py:1237-1241`) and VOP3A (`tools/disasm_rdna2.py:1706-1707`) destination formatting to use `decode_s_reg(vdst)` when `op_name` is `v_readfirstlane_b32` (or `v_readfirstlane_b32_e64` / `v_readfirstlane_b32`). - Add regression tests for both VOP1 and VOP3A `v_readfirstlane_b32` encodings in `tests/rdna2_tools_check.py`. ### Observed behavior `decode_instruction` unconditionally formats `dst_str` as `f"v{vdst}"` in both VOP1 (`tools/disasm_rdna2.py:1237`) and VOP3A (`tools/disasm_rdna2.py:1706`), producing a VGPR destination: ```text vop1: v_readfirstlane_b32 v2, v0 vop3a: v_readfirstlane_b32 v2, v0 ``` ### Environment Windows 10 Pro 24H2 (build 26100.7623), Python 3.11.15. ### Checklist - [x] I reproduced this on a source-built input. - [x] I did not include game files, dumps, distribution links or credentials. AI-assisted.
R0Y00 commented 2026-11-24 06:48:54 +00:00 (Migrated from github.com)
Author
Contributor

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


Please verify the destination and opcode with the LLVM 15 gfx1013 round trip. The plain register form should print an SGPR destination and preserve the source and stream alignment. Only change the VOP3A form if that target actually assembles the same operation there. A following instruction makes a useful alignment control.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7088911563 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7088911563). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T01:08:51Z. --- Please verify the destination and opcode with the LLVM 15 `gfx1013` round trip. The plain register form should print an SGPR destination and preserve the source and stream alignment. Only change the VOP3A form if that target actually assembles the same operation there. A following instruction makes a useful alignment control.
FZNull commented 2026-11-24 06:48:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T01:55:33Z.


Ran the gfx1013 round trip the issue asks for. Note the assembler here is LLVM 21.1.8 built with the AMDGPU target (-triple=amdgcn--amdpal -mcpu=gfx1013), not the LLVM 15 in CI, so treat it as strong evidence that still wants a CI-side confirmation.

VOP1 form, as the issue expects:

$ echo 'v_readfirstlane_b32 s2, v0' | llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding
	v_readfirstlane_b32 s2, v0              ; encoding: [0x00,0x05,0x04,0x7e]

The encoding is the same two words the issue disassembles (0005047e), and the assembler prints an SGPR destination. So tools/disasm_rdna2.py should format the VOP1 destination through decode_s_reg(vdst).

VOP3A form: this target does not assemble it.

$ echo 'v_readfirstlane_b32_e64 s2, v0' | llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding
<stdin>:1:1: error: e64 variant of this instruction is not supported

Per the guidance ("only change the VOP3A form if that target actually assembles the same operation there"), the VOP3A destination formatting should stay as it is. Two further probes agree that the operation only exists in one shape on this target:

$ echo 'v_readfirstlane_b32 v2, v0' | llvm-mc ... -show-encoding
<stdin>:1:21: error: invalid operand for instruction
$ echo 'v_readfirstlane_b32 s2, s0' | llvm-mc ... -show-encoding
<stdin>:1:25: error: invalid operand for instruction

So on gfx1013 the instruction is VOP1 only, with an SGPR destination and a VGPR source. That also suggests the VOP3A word 020082d500010000 the issue disassembles as this op is probably not this instruction; it would be worth decoding it against the ISA before the VOP1-formatting change is made on its strength.

I have not changed any code. If it helps, I can send the VOP1-only formatting change plus a VOP3A-unchanged regression test.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7089522349 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7089522349). Originally posted by [FZNull](https://github.com/FZNull) on 2026-11-23T01:55:33Z. --- Ran the `gfx1013` round trip the issue asks for. Note the assembler here is **LLVM 21.1.8** built with the AMDGPU target (`-triple=amdgcn--amdpal -mcpu=gfx1013`), not the LLVM 15 in CI, so treat it as strong evidence that still wants a CI-side confirmation. **VOP1 form, as the issue expects:** ```text $ echo 'v_readfirstlane_b32 s2, v0' | llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding v_readfirstlane_b32 s2, v0 ; encoding: [0x00,0x05,0x04,0x7e] ``` The encoding is the same two words the issue disassembles (`0005047e`), and the assembler prints an **SGPR destination**. So `tools/disasm_rdna2.py` should format the VOP1 destination through `decode_s_reg(vdst)`. **VOP3A form:** this target does not assemble it. ```text $ echo 'v_readfirstlane_b32_e64 s2, v0' | llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding <stdin>:1:1: error: e64 variant of this instruction is not supported ``` Per the guidance ("only change the VOP3A form if that target actually assembles the same operation there"), the VOP3A destination formatting should stay as it is. Two further probes agree that the operation only exists in one shape on this target: ```text $ echo 'v_readfirstlane_b32 v2, v0' | llvm-mc ... -show-encoding <stdin>:1:21: error: invalid operand for instruction $ echo 'v_readfirstlane_b32 s2, s0' | llvm-mc ... -show-encoding <stdin>:1:25: error: invalid operand for instruction ``` So on `gfx1013` the instruction is VOP1 only, with an SGPR destination and a VGPR source. That also suggests the VOP3A word `020082d500010000` the issue disassembles as this op is probably not this instruction; it would be worth decoding it against the ISA before the VOP1-formatting change is made on its strength. I have not changed any code. If it helps, I can send the VOP1-only formatting change plus a VOP3A-unchanged regression test.
Ammmae0x commented 2026-11-24 06:48:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-23T01:57:09Z.


Open PR #765 already updates tools/disasm_rdna2.py to format v_readfirstlane_b32 destinations as SGPRs in both VOP1 and VOP3 paths, so holding off on opening a duplicate PR while #765 is in review (noting the maintainer guidance to verify VOP3A encoding and stream alignment via LLVM 15 gfx1013 round trip).

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7089542508 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7089542508). Originally posted by [Ammmae0x](https://github.com/Ammmae0x) on 2026-11-23T01:57:09Z. --- Open PR #765 already updates `tools/disasm_rdna2.py` to format `v_readfirstlane_b32` destinations as SGPRs in both VOP1 and VOP3 paths, so holding off on opening a duplicate PR while #765 is in review (noting the maintainer guidance to verify VOP3A encoding and stream alignment via LLVM 15 `gfx1013` round trip). AI-assisted.
R0Y00 commented 2026-11-24 06:48:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T02:07:03Z.


Independent LLVM 15 gfx1013 check: v_readfirstlane_b32 s2, v0 assembles to 0005047e and disassembles back with an SGPR destination, followed by s_endpgm. The explicit _e64 spelling is rejected by the assembler, and 020082d500010000 produces invalid-encoding warnings in the disassembler. The following s_endpgm still decodes.

Please fix the VOP1 SGPR destination and include the following instruction in the regression. For the proposed VOP3A bytes, use a distinct unsupported-encoding diagnostic and preserve the eight-byte record boundary. The check should keep the next instruction visible at offset 8.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7089676568 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7089676568). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T02:07:03Z. --- Independent LLVM 15 gfx1013 check: v_readfirstlane_b32 s2, v0 assembles to 0005047e and disassembles back with an SGPR destination, followed by s_endpgm. The explicit _e64 spelling is rejected by the assembler, and 020082d500010000 produces invalid-encoding warnings in the disassembler. The following s_endpgm still decodes. Please fix the VOP1 SGPR destination and include the following instruction in the regression. For the proposed VOP3A bytes, use a distinct unsupported-encoding diagnostic and preserve the eight-byte record boundary. The check should keep the next instruction visible at offset 8.
Sign in to join this conversation.
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#740
No description provided.