shader: expand 64-bit scalar bitfield extraction in pixel_aot and scanner #694

Merged
Holastor merged 1 commit from upstream-pr/700 into main 2026-11-22 23:23:46 +00:00
Holastor commented 2026-11-22 20:54:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T20:54:54Z.


Summary

Expand 64-bit scalar bitfield extraction and mask operations in tools/pixel_aot.py and tools/scan_unsupported_shaders.py:

  • tools/pixel_aot.py: expand scalar_u64() to accept full 64-bit hexadecimal literals (0x[0-9a-f]{1,16}), preserving 32-bit sign extension for literals up to 8 hex digits (len <= 10).
  • tools/scan_unsupported_shaders.py:
    • Register s_bfe_u64 and s_bfe_i64 in SUPPORTED_INSTRUCTIONS_REGEX and KNOWN_RDNA2_BASE_OPCODES.
    • Broaden SCALAR64_SOURCE pattern to accept 64-bit hex literals up to 16 hex digits (0x[0-9a-f]{1,16}).
  • tests/pixel_aot_check.py:
    • Add translation assertions for 64-bit hex literals and immediate control words in SCALAR_BFE64_OPS.
    • Assert SCALAR_BFE64_OPS <= ACCEPTED.
    • Add negative controls rejecting out-of-range hex literals (> 64 bits) and invalid s_bfm_b64 forms (single SGPR destination, VGPR sources, missing operands, out-of-range SGPRs).
  • tests/rdna2_tools_check.py:
    • Add scanner recognition tests for s_bfe_u64, s_bfe_i64, and s_bfm_b64 with 64-bit registers, hex literals, and immediate control constants.
    • Verify rejection of invalid operand combinations and spellings.

Evidence

  1. Pure-Python check suite:
python -B tests/pixel_aot_check.py
python -B tests/rdna2_tools_check.py
python -B tests/pso_readiness_check.py
python -B tests/form_coverage_check.py
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py

Observed result:

  • tests/pixel_aot_check.py: all assertions and negative controls passed.
  • tests/rdna2_tools_check.py: 52 tests passed (1 capability skip).
  • Form coverage, links, and bidi checks passed without errors.
  1. Negative controls:
  • tests/pixel_aot_check.py:
    • 17-digit hex literals (0x10000000000000000) correctly rejected by scalar_u64.
    • s_bfm_b64 with single destination, VGPR source, or out-of-range SGPR correctly rejected.
  • tests/rdna2_tools_check.py:
    • Single SGPR destinations on 64-bit BFE/BFM rejected.
    • Missing 3rd operand rejected.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6547667030 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/700). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-22T20:54:54Z. --- ### Summary Expand 64-bit scalar bitfield extraction and mask operations in `tools/pixel_aot.py` and `tools/scan_unsupported_shaders.py`: - `tools/pixel_aot.py`: expand `scalar_u64()` to accept full 64-bit hexadecimal literals (`0x[0-9a-f]{1,16}`), preserving 32-bit sign extension for literals up to 8 hex digits (`len <= 10`). - `tools/scan_unsupported_shaders.py`: - Register `s_bfe_u64` and `s_bfe_i64` in `SUPPORTED_INSTRUCTIONS_REGEX` and `KNOWN_RDNA2_BASE_OPCODES`. - Broaden `SCALAR64_SOURCE` pattern to accept 64-bit hex literals up to 16 hex digits (`0x[0-9a-f]{1,16}`). - `tests/pixel_aot_check.py`: - Add translation assertions for 64-bit hex literals and immediate control words in `SCALAR_BFE64_OPS`. - Assert `SCALAR_BFE64_OPS <= ACCEPTED`. - Add negative controls rejecting out-of-range hex literals (> 64 bits) and invalid `s_bfm_b64` forms (single SGPR destination, VGPR sources, missing operands, out-of-range SGPRs). - `tests/rdna2_tools_check.py`: - Add scanner recognition tests for `s_bfe_u64`, `s_bfe_i64`, and `s_bfm_b64` with 64-bit registers, hex literals, and immediate control constants. - Verify rejection of invalid operand combinations and spellings. ### Evidence 1. **Pure-Python check suite**: ```powershell python -B tests/pixel_aot_check.py python -B tests/rdna2_tools_check.py python -B tests/pso_readiness_check.py python -B tests/form_coverage_check.py python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py ``` Observed result: - `tests/pixel_aot_check.py`: all assertions and negative controls passed. - `tests/rdna2_tools_check.py`: 52 tests passed (1 capability skip). - Form coverage, links, and bidi checks passed without errors. 2. **Negative controls**: - `tests/pixel_aot_check.py`: - 17-digit hex literals (`0x10000000000000000`) correctly rejected by `scalar_u64`. - `s_bfm_b64` with single destination, VGPR source, or out-of-range SGPR correctly rejected. - `tests/rdna2_tools_check.py`: - Single SGPR destinations on 64-bit BFE/BFM rejected. - Missing 3rd operand rejected.
