Skip to content

fix(agc): share a registered shader's decoded state with its other headers - #9991

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/share-registered-state
Oct 24, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
milescoviello:fix/share-registered-state

Conversation

@milescoviello

@milescoviello milescoviello commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Ghost of Tsushima Director's Cut (PPSA02225) registers shaders about 400 times a second during its opening. It registers the same code with the same registers over and over, each time through a header at a new address. Every registration decodes the header's registers into a RegisteredShaderState, three dense register sets of about 10 KiB, and its snapshot keeps that copy for as long as the registry holds it. In 200 s the title made 80,000 registrations: none matched a published snapshot's header address, so all 80,000 were published, and 68,144 of them (85 %) repeated the code and decoded registers of a snapshot at another header address. Only 11,856 were distinct. A jemalloc profile at 240 s put about 1 GiB of live heap under RegisterShader's register sets (InitialContextRegisters copies, the Registers built from the user-config initializer, Registers::mark). This title's opening is where the 20 GiB memory cap ends my runs.

How

  • A new snapshot takes the RegisteredShaderState of a published snapshot at the same code address with the same type, the same code and equal decoded registers, instead of keeping its own copy. The lookup runs under the registry mutex, next to the existing same-header check.
  • RegisteredShaderState gets a defaulted operator==; Registers already compares by entries.
  • The state is immutable once published (shared_ptr<const RegisteredShaderState>), and its users copy it into a QueueState before using it. Registers::Fingerprint's cache is only written on those live copies.
  • The preparation is not shared. Its request carries the header bytes and address, and this title's headers at other addresses hold other pointers.

Tested

Ubuntu 26.04.1, GCC 15.2, NVIDIA RTX 4070 Ti (615.71.09).

Ghost of Tsushima Director's Cut (PPSA02225). main can't take this title past its first minutes, so these runs use @EagleBearerYS's test/ghost-9742-9717 stack with #8115, #8121, #8213, #8608 and #9318, built from release libs with and without this change, plus a local counter of registrations. Each run is warm, 200 s, with a 20 GiB cap. Both builds see the same registration stream: 90,000 registrations, 76,792 of them (85 %) repeating another header's code and registers, and 13,208 distinct.

run this change RssAnon at 100 s RssAnon at 190 s
S1 yes 3,100 MB 4,632 MB
R1 no 4,987 MB 5,319 MB
S2 yes 4,202 MB 4,664 MB
R2 no 4,982 MB 5,284 MB

That's about 650 MB less at 190 s, and more earlier, where the registrations are densest.

Tests

  • agc_driver_prepared_shaders's shared-code case now checks the state at both points. While its two headers have different registers, they keep separate states. Once both are type 2 with the same code and registers, they hold the same state, with the header's context register in it.
  • With the sharing reverted and the test kept, agc_driver_prepared_shaders fails: "two headers with the same code and registers decoded their registered state twice".
  • The 25 tests matching ^agc_driver_prepared_shaders|^agc_driver_graphics$|^agc_driver_submit$|draw_cache pass 3 of 3.
  • Khronos validation layer 1.4.363, main against this branch over ^agc_driver_prepared_shaders|draw_cache: 24 of 24 pass on both, with no VUID on either. GCC 15.2 crashed (an internal compiler error in Pm4.hpp) building agc_driver_draw_cache_relocation_tests on the main side, so that one test ran from an earlier build there.
  • Windows 11 VM (GeForce GT 1030, NVIDIA R580, WinLibs GCC, Release, ANYPS5_REQUIRE_VULKAN=1): the same 25 tests pass 3 of 3 on this branch and on its merge base.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: NVIDIA RTX 4070 Ti (Linux); NVIDIA GeForce GT 1030 (Windows); NVIDIA GeForce RTX 3080, driver 617.42, Windows 11 (@VakzOs)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

…aders

Every registration decodes the header's registers into a
RegisteredShaderState: three dense register sets, about 10 KiB, kept by
the snapshot for the life of the registry. A title that registers the
same code with the same registers at another header address got a copy
each time. Ghost of Tsushima does that for 85 % of its registrations,
about 400 a second during its opening, so by 200 s 68,000 of its 80,000
snapshots held a copy of a state another snapshot already had.

A new snapshot now takes the state of a published snapshot at the same
code address whose type, code and decoded registers are equal. The state
is immutable once published, and its users only copy it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head e118657. The implementation shares only immutable decoded register state across snapshots with the same code address, type, code bytes and decoded state; prepared state remains per snapshot. I found no correctness issue in the diff. The focused regression checks both non-sharing when registers differ and sharing after they match. The PR reports 25 focused tests passing 3/3 and matched main/change validation runs with no VUIDs.

Eligibility, conventions, intake, labels and report checks pass. The hosted product build jobs are skipped, and I have not run the GPU tests locally because this environment has no Vulkan device.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 5115 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp
PR 5431 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6188 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 6867 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp
PR 6977 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp
PR 7682 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 8140 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 8592 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9431 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9432 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp
PR 9672 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9673 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9674 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9675 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9676 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9842 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9891 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9892 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9893 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 9895 core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Execution/include/Driver/Shaders/ShaderRegistry.hpp
core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cpp
core/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cpp

@milescoviello

Copy link
Copy Markdown
Contributor Author

Thanks @MarcZX10. The Windows run has finished since your review: on the Windows 11 VM (GeForce GT 1030, R580), the same 25 tests pass 3 of 3 on this head and on its merge base. It's in Tested now.

AI-assisted: yes (Claude Code)

@VakzOs

VakzOs commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Ran the same focused tests on main (6b2d6af) and on this PR (head e118657, tested as GitHub’s merge commit 2552be7 with that main) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, using ctest --test-dir build -R "^agc_driver_prepared_shaders$" -V.

GPU: NVIDIA GeForce RTX 3080, NVIDIA driver 617.42, Windows 11 Pro build 26200
main: 1/1 passed; 0 distinct VUID- messages
this PR: 1/1 passed; 0 distinct VUID- messages
Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS
New VUID- messages compared with main: none

@milescoviello

Copy link
Copy Markdown
Contributor Author

@VakzOs thanks for the validation-layer run on the RTX 3080. A clean pass against main on a second NVIDIA card and on Windows is useful. I added it to the GPU list.

AI-assisted: yes (Claude Code)

@oneandonlydean oneandonlydean self-assigned this Oct 23, 2026
@oneandonlydean
oneandonlydean merged commit c19d4a7 into boykopovar:main Oct 24, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants