shader: lower s_ff1_i32 of a tracked scalar #2058
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2065"
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-24T23:55:01Z.
Part of #2022 (item F)
Summary
tools/compute_store_aot.pylowerss_ff1_i32_b32ands_ff1_i32_b64when the source is a tracked data word (the same words scalar ALU already accepts). The result is the index of the lowest set bit, or0xffffffffwhen the source is 0.b64reads an even SGPR pair and scans all 64 bits.SCCstays unmodelled.s_ff1_i32_b64 sD, execands_ff1_i32_b32 sD, exec_lostill fold to 0 outside a guarded region. Untracked SGPRs, literals, descriptors, the saved exec mask,vcc,exec_hi, a mismatched width, ands_ff0_i32_b32stay refused.LLVM 15.0.7 selects both opcodes as
AMDGPUffbl_b32(llvm/lib/Target/AMDGPU/SOPInstructions.tdlines 259-264) and defines that node as count-trailing-zeros with -1 when the input is zero (llvm/lib/Target/AMDGPU/AMDGPUISelLowering.hline 433). Mesa 23.3.6 definesfind_lsbas that scan, returning -1 when no bit is set (src/compiler/nir/nir_opcodes.pylines 550-558), and ACO selects a scalar 32-bit source tos_ff1_i32_b32and a scalar 64-bit source tos_ff1_i32_b64(src/amd/compiler/aco_instruction_selection.cpplines 1757-1764).Fixture
Hand-assembled gfx1013, one group of 32 threads, four stored words:
b32of 0, of 1 (bit 0), and of0x80000000(bit 31), andb64whose only set bit is bit 63. The reference is an independent bit scan. Dropping the scalar lowering makes the translation control raiseUnsupported first active lane source.Tests
LLVM 15.0.7. Negative control: with the scalar lowering disabled,
ff1_scalar_controlsexited 1 (Unsupported first active lane source: s4). Restored before commit.Windows 11 (MSVC 19.42, RTX 4070 Ti, driver 621.35), dev build at
a81a6f07:AI-assisted (Cursor)
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T00:07:50Z.
Review: COMMENTED
Review of head
a81a6f0738(shader: lower s_ff1_i32 of a tracked scalar).Findings: 0 P1, 0 P2. Merge-tree against origin/main is clean; PR is MERGEABLE.
s_ff1_i32_b32of a tracked data word lowers tofirstbitlow(word)(0xffffffff for 0).b64takes an even SGPR pair, low half first, else 32 plus the high half, else 0xffffffff. The exec/exec_lo fold is unchanged. Untracked, pending, descriptor, saved-exec, odd or mis-sized pair, and wrong-width sources are refused, each with a control.compute_store_aot_ff1_scalar_<adapter>.Commands executed locally:
python3 -B tests/compute_store_check.py(control section runs at start and passed): PASSpython3 tests/docs_links_check.py: PASS (18 files, 389 links)python3 tests/bidi_controls_check.py: PASSgit diff --check origin/main...HEAD: PASSgh pr checks 2065: Windows build and test, Linux Python checks, gfx1013 fixtures all passpython3 x2w_pipe.py win2025 2065 --wait 900: Debug (dev) PASS, Release /O2 PASS, includescompute_store_aot_ff1_scalar_warpMutations killed (reverted afterwards):
32uchanged to31uintools/compute_store_aot.py: controls fail on the exact-HLSL assertion.0xffffffffuchanged to0u: controls fail on the exact-HLSL assertion.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:00:54Z.
Executed your check on both adapters here, then mutated the lowering three ways — caught on each backend
This PR's test needs
dxcand a builtoffscreen_check, both of which exist on this machine, so unlike the pure-Python PRs I could run the real draw:and on the physical adapter:
Windows 11 build 26300.9974, DXC 10.0.26100.0, debug layer enabled on both.
Mutation, run against both backends
tools/compute_store_aot.py32u +0uinstead of0xffffffffufirstbithighinstead offirstbitlowAll three fail through the actual comparison (
mismatches), not through a compile error, so the fixture is checking values on a real device rather thantext. That is the strongest form this review can take, and it is worth saying in the PR body: 320 compared words, two adapters, zero debug-layer
errors.
The one property worth extra attention
({lo} != 0u ? firstbitlow({lo}) : ({hi} != 0u ? 32u + firstbitlow({hi}) : 0xffffffffu))— the0xffffffffucase is what an all-zero 64-bit pairreturns, and it is the value a caller tests against to mean "no active lane". A zero there would be indistinguishable from lane 0 and would silently
select a lane that is not active. It is mutation two, and it fails on both adapters.
What is still not covered
The pairing rules (
lo % 2 == 0,hi == lo + 1,hi <= 105) are refusals, and a draw fixture cannot show them: they only fire on assemblies thefixture never emits. If you want those pinned, they belong in the refusal-form check rather than here — the same split other handlers in this file use.
Notes