perf(agc-driver): prepare shader ABI variants before taking the preparation lock #3159
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3159"
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 XairRrR on 2026-10-10T23:32:08Z.
What
A shader preparation transaction took the global writers lock when constructed and kept it to the end.
ResolveShaderAbi, reached fromsceAgcCreateInterpolantMappingandsceAgcLinkShaders, compiled its variants inside such a transaction, so every thread creating or linking shaders waited behind one compile.PPSA05684 creates shaders while it streams its first level. Stack samples had a game thread blocked on this lock in most samples. The frames over 150 ms spent about 515 ms each in
Shader.Register, against 9 ms in the other frames (frame-timing.log).Changes:
Read,EditorHold.ResolveShaderAbiprepares the variants before reading the prepared state when its ABI was not committed yet.PublishRegisteredShaderholds it, andRegisterShaderholds it before the driver mutex, so the lock order is unchanged.Committakes no lock: a transaction with changes already holds it.Test in
tests/execution/PreparedPublication.cpp(TransactionLock): an open transaction that has read nothing does not block another one, and one that has read does. It fails on main ("an open transaction that read nothing blocked another one"). The existingRegistrationtest (a replacement must not interleave with an unfinished preparation) passes 32/32 parallel runs.Tested
BUILD_TESTING=ON.a11c8f7f. Full ctest: 831/832. The one failure,agc_driver_emulated_color_compare, fails the same way on plain main. Conventions check passed.Checklist
main; no other open PR implements the same functionsdefer_lockconstructor and dropsHold.NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T00:16:18Z.
Review: COMMENTED
The review of #3158 covers both of these — it is written as a pair, because the premise and the measurements belong together. The short version here, so this one is not left without a note of its own: it is the sharper of the two, because it attaches its cost to something a player feels. Frames over 150 ms spent about 515 ms in
Shader.Registeragainst 9 ms in the others, and the samples are what rule out the simpler explanation that the lock was merely contended. Taking the lock on first use and preparing the variants before reading prepared state is the standard shape.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-11T01:00:25Z.
Correction to the checklist: #2363 (open since Oct 9) touches the same code. Both defer taking the preparation writers lock, for different callers:
RegisterShader, keeping eager locking as the default and adding astd::defer_lockconstructor.ResolveShaderAbi(reached fromsceAgcCreateInterpolantMappingandsceAgcLinkShaders) prepares its variants before the firstRead.They conflict in
ShaderRegistry.cppand can't both merge as they are. Whichever lands second needs a rebase. If #2363 goes first, I'll rebase this one on itsdefer_lockconstructor and keep only theResolveShaderAbipart, plus deferring the transaction thatsceAgcCreateInterpolantMappingopens.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-11T01:08:28Z.
Could you add the after numbers for this change alone on PPSA05684: the >150 ms frames and the
Shader.Registertime with it, against the 515 ms you measured before? Perf PRs need both sides (#218).Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T01:51:16Z.
Windows run, since the PR has no Windows results yet: Windows 11, WinLibs GCC 15.2.0 r7, Release, merged onto
maind31b57a4in one build with #3213, #3159, #3158, #3142, #3141 and #2977, on an RTX 5060 Laptop and the Arrow Lake iGPU (ANYPS5_GPU=Intel).agc_driver_prepared_publication(with the newTransactionLockcase) passes on both GPUs.In the full
ctestof that build, the only failure not also on plainmainisagc_driver_dcc_keys_first_write, which I bisected to #3158 alone (reported there).AI-assisted (Claude Code); I ran this on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T07:05:59Z.
Review: CHANGES_REQUESTED
Checked: build and ctest of libSceAgcDriver are green (349/349), and
agc_driver_prepared_publicationfails without the change, so the new test does pin it. The lock logic reads right.Two things before this can merge:
Shader.Registertime on PPSA05684 with this change alone, against the 515 ms / 9 ms you measured before.ShaderPreparationTransactiontakeswritersand both editShaderRegistry.cpp, so they can't both land as they are. The checklist saysDepends on: none; please settle the order with #2363 and list it under Depends on. If #2363 goes first, rebase and reuse its deferred-lock constructor rather than adding a second mechanism (Hold) for the same thing.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-11T12:52:40Z.
After numbers on PPSA05684, as asked. Same bring-up branch, one 15-minute run each from boot to the chapter 1 boat intro, with and without this change (the PR's exact code). Plain
maindoes not run this title yet.Shader.RegistercallsShader.RegistertotalShader.Registerper frame over 150 msShader.Registerper other frameShader.ResolveAbiper call (15,374 calls)The wait in
Shader.Registeris gone. The count of frames over 150 ms does not change, though, so those frames have another cause.ResolveAbicosts more per call, likely because threads now prepare the same variants concurrently outside the lock. My earlier 515 ms figure came from an older state of the branch. One run per side, so treat these as indicative.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-11T13:13:33Z.
On the order with #2363: #2363 is still waiting on start-up numbers from its own title, so I've left this PR independent of it and rebased it onto current
main(the only conflict was the test list inPreparedPublication.cpp).If #2363 lands first, I'll rebase this one onto its
defer_lockconstructor and dropHold, keeping only theResolveShaderAbipart, as @adriadam10 asked. If this one lands first, #2363 can reuseHold(or the lazy root lock) instead of a second constructor. The description now says so under Depends on.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T13:27:15Z.
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/Execution/src/Driver/Shaders/ShaderRegistry.cppL160, L162, L182, L195, L1096Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T21:23:49Z.
Review: APPROVED
Checked: libSceAgcDriver build and ctest are green;
agc_driver_prepared_publicationpasses and fails without the change;Commitstill takes each destination mutex and the lock order (writersbefore the driver mutex) is unchanged. The after numbers address the earlier request. Merging; whichever of this and #2363 lands second rebases onto the other.