fix(agc): share the code of registrations of one program #10685
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10685"
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 milescoviello on 2026-10-24T17:45:19Z.
What
Every shader registration keeps a
ShaderSnapshotwith a copy of its program's code, and a program registered through several headers kept one copy per header. In Ghost of Tsushima (PPSA02225) that adds up: 172 s in, the registry held 94,000 snapshots at 14,321 code addresses, with 185.8 MiB of code of which 43.0 MiB was distinct (counted by a local diagnostic over the live registry, numbers below).A snapshot's
codeis now aSharedCode: a shared, immutable buffer that reads like thestd::vector<std::uint32_t>it replaces (data(),size(), iteration,==, conversion toconst std::vector&, andstd::spanbuilds from it).RegisterShaderalready compares a new snapshot's code with the snapshots registered at the same code address. When the words are equal, the new snapshot now takes that snapshot's buffer, so all headers of one program share one copy. Equality checks the buffer first, so later comparisons between snapshots of one program no longer compare the words.How
ShaderRegistry.hpp:SharedCodeholds astd::shared_ptrto the words. Writes go throughMutable(), which copies a buffer that is already shared, and throughresizeandassign. There is no non-constdata(), so a span over a non-const snapshot can't copy by accident. Snapshots are published asshared_ptr<const ShaderSnapshot>, so a published buffer is never written.ShaderRegistry.cpp: the second pass over the code address's snapshots inRegisterShadertakes the buffer of the first snapshot with equal code, then looks for an equal registered state as before. The raw-shader reader andRegisterShader's copy from guest memory write throughMutable().PreparedGraphics.cpp(a test fixture) grows its code throughMutable().Tested
Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, NVIDIA 615.71.09, on
maindc9f1ef656.SharedCodeHeadersinagc_driver_prepared_shadersregisters a vertex and a mesh header over one program and now also requires their snapshots to share the code buffer. With the sharing step removed (a mutant), theindirect,uncachedanddebugmodes, which run that test, fail 3 of 3:two headers of one program keep separate copies of its code.ShaderSnapshot(register_key|_submit|alpha_to_coverage|1555|565|dual_source|packed_|pipeline_journal|prepared_|program_writes_memory|reversed_order|sample_multisample_target|vertex_clip_cull|^agc_driver_graphics$|lazy_resolved|draw_cache): 76 of 76 pass 3 of 3 on this head (4f15f29b42) and onmain.maindc9f1ef656vs this head: the same pattern matches 77 tests there, and they pass 3 of 3 on each side (agc_driver_packed_float16_nativeskips on that GPU).22d82e41c4merged ontomain65c2713b6c(no conflicts), the 28 tests of the four changed test sources,ctest --repeat until-fail:2: 28 of 28 in both runs on a GeForce RTX 4070 SUPER and a GTX 1650 SUPER (NVIDIA 616.92) and on an AMD Radeon RDNA2 iGPU (1002:164e, AMD 32.0.21030.2001). These tests don't build againstmain'sShaderRegistryfiles, so there is nomainarm.mainand on this head: 76 of 76 pass on each, with no layer-missing line. Both report the same 14VUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605, and none is new in the head.got/g14, my local stack of open PRs that gets the title through its opening, plus that diagnostic; B is A plus this change. 16 GB cap, warm cache, both runs end at the cap.At 94,000 registrations that is 132.8 MiB less code held, one buffer per code address. The 10,862 distinct programs among those 14,321 addresses come to 43.0 MiB, so interning across addresses would save about 10 MiB more; this change keeps to one address. The heap profile that pointed here had
RegisterShaderholding 295 MiB live 900 s into the opening, 197.5 MiB of it these code copies.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 MarcZX10 on 2026-10-24T19:27:33Z.
Review: APPROVED
Reviewed exact head
4f15f29b4215be2105bbad01a9447ffbf130e6be.SharedCodeshares an immutable code buffer only after equal code is found for the same code address;Mutable()copies when storage is shared, so construction/raw reads can still write before publication and later edits detach safely. Registered state reuse remains separately gated by shader type and register equality. The new regression checks that two headers over one program share their code while retaining distinct registered states.git diff --checkand conventions pass. The PR reports 76 focused AGC tests passing 3/3 on both Linux and Windows with validation, plus title measurements showing the expected memory reduction; I did not rerun the GPU tests locally. Hosted policy checks pass; product jobs are skipped by the current intake policy.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:23:50Z.
Review: APPROVED
Reviewed the full diff at
4f15f29b42. SharedCode provides copy-on-write mutation for unpublished snapshots and shares immutable words only after equality at the same code address; the test asserts two headers over one program share storage while retaining distinct registered state. The author reports a mutation control failing without the share step, 76 focused tests passing repeatedly on Linux and Windows, matching validation-layer results, and live Ghost of Tsushima registry measurements reducing code storage by 132.8 MiB at 94,000 registrations. Hosted eligibility, conventions, intake and labels pass; product jobs were skipped by path policy. I found no correctness blocker in the reviewed ownership/mutation paths.