tooling: scan records after s_endpgm #1048

Merged
romn4rch merged 2 commits from upstream-pr/1055 into main 2026-11-24 00:08:24 +00:00
romn4rch commented 2026-11-23 23:37:07 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by romn4rch on 2026-11-23T23:37:07Z.


Change

disasm_rdna2 stopped at the first s_endpgm even when the caller supplied more code, so the shader scan omitted later records. Continue decoding the supplied span, name SOPP opcode 0x1f as s_code_end, and recognize it in the scanner without marking it translator-supported. The LLVM 15 fixture also confirms the all-zero word must remain a four-byte unknown record. Lowering and caller-owned bounds remain unchanged.

Fixes #938

Verification

  • python -B tests/rdna2_tools_check.py - passed: 97 tests, 8 skipped. The LLVM source-built boundary test was skipped locally because LLVM_LIB, llvm-mc, and llvm-objcopy are unavailable.
  • git diff --check - passed.
  • ctest --preset dev --no-tests=error -R '^rdna2_tools_check$' - not run; the CTest build tree is not configured (out\build\dev\CTestTestfile.cmake is absent).

Evidence and follow-up

The synthetic gfx1013 regressions cover a one-exit control, a branch past the first exit, s_code_end, and a trailing zero word. The binary scan test verifies that post-exit instructions are counted while lowering still rejects them after program end. The LLVM 15 source-built comparison runs when its tools are available. No game files or external samples are used. Format-aware callers remain responsible for trimming verified padding; no README or build documentation change is needed because no public build requirement changed.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6571118473 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1055). Originally posted by [romn4rch](https://github.com/romn4rch) on 2026-11-23T23:37:07Z. --- ## Change `disasm_rdna2` stopped at the first `s_endpgm` even when the caller supplied more code, so the shader scan omitted later records. Continue decoding the supplied span, name SOPP opcode `0x1f` as `s_code_end`, and recognize it in the scanner without marking it translator-supported. The LLVM 15 fixture also confirms the all-zero word must remain a four-byte unknown record. Lowering and caller-owned bounds remain unchanged. Fixes #938 ## Verification - `python -B tests/rdna2_tools_check.py` - passed: 97 tests, 8 skipped. The LLVM source-built boundary test was skipped locally because `LLVM_LIB`, `llvm-mc`, and `llvm-objcopy` are unavailable. - `git diff --check` - passed. - `ctest --preset dev --no-tests=error -R '^rdna2_tools_check$'` - not run; the CTest build tree is not configured (`out\build\dev\CTestTestfile.cmake` is absent). ## Evidence and follow-up The synthetic gfx1013 regressions cover a one-exit control, a branch past the first exit, `s_code_end`, and a trailing zero word. The binary scan test verifies that post-exit instructions are counted while lowering still rejects them after program end. The LLVM 15 source-built comparison runs when its tools are available. No game files or external samples are used. Format-aware callers remain responsible for trimming verified padding; no README or build documentation change is needed because no public build requirement changed. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted.
upstream-sync closed this pull request 2026-11-24 06:46:03 +00:00
thepatrickworld commented 2026-11-24 06:49:53 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-23T23:47:49Z.


The Assemble and translate gfx1013 fixtures job fails on one test. The immediate cause is in the SOPP table: SOPP 0x14 is not S_CODE_END, it is S_INCPERFLEVEL. S_CODE_END is 0x1f, and it is missing from the table.

The ISA. In the RDNA 2 reference (§12.5, https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf) the Opcode # column is decimal: 14 is S_SLEEP, which is 0x0e; 20 is S_INCPERFLEVEL, which is 0x14; 31 is S_CODE_END, which is 0x1f. LLVM 15.0.7, the encoder this job runs, has the same numbers for the GFX10 generation gfx1013 belongs to (llvm/lib/Target/AMDGPU/[email protected]: S_SLEEP 0x00e, S_INCPERFLEVEL 0x014, S_CODE_END 0x01f).

The CI log confirms it for gfx1013: llvm-mc -mcpu=gfx1013 assembled s_code_end to the word your decoder reports as s_sopp_1f, i.e. SOPP 0x1f.

Your decoder, run locally on the four words (I did not run llvm-mc myself, so the CI log is my only LLVM 15 evidence):

0xbf9f0000  (SOPP 0x1f, real S_CODE_END)       -> (4, 's_sopp_1f', 's_sopp_1f 0x0', 'Unknown SOPP')
0xbf940000  (SOPP 0x14, real S_INCPERFLEVEL)   -> (4, 's_code_end', 's_code_end', 'Code end marker')
0xbf8e0000  (SOPP 0x0e, real S_SLEEP)          -> s_sopp_0e, unknown
0x00000000                                     -> (4, 'v_vop2_00', 'v_vop2_00 v0, s0, v0', 'Unknown VOP2')

So the entry at tools/disasm_rdna2.py:137 names the wrong opcode, 0x1f is missing, and 0x0e is a separate gap in the same table.

Consequences beyond the red test:

  • A real S_INCPERFLEVEL (0x14) decodes as s_code_end and takes the no-operand branch at tools/disasm_rdna2.py:1685, so its SIMM16 operand is dropped and the scan counts a perf-level instruction as a code-end marker.
  • A real S_CODE_END still comes back as an unrecognised SOPP, so the scan never sees the marker this PR is about.
  • With 0x0e absent, a real S_SLEEP decodes to s_sopp_0e, which cannot match the s_sleep pattern in SUPPORTED_INSTRUCTIONS_REGEX (tools/scan_unsupported_shaders.py:89). That predates this PR, but it is the same table.

Offset 20 differs as well, and the log shows it: your decoder returns (20, 4, 'v_vop2_00', 'v_vop2_00 v0, s0, v0') where the expectation says word_0x00000000 / .long 0x00000000. 0x00000000 matches the VOP2 test (bit 31 == 0) before the .long fallback. But VOP2 opcode 0x000 is not a defined gfx10 instruction — LLVM 15 puts V_CNDMASK_B32 at 0x001 — so the decoder is inventing an instruction for an undefined encoding, and the .long expectation matches what LLVM 15 does with that word: it fails to decode it. Since I have not run LLVM 15 here, whether assertRaisesRegex(ValueError, "at byte 20$") passes on that job is unverified: check it there rather than change the expectation.

Two things I would raise on the change itself rather than on the red:

  • The behaviour change is not only the name. Removing the stop at the first s_endpgm means every trailing padding word in a shader is now decoded — that is what surfaces offset 20 here. It is worth saying in the PR body, because the scan output for existing files changes.
  • assertTrue(is_opcode_recognized("s_code_end")) is circular: it compares a name against KNOWN_RDNA2_BASE_OPCODES (tools/scan_unsupported_shaders.py:363-375) and never touches the decode table. Only the decode path proves the marker is recognised.

Suggested table, if it helps:

0x1f: ("s_code_end", "Code end marker"),
0x0e: ("s_sleep", "Sleep for 64(SIMM16[6:0]-1)..64SIMM16[6:0] cycles"),
0x14: ("s_incperflevel", "Increment performance counter selected by SIMM16[3:0]"),

Note that test_s_code_end_is_recognized_but_not_translated in this PR decodes 000094bf and expects s_code_end; once 0x14 is renamed it has to use 00009fbf. And the else branch prints these immediates as 0x0, where LLVM prints 0; several tests compare against LLVM's text, so that format will need to match.

AI-assisted; I read the failing job log and ran your decoder locally on the words above. I did not run llvm-mc or libLLVM 15, so the LLVM 15 behaviour at offset 20 is unverified.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7117373347 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1055#issuecomment-7117373347). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-23T23:47:49Z. --- The `Assemble and translate gfx1013 fixtures` job fails on one test. The immediate cause is in the SOPP table: SOPP `0x14` is not `S_CODE_END`, it is `S_INCPERFLEVEL`. `S_CODE_END` is `0x1f`, and it is missing from the table. **The ISA.** In the RDNA 2 reference (§12.5, https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf) the `Opcode #` column is **decimal**: 14 is `S_SLEEP`, which is `0x0e`; 20 is `S_INCPERFLEVEL`, which is `0x14`; 31 is `S_CODE_END`, which is `0x1f`. LLVM 15.0.7, the encoder this job runs, has the same numbers for the GFX10 generation gfx1013 belongs to (`llvm/lib/Target/AMDGPU/[email protected]`: `S_SLEEP` `0x00e`, `S_INCPERFLEVEL` `0x014`, `S_CODE_END` `0x01f`). **The CI log** confirms it for gfx1013: `llvm-mc -mcpu=gfx1013` assembled `s_code_end` to the word your decoder reports as `s_sopp_1f`, i.e. SOPP `0x1f`. **Your decoder**, run locally on the four words (I did not run `llvm-mc` myself, so the CI log is my only LLVM 15 evidence): ``` 0xbf9f0000 (SOPP 0x1f, real S_CODE_END) -> (4, 's_sopp_1f', 's_sopp_1f 0x0', 'Unknown SOPP') 0xbf940000 (SOPP 0x14, real S_INCPERFLEVEL) -> (4, 's_code_end', 's_code_end', 'Code end marker') 0xbf8e0000 (SOPP 0x0e, real S_SLEEP) -> s_sopp_0e, unknown 0x00000000 -> (4, 'v_vop2_00', 'v_vop2_00 v0, s0, v0', 'Unknown VOP2') ``` So the entry at `tools/disasm_rdna2.py:137` names the wrong opcode, `0x1f` is missing, and `0x0e` is a separate gap in the same table. Consequences beyond the red test: - A real `S_INCPERFLEVEL` (`0x14`) decodes as `s_code_end` and takes the no-operand branch at `tools/disasm_rdna2.py:1685`, so its `SIMM16` operand is dropped and the scan counts a perf-level instruction as a code-end marker. - A real `S_CODE_END` still comes back as an unrecognised SOPP, so the scan never sees the marker this PR is about. - With `0x0e` absent, a real `S_SLEEP` decodes to `s_sopp_0e`, which cannot match the `s_sleep` pattern in `SUPPORTED_INSTRUCTIONS_REGEX` (`tools/scan_unsupported_shaders.py:89`). That predates this PR, but it is the same table. **Offset 20** differs as well, and the log shows it: your decoder returns `(20, 4, 'v_vop2_00', 'v_vop2_00 v0, s0, v0')` where the expectation says `word_0x00000000` / `.long 0x00000000`. `0x00000000` matches the VOP2 test (bit 31 == 0) before the `.long` fallback. But VOP2 opcode `0x000` is not a defined gfx10 instruction — LLVM 15 puts `V_CNDMASK_B32` at `0x001` — so the decoder is inventing an instruction for an undefined encoding, and the `.long` expectation matches what LLVM 15 does with that word: it fails to decode it. Since I have not run LLVM 15 here, whether `assertRaisesRegex(ValueError, "at byte 20$")` passes on that job is unverified: check it there rather than change the expectation. Two things I would raise on the change itself rather than on the red: - The behaviour change is not only the name. Removing the stop at the first `s_endpgm` means every trailing padding word in a shader is now decoded — that is what surfaces offset 20 here. It is worth saying in the PR body, because the scan output for existing files changes. - `assertTrue(is_opcode_recognized("s_code_end"))` is circular: it compares a **name** against `KNOWN_RDNA2_BASE_OPCODES` (`tools/scan_unsupported_shaders.py:363-375`) and never touches the decode table. Only the decode path proves the marker is recognised. Suggested table, if it helps: ``` 0x1f: ("s_code_end", "Code end marker"), 0x0e: ("s_sleep", "Sleep for 64(SIMM16[6:0]-1)..64SIMM16[6:0] cycles"), 0x14: ("s_incperflevel", "Increment performance counter selected by SIMM16[3:0]"), ``` Note that `test_s_code_end_is_recognized_but_not_translated` in this PR decodes `000094bf` and expects `s_code_end`; once `0x14` is renamed it has to use `00009fbf`. And the `else` branch prints these immediates as `0x0`, where LLVM prints `0`; several tests compare against LLVM's text, so that format will need to match. _AI-assisted; I read the failing job log and ran your decoder locally on the words above. I did not run `llvm-mc` or libLLVM 15, so the LLVM 15 behaviour at offset 20 is unverified._
thepatrickworld commented 2026-11-24 06:49:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-24T00:00:45Z.


Checked at edb4eb20, and the job that was red is now green.

Assemble and translate gfx1013 fixtures: success. It runs LLVM_LIB=libLLVM-15.so.1 LLVM_MC=llvm-mc-15 LLVM_OBJCOPY=llvm-objcopy-15 python3 -B tests/rdna2_tools_check.py — 97 tests, no failure — so test_source_built_records_after_s_endpgm passed against real LLVM output this time. That is the assertion that carried the diagnosis, and it now holds with 0x1f in the table.

Locally on your head, the four words behave as follows:

0xbf9f0000  -> (4, 's_code_end', 's_code_end', 'Code end marker')
0xbf940000  -> (4, 's_sopp_14', 's_sopp_14 0x0', 'Unknown SOPP')
0xbf8e0000  -> (4, 's_sopp_0e', 's_sopp_0e 0x0', 'Unknown SOPP')
0x00000000  -> (4, 'word_0x00000000', '.long 0x00000000', 'Unrecognized RDNA 2 instruction encoding')

So the marker and the zero word are both where you want them. 0x0e and 0x14 still fall through to the unknown-SOPP path; that is not a blocker for this PR, and the s_sleep regex point stays open only if you want it folded in here.

The two Windows jobs were still in_progress when I looked, so this is about the LLVM job and the Linux Python job (both green), not the whole gate.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7117605974 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1055#issuecomment-7117605974). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-24T00:00:45Z. --- Checked at `edb4eb20`, and the job that was red is now green. **`Assemble and translate gfx1013 fixtures`: success.** It runs `LLVM_LIB=libLLVM-15.so.1 LLVM_MC=llvm-mc-15 LLVM_OBJCOPY=llvm-objcopy-15 python3 -B tests/rdna2_tools_check.py` — 97 tests, no failure — so `test_source_built_records_after_s_endpgm` passed against real LLVM output this time. That is the assertion that carried the diagnosis, and it now holds with `0x1f` in the table. Locally on your head, the four words behave as follows: ``` 0xbf9f0000 -> (4, 's_code_end', 's_code_end', 'Code end marker') 0xbf940000 -> (4, 's_sopp_14', 's_sopp_14 0x0', 'Unknown SOPP') 0xbf8e0000 -> (4, 's_sopp_0e', 's_sopp_0e 0x0', 'Unknown SOPP') 0x00000000 -> (4, 'word_0x00000000', '.long 0x00000000', 'Unrecognized RDNA 2 instruction encoding') ``` So the marker and the zero word are both where you want them. `0x0e` and `0x14` still fall through to the unknown-SOPP path; that is not a blocker for this PR, and the `s_sleep` regex point stays open only if you want it folded in here. The two Windows jobs were still `in_progress` when I looked, so this is about the LLVM job and the Linux Python job (both green), not the whole gate. _AI-assisted._
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!1048
No description provided.