graphics: collect scalar reads without native recursion (Assassin's Creed Black Flag) #1967
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!1967
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1967/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?
@Nawid3333 on GitHub · 2026-10-29 04:55 UTC · original
Nawid3333:fix/scalar-read-stack→main· +156 −33 · 2 files · 4 commits · closed without mergingTracker::CollectScalarReadwalks every operand of the values it reaches with one native call per value, so its depth is the longest dependency chain of the shader. In Assassin's Creed Black Flag Resynced (PPSA28183), the walks at the loading screen go up to 2334 values deep (compute shader 0x38261e1654654fe6, 678 blocks). With one native frame per value, that overflows the stack of the thread that translates the shader (astd::jthread, 1 MiB by default on Windows), and the emulator exits with0xC00000FDand no error message.Game test (Assassin's Creed Black Flag Resynced, PPSA28183), Windows 11, RX 9070 XT: builds of main
c528324dplus #1867, which fixes the earlier stop atsampled image descriptor 43 uses unsupported format 20, and a local input-script helper (not part of this PR) that presses the buttons through the first-launch menus.0xC00000FDat the loading screen after the first-launch menus, about 5 minutes in. Crispy81 reported the same silent exit at the loading screen on #1792 (#1792).image heaps exceed 65536 resident images(imageHeap.cpp:389).To find the function, I used a local build that writes the return addresses on the stack when it overflows: almost all of them were nested
CollectScalarReadcalls underTracker::Run, while a compute shader for an indirect dispatch was translated. A second local build logged the depth of every walk deeper than 256; the game has 59 of them, the deepest 2334.Change: the walk keeps its pending operands on a
std::vector. It visits them in the order of the recursion (the descriptor dwords of a scalar read, then its operands after the handle) and keeps the same visiting, visited and cycle rules, so it collects the same reads in the same order. #937 contains a similar explicit-stackCollectScalarReadas part of a larger Wolverine PR; this is only that walk, on current main.Tests
deep scalar read dependencies(new, inresource_tracking_tests): aReadConstBuffersits behind 20000 FP additions and a one-input Phi that a global address uses as its low dword, so only this walk finds the read.TrackResourcesruns on a thread with a 1 MiB stack and must plan the read and replace its use with SRT slot 0. With c528324d'sResourceTracking.cpp,resource_tracking_testsexits with0xC00000FD; with this PR it passes.resource_tracking_testsandshader_cfg_testspass on this branch on Windows (clang-cl);shader_cfg_testsalso passes onc528324d.resource_tracking) passes one104fb95, which merges main4919fdb6(the walk keeps 216bd28b's visited set and its order).Fixes #2151: Ghost of Yōtei exits the same way (
0xC00000FD) while it translates a 309-block compute shader; my measurements are in the comment below.If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it found the overflowing function, wrote the change, and ran the game and the tests on my PC (Windows 11); OpenAI Codex designed the test.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-29 05:03 UTC · original · edited 2026-10-30 19:48 UTC
No actionable comments were generated in the recent review.
84904c8b-a969-4834-9ef9-68ebb23bd11cReviewing files that changed from the base of the PR and between
d9a1023517ande104fb951e.src/graphics/shader/recompiler/ir/passes/ResourceTracking.cpptests/ResourceTrackingTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Walkthrough
CollectScalarReadnow traverses typed planning-value dependencies with an explicit stack instead of recursive calls. The existing cycle checks, handle validation, descriptor-source collection, and immediate U32 offset rule remain. A new test builds a 20,000-operation dependency chain and checks resource planning on a 1 MiB worker-thread stack.Suggested reviewers:
nmzikPriority:
Normal
Change: Bug fix
Merge Risk:
Minimal · up to
e104fThe change preserves scalar-read planning order. No merge-blocking risk was identified.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 5 functions across 2 files.
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.@Nawid3333 on GitHub · 2026-10-29 05:23 UTC · original
The next stop after this PR, in case it helps with the image heap: after Difficulty Tuning the game shows the loading screen of the first mission, then exits with
image heaps exceed 65536 resident images(imageHeap.cpp:389), about 12 minutes in.A local diagnostic build (not part of this PR) logged the heap when it reached 65536 elements:
0x4065100000,0xdb6800bytes, 449344 descriptors of 32 bytes) has 10 views and 59875 of the elements. All 10 views use step 32 and no limit. They start atfirst= 0, 32, 64, 96, 128, 160 and 320 bytes; the four that start at 0 differ in their profile.The large views cover the same table from start offsets at most 320 bytes apart and hold nearly the same number of elements, so it looks like the heap stores the same descriptors once per view (
view.elementsinImageHeap::Intern). Each view also has its own slot array over the whole table (3594753 slots).@Nawid3333 on GitHub · 2026-11-01 23:20 UTC · original
Ghost of Yotei (PPSA26344) stops in the same recursion. It is the stop #1599 reports: 0xC00000FD while translating a large compute shader (about 308 blocks, 7 loops).
893b03552(RX 9070 XT, Windows 11): the game exits with 0xC00000FD while it translates CS0xc7d37e2ca4c818a4(309 blocks after structurization, 7 loops). The log ends at "native IR before resource tracking". A lab-only census of the return addresses on the overflowed stack finds 1191 frames inTracker::CollectScalarRead.!Allocate(layout, fresh_batch)atdescriptorHeap.cpp:57, the error GTA V's RT mode reports in #829.@Nawid3333 on GitHub · 2026-11-09 14:39 UTC · original
Superseded by
26ad49a66in main, which collects the scalar reads on an explicit stack. This PR's test (20,000 FP dependencies hiding a scalar read, on a 1 MiB stack) passes on mainf399d4818on Windows. Closing this one.Pull request closed