shader: lower negated and absolute f32 source operands in compute #1666
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1673"
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 RenzoWit35 on 2026-11-24T16:49:32Z.
Change
Issue #1546 lists "the
-|v|operand form" among the single-instruction gaps of the measured compute programs, without naming an instruction; the per-family PRs for that issue do not cover it. The only binary32 ALU formstools/compute_store_aot.pylowers arev_add_f32,v_sub_f32,v_subrev_f32andv_mul_f32(_e32only), so this PR adds their VOP3_e64spelling with source modifiers. No opcode is added._e64form is accepted when at least one source carries-v,|v|or-|v|on a VGPR or SGPR, as LLVM 15 prints them. The other source may be any binary32 source the_e32forms accept (VGPR, known SGPR, literal, integer zero, inline float constant).pixel_aot.pydoes forv_cvt_f64_f32_e64and the binary64 compare sources:|v|becomes(w & 0x7fffffffu),-vbecomes(w ^ 0x80000000u), and-|v|becomes((w & 0x7fffffffu) ^ 0x80000000u). A signed zero or NaN payload keeps its other bits, and the output contains no floatabs()or unary minus._e64spelling (the existing control incompute_store_check.pyis unchanged);_e32;clamp,mul:2,mul:4anddiv:2, refused withUnsupported float output modifier;abs()andneg()spellings, unbalanced or nested bars, and modifiers on constants (|1.0|,neg(0x3f800000),-0x3f800000), refused withUnsupported float source modifier;Unverified float operand.float_e64_source(), afterfloat_word(), and one newelifbranch placed before the existing_e32float branch inlower(). It reuses theFALUtemplates and does not change the shared opcode alternations.tests/compute_alu_negabs_check.py(modescontrols,draw,binary), registered ascompute_store_aot_f32_negabs_{warp,hardware}. Thebinarymode is added to the Ubuntu LLVM 15 list in.github/workflows/windows.yml.docs/experiments.mdgets a new subsection, and one sentence of the binary32 section is corrected.Verification
Environment: Windows 11 Enterprise 10.0.26300, MSVC 19.51 (14.51), DXC 1.8.2502.11, WARP 10.0.26100.9818. The D3D12 debug layer was unavailable. Parent commit
c864f138.Before the change, origin/main refuses the form:
v_add_f32_e64 v4, -|v2|, v3givesUnsupported compute instruction: v_add_f32_e64 v4, -|v2|, v3. The same happens for-v2and|v2|.The fixture is the read-compute-write kernel with
cap = params[0].y = -0.75:dtakes both signs, andzis +0.0 or -0.0 depending on the lane. Each modifier appears on two operations, including one SGPR source.groups=1,groups=1,groups=5) reportcompared_words=320 mismatches=0, followed byread_f32_negabs: 3 dispatches, 12 wrong references and 12 mutated sources checked.Compute readback differs): each of the four abs masks dropped, and each of the four sign flips dropped or replaced by an abs.python -B tests/compute_alu_negabs_check.py controls) pass. They pin the exact store and evaluate the three modifier expressions against the bit model on +0, -0, quiet and signalling NaN payloads, -inf, a negative value and a denormal word. They also check 37 refusals.ctest --preset dev --no-tests=error -R '^compute_(store_aot|mesh|to_pixel).*_warp$'passes 49 of 49.tests/docs_links_check.pyalso passes.compute_store_check.pyhas nocontrolsmode; its translation controls run inside thecompute_store_aot_*tests above.cmake --preset release, thencmake --build --preset release --target offscreen_check --parallel 4, thenctest --preset release --no-tests=error -R '^compute_store_aot_(f32|f32_negabs|alu_xor3|alu_minmax3|guard_read)_warp$'. This passes 5 of 5.Not run locally:
python -B tests/compute_alu_negabs_check.py binary llvm-mc-15 llvm-objcopy-15 libLLVM-15.so.1needs llvm-mc and libLLVM, and neither is installed on this PC. It runs in the Ubuntu job. Until then, the claim that LLVM 15 prints|v4|,-v4and-|v4|exactly this way rests on the AMDGPU printer conventions thatpixel_aot.pyalready relies on.Evidence and follow-up
Refs #1546
The open PRs that also edit
tools/compute_store_aot.pyare #1580, #1591, #1592 and #1596 for #1546, plus #1566 and #1655. The #1546 ones change theALUtable, the integer opcode alternations inlower(), add a VOP1 branch after the integer branch (#1591), and add av_cvt_pk_u8_f32branch and table afterFLOAT_INLINE(#1592). #1579, #1582 and #1588 change the scalar ALU part. This PR touches none of those lines: its helper sits afterfloat_word()and its branch before the_e32float branch.git merge-treeagainst the current main reports no conflict. InCMakeLists.txtthe new test follows thealu_xor3entry, and indocs/experiments.mdthe new subsection follows "Three-input XOR". Those are the only places a rebase could need a trivial resolution against the open PRs.Possible follow-ups, not in this PR:
neg(0x...));_e64spelling;clampand omod;AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T16:54:49Z.
Review: COMMENTED
Peer review of #1673 (
a0b6d41baf687bdd4126af2b4feff2803ca76dbe): no defects found (0 P1, 0 P2).Summary
tools/compute_store_aot.py(float_e64_source,lower): lowersv_{add,sub,subrev,mul}_f32_e64when at least one source has-,|...|, or-|...|in LLVM 15 register spelling, applying bit-31 integer masks (& 0x7fffffffuthen^ 0x80000000u) while rejecting output modifiers (clamp,mul:2,mul:4,div:2), unbalanced bars,abs()/neg()spellings, modified constants, and unmodified_e64forms.tests/compute_alu_negabs_check.py,CMakeLists.txt,.github/workflows/windows.yml,docs/experiments.md: adds controls, LLVM round-trip (binarymode wired intowindows.ymlwith*COMMON_LLVM), WARP/hardware CTest (compute_store_aot_f32_negabs_${adapter}), and 12 wrong-reference + 12 HLSL mutation checks. Title-neutral andgit diff --checkclean.Verification
python3 -B tests/compute_alu_negabs_check.py controls-> PASSpython3 -B tests/compute_alu_negabs_check.py binary /usr/bin/llvm-mc-19 /usr/bin/llvm-objcopy-19 /usr/lib/x86_64-linux-gnu/libLLVM-19.so-> PASS (read_f32_negabs: LLVM round trip prints the 5 modified forms and translates identically)python3 -B tests/docs_links_check.py-> PASS (Checked 16 Markdown files and 351 links.)git diff --check origin/main...HEAD-> PASSx2w_pipe.py win2025 1673):--preset dev):cmake --build --preset dev --target offscreen_check+ctest --preset dev-> 45/45 passed (compute_store_aot_f32_negabs_warp4.90s;*_hardwareexcluded on VM)./O2(--preset release):cmake --build --preset release --target offscreen_check+ctest --preset release-> 45/45 passed (compute_store_aot_f32_negabs_warp4.84s).0x7fffffffu->0xffffffffuintools/compute_store_aot.py(float_e64_source);python3 -B tests/compute_alu_negabs_check.py controlsfailed as expected (AssertionErrorincontrols(), exit code 1). Restored viagit checkout -- ..AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T12:53:49Z.
@RenzoWit35 could you rebase this branch onto current
mainand force-push?GitHub reports head
a0b6d41bas conflicting withmain, so it cannot be merged as is.Files that conflict with current
main(cf97bee1):.github/workflows/windows.ymlCMakeLists.txtdocs/experiments.mdCommands run locally:
Once it is rebased and CI is green it will be re-checked right away.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:16:14Z.
Merged
origin/maininto this branch (e85592ebd, fast-forward froma0b6d41ba) so the PR no longer conflicts. No author code was changed.Conflicts, all mechanical, both sides kept: the Linux check list in
.github/workflows/windows.yml, the xor3/bcnt test block inCMakeLists.txt(thecompute_store_aot_f32_negabs_*tests now sit after main's xor3 entry), anddocs/experiments.md(this PR's negabs section followed by the sections that landed on main).tools/compute_store_aot.pymerged without conflicts.Verification:
python3 -B tests/compute_alu_negabs_check.py controls: PASS (Linux)x2w_pipe.py win2025 1673 --patch <merge diff> --targets offscreen_check --regex compute_store_aot_f32_negabs: dev 2/2 and release 2/2 passed (compute_store_aot_f32_negabs_warpand_hardware).AI-assisted; commands listed were executed locally.