shader: bound post-tested loop image tables by their start value (Guardians of the Galaxy, #1004) #1444
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!1444
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1444"
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-12 08:38 UTC · original
overlordxrz-source:fix/gotg-post-tested-loop→main· +163 −12 · 2 files · 1 commits · openGame: Marvel's Guardians of the Galaxy (PPSA01748), issue #1004.
Problem: With #1438 applied, the game gets past its first crash, shows a loading screen, and then stops at:
@hackerinfo89 traced it to this loop over a 16-entry T# table (his comment, plus the native IR he attached):
In the IR the key is
Phi [1, entry], [%1215, latch]with%1215 = IAdd32 %847, 1. The only way back to the header is the SCC true edge ofULessThan32 %1215, 16.BoundedLoop(BoundedLoopCountbefore429d0af6) only accepts a counter that starts at 0 and is tested against its bound before the body. So this handle gets no key range,TryMakeIndirectImagerejects it, and the image falls through to the failure above.Change:
ResourceTracking.cpp: addsBoundedPostTestLoop. It accepts a header Phi that enters at an immediatestart, haskey + 1as its back value, and whose only way back is the positive, all-lanes edge ofULessThan32(key + 1, limit)orSLessThan32(key + 1, limit), withstart < limit(andstart >= 0for the signed compare). The edge can be on the back-edge block itself (the synthetic continue block here) or on every path from the header to it. Then every value of the key is in[start, limit). That holds after the loop too, because the test runs after the body, so the use doesn't need a dominating guard. The direct image-table path tries it only afterBoundedLoop, and then recordsselector_first = startandkey_count = limit - start.ResourceMaterialization.cpp: the selector-less direct-table path now enumerates keys fromselector_firstwhen it is set, and its bounds check covers the last key. Before, it always started at 0. In this shader, table entry 0 is read separately after the loop at a constant offset, so the loop's table is exactly keys 1..15.Shapes that are not in the shader stay rejected: a runtime limit, a
!=exit, and any start at or past the limit.Tests:
TestPostTestedImageLoopintests/ResourceTrackingTests.cpprebuilds the shader's IR shape: start 1, limit 16, a synthetic continue block that carries the SCC branch, and the same eight descriptor reads sampled twice. Variants:ultfrom 1, from 0 and from 15, andsltfrom 1.Results:
resource_tracking_testspasses in full, built natively (aarch64 Linux, zig 0.17 clang).dad900c6): the new test fails with the reported error,pc=0x00000604 GetImageResource dword 0 is not a valid runtime value.The touched files also compile for x86_64-linux with zig.
clang-format23.1.3 withsrc/.clang-formatis clean on the changed lines.I couldn't run
resource_materialization_testshere: it JITs x86 code and dies with SIGILL on this aarch64 host, and unmodified main does the same. CI should cover it.Scope: this fixes the second stop only. It doesn't depend on #1438 (the files don't overlap), so it is based on main. hackerinfo89 also reported a third stop after this one (PS
0x4a260221f9feeae6, an SRT selected by a per-primitive material index). That one needs separate design work and isn't addressed here.Thanks to @hackerinfo89 for the analysis, the logs and the full shader dump.
AI-assisted: yes
@coderabbitai[bot] on GitHub · 2026-10-12 08:40 UTC · original · edited 2026-10-16 02:42 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
f3231692-6edd-43d6-89cf-952b37031449📥 Commits
Reviewing files that changed from the base of the PR and between 1e11e530e2ce94d398797a39ee62c3294423333d and
1f309cd5c3.📒 Files selected for processing: 2
src/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; 5 remain after this review.
📝 Walkthrough
Post-tested loop recognition now supports qualifying unit-increment loops whose immediate start is below the signed or unsigned limit. Indirect descriptor planning uses the recognized start and range length to set
selector_firstandkey_count. Tests cover accepted and rejected loop forms, signed and unsigned pixel-shader loops, and materialization of keys without reading key 0.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
1f309No merge-blocking issue is established for the post-tested image-table loop change. Merge 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.@theantipopau on GitHub · 2026-10-12 10:21 UTC · original · approved these changes
Verified against main (the PR branches on a lot of other in-flight work, so I fetched
fix/gotg-post-tested-loopand reviewed just the three files in its commit1e11e530):BoundedPostTestLoopprep-test ordering is right: with the test after the body,(key+1) < limiton the post-loop edge proveskey ∈ [start, limit)inside and after the loop, so the sampled use in the header/body needs no dominating guard. It only accepts a 2-arm U32 Phi with immediate start,IAdd32 key, 1back value, an immediateULessThan32/SLessThan32operand-0 compare,start < limit(and non-negative signed start), and the continuation edgeImplies(edge.condition, comparator)withLaneQuantifier::All—GuardedOnEntrycovers the synthetic-continue-block shape in the GotG IR (latch → proxy → header/exit), andVccNonZero(AnyLane) variants are rejected since Some-lane continuation can't bound the divergent lanes.ResourceMaterialization: enumeration now usesiota(keys, first)and the stride/bounds check correctly accounts forfirstvia(first + key_count - 1) * stride, and the selector-less path validatesselector_firstthroughclean.Evaluatelikekey_count. The pre-existingelse if (!indirect.selector_first.IsEmpty())selector path already handled first/count, so appendingselector_firstfrom a post-test loop can't desync that path.image_sample_lsharing oneGetImageResource, start=1, limit=16) and asserts negative cases: start==limit, non-1 step, false-edge polarity, VccNonZero, signed start below 0, and that key 0's record (0x100) is never read.CI green on Linux/Windows/macOS (run 38226266320). LGTM.
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.