graphics: give the GPU thread the same stack on every host #1609
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!1609
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1609/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-17 16:53 UTC · original
Nawid3333:host/gpu-thread-stack→main· +197 −11 · 7 files · 7 commits · closed without mergingShader translation runs on the GPU thread, and parts of it recurse along the shader's structure (for example
LoopBoundProof::EvaluateinResourceTracking.cpp). The GPU thread is astd::jthread, so it gets the host's default stack: 1 MiB on Windows (the official build sets no/STACK), 512 KiB for secondary threads on macOS, usually 8 MiB on Linux. So how deep a shader's analysis may go depends on the host.The three stack-overflow reports (
0xC00000FD) while shaders are translated are all on Windows: #1513 (Marvel's Wolverine, which the reporter attributes toLoopBoundProof::Evaluate), #1599 (Ghost of Yotei, while translating a large compute shader) and #1417 (007 First Light). In #1417 the reporter raised the executable's stack reserve from 1 MiB to 16 MiB and got past the overflow (the game then stopped at an unrelated unsupported indirect image). I don't have these games, so I couldn't check the change with them.Game test (Ghost of Yotei, PPSA26344): Ben-Dash ran a build of this PR (
497020a): the compute shader that overflowed before (0xd0bbff78032edd55) now translates fully, and the game reaches act_prologue (431 frames) before it stops at an unrelated resource-tracking error (#1609).Change:
Common::ThreadWithStackstarts a thread with an explicit stack reserve (_beginthreadexwithSTACK_SIZE_PARAM_IS_A_RESERVATIONon Windows,pthread_attr_setstacksizeelsewhere);Join()or the destructor joins it, and a failed or self join exits instead of hanging. The GPU thread uses it with 64 MiB, four times the 16 MiB that was enough in #1417. On Windows that memory is only reserved and is committed as the stack grows; on Linux and macOS it is mapped on first touch. Other threads keep their default. This doesn't remove the deep recursion itself, which is yours to decide; it makes every host give the GPU thread the same room.Tests
HostThreadTests(new, added to CI on all three platforms): aThreadWithStackwith 64 MiB runs a function that uses 32 MiB of stack, more than any host's default; it passes. A local variant with a 1 MiB stack dies with0xC00000FD(stack overflow) on Windows.kyty_emulatorbuilds on Windows; fork CI (build and tests on Windows, Linux and macOS, including the new test) passes on69ca5322.If you'd like this done differently, tell me and I'll change it.
Written with Claude Code (AI): it found the reports, wrote the change and ran the tests on my PC (Windows 11).
🤖 Generated with Claude Code
906d2556into host/gpu-thread-stack 2287cc479e@coderabbitai[bot] on GitHub · 2026-10-17 16:57 UTC · original · edited 2026-10-28 21:46 UTC
Walkthrough
The change adds
Common::ThreadWithStack, which starts and joins a thread with a requested stack size on Windows and POSIX platforms.GuestGpunow uses this wrapper with a 64 MiB stack. New tests check recursive stack use and repeated calls toJoin(). CMake registers the tests, and the Windows, macOS, and Linux build jobs build and run them.Suggested reviewers:
nmzikPriority:
Normal
Change: Bug fix
Merge Risk:
Low · previous review
70803The GPU worker now starts through a new cross-platform wrapper with a 64 MiB stack. In final builds, a failure to create that thread would go unreported and could hang GPU synchronization instead of exiting with a diagnostic. This is a narrow edge case with a small fix, so the change is close to mergeable.
Pre-merge checks:
5
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.@ -666,6 +672,7 @@ if(BUILD_TESTING)add_test(NAME vdecsw COMMAND $<TARGET_FILE:vdecsw_tests>)add_test(NAME bit_array COMMAND $<TARGET_FILE:bit_array_tests>)add_test(NAME lru_cache COMMAND $<TARGET_FILE:lru_cache_tests>)add_test(NAME host_thread COMMAND $<TARGET_FILE:host_thread_tests>)@coderabbitai[bot] on GitHub · 2026-10-17 16:57 UTC · original · edited 2026-10-17 17:01 UTC
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Add
host_thread_teststo thekyty_testsdependencies.host_thread_testsisEXCLUDE_FROM_ALL, but thekyty_teststarget at Line 712 does not depend on it. If a developer buildskyty_testsand then runs CTest, the newhost_threadtest cannot run because its executable was not built. Addhost_thread_teststo that dependency list. (cmake.org)✅ Addressed in commit
497020a@coderabbitai[bot] on GitHub · 2026-10-17 16:57 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
44a396b2-2dce-4995-8d60-2e52579077e2📥 Commits
Reviewing files that changed from the base of the PR and between
763d3be3a9and69ca5322c7.📒 Files selected for processing: 7
.github/workflows/build.ymlCMakeLists.txtsrc/common/threads.cppsrc/common/threads.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/graphicsRun.htests/HostThreadTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ -666,6 +672,7 @@ if(BUILD_TESTING)add_test(NAME vdecsw COMMAND $<TARGET_FILE:vdecsw_tests>)add_test(NAME bit_array COMMAND $<TARGET_FILE:bit_array_tests>)add_test(NAME lru_cache COMMAND $<TARGET_FILE:lru_cache_tests>)add_test(NAME host_thread COMMAND $<TARGET_FILE:host_thread_tests>)@Nawid3333 on GitHub · 2026-10-17 16:59 UTC · original
Thanks, added to
kyty_testsin497020a0.@MrFr3di on GitHub · 2026-10-18 17:03 UTC · original
Increasing the stack size isn't a solution to the underlying problem, and this PR doesn't actually fix it either
@Nawid3333 on GitHub · 2026-10-18 18:02 UTC · original
Agreed that more stack doesn't remove the recursion; the description says so ("This doesn't remove the deep recursion itself"). The PR gives the GPU thread the same, larger stack (64 MiB) on every host, instead of the host default: 1 MiB on Windows, 512 KiB on macOS, usually 8 MiB on Linux. In #1417 (007 First Light), a copy of the official build with a 16 MiB stack reserve got past the overflow (it then stopped at an unrelated unsupported image), so up to where it stopped, 16 MiB was enough. The recursion in
LoopBoundProof::Evaluate(the one #1513 points to) does end: it records each instruction before it recurses and, when it meets one again, returns its cached result, or a free variable if that instruction is still being evaluated (a cycle), so it visits each instruction at most twice and its depth is bounded by the shader's size; a large shader can still need more than 1 MiB. I couldn't test the PR with these games myself.Did you run this PR's build with one of these games and still get the overflow? If so, could you post the log or the call stack? That would show where it overflows; a recursion that never ends there would need a different fix than a stack size.
@Ben-Dash on GitHub · 2026-10-20 01:48 UTC · original
I was able to run it on my machine with Ghost of Yotei, and managed to make it much farther than before. With a larger GPU-thread stack (fork build
497020a), the CS that overflowed before (0xd0bbff78032edd55) now translates fully. The game reaches act_prologue and 431 frames, then got hit with a "shader resource tracking: hash=0xe3030eb1ce633def stage=compute pc=0x00000980buffer descriptor is not a valid runtime value; GPU-selected access requiresa scalar, raw 8/16-bit, raw DWORD x1/x2/x3/x4, or formatted X load The shader has 18 blocks and 1 loop; BufferAtomicIAdd32 uses a GetBufferResource whose descriptor dwords are loop Phis."It seems like something of use is possible from this fork, so it may be worth checking it out more.
GhostOfYotei - StackOverflowTest.txt
(Note that the 100mb log cannot be uploaded here, if you need it, I can link a google drive to it.)
@Nawid3333 on GitHub · 2026-10-20 14:14 UTC · original
@Ben-Dash thanks for testing it, that is the game evidence this PR was missing.
With your build of this PR (
497020a), the compute shader that overflowed before (0xd0bbff78032edd55) now translates fully on the 64 MiB GPU-thread stack, so for that shader the stack size was the limit.The new stop is a different problem. After act_prologue and 431 frames, the resource tracker (ResourceTracking.cpp:580) rejects compute shader 0xe3030eb1ce633def: its
BufferAtomicIAdd32takes its buffer descriptor from loop Phis, and the tracker only accepts that for scalar, raw or formatted loads, not for an atomic. This PR does not touch that check. It belongs in the Ghost of Yotei issue (#1599) rather than here; I found no existing issue or PR for this error.I'll add Ghost of Yotei to the PR description.
@Ben-Dash on GitHub · 2026-10-21 20:45 UTC · original
Are there any plans to merge this pull with the main branch? I can't conduct any more testing on Ghost of Yotei until something gets done about the stack overflow, as all of the current builds crash on the exact same error, as listed in this issue.
@Nawid3333 on GitHub · 2026-10-21 22:01 UTC · original
@Ben-Dash merging is up to @Nmzik. Until then, here is a Windows build of today's main (
28648188) with this PR, so you can keep testing: https://github.com/Nawid3333/KytyPS5/actions/runs/39679772503 (artifactKytyPS5-Windows-x64, downloading it needs a GitHub login). It would also show whether the later stop you hit (compute shader 0xe3030eb1ce633def,BufferAtomicIAdd32 uses a GetBufferResource whose descriptor dwords are loop Phis) is still there on current main.@Ben-Dash on GitHub · 2026-10-22 00:12 UTC · original
Even with this version, I still hit the same error. Making a separate issue report based off my findings feels redundant when I can't even get past the stack oveflow on the main release. I'll wait for @Nmzik to get around to merging this fix (or something else that fixes the overflow) before I continue my testing. Hope a definite fix for the overflow gets pushed soon.
@coderabbitai[bot] on GitHub · 2026-10-24 19:00 UTC · original · reviewed
7ea0db61-3a75-408a-b2a7-a742082bfb60Reviewing files that changed from the base of the PR and between
497020a07cand2287cc479e.CMakeLists.txtsrc/common/threads.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/graphicsRun.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@Ben-Dash on GitHub · 2026-10-24 20:15 UTC · original
@Nawid3333 Is this an updated version with the fix to the problem as mentioned above?
@Ben-Dash on GitHub · 2026-10-24 21:32 UTC · original
Well things have certainly developed with this build. The game now compiles 139 shaders (6 VS / 25 PS / 108 CS, including the 309-block compute shader), reaches act_prologue, and submits 453 flips. The overlay then stalls out and proceeds to push no subsequent frames. Once the game is stalled, no resource values fill up (I.e. RAM/VRAM), and the overlay displays 781,800 write-tracking faults per second.
The log records a couple events before stalling; a flip request (display buffer 2), then a graphics-core equeue event with data=0x1c5 (453) received by ProxySetSync, which waits on "ProxySet Cull" with timo=inf and never wakes. The last asset opened is cache_ps5/load_menu_catalog.log.
I attached a screenshot of the resource monitor and one of the logs, but the main logs are too big for Github to upload.

GhostOfYotei - StackOverflowTest4.txt
@Nawid3333 on GitHub · 2026-10-27 21:51 UTC · original
A second game: Resident Evil Requiem (#1929), Windows 11, RX 9070 XT.
986721f), Crispy81's run reached the questions before the main menu and then closed without an error message. The log ends in the middle of translating compute shader 0xbf3870f00b0a8e75.0685bffb(7fa8d3a), that shader translates fully (SPIR-V EmitProgram ... words=2363). The game reaches the main menu and, after New Game, starts the opening cutscene. It then stops at a GPU device loss (vkQueueSubmit failed: ErrorDeviceLostatcommandScheduler.cpp:385), which is a separate problem.The two builds have different bases (
986721fvs0685bffb), so this isn't a strict A/B. The stop inside that one shader's translation is what a stack overflow on the GPU thread looks like, and with this PR it's gone (#1929).@Nawid3333 on GitHub · 2026-10-27 21:59 UTC · original
@Ben-Dash sorry for the late answer.
28648188with this PR) has only this PR's change, the larger GPU-thread stack. If the error you still hit on 10-22 was the later stop I mentioned (BufferAtomicIAdd32 uses a GetBufferResource whose descriptor dwords are loop Phis), #1939 is the open PR for that one.GpuThreadStackSizeof 64 MiB withCommon::ThreadWithStackingraphicsRun.cpp), so your results there run with it too.@coderabbitai[bot] on GitHub · 2026-10-28 21:10 UTC · original · reviewed
020d3945-3911-4197-8583-3b5ea14c54d9Reviewing files that changed from the base of the PR and between
4c29ca5c13and70803c0806..github/workflows/build.ymlCMakeLists.txtsrc/common/threads.hsrc/graphics/guest_gpu/graphicsRun.cppsrc/graphics/guest_gpu/graphicsRun.hIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
@Nmzik on GitHub · 2026-10-28 21:50 UTC · original
@Nawid3333 This is weird fix
@Nawid3333 on GitHub · 2026-10-28 22:00 UTC · original
@Nmzik Understood, a bigger stack only hides the deep recursion. Three games stop on it, each with a stack overflow on the GPU thread while one shader is being translated:
0xC00000FD, which the report places inLoopBoundProof::Evaluate.0xC00000FDon compute shader 0xd0bbff78032edd55; the last recompiler line before it is "native IR before resource tracking", so it overflows in resource tracking as well. With more stack the shader translates and the game runs on to a different, unrelated stop.LoopBoundProof::Evaluate(ResourceTracking.cpp) calls itself once per operand along the value chain, so its stack use grows with the shader. Nothing about it is specific to these games: a shader with a long enough chain overflows any thread's stack, only at different sizes on different hosts. If you want, I'll send a PR that removes that recursion, so the stack use no longer depends on the shader. Before that I'd check with the Requiem shader that it overflows in the same place, and add a test shader that overflows on main today.Pull request closed