graphics: give the GPU thread the same stack on every host #1609

Closed
github-bot wants to merge 7 commits from gh-pr/1609/head into gh-pr/1609/base
Owner

@⁠Nawid3333 on GitHub · 2026-10-17 16:53 UTC · original
Nawid3333:host/gpu-thread-stack → main · +197 −11 · 7 files · 7 commits · closed without merging

Shader translation runs on the GPU thread, and parts of it recurse along the shader's structure (for example LoopBoundProof::Evaluate in ResourceTracking.cpp). The GPU thread is a std::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 to LoopBoundProof::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::ThreadWithStack starts a thread with an explicit stack reserve (_beginthreadex with STACK_SIZE_PARAM_IS_A_RESERVATION on Windows, pthread_attr_setstacksize elsewhere); 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): a ThreadWithStack with 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 with 0xC00000FD (stack overflow) on Windows.
  • kyty_emulator builds on Windows; fork CI (build and tests on Windows, Linux and macOS, including the new test) passes on 69ca5322.

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

**@⁠Nawid3333** on GitHub · 2026-10-17 16:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609) `Nawid3333:host/gpu-thread-stack` → `main` · +197 −11 · 7 files · 7 commits · closed without merging Shader translation runs on the GPU thread, and parts of it recurse along the shader's structure (for example `LoopBoundProof::Evaluate` in `ResourceTracking.cpp`). The GPU thread is a `std::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 to `LoopBoundProof::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 (https://git.gtahub.st/github/KytyPS5--KytyPS5/pulls/1609). **Change:** `Common::ThreadWithStack` starts a thread with an explicit stack reserve (`_beginthreadex` with `STACK_SIZE_PARAM_IS_A_RESERVATION` on Windows, `pthread_attr_setstacksize` elsewhere); `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): a `ThreadWithStack` with 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 with `0xC00000FD` (stack overflow) on Windows. - `kyty_emulator` builds on Windows; fork CI (build and tests on Windows, Linux and macOS, including the new test) passes on 69ca5322. 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](https://claude.com/claude-code)
Shader translation runs on the GPU thread and several passes recurse with
the shader's structure. std::jthread gets the host's default stack: 1 MiB on
Windows, 512 KiB for secondary threads on macOS, usually 8 MiB on Linux, so
the same shader can overflow on Windows and macOS and translate on Linux.
Common::ThreadWithStack creates the thread with an explicit stack reserve,
and the GPU thread uses 64 MiB.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
EXIT_IF does not evaluate its argument in KYTY_FINAL builds, so the thread would not be
created or joined there (CodeRabbit).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	.github/workflows/build.yml
EXIT_IF is compiled out in KYTY_FINAL builds, so a failed _beginthreadex,
pthread_attr_init, pthread_attr_setstacksize or pthread_create went
unnoticed and the GPU ran without its thread (std::jthread threw instead).
The checks now use EXIT with the error code. (CodeRabbit review.)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Join's checks were EXIT_IF as well, so in KYTY_FINAL builds a self-join or a
failed wait/pthread_join was recorded as joined. Windows narrowed the stack
size to unsigned without a check. (Codex review.)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:37 +00:00
github-bot closed this pull request 2026-11-26 10:01:37 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 16:57 UTC · original · edited 2026-10-28 21:46 UTC

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
Walkthrough

The change adds Common::ThreadWithStack, which starts and joins a thread with a requested stack size on Windows and POSIX platforms. GuestGpu now uses this wrapper with a 64 MiB stack. New tests check recursive stack use and repeated calls to Join(). CMake registers the tests, and the Windows, macOS, and Linux build jobs build and run them.

Suggested reviewers: nmzik

Priority: Normal

Change: Bug fix

Merge Risk: Low · previous review 70803

