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

Closed
opened 2026-11-26 22:15:25 +00:00 by github-bot · 4 comments
Owner

@⁠Ammmae0x on GitHub · 2026-11-23 00:26 UTC · original

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.

**@⁠Ammmae0x** on GitHub · 2026-11-23 00:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/746) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:15:25 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 01:08 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-23 01:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7088911563) 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.
Author
Owner

@⁠FZNull on GitHub · 2026-11-23 01:55 UTC · original

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.

**@⁠FZNull** on GitHub · 2026-11-23 01:55 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7089522349) 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.
Author
Owner

@⁠Ammmae0x on GitHub · 2026-11-23 01:57 UTC · original

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.

**@⁠Ammmae0x** on GitHub · 2026-11-23 01:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7089542508) 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-23 02:07 UTC · original

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.

**@⁠R0Y00** on GitHub · 2026-11-23 02:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/issues/746#issuecomment-7089676568) 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.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

Reference
github/R0Y00--Xbox2Windows#746
No description provided.