upstream-sync closed this pull request 2026-11-24 06:44:24 +00:00
MatyEjsr commented 2026-11-24 06:48:47 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MatyEjsr on 2026-11-22T21:51:39Z.


Verdict: Request changes (reviewed head 88f444e704fa2892610cfd16c2564829043581c1, compared against main 4c3b573).

Verification

Environment: Windows 11 x64, Python 3.12.10, DXC (C:\VulkanSDK\1.4.363.0\Bin\dxc.exe) for offline HLSL compile checks, and WSL Arch llvm-mc 23.1.5 (-triple=amdgcn--amdpal -mcpu=gfx1013) for ISA encoding checks. Zero-GPU review (no WARP or hardware draw executed).

Commands and results on 88f444e:

  • python -B tests/pixel_aot_check.py: passed (exit 0).
  • python -B tests/rdna2_tools_check.py: 52 passed, 1 skipped (test_llvm_comparison, skipped because LLVM_LIB is not set on Windows).
  • python -B tests/docs_links_check.py and python -B tests/bidi_controls_check.py: both passed.
  • Offline dxc -T ps_6_0 -E main -WX on scalar_bfe64("s_bfe_u64"|"s_bfe_i64", "0x8123456789abcdef", control="0x200020"): exit 0, 0 warnings.
  • git merge-tree --write-tree main 88f444e: clean against 4c3b573 (exit 0); conflicts with #688 (git merge-tree exit 1).

Issues to address

  1. Arbitrary 64-bit hex literals are not encodable on gfx1013:

    • On GFX1013, SOP1/SOP2 literal constants (ssrc == 255) are strictly a single 32-bit dword (zero-extended for _u64/_b64, sign-extended for _i64).
    • Verified with llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding:
      • s_bfe_u64 s[0:1], 0x8123456789abcdef, s4 -> error: invalid operand for instruction
      • s_bfe_i64 s[0:1], 0x8123456789abcdef, s4 -> error: invalid operand for instruction
      • s_bfe_u64 s[0:1], 0x100000000, s4 -> error: invalid operand for instruction
      • s_and_b64 s[0:1], 0x8123456789abcdef, s[2:3] -> error: invalid operand for instruction
    • When a valid 32-bit literal (0x80000000, or assembly input 0xffffffff80000000 on s_bfe_i64) is assembled and disassembled back with llvm-mc --disassemble, LLVM always prints the 8-hex-digit literal (0x80000000).
    • Widening SCALAR64_SOURCE and scalar_u64() to 0x[0-9a-f]{1,16} therefore accepts unencodable 64-bit hex literals across all 64-bit SALU rules (s_bfe_*64, s_and_b64, s_lshl_b64, s_cmp_eq_u64, etc.).
  2. String-length-dependent sign extension in scalar_u64():

    • if len(token) <= 10: makes the decoded 64-bit value depend on leading zeros rather than the numeric value: for signed=True, scalar_u64("0x80000000", ..., signed=True) returns ('2147483648u', '4294967295u'), while scalar_u64("0x080000000", ..., signed=True) returns ('2147483648u', '0u').
    • If the intent is to keep scalar_u64() aligned with real gfx1013 literals, reverting the 0x[0-9a-f]{1,16} widening avoids both issues (or if sign-extended 64-bit hex spelling like 0xffffffff80000000 is specifically needed, only accept values representable as a 32-bit SOP literal).
  3. Conflict and contradiction with #688:

    • This PR tests that single-SGPR forms (s_bfe_u64 s0, s[2:3], s4, s_bfe_u64 s[0:1], s2, s4, s_bfm_b64 s0, s2, s3) are rejected, while #688 changes pixel_aot.py and scan_unsupported_shaders.py to accept those same forms (and both PRs conflict in tools/scan_unsupported_shaders.py and tests/rdna2_tools_check.py).