The 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: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: giving the GPU thread a consistent stack size across hosts.
Description check Passed The description directly explains the stack-size problem, the ThreadWithStack implementation, the GPU-thread change, and the related tests.
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 16:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6237119354) · edited 2026-10-28 21:46 UTC <!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1609?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > - Last reviewed commit: 70803c0806a1c64f8aebd0e7682ffd6dab64899d > - Latest commit, not reviewed: c593c7424c60e57d728deee6d93a49f1d6afadc9 > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> The change adds `Common::ThreadWithStack`, which starts and joins a thread with a requested stack size on Windows and POSIX platforms. `GuestGpu` now uses this wrapper with a 64 MiB stack. New tests check recursive stack use and repeated calls to `Join()`. CMake registers the tests, and the Windows, macOS, and Linux build jobs build and run them. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <strong>Priority: <picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/priority-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Normal</strong> <!-- change_assessment_commit:"70803c0806a1c64f8aebd0e7682ffd6dab64899d" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/risk-low-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Low</strong> · previous review <code>70803</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `70803` --> <!-- final_review_risk_coverage:{"sourceCommitId":"70803c0806a1c64f8aebd0e7682ffd6dab64899d","coveredCommitId":"70803c0806a1c64f8aebd0e7682ffd6dab64899d","kind":"reviewed"} --> The 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. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 5</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------ | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: giving the GPU thread a consistent stack size across hosts. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the stack-size problem, the ThreadWithStack implementation, the GPU-thread change, and the related tests. | | Docstring Coverage | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1609)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -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>)
Author
Owner

@⁠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_tests to the kyty_tests dependencies.

host_thread_tests is EXCLUDE_FROM_ALL, but the kyty_tests target at Line 712 does not depend on it. If a developer builds kyty_tests and then runs CTest, the new host_thread test cannot run because its executable was not built. Add host_thread_tests to that dependency list. (cmake.org)

✅ Addressed in commit 497020a

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 16:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#discussion_r4303599636) · edited 2026-10-17 17:01 UTC **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** **Add `host_thread_tests` to the `kyty_tests` dependencies.** `host_thread_tests` is `EXCLUDE_FROM_ALL`, but the `kyty_tests` target at Line 712 does not depend on it. If a developer builds `kyty_tests` and then runs CTest, the new `host_thread` test cannot run because its executable was not built. Add `host_thread_tests` to that dependency list. ([cmake.org](https://cmake.org/cmake/help/latest/prop_tgt/EXCLUDE_FROM_ALL.html?utm_source=openai)) <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:5f21ce2dbe1d9bf3518b4447 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit 497020a
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 16:57 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 44a396b2-2dce-4995-8d60-2e52579077e2
📥 Commits

Reviewing files that changed from the base of the PR and between 763d3be3a9 and 69ca5322c7.

📒 Files selected for processing: 7
  • .github/workflows/build.yml
  • CMakeLists.txt
  • src/common/threads.cpp
  • src/common/threads.h
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/guest_gpu/graphicsRun.h
  • tests/HostThreadTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 16:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#pullrequestreview-5558922853) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `44a396b2-2dce-4995-8d60-2e52579077e2` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 763d3be3a9bc4e5a068d7cf52015030d6c03308f and 69ca5322c7c90483b952ae2b810d1baa23f7f755. </details> <details> <summary>📒 Files selected for processing: 7</summary> * `.github/workflows/build.yml` * `CMakeLists.txt` * `src/common/threads.cpp` * `src/common/threads.h` * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/guest_gpu/graphicsRun.h` * `tests/HostThreadTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=4c4bb241-239e-434a-8bf6-12a2e9a7cb02 attempt=76ce4f98-971b-4778-b3a1-1ccbd7bc4884 batch=1/1 -->
@ -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>)
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-17 16:59 UTC · original

Thanks, added to kyty_tests in 497020a0.

**@⁠Nawid3333** on GitHub · 2026-10-17 16:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#discussion_r4303605879) Thanks, added to `kyty_tests` in 497020a0.
Author
Owner

@⁠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

**@⁠MrFr3di** on GitHub · 2026-10-18 17:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6252653113) Increasing the stack size isn't a solution to the underlying problem, and this PR doesn't actually fix it either
Author
Owner

@⁠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.

**@⁠Nawid3333** on GitHub · 2026-10-18 18:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6253262206) 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.
Author
Owner

@⁠Ben-Dash on GitHub · 2026-10-20 01:48 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.

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.)

