tooling: recognize SOPK hwreg opcodes in scanner and add boundary tests #949

Merged
Batushn merged 1 commit from upstream-pr/956 into main 2026-11-23 19:20:48 +00:00
Batushn commented 2026-11-23 18:37:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Batushn on 2026-11-23T18:37:49Z.


Summary

Rebased onto main after #951 as a small follow-up to #938, keeping only the remaining useful differences requested by @R0Y00:

  • Scanner ISA opcode recognition (tools/scan_unsupported_shaders.py): add s_getreg_b32, s_setreg_b32, and s_setreg_imm32_b32 to KNOWN_RDNA2_BASE_OPCODES (SOPK). Without this, even an otherwise lowerable pixel shader using accepted s_setreg_imm32_b32 forms was still classified as unsupported_opcodes (opcodes_recognized=False).
  • Separate recognition vs. translation-support tests (tests/rdna2_tools_check.py):
    • Tightened test_binary_scan_reports_decoded_hwreg_writes_as_supported to assert opcodes_recognized=True and unsupported_opcodes={} on both the accepted and directed-rounding binary controls.
    • Added test_binary_scan_hwreg_recognition_stays_separate_from_translation_support proving:
      1. A full pixel shader using accepted s_setreg_imm32_b32 forms (HW_REG_FLAT_SCR_LO/HI, HW_REG_MODE 0/3) now reaches compatibility_category == "accepted" and is_fully_supported == True.
      2. s_getreg_b32 and s_setreg_b32 are recognized RDNA 2 opcodes (opcodes_recognized == True, unsupported_opcodes == {}) yet remain rejected by the translator (is_instruction_supported == False, translator_accepted == False, compatibility_category == "opcode_recognized_translator_rejected"), tested both in a binary scan and embedded in an otherwise accepted pixel shader.
      3. Negative control: an unknown opcode still reports opcodes_recognized == False and compatibility_category == "unsupported_opcodes".
  • SOPK truncated second-dword & s_endpgm boundary controls (tests/rdna2_tools_check.py):
    • Added test_hwreg_truncated_literal_and_endpgm_boundaries covering 4-byte and 6-byte truncated s_setreg_imm32_b32 streams, mid-stream truncation after s_getreg_b32, and a boundary control where s_setreg_imm32_b32's 32-bit literal equals 0xbf810000 (s_endpgm) so disassembly consumes it as a literal, decodes the following s_getreg_b32, and stops cleanly at the real s_endpgm before trailing bytes.

Refs #938

Verification

  • python -B tests/rdna2_tools_check.py on Windows 11 (Python 3.12.10, synthetic inputs, no game files): Ran 80 tests ... OK (skipped=2) (the 2 skipped tests require llvm-mc/llvm-objcopy and will run in Ubuntu CI).

AI-assisted: yes

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6566258079 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/956). Originally posted by [Batushn](https://github.com/Batushn) on 2026-11-23T18:37:49Z. --- ## Summary Rebased onto `main` after #951 as a small follow-up to #938, keeping only the remaining useful differences requested by @R0Y00: - **Scanner ISA opcode recognition (`tools/scan_unsupported_shaders.py`):** add `s_getreg_b32`, `s_setreg_b32`, and `s_setreg_imm32_b32` to `KNOWN_RDNA2_BASE_OPCODES` (SOPK). Without this, even an otherwise lowerable pixel shader using accepted `s_setreg_imm32_b32` forms was still classified as `unsupported_opcodes` (`opcodes_recognized=False`). - **Separate recognition vs. translation-support tests (`tests/rdna2_tools_check.py`):** - Tightened `test_binary_scan_reports_decoded_hwreg_writes_as_supported` to assert `opcodes_recognized=True` and `unsupported_opcodes={}` on both the accepted and directed-rounding binary controls. - Added `test_binary_scan_hwreg_recognition_stays_separate_from_translation_support` proving: 1. A full pixel shader using accepted `s_setreg_imm32_b32` forms (`HW_REG_FLAT_SCR_LO`/`HI`, `HW_REG_MODE` `0`/`3`) now reaches `compatibility_category == "accepted"` and `is_fully_supported == True`. 2. `s_getreg_b32` and `s_setreg_b32` are recognized RDNA 2 opcodes (`opcodes_recognized == True`, `unsupported_opcodes == {}`) yet remain rejected by the translator (`is_instruction_supported == False`, `translator_accepted == False`, `compatibility_category == "opcode_recognized_translator_rejected"`), tested both in a binary scan and embedded in an otherwise accepted pixel shader. 3. Negative control: an unknown opcode still reports `opcodes_recognized == False` and `compatibility_category == "unsupported_opcodes"`. - **SOPK truncated second-dword & `s_endpgm` boundary controls (`tests/rdna2_tools_check.py`):** - Added `test_hwreg_truncated_literal_and_endpgm_boundaries` covering 4-byte and 6-byte truncated `s_setreg_imm32_b32` streams, mid-stream truncation after `s_getreg_b32`, and a boundary control where `s_setreg_imm32_b32`'s 32-bit literal equals `0xbf810000` (`s_endpgm`) so disassembly consumes it as a literal, decodes the following `s_getreg_b32`, and stops cleanly at the real `s_endpgm` before trailing bytes. Refs #938 ## Verification - `python -B tests/rdna2_tools_check.py` on Windows 11 (Python 3.12.10, synthetic inputs, no game files): `Ran 80 tests ... OK (skipped=2)` (the 2 skipped tests require `llvm-mc`/`llvm-objcopy` and will run in Ubuntu CI). AI-assisted: yes
upstream-sync closed this pull request 2026-11-24 06:45:35 +00:00
Batushn commented 2026-11-24 06:49:31 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Batushn on 2026-11-23T19:07:51Z.


Thanks @R0Y00! Rebased #956 onto main (788fc9e) after #951 as a focused follow-up retaining only:

  1. Adding s_getreg_b32, s_setreg_b32, and s_setreg_imm32_b32 to KNOWN_RDNA2_BASE_OPCODES in tools/scan_unsupported_shaders.py, with tests proving recognition stays separate from translation support for s_getreg_b32 / s_setreg_b32 while an accepted s_setreg_imm32_b32 pixel shader reaches accepted.
  2. Truncated second-dword (4-byte, 6-byte, mid-stream) and s_endpgm-as-literal (0xbf810000) boundary controls in tests/rdna2_tools_check.py.

Local check: python -B tests/rdna2_tools_check.py -> 80 run (78 passed, 2 LLVM-only skipped); CI is now re-running on the rebased head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7111135307 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/956#issuecomment-7111135307). Originally posted by [Batushn](https://github.com/Batushn) on 2026-11-23T19:07:51Z. --- Thanks @R0Y00! Rebased #956 onto `main` (`788fc9e`) after #951 as a focused follow-up retaining only: 1. Adding `s_getreg_b32`, `s_setreg_b32`, and `s_setreg_imm32_b32` to `KNOWN_RDNA2_BASE_OPCODES` in `tools/scan_unsupported_shaders.py`, with tests proving recognition stays separate from translation support for `s_getreg_b32` / `s_setreg_b32` while an accepted `s_setreg_imm32_b32` pixel shader reaches `accepted`. 2. Truncated second-dword (4-byte, 6-byte, mid-stream) and `s_endpgm`-as-literal (`0xbf810000`) boundary controls in `tests/rdna2_tools_check.py`. Local check: `python -B tests/rdna2_tools_check.py` -> 80 run (78 passed, 2 LLVM-only skipped); CI is now re-running on the rebased head.
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!949
No description provided.