shader: lower gfx1013 32-bit bit-scan and bit-reverse ops in pixel_aot #541
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!541
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/541/head"
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?
@alexander-src on GitHub · 2026-11-22 10:10 UTC · original
alexander-src:shader/bit-scan-reverse-pixel-aot→main· +218 −1 · 5 files · 1 commits · closed without mergingChange
Lower gfx1013 32-bit vector bit-reverse and bit-scan instructions in
tools/pixel_aot.py, covering both VOP1 (_e32) and VOP3 (_e64) encodings (+8 forms in bothgfx1013.tsvandrdna2.tsv):v_bfrev_b32(_e32,_e64) via HLSLreversebits.v_ffbl_b32(_e32,_e64) via HLSLfirstbitlow.v_ffbh_u32(_e32,_e64) via lazy helperffbh_u32, converting HLSL's LSB-indexedfirstbithighposition to RDNA 2's MSB-indexed count (31u - firstbithigh(value), returning0xffffffffuon0).v_ffbh_i32(_e32,_e64) via lazy helperffbh_i32, inverting negative inputs before applying31u - firstbithigh(mask)so all-zero and all-one inputs return0xffffffffuand0x80000000/0x7fffffffreturn1.All four entries sit in
INTEGERwith lazySALU_HELPERSemission, so existing shaders stay byte-identical andv256+, float source modifiers,clamp, SDWA forms, WQM blocks and pending-load or pending-sample hazards are rejected. Added LLVM assemble/disassemble round-trip coverage, batched draw tests (--check-pixel-batch) across five constant sets with six wrong-mode references and a mutated-shader control (v_ffbh_i32_e32->v_ffbh_u32_e32), form-coverage assertions intests/form_coverage_check.py, and documentation indocs/experiments.md.Verification
Tested on Linux x64 at commit
6ca999c(based on914d241) with Python 3 (requirements-dev.txtinstalled) and LLVM 23.1.4 (llvm-mc,llvm-objcopy,/usr/lib/libLLVM.so):python -B tests/pixel_aot_check.py binary llvm-mc llvm-objcopy /usr/lib/libLLVM.so: passed.python -B tests/form_coverage_check.py: passed (verifies all 8VOP1/VOP3forms ingfx1013.tsvandrdna2.tsv).python -B tests/pso_readiness_check.py: passed.LLVM_LIB=/usr/lib/libLLVM.so LLVM_MC=llvm-mc LLVM_OBJCOPY=llvm-objcopy python -B tests/rdna2_tools_check.py: passed (33 tests, OK).python -B tests/docs_links_check.py: passed (10 Markdown files, 112 links).python -B tests/bidi_controls_check.py: passed (506 tracked files).ffbh_u32andffbh_i32against the AMD RDNA 2 ISA bit-scan loops across 100,139 inputs (all power-of-two, mask, sign-boundary and random 32-bit values): 0 mismatches.Could not run DXC / D3D12 WARP or hardware draws locally on Linux (missing Windows SDK, DXC and D3D12 runtime); Windows CI runs
pixel_aot_blend_scalar_warpandpixel_aot_blend_scalar_hardware.Evidence and follow-up
All fixtures are synthetic gfx1013 assembly programs written directly in
tests/pixel_aot_check.py(MIT). Because HLSL SM 6.0firstbithighreturns an LSB-based bit index (0..31) whereas RDNA 2v_ffbh_u32andv_ffbh_i32count from the MSB (0at bit 31,31at bit 0), the wrong-mode draw controls explicitly assert that LSB-indexed or unsigned-for-signed behavior mismatches. Follow-up work can lowerv_bcnt_u32_b32and scalars_ff0/s_ff1/s_flbitforms.Checklist
AI-assisted: yes.
@roansystemlabs on GitHub · 2026-11-22 13:22 UTC · original
Windows hardware run for this PR, since the description notes the DXC / D3D12 draws could not run on Linux.
Commit:
6d03c5c(PR head), built with thedevpreset (MSVC 19.44, Windows SDK 10.0.26100 DXC).pixel_aot_blend_scalar_hardware/_warprdna2_tools_checkAll 44 renderer launches per adapter report
debug_layer=enabled,debug_errors=0 debug_warnings=0andmax_absolute_error=0.python -B tests/form_coverage_check.pyandtests/docs_links_check.pyalso pass on Windows.Negative controls (local edits to
tools/pixel_aot.py, reverted afterwards; the bit-scan batch fails on both adapters each time):ffbh_u32helper returnsfirstbithigh(value)(no31u -)status=mismatch, and theffbh_u32_lsbwrong-mode reference now passesffbh_i32helper drops the sign inversion (mask = value)ffbh_i32_unsignedwrong-mode reference now passesSo the
31u - firstbithighconversion and the signed inversion are load-bearing on NVIDIA hardware as well as on WARP, and each mutation lands exactly on the wrong-mode reference written for it. Unmodified, the RTX 3070 output matches the RDNA 2 references for all five sets, including the zero →0xffffffffcases.Environment: Windows 11 build 26200.9974, NVIDIA GeForce RTX 3070 (10de:2484), driver 32.0.16.2101, D3D12 debug layer on (Graphics Tools); WARP 10.0.26100.9818.
Not tested: AMD or Intel hardware, the LLVM binary round-trip (
pixel_aot_check.py binary, no LLVM on this machine), the/O2release preset, and the full suite.AI-assisted: prepared with an AI coding agent and reviewed by a human before posting.
@alexander-src on GitHub · 2026-11-22 15:10 UTC · original
Thanks @roansystemlabs for running the RTX 3070 and WARP verification along with the helper mutation checks. Rebased onto
main(c8a3fd9->317aa0a) after #542 merged to clear thepixel_aot.py/pixel_aot_check.py/form_coverage_check.pyconflicts, and re-verified all six Linux + LLVM checks locally.AI-assisted: yes
@MarlomMedeiros on GitHub · 2026-11-22 17:56 UTC · original
AI-assisted: yes. All reported checks ran locally on the adapter and driver listed.
@alexander-src on GitHub · 2026-11-22 18:31 UTC · original
Thanks @MarlomMedeiros for running the RTX 5070 and WARP checks and flagging the drift against main. Rebased onto
719552e(317aa0a ->45185c0) to clear the conflicts in tests/form_coverage_check.py and tests/pixel_aot_check.py, and re-ran pixel_aot_check.py binary, form_coverage_check.py, pso_readiness_check.py, rdna2_tools_check.py (49 passed, 1 skipped), docs_links_check.py, and bidi_controls_check.py locally.AI-assisted: yes
@rwZephyr on GitHub · 2026-11-22 18:56 UTC · original
Independent Windows 10 retest of the rebased head
45185c0cd8c165682ecd791b9e12e027aa32f5e2. Windows 10 22H2 build19045.6466, MSVC19.44.35230, Windows SDK10.0.26100.0, DXC1.8.2502.11. The Debug build used/MTd. D3D12 debug layer unavailable on both backends.10de:2414), driver621.24(32.0.16.2124via DXGI). Passed.1414:008c), driver10.0.19041.5794. Passed.I also called
check_bit_scan_drawsdirectly on both backends. All five input sets and the repeated first set matched all 4,096 pixels per draw with zero absolute error. The first reference RGBA value was(235, 85, 119, 17). All six wrong-reference cases and the signed-to-unsigned shader mutation produced the expectedpixel_mismatchat(0, 0)on both backends.The base translator at
719552erejected the same program atv_bfrev_b32_e32, before rendering.AI-assisted. All reported tests ran locally.
@R0Y00 on GitHub · 2026-11-23 03:22 UTC · original · edited 2026-11-23 03:24 UTC
Thanks for the bit-scan reference and the independent Windows retest. Main now has all four forms in both encodings through #755, with separate integer-readback CTests, LLVM 15 assembly and independent expected words. #735 was closed after that scope and the #728
v_xnor_b32form were confirmed. The work here covers the same implementation, so I’m closing the overlapping PR.@MarlomMedeiros on GitHub · 2026-11-22 17:54 UTC · original · reviewed
Community review + independent run, since the PR notes DXC/D3D12/WARP could not run on the authoring Linux host.
Environment
317aa0aon basec8a3fd9ctest --preset dev --no-tests=error -R '^pixel_aot_blend_scalar_(warp|hardware)$' -V: both passeddebug_errors=0 debug_warnings=0, all drawspixels=4096 max_absolute_error=0tests/pixel_aot_check.pycontrols,tests/form_coverage_check.pyand the LLVM 15.0.7 binary round-trip all pass on this commitReview notes
v_bfrev_b32->reversebits,v_ffbl_b32->firstbitlowmap directly onto HLSL intrinsics;firstbitlowreturning -1 as uint is bit-identical to the ISA's 0xffffffff-on-zero.ffbh_u32=31 - firstbithighgives the MSB-side bit position, with the zero case returning 0xffffffff.ffbh_i32complements on sign before scanning, so all-sign patterns (0, 0xffffffff) correctly return -1 and the position counts from the MSB as the ISA defines. Both helpers are only emitted when used, verified by the leakage assert.pixel_aot_blend_scalar_*fixtures; the six reference modes (lsb positions, unsigned-vs-signed ffbh, zero input, ffbl-as-ffbh distinction, bfrev self-inverse) pin the exact semantics that matter.c8a3fd9is a few commits behind currentmain(8f57366), so a rebase may be requested; the touched areas look quiet enough that conflicts should be small.No blockers found.
Pull request closed