shader: plan more indirect image table shapes #1118
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!1118
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1118"
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?
@NeySlim on GitHub · 2026-10-06 19:45 UTC · original
NeySlim:feat/indirect-table-shapes→main· +299 −4 · 5 files · 2 commits · openGod of War Ragnarök (PPSA08332) selects light and material textures through descriptor tables indexed by waterfall loops (
s_ff1over a lane mask), bounded loops and loaded selectors. Several of these shapes were refused by resource tracking (GetImageResource dword 0 is not a valid runtime value).Most of the original PR is now on main: wider records (
a287a54f2), the guard proofs (a287a54f2,25e1cc7ec,d70cbd418,ed1195d1,9a3aca96), shared descriptor reads (7e884f55), masked keys and pointer-backed selector tables (1fa79d5c). What is left:ff1(mask)) whoseff1(mask) != -1test is carried by the image's own EXEC predicate, rather than by a branch, is bounded like the branch-guarded form.index * stride + offset, withindexa zero-based loop counter bounded by a signed compare (s_cmp_lt_i32), becomes a pointer-backed selector read; a negative count runs no iteration.key * stride + offset, 32-bit), negative keys included. When every path from the key's load to the image crosses a uniformkey >= 0test, a negative key never reaches the image and its record is not a candidate.Tests
TestLaneGuardedBitScanTableandTestLoopSelectedSignedKeyinresource_tracking_tests(guarded, unguarded, unrelated, inverted andkey >= -1tests, a second unguarded sample, a negative count). Each fails when the rule it covers is removed.Validation
Linux, AMD Radeon 8060S, Mesa RADV 26.2.3, rebased on
9e41d832. CPU suites pass;shader_recompiler_compute_testsone case per process gives the same results as main (627 of 637; the same 10 fail on main on this setup). The game was checked with the earlier version of this PR; the planner accepted all of the compute and pixel shaders it compiles up to its first setup screen.Related work: #811 and #852 generalize the same planner for Horizon Forbidden West, and #1255 touches the same code; whichever lands second, I will rebase it.
Not tested on Windows or macOS; the change is platform-independent recompiler code.
AI use
The investigation, the code, the tests and this description were produced with Claude Code (AI agent) on my machine. I reviewed the diff and the results before submitting.
@coderabbitai[bot] on GitHub · 2026-10-06 20:04 UTC · original · edited 2026-10-19 04:56 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
4c52e2ff-356f-4478-8b7c-14bb21eb0859📥 Commits
Reviewing files that changed from the base of the PR and between d615e4ec43c2e525b3359aa792420a92d05325a9 and 65660f8d4c018fe182d0be6ab243377e401d55f9.
📒 Files selected for processing (3)
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.
📝 Walkthrough
📝 Walkthrough
Walkthrough
Resource tracking adds nonzero proofs across predecessor paths, lane-aware guard analysis, masked shifted-key matching, and bounded scalar-address selector recognition. It accepts qualifying reads that dominate handles, supports additional indirect image selector bounds, and reuses matching descriptor plans. Tests cover accepted and rejected lane-guard cases. Resource materialization reads scalar-pointer selector keys with probe and offset checks. Keys with the high bit set leave the candidate descriptor null without a descriptor-table read.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Feature
Merge Risk: ⚪ Minimal · up to
65660The described selector changes have no established outstanding issue in this review. They are mergeable after normal checks.
Pre-merge checks:
4 ·
1
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-06 20:04 UTC · original · edited 2026-10-06 21:18 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 374 (outdated):🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7390
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 542
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 12254
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8936
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8356
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4999
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4056
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6424
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7982
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3601
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6660
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10713
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2610
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6051
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7314
Normalize negative signed bounds before applying the probe limit.
BoundedLoopacceptsSLessThan32bounds and stores the bound askey_count. Evaluation preserves its U32 bit pattern, so a negative signed bound can exceed the probe limit before the later conversion to zero. This can make indirect-image materialization fail even though the zero-based loop has no iterations. Track the bound’s signedness and normalize only signed nonpositive counts; keep large unsigned bounds subject to the limit.🐛 Suggested fix
✅ Addressed in commit 4721ac4
@coderabbitai[bot] on GitHub · 2026-10-06 20:04 UTC · original · edited 2026-10-06 21:18 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1148 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8812
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21649
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19816
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5597
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3975
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6744
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5795
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7283
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10299
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8532
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 679
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2809
Insert masked keys after the block’s final Phi.
A masked key can be accepted in an indirect-image plan when its mask bound is below 64. If that key is a Phi with later Phis,
MaskedKeyinserts a liveBitwiseAnd32between them. The SPIR-V emitter calls its failure path when it reaches a Phi after a non-Phi instruction. Insert after the complete Phi group.A failed match does not roll back the insertion, but the claim that nothing later removes it is too strong:
CompileProgramruns another dead-code elimination after resource tracking. The accepted-plan path can keep the masked key live, so that cleanup does not prevent the ordering failure.Proposed fix
✅ Addressed in commit 4721ac4
@coderabbitai[bot] on GitHub · 2026-10-06 20:04 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
d43c5aac-3bd4-4aa3-ba36-cb1cf1979fab📥 Commits
Reviewing files that changed from the base of the PR and between
199d0a9d92and c5bc56e17bbb5cc6577ae0365bc2e22e1ac2fb24.📒 Files selected for processing (2)
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-06 20:27 UTC · original · reviewed
ℹ️ Review info
⚙️ Run configuration
f649e13a-517e-43f0-af40-e1d37e84c0c3📥 Commits
Reviewing files that changed from the base of the PR and between c5bc56e17bbb5cc6577ae0365bc2e22e1ac2fb24 and 39dfea39cd511664eadf4a889e2f553958de7152.
📒 Files selected for processing (2)
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppsrc/graphics/shader/recompiler/ir/passes/ResourceTracking.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-06 20:36 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
daa12953-4ccc-4343-909b-d12a5c29f91c📥 Commits
Reviewing files that changed from the base of the PR and between 39dfea39cd511664eadf4a889e2f553958de7152 and d645fdbc954bf8f7f2f91ee5a59766809b877d64.
📒 Files selected for processing (1)
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
@coderabbitai[bot] on GitHub · 2026-10-06 20:36 UTC · original · edited 2026-10-06 21:18 UTC
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1589 (outdated):🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Reject negative displacement in the matched selector offset.
If
read->Arg(1)adds-4andmemory->offsetis zero,MatchTableOffsetrecordsoffsetas0xfffffffc. The new check accepts the zero memory offset, and the combined offset passes the laterUINT32_MAXcheck. Materialization then reads a large positive offset instead of rejecting this selector plan. Check the sign of the matched immediate displacement before recording the selector.✅ Addressed in commit 54ee0da
@NeySlim on GitHub · 2026-10-06 21:18 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1148 (outdated):Good catch, fixed in 39dfea3: the masked key is now inserted after the block's whole Phi group, so a key defined by a Phi no longer splits it.
@NeySlim on GitHub · 2026-10-06 21:18 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 374 (outdated):Reordered in 39dfea3 to match the immediate-key path: the count is normalized to zero for signed nonpositive values first and the probe limit is checked afterwards. I kept the existing "normalize then limit" semantics rather than adding a signedness flag, so an unsigned count above 2^31 is also treated as empty, as it already is for immediate keys; that case has no practical shader shape.
@NeySlim on GitHub · 2026-10-06 21:18 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1589 (outdated):Agreed. d645fdb rejected a negative SMEM displacement and 54ee0da also rejects a negative shader-side immediate and a sum above
INT32_MAX, since the materializer adds both unsigned.@coderabbitai[bot] on GitHub · 2026-10-06 21:18 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1148 (outdated):@NeySlim, thanks for the fix.MaskedKeynow insertsBitwiseAnd32after the complete Phi group, which addresses the ordering issue.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-10-06 21:18 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceTracking.cppline 1589 (outdated):@NeySlimThanks for the clarification and fix.MatchLoopSelectedKeynow rejects negative SMEM displacements, negative matched shader-side displacements, and combined offsets aboveINT32_MAX. These checks address the reported case.✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-10-06 21:18 UTC · original
On
src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cppline 374 (outdated):@NeySlim, the supplied code now normalizes nonpositive signed counts before checkingMaxIndirectDescriptorProbes. This addresses the ordering issue.Thanks for clarifying the intended semantics. Keeping the immediate-key behavior is reasonable for the supported shader shapes; a signedness flag is not needed for this fix.
✏️ Learnings added
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
@NeySlim on GitHub · 2026-10-07 14:44 UTC · original
Pushed d615e4e with two fixes found while testing this branch on God of War Ragnarök (PPSA08332):
TestGuardedDirectImageTablefailed on this branch: itsExecZeroandVccZerovariants were accepted becauseEdgeProvesNonzerono longer required an all-lanes edge. The requirement from main is back, and the test passes again.Two bit-scan loops still failed with
GetImageResource dword 0 is not a valid runtime value, because their guard is built withs_cselect_b64 <mask>, exec, 0:0x3352cea59e15e2f2: the loop exits ons_cbranch_vccnzwithvcc = ((ff1 >= n) || (ff1 == -1)) && exec;0x25e7d7d6b79a016f:s_cmp_lg_u32 -1, ff1; s_cselect_b64 s8, exec, 0; s_mov_b64 exec, s8.The texel only reaches registers through
SelectU32(lanes, component, old).ObservedLanesreturns that common lane predicate, and the key is accepted when either:ff1 != -1oncelanesis known true (lanesimplies the EXEC term of the guard), orlanesitself containsff1 != -1(the second shader).Lanes that never observe the texel do not matter: a key outside the mapping falls back to the root resource.
Tests (
resource_tracking,resource_materialization): newTestGuardedDirectImageTablevariants.LaneExitandLaneMaskare accepted.LaneUnobserved(texel not masked),LaneUnrelated(predicate unrelated to EXEC) andLaneAny(any-lane edge) are rejected. WithoutObservedLanes,LaneExitandLaneMaskfail with the original error.AI use: investigated, written and tested with Claude Code (AI agent) on my machine; I reviewed the diff and the results.
@NeySlim on GitHub · 2026-10-09 19:53 UTC · original
Rebased on main (
59183dbf), squashed into one commit (65660f8d) since every commit conflicted with the reworked planner. Main now forwards the loop increment through a synthetic continue block inBoundedLoop, so I dropped that part and kept main's version. The rest sits on main's structures: the bit-scan proof no longer needsblock_info, the twin-handle reuse runs inside the new per-handleplan_handleloop (images and samplers),TryMakeFiniteDescriptorreplacesTryMakeFiniteImage, and the wider-record bound sits next to main'sMatchScalarMaterialKeybranch.resource_trackingandresource_materializationpass; the lane-guardedTestGuardedDirectImageTablevariants fail with main's tracking and pass here. Full GPU suite, one case per process: 602/612, same as main.@NeySlim on GitHub · 2026-10-09 20:38 UTC · original
Pushed 5114cc1: a negative selector value no longer binds a null descriptor.
In God of War Ragnarök (PPSA08332) the only negative key comes from pixel shader
0xb466313c9f94f942, where -1 is a "no texture" sentinel that the shader tests before the descriptor read:Changes:
selector_nonnegativewhen every path from the key's load to the image crosses a uniform edge that proveskey >= 0(signed compares with an immediate, throughLogicalNotand conjunctions). Materialization then drops negative keys, since the image never runs with them.(key * stride + offset)in 32 bits. An unreadable record fails specialization as before.InternSourceor a twin handle keeps the flag only if every use is proven.Tests:
TestLoopSelectedSignedKeycovers the guarded key (no candidate for -1) and four cases without a valid proof (no guard, unrelated value, inverted guard, a second unguarded sample of the same table), where -1 reads the record before the table. Both halves fail on the previous commit.resource_trackingandresource_materializationpass, and the GPU suite (one case per process) gives 602 of 612, the same as main. In the game, all 13 loop-selected tables compiled up to the setup screen get the proof, and the game still reaches gameplay with correct rendering.AI use: investigated, written and tested with Claude Code (AI agent) on my machine.
@NeySlim on GitHub · 2026-10-11 18:18 UTC · original
Rebased on main after
4c87dbeb; the only conflict was a test fixture (ImageSampleRawnow takes the EXEC operand), no change to the planner.resource_tracking,resource_materialization,scalar_provenanceandshader_cfgpass, the guard-proof tests still fail when their rules are removed, and the GPU suite one case per process gives 613 of 623, the same as main.@NeySlim on GitHub · 2026-10-14 07:05 UTC · original
Rebased on main. Most of this landed in
1fa79d5c,7e884f55,ed1195d1and9a3aca96; what is left is the bit scan bound carried by the image's EXEC, the signed loop count and the negative-key proof. Added a key >= -1 case to the test.@NeySlim on GitHub · 2026-10-14 07:16 UTC · original
Correction to my last comment: the parts that landed are
a287a54f2,25e1cc7ec,d70cbd418,ed1195d1,9a3aca96,7e884f55and1fa79d5c(body updated).@Ekt0re on GitHub · 2026-10-26 15:59 UTC · original
Hi, I was looking at this pull request, and I see it's very interesting. How's it going? Have you made any recent updates or achieved any new results?
@NeySlim on GitHub · 2026-10-26 16:06 UTC · original
No updates, I've stopped working on this. Most of it landed on main already; the branch stays open if anyone wants to pick up the rest.
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.