fix(agc): read unregistered graphics programs beside registered shaders #5751
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5751"
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 NaitikJoshiPro on 2026-10-14T09:19:32Z.
What
Since
39fdc48b5, an unregistered (raw) graphics program is read only while the shader registry is empty. Once any shader is registered, every draw of a program outside the registered code throwsgraphics program does not belong to a compatible registered shader.RegisterShaderalso throws after the first raw draw anywhere.Compute dispatches don't have this restriction: they resolve a registered program by its registration and read any other address raw. Some titles need both kinds of program. Homebrew built on the oops-sdk does: its display path (
src/agc/agc_display.c) registers its shaders throughsceAgcCreateShader, and radeonsi (oops-mesa) submits raw programs for every GL draw. SuperTuxKart (STKT00001, project-oops/oops-apps) stops at its first GL draw with the error above.Fix. Graphics programs now resolve the way compute does:
RegisteredProgram.The concern behind the old
RegisterShadercheck stays covered. A draw keeps a raw snapshot that the draw cache revalidates by reading it raw again, so a registration over the same code would give one program two identities. The code range of every raw program that is drawn is recorded, andRegisterShaderthrows only when the new shader's code overlaps one of those ranges (a shader was registered over a graphics program that was drawn without registration). Registrations elsewhere are accepted. The range is recorded once per raw snapshot: a flag on the snapshot keeps later decodes of the same program off the lock, so the decode path takes no new lock after a program's first draw. Recorded ranges are merged when they overlap or touch, so the check at registration looks only at the predecessor of the queried end.Concrete case.
agc_driver(testProgramSnapshots) now resolves a raw address while another shader is registered. On currentmain,ProgramSnapshotthrows for that address. The test also checks that a registered program requested as another type is still refused, and checks the range bookkeeping with nested, overlapping and adjacent ranges.agc_driver_prepared_graphicsused an address outside every registration as its invalid case; it now registers the draw's programs as compute shaders, which is still refused.agc_driver_prepared_unregistered_graphicsnow checks that the raw-drawn ranges are recorded exactly, starting at the program and not before it, and that unrelated code doesn't count as drawn raw. Before, it checked that any later registration was refused.Tested
main(ab9a47684; the commits since then touch only the relinker and CI tools) withANYPS5_REQUIRE_VULKAN=1.agc_driver,agc_driver_prepared_graphics(and its_prebuild_unset,_prebuild_0and_prebuild_1variants) andagc_driver_prepared_unregistered_graphicspass: 6 of 6, no skips. The workflow is fork-only and is not part of this PR.main, SuperTuxKart stops earlier than this draw:sceAgcInit(state, version)(#5163), plus PM4 and register states radeonsi uses that the driver still refuses. So this change on its own unblocks no title.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 CnRJay on 2026-10-14T19:41:22Z.
Review: COMMENTED
Letting raw programs coexist with registered ones, and narrowing the
RegisterShaderrefusal to overlapping code, is a sensible rule. Two problems before this can be judged:agc_driver,agc_driver_prepared_unregistered_graphicsandagc_driver_prepared_graphicshaven't been run on any configuration this repository ships. Please run them on Linux or Windows (CI on your fork is enough) and say so. A SuperTuxKart result on the Metal port is evidence for the port, not for this tree.NoteRawGraphicsDrawwas a relaxed atomic store. It now takesrawGraphicsMutexand does astd::mapinsert fromDecodeGraphicsPrograms, which runs on every draw-decode miss of an unregistered program. With radeonsi-on-oops, the case this PR is for, every GL program is raw, so every queue worker that decodes serializes on that lock. The range only needs recording once per program: doing it where the program is first read raw (ReadRawShader), or behind a flag on the snapshot, keeps the decode path lock-free as it was.RawGraphicsDrawnInalso walks every recorded range belowend. It should useupper_boundand look at the predecessor, as the other range maps in the driver do. It only runs at registration, but it is linear in the number of raw programs.Imported from boykopovar/AnyPS5. Originally posted by NaitikJoshiPro on 2026-10-15T00:54:52Z.
Rebased on
mainand changed:agc_driver,agc_driver_prepared_graphics(with its three_prebuild_*variants) andagc_driver_prepared_unregistered_graphicspass on Linux x86-64 with lavapipe (llvmpipe, LLVM 20, GCC 14,ANYPS5_REQUIRE_VULKAN=1, no skips): https://github.com/NaitikJoshiPro/AnyPS5/actions/runs/38661687268. The first lavapipe run caught a real gap.agc_driver_prepared_graphicsused an address outside every registration as its invalid case, and that address is now read raw. The test now registers the draw's programs as compute shaders, which is still refused (PreparedGraphics.cpp). The Metal port already carried that test change, but it was missing from this PR.NoteRawGraphicsDrawreturns after one acquire load once the snapshot's newrawGraphicsNotedflag is set (ShaderRegistry.hpp,ShaderRegistry.cpp), so the mutex is taken only on a program's first raw draw. I put the flag on the snapshot rather than recording inReadRawShader.ReadRawShaderalso serves compute programs and the null pixel program, and neither should block a later registration.RawGraphicsDrawnIn. Ranges are merged on insert when they overlap or touch. The lookup islower_bound(end)plus the predecessor, so it costs O(log n).agc_drivergainstestRawGraphicsRangesfor nested, overlapping, adjacent and empty ranges (tests/Submit.cpp).The description's testing section is updated.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:09:08Z.
Some 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/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppcore/libs/prx/libSceAgcDriver/tests/Submit.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/DrawDecode.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T12:32:37Z.
Checked the diff against
main: graphics programs now resolve like compute (registered address → its registration, other type still throws; anything else raw), andRegisterShaderrefuses only when the new code overlaps a raw-drawn range. The per-snapshot flag keeps the decode path off the mutex after a program's first draw, and the range lookup islower_bound+ predecessor.Built and ran the libSceAgcDriver scope on the merged tree:
agc_driver,agc_driver_prepared_graphics(+ prebuild variants) andagc_driver_prepared_unregistered_graphicspass; without the change the new tests don't build. Onlyagc_driver_tessellationfails, and it also does onmain. Windows not run here; merging after the full Build is green.