shader: lower gfx1013 three-operand VOP3 integer instructions in pixel_aot #520

Closed
Vonsek wants to merge 1 commit from upstream-pr/526 into main
Vonsek commented 2026-11-22 09:17:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-22T09:17:48Z.


Change

tools/pixel_aot.py now lowers the eight VOP3-only three-operand integer instructions that compilers emit to fold address and bit-packing arithmetic. Each one becomes a single HLSL uint expression in the existing INTEGER table:

Instruction Definition (AMD RDNA 2 ISA)
v_lshl_add_u32 (S0 << S1[4:0]) + S2
v_add_lshl_u32 (S0 + S1) << S2[4:0]
v_lshl_or_b32 (S0 << S1[4:0]) | S2
v_and_or_b32 (S0 & S1) | S2
v_or3_b32 S0 | S1 | S2
v_xor3_b32 S0 ^ S1 ^ S2
v_xad_u32 (S0 ^ S1) + S2
v_add3_u32 S0 + S1 + S2

Sums wrap modulo 2^32, shift counts use bits [4:0] only, and the result keeps its 32-bit pattern in the vector register through asfloat. Operands go through the existing int_operand path, so float source modifiers, clamp, a wrong operand count, a 33-bit immediate, unwritten registers, reads of outstanding samples or scalar loads and the whole-quad mask are rejected. tools/scan_unsupported_shaders.py reads the same table, so it recognises the new forms without a separate list.

Tests:

  • tests/pixel_aot_check.py adds int3_program(k). It writes all eight results with SGPR, VGPR, inline, negative inline (-7) and literal (0x0f0f00f0) operands, then exports the four bytes of result k through v_cvt_f32_ubyte0-3, so each channel is an exact integer from 0 to 255. int3_reference is an independent Python model of the ISA definitions. The two input sets have shift counts with bits above bit 4, left shifts that drop high bits and v_add3_u32 sums that carry out of bit 31. Every input and result is the pattern of a normal binary32 value, so the check does not depend on driver flushing or NaN quieting.
  • New mode draw-int3, registered as pixel_aot_int3_hardware and pixel_aot_int3_warp (60 s timeout, SKIP_RETURN_CODE 77 on hardware, FORM_COVERAGE_RECORD set): 8 compiles × 2 input sets, then five negative draws that must report pixel_mismatch: v_lshl_add_u32→v_lshl_or_b32, v_add_lshl_u32→v_lshl_add_u32, v_and_or_b32→v_or3_b32, v_xad_u32→v_xor3_b32 and v_add3_u32→v_xor3_b32.
  • Controls: exact HLSL for each form; masking of an inline count above 31; rejection of modifiers, clamp, wrong source counts, 0x100000000, unwritten registers; rejection of the neighbouring v_alignbit_b32, v_alignbyte_b32, v_perm_b32, v_mad_u32_u24, v_mad_u32_u16, v_sad_u32, v_lerp_u8 and v_mul_lo_u32; rejection of reads before vmcnt(0)/lgkmcnt(0) and use under WQM.
  • tests/pixel_aot_check.py binary round-trips the fixture for results 0 and 7.
  • tests/form_coverage_check.py asserts the eight VOP3 forms are counted in both gfx1013.tsv and rdna2.tsv (exactly 8 more covered forms) and the eight rejected neighbours stay out.

docs/experiments.md#offline-pixel-shader-recompilation describes the forms, the fixture, the negative controls and the new tests.

