shader: resolve setpc dword jump tables whose load overwrites the selector #1485
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!1485
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1485/head"
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?
@overlordxrz-source on GitHub · 2026-10-13 19:53 UTC · original
overlordxrz-source:nhl-setpc-dword-aliased-selector→main· +55 −1 · 2 files · 1 commits · closed without mergingFixes the NHL 27 (PPSA34063, #1101) stop in compute shader
0xad738baf31b6e28b:The shader jumps through a dword offset table, and the table load writes back into its own index register:
ResolveSetpcDwordJumpTablerejected this because the selector and the loaded offset are the same register (selector_code == offset_code). That check isn't needed. A resolved table load goes intocode_table_load_pcsand isn't translated (IsCodeTableLoad), so at thes_setpc_b64the register still holds the selector.ScalarCodeWrittenInRangestill rejects any write between the load and the setpc. The qword resolver (ResolveSetpcJumpTable) never had this check.fozter found this and wrote the fix while investigating NHL 27 (shader dump: https://github.com/user-attachments/files/33356991/shader_0xad738baf31b6e28b_pr1446.txt). It's his patch, used with his permission (#1101), so he's the commit author. I turned it into a commit on current main and checked it.
Adds
TestNewShaderRecompilerSetpcDwordJumpTableAliasedSelector.Testing:
CFG::BuildGraph. The cases were the new test's shader words, the existing dword-table test shape, and a skeleton of the NHL shader's scalar code (same registers, the add with the literal first, a 23-entry table).unsupported dynamic S_SETPC_B64.0->0x30 4->0x38 8->0x30, and 23 cases for the NHL skeleton. The existing dword test is unchanged.-Wall -Wextra: no new warnings.tests/shaderCfgTests.cppbuilds with-fsyntax-only.shader_cfg_testsbinary here, so the IR/SPIR-V checks in the new test (dispatcher mode, noSLoadDword,OpSwitch, spirv-val) haven't been run locally.AI-assisted: yes. fozter's investigation and patch were done with Claude. I used AI to review it, write the harness and draft this text. I reviewed the change and ran the checks above.
@coderabbitai[bot] on GitHub · 2026-10-13 19:59 UTC · original
📝 Walkthrough
ResolveSetpcDwordJumpTablenow accepts a scalar selector that uses the same register as the jump-table load’s byte offset. It continues to reject non-scalar selectors and selectors overwritten between the load andS_SETPC_B64. A regression test checks dispatcher lowering, target mappings, IR output, and SPIR-V validity.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
2dfabShaders whose jump-table load overwrites its own selector register now compile. If a branch target later reads that register, it could see the selector instead of the loaded word. The risk is narrow, but it should be resolved or explicitly accepted before merge.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 too large.)
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.@coderabbitai[bot] on GitHub · 2026-10-13 19:59 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
c7119d66-cd8e-4004-b1ae-91d3b3809dae📥 Commits
Reviewing files that changed from the base of the PR and between
df5b9b92beand2dfab0d50b.📒 Files selected for processing: 2
src/graphics/shader/recompiler/frontend/cfg/ShaderCFG.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.
@ -469,2 +469,4 @@return false;}// The load may overwrite its own index register (s_load_dword s19, s[22:23], s19): code-table// loads are not translated, so the register still holds the selector at the S_SETPC_B64.@coderabbitai[bot] on GitHub · 2026-10-13 19:59 UTC · original
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 20140
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41496
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41873
Preserve the loaded value when the aliased register remains live.
Translate.cppskips every code-table load before callingTranslator::TranslateInstruction. A normal SGPR read andReadScalarCodeboth return the currentir.GetScalarRegvalue. Therefore, a target that reads the aliased register can observe its pre-load selector value instead of the table word.Reconstruct the loaded word for later reads, or reject this shape when the aliased register remains live.
@overlordxrz-source on GitHub · 2026-10-14 19:34 UTC · original
@coderabbitai This isn't new to the aliased case. On main, every resolved dword table load is skipped the same way (
IsCodeTableLoadin Translate.cpp), so in the non-aliased shape the offset register is never written either and a target that read it would see whatever was there before. The patch only drops theselector_code == offset_coderejection; it doesn't change what the targets see. Neither the NHL 27 shader nor the existing tests read the loaded word after thes_setpc_b64(it's only used for the address). If a title turns up that does, the fix is to write each case's table word into that register at the start of its target, for every dword table, as a separate change.AI-assisted: yes
@coderabbitai[bot] on GitHub · 2026-10-14 19:35 UTC · original
🧩 Analysis chain
🏁 Script executed:
Length of output: 22062
@overlordxrz-sourceYou’re right.Translate.cppskips code-table loads without an alias-specific condition. The diff only removes the alias rejection and retainsScalarCodeWrittenInRange. The new test’s targets do not read the load destination.The missing loaded-word value is an existing limitation, not an alias-specific regression. I withdraw this concern for
#1485. Thanks for the clarification.If a shader needs the loaded word after the jump, that needs a separate fix for all resolved dword tables. Would you like a follow-up issue for that limitation?
✏️ Learnings added
You are interacting with an AI system.
Pull request closed