shader: lower vector bitfield, population count and bit scans #430
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/436"
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 Joacoorandom on 2026-11-22T02:51:20Z.
Change
The pixel translator currently rejects vector bitfield extraction/masks, population counts, bit reversal and bit scans. Add twelve instruction forms covering
v_bfe_u32,v_bfe_i32,v_bfm_b32,v_bcnt_u32_b32, and e32/e64v_bfrev_b32,v_ffbh_u32,v_ffbh_i32,v_ffbl_b32.Preserve raw VGPR bits through HLSL, mask offsets and widths to five bits, handle signed extracts crossing bit 31, wrapping population-count addition and the all-zero/all-sign-bit scan sentinel. Pending loads/samples, entry execution-mask restrictions and unsupported modifiers remain guarded.
This touches
tools/pixel_aot.py:lowerand its helper selection. No prerequisite PR. #329's SDWA work also touches the pixel translator, but SDWA/DPP variants are outside this change.Verification
Latest integration:
f3aeede, merging upstreamf8d11adwhile retaining the existing PR headf85b327. Resolved README, experiment notes, coverage checks, binary-fixture registration, draw dispatch and HLSL helper selection. The current main draw-core/other draw modes, DPP fixtures and float-to-int helpers are retained.On this integration, the LLVM 18 binary round trip,
tests/form_coverage_check.py,tests/docs_links_check.py,tests/bidi_controls_check.pyandgit diff --checkpassed. The focused vector-bit matrix also passed on native Windows WARP 10.0.26100.9818: 192 positive draws, twelve wrong-reference controls, zero pixel error and no skips (debug layer unavailable). This check used the merged Python translator/test and helper include with the previously built renderer; it was not a full rebuild of current main.Exact focused native command:
The results below are historical measurements of the indicated earlier commits; the new integration starts fresh CI.
Commit
8e3158c, based on upstream73ed4b7. Includes the newly merged #322 capability-skip fix. Windows 11 build 26300.9974, MSVC/ML64 19.44.35230, Windows SDK 10.0.26100 DXC, Python 3.12.8.After rebasing, rebuilt the renderer and passed both selected WARP tests:
On the pre-rebase implementation
9373f17(base6ee2406), ran:Both new tests passed: NVIDIA GeForce RTX 3060 (10de:2503), driver 32.0.16.2101, in 113.72 seconds; WARP 10.0.26100.9818 in 8.46 seconds. Each backend checked 192 positive draws and twelve deliberately wrong references. Zero pixel error; no capability skips. The debug layer was unavailable. Hardware has not been rerun after rebasing.
Linux checks passed on the rebased commit:
LLVM 18 assembled/disassembled all twelve gfx1013 forms and binary-derived HLSL matched source lowering. Coverage checks require exactly twelve added forms in each GPU reference list and refuse coverage from failed or skipped tests.
The legacy
pixel_aot_hardwarereached its separate 60-second timeout during earlier validation. It is not counted as a pass or capability skip. The original serial new-test matrix exceeded 180 seconds; four independent renderer workers, separate case files and per-process deadlines completed the same matrix within the budget. Full-suite success is not claimed.Evidence and follow-up
The source-built assembly fixtures, translator changes and independent Python bit-loop reference are original MIT code. Sixteen input sets cover offset/width masking, signed boundaries, zero/all-one values, scan sentinels and population-count wraparound. Every 32-bit result is exported as four exact byte-valued channels; all twelve wrong references must report a pixel mismatch. Acceptance-only checks do not add forms to unrelated draw records.
README and
docs/experiments.mddocument the supported forms, limits and reproduction commands. No proprietary binaries or prototype apps are included.AI-assisted implementation and tests.
Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-22T19:48:24Z.
Hardware run of the current head, since the description notes hardware was not rerun after the rebase and the integration was not a full rebuild.
Commit:
f3aeede(PR head), fresh configure and full build with thedevpreset (MSVC 19.44, DXC 1.9.2602.17 from Windows SDK 10.0.26100).pixel_aot_bits_hardware/_warpEach adapter reports 12 ×
cases=16 matched, withdebug_layer=enabled debug_errors=0 debug_warnings=0andmax_absolute_error=0on every printed draw, and the wrong-byte control is caught for every form.pixel_aot_hardware(41.3 s) andpixel_aot_warp(8.1 s) also pass.tests/form_coverage_check.pypasses.Full suite:
ctest --preset dev --no-tests=errorgives 278/278, with the usual four capability skips (bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp,cpu_aot_crypto_sha).Timing note: the GPU was not fully idle. Other processes used 0–6 % of the GPU and about 5.5 GB of 8 GB VRAM, and another D3D12 test process ran at the same time for part of the session. The pass/fail results do not depend on this. Treat the times as approximate.
Negative controls (local edits to
tools/pixel_aot.py, one at a time, reverted afterwards; both tests fail each time):v_bfe_i32helper uses a logical shift (dropsasint)v_bfe_i32(0xdeadbeef, 0x4, 0x8)v_ffbh_i32drops the sign inversionv_ffbh_i32_e32(0xffffffff, 0x0, 0x0)v_bcnt_u32_b32drops+ {1}v_bcnt_u32_b32(0x80000000, 0x1f, 0x1)v_ffbh_u32helper drops31u -v_ffbh_u32_e32(0xffffffff, 0x0, 0x0)Overlap with #541. #541 (head
45185c0) also lowersv_bfrev_b32,v_ffbh_u32andv_ffbh_i32(e32/e64), with its ownffbh_u32/ffbh_i32helpers. The two branches merge without textual conflicts. I merged #541 intof3aeedelocally and rebuilt:pixel_aot_bits_*,pixel_aot_blend_scalar_*,pixel_aot_hardware/_warp,rdna2_tools_check,docs_linksandform_coverage_check.pyall pass on RTX 3070 and WARP.v_ffbh_*forms. The generated HLSL callsffbh_u32/ffbh_i32, not this PR'sv_ffbh_u32helper. With the31u -mutation applied to this PR's helper,pixel_aot_bits_hardwareand_warpstill pass in the merged tree, while the same mutation fails on this PR alone (last row above).The reason is ordering: #541's integer-op branch in
lower()matchesv_bfrev_b32/v_ffbh_*before this PR's branch is reached. So if both PRs land as they are, this PR'sv_bfrev_b32/v_ffbh_*entries and itsv_ffbh_u32helper become unreachable, and its bits cases exercise #541's helpers instead. Results are identical today, but there would be two copies of the same rule, and a later fix to one copy would not reach the generated code if it was the dead one.Suggestion: whichever of the two PRs lands second drops its duplicate
v_bfrev_b32/v_ffbh_*lowering and helpers and keeps its test cases, so both suites cover the single remaining implementation.Environment: Windows 11 build 26200.9974, NVIDIA GeForce RTX 3070 (10de:2484), driver 32.0.16.2101, D3D12 debug layer on (Graphics Tools installed); 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), and the/O2release preset.AI-assisted: yes. All reported checks ran locally on the adapter and driver listed.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T08:56:45Z.
Current
mainalready lowers the four plain unary families in both spellings (v_bfrev_b32,v_ffbl_b32,v_ffbh_u32,v_ffbh_i32) using its shared integer templates. The remaining implementation here isv_bfe_{u32,i32},v_bfm_b32andv_bcnt_u32_b32. Let’s retain your independent edge references, especially the signed extract crossing bit 31 and the population-count addition wrapping at 2^32, while using the current unary helpers. That keeps the previous hardware evidence and avoids replacing shared code already in use.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T09:25:25Z.
I fast-forwarded the branch to
f80b24band resolved the shared lowering and coverage conflicts. The four new bitfield and population-count operations use the existing integer lowering, and all twelve of your independent reference cases still run. Each form now batches its 16 inputs and one wrong reference on a single renderer device. LLVM 15 round-trip and Python controls passed. Windows 11 build 26200.9974: WARP 10.0.26100.9818 passed in 5.7 s and RTX 4060 Laptop 32.0.16.1656 in 19.3 s, both with the debug layer enabled. Waiting for GitHub CI on this head.