Verification

  • Linux, LLVM 18: tests/pixel_aot_check.py binary ... passes (disassembled fixture lowers to the same HLSL as the source text); controls, form_coverage_check, rdna2_tools_check, pso_readiness_check, docs_links_check and bidi_controls_check pass.
  • With tools/pixel_aot.py from main, tests/pixel_aot_check.py and tests/form_coverage_check.py fail with ValueError: Unsupported instruction 22: v_lshl_add_u32 v20, s44, s47, v19.
  • The generated HLSL interpreted on the CPU with 32-bit wrapping uint semantics matches int3_reference for all 8 variants and both input sets.
  • DXC compilation and the D3D12 draws, measured on Windows: DXC 1.9.2602.17 compiles all eight variants, every draw matches int3_reference for both input sets, and all five negative draws report pixel_mismatch, on the RTX 5080 and on WARP.
  • Windows: ctest --preset dev --no-tests=error -R '^pixel_aot_(int3_(hardware|warp)|hardware|warp)$' -V at d8246c4 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100: 4/4 passed. pixel_aot_int3_hardware on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) took 5.9 s and pixel_aot_int3_warp 1.4 s; pixel_aot_hardware and pixel_aot_warp still pass. The D3D12 debug layer was not available. The full ctest --preset dev --no-tests=error passed 238/238, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped.

