shader: lower RDNA2 SOPK immediate instructions #514

Closed
agilesh08 wants to merge 1 commit from upstream-pr/520 into main
agilesh08 commented 2026-11-22 08:53:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T08:53:08Z.


Change

Adds static lowering for 6 RDNA2 SOPK immediate instructions in tools/pixel_aot.py:

  • s_cmovk_i32: conditional move of a 16-bit sign-extended immediate to an SGPR destination if scc is true, preserving destination otherwise. Requires a tracked scc.
  • s_cmpk_eq_i32, s_cmpk_lg_i32, s_cmpk_gt_i32: signed 32-bit comparison of an SGPR against a 16-bit sign-extended immediate (==, !=, >); updates scc with the comparison outcome.
  • s_addk_i32: signed 32-bit addition of a 16-bit sign-extended immediate into an SGPR; models signed 2's-complement overflow into scc.
  • s_mulk_i32: signed 32-bit multiplication of an SGPR by a 16-bit sign-extended immediate; preserves scc.

Immediate handling and checks:

  • Verifies 16-bit immediate range (0 <= imm <= 0xffff) and sign-extends (imm if imm < 0x8000 else imm - 0x10000).
  • Extends test coverage in tests/pixel_aot_check.py (check_sopk_immediates), asserts coverage in tests/form_coverage_check.py across gfx1013.tsv and rdna2.tsv, checks disassembly in tests/rdna2_tools_check.py, and documents behavior in docs/experiments.md.

Verification

On Windows x64:

# Pixel translator self-tests and negative control checks
.\.venv\Scripts\python.exe -B tests/pixel_aot_check.py
# Result: 0 (passes cleanly)

# Instruction coverage verification (asserts sopk_forms <= covered on gfx1013 and rdna2)
.\.venv\Scripts\python.exe -B tests/form_coverage_check.py
# Result: form coverage checks passed

# RDNA2 tools disassembly and parser verification
.\.venv\Scripts\python.exe -B tests/rdna2_tools_check.py
# Result: Ran 31 tests in 1.727s, OK (skipped=1)

# Documentation links and bidirectional controls checks
.\.venv\Scripts\python.exe -B tests/docs_links_check.py
# Result: Self-test passed. Checked 10 Markdown files and 114 links.

.\.venv\Scripts\python.exe -B tests/bidi_controls_check.py
# Result: Self-test passed. Checked 478 tracked source, script and build/CI files: no bidirectional controls.

# Whitespace integrity check
git -c core.whitespace=cr-at-eol diff --check
# Result: 0 (clean)

Direct binary translation check with LLVM 15 runs in GitHub Actions Ubuntu CI (tests/pixel_aot_check.py binary).

Evidence and follow-up

  • Unit tests in tests/pixel_aot_check.py (check_sopk_immediates) verify correct translation of immediate instructions with negative and positive 16-bit values (e.g. 0x7fff, 0x8000 sign-extended to -32768, -2).
  • Negative controls verify that:
    • Immediate values outside 16 bits (e.g. 0x10000) are rejected.
    • Destination registers out-of-range (s106) are rejected.
    • s_cmovk_i32 without a tracked prior scc raises ValueError("Conditional move requires a tracked SCC").
    • Operations overlapping an outstanding scalar load are rejected.

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.

Assisted by AI.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6540491704 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/520). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T08:53:08Z. --- ## Change Adds static lowering for 6 RDNA2 SOPK immediate instructions in `tools/pixel_aot.py`: - `s_cmovk_i32`: conditional move of a 16-bit sign-extended immediate to an SGPR destination if `scc` is true, preserving destination otherwise. Requires a tracked `scc`. - `s_cmpk_eq_i32`, `s_cmpk_lg_i32`, `s_cmpk_gt_i32`: signed 32-bit comparison of an SGPR against a 16-bit sign-extended immediate (`==`, `!=`, `>`); updates `scc` with the comparison outcome. - `s_addk_i32`: signed 32-bit addition of a 16-bit sign-extended immediate into an SGPR; models signed 2's-complement overflow into `scc`. - `s_mulk_i32`: signed 32-bit multiplication of an SGPR by a 16-bit sign-extended immediate; preserves `scc`. Immediate handling and checks: - Verifies 16-bit immediate range (`0 <= imm <= 0xffff`) and sign-extends (`imm if imm < 0x8000 else imm - 0x10000`). - Extends test coverage in `tests/pixel_aot_check.py` (`check_sopk_immediates`), asserts coverage in `tests/form_coverage_check.py` across `gfx1013.tsv` and `rdna2.tsv`, checks disassembly in `tests/rdna2_tools_check.py`, and documents behavior in `docs/experiments.md`. ## Verification On Windows x64: ```powershell # Pixel translator self-tests and negative control checks .\.venv\Scripts\python.exe -B tests/pixel_aot_check.py # Result: 0 (passes cleanly) # Instruction coverage verification (asserts sopk_forms <= covered on gfx1013 and rdna2) .\.venv\Scripts\python.exe -B tests/form_coverage_check.py # Result: form coverage checks passed # RDNA2 tools disassembly and parser verification .\.venv\Scripts\python.exe -B tests/rdna2_tools_check.py # Result: Ran 31 tests in 1.727s, OK (skipped=1) # Documentation links and bidirectional controls checks .\.venv\Scripts\python.exe -B tests/docs_links_check.py # Result: Self-test passed. Checked 10 Markdown files and 114 links. .\.venv\Scripts\python.exe -B tests/bidi_controls_check.py # Result: Self-test passed. Checked 478 tracked source, script and build/CI files: no bidirectional controls. # Whitespace integrity check git -c core.whitespace=cr-at-eol diff --check # Result: 0 (clean) ``` Direct binary translation check with LLVM 15 runs in GitHub Actions Ubuntu CI (`tests/pixel_aot_check.py binary`). ## Evidence and follow-up - Unit tests in `tests/pixel_aot_check.py` (`check_sopk_immediates`) verify correct translation of immediate instructions with negative and positive 16-bit values (e.g. `0x7fff`, `0x8000` sign-extended to `-32768`, `-2`). - Negative controls verify that: - Immediate values outside 16 bits (e.g. `0x10000`) are rejected. - Destination registers out-of-range (`s106`) are rejected. - `s_cmovk_i32` without a tracked prior `scc` raises `ValueError("Conditional move requires a tracked SCC")`. - Operations overlapping an outstanding scalar load are rejected. ## 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. Assisted by AI.
upstream-sync closed this pull request 2026-11-24 06:43:29 +00:00
agilesh08 commented 2026-11-24 06:48:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by agilesh08 on 2026-11-22T09:46:28Z.


Closing for now to keep active review focused; will revisit after current PRs land.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7077361545 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/520#issuecomment-7077361545). Originally posted by [agilesh08](https://github.com/agilesh08) on 2026-11-22T09:46:28Z. --- Closing for now to keep active review focused; will revisit after current PRs land.

Pull request closed

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!514
No description provided.