native: fold s_brev_b32 and s_bfe_u32 with constant operands #3524
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3524"
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 JB2WIN on 2026-11-29T22:46:00Z.
Change
The native compute symbol analysis (
transfer,src/gfx1013_compute_native.cpp) now foldss_brev_b32with a constant source ands_bfe_u32with two constant sources into constant symbols. Until now both always produced an unknown symbol.Compilers write high-bit constants as
s_brev_b32 sN, <inline constant>. For example, 0x80000000 is word 3 of a static sampler with an OPAQUE_WHITE border. A literal sampler built that way was refused asnonconstant sampler. With the fold it is a literal sampler.The fold matches the DXIL lowering. For
s_bfe_u32it computes(S0 >> S1[4:0]) & ((1 << S1[22:16]) - 1), with width 0 giving 0 (gfx1013_direct_compute.inl, thes_bfe_u32/s_bfe_i32case). A width of 32 or more is left unknown.s_brev_b32is the 32-bit bit reverse.Refs #3224 (claim: issuecomment-7263320436), #3023. This replaces #3517, which I closed.
Verification
Build
cmake --preset release/cmake --build --preset releaseon2ff74a6a, Windows 11, NVIDIA GeForce RTX 3080, hardware adapter.native_sampler_heap_check.py, new fixture modemixed_border: the literal static sampler ofmixedis built withs_mov_b32 s44, 0x60008; s_bfe_u32 s40, 0x3200, s44, so word 0 is 0x32 (CLAMP on x, BORDER on y). Word 3 iss_brev_b32 s43, 1(OPAQUE_WHITE). At the fixture coordinate (v = -0.375) every lane reads the white border and matches the CPU model. The fixture's CPU model now reads the address mode per axis. Before, it applied CLAMP_X to both axes; the other modes set the same mode on both axes, so their expectations are unchanged.s_brev_b32 s15, 1as word 3 of a literal sampler compiles.s_brev_b32ofv_readfirstlane_b32 s44, v0ands_bfe_u32with width 32 still refuse withnonconstant sampler.ctest -R 'native_sampler|inline_sampler|native_exec_symbol|startup_compute_dispatch_native|native_direct|native_compute|native_salu|native_descriptor': 47/47 pass.native_sampler_heap_warpandstartup_compute_dispatch_native_warpskip (wave32), as on main.mixed_borderis refused (fixture case mixed_border exits 0fails). Bit index31 - bit→30 - bit: lane 0 reads (0, 0, 0, 1) instead of (1, 1, 1, 1). Mask width → width - 1: lane 0 reads the clamped texel (31, 2, 103, 1000).s_bfe_u32result, not the x field (v is outside, so y alone decides).Evidence and follow-up
All fixtures are source-built (LLVM 15
clang -cc1as -target-cpu gfx1013encodings, in comments next to the words).Local census on my 2,689 slot 67 compute requests (
compile_dxil --refusals --jobs 8, local data, counts only), against the samemainwithout the change: 828 compile both times. Two requests move fromunbound numeric SGPR sNto the laterdirect resource-heap load requires the selected GPU slot and its view type. No request goes from compiled to refused.On the #3023 prototype route, this turns word 3 of 299 comparison samplers into the constant 0x80000000. Those samplers then stop at the comparison path's CLAMP_LAST_TEXEL-only check (CLAMP_BORDER on x and y). That is the next PR.
Checklist
AI-assisted.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T23:06:14Z.
Review: APPROVED
Read at
1c89ddde(diff only, nothing built here). The new instruction words decode by hand to what the comments say (SOP1 op 0x0bs_brev_b32, SOP2 op 0x27s_bfe_u32, literals and SGPR numbers included), and both folds match the DXIL lowering on main:src/gfx1013_direct_compute.inl:4505(Bfrev) and:4777-4784(width 0 gives 0, otherwise shift and mask; width >= 32 is left unknown here, which is the conservative side).Each half has a check that fails on revert: without the
s_bfe_u32fold word 0 of the literal sampler is not constant andfixture case mixed_border exits 0fails; without thes_brev_b32fold thebrev_word3control fails; without thewidth < 32guardbfe_wide_word0is no longer refused.Non-blocking:
tests/native_sampler_heap_check.py:262-264, loop at:340), before the compile-only controls at:391-393, so CI does not run any of the new checks. Running the compile-only controls before the fixture loop would let CI coverbrev_word3,brev_gpu_word3andbfe_wide_word0.transfer()is also called by the mesh path (src/gfx1013_direct_mesh.inl:693,:757,:815,:983,:1028,:1036,:1102), which the compute census does not cover. The change only turns an unknown into a constant there.Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-29T23:19:42Z.
@Leyukaka thanks. Moved the three compile-only fold controls ahead of the fixture loop in
73881a42. On WARP the check now prints them, then exits 77 at the first fixture case.On the mesh callers of
transfer(): it only turns an unknown into a constant there as well. The symbol stays numeric (Symbol::numeric()covers both), sorequire_numericand the masked checks behave the same.AI-assisted.