pixel_aot: lower 32-bit bitwise, shift and integer conversion operations #229

Merged
Vonsek merged 2 commits from upstream-pr/232 into main 2026-11-22 07:59:52 +00:00
Vonsek commented 2026-11-21 18:52:11 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T18:52:11Z.


Change

tools/pixel_aot.py now translates these gfx1013 VALU operations instead of rejecting them:

  • v_and_b32, v_or_b32, v_xor_b32, v_not_b32 and v_bfi_b32
  • v_lshlrev_b32, v_lshrrev_b32 and v_ashrrev_i32, with the shift count masked to its low five bits as on the target
  • v_cvt_f32_u32 and v_cvt_f32_i32
  • v_cvt_u32_f32 and v_cvt_i32_f32

Registers stay float in the generated HLSL. The integer operations work on asuint of their operands and store the result with asfloat. Integer inline constants are used as values and float inline constants as their binary32 patterns, matching the hardware encoding. The integer operations reject source modifiers and clamp.

The float-to-integer conversions call two small helpers, f2u and f2i, added to the shader preamble. They truncate, return 0 for NaN and saturate at the type limits. A plain HLSL cast leaves NaN and out-of-range inputs undefined, so the helpers make the target behavior explicit. The float source of these conversions accepts the usual - and |x| modifiers.

Other integer forms stay unsupported and are tested as rejected: v_add_nc_u32, v_or3_b32, v_bfe_u32, v_cvt_f32_ubyte0 and v_cvt_flr_i32_f32.

Verification

tests/pixel_aot_check.py adds bits(), a source-built program that shifts sample bits by counts loaded from constants (including counts above 31), masks, inserts bits with v_bfi_b32, applies an arithmetic shift after setting the sign bit, inverts, converts scaled samples, a NaN and an overflowing constant to integers, and converts back to float scaled by powers of two. Every integer converted to float is below 2^24, so the expected colors computed by bits_case() are exact. The test compares all four channels of all 64 texels bitwise after round-toward-zero half export.

  • Controls: generated HLSL and operand encodings for each operation; rejection of modifiers and clamp on integer operations, wrong operand counts, the neighboring unsupported forms, reads before the waits, writes into pending sample registers, and whole-quad mode.
  • Binary (Linux, LLVM 18): tests/pixel_aot_check.py binary ... passes; the program is assembled for gfx1013, wrapped in a synthetic record, extracted, disassembled and lowered, and equals lowering the source text. Without the tools/pixel_aot.py change it fails with Unsupported instruction 22: v_lshlrev_b32_e32 v18, s44, v12.
  • Reference cross-check: the generated shader body compiled as C (bit casts for asuint/asfloat, same helpers) matches bits_case() on every texel for both constant sets.
  • Draw: two constant sets, (shift counts 36 and 20, quiet NaN, 2^33) and (35 and 21, negative NaN with payload, +infinity). Two negative controls must report pixel_mismatch: lowering the overflow input to 2^31 in the saved reference, and replacing v_ashrrev_i32 with v_lshrrev_b32.
  • Windows: ctest --preset dev --no-tests=error -R '^pixel_aot_' -V at 534e0cf (rebased on main d311159, beside #258's truncation draw; earlier runs gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 2/2 passed. This is the first DXC compile and D3D12 draw of bits(); it needed no changes. pixel_aot_hardware on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and pixel_aot_warp on the Microsoft Basic Render Driver report pixels=4096 channels=16384 max_absolute_error=0 for every draw, and both negative controls report the expected mismatch. The D3D12 debug layer was not available. The full ctest --preset dev --no-tests=error passed 136/136, with bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp skipped.

Evidence and follow-up

  • AMD RDNA instruction reference for the operand order of the reversed shifts, v_bfi_b32 and the clamping float-to-integer conversions.
  • The draw reference assumes correctly rounded UNORM sampling and exact power-of-two multiplication, as the existing select program does. Integer-to-float rounding above 2^24 is not measured.
  • Not included: integer add and subtract with carry, v_or3_b32, v_and_or_b32, v_lshl_or_b32, bitfield extract, byte conversions and the floor and round-to-integer conversions.
  • This touches the same ALU table as #169; whichever merges second needs a small rebase.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6532993464 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/232). Originally posted by [Vonsek](https://github.com/Vonsek) on 2026-11-21T18:52:11Z. --- ## Change `tools/pixel_aot.py` now translates these gfx1013 VALU operations instead of rejecting them: - `v_and_b32`, `v_or_b32`, `v_xor_b32`, `v_not_b32` and `v_bfi_b32` - `v_lshlrev_b32`, `v_lshrrev_b32` and `v_ashrrev_i32`, with the shift count masked to its low five bits as on the target - `v_cvt_f32_u32` and `v_cvt_f32_i32` - `v_cvt_u32_f32` and `v_cvt_i32_f32` Registers stay `float` in the generated HLSL. The integer operations work on `asuint` of their operands and store the result with `asfloat`. Integer inline constants are used as values and float inline constants as their binary32 patterns, matching the hardware encoding. The integer operations reject source modifiers and clamp. The float-to-integer conversions call two small helpers, `f2u` and `f2i`, added to the shader preamble. They truncate, return 0 for NaN and saturate at the type limits. A plain HLSL cast leaves NaN and out-of-range inputs undefined, so the helpers make the target behavior explicit. The float source of these conversions accepts the usual `-` and `|x|` modifiers. Other integer forms stay unsupported and are tested as rejected: `v_add_nc_u32`, `v_or3_b32`, `v_bfe_u32`, `v_cvt_f32_ubyte0` and `v_cvt_flr_i32_f32`. ## Verification `tests/pixel_aot_check.py` adds `bits()`, a source-built program that shifts sample bits by counts loaded from constants (including counts above 31), masks, inserts bits with `v_bfi_b32`, applies an arithmetic shift after setting the sign bit, inverts, converts scaled samples, a NaN and an overflowing constant to integers, and converts back to float scaled by powers of two. Every integer converted to float is below 2^24, so the expected colors computed by `bits_case()` are exact. The test compares all four channels of all 64 texels bitwise after round-toward-zero half export. - Controls: generated HLSL and operand encodings for each operation; rejection of modifiers and clamp on integer operations, wrong operand counts, the neighboring unsupported forms, reads before the waits, writes into pending sample registers, and whole-quad mode. - Binary (Linux, LLVM 18): `tests/pixel_aot_check.py binary ...` passes; the program is assembled for gfx1013, wrapped in a synthetic record, extracted, disassembled and lowered, and equals lowering the source text. Without the `tools/pixel_aot.py` change it fails with `Unsupported instruction 22: v_lshlrev_b32_e32 v18, s44, v12`. - Reference cross-check: the generated shader body compiled as C (bit casts for `asuint`/`asfloat`, same helpers) matches `bits_case()` on every texel for both constant sets. - Draw: two constant sets, (shift counts 36 and 20, quiet NaN, 2^33) and (35 and 21, negative NaN with payload, +infinity). Two negative controls must report `pixel_mismatch`: lowering the overflow input to 2^31 in the saved reference, and replacing `v_ashrrev_i32` with `v_lshrrev_b32`. - Windows: `ctest --preset dev --no-tests=error -R '^pixel_aot_' -V` at 534e0cf (rebased on main d311159, beside #258's truncation draw; earlier runs gave the same result) on Windows 11 build 26200.9974, VS Build Tools 2022 17.14 (MSVC 14.44.35207), Windows SDK 10.0.26100, DXC 1.9.2602.17: 2/2 passed. This is the first DXC compile and D3D12 draw of `bits()`; it needed no changes. `pixel_aot_hardware` on an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) and `pixel_aot_warp` on the Microsoft Basic Render Driver report `pixels=4096 channels=16384 max_absolute_error=0` for every draw, and both negative controls report the expected mismatch. The D3D12 debug layer was not available. The full `ctest --preset dev --no-tests=error` passed 136/136, with `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp` skipped. ## Evidence and follow-up - [AMD RDNA instruction reference](https://gpuopen.com/wp-content/uploads/2019/08/RDNA_Shader_ISA_5August2019.pdf) for the operand order of the reversed shifts, `v_bfi_b32` and the clamping float-to-integer conversions. - The draw reference assumes correctly rounded UNORM sampling and exact power-of-two multiplication, as the existing select program does. Integer-to-float rounding above 2^24 is not measured. - Not included: integer add and subtract with carry, `v_or3_b32`, `v_and_or_b32`, `v_lshl_or_b32`, bitfield extract, byte conversions and the floor and round-to-integer conversions. - This touches the same ALU table as #169; whichever merges second needs a small rebase.
upstream-sync closed this pull request 2026-11-24 06:41:56 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:47:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-21T19:17:01Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-21T19:22:47.475656Z 4425fa2 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7067906872 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/232#issuecomment-7067906872). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-21T19:17:01Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"4425fa23231738836a66eaea1322a5cc92448271","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-21T19:22:47.475656Z">2026-11-21T19:22:47.475656Z</relative-time> | `4425fa2` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
R0Y00 commented 2026-11-24 06:47:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:28:25Z.


At 3ff19f2, Git reports conflicts in README.md, docs/experiments.md and tests/pixel_aot_check.py. The translator itself merges automatically. Please retain #273's pending-write and #277's scalar-load controls alongside the integer conversion and shift cases, then rerun the shared pixel suite.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7068777337 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/232#issuecomment-7068777337). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T20:28:25Z. --- At `3ff19f2`, Git reports conflicts in `README.md`, `docs/experiments.md` and `tests/pixel_aot_check.py`. The translator itself merges automatically. Please retain #273's pending-write and #277's scalar-load controls alongside the integer conversion and shift cases, then rerun the shared pixel suite.
R0Y00 commented 2026-11-24 06:48:02 +00:00 (Migrated from github.com)

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


At 534e0cf, the merge conflicts are in tests/pixel_aot_check.py. The docs and README now merge automatically. Please preserve the landed ceiling controls alongside the integer shifts and conversions.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7069490385 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/232#issuecomment-7069490385). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-21T21:27:45Z. --- At `534e0cf`, the merge conflicts are in `tests/pixel_aot_check.py`. The docs and README now merge automatically. Please preserve the landed ceiling controls alongside the integer shifts and conversions.
R0Y00 commented 2026-11-24 06:48:26 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T06:40:31Z.


While integrating this with #169 I found a behavioral overlap with #360. This branch accepts source modifiers on the float-to-integer conversions, while #438 has explicit rejection controls for those e64 forms. #392 also covers the forward conversions with inexact rounding rows. The shifts, bitwise operations and v_bfi_b32 here have independent value. Can we land those first, with the masked-count and arithmetic-vs-logical shift draw controls, and run the combined bits() fixture once the conversion stack lands? That would preserve both sets of evidence and avoid making a later rebase silently change which instructions are accepted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7075463498 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/232#issuecomment-7075463498). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T06:40:31Z. --- While integrating this with #169 I found a behavioral overlap with #360. This branch accepts source modifiers on the float-to-integer conversions, while #438 has explicit rejection controls for those e64 forms. #392 also covers the forward conversions with inexact rounding rows. The shifts, bitwise operations and `v_bfi_b32` here have independent value. Can we land those first, with the masked-count and arithmetic-vs-logical shift draw controls, and run the combined `bits()` fixture once the conversion stack lands? That would preserve both sets of evidence and avoid making a later rebase silently change which instructions are accepted.
R0Y00 commented 2026-11-24 06:48:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T07:55:28Z.


Commit 54c8a11 narrows this candidate to bitwise operations and masked shifts. The draw suite passed on WARP and hardware. The e32 conversion coverage stays with the conversion PRs. A separate e64 abs/neg change can extend the input domain once LLVM 15 assembly and disassembly confirm the encoding and bit-level controls cover signed zero, NaN, infinities and saturation boundaries.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7076202492 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/232#issuecomment-7076202492). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T07:55:28Z. --- Commit 54c8a11 narrows this candidate to bitwise operations and masked shifts. The draw suite passed on WARP and hardware. The e32 conversion coverage stays with the conversion PRs. A separate e64 abs/neg change can extend the input domain once LLVM 15 assembly and disassembly confirm the encoding and bit-level controls cover signed zero, NaN, infinities and saturation boundaries.
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!229
No description provided.