Lower reversed float subtract and vector moves in pixel shaders #143

Merged
bosseurdinternet merged 1 commit from upstream-pr/144 into main 2026-11-21 18:08:48 +00:00
bosseurdinternet commented 2026-11-21 17:05:01 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T17:05:01Z.


Change

Adds two instructions the offline gfx1013 pixel translator rejected. Rebased on #121, whose six operations and fixtures are unchanged.

  • v_subrev_f32 (src1 - src0), _e32 and _e64, with the existing clamp suffix.
  • v_mov_b32 for numeric values. A move copies a sample component, a loaded constant, an earlier result or an inline or literal constant, and emits one precise float statement. Integer inline constants stay bit patterns, as in the other operands. Moves of barycentrics, interpolated or partial coordinates, packed pairs or descriptor words are rejected, as are moves with a modifier, moves in whole-quad mode and reads before the required s_waitcnt.
  • A move into a register that an outstanding image_sample will still fill is rejected until s_waitcnt vmcnt(0).

The arithmetic() fixture uses v_add_f32 and v_mul_f32 from #121 next to the two new instructions.

Verification

  • python3 -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM-19.so on Linux with LLVM 19: passes, including the round trip of arithmetic() beside the shaping() and predicate fixtures already on main. pyflakes is clean on both Python files.
  • Controls for v_subrev_f32: operand order asserted on the generated HLSL, wrong arity rejected, and the render case's negative control replaces it with v_sub_f32.
  • Controls for v_mov_b32: non-numeric sources, a modifier, clamp, wrong arity, whole-quad mode, a sample read before vmcnt(0), a constant read before lgkmcnt(0), and a move into each of the four pending sample destinations are rejected. The same move into a free register, and into a sample destination after the wait, is accepted.
  • Operand order: llc 19 for gfx1013 selects v_subrev_f32_e32 v0, s0, v0 for v - s, and LLVM prints src0 first.
  • Manual mutants, not in CI: swapping the subrev template, removing the move's mask guard, letting the move accept any value, or disabling the pending-destination check each fail the tests.
  • The assembly (LLVM 15) and WARP draw checks run in CI; see the latest run on this PR. pixel_aot_hardware is not run: there is no D3D12 adapter on my machine.

Evidence and follow-up

  • The fixture is assembled from source in the test. No binaries were added.
  • The CPU reference rounds each step to binary32 and asserts that the rounding changes nothing for the bound 8×8 texture, so the expected colours do not depend on rounding direction or fusion. It assumes correctly rounded UNORM sampling, as the copy test does.
  • Out of scope, noticed while testing: the arithmetic branch does not reject a write to a pending sample destination either, half_rtz in the test is only correct for non-negative values (current callers pass none), and LLVM prints negated constants as neg(...), which the translator rejects.
  • Translation and bindings

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6531842813 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/144). Originally posted by [bosseurdinternet](https://github.com/bosseurdinternet) on 2026-11-21T17:05:01Z. --- ## Change Adds two instructions the offline gfx1013 pixel translator rejected. Rebased on #121, whose six operations and fixtures are unchanged. - `v_subrev_f32` (src1 - src0), `_e32` and `_e64`, with the existing `clamp` suffix. - `v_mov_b32` for numeric values. A move copies a sample component, a loaded constant, an earlier result or an inline or literal constant, and emits one `precise float` statement. Integer inline constants stay bit patterns, as in the other operands. Moves of barycentrics, interpolated or partial coordinates, packed pairs or descriptor words are rejected, as are moves with a modifier, moves in whole-quad mode and reads before the required `s_waitcnt`. - A move into a register that an outstanding `image_sample` will still fill is rejected until `s_waitcnt vmcnt(0)`. The `arithmetic()` fixture uses `v_add_f32` and `v_mul_f32` from #121 next to the two new instructions. ## Verification - `python3 -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy libLLVM-19.so` on Linux with LLVM 19: passes, including the round trip of `arithmetic()` beside the `shaping()` and predicate fixtures already on main. pyflakes is clean on both Python files. - Controls for `v_subrev_f32`: operand order asserted on the generated HLSL, wrong arity rejected, and the render case's negative control replaces it with `v_sub_f32`. - Controls for `v_mov_b32`: non-numeric sources, a modifier, `clamp`, wrong arity, whole-quad mode, a sample read before `vmcnt(0)`, a constant read before `lgkmcnt(0)`, and a move into each of the four pending sample destinations are rejected. The same move into a free register, and into a sample destination after the wait, is accepted. - Operand order: `llc` 19 for gfx1013 selects `v_subrev_f32_e32 v0, s0, v0` for `v - s`, and LLVM prints src0 first. - Manual mutants, not in CI: swapping the subrev template, removing the move's mask guard, letting the move accept any value, or disabling the pending-destination check each fail the tests. - The assembly (LLVM 15) and WARP draw checks run in CI; see the latest run on this PR. `pixel_aot_hardware` is not run: there is no D3D12 adapter on my machine. ## Evidence and follow-up - The fixture is assembled from source in the test. No binaries were added. - The CPU reference rounds each step to binary32 and asserts that the rounding changes nothing for the bound 8×8 texture, so the expected colours do not depend on rounding direction or fusion. It assumes correctly rounded UNORM sampling, as the copy test does. - Out of scope, noticed while testing: the arithmetic branch does not reject a write to a pending sample destination either, `half_rtz` in the test is only correct for non-negative values (current callers pass none), and LLVM prints negated constants as `neg(...)`, which the translator rejects. - [Translation and bindings](https://github.com/R0Y00/Xbox2Windows/blob/main/docs/experiments.md#offline-pixel-shader-recompilation) _AI-assisted (Claude Code)._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:41:32 +00:00
R0Y00 commented 2026-11-24 06:47:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:17:58Z.


Please rebase on #121 once it lands and keep v_subrev and v_mov with their own controls. For v_mov, cover writing to a register whose prior texture sample is still pending so that the emitted dataflow remains valid.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066369844 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/144#issuecomment-7066369844). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T17:17:58Z. --- Please rebase on #121 once it lands and keep v_subrev and v_mov with their own controls. For v_mov, cover writing to a register whose prior texture sample is still pending so that the emitted dataflow remains valid.
bosseurdinternet commented 2026-11-24 06:47:42 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T17:31:26Z.


Thanks for the review. The v_mov point is addressed in 5cf9cb4, and the branch is rebased on c1a65f0.

Move into a pending sample destination. The translator now tracks the destination registers of each image_sample until s_waitcnt vmcnt(0) and rejects a v_mov_b32 into one of them with "Write overlaps an outstanding sample". Controls in check_controls, on the arithmetic() fixture:

  • a move into each of v12 to v15 before the wait is rejected;
  • the same move into a free register at that position is accepted, and the generated HLSL keeps the order sample, constant, first use of the sample;
  • the same move into v12 after the wait is accepted, and the later copy reads the moved constant.

Manual mutant, not in CI: with the new check disabled, check_controls fails on the first rejected move.

The arithmetic branch has the same gap for its destination register. I left it unchanged here to keep this PR to the two instructions; I can send it separately if you want it.

#121. I will rebase onto it once it lands and drop the two shared table entries. v_subrev_f32 and v_mov_b32 keep their own controls: operand order and text assertions, wrong arity, non-numeric sources, reads before either wait, whole-quad mode and the pending-destination cases above. The render case's negative control replaces v_subrev_f32 with v_sub_f32.

Verified here: tests/pixel_aot_check.py binary with LLVM 19 and pyflakes. The Windows draw is left to CI.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066545480 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/144#issuecomment-7066545480). Originally posted by [bosseurdinternet](https://github.com/bosseurdinternet) on 2026-11-21T17:31:26Z. --- Thanks for the review. The `v_mov` point is addressed in `5cf9cb4`, and the branch is rebased on `c1a65f0`. **Move into a pending sample destination.** The translator now tracks the destination registers of each `image_sample` until `s_waitcnt vmcnt(0)` and rejects a `v_mov_b32` into one of them with "Write overlaps an outstanding sample". Controls in `check_controls`, on the `arithmetic()` fixture: - a move into each of `v12` to `v15` before the wait is rejected; - the same move into a free register at that position is accepted, and the generated HLSL keeps the order sample, constant, first use of the sample; - the same move into `v12` after the wait is accepted, and the later copy reads the moved constant. Manual mutant, not in CI: with the new check disabled, `check_controls` fails on the first rejected move. The arithmetic branch has the same gap for its destination register. I left it unchanged here to keep this PR to the two instructions; I can send it separately if you want it. **#121.** I will rebase onto it once it lands and drop the two shared table entries. `v_subrev_f32` and `v_mov_b32` keep their own controls: operand order and text assertions, wrong arity, non-numeric sources, reads before either wait, whole-quad mode and the pending-destination cases above. The render case's negative control replaces `v_subrev_f32` with `v_sub_f32`. Verified here: `tests/pixel_aot_check.py binary` with LLVM 19 and pyflakes. The Windows draw is left to CI. _AI-assisted (Claude Code)._
R0Y00 commented 2026-11-24 06:47:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T17:58:50Z.


Thanks for covering pending sample destinations. #121 has now landed, and GitHub reports a merge conflict on 420f14b. Please reconcile the pixel lowering and fixture lists with #121, retaining its six arithmetic operations as well as your v_subrev/v_mov controls and the predicate fixtures already on main. Then rerun the assembly and WARP checks.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066910605 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/144#issuecomment-7066910605). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T17:58:50Z. --- Thanks for covering pending sample destinations. #121 has now landed, and GitHub reports a merge conflict on 420f14b. Please reconcile the pixel lowering and fixture lists with #121, retaining its six arithmetic operations as well as your v_subrev/v_mov controls and the predicate fixtures already on main. Then rerun the assembly and WARP checks.
bosseurdinternet commented 2026-11-24 06:47:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by bosseurdinternet on 2026-11-21T18:03:46Z.


Reconciled with #121 at 7e97af3, rebased on ccfa703.

  • Lowering. The ALU table and the arithmetic pattern keep #121's six operations unchanged. This PR now adds only the subrev entry, |subrev in the pattern, the v_mov_b32 branch and the pending-destination tracking. The duplicate add and mul entries are gone.
  • Fixture lists. arithmetic() is added beside shaping() in the exp-spelling loop and in check_binary, where the four predicate groups and the dual-texture fixtures are unchanged. In check_render the arithmetic block runs before the existing curve/shaping loop, which is unchanged.
  • Controls. The v_subrev_f32 and v_mov_b32 controls are as before, including the four pending sample destinations.

Checks at 7e97af3:

  • Assembly, Ubuntu job with LLVM 15: passed. Locally with LLVM 19: tests/pixel_aot_check.py binary passed.
  • WARP, Windows job: pixel_aot_warp passed, 77 of 77 tests passed.

The two commits are squashed into one, and the title and description now describe only v_subrev_f32 and v_mov_b32.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7066972266 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/144#issuecomment-7066972266). Originally posted by [bosseurdinternet](https://github.com/bosseurdinternet) on 2026-11-21T18:03:46Z. --- Reconciled with #121 at `7e97af3`, rebased on `ccfa703`. - **Lowering.** The `ALU` table and the arithmetic pattern keep #121's six operations unchanged. This PR now adds only the `subrev` entry, `|subrev` in the pattern, the `v_mov_b32` branch and the pending-destination tracking. The duplicate `add` and `mul` entries are gone. - **Fixture lists.** `arithmetic()` is added beside `shaping()` in the exp-spelling loop and in `check_binary`, where the four predicate groups and the dual-texture fixtures are unchanged. In `check_render` the arithmetic block runs before the existing `curve`/`shaping` loop, which is unchanged. - **Controls.** The `v_subrev_f32` and `v_mov_b32` controls are as before, including the four pending sample destinations. Checks at `7e97af3`: - Assembly, Ubuntu job with LLVM 15: passed. Locally with LLVM 19: `tests/pixel_aot_check.py binary` passed. - WARP, Windows job: `pixel_aot_warp` passed, 77 of 77 tests passed. The two commits are squashed into one, and the title and description now describe only `v_subrev_f32` and `v_mov_b32`. _AI-assisted (Claude Code)._
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!143
No description provided.