**@⁠Ben-Dash** on GitHub · 2026-10-20 01:48 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6281421065) > 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. 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](https://github.com/user-attachments/files/33694337/GhostOfYotei.-.StackOverflowTest.txt) (Note that the 100mb log cannot be uploaded here, if you need it, I can link a google drive to it.)
Author
Owner

@⁠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 BufferAtomicIAdd32 takes 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.

**@⁠Nawid3333** on GitHub · 2026-10-20 14:14 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6292939080) @⁠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 `BufferAtomicIAdd32` takes 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.
Author
Owner

@⁠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.

**@⁠Ben-Dash** on GitHub · 2026-10-21 20:45 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6326166849) 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](https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1599) issue.
Author
Owner

@⁠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 (artifact KytyPS5-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.

**@⁠Nawid3333** on GitHub · 2026-10-21 22:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6327518716) @⁠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 (artifact `KytyPS5-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.
Author
Owner

@⁠Ben-Dash on GitHub · 2026-10-22 00:12 UTC · original

@⁠Ben-Dash merging is up to @⁠Nmzik. Until then, here is a Windows build of today's main (2864818) with this PR, so you can keep testing: https://github.com/Nawid3333/KytyPS5/actions/runs/39679772503 (artifact KytyPS5-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.

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.

**@⁠Ben-Dash** on GitHub · 2026-10-22 00:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6329443127) > @⁠Ben-Dash merging is up to @⁠Nmzik. Until then, here is a Windows build of today's main ([2864818](https://github.com/KytyPS5/KytyPS5/commit/286481889fcdda9390c6ef2bf7e66c84aff978ba)) with this PR, so you can keep testing: https://github.com/Nawid3333/KytyPS5/actions/runs/39679772503 (artifact `KytyPS5-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. 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.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-24 19:00 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Major · Do not place native thread operations inside EXIT_IF. · threads.cpp:411-423

src/common/threads.cpp:411-423
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Do not place native thread operations inside EXIT_IF.

A build that defines KYTY_FINAL can skip every POSIX startup call because EXIT_IF(x) does not evaluate x. The constructor then calls pthread_attr_destroy on an attribute whose initialization was skipped. On Windows, _beginthreadex can fail, but the null-handle check is skipped. GuestGpu can therefore retain a wrapper without a GPU worker.

Join() has the same defect. In KYTY_FINAL, it skips pthread_join and WaitForSingleObject even after successful thread creation. The wrapper can mark itself joined and release ThreadWithStackPrivate while the worker still uses it. This is a use-after-free path, not an invalid native join call.

The repository’s default CMake and CI configuration does not define KYTY_FINAL, but src/cmake_config.h.in permits an explicitly configured build to define it. The former std::jthread construction did not retain a thread object when native startup failed.

Move the native calls out of EXIT_IF and use an always-active failure path. Apply the same change to Join().

Suggested fix
 	m_thread->handle = reinterpret_cast<HANDLE>(
 	    _beginthreadex(nullptr, static_cast<unsigned>(stack_size), ThreadWithStackPrivate::Run,
 	                   m_thread.get(), STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr));
-	EXIT_IF(m_thread->handle == nullptr);
+	if (m_thread->handle == nullptr) {
+		EXIT("ThreadWithStack: failed to create thread");
+	}
 #else
 	pthread_attr_t attr;
-	EXIT_IF(pthread_attr_init(&attr) != 0);
-	EXIT_IF(pthread_attr_setstacksize(&attr, stack_size) != 0);
-	EXIT_IF(pthread_create(&m_thread->thread, &attr, ThreadWithStackPrivate::Run, m_thread.get()) !=
-	        0);
+	if (pthread_attr_init(&attr) != 0) {
+		EXIT("ThreadWithStack: pthread_attr_init failed");
+	}
+	if (pthread_attr_setstacksize(&attr, stack_size) != 0) {
+		pthread_attr_destroy(&attr);
+		EXIT("ThreadWithStack: pthread_attr_setstacksize failed");
+	}
+	int result = pthread_create(&m_thread->thread, &attr, ThreadWithStackPrivate::Run, m_thread.get());
 	pthread_attr_destroy(&attr);
+	if (result != 0) {
+		EXIT("ThreadWithStack: pthread_create failed");
+	}
 #endif
 #if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
-	EXIT_IF(GetThreadId(m_thread->handle) == GetCurrentThreadId());
-	EXIT_IF(WaitForSingleObject(m_thread->handle, INFINITE) != WAIT_OBJECT_0);
+	if (GetThreadId(m_thread->handle) == GetCurrentThreadId()) {
+		EXIT("ThreadWithStack: cannot join the current thread");
+	}
+	if (WaitForSingleObject(m_thread->handle, INFINITE) != WAIT_OBJECT_0) {
+		EXIT("ThreadWithStack: failed to join thread");
+	}
 	CloseHandle(m_thread->handle);
 #else
-	EXIT_IF(pthread_join(m_thread->thread, nullptr) != 0);
+	if (pthread_join(m_thread->thread, nullptr) != 0) {
+		EXIT("ThreadWithStack: failed to join thread");
+	}
 #endif

Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 497020a07c and 2287cc479e.

Files selected for processing: 4
  • CMakeLists.txt
  • src/common/threads.h
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/guest_gpu/graphicsRun.h

Included 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-24 19:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#pullrequestreview-5639525872) · **reviewed** <!-- coderabbit-ai-generated:v1 --> > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/major-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Major</strong> · Do not place native thread operations inside <code>EXIT_IF</code>. · <code>threads.cpp:411-423</code></summary><blockquote> > <dl> > <dd> > > `src/common/threads.cpp:411-423` > **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** > > **Do not place native thread operations inside `EXIT_IF`.** > > A build that defines `KYTY_FINAL` can skip every POSIX startup call because `EXIT_IF(x)` does not evaluate `x`. The constructor then calls `pthread_attr_destroy` on an attribute whose initialization was skipped. On Windows, `_beginthreadex` can fail, but the null-handle check is skipped. `GuestGpu` can therefore retain a wrapper without a GPU worker. > > `Join()` has the same defect. In `KYTY_FINAL`, it skips `pthread_join` and `WaitForSingleObject` even after successful thread creation. The wrapper can mark itself joined and release `ThreadWithStackPrivate` while the worker still uses it. This is a use-after-free path, not an invalid native join call. > > The repository’s default CMake and CI configuration does not define `KYTY_FINAL`, but `src/cmake_config.h.in` permits an explicitly configured build to define it. The former `std::jthread` construction did not retain a thread object when native startup failed. > > Move the native calls out of `EXIT_IF` and use an always-active failure path. Apply the same change to `Join()`. > > <details> > <summary>Suggested fix</summary> > <dl> > <dd> > > ```diff > m_thread->handle = reinterpret_cast<HANDLE>( > _beginthreadex(nullptr, static_cast<unsigned>(stack_size), ThreadWithStackPrivate::Run, > m_thread.get(), STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr)); > - EXIT_IF(m_thread->handle == nullptr); > + if (m_thread->handle == nullptr) { > + EXIT("ThreadWithStack: failed to create thread"); > + } > #else > pthread_attr_t attr; > - EXIT_IF(pthread_attr_init(&attr) != 0); > - EXIT_IF(pthread_attr_setstacksize(&attr, stack_size) != 0); > - EXIT_IF(pthread_create(&m_thread->thread, &attr, ThreadWithStackPrivate::Run, m_thread.get()) != > - 0); > + if (pthread_attr_init(&attr) != 0) { > + EXIT("ThreadWithStack: pthread_attr_init failed"); > + } > + if (pthread_attr_setstacksize(&attr, stack_size) != 0) { > + pthread_attr_destroy(&attr); > + EXIT("ThreadWithStack: pthread_attr_setstacksize failed"); > + } > + int result = pthread_create(&m_thread->thread, &attr, ThreadWithStackPrivate::Run, m_thread.get()); > pthread_attr_destroy(&attr); > + if (result != 0) { > + EXIT("ThreadWithStack: pthread_create failed"); > + } > #endif > ``` > > ```diff > #if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS > - EXIT_IF(GetThreadId(m_thread->handle) == GetCurrentThreadId()); > - EXIT_IF(WaitForSingleObject(m_thread->handle, INFINITE) != WAIT_OBJECT_0); > + if (GetThreadId(m_thread->handle) == GetCurrentThreadId()) { > + EXIT("ThreadWithStack: cannot join the current thread"); > + } > + if (WaitForSingleObject(m_thread->handle, INFINITE) != WAIT_OBJECT_0) { > + EXIT("ThreadWithStack: failed to join thread"); > + } > CloseHandle(m_thread->handle); > #else > - EXIT_IF(pthread_join(m_thread->thread, nullptr) != 0); > + if (pthread_join(m_thread->thread, nullptr) != 0) { > + EXIT("ThreadWithStack: failed to join thread"); > + } > #endif > ``` > > </dd> > </dl> > </details> > > <!-- cr-comment:v1:366e65dbcf57ea10042e4823 --> > > </dd> > </dl> > </blockquote></details> --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/906d25568fb9c409d798b97ae72c7c12cbedb914/.coderabbit.yaml>) - **Commit**: [906d255](<https://github.com/KytyPS5/KytyPS5/commit/906d25568fb9c409d798b97ae72c7c12cbedb914>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `7ea0db61-3a75-408a-b2a7-a742082bfb60` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 497020a07ce8aae1b66411f1b878ed62ba07918e and 2287cc479ef36737e8a60cb66644a03ad6cec921. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 4</summary> <dl> <dd> * `CMakeLists.txt` * `src/common/threads.h` * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/guest_gpu/graphicsRun.h` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </dd> </dl> </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=7d0d5fc6-7ae0-4028-9360-23d41d7d081d attempt=1c9a341c-40bf-4e14-8e09-4eef4b7b18cc batch=1/1 -->
Author
Owner

@⁠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 20:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6389025040) @⁠Nawid3333 Is this an updated version with the fix to the problem as mentioned above?
Author
Owner

@⁠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.
Screenshot 2026-10-24 170909
GhostOfYotei - StackOverflowTest4.txt

**@⁠Ben-Dash** on GitHub · 2026-10-24 21:32 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6389794376) 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. <img width="1627" height="997" alt="Screenshot 2026-10-24 170909" src="https://github.com/user-attachments/assets/6c45b57f-e9e9-419a-a3ac-8b02fac1dad3" /> [GhostOfYotei - StackOverflowTest4.txt](https://github.com/user-attachments/files/33914009/GhostOfYotei.-.StackOverflowTest4.txt)
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-27 21:51 UTC · original

A second game: Resident Evil Requiem (#1929), Windows 11, RX 9070 XT.

  • On the official 0.3.0 build (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.
  • With a Windows build of this PR on main 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: ErrorDeviceLost at commandScheduler.cpp:385), which is a separate problem.

The two builds have different bases (986721f vs 0685bffb), 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:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6454526681) A second game: Resident Evil Requiem (#1929), Windows 11, RX 9070 XT. - On the official 0.3.0 build (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. - With a Windows build of this PR on main 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: ErrorDeviceLost` at `commandScheduler.cpp:385`), which is a separate problem. The two builds have different bases (986721f vs 0685bffb), 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 (https://git.gtahub.st/github/KytyPS5--KytyPS5/issues/1929).
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-27 21:59 UTC · original

@⁠Ben-Dash sorry for the late answer.

  • The build I linked on 10-21 (main 28648188 with 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.
  • Your 10-24 result (139 shaders including the 309-block compute shader, act_prologue, 453 flips) gets past the overflow. The stall after it, with ProxySetSync waiting on "ProxySet Cull" with no timeout while the overlay shows 781,800 write-tracking faults per second, is a different problem. The log excerpt doesn't name the build: which build or branch was that?
  • andsouzam's yotei-bringup branch, which you're testing in #1599, has this PR's stack change unchanged (GpuThreadStackSize of 64 MiB with Common::ThreadWithStack in graphicsRun.cpp), so your results there run with it too.
**@⁠Nawid3333** on GitHub · 2026-10-27 21:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6454667148) @⁠Ben-Dash sorry for the late answer. - The build I linked on 10-21 (main 28648188 with 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. - Your 10-24 result (139 shaders including the 309-block compute shader, act_prologue, 453 flips) gets past the overflow. The stall after it, with ProxySetSync waiting on "ProxySet Cull" with no timeout while the overlay shows 781,800 write-tracking faults per second, is a different problem. The log excerpt doesn't name the build: which build or branch was that? - andsouzam's yotei-bringup branch, which you're testing in #1599, has this PR's stack change unchanged (`GpuThreadStackSize` of 64 MiB with `Common::ThreadWithStack` in `graphicsRun.cpp`), so your results there run with it too.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-28 21:10 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

Minor · Make the thread-creation checks unconditional. In KYTY_FINAL builds, a… · threads.cpp:380-430

src/common/threads.cpp:380-430
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Make the thread-creation checks unconditional. In KYTY_FINAL builds, a failed create is ignored and SendCommandSync can block forever.

ThreadWithStack checks each thread-creation call with EXIT_IF. EXIT_IF is compiled out in KYTY_FINAL builds, so a failed CreateThread, _beginthreadex, pthread_attr_init, pthread_attr_setstacksize, or pthread_create continues silently. GuestGpu then runs with no GPU worker. SendCommandSync enqueues the command and waits on done.acquire(), which never returns because no worker runs ThreadRun. Non-final builds report and halt on the same failures, so this applies only to KYTY_FINAL builds.

Suggested fix
 #if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS
 	// Reserve the stack; pages are committed as the thread uses them.
 	m_thread->handle = reinterpret_cast<HANDLE>(
 	    _beginthreadex(nullptr, static_cast<unsigned>(stack_size), ThreadWithStackPrivate::Run,
 	                   m_thread.get(), STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr));
-	EXIT_IF(m_thread->handle == nullptr);
+	if (m_thread->handle == nullptr) {
+		EXIT("_beginthreadex failed\n");
+	}
 #else
 	// The calls stay outside EXIT_IF, which does not evaluate its argument in KYTY_FINAL builds.
 	pthread_attr_t attr;
 	const int      init = pthread_attr_init(&attr);
-	EXIT_IF(init != 0);
+	if (init != 0) {
+		EXIT("pthread_attr_init failed: %d\n", init);
+	}
 	const int stack = pthread_attr_setstacksize(&attr, stack_size);
-	EXIT_IF(stack != 0);
+	if (stack != 0) {
+		EXIT("pthread_attr_setstacksize failed: %d\n", stack);
+	}
 	const int created =
 	    pthread_create(&m_thread->thread, &attr, ThreadWithStackPrivate::Run, m_thread.get());
-	EXIT_IF(created != 0);
+	if (created != 0) {
+		EXIT("pthread_create failed: %d\n", created);
+	}
 	pthread_attr_destroy(&attr);
 #endif

Review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4c29ca5c13 and 70803c0806.

Files selected for processing: 5
  • .github/workflows/build.yml
  • CMakeLists.txt
  • src/common/threads.h
  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/guest_gpu/graphicsRun.h

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-28 21:10 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#pullrequestreview-5689744181) · **reviewed** <!-- coderabbit-ai-generated:v1 --> > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/amber-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Minor</strong> · Make the thread-creation checks unconditional. In <code>KYTY_FINAL</code> builds, a… · <code>threads.cpp:380-430</code></summary><blockquote> > <dl> > <dd> > > `src/common/threads.cpp:380-430` > **🩺 Stability & Availability** | **🟡 Minor** | **⚡ Quick win** > > **Make the thread-creation checks unconditional. In `KYTY_FINAL` builds, a failed create is ignored and `SendCommandSync` can block forever.** > > `ThreadWithStack` checks each thread-creation call with `EXIT_IF`. `EXIT_IF` is compiled out in `KYTY_FINAL` builds, so a failed `CreateThread`, `_beginthreadex`, `pthread_attr_init`, `pthread_attr_setstacksize`, or `pthread_create` continues silently. `GuestGpu` then runs with no GPU worker. `SendCommandSync` enqueues the command and waits on `done.acquire()`, which never returns because no worker runs `ThreadRun`. Non-final builds report and halt on the same failures, so this applies only to `KYTY_FINAL` builds. > > <details> > <summary>Suggested fix</summary> > <dl> > <dd> > > ```diff > #if KYTY_PLATFORM == KYTY_PLATFORM_WINDOWS > // Reserve the stack; pages are committed as the thread uses them. > m_thread->handle = reinterpret_cast<HANDLE>( > _beginthreadex(nullptr, static_cast<unsigned>(stack_size), ThreadWithStackPrivate::Run, > m_thread.get(), STACK_SIZE_PARAM_IS_A_RESERVATION, nullptr)); > - EXIT_IF(m_thread->handle == nullptr); > + if (m_thread->handle == nullptr) { > + EXIT("_beginthreadex failed\n"); > + } > #else > // The calls stay outside EXIT_IF, which does not evaluate its argument in KYTY_FINAL builds. > pthread_attr_t attr; > const int init = pthread_attr_init(&attr); > - EXIT_IF(init != 0); > + if (init != 0) { > + EXIT("pthread_attr_init failed: %d\n", init); > + } > const int stack = pthread_attr_setstacksize(&attr, stack_size); > - EXIT_IF(stack != 0); > + if (stack != 0) { > + EXIT("pthread_attr_setstacksize failed: %d\n", stack); > + } > const int created = > pthread_create(&m_thread->thread, &attr, ThreadWithStackPrivate::Run, m_thread.get()); > - EXIT_IF(created != 0); > + if (created != 0) { > + EXIT("pthread_create failed: %d\n", created); > + } > pthread_attr_destroy(&attr); > #endif > ``` > > </dd> > </dl> > </details> > > <!-- cr-comment:v1:692d56454986d533d39c488f --> > > </dd> > </dl> > </blockquote></details> --- <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</summary> <dl> <dd> - **Source mode**: Auto - **Repository**: [KytyPS5/KytyPS5](<https://github.com/KytyPS5/KytyPS5>) - **Branch**: [main](<https://github.com/KytyPS5/KytyPS5/tree/main>) - **File**: [.coderabbit.yaml](<https://github.com/KytyPS5/KytyPS5/blob/c528324d27bb6e6094d9efaf11fdbb88d27d8891/.coderabbit.yaml>) - **Commit**: [c528324](<https://github.com/KytyPS5/KytyPS5/commit/c528324d27bb6e6094d9efaf11fdbb88d27d8891>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `020d3945-3911-4197-8583-3b5ea14c54d9` </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 4c29ca5c132f98120a5d2568afbad7011f21c1dc and 70803c0806a1c64f8aebd0e7682ffd6dab64899d. </dd> </dl> </details> <details> <summary><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 5</summary> <dl> <dd> * `.github/workflows/build.yml` * `CMakeLists.txt` * `src/common/threads.h` * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/guest_gpu/graphicsRun.h` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. </dd> </dl> </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=78d12317-0975-4f96-a4ec-00642be3bf61 attempt=afb5c67c-c894-404b-bcb9-5c1c593e93f2 batch=1/1 -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-28 21:50 UTC · original

@⁠Nawid3333 This is weird fix

**@⁠Nmzik** on GitHub · 2026-10-28 21:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6481544828) @⁠Nawid3333 This is weird fix
Author
Owner

@⁠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:

  • Marvel's Wolverine (#1513): 0xC00000FD, which the report places in LoopBoundProof::Evaluate.
  • Ghost of Yotei (#1599): 0xC00000FD on 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.
  • Resident Evil Requiem (#1929): the log ends in the middle of compute shader 0xbf3870f00b0a8e75. With more stack it translates and the game reaches the main menu and the opening cutscene.

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.

**@⁠Nawid3333** on GitHub · 2026-10-28 22:00 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1609#issuecomment-6481752328) @⁠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: - Marvel's Wolverine (#1513): `0xC00000FD`, which the report places in `LoopBoundProof::Evaluate`. - Ghost of Yotei (#1599): `0xC00000FD` on 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. - Resident Evil Requiem (#1929): the log ends in the middle of compute shader 0xbf3870f00b0a8e75. With more stack it translates and the game reaches the main menu and the opening cutscene. `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

This discussion has been locked. Commenting is limited to contributors.
No description provided.