shader: lower 32-bit bit counts and scans in the direct compute path #3051
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3051"
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 pigalot on 2026-11-27T11:37:47Z.
Fixes #3050 (part of #2935, instruction coverage).
Change
The direct compute frontend (
src/gfx1013_direct_compute.inl) used to refuse the 32-bit bit counts and bit scans withdirect DXIL lowering for <name>. They now lower to DXILCountbits(31),FirstbitLo(32),FirstbitHi(33) andFirstbitSHi(34):s_bcnt0_i32_b32,s_bcnt1_i32_b32s_ff0_i32_b32,s_ff1_i32_b32,v_ffbl_b32s_flbit_i32_b32,v_ffbh_u32s_flbit_i32,v_ffbh_i32gfx2hlsl.py(op_s_ff1_i32_b32,op_s_flbit_i32_b32and thes_bcnt*table) and oftools/pixel_aot.py(dpp_ffbh_u32,dpp_ffbh_i32,bcnt1_i32_b32).31 -correction: DXILFirstbitHiandFirstbitSHialready count from bit 31.dxc -T cs_6_0compiles HLSLfirstbithigh(x)tounaryBits(33, x)followed bysub i32 31, …and a select for -1.direct ALU operand modifiers, as for the other integer VOP3 forms. The 64-bit scalar forms are left for later.Verification
main1c879506plus this change (44f24d71). Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 5090 (driver 32.0.16.1088), dev preset with the debug layer on.native_bitscan_controlscompiled; clamp refused; the wrong-end, unsigned, zero-is-32, SCC-dropped and SCC-written references each differnative_bitscan_hardwarebit counts and scans: 1024 words of two groups and the guards matchedmainsource)native compute +0x40: direct DXIL lowering for v_ffbh_u32FirstbitLoandFirstbitHiexchangeds_bcnt1thens_ff1)ctest -R '^native_' -E '_hardware$' -j 8docs_links_check,bidi_controls_checkmain98007de5without this change:native_sdwa_f16_ir,native_sdwa_f16_hardwareandnative_cvt_pk_u8_hardware.native_sdwa_f16_irfails the same way at1c879506with it.sdwa_f16checks report the same value as the expected one, for example(0, 'add', '0xa55a4200', '0xa55a4200'), so theirmatches()seems to reject an equal word.cvt_pk_u8differs in the low byte,0xa5a5a501against0xa5a5a500.Evidence and follow-up
tests/native_bitscan_check.py(tests/cmake/native_bitscan.cmake), with notes indocs/experiments/native-direct-bitscan.md. It is original and uses no external inputs.sop1,scalar,vop2,vmove). Every word was checked withtools/disasm_rdna2.py --hex. LLVM was not available with the AMDGPU target here.compile_dxil --refusals(counts only) on 2,689 compute requests.s_absdiff_i32, 2 atunbound numeric SGPR, 1 atdirect descriptor address outside bound tableand 1 atnon-contiguous resource descriptor.Checklist
This change was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T11:52:52Z.
Review: APPROVED
Reviewed
44f24d71withmain298a2034(integration tree5c5734ff). I rebuilt and ranctest --preset <dev|release> --no-tests=error -V -R '^(native_bitscan_(controls|hardware)|native_f16_alu_(ir|hardware)|native_global_srv_heap_replay_(hardware|warp))$'. Each preset gave five passes and one WARP capability skip in the unrelated heap replay. The RTX matched every one of the 1,024 output words and the guards. The control compiled, rejected clamp and distinguished the wrong scan end, unsigned scan, no-match handling and both SCC mutations. Windows 11 26200.9974, SDK DXC 10.0.26100, RTX 4060 Laptop driver 32.0.16.1656, WARP 10.0.26100.9818. The native replay fixture does not enable the D3D12 debug layer. Hosted Windows, Linux Python and gfx1013 checks passed.