Registering s_bfe_u64/s_bfe_i64 in scan_unsupported_shaders.py (SUPPORTED_INSTRUCTIONS_REGEX + KNOWN_RDNA2_BASE_OPCODES), the 32-bit immediate control word check (0x200020, confirmed valid in llvm-mc), and the s_bfm_b64 negative controls are all solid on their own.

AI-assisted review (local Python, offline DXC, and llvm-mc checks executed locally).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086368688 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/700#issuecomment-7086368688). Originally posted by [MatyEjsr](https://github.com/MatyEjsr) on 2026-11-22T21:51:39Z. --- **Verdict: Request changes** (reviewed head `88f444e704fa2892610cfd16c2564829043581c1`, compared against `main` `4c3b573`). ### Verification Environment: Windows 11 x64, Python 3.12.10, DXC (`C:\VulkanSDK\1.4.363.0\Bin\dxc.exe`) for offline HLSL compile checks, and WSL Arch `llvm-mc` 23.1.5 (`-triple=amdgcn--amdpal -mcpu=gfx1013`) for ISA encoding checks. Zero-GPU review (no WARP or hardware draw executed). Commands and results on `88f444e`: - `python -B tests/pixel_aot_check.py`: passed (exit 0). - `python -B tests/rdna2_tools_check.py`: **52 passed, 1 skipped** (`test_llvm_comparison`, skipped because `LLVM_LIB` is not set on Windows). - `python -B tests/docs_links_check.py` and `python -B tests/bidi_controls_check.py`: both passed. - Offline `dxc -T ps_6_0 -E main -WX` on `scalar_bfe64("s_bfe_u64"|"s_bfe_i64", "0x8123456789abcdef", control="0x200020")`: exit 0, 0 warnings. - `git merge-tree --write-tree main 88f444e`: clean against `4c3b573` (exit 0); **conflicts with #688** (`git merge-tree` exit 1). ### Issues to address 1. **Arbitrary 64-bit hex literals are not encodable on `gfx1013`:** - On GFX1013, SOP1/SOP2 literal constants (`ssrc == 255`) are strictly a single 32-bit dword (zero-extended for `_u64`/`_b64`, sign-extended for `_i64`). - Verified with `llvm-mc -triple=amdgcn--amdpal -mcpu=gfx1013 -show-encoding`: - `s_bfe_u64 s[0:1], 0x8123456789abcdef, s4` -> `error: invalid operand for instruction` - `s_bfe_i64 s[0:1], 0x8123456789abcdef, s4` -> `error: invalid operand for instruction` - `s_bfe_u64 s[0:1], 0x100000000, s4` -> `error: invalid operand for instruction` - `s_and_b64 s[0:1], 0x8123456789abcdef, s[2:3]` -> `error: invalid operand for instruction` - When a valid 32-bit literal (`0x80000000`, or assembly input `0xffffffff80000000` on `s_bfe_i64`) is assembled and disassembled back with `llvm-mc --disassemble`, LLVM always prints the 8-hex-digit literal (`0x80000000`). - Widening `SCALAR64_SOURCE` and `scalar_u64()` to `0x[0-9a-f]{1,16}` therefore accepts unencodable 64-bit hex literals across all 64-bit SALU rules (`s_bfe_*64`, `s_and_b64`, `s_lshl_b64`, `s_cmp_eq_u64`, etc.). 2. **String-length-dependent sign extension in `scalar_u64()`:** - `if len(token) <= 10:` makes the decoded 64-bit value depend on leading zeros rather than the numeric value: for `signed=True`, `scalar_u64("0x80000000", ..., signed=True)` returns `('2147483648u', '4294967295u')`, while `scalar_u64("0x080000000", ..., signed=True)` returns `('2147483648u', '0u')`. - If the intent is to keep `scalar_u64()` aligned with real `gfx1013` literals, reverting the `0x[0-9a-f]{1,16}` widening avoids both issues (or if sign-extended 64-bit hex spelling like `0xffffffff80000000` is specifically needed, only accept values representable as a 32-bit SOP literal). 3. **Conflict and contradiction with #688:** - This PR tests that single-SGPR forms (`s_bfe_u64 s0, s[2:3], s4`, `s_bfe_u64 s[0:1], s2, s4`, `s_bfm_b64 s0, s2, s3`) are rejected, while #688 changes `pixel_aot.py` and `scan_unsupported_shaders.py` to accept those same forms (and both PRs conflict in `tools/scan_unsupported_shaders.py` and `tests/rdna2_tools_check.py`). Registering `s_bfe_u64`/`s_bfe_i64` in `scan_unsupported_shaders.py` (`SUPPORTED_INSTRUCTIONS_REGEX` + `KNOWN_RDNA2_BASE_OPCODES`), the 32-bit immediate control word check (`0x200020`, confirmed valid in `llvm-mc`), and the `s_bfm_b64` negative controls are all solid on their own. *AI-assisted review (local Python, offline DXC, and `llvm-mc` checks executed locally).*
Holastor commented 2026-11-24 06:48:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T22:28:32Z.


