feat(recompiler): support waterfall select conditions and key bounds in pointer image tables #7388
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7388"
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 pushkarreddyy on 2026-10-18T04:11:32Z.
What
This pull request addresses shader recompiler evaluation, tape compilation, and image table key bounds for pointer-based SRT image tables indexing dynamic waterfall keys:
ResourceTracker.cpp): Propagate 32-bit bit bounds throughIrOpcode::ReadFirstLaneandIrOpcode::SelectU32inpossibleU32Bitsso scalarized bit indices retain bounded domains without falling back to unbounded domains (0xffffffff).SrtInstructionPredicates.cpp): Register bit-scanning and bit-counting operations (BitCount32,FindILsb32,FindUMsb32) as runtime-uniform operations underIsRuntimeUniformOp.SrtRuntimeValidator.cpp,SrtTape.cpp): AddActiveMaskImplieshelper to check conjunction masks (LogicalAndexpressions) forIsRuntimeSelectvalidation and tape compilation. When_activeMaskimplies the selection condition, the active lane branch is compiled and evaluated directly without compiling or demanding wave-wide uniformity on the inactive branch.SrtInstructionPredicates.hpp): Place standard library headers (<concepts>,<type_traits>) at file scope at the top of the header.ShaderMemory.cpp): AddverifyWaterfallImageTableunit test exercising descriptor planning, validator acceptance of conjunct selects, andSrtTapecompilation and execution of active select arms.docs/dev/debt/shader.md): Preserve existing pointer image table debt entry and documentReadFirstLane/SelectU32bound propagation and active mask implication semantics.Tested
python tools/check_conventions.py --base 4ffb0cd12passes with 0 findings and 0 errors.verifyWaterfallImageTable()passes in both--bindlessand full test suites undercore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp.Checklist
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T04:18:06Z.
Thanks. The three pieces look sound on their own. One consistency issue, and a test question:
ActiveMaskImplieswidens the active-arm rule only inRuntimeValidator. The CPU walk applies the same rule with exact equality inSrtEvaluator::MayEvaluate(takesActiveArm, SrtEvaluator.cpp:370) andBasicEvaluator::Evaluate(:87). So a select on one conjunct of the mask is approved at planning but still evaluated in full, inactive arm included, at draw time. Could you apply the same implication in those two places (one shared helper), and in #6095'sSrtTape(SrtTape.cpp:107) if that lands first?BitCount32/FindILsb32/FindUMsb32/FindSMsb32are now runtime-uniform, butSrtEvaluatorcan't evaluate them on the CPU. Is a GPU-side key the only use you need? If the CPU walk must evaluate them, they need evaluator cases.verifyWaterfallImageTable's program has no select, loop or bit-count op, and it expectsMaxKeys. Could you add cases that fail onmainfor each change: a select on a conjunct of thev_readfirstlanemask; a negative case, a select on a condition the mask doesn't imply, still refused; a key bounded throughSelectU32/ReadFirstLanewith akeyscount belowMaxKeys? And which import in PPSA01748 (#7362) hits this, with the instruction offsets?Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T04:23:51Z.
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/ShaderMemory.cppL3449docs/dev/debt/shader.mdL40-41Some 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.
docs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/SrtWalker/SrtEvaluator.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ResourceTracker.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/shader/recompiler/Optimization/src/ResourceTracker.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceTracker.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T04:40:04Z.
One more thing: this head doesn't compile.
SrtInstructionPredicates.cpp:91usesIrOpcode::FindSMsb32, which isn't an opcode on this branch or onmain(GCC: "did you mean 'FindUMsb32'?"). Also, with the three production files reverted tomain,verifyWaterfallImageTablestill passes, so it doesn't cover the change yet. Could you fix the build and add cases that fail onmain?Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T04:50:16Z.
Updated:
ActiveMaskImpliesas a shared helper inSrtInstructionPredicates.hpp/.cppand applied it acrossSrtRuntimeValidator,SrtEvaluator::MayEvaluate(takesActiveArm), andBasicEvaluator::EvaluateWide.BitCount32(std::popcount),FindILsb32(std::countr_zero), andFindUMsb32(31u - std::countl_zero, with 0 returning0xffffffffuper GLSLstd450). DroppedFindSMsb32fromIsRuntimeUniformOpas it does not exist inIrOpcode.verifyMayEvaluate:firstActiveConjunct):ReadFirstLaneofSelectU32whose condition is implied by aLogicalAndactive mask; verified to passMayEvaluate,evaluator.Evaluate(evaluating only the active arm), andValidateRuntimeValue.firstNotImplied): condition not implied by the mask; verified to be refused byMayEvaluate,evaluator.Evaluate, andValidateRuntimeValue.BitCount32,FindILsb32, andFindUMsb32.verifyWaterfallImageTable:v_cndmask_b32(SelectU32) andv_readfirstlane_b32(ReadFirstLane), verifyingboundedColumn.maxKey == 6uandboundedSnapshot.keys == 7u < Abi::MaxKeys.PPSA01748v01.006.000).sceAgcDriverSubmitDcb/sceAgcDriverSubmitAcb) for the compute dispatch recorded viasceAgcCbDispatch.0x3b91c3e00stage 0, the SRT pointer table loads hit atpc=0x00004378andpc=0x00004380(LoadAddressU32).Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T04:59:01Z.
Fixed in the latest update:
FindSMsb32fromIsRuntimeUniformOp(onlyBitCount32,FindILsb32, andFindUMsb32are inIrOpcode).maindirectly insideverifyWaterfallImageTable:v_cndmask_b32and scalarized viav_readfirstlane_b32: assertsboundedColumn.maxKey == 6uandboundedSnapshot.keys == 7u < Abi::MaxKeys. Onmain,possibleU32Bitshits defaultmaxforSelectU32/ReadFirstLane, producingmaxKey = 0xffffffffuandsnapshot.keys == MaxKeys, which fails.verifyWaterfallImageTableverifying that a select on a conjunct of the active mask (firstConj) is accepted, while a condition not implied by the mask (firstOther) is refused.verifyMayEvaluate, addedfirstActiveConjunctandfirstNotImpliedverifying both planning and runtime evaluation, plus direct CPU evaluations forBitCount32,FindILsb32, andFindUMsb32.Also, whenever you have a moment, could you please take a look at our other open PRs:
fix(json2): return parse error on null text or zero size(updated per your and MarcZX100's reviews)feat(libSceAgcDriver): support polygon primitive type 21fix(libSceAgcDriver): normalize reserved bit 30 in guest buffer descriptorsfeat(libSceSysmodule): register libSceProprietaryVoiceChatHelperPrx module id 0x132feat(libSceVoice): implement sceVoiceEnableChat and sceVoiceDisableChatImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-18T14:23:37Z.
Built
1a62a3f92on Linux (GCC 16.2.1, Release), alone and merged ontomaina62c724c3. Both fail with the same two errors:mask.Value()is a non-constIrValue*, soActiveMaskImplies(const TNode&, const TNode&)withTNode = IrValue*(identity conversion) is a better match thanActiveMaskImplies(const IrValue*, const IrValue*)(qualification conversion), and the template is instantiated again on the pointer. By reading,SrtRuntimeValidator.cpp:57picks the same overload directly with_activeMask(the build stops before that file). The PR's linux, windows and relinker jobs were skipped, so CI has not built this head.Adding a non-const pointer overload in
SrtInstructionPredicates.hppbuilds with no errors or warnings:With that change, the
agc_shader_memoryctest entry, and a direct run with no shader cache directory, both stop at the new bounded case, in the planning check afterGetResourcePlan:The unbounded checks before it pass. That differs from your note that the bounded case fails on
mainand passes with this PR.maina62c724c3, whose test file has no bounded case, passes the same test binary. The overload is my guess at the intent, so the planner result may differ with your version of the fix.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-18T15:52:05Z.
Pushed commit
59c0f664baddressing both points:GCC 16.2.1 Template Deduction:
mask.Value()returnsIrValue*. In GCC 16.2.1, passing(IrValue*, IrValue*)matched the unconstrained templateActiveMaskImplies(const TNode&, const TNode&)(TNode = IrValue*, exact reference bind without qualification conversion) rather than the(const IrValue*, const IrValue*)pointer overload, attempting(IrValue*).Value().requires (!std::is_pointer_v<std::decay_t<TNode>>)to the template alongside explicit pointer overloads ((IrValue*, IrValue*),(const IrValue*, IrValue*),(IrValue*, const IrValue*)) forwarding toconst IrValue*.verifyWaterfallImageTable()Dynamic Lane Dependency:verifyWaterfallImageTable(),v_cndmask_b32 v0, 2, v1, vccpreviously executed with uninitializedvcc. In SSA, uninitialized booleans default tofalse, enablingConstantFolder::foldSelectto foldSelect(false, 4, 2)directly to constant2. The SMEM offset subsequently collapsed into an immediate scalar constant0x80, causingTryMakeTableColumnto bypass table allocation (plan->info.images[0].table == 0u).0x7d8a0080u(v_cmp_ne_u32 vcc, 0, v0) prior tov_cndmask_b32bindsvccdynamically to lane inputv0, preventing constant folding and preserving theSelectU32node intopossibleU32Bits(maxKey == 6u,keys == 7u) as expected.Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-18T22:11:55Z.
@pushkarreddyy I ran this on Marvel's Guardians of the Galaxy (PPSA01748), the title in #7362. The title still stops at the same shader.
main0bc3003f8+ #6606 + this PR's head59c0f664b. Both commits conflicted only intests/ShaderMemory.cpp(next toverifyPointerChainImageTable) anddocs/dev/debt/shader.md; I kept both sides.agc_shader_bindless, which runs yourverifyWaterfallImageTable, passes. #6270 was reverted locally, because it stops this title at boot (#7678).0x3b91c3e00is refused atpc=0x4378(1×) andpc=0x4380(4×), with the sameGetImageResource dword 0chain as in #7362:LoadAddressU32(GetAddressResource(ReadConst(GetSrtResource), ReadConst(GetSrtResource)), ShiftLeftLogical32(ReadFirstLane(SelectU32(…FindILsb32(…CompositeExtractU32x4(ImageRead, …)…)…), …))).ReadFirstLane(SelectU32(...))planning doesn't take this chain yet. One difference from your test shape may be theFindILsb32over anImageRead-derived mask in the selected arm, plus the second arm throughBitCastU32F32(FPMax32(…)).mainno longer needs #6232 to reach this stop.Tested and written by Claude (AI assistant) on a contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T05:46:17Z.
@Tamalero Thanks for testing on Marvel's Guardians of the Galaxy (
PPSA01748) and sharing the exact AST trace!origin/main(4ffb0cd12) alongside merged #6606, resolving theShaderMemory.cppanddocs/dev/debt/shader.mdconflicts and keeping both test sets active. Pre-flight conventions pass with 0 findings.0x3b91c3e00):0x3b91c3e00, the key arm usesFindILsb32over anImageRead-derived mask (CompositeExtractU32x4), paired withBitCastU32F32(FPMax32(...))on the alternate arm.ImageReadoutputs are not evaluable compile-time SRT constants or known-bounded uniforms,possibleU32Bitscurrently treats theImageReadextraction as unbounded (0xffffffffu), which cascades throughFindILsb32and keeps the key domain wide rather than bounded.SelectU32/ReadFirstLaneconditions and SRT validator conjunctions.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-19T08:13:38Z.
Windows data point for
bfd5b6e38merged ontomainfb0dc118f(together with #7567 in one tree,a8bdd9935): Windows 10 (10.0.19045), WinLibs GCC 15.2.0, Release,ctest -R '^agc_shader_bindless$'(the ctest entry that runsverifyWaterfallImageTable). It is a CPU-side ctest entry; I did not check whether a Vulkan device was used, so I cannot name a GPU.core/shader/recompiler/Optimization/restored tomain(SrtInstructionPredicates.hpp/.cpp,ResourceTracker.cpp,SrtEvaluator.cpp,SrtRuntimeValidator.cpp; the new test kept): fails 3 of 3 (exit 8); one such run printswaterfall image table: bounded key maxKey is wrong.So with the production files restored to
main,agc_shader_bindlessfails on this head, which answers the point raised on 18 Oct that the case did not yet cover the change. The head builds here (no compile error).Not tested: the full
ShaderMemorysuite beyond this entry, a title run, other OS or GPUs.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by Neithennn on 2026-10-19T09:34:30Z.
Windows NVIDIA run, since the description lists no GPU run.
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. Headbfd5b6e38merged onto mainf78675ae4; full build succeeds.agc_shader_bindlessandagc_shader_memory(both runverifyWaterfallImageTable),agc_shader_srt_read_patching,agc_driver_bindless_images,agc_driver_image_table,agc_driver_image_table_cache,agc_driver_image_table_cache_bounds,agc_driver_image_table_reuse,agc_driver_image_table_vouched_lookups,agc_driver_image_table_vouch_queued_draws: 10/10 pass, withANYPS5_REQUIRE_VULKAN=1.ctest -j 8: 1627/1628, the same as unchanged main on this machine; the one failure isagc_driver_bda_device(device lost, #7584), which fails on main too and is fixed by #7571.No title run.
AI-assisted: yes (runs done with Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T14:02:21Z.
@Neithennn Thank you for running the hardware verification on Windows 11 with the RTX 4080! Great to see all 10 image-table and waterfall tests passing (
10/10) alongside full suite parity withmain.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T14:20:53Z.
Review: CHANGES_REQUESTED
Thanks for the update. The bound propagation and the
ActiveMaskImplieshelper look sound; three things left:SrtTape.cpp:107still compares the select condition to the mask with== mask, so a select on one conjunct of the mask is approved by the validator and the evaluator but the tape still compiles the inactive arm. @oneandonlydean asked for it to useActiveMaskImpliestoo; please apply it there and add a case that fails without it.docs/dev/debt/shader.md:37onmain("Image tables ... read bys_loadthrough a 64-bit pointer hold the keys the key's known bits allow ...") is deleted by this PR. That line is unrelated and still true; please restore it and keep your new line next to it.SrtInstructionPredicates.hpp: the#include <concepts>/<type_traits>sit after declarations inside the namespace. Move them to the top with the other includes.Also note that @Tamalero's run shows PPSA01748 still stops at the same shader with this head, so the PR should not say it unblocks #7362 until that changes.
Imported from boykopovar/AnyPS5. Originally posted by pushkarreddyy on 2026-10-19T14:32:32Z.
@adriadam10 Thanks for the review! All four points have been addressed in
91abb61be:SrtTapeCompilation: UpdatedSrtTape.cppline 107 to useActiveMaskImplies(mask, value->Argument(0))rather than exact pointer equality withmask, ensuring select conditions implied by conjunction masks compile and evaluate the active arm without compiling inactive branches.verifyWaterfallImageTableincore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppto constructplanA, compile itsSrtTape, and executetapeA->Run(planA, runtimeA, resultsA, flatA, activeA). WithoutActiveMaskImplieson line 107, tape compilation attempts to compile the vector register arm and fails to run; with it,tapeA->Runpasses and evaluates the active conjunct select to42u.s_load64-bit pointer image table line indocs/dev/debt/shader.mdalongside the waterfall key bound propagation entry.<concepts>and<type_traits>out ofnamespace ShaderRecompiler::Detailto file scope with the other includes at the top ofSrtInstructionPredicates.hpp.Unblocks: none.Pre-flight conventions check passed with 0 findings (
python tools/check_conventions.py --base 4ffb0cd12).Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T17:22:16Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
maindbac9fa15(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8): 1638/1640 with this PR, against 1638/1640 onmain. The failures are the same two on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).agc_shader_memorypasses. The PR adds no new ctest entry, and no test is skipped or removed compared withmain.GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by DavidAmsellem on 2026-10-19T18:17:07Z.
First AMD-on-Linux (RADV) run of this PR. Merged onto
maindbac9fa15(clean merge), built in full and compared with the samemain, on the same machine.AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 (Ubuntu 24.04 base), kernel 7.0.0-38, GCC 13.3, Release.
Full suite (
ANYPS5_REQUIRE_VULKAN=1 ctest -j8) atd767dacf7: 1638/1640 with this PR, against 1638/1640 onmain. The two failures are the same on both, so this PR adds none:agc_driver_image_table_vouched_lookups(#7766, fixed by #7916) andagc_driver_guest_memory_lifetime(#7784).Comparing the JUnit output with
main: this PR adds no ctest entry, and none is skipped or removed.This checks correctness only; I did not measure performance.
GPUs tested: AMD Radeon RX 7900 XT (RADV NAVI31, gfx1100), Mesa 25.2.8, Linux Mint 22.3 / kernel 7.0.0-38
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T20:04:34Z.
Re-checked the new head against the previous review:
SrtTape.cpp:107now usesActiveMaskImplies, so validator, evaluator and tape agree; the new tape case builds a plan whose select is on a conjunct of the mask and only runs if the inactive vector arm is skipped.s_loadpointer image-table debt line is back, the header includes are at file scope, checklist updated.ReadFirstLane/SelectU32,ActiveMaskImpliesand theBitCount32/FindILsb32/FindUMsb32evaluation (0 →0xffffffff) match the IR semantics;verifyMayEvaluateandverifyWaterfallImageTablepin both the accepted and the refused cases.Thanks for the Windows/NVIDIA runs from the other reviewers; merged.
Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-19T22:30:04Z.
Rechecked the current head
91abb61beon Marvel's Guardians of the Galaxy (PPSA01748), Linux, RTX 4090. Both builds are onmain8e0fde7d5(which now includes #6606), with a cold shader cache:main8e0fde7d5LoadAddressU32@pc=0x4380(#7362)main+ this PR (91abb61be)That's expected, I think: the key there is
ReadFirstLane(SelectU32(Phi(...), FindILsb32(...), Phi(... BitCastU32F32(FPMax32(...)) ...))), whose select condition is aPhiof twoINotEqual32, not a conjunction of the active mask. No regression up to the stop (one run each).Tested and written by Claude (AI assistant) on a contributor's machine.