perf(shader): fold integer compares by value sets and known bits #6176
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6176"
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 boykopovar/AnyPS5. Originally posted by mitul72 on 2026-10-15T00:29:39Z.
What
Two commits.
Integer compare folding:
IEqual32andINotEqual32against a constant fold when the other operand has a value set of at most 64 values (through shifts, bitfield extracts, and/or/xor/mul/umin with a constant, add and select) that excludes the constant or holds only it, or when a known bit of the operand contradicts the constant. Known bits come from constants, shifts and bitfield extracts by constants, and/or/xor, add (up to the first unknown bit), mul (trailing zeros), umin, select, phi and lane reads.ULessThan32against a constant folds from the known-bit and value-set bounds. A fold pass computes known bits and value set once per compared operand, and a sum is not enumerated when its two operand sets hold more than 65 values together. All folds are identities of the operand's possible values; out-of-range M0 handling of the relative indexing lowerings is unchanged. With M0 = 4i + k, three of every four entries of ans_movrels/s_movreldcompare chain fold away.SPIR-V constant sharing: specialization emitted a new
OpConstantper folded result. A folded value now reuses an existing constant of the same type and value for the operands the specialization decodes; other consumers (subgroup, extended instructions) keep their own definitions. AnOpBitcastto its operand's type, or back to the type before a previous bitcast, becomes a copy. A compute program with one formatted load shrinks from 10730 to 1117 words, so the formatted-load sharing check now compares the words two more loads add with the words the first added.Tests:
IntegerFolding, additions toSpirvOptimizer, and the execution testRelativeIndexingKnownBits.Tested
Linux, RX 9060 XT (RADV GFX12, local Mesa). Full
ctestpasses exceptagc_driver_tessellation, which segfaults inside RADV while linking pipeline libraries on unmodified upstream703aa8f63as well.Performance, old base (upstream
d53960612+ #454 + the 1D fix), Astro Bot hub, GPU busy per frame: 166 ms vs 172-179 ms (-4 to -5%); withAPS5_LOOP_GUARD=64, 136 ms vs 141-143 ms. Not re-measured individually on703aa8f63.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T07:33:06Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libSceAgcDriver/tests/SpirvOptimizer.cppL550Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/include/Optimization/ConstantFolder.hppcore/shader/recompiler/Optimization/src/ConstantFolder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/shader/recompiler/Optimization/src/ConstantFolder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by Neithennn on 2026-10-15T15:52:32Z.
Windows NVIDIA run, since the description lists RADV only.
Windows 11 Pro 26200, NVIDIA GeForce RTX 4080 (driver 617.42), AMD Ryzen 7 5800X, WinLibs GCC 15.2.0 r7, Ninja, Release, bundled dependencies,
BUILD_TESTING=ON,ANYPS5_NO_SHADER_CACHE=1. Head088f9509bmerged onto main92e50418f; full build succeeds.agc_integer_folding,agc_driver_relative_indexing_known_bits,agc_driver_relative_indexing,agc_driver_scalar_relative_indexing,agc_formatted_buffer_once,agc_formatted_buffer_byte_stores: pass.ctest -j 8: 1296/1296, includingagc_driver_tessellation. Unchanged main on the same machine: 1294/1294.Correctness only; no performance measurement and no title run.
AI-assisted: yes (runs done with Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-16T08:52:43Z.
Tested on Linux (Arch),
c++ (GCC) 16.2.1 20260810, Release,BUILD_TESTING=ON,mainat5d9dcc42d2ec5401aebd089028b8d4d7410a77b4. GPU tests ran on lavapipe (Mesa 26.2.2, llvmpipe with LLVM 22.1.8).agc_driver_relative_indexing_known_bits(this PR's test) fails onmainplus this PR (2 of 2):Most likely cause: lavapipe runs subgroups of 8 here (other tests print "subgroup size 8 does not hold exactly one wave32"), so a wave32
v_readfirstlanecannot see lane 0 from lane 8. Other wave32 tests skip on such devices, for exampleBitfieldMask.cpp:85(if (device->Target().subgroupSize < Threads)).RelativeIndexingKnownBits.cpp:107-112runs bothRun(*device, 32, 32)andRun(*device, 64, 64)without that check.Suggested fix: skip with
VulkanTestSkippedwhendevice->Target().subgroupSizeis smaller than the wave.Separately, this PR breaks two existing tests when merged with an older open PR (same
main, lavapipe). Each PR alone passes,mainalone passes, and each pair fails (2 of 2):agc_shader_disk_cachefails:This is the check at
ShaderDiskCache.cpp:1381of #5315 (require(rgba == bgra, ...)). Both PRs changeSpirvSpecialization.cpp. Most likely cause: the newshareConstants()of this PR (called atSpirvSpecialization.cpp:558) merges constants with the same type and value, so which constant id survives can depend on the folded selector (4 or 6 in that test), and the two specialized modules then differ. Whichever PR lands second needs to keep the output independent of the selector or adjust the test.agc_redundant_value_eliminationfails:The two PRs share no file (#5353 changes
DescriptorBindingBuilder.cppandSpirvRuntimeBuffer.cpp), so this is a behaviour interaction. I did not find the exact cause.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T19:29:01Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.