Thanks @MatyEjsr for the thorough review and ISA verification!

We've addressed all three points:

  1. Reverted 0x[0-9a-f]{1,16} widening: SCALAR64_SOURCE in tools/scan_unsupported_shaders.py and scalar_u64() in tools/pixel_aot.py strictly keep 32-bit hex literals 0x[0-9a-f]{1,8}, matching real GFX1013 encodability where literal constants (ssrc == 255) are single 32-bit dwords.
  2. Reverted length-dependent sign extension: scalar_u64() directly sign-extends 32-bit literals based on bit 31 (value & 0x80000000) when signed=True. Added rejection controls in tests/pixel_aot_check.py for literals > 32 bits (0x8123456789abcdef and 0x100000000) and scanner rejection checks in tests/rdna2_tools_check.py.
  3. Conflict with #688: Resolved cleanly — #688 was updated to address the root cause in disasm_rdna2.py (formatting 64-bit SOP1/SOP2 operands as pairs s[N:N+1]), completely removing the single-SGPR widening from pixel_aot.py / scan_unsupported_shaders.py. Rebased this branch onto main with 0 conflicts.

All test suites pass locally (tests/rdna2_tools_check.py, tests/pixel_aot_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py, tests/pso_readiness_check.py, tests/dxil_retarget_check.py).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7086843704 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/700#issuecomment-7086843704). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-22T22:28:32Z. --- Thanks @MatyEjsr for the thorough review and ISA verification! We've addressed all three points: 1. **Reverted `0x[0-9a-f]{1,16}` widening**: `SCALAR64_SOURCE` in `tools/scan_unsupported_shaders.py` and `scalar_u64()` in `tools/pixel_aot.py` strictly keep 32-bit hex literals `0x[0-9a-f]{1,8}`, matching real GFX1013 encodability where literal constants (`ssrc == 255`) are single 32-bit dwords. 2. **Reverted length-dependent sign extension**: `scalar_u64()` directly sign-extends 32-bit literals based on bit 31 (`value & 0x80000000`) when `signed=True`. Added rejection controls in `tests/pixel_aot_check.py` for literals > 32 bits (`0x8123456789abcdef` and `0x100000000`) and scanner rejection checks in `tests/rdna2_tools_check.py`. 3. **Conflict with #688**: Resolved cleanly — #688 was updated to address the root cause in `disasm_rdna2.py` (formatting 64-bit SOP1/SOP2 operands as pairs `s[N:N+1]`), completely removing the single-SGPR widening from `pixel_aot.py` / `scan_unsupported_shaders.py`. Rebased this branch onto `main` with 0 conflicts. All test suites pass locally (`tests/rdna2_tools_check.py`, `tests/pixel_aot_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `tests/pso_readiness_check.py`, `tests/dxil_retarget_check.py`).
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!694
No description provided.