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

Manually merged
github merged 1 commit from gh-pr/956/head into gh-pr/956/base 2026-11-26 22:31:09 +00:00
Owner

@⁠Batushn on GitHub · 2026-11-23 18:37 UTC · original
Batushn:disasm/hwreg-symbolic-spelling → main · +145 −1 · 2 files · 1 commits · merged 2026-11-23 19:20 UTC

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

**@⁠Batushn** on GitHub · 2026-11-23 18:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/956) `Batushn:disasm/hwreg-symbolic-spelling` → `main` · +145 −1 · 2 files · 1 commits · merged 2026-11-23 19:20 UTC ## 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:31:06 +00:00
github manually merged commit 788fc9ebf0 into gh-pr/956/base 2026-11-26 22:31:09 +00:00
Author
Owner

@⁠Batushn on GitHub · 2026-11-23 19:07 UTC · original

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.

**@⁠Batushn** on GitHub · 2026-11-23 19:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/956#issuecomment-7111135307) 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.