fix(agc): refresh relocated shader snapshot headers #5830
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5830"
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 MarcZX10 on 2026-10-14T12:49:27Z.
What
Fix shader ABI resolution when a title passes a relocated copy of a registered shader header. Once
SameHeaderverifies the copy, publish a snapshot keyed to its guest address and copy its complete header bytes, so later decoders interpret embedded pointers relative to the correct header base. Apply the same behavior to graphics-stage, static shader, and rectangle ABI resolution.This carries Nelson's fix from the previously intake-closed #2969, preserving the original commit author. The rebase keeps the newer unaligned-header test already on
mainalongside the relocated full-header regression.Fixes #2914.
Tested
cmake -S . -B /tmp/AnyPS5-2914-build3 -G Ninja -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Releaseconfigured successfully.cmake --build /tmp/AnyPS5-2914-build3 --target agc_driver_prepared_shaders_tests --parallel 4passed.python3 tools/check_conventions.py --base upstream/mainpassed.git diff --check upstream/main...HEADpassed.agc_driver_prepared_shaders*CTest cases. They all stop before test setup because this Linux host's Xeon E5-1620 v2 lacks AVX2, FMA, BMI1/BMI2, LZCNT and MOVBE, which the test runtime requires. I could not execute these cases on this host.Checklist
main; the earlier duplicate PR was closed during intake pauseImported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-10-14T19:18:12Z.
Review: COMMENTED
Decoding embedded header pointers against the copy the title actually passed is the right fix for #2914. The way the copy is kept costs more than it needs to, though:
std::make_shared<ShaderSnapshot>(*snapshot)duplicatescode, which is the shader's full program, not just the header.PublishRegisteredShaderthen builds a newShaderRegistry(a copy of the whole map, every registered shader) to publish it. That runs on everyResolveShaderAbi/ResolveGraphicsAbi/ResolveGraphicsStagesAbicall whose header address differs from the registered one. Those are reached fromsceAgcCreatePrimState,sceAgcLinkShadersand the interpolant-mapping calls. An engine that builds its state objects per frame or per material, from header copies in transient memory, would pay a registry copy per call.headerAddressor different code. A title that copies headers into a ring buffer or onto the stack publishes a new snapshot, with its owncodecopy, for every address it uses, and none is ever retired.The decoders only need the header bytes and their guest base. Passing those for the resolution, as a header view alongside the registered snapshot, would avoid touching the registry at all. If a published entry is really needed for later lookups by that address, the copy could share the original's
code(holding it byshared_ptr), and the entries could be bounded per code address.Also, as the description says, none of the nine
agc_driver_prepared_shaders*cases ran because the host lacks AVX2. These tests should run on a supported CPU before merging, since this changes what the registry publishes.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T02:09:49Z.
I ran two of the nine
agc_driver_prepared_shaders*cases,agc_driver_prepared_shadersandagc_driver_prepared_shaders_indirect, on a CPU with AVX2, since the description and CnRJay's review note they had not run yet. CI skipped its build jobs here, so this is the first run I know of. Both fail with this PR.Setup: Linux, x86-64 with AVX2, Mesa 26.2.4 lavapipe (llvmpipe, LLVM 23.1.1), default CMake build (CMAKE_BUILD_TYPE empty, unoptimized), clean environment.
ctest -R '^agc_driver_prepared_shaders(_indirect)?$', 3 runs each.3ea0132fbas submitted: 3 of 3 runs fail. Both tests stop at "AGC driver: shader metadata is outside the registered header".96dd64719), the new test lines kept: 3 of 3 pass, both tests.8cd937e29: same failure, 3 of 3. With ShaderRegistry.cpp left as on main and only the test lines applied: 3 of 3 pass.Where it stops (found with temporary prints, since removed): in
SharedCodeHeaders, at the existingAgcDriverResolveShaderAbi_nid_postfix(©, {}, primitive)call right aftercopy.user_data = nullptr;(line 391 on the PR head). That case was on main before this PR and passes there. Neither of the two calls this PR adds (relocatedlater inSharedCodeHeaders,fullCopyinRegistration) is reached. So the ShaderRegistry.cpp change breaks a case this test already covered.Separately, the two added calls do not fail without the change: with ShaderRegistry.cpp reverted, both tests pass with the new calls in place. They only check that the call does not throw, so as written they would not catch a regression of the fix.
I did not look into which part of the ShaderRegistry.cpp change causes it, did not run the other seven cases, and did not check Windows or macOS. The branch's merge base is 516 commits behind main at
8cd937e29.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:10:04Z.
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.cppL1215-1216Some 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/Shaders/ShaderRegistry.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppcore/libs/prx/libSceAgcDriver/tests/execution/PreparedShaders.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:22:03Z.
Review: CHANGES_REQUESTED
Thanks for carrying this over. Two blockers:
agc_driver_prepared_shaders,_indirect,_uncachedand_debugfail on the PR head (merged onto current main) withAGC driver: shader metadata is outside the registered header. They pass with theShaderRegistry.cppchange reverted, soRelocateSnapshotHeaderbreaks a case the tests already covered (Dextroid17 reports it stops at theAgcDriverResolveShaderAbi_nid_postfix(©, {}, primitive)call aftercopy.user_data = nullptr;inSharedCodeHeaders). Please reproduce on a CPU with AVX2 or in CI and fix.relocated(PreparedShaders.cpp:425-427) andfullCopy(:514-516) only check that the call doesn't throw, and they pass withShaderRegistry.cppreverted. Assert that the decoded header pointers resolve against the relocated copy (e.g. auser_data/ input semantic value read through the copy), and check the test fails without the fix.Also, as CnRJay noted:
ShaderRegistry.cpp:473-482copies the whole snapshot (includingcode) and republishes the whole registry on every relocated call, and entries per copy address are never retired. Passing the header bytes and base address to the decoders as a view, or sharingcodeand bounding entries per code address, would avoid that.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-15T23:43:12Z.
I looked into why
RelocateSnapshotHeaderbreaksSharedCodeHeaders. Same setup as my earlier comment (lavapipe, default unoptimized build, clean environment), on head3ea0132fb.What happens. At the call on line 391,
copy(declared on line 389) is a bareShader(96 bytes) copied fromvertex.shader. Itsheader_sizestill says 264, and itssh_registersstill points intovertex. A temporary print (since removed) inRelocateSnapshotHeaderand at the throw inReadHeaderArrayshowed a new base©of 0x7ffec62d4ec0, a registered base of 0x7ffec62d4f80,header_size264,sizeof(Shader)96, andsh_registersat 0x7ffec62d4fe0, which is 288 bytes past the new base.So the relocated snapshot takes
©as its base and copies 264 bytes from there, 168 bytes past the end ofcopy.DecodeRegisteredStatethen readssh_registers, which still points into the original header, 288 bytes past the new base and beyond the 264 bytes captured, andReadHeaderArraythrows "shader metadata is outside the registered header".Why it is not just this test. By reading
SameHeader(line 365) and its two fallbacks: the compare runs throughnum_sh_registers, the last field, so it covers everyShaderfield. The only ones allowed to differ areuser_data(always ignored),sh_registers(RelocatedRegisters, if the register values match) and, for a fused hull,typeand five register values (FusedHullHeader). So in every copySameHeaderaccepts,cx_registers,specials,input_semanticsandoutput_semanticshold the same values as the registered header and point into the original. Rebasing the whole snapshot onto the copy's address reads them against the copy's base, so they fall outside the captured bytes unless the original happens to lie withinheader_sizebytes above the copy. A copy with every non-null pointer moved into itself is rejected before that. I added one locally after therelocatedcall. With ShaderRegistry.cpp at the merge base, and on this head with the check below applied, it fails with "graphics ABI refers to a replaced shader header" (3 of 3 runs each). On this head as submitted, the test stops at line 391 first and never reaches it.A check that it is the rebase. With
RelocateSnapshotHeaderchanged locally to keep the registered snapshot unless all six metadata pointers are null or inside[shader + sizeof(Shader), shader + header_size), all nineagc_driver_prepared_shaders*cases pass, 3 of 3 runs. That is only a diagnosis, not a proposed fix. By reading, no call in the existing tests passes a copy whose pointers all point into itself, so with this check nothing relocates and the result matches the merge base.About #2914. The issue traces the crash to a fork change (
9ad1b82a) that updatedheaderAddresswithout re-reading the header bytes. NRAPM later replied there that the title still crashed on main after #2856. By reading the merge base, the snapshot is never rebased, so the decoders read the registered bytes against the base they were captured with. I could not run Astro's Playroom, so I can't say which read fails there now. If the title needs the copy's ownuser_data, that is the only pointer whose targetSameHeaderdoes not check. Reading that pointer against the copy, and the rest against the registered header (for example through the header view CnRJay and adriadam10 suggested), would avoid rebasing pointers thatSameHeaderrequires to stay in the original.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T01:01:22Z.
I am closing this submission because its implementation carries code from #2969, which was closed during the intake pause; the current contribution constraints prohibit reusing code from intake-paused PRs. Independent review also reproduced a regression in existing
SharedCodeHeaderscases and identified unbounded snapshot/registry copying, so this head should not merge. Issue #2914 remains open; any follow-up will be developed independently from currentmainand the issue evidence.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-16T01:01:24Z.
Closing this PR for the reasons above. This does not close #2914.
Pull request closed