shader: link compute calls through function tables, fix call-target crash (PPSA01473) #1849
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1849
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1849"
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?
@MrBigBritches on GitHub · 2026-10-22 22:24 UTC · original
MrBigBritches:rift-apart-shader-calls→main· +864 −120 · 18 files · 2 commits · openFixes a fatal assert when preparing
S_SWAPPC_B64call targets in compute shaders (seen at startup in Ratchet & Clank: Rift Apart, PPSA01473). Also adds experimental, off-by-default support for calls whose target is read from a function table at an entry selected by GPU data.Crash fix
FindScalarDefinitionasserted when more than one write reached a call-target register. For example, a callee address is loaded before a loop and reloaded on the back edge.CFG::FindScalarDefinitionsnow returns every reaching definition, sorted and de-duplicated.MayWriteScalarRegisterassumed lane reads and wave32 lane masks write an SGPR pair, which produced false "multiple definitions". These now write one SGPR, and wave32 programs passwave64 = false.Function-table calls (experimental)
Some shaders run a waterfall loop that reads the callee from a GPU buffer at
readfirstlane(index) * strideand calls it withS_SWAPPC_B64.PrepareCallTargetsrecognises this pattern (MatchCallTable).RefreshShaderSourcereads the table in 1 MB chunks and links each distinct callee once.S_GETPC_B64reads of constants embedded in its code are still allowed (Program::native_bytes). PCs inside linked code are still rejected.function_table_callsconfig option:--function-table-callson the command line;Robustness for large linked programs
Tracker::CollectScalarReadis now iterative.Common::RunWithStackruns work on a thread with a large stack:CreateThreadon Windows;pipelineCachetranslates and compiles linked programs on a 256 MB stack.Testing
TestFunctionTableLeafCallcovers:shader_cfg_testsandmemory_tracker_testspass (Windows, clang-cl).RunWithStack's POSIX path was checked on Linux with a standalone deep-recursion test. It has not been built on macOS.@coderabbitai[bot] on GitHub · 2026-10-22 22:31 UTC · original · edited 2026-10-22 23:59 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
39a60125-e6f7-4920-8b0d-8bc201f3bbe9📥 Commits
Reviewing files that changed from the base of the PR and between
f1d24de936andb9d283ca19.📒 Files selected for processing: 2
src/graphics/shader/recompiler/ShaderRecompiler.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
📝 Walkthrough
The change adds a disabled-by-default option for linking shader calls whose targets come from supported function tables. The recompiler tracks multiple reaching definitions, reads and refreshes table entries, and builds dispatchers for distinct callees. The launcher and command line expose the option. Linked shader translation and compilation use a temporary thread with a larger stack. The change also replaces recursive scalar-read collection with an iterative traversal and adds function-table linking and refresh tests.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
b9d28Unsupported GPU-selected call targets now take the dispatch-skip fallback rather than stopping the emulator. No actionable merge-blocking risk remains after normal checks.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title names the two main changes: function-table call linking for compute shaders and a fix for a call-target crash (PPSA01473). The changeset matches both parts. The title is long at 85 characters, but it is specific and on-topic, so it passes.
Full details: Description check
Explanation
The description is detailed and on-topic. It explains the crash fix in FindScalarDefinition and MayWriteScalarRegister, the experimental function-table call support, the iterative Tracker::CollectScalarRead, the RunWithStack helper, the new config option and launcher checkbox, and the tests. This matches the file summaries.
Full details: Docstring Coverage
Explanation
Docstring coverage is 19.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 36 functions across 16 files. (1 skipped: 1 too large.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment
@coderabbitai helpto get the list of available commands.@ -568,0 +694,4 @@source.unsupported_call_pc = call.pc;source.calls.clear();return;}@coderabbitai[bot] on GitHub · 2026-10-22 22:31 UTC · original
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42329
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 38203
Replace the
ReadConstBufferassertion with the dispatch-skip fallback.This assertion existed before the PR, so the PR retains an existing crash path. When a non-runtime target is not a direct
ReadConstBuffer, route it tounsupported_call_pcinstead of asserting. Thefunction_table_callsoption cannot protect this path because the assertion runs first.🐛 Suggested fix
📝 Committable suggestion
@coderabbitai[bot] on GitHub · 2026-10-22 22:31 UTC · original · edited 2026-10-22 23:54 UTC
On
src/graphics/shader/recompiler/ShaderRecompiler.cppline 844 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Fix the per-chunk start index so boundary-crossing entries are scanned.
first_entryis the first entry whose start is at or afterchunk_start. The comment and the loop bound use the position of the target pair (entry + low_offset). Take an entryEwithE < chunk_start <= E + low_offset:E, becauseE + low_offset >= chunk_start.E, becausefirst_entryroundschunk_startup.Eis never read. This needs anIMul32stride that does not divideTableChunkBytes(for example 48),low_offset > 0, and a table larger than 1 MiB. A lost target makes the dispatcher fall through toreturn_pc, so the call is skipped without any message. Power-of-two strides are not affected.🐛 Proposed fix
atstays non-negative becauseentry + low_offset >= chunk_start.📝 Committable suggestion
✅ Addressed in commit
b9d283c@coderabbitai[bot] on GitHub · 2026-10-22 22:31 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
40a32c66-54ec-4d96-ba93-b3798fc15969📥 Commits
Reviewing files that changed from the base of the PR and between
79837b423dandf1d24de936.📒 Files selected for processing: 18
src/common/emulatorConfig.cppsrc/common/emulatorConfig.hsrc/common/threads.cppsrc/common/threads.hsrc/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/shader/recompiler/ShaderRecompiler.cppsrc/graphics/shader/recompiler/ShaderRecompiler.hsrc/graphics/shader/recompiler/frontend/cfg/ShaderCFG.cppsrc/graphics/shader/recompiler/frontend/cfg/ShaderCFG.hsrc/graphics/shader/recompiler/frontend/decode/ShaderDecoder.hsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppsrc/launcher/forms/configuration_edit_dialog.uisrc/launcher/include/configuration.hsrc/launcher/src/configuration.cppsrc/launcher/src/configurationEditDialog.cppsrc/launcher/src/mainDialog.cppsrc/main.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ZrDaniel07 on GitHub · 2026-10-31 03:36 UTC · original
A note for whoever continues the function-table work. On GT7 (PPSA01317, v01.680), with the call-target part of this PR ported to
main4919fdb6(currentmainhandles that crash withabd77f57), the drive starts. One call target is still left that neither can resolve, so its dispatch is skipped. It belongs to a compute shader that traces a batch of rays against a BVH. ItsS_SWAPPC_B64targets come from a hit-group table indexed by the instance each ray hits, so the callee is only known on the GPU. The decoded layout is in #1451: #1451.AI use: Claude Code read the shader and drafted this with me; I ran the game.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.