shader: lower the 64-bit VOP3 shifts in pixel_aot #957

Merged
MasterDomino merged 3 commits from upstream-pr/964 into main 2026-11-23 19:50:42 +00:00
MasterDomino commented 2026-11-23 19:02:30 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T19:02:30Z.


Change

Implements #928 as scoped there: tools/pixel_aot.py lowers the 64-bit VOP3 shifts v_lshlrev_b64, v_lshrrev_b64 and v_ashrrev_i64. These are opcodes 767-769 in the AMD RDNA 2 ISA guide §12.12: D = S1 << S0[5:0], S1 >> S0[5:0] and signext(S1) >> S0[5:0].

  • Representation. The value uses the two-word representation of the 64-bit comparisons (int64_operand), so the HLSL needs no 64-bit type.
  • Amount and fill. The amount keeps six bits (& 63u). Only v_ashrrev_i64 fills with the sign bit.
  • In-place. Both source words are read into lo/hi temporaries before the destination pair is written, so the in-place LLVM form keeps the original value.
  • No shift by 32 or more. The result is selected for amounts below and above 32 (sh < 32u ? … : …). Every 32-bit HLSL shift count is sb = amount & 31, 32u - sb when sb != 0, or 31u. A 32-bit HLSL shift never receives a count of 32 or more, which HLSL would wrap.
  • Operands.
    • The amount is a VGPR, an SGPR, an inline integer from -16 to 64 or a literal.
    • The value is a VGPR pair, an SGPR pair or an inline integer, sign-extended to 64 bits as the comparisons assume.
    • At most one source may be an SGPR or literal, the ISA's one scalar broadcast constant; LLVM 15 refuses the others with violates constant bus restrictions.
    • The _e64 spelling lowers identically to LLVM's suffix-less print.
  • Refused: _e32, clamp, op_sel, source modifiers, a destination that is not a pair within v0..v255 or that has an outstanding image sample, float amounts, a literal value, untracked sources, and use inside a masked region. Two refusals come from the existing int64_operand and keep its "64-bit comparison" wording.
  • Scanner. tools/scan_unsupported_shaders.py gets a pattern for the same operand shapes, including the one-scalar rule. tests/rdna2_tools_check.py::test_shift64_scanner_support pins it.

Refs #928

Verification

Upstream main at 185ffbe, Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7.

python -B tests/pixel_aot_check.py                       # controls, including check_shift64_controls
python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM-15.so>
python -B tests/compute_store_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM-15.so>
python -B tests/form_coverage_check.py
LLVM_LIB=… LLVM_MC=… LLVM_OBJCOPY=… python -B tests/rdna2_tools_check.py

All exit 0, and so do the 26 platform-independent checks and tests/ffx_dispatch_aot_check.py with LLVM 15.

  • Controls.
    • In all nine programs, each shift keeps six bits of the amount, and every HLSL shift count is one of sb, 32u - sb or 31u.
    • asint appears only for v_ashrrev_i64.
    • In the in-place program, the lo/hi reads precede both destination writes.
    • _e64 lowers identically.
    • 17 malformed or out-of-scope forms are refused, each checked for the intended reason. So are a destination with an outstanding image sample and a shift inside a masked region.
  • Binary. All nine programs are assembled and disassembled with LLVM 15 for gfx1013, and each must lower identically to its source.
  • Formula check (local, not part of the suite). A Python model of the emitted expressions, including HLSL's five-bit shift-count masking, matches a plain 64-bit reference on 2,751 cases. Those are 7 values × (amounts 0-127 plus 0xffffffc1, 0x80000020, 0xffffffff) × 3 instructions.
  • Draw dry run. Not a substitute for WARP. check_shift64_draw ran with the Linux DXC 1.9.2609 release and only the D3D12 calls replaced by recorders. All 12 shaders compile (9 programs and 3 mutants), and 270 well-formed integer cases are written.

Not run here: pixel_aot_shift64_warp. It needs Windows; this PR's CI run is the first WARP result.

  • Programs. Three per instruction: register sources; the in-place pair next to the literal amount 0x41 (wraps to 1); and an SGPR-pair value next to the inline -1.
  • Inputs. Three values, one with a negative high word, and the amounts 0, 1, 31, 32, 33, 63, 64, 65, 0xffffffc1 and 0x80000020.
  • Readback. All four result words through R32G32B32A32_UINT, against shift64_reference, which is written from the ISA formulas.
  • Mutated v_ashrrev_i64 shaders that must mismatch: the amount masked to five bits, the sign fill replaced with zeros, and the result words swapped.

No _hardware run is reported.

Evidence and follow-up

All fixtures are source-built. Two inputs are assumed, not sourced:

  • the 64-bit sign extension of an inline value, the same assumption as the 64-bit comparisons;
  • the legality of unaligned VGPR pairs on hardware.

The draw pins the translator's model on a desktop adapter; it is not evidence for gfx1013 execution. On one local input (the 12,101 PS records from #932, aggregates only), v_lshlrev_b64 appears in 255 records (2.1%), and the other two shifts don't appear.

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. (docs/experiments.md, next to the 64-bit comparisons.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted.

🤖 Generated with Claude Code

https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6566684558 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/964). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T19:02:30Z. --- ## Change Implements #928 as scoped there: `tools/pixel_aot.py` lowers the 64-bit VOP3 shifts `v_lshlrev_b64`, `v_lshrrev_b64` and `v_ashrrev_i64`. These are opcodes 767-769 in the [AMD RDNA 2 ISA guide](https://gpuopen.com/download/rdna2-shader-instruction-set-architecture.pdf) §12.12: `D = S1 << S0[5:0]`, `S1 >> S0[5:0]` and `signext(S1) >> S0[5:0]`. - **Representation.** The value uses the two-word representation of the 64-bit comparisons (`int64_operand`), so the HLSL needs no 64-bit type. - **Amount and fill.** The amount keeps six bits (`& 63u`). Only `v_ashrrev_i64` fills with the sign bit. - **In-place.** Both source words are read into `lo`/`hi` temporaries before the destination pair is written, so the in-place LLVM form keeps the original value. - **No shift by 32 or more.** The result is selected for amounts below and above 32 (`sh < 32u ? … : …`). Every 32-bit HLSL shift count is `sb = amount & 31`, `32u - sb` when `sb != 0`, or `31u`. A 32-bit HLSL shift never receives a count of 32 or more, which HLSL would wrap. - **Operands.** - The amount is a VGPR, an SGPR, an inline integer from -16 to 64 or a literal. - The value is a VGPR pair, an SGPR pair or an inline integer, sign-extended to 64 bits as the comparisons assume. - At most one source may be an SGPR or literal, the ISA's one scalar broadcast constant; LLVM 15 refuses the others with `violates constant bus restrictions`. - The `_e64` spelling lowers identically to LLVM's suffix-less print. - **Refused:** `_e32`, `clamp`, `op_sel`, source modifiers, a destination that is not a pair within `v0`..`v255` or that has an outstanding image sample, float amounts, a literal value, untracked sources, and use inside a masked region. Two refusals come from the existing `int64_operand` and keep its "64-bit comparison" wording. - **Scanner.** `tools/scan_unsupported_shaders.py` gets a pattern for the same operand shapes, including the one-scalar rule. `tests/rdna2_tools_check.py::test_shift64_scanner_support` pins it. Refs #928 ## Verification Upstream `main` at `185ffbe`, Fedora 45 x86_64, Python 3.15.2, LLVM 15.0.7. ```sh python -B tests/pixel_aot_check.py # controls, including check_shift64_controls python -B tests/pixel_aot_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM-15.so> python -B tests/compute_store_check.py binary <llvm-mc> <llvm-objcopy> <libLLVM-15.so> python -B tests/form_coverage_check.py LLVM_LIB=… LLVM_MC=… LLVM_OBJCOPY=… python -B tests/rdna2_tools_check.py ``` All exit 0, and so do the 26 platform-independent checks and `tests/ffx_dispatch_aot_check.py` with LLVM 15. - **Controls.** - In all nine programs, each shift keeps six bits of the amount, and every HLSL shift count is one of `sb`, `32u - sb` or `31u`. - `asint` appears only for `v_ashrrev_i64`. - In the in-place program, the `lo`/`hi` reads precede both destination writes. - `_e64` lowers identically. - 17 malformed or out-of-scope forms are refused, each checked for the intended reason. So are a destination with an outstanding image sample and a shift inside a masked region. - **Binary.** All nine programs are assembled and disassembled with LLVM 15 for gfx1013, and each must lower identically to its source. - **Formula check (local, not part of the suite).** A Python model of the emitted expressions, including HLSL's five-bit shift-count masking, matches a plain 64-bit reference on 2,751 cases. Those are 7 values × (amounts 0-127 plus `0xffffffc1`, `0x80000020`, `0xffffffff`) × 3 instructions. - **Draw dry run.** Not a substitute for WARP. `check_shift64_draw` ran with the Linux DXC 1.9.2609 release and only the D3D12 calls replaced by recorders. All 12 shaders compile (9 programs and 3 mutants), and 270 well-formed integer cases are written. **Not run here: `pixel_aot_shift64_warp`.** It needs Windows; this PR's CI run is the first WARP result. - **Programs.** Three per instruction: register sources; the in-place pair next to the literal amount `0x41` (wraps to 1); and an SGPR-pair value next to the inline `-1`. - **Inputs.** Three values, one with a negative high word, and the amounts 0, 1, 31, 32, 33, 63, 64, 65, `0xffffffc1` and `0x80000020`. - **Readback.** All four result words through `R32G32B32A32_UINT`, against `shift64_reference`, which is written from the ISA formulas. - **Mutated `v_ashrrev_i64` shaders that must mismatch:** the amount masked to five bits, the sign fill replaced with zeros, and the result words swapped. No `_hardware` run is reported. ## Evidence and follow-up All fixtures are source-built. Two inputs are assumed, not sourced: - the 64-bit sign extension of an inline value, the same assumption as the 64-bit comparisons; - the legality of unaligned VGPR pairs on hardware. The draw pins the translator's model on a desktop adapter; it is not evidence for gfx1013 execution. On one local input (the 12,101 PS records from #932, aggregates only), `v_lshlrev_b64` appears in 255 records (2.1%), and the other two shifts don't appear. ## 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. (`docs/experiments.md`, next to the 64-bit comparisons.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01B48PpcRN2Er51keRf2DsS5
upstream-sync closed this pull request 2026-11-24 06:45:37 +00:00
R0Y00 commented 2026-11-24 06:49:32 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T19:21:45Z.


I made the carry-side shift count stay in 0..31 even in the unselected arm at a zero subshift. That keeps both generated dword shift expressions in range while preserving the zero carry. The existing static controls, full LLVM 15 binary pass, and shift64 readbacks on WARP and RTX 4060 Laptop all passed with the change. The author fixtures and mismatch controls are unchanged.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7111493494 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/964#issuecomment-7111493494). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T19:21:45Z. --- I made the carry-side shift count stay in 0..31 even in the unselected arm at a zero subshift. That keeps both generated dword shift expressions in range while preserving the zero carry. The existing static controls, full LLVM 15 binary pass, and shift64 readbacks on WARP and RTX 4060 Laptop all passed with the change. The author fixtures and mismatch controls are unchanged.
MasterDomino commented 2026-11-24 06:49:33 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-23T19:26:02Z.


Thanks for the fix, you're right. HLSL evaluates both arms of ?:, so with a zero sub-shift the unselected arm computed lo >> 32. That value was always discarded, and HLSL masks the count, which is why the readback and my model agreed. But my description's claim that no 32-bit shift receives a count of 32 or more was wrong, and my static control only matched the (32u - sb) spelling instead of checking the range. sc = (32u - sb) & 31u closes it properly.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7111598039 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/964#issuecomment-7111598039). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-23T19:26:02Z. --- Thanks for the fix, you're right. HLSL evaluates both arms of `?:`, so with a zero sub-shift the unselected arm computed `lo >> 32`. That value was always discarded, and HLSL masks the count, which is why the readback and my model agreed. But my description's claim that no 32-bit shift receives a count of 32 or more was wrong, and my static control only matched the `(32u - sb)` spelling instead of checking the range. `sc = (32u - sb) & 31u` closes it properly. AI-assisted.
lantiumBot commented 2026-11-24 06:49:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lantiumBot on 2026-11-23T20:07:16Z.


First _hardware result for this draw, on RDNA 4. Data only.

pixel_aot_shift64_hardware passed on an AMD Radeon RX 9060 XT, and pixel_aot_shift64_warp passed on in-box WARP, at merged main.

ctest --preset dev --no-tests=error -R '^pixel_aot_shift64_(hardware|warp)$' -V
  • Commit: f8e80e5663097c3ccc6fd35adbe4fba65e0fbf2e, clean tree, dev preset (Debug)
  • Adapter: AMD Radeon RX 9060 XT (vendor=1002 device=7590), driver 32.0.32029.2010
  • WARP: Microsoft Basic Render Driver (1414:008c), in-box, driver 10.0.26100.10068
  • Windows build: 26300.10075, D3D12 debug layer unavailable
  • DXC 1.9.2602.17 (21d28f727) from Windows SDK 10.0.26100.0

One run per backend, 0 capability skips. The test prints no per-case lines on success, so this reports the CTest verdict only: the positive cases matched and the three mutated v_ashrrev_i64 shaders mismatched as the fixture requires.

For context, the full ctest --preset dev --no-tests=error -R '_hardware$' run at this commit gave 137 tests: 133 passed, 1 capability skip (bc7_mode6_multiblock_hardware), 3 failed. The three failures are the rows already recorded for RDNA 4 (dxr_opacity_hardware, gpu_alias_lookup_writes_hardware, pixel_aot_comparisons_hardware, #958).

AI-assisted (Claude Code - Fable 5.2); runs executed locally on the adapter above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112590620 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/964#issuecomment-7112590620). Originally posted by [lantiumBot](https://github.com/lantiumBot) on 2026-11-23T20:07:16Z. --- First `_hardware` result for this draw, on RDNA 4. Data only. `pixel_aot_shift64_hardware` passed on an AMD Radeon RX 9060 XT, and `pixel_aot_shift64_warp` passed on in-box WARP, at merged `main`. ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_shift64_(hardware|warp)$' -V ``` - Commit: `f8e80e5663097c3ccc6fd35adbe4fba65e0fbf2e`, clean tree, `dev` preset (Debug) - Adapter: AMD Radeon RX 9060 XT (vendor=1002 device=7590), driver 32.0.32029.2010 - WARP: Microsoft Basic Render Driver (1414:008c), in-box, driver 10.0.26100.10068 - Windows build: 26300.10075, D3D12 debug layer unavailable - DXC 1.9.2602.17 (21d28f727) from Windows SDK 10.0.26100.0 One run per backend, 0 capability skips. The test prints no per-case lines on success, so this reports the CTest verdict only: the positive cases matched and the three mutated `v_ashrrev_i64` shaders mismatched as the fixture requires. For context, the full `ctest --preset dev --no-tests=error -R '_hardware$'` run at this commit gave 137 tests: 133 passed, 1 capability skip (`bc7_mode6_multiblock_hardware`), 3 failed. The three failures are the rows already recorded for RDNA 4 (`dxr_opacity_hardware`, `gpu_alias_lookup_writes_hardware`, `pixel_aot_comparisons_hardware`, #958). AI-assisted (Claude Code - Fable 5.2); runs executed locally on the adapter above.
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!957
No description provided.