shader: lower s_brev_b32 in pixel_aot #758

Merged
JB2WIN merged 2 commits from upstream-pr/764 into main 2026-11-23 02:41:07 +00:00
JB2WIN commented 2026-11-23 01:32:05 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T01:32:05Z.


Change

tools/pixel_aot.py now lowers SOP1 s_brev_b32 sD, S0 through the SCALAR table as reversebits(S0), without an SCC write. This follows the documented s_brev_b64 convention ("preserve SCC") and its existing reversebits lowering. The scanner and PSO-readiness checks pick the form up from the table.

  • Changed expectation. check_controls listed s_brev_b32 s62, s44 among the neighbouring forms the lowerer does not implement. That form is now supported, so the probe is now s_brev_b32 s62, v12, which is still refused because the source is a VGPR. Positive coverage is in the new tests.
  • Rejected: a VGPR source or destination, wrong operand counts, s106, pair operands, untracked SGPRs, and reads or writes of pending scalar loads.

AI-assisted (Claude Code).

Verification

Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, with the D3D12 debug layer enabled. Head is rebased on current main.

  • New draw draw-brev (pixel_aot_brev_{hardware,warp}):
    • The program runs s_cmp_eq_u32 s44, s45, then s_brev_b32 on a register and on a literal, then s_cselect_b32 on that SCC, then a second s_brev_b32.
    • The select lane shows that SCC survives the reversals. A static check confirms that only the compare writes SCC.
    • Seven word sets cover 0, 0xffffffff, 0x80000000, 1, 0xaaaaaaaa, 0x12345678 and 0x55555555, with both SCC outcomes. Readback is full width against an independent Python bit loop.
  • Mutations. Each must report a mismatch, and each does:
    • reversebits replaced by a complement;
    • an SCC-writing s_not_b32 inserted before the select, which is caught only by the select lane;
    • the instruction itself replaced by s_not_b32.
  • Dev-time checks (not committed):
    • With the table entry removed, the controls fail.
    • With NONZERO as the SCC expression, the static SCC check fails.
  • Commands:
    • ctest --preset dev --no-tests=error -R "^pixel_aot_brev_": 2/2 passed (4.5 s hardware, 1.6 s WARP)
    • Full ctest --preset dev --no-tests=error: 333/333 passed, skips bvh_wave64_hardware, bvh_wave64_warp, wave_shuffle_warp (same as on main)
    • tests/pixel_aot_check.py binary with LLVM 15.0.7: exit 0. This ran locally, with llvm-mc through a clang -cc1as shim.
    • The controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py pass.
  • Semantics source: the project's s_brev_b64 convention and lowering. I could not check against the RDNA 2 ISA PDF.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6550439992 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/764). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T01:32:05Z. --- ## Change `tools/pixel_aot.py` now lowers SOP1 `s_brev_b32 sD, S0` through the `SCALAR` table as `reversebits(S0)`, without an SCC write. This follows the documented `s_brev_b64` convention ("preserve SCC") and its existing `reversebits` lowering. The scanner and PSO-readiness checks pick the form up from the table. - **Changed expectation.** `check_controls` listed `s_brev_b32 s62, s44` among the neighbouring forms the lowerer does not implement. That form is now supported, so the probe is now `s_brev_b32 s62, v12`, which is still refused because the source is a VGPR. Positive coverage is in the new tests. - **Rejected:** a VGPR source or destination, wrong operand counts, `s106`, pair operands, untracked SGPRs, and reads or writes of pending scalar loads. AI-assisted (Claude Code). ## Verification Environment: Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, with the D3D12 debug layer enabled. Head is rebased on current `main`. - **New draw `draw-brev`** (`pixel_aot_brev_{hardware,warp}`): - The program runs `s_cmp_eq_u32 s44, s45`, then `s_brev_b32` on a register and on a literal, then `s_cselect_b32` on that SCC, then a second `s_brev_b32`. - The select lane shows that SCC survives the reversals. A static check confirms that only the compare writes SCC. - Seven word sets cover `0`, `0xffffffff`, `0x80000000`, `1`, `0xaaaaaaaa`, `0x12345678` and `0x55555555`, with both SCC outcomes. Readback is full width against an independent Python bit loop. - **Mutations.** Each must report a mismatch, and each does: - `reversebits` replaced by a complement; - an SCC-writing `s_not_b32` inserted before the select, which is caught only by the select lane; - the instruction itself replaced by `s_not_b32`. - **Dev-time checks (not committed):** - With the table entry removed, the controls fail. - With `NONZERO` as the SCC expression, the static SCC check fails. - **Commands:** - `ctest --preset dev --no-tests=error -R "^pixel_aot_brev_"`: 2/2 passed (4.5 s hardware, 1.6 s WARP) - Full `ctest --preset dev --no-tests=error`: 333/333 passed, skips `bvh_wave64_hardware`, `bvh_wave64_warp`, `wave_shuffle_warp` (same as on `main`) - `tests/pixel_aot_check.py binary` with LLVM 15.0.7: exit 0. This ran locally, with `llvm-mc` through a `clang -cc1as` shim. - The controls, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` pass. - **Semantics source:** the project's `s_brev_b64` convention and lowering. I could not check against the RDNA 2 ISA PDF. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:41 +00:00
JB2WIN commented 2026-11-24 06:48:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T02:36:19Z.


Semantics source: LLVM 15.0.7 SOPInstructions.td defines S_BREV_B32 with the pattern (set i32:$sdst, (UniformUnaryFrag<bitreverse> i32:$src0)). It sits outside every let Defs = [SCC] block, and S_NOT_B32/S_WQM_B32 are inside one (L209-219). So LLVM treats s_brev_b32 as a bit reverse that does not write SCC, which is what this PR lowers and what the select lane checks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7090068808 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/764#issuecomment-7090068808). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T02:36:19Z. --- Semantics source: LLVM 15.0.7 [`SOPInstructions.td`](https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/llvm/lib/Target/AMDGPU/SOPInstructions.td#L236-L243) defines `S_BREV_B32` with the pattern `(set i32:$sdst, (UniformUnaryFrag<bitreverse> i32:$src0))`. It sits outside every `let Defs = [SCC]` block, and `S_NOT_B32`/`S_WQM_B32` are inside one (L209-219). So LLVM treats `s_brev_b32` as a bit reverse that does not write SCC, which is what this PR lowers and what the select lane checks.
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!758
No description provided.