Evidence and follow-up

  • The 5-bit masking of shift counts follows the RDNA 2 ISA reference and is not measured on Scarlett.
  • The draw avoids NaN and denormal bit patterns.
  • Still uncovered nearby: v_alignbit_b32, v_alignbyte_b32, v_perm_b32, v_mad_u32_u24/v_mad_i32_i24, v_mul_lo_u32/v_mul_hi_u32, v_sad_*, v_lerp_u8 and v_mbcnt_*. Bit counts and scans are in open #436.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6540694839 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/526). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-22T09:17:48Z. --- ## Change `tools/pixel_aot.py` now lowers the eight VOP3-only three-operand integer instructions that compilers emit to fold address and bit-packing arithmetic. Each one becomes a single HLSL `uint` expression in the existing `INTEGER` table: | Instruction | Definition (AMD RDNA 2 ISA) | |---|---| | `v_lshl_add_u32` | (S0 << S1[4:0]) + S2 | | `v_add_lshl_u32` | (S0 + S1) << S2[4:0] | | `v_lshl_or_b32` | (S0 << S1[4:0]) \| S2 | | `v_and_or_b32` | (S0 & S1) \| S2 | | `v_or3_b32` | S0 \| S1 \| S2 | | `v_xor3_b32` | S0 ^ S1 ^ S2 | | `v_xad_u32` | (S0 ^ S1) + S2 | | `v_add3_u32` | S0 + S1 + S2 | Sums wrap modulo 2^32, shift counts use bits [4:0] only, and the result keeps its 32-bit pattern in the vector register through `asfloat`. Operands go through the existing `int_operand` path, so float source modifiers, `clamp`, a wrong operand count, a 33-bit immediate, unwritten registers, reads of outstanding samples or scalar loads and the whole-quad mask are rejected. `tools/scan_unsupported_shaders.py` reads the same table, so it recognises the new forms without a separate list. Tests: - `tests/pixel_aot_check.py` adds `int3_program(k)`. It writes all eight results with SGPR, VGPR, inline, negative inline (`-7`) and literal (`0x0f0f00f0`) operands, then exports the four bytes of result `k` through `v_cvt_f32_ubyte0`-`3`, so each channel is an exact integer from 0 to 255. `int3_reference` is an independent Python model of the ISA definitions. The two input sets have shift counts with bits above bit 4, left shifts that drop high bits and `v_add3_u32` sums that carry out of bit 31. Every input and result is the pattern of a normal binary32 value, so the check does not depend on driver flushing or NaN quieting. - New mode `draw-int3`, registered as `pixel_aot_int3_hardware` and `pixel_aot_int3_warp` (60 s timeout, `SKIP_RETURN_CODE 77` on hardware, `FORM_COVERAGE_RECORD` set): 8 compiles × 2 input sets, then five negative draws that must report `pixel_mismatch`: `v_lshl_add_u32`→`v_lshl_or_b32`, `v_add_lshl_u32`→`v_lshl_add_u32`, `v_and_or_b32`→`v_or3_b32`, `v_xad_u32`→`v_xor3_b32` and `v_add3_u32`→`v_xor3_b32`. - Controls: exact HLSL for each form; masking of an inline count above 31; rejection of modifiers, clamp, wrong source counts, `0x100000000`, unwritten registers; rejection of the neighbouring `v_alignbit_b32`, `v_alignbyte_b32`, `v_perm_b32`, `v_mad_u32_u24`, `v_mad_u32_u16`, `v_sad_u32`, `v_lerp_u8` and `v_mul_lo_u32`; rejection of reads before `vmcnt(0)`/`lgkmcnt(0)` and use under WQM. - `tests/pixel_aot_check.py binary` round-trips the fixture for results 0 and 7. - `tests/form_coverage_check.py` asserts the eight VOP3 forms are counted in both `gfx1013.tsv` and `rdna2.tsv` (exactly 8 more covered forms) and the eight rejected neighbours stay out. `docs/experiments.md#offline-pixel-shader-recompilation` describes the forms, the fixture, the negative controls and the new tests. ## Verification - Linux, LLVM 18: `tests/pixel_aot_check.py binary ...` passes (disassembled fixture lowers to the same HLSL as the source text); controls, `form_coverage_check`, `rdna2_tools_check`, `pso_readiness_check`, `docs_links_check` and `bidi_controls_check` pass. - With `tools/pixel_aot.py` from `main`, `tests/pixel_aot_check.py` and `tests/form_coverage_check.py` fail with `ValueError: Unsupported instruction 22: v_lshl_add_u32 v20, s44, s47, v19`. - The generated HLSL interpreted on the CPU with 32-bit wrapping `uint` semantics matches `int3_reference` for all 8 variants and both input sets. - DXC compilation and the D3D12 draws, measured on Windows: DXC 1.9.2602.17 compiles all eight variants, every draw matches `int3_reference` for both input sets, and all five negative draws report `pixel_mismatch`, on the RTX 5080 and on WARP. - Windows: `ctest --preset dev --no-tests=error -R '^pixel_aot_(int3_(hardware|warp)|hardware|warp)$' -V` at d8246c4 on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100: 4/4 passed. `pixel_aot_int3_hardware` on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) took 5.9 s and `pixel_aot_int3_warp` 1.4 s; `pixel_aot_hardware` and `pixel_aot_warp` still pass. The D3D12 debug layer was not available. The full `ctest --preset dev --no-tests=error` passed 238/238, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. ## Evidence and follow-up - The 5-bit masking of shift counts follows the RDNA 2 ISA reference and is not measured on Scarlett. - The draw avoids NaN and denormal bit patterns. - Still uncovered nearby: `v_alignbit_b32`, `v_alignbyte_b32`, `v_perm_b32`, `v_mad_u32_u24`/`v_mad_i32_i24`, `v_mul_lo_u32`/`v_mul_hi_u32`, `v_sad_*`, `v_lerp_u8` and `v_mbcnt_*`. Bit counts and scans are in open #436.
upstream-sync closed this pull request 2026-11-24 06:43:30 +00:00
R0Y00 commented 2026-11-24 06:49:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:58:41Z.


All eight ternary 32-bit forms landed in #766 with LLVM 15 binary round-trip, WARP and hardware readback, and mutation controls. I verified the same eight names in main. Closing the duplicate implementation and keeping this branch available. The pending-load and opcode-substitution controls here are useful reference material for a focused test follow-up if they expose a gap in the current suite.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7115167369 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/526#issuecomment-7115167369). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T21:58:41Z. --- All eight ternary 32-bit forms landed in #766 with LLVM 15 binary round-trip, WARP and hardware readback, and mutation controls. I verified the same eight names in main. Closing the duplicate implementation and keeping this branch available. The pending-load and opcode-substitution controls here are useful reference material for a focused test follow-up if they expose a gap in the current suite.

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