pixel_aot: lower 32-bit bitwise, shift and integer conversion operations #229
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/232"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Vonsek on 2026-11-21T18:52:11Z.
Change
tools/pixel_aot.pynow translates these gfx1013 VALU operations instead of rejecting them:v_and_b32,v_or_b32,v_xor_b32,v_not_b32andv_bfi_b32v_lshlrev_b32,v_lshrrev_b32andv_ashrrev_i32, with the shift count masked to its low five bits as on the targetv_cvt_f32_u32andv_cvt_f32_i32v_cvt_u32_f32andv_cvt_i32_f32Registers stay
floatin the generated HLSL. The integer operations work onasuintof their operands and store the result withasfloat. 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,
f2uandf2i, 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_ubyte0andv_cvt_flr_i32_f32.Verification
tests/pixel_aot_check.pyaddsbits(), a source-built program that shifts sample bits by counts loaded from constants (including counts above 31), masks, inserts bits withv_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 bybits_case()are exact. The test compares all four channels of all 64 texels bitwise after round-toward-zero half export.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 thetools/pixel_aot.pychange it fails withUnsupported instruction 22: v_lshlrev_b32_e32 v18, s44, v12.asuint/asfloat, same helpers) matchesbits_case()on every texel for both constant sets.pixel_mismatch: lowering the overflow input to 2^31 in the saved reference, and replacingv_ashrrev_i32withv_lshrrev_b32.ctest --preset dev --no-tests=error -R '^pixel_aot_' -Vat534e0cf(rebased on maind311159, 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 ofbits(); it needed no changes.pixel_aot_hardwareon an NVIDIA GeForce RTX 5080 (driver 32.0.16.1692) andpixel_aot_warpon the Microsoft Basic Render Driver reportpixels=4096 channels=16384 max_absolute_error=0for every draw, and both negative controls report the expected mismatch. The D3D12 debug layer was not available. The fullctest --preset dev --no-tests=errorpassed 136/136, withbvh_wave64_hardware,bvh_wave64_warpandwave_shuffle_warpskipped.Evidence and follow-up
v_bfi_b32and the clamping float-to-integer conversions.v_or3_b32,v_and_or_b32,v_lshl_or_b32, bitfield extract, byte conversions and the floor and round-to-integer conversions.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.
4425fa2ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:28:25Z.
At
3ff19f2, Git reports conflicts inREADME.md,docs/experiments.mdandtests/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.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:27:45Z.
At
534e0cf, the merge conflicts are intests/pixel_aot_check.py. The docs and README now merge automatically. Please preserve the landed ceiling controls alongside the integer shifts and conversions.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_b32here have independent value. Can we land those first, with the masked-count and arithmetic-vs-logical shift draw controls, and run the combinedbits()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.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T07:55:28Z.
Commit
54c8a11narrows 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.