shader: lower s_ff1_i32 on a general scalar in gfx2hlsl (#2022 Item F) #2631
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2639"
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 SimSalabimse on 2026-11-26T00:06:12Z.
Change
Part of #2022 Item F (
s_ff1_i32_b32/s_ff1_i32_b64of a general scalar) intools/startup/gfx2hlsl.py.The compute-entry special case on
exec_lostill folds to lane 0. Ordinary SGPR and immediate sources now lower tofirstbitlow(and a lo-then-hi scan for the 64-bit form), matchingpixel_aot/ Mesa. SCC is unchanged. Lane masks and descriptor-bearing sources stay refused. Known constant sources fold.Claim before coding. Base is
main.AI-assisted.
Verification
Commit under test: this PR head.
All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free.
Windows verification:
Evidence and follow-up
disasm_rdna2/gfx2hlsl.decode; no retail bytes.firstbitlowdiverges from the ISA reference.vcc_loas "requires compute exec_lo" now expects the lane-mask refusal from the general path.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T00:11:35Z.
Review: COMMENTED
Review of head
a525adc7(comment only, no approval).What is good
op_s_ff1_i32_b32/_b64intools/startup/gfx2hlsl.py: operand checks, lane-mask and descriptor-data refusals, constant folding and the lo-then-hi scan (32u + firstbitlow(hi),0xffffffffuwhen both words are zero) match the ISA semantics and thepixel_aotbehavior. SCC is untouched.exec_locompute-entry fold is preserved. Thesopk_accummutation pin was narrowed correctly.startup_gfx2hlsl_compute_check,handler_arity,s_bitcmp,sopk_accum,translatorall still pass. CTest entry and thewindows.yml/AGENTS.mdlines are consistent. No other open or merged PR covers the b64 / general-scalar slice (#2065 and #1903 only covered the tracked scalar and the exec fold).What is missing (why this is not merged by us)
tests/startup_gfx2hlsl_s_ff1_check.pyevaluates the translated HLSL text on the CPU. For a shader/math lowering we need a real D3D12 WARP GPU readback compared with a CPU reference. The point is to prove thatfirstbitlowon the real compiler returns0xfffffffffor 0 and that the?:expression compiles and runs. Please add a small WARP readback fixture (seetests/rcas_coordinate_readback/readback.cppandtests/startup_compute_binding_trace.cppfor existing readback patterns) covering: 0, 1, 0x80000000, 0x00010000, and for b64: lo=0/hi=nonzero, lo nonzero, both zero. Then it can be tested on Win2025.Commands run locally (Linux, exact head)
python3 -B tests/startup_gfx2hlsl_s_ff1_check.py-> all okpython3 -B tests/startup_gfx2hlsl_compute_check.py,..._handler_arity_check.py,..._s_bitcmp_check.py,..._sopk_accum_check.py,startup_translator_check.py-> passpython3 -B tests/docs_links_check.py,python3 -B tests/bidi_controls_check.py-> pass;git diff --check origin/main...HEAD-> clean32u +->31u +in the b64 scan): the new test fails ("s_ff1_i32_b64 SGPR pair").firstbitlow->firstbithighin the b32 path): the new test fails (AssertionError on the emitted text).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T00:11:58Z.
The general b64 register-pair
s_ff1_i32_b64is already in the open #2072, whose Windows draw is being corrected. This PR also covers distinct work: the b32 general-SGPR form and the b64 immediates that #2072 explicitly refuses. Please coordinate with @tedin7 so one candidate owns the b64 register-pair lowering and both contributions keep their independent controls. The b32 slice can proceed separately. For b64 immediates, keep the exact encoding and extension rule in the fixture.Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T00:19:51Z.
@tedin7 @R0Y00 — coordinating as requested.
Ownership split
s_ff1_i32_b32of a general SGPR (plus the existing compute-entryexec_lofold).s_ff1_i32_b64of a live SGPR pair stays refused here with an explicit#2072message. That register-pair lowering remains yours in #2072.GPU readback
dispatchmode ontests/startup_gfx2hlsl_s_ff1_check.py(UAV dump viaoffscreen_check, same pattern asstartup_gfx2hlsl_pack_absdiff_check).0,1,0x80000000,0x00010000— including a hard check thatfirstbitlow(0) == 0xffffffff.0,1,0x00010000,0x80000000.Pushed on
cursor/gfx2hlsl-s-ff1-general-5a9e(fdf07439).Windows (when available):
AI-assisted; Linux CPU checks re-run green; WARP dispatch not run on this agent.
Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T00:45:21Z.
Host Windows retest on this PR head:
Passed:
startup_gfx2hlsl_s_ff1,startup_gfx2hlsl_s_ff1_dispatch_warp,startup_gfx2hlsl_s_ff1_dispatch_hardware(3/3).Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T01:36:25Z.
Review: COMMENTED
Review of head
b91218a6(comment only).The earlier request is met: the PR now adds a real D3D12 readback test.
startup_gfx2hlsl_s_ff1_dispatch_warpand_hardwarerun the b32 lowering as a compute shader and read the UAV back, next to the CPU-evaluation teststartup_gfx2hlsl_s_ff1. Both are registered in CMakeLists.txt and the new check is listed in.github/workflows/windows.yml.What I checked on this head, against origin/main:
tools/startup/gfx2hlsl.pyusesfirstbitlow(0xffffffff for zero), matching the siblingv_ffbl_b32entry; the b64 lo-then-hi form matches the existing b64 helper near line 7204.firstbitlowwithfirstbithighin the s_ff1 lowering makesstartup_gfx2hlsl_s_ff1_check.pyfail (AssertionError ons3 = firstbithigh(s1);).Commands run locally (Linux):
python3 -B tests/startup_gfx2hlsl_s_ff1_check.py(all ok)python3 -B tests/startup_gfx2hlsl_compute_check.py,..._handler_arity_check.py,..._s_bitcmp_check.py,tests/startup_translator_check.py(all pass)python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD(clean)Not run by this review: the Windows dispatch tests. CI on this head was still pending when I looked; a Win2025 WARP receipt is a separate step.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T01:57:36Z.
Added to
tests/startup_gfx2hlsl_s_ff1_check.py(commit69f8660ba): a D3D12 readback fors_ff1_i32_b64of a live SGPR pairs4:s5. The existing dispatch only covered the b32 form and b64 immediates; the pair lowering was only string-checked. The newdispatch_b64_pairsruns 8 lo/hi cases (both zero, lo only, hi only, both set, edge bits in each half) and compares every result with a CPU reference. It also checks that a zero lo word scans the high word ((0, 0x10)gives 36).Verification (Windows Server 2025, MSVC + D3D12 WARP, on
b57b674dplus this patch):python3 tests/startup_gfx2hlsl_s_ff1_check.py(Linux): all okx2w_pipe.py win2025 2639 --patch <diff> --regex '^startup_gfx2hlsl_s_ff1': dev 3/3 and release 3/3 passed (startup_gfx2hlsl_s_ff1,_dispatch_warp,_dispatch_hardware)AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:09:48Z.
Merged current
maininto this branch (merge commitc34ae8962, no rebase, no force push) because the PR had gone into conflict.mainadded at the same spots:.github/workflows/windows.yml,AGENTS.md, and theCMakeLists.txttest block. Both sides are kept. The s_ff1foreachnow closes before the s_flbit block.tools/startup/gfx2hlsl.pymerged without conflicts.b57b674dplus the readback test pushed as69f8660ba):ctest -R '^startup_gfx2hlsl_s_ff1', 3/3 passed (startup_gfx2hlsl_s_ff1,_dispatch_warp,_dispatch_hardware).c34ae8962:python3 tests/startup_gfx2hlsl_s_ff1_check.pyok,python3 tests/startup_gfx2hlsl_s_flbit_check.pyok,python3 tests/startup_gfx2hlsl_s_bit_scan_check.pyok,python3 tests/startup_gfx2hlsl_compute_check.pyok,python3 tests/docs_links_check.pyok,python3 tests/bidi_controls_check.pyok,git diff --checkclean.Squash merge is queued for when this head's CI is green.
AI-assisted; commands listed were executed locally.