pixel_aot: lower 32-bit vector bitwise logic and shifts #336

Closed
Holastor wants to merge 1 commit from upstream-pr/341 into main
Holastor commented 2026-11-21 22:45:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-21T22:45:59Z.


Change

Lower 32-bit vector bitwise logic and shift operations in tools/pixel_aot.py:

  • v_and_b32
  • v_or_b32
  • v_xor_b32
  • v_lshlrev_b32
  • v_lshrrev_b32
  • v_ashrrev_i32

This advances milestone #1 / offline pixel shader recompilation, isolating the 32-bit vector bitwise and shift portion independently from the overlapping, unmerged work in #232 (Refs #232).

Vector registers remain precise float in the emitted HLSL. Operands are bit-cast to unsigned 32-bit integers via asuint, and the result is stored with asfloat. The reverse shift forms mask the shift count in src0 to 5 bits (& 31u) matching RDNA2 hardware semantics (S1.u << (S0.u & 31), S1.u >> (S0.u & 31), S1.i >> (S0.u & 31)). v_ashrrev_i32 performs arithmetic right shift on asint, sign-extending negative values before casting back to uint.

Operand checking (vgpr_name, u32_operand) validates register ranges (v0..v255), rejects uninitialized or non-numeric vector registers, and checks against collisions with outstanding texture samples before s_waitcnt vmcnt(0) as well as pending scalar constant loads before s_waitcnt lgkmcnt(0).

tools/scan_unsupported_shaders.py tracks supported forms directly from pixel_aot.VECTOR_BITWISE_32, preventing drift between the scanner and lowerer.

Verification

Commit under test: 68df671 (branched cleanly from current main at 1292d15).

Environment: Windows 11 build 26100, MSVC 19.51.36263.0, Windows SDK 10.0.26100.0, DXC 10.0.26100.0, D3D12 debug layer enabled on both backends.

  • Physical GPU: AMD Radeon RX 6600M (vendor=1002 device=73ff), driver 32.0.21045.11001
  • WARP: Microsoft Basic Render Driver (vendor=1414 device=008c), driver 10.0.26100.9818

D3D12 hardware, WARP and tool tests

cmake --build --preset dev
ctest --preset dev --no-tests=error -R '^pixel_aot_|^rdna2_tools' -V
1/3 Test #122: rdna2_tools_check ................   Passed    0.62 sec
2/3 Test #126: pixel_aot_hardware ...............   Passed    3.94 sec
3/3 Test #129: pixel_aot_warp ...................   Passed    4.71 sec

100% tests passed, 0 tests failed out of 3
Total Test time (real) =  15.57 sec

Test logs:

  • pixel_aot_hardware:
    backend=hardware debug_layer=enabled
    adapter=AMD Radeon RX 6600M vendor=1002 device=73ff
    driver=32.0.21045.11001
    pixels=4096 channels=16384 max_absolute_error=0
    debug_errors=0 debug_warnings=0
    
  • pixel_aot_warp:
    backend=warp debug_layer=enabled
    adapter=Microsoft Basic Render Driver vendor=1414 device=008c
    driver=10.0.26100.9818
    pixels=4096 channels=16384 max_absolute_error=0
    debug_errors=0 debug_warnings=0
    

Pure-Python test suite

python -B tests/bcpack_check.py
python -B tests/form_coverage_check.py
python -B tests/dxcontainer_part_offsets_check.py
python -B tests/layout_chunks_check.py
python -B tests/resource_ranges_check.py
python -B tests/script_state_check.py
python -B tests/intake/paths_check.py
python -B tests/rdna2_tools_check.py
python -B tests/pso_readiness_check.py

All 9 test suites passed (27/27 tests in rdna2_tools_check OK with 1 capability skip).

Evidence and follow-up

  • Source-built synthetic fixture: Added BITWISE_BODY in tests/pixel_aot_check.py using with_constants (s44:s47) and sample registers (v12:v15), producing exact half-float outputs [1.5, 3.0, 2.0, 1.0].
  • Negative mutation controls: Four mutations in check_vector_bitwise_draw verify that each distinct operation is enforced:
    1. v_ashrrev_i32 to v_lshrrev_b32 (proves arithmetic vs logical right shift; 0xf0000000 >> 4 sign-extends to 0xff000000 rather than zero-filling to 0x0f000000).
    2. v_xor_b32 to v_and_b32 (proves XOR vs AND; zeroing the channel).
    3. v_and_b32 to v_or_b32 (proves AND vs OR; altering red to 1.75).
    4. v_lshrrev_b32 to v_ashrrev_i32 (proves logical right shift of 0x80000000 >> 1 does not sign extend, distinguishing +2.0 from -2.0).
      Each mutation independently asserts result.returncode == 1 and "pixel_mismatch" in result.stderr.
  • Negative controls in check_controls: Reject writes overlapping outstanding samples before s_waitcnt vmcnt(0), uninitialized VGPR reads (v50), non-numeric vector register reads (v0 holding bary_i), out-of-range registers (v256), and execution in quad mode.
  • RDNA2 tools golden vectors: Added raw little-endian binary encodings for all six VOP2 opcodes (0207021a, 0207021c, 0207021e, 02070220, 02070222, 02070224) to tests/rdna2_tools_check.py.
  • GFX1013 binary packaging: Added BITWISE_BODY to fixtures in check_binary for llvm-mc assembly and libLLVM disassembly.
  • License: Original contributions submitted under the MIT License.
  • Title-neutral wording: Kept throughout; no game files, dumps, torrents or credentials included.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535388734 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/341). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-21T22:45:59Z. --- ## Change Lower 32-bit vector bitwise logic and shift operations in `tools/pixel_aot.py`: - `v_and_b32` - `v_or_b32` - `v_xor_b32` - `v_lshlrev_b32` - `v_lshrrev_b32` - `v_ashrrev_i32` This advances milestone #1 / offline pixel shader recompilation, isolating the 32-bit vector bitwise and shift portion independently from the overlapping, unmerged work in #232 (`Refs #232`). Vector registers remain `precise float` in the emitted HLSL. Operands are bit-cast to unsigned 32-bit integers via `asuint`, and the result is stored with `asfloat`. The reverse shift forms mask the shift count in `src0` to 5 bits (`& 31u`) matching RDNA2 hardware semantics (`S1.u << (S0.u & 31)`, `S1.u >> (S0.u & 31)`, `S1.i >> (S0.u & 31)`). `v_ashrrev_i32` performs arithmetic right shift on `asint`, sign-extending negative values before casting back to `uint`. Operand checking (`vgpr_name`, `u32_operand`) validates register ranges (`v0`..`v255`), rejects uninitialized or non-numeric vector registers, and checks against collisions with outstanding texture samples before `s_waitcnt vmcnt(0)` as well as pending scalar constant loads before `s_waitcnt lgkmcnt(0)`. `tools/scan_unsupported_shaders.py` tracks supported forms directly from `pixel_aot.VECTOR_BITWISE_32`, preventing drift between the scanner and lowerer. ## Verification Commit under test: `68df671` (branched cleanly from current `main` at `1292d15`). **Environment:** Windows 11 build 26100, MSVC 19.51.36263.0, Windows SDK 10.0.26100.0, DXC 10.0.26100.0, D3D12 debug layer enabled on both backends. - Physical GPU: AMD Radeon RX 6600M (`vendor=1002 device=73ff`), driver `32.0.21045.11001` - WARP: Microsoft Basic Render Driver (`vendor=1414 device=008c`), driver `10.0.26100.9818` ### D3D12 hardware, WARP and tool tests ```powershell cmake --build --preset dev ctest --preset dev --no-tests=error -R '^pixel_aot_|^rdna2_tools' -V ``` ```text 1/3 Test #122: rdna2_tools_check ................ Passed 0.62 sec 2/3 Test #126: pixel_aot_hardware ............... Passed 3.94 sec 3/3 Test #129: pixel_aot_warp ................... Passed 4.71 sec 100% tests passed, 0 tests failed out of 3 Total Test time (real) = 15.57 sec ``` Test logs: - `pixel_aot_hardware`: ```text backend=hardware debug_layer=enabled adapter=AMD Radeon RX 6600M vendor=1002 device=73ff driver=32.0.21045.11001 pixels=4096 channels=16384 max_absolute_error=0 debug_errors=0 debug_warnings=0 ``` - `pixel_aot_warp`: ```text backend=warp debug_layer=enabled adapter=Microsoft Basic Render Driver vendor=1414 device=008c driver=10.0.26100.9818 pixels=4096 channels=16384 max_absolute_error=0 debug_errors=0 debug_warnings=0 ``` ### Pure-Python test suite ```powershell python -B tests/bcpack_check.py python -B tests/form_coverage_check.py python -B tests/dxcontainer_part_offsets_check.py python -B tests/layout_chunks_check.py python -B tests/resource_ranges_check.py python -B tests/script_state_check.py python -B tests/intake/paths_check.py python -B tests/rdna2_tools_check.py python -B tests/pso_readiness_check.py ``` All 9 test suites passed (27/27 tests in `rdna2_tools_check` OK with 1 capability skip). ## Evidence and follow-up - **Source-built synthetic fixture:** Added `BITWISE_BODY` in `tests/pixel_aot_check.py` using `with_constants` (`s44:s47`) and sample registers (`v12:v15`), producing exact half-float outputs `[1.5, 3.0, 2.0, 1.0]`. - **Negative mutation controls:** Four mutations in `check_vector_bitwise_draw` verify that each distinct operation is enforced: 1. `v_ashrrev_i32` to `v_lshrrev_b32` (proves arithmetic vs logical right shift; `0xf0000000 >> 4` sign-extends to `0xff000000` rather than zero-filling to `0x0f000000`). 2. `v_xor_b32` to `v_and_b32` (proves XOR vs AND; zeroing the channel). 3. `v_and_b32` to `v_or_b32` (proves AND vs OR; altering red to 1.75). 4. `v_lshrrev_b32` to `v_ashrrev_i32` (proves logical right shift of `0x80000000 >> 1` does not sign extend, distinguishing `+2.0` from `-2.0`). Each mutation independently asserts `result.returncode == 1` and `"pixel_mismatch" in result.stderr`. - **Negative controls in `check_controls`:** Reject writes overlapping outstanding samples before `s_waitcnt vmcnt(0)`, uninitialized VGPR reads (`v50`), non-numeric vector register reads (`v0` holding `bary_i`), out-of-range registers (`v256`), and execution in quad mode. - **RDNA2 tools golden vectors:** Added raw little-endian binary encodings for all six VOP2 opcodes (`0207021a`, `0207021c`, `0207021e`, `02070220`, `02070222`, `02070224`) to `tests/rdna2_tools_check.py`. - **GFX1013 binary packaging:** Added `BITWISE_BODY` to `fixtures` in `check_binary` for `llvm-mc` assembly and `libLLVM` disassembly. - **License:** Original contributions submitted under the MIT License. - **Title-neutral wording:** Kept throughout; no game files, dumps, torrents or credentials included. ## 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.
upstream-sync closed this pull request 2026-11-24 06:42:31 +00:00
Holastor commented 2026-11-24 06:48:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-22T08:29:15Z.


@R0Y00 Closing as superseded by #232 (5a16ee9), which landed 32-bit vector bitwise logic, shifts (v_and_b32, v_or_b32, v_xor_b32, v_not_b32, v_bfi_b32, v_lshlrev_b32, v_lshrrev_b32, v_ashrrev_i32) and integer conversions into main.

Opened a follow-up PR #505 to register the pixel_aot.INTEGER instructions in tools/scan_unsupported_shaders.py and verify tracking in pso_readiness_check.py.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7076547447 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/341#issuecomment-7076547447). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-22T08:29:15Z. --- @R0Y00 Closing as superseded by #232 (`5a16ee9`), which landed 32-bit vector bitwise logic, shifts (`v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_not_b32`, `v_bfi_b32`, `v_lshlrev_b32`, `v_lshrrev_b32`, `v_ashrrev_i32`) and integer conversions into `main`. Opened a follow-up PR #505 to register the `pixel_aot.INTEGER` instructions in `tools/scan_unsupported_shaders.py` and verify tracking in `pso_readiness_check.py`.

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