fix(shader): link table calls whose descriptor comes from another buffer #14296
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14296"
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 ycbuzi on 2026-11-01T07:04:08Z.
What
FindTableCallslinks a compute shader'ss_swappc_b64when its target comes from a call table, but only when the table's descriptor is loaded through a pointer withs_load_dword*. Marvel's Spider-Man Remastered (PPSA01467) loads that descriptor one level deeper, from another buffer, so the call stayed unlinked and the shader was refused (#14168):FindTableCallsnow follows that one extra level and records its offset inTableCall::nestedDescriptorOffset. The nested load needs an immediate, dword-aligned offset and no register offset; anything else stays refused as before.ReadTableCalleesreads descriptor A, checks that the offset fits inside A's buffer, and reads descriptor B from it. The rest of the linking is unchanged.The limits are in
docs/dev/debt/libSceAgcDriver.md: one level only, and the descriptor is read once at link time.This is not a full fix for the title. It moves past this stop to later ones, listed under Tested.
Tested
Windows 11, Ryzen 9 7900, Release, WinLibs GCC 15.2.0.
Tests on the commit before this PR and on this PR, same machine,
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, run throughctest -Vfrom a non-elevated process. A control test (agc_driver_vertex_fetch) proved the layer loaded on both sides (43 layer log lines), and no log has the missing-layer line.Tests:
agc_driver_compute_fs_table_calls,agc_driver_compute_table_calls,agc_driver_compute_nested_table_call,agc_driver_prepared_shaders,scalar_call. The new execution test was kept on the base side as a negative control.VUID-lines, both sidesagc_driver_compute_nested_table_callfailsagc_driver_compute_nested_table_callfailsThese ran before a final rebase onto current
main. After the rebase I reran the same five tests withANYPS5_REQUIRE_VULKAN=1on the 4070 only, without the layer, and they pass.Marvel's Spider-Man Remastered (PPSA01467, 01.008.001), RTX 4070 SUPER, NVIDIA 616.92,
APS5_PLAYGO_UNLISTED_CHUNKS=installed, a backport's fake-signedeboot.binwith the game's own data. A script pressed the buttons and nobody played. The only library swapped islibSceAgcDriver.prx.computed/data-dependent s_swappc_b64 call target at program counter 0x0000136c is not statically resolvableread-write alias of shared guest memory 0xb126960000+0x40000: a resident run of direct memory extends outside the rangeGetImageResource dword 0 is not a valid runtime valueThe
s_swappc_b64refusal does not appear in either run with this PR, and it was logged in every earlier run without it. Those two later stops are different from each other, and I have not looked into either. I did not check the picture, and the frame rate is still under 4 FPS.The game's table contents were not inspected beyond linking succeeding, and no other title with this shape was tested.
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.mdfiles or images added to the repository (attach them to this PR)#8140 changes the same call-linking code (
FindTableCalls,LinkCallsandShaderRegistry.cpp) for a different refusal, a callee that reads its program counter. Whichever lands second will need a small merge.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T06:37:40Z.
Review: COMMENTED
Reviewed — no blocking findings
Table calls whose descriptor is loaded from a buffer, which itself came through the table pointer, are now followed one level: the recompiler's
FindTableCallsrecords a nested descriptor offset, andReadTableCalleesreads the nested descriptor once at link time. The bounds checks I read come before each read. The new unit check and the execution test did not run on this head, so the behaviour is not verified by any run.What I ran
46dc30ea75b06c5f56ba5486c0119d53c7996181; baseb41526345185943c53af0c6eee97863df4389c9e. 6 files, +148/-3:ShaderRegistry.cpp(+5: the nested read inReadTableCallees),ControlFlow/src/GraphBuilder.cpp(+21/-3: the nested descriptor search inFindTableCalls),ControlFlow/include/ControlFlow/GraphBuilder.hpp(+1: anestedDescriptorOffsetfield),core/libs/tests/ScalarCall.cpp(+17:CheckNestedTableCall),tests/execution/ComputeNestedTableCall.cpp(+106, not read in full), anddocs/dev/debt/libSceAgcDriver.md(+1).descriptor < innerLoadedis tested beforedescriptor - innerLoaded; the inner load's size and offset are checked; the outer pointer must be 4-dword aligned; the nested offset isinner.memoryOffset + (descriptor - innerLoaded) * 4; andReadTableCalleeschecks that offset against the outer descriptor's size before it reads.CheckNestedTableCall) and the debt entry.findLastWriter,reachingWriter,sameBlockand the execution test. The analysis is not traced beyond the lines in the diff.Build,windowsand bothrelinkerjobs passed. The Windows CTest run reports one case (100% tests passed, 0 tests failed out of 1), soCheckNestedTableCalland the execution test did not run.Results
ReadTableCallees(read)findLastWriter,reachingWriter,sameBlock)CheckNestedTableCall(scalar unit check)ComputeNestedTableCall(execution test)Read-only check output
Precheck was not run: no PR-head code is run here. Diff check: passed. Conventions: passed. ABI audit: not applicable. Stack check: passed. Hosted:
gh api repos/boykopovar/AnyPS5/commits/46dc30ea75b06c5f56ba5486c0119d53c7996181/check-runs, and the Windows job log.Negative control
Not run here. A negative control needs a local build and run, and code from this head is not run here.
Findings
Blocking
None, as far as the code read here goes.
Non-blocking
CheckNestedTableCallandComputeNestedTableCalldid not run on Windows, and this head has no Linux run. A run of theScalarCalltest (which callsCheckNestedTableCall) and of the execution test on a GPU host would show whether the path works.Sources
github.com/boykopovar/AnyPS5@46dc30ea75/core/libs/prx/libSceAgcDriver/Execution/src/Driver/Shaders/ShaderRegistry.cppgithub.com/boykopovar/AnyPS5@46dc30ea75/core/shader/recompiler/ControlFlow/src/GraphBuilder.cppgithub.com/boykopovar/AnyPS5@46dc30ea75/core/libs/tests/ScalarCall.cppgithub.com/boykopovar/AnyPS5@46dc30ea75/docs/dev/debt/libSceAgcDriver.mdwindowson46dc30ea75Not verified
findLastWriter,reachingWriter,sameBlock) and whether the nested search is sound on every path.ComputeNestedTableCall(not read in full).To get this to a good state