graphics: drain submitted guest command buffer to fix CPU/GPU fence race (Dead Cells hang, #1189) #1190

Open
github-bot wants to merge 1 commit from github-bot/gh-1190 into main AGit
Owner

@⁠tyyyyyyyyyyyyyyyy on GitHub · 2026-10-08 07:06 UTC · original
tyyyyyyyyyyyyyyyy:fix/dcb-submit-ordering → main · +1 −0 · 1 files · 1 commits · open

Fixes the hard hang on Linux/RADV described in #1189 (Dead Cells, PPSA15552; also reported for other titles).

Root cause (from #1189)

At the hang the gfx queue front is a Graphics submission suspended on IT_WAIT_REG_MEM_64(fence == 1). A gdb hardware watchpoint on the fence shows the value alternating:

WATCH val=1   <- CommandProcessor::WriteData (from CpOpWriteData, the GPU command)
WATCH val=0   <- guest code

i.e. the submitted buffer does IT_WRITE_DATA(1 -> fence) + IT_WAIT_REG_MEM_64(fence == 1), but the guest CPU runs ahead and stores 0 to the same fence before the (asynchronous) GPU thread has finished processing the buffer, so the wait never observes 1. The queue stalls and GuestGpu::SuspendPoint then deadlocks on m_suspend_point_ready. Windows is unaffected (different timing).

Change

GuestGpu::Submit() now drains the submitted buffer before returning to the guest so the guest stays in step with the emulated GPU.

Testing

With this change Dead Cells, Hollow Knight Silksong, Raiden IV and TMNT Splintered Fate all run at 60 fps with no hang (vs. Dead Cells deadlocking within ~30-60 s without it).

Note

WaitForIdle() after every DCB submit is a coarse fix — it serialises CPU and GPU. It is fine on the titles above, but maintainers may prefer a narrower synchronisation. Opening it to start the discussion; happy to rework.

**@⁠tyyyyyyyyyyyyyyyy** on GitHub · 2026-10-08 07:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1190) `tyyyyyyyyyyyyyyyy:fix/dcb-submit-ordering` → `main` · +1 −0 · 1 files · 1 commits · open Fixes the hard hang on Linux/RADV described in #1189 (Dead Cells, PPSA15552; also reported for other titles). ## Root cause (from #1189) At the hang the gfx queue front is a `Graphics` submission suspended on `IT_WAIT_REG_MEM_64(fence == 1)`. A gdb hardware watchpoint on the fence shows the value alternating: ``` WATCH val=1 <- CommandProcessor::WriteData (from CpOpWriteData, the GPU command) WATCH val=0 <- guest code ``` i.e. the submitted buffer does `IT_WRITE_DATA(1 -> fence)` + `IT_WAIT_REG_MEM_64(fence == 1)`, but the guest CPU runs ahead and stores `0` to the same fence before the (asynchronous) GPU thread has finished processing the buffer, so the wait never observes `1`. The queue stalls and `GuestGpu::SuspendPoint` then deadlocks on `m_suspend_point_ready`. Windows is unaffected (different timing). ## Change `GuestGpu::Submit()` now drains the submitted buffer before returning to the guest so the guest stays in step with the emulated GPU. ## Testing With this change Dead Cells, Hollow Knight Silksong, Raiden IV and TMNT Splintered Fate all run at 60 fps with no hang (vs. Dead Cells deadlocking within ~30-60 s without it). ## Note `WaitForIdle()` after every DCB submit is a coarse fix — it serialises CPU and GPU. It is fine on the titles above, but maintainers may prefer a narrower synchronisation. Opening it to start the discussion; happy to rework.
The guest can outrun the emulated GPU: it submits a DCB that ends with
IT_WRITE_DATA(1 -> fence) + IT_WAIT_REG_MEM_64(fence == 1), then immediately starts
the next iteration and stores 0 to the same fence while the GPU thread is still
processing the buffer, so the wait never observes 1. The gfx queue then stalls
(GuestGpu::SuspendPoint deadlocks on m_suspend_point_ready).

Reproduced with Dead Cells (PPSA15552) on Linux/RADV (RX 5700); works on Windows.
A gdb hardware watchpoint on the fence shows the value alternating 1 (written by
CommandProcessor::WriteData from CpOpWriteData) and 0 (written by guest code).

Flushing the submitted buffer in GuestGpu::Submit() keeps the guest in step with
the GPU and fixes the deadlock. Tested with Dead Cells, Hollow Knight Silksong,
Raiden IV and TMNT Splintered Fate (all 60 fps, no hang).

Fixes #1189
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:47:12 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 07:11 UTC · original

Review in Change Stack →

📝 Walkthrough

Walkthrough

GuestGpu::Submit now calls WaitForIdle() after enqueueing a nonempty graphics submission. Empty submissions still return immediately.

Suggested reviewers: nmzik

Priority: ⬆️ High

Change: Bug fix

Merge Risk: 🟠 High · up to 31fe6

Every graphics submission now waits for the GPU to finish. If a submitted command buffer waits for a value that the game writes only after submission returns, the game hangs permanently. This can affect any title that uses that pattern. Replace the full drain with targeted fence synchronization before merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description directly explains the Linux/RADV fence race, the GuestGpu::Submit() change, affected games, testing results, and the synchronization trade-off.
Title check ✅ Passed The title clearly identifies the graphics change, the CPU/GPU fence race, and the primary Dead Cells hang issue.
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.
  • Autopilot · 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-08 07:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1190#issuecomment-6054602338) <!-- 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/1190?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `GuestGpu::Submit` now calls `WaitForIdle()` after enqueueing a nonempty graphics submission. Empty submissions still return immediately. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"31fe6461b5121dcdaff99c7e4baef52884cd72ff" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** **🟠 High** · up to `31fe6` <!-- final_review_risk_coverage:{"sourceCommitId":"31fe6461b5121dcdaff99c7e4baef52884cd72ff","coveredCommitId":"31fe6461b5121dcdaff99c7e4baef52884cd72ff","kind":"reviewed"} --> Every graphics submission now waits for the GPU to finish. If a submitted command buffer waits for a value that the game writes only after submission returns, the game hangs permanently. This can affect any title that uses that pattern. Replace the full drain with targeted fence synchronization before merging. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :---------------- | :--------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------ | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Description check | ✅ Passed | The description directly explains the Linux/RADV fence race, the `GuestGpu::Submit()` change, affected games, testing results, and the synchronization trade-off. | | Title check | ✅ Passed | The title clearly identifies the graphics change, the CPU/GPU fence race, and the primary Dead Cells hang issue. | | 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. | </details> </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">Autopilot</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=1190)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [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) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -145,6 +145,7 @@ void GuestGpu::Submit(std::span<const uint32_t> draw_commands,
submission.commands = draw_commands;
submission.constant_commands = constant_commands;
Enqueue(std::move(submission));
WaitForIdle();
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 07:11 UTC · original

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

Keep Submit() from waiting on guest progress.

WaitForIdle() waits until all submissions complete. If this submission executes a WAIT_REG_MEM for a value that the submitting guest thread will write after Submit() returns, the blocked submission stays pending and this call cannot return. The guest thread cannot perform the write, so the game hangs. Use targeted synchronization for the fence ordering instead of draining blocked PM4 work in Submit().

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 07:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1190#discussion_r4216020160) **🩺 Stability & Availability** | **🟠 Major** | **🏗️ Heavy lift** **Keep `Submit()` from waiting on guest progress.** `WaitForIdle()` waits until all submissions complete. If this submission executes a `WAIT_REG_MEM` for a value that the submitting guest thread will write after `Submit()` returns, the blocked submission stays pending and this call cannot return. The guest thread cannot perform the write, so the game hangs. Use targeted synchronization for the fence ordering instead of draining blocked PM4 work in `Submit()`. <!-- fingerprinting:phantom:triton:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:ceb35264b2215de5927bfa04 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-08 07:11 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: e850eaf3-9ac1-4f80-a82f-bec33cebbbc5
📥 Commits

Reviewing files that changed from the base of the PR and between 5a8808086a and 31fe6461b5.

📒 Files selected for processing (1)
  • src/graphics/guest_gpu/graphicsRun.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-08 07:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1190#pullrequestreview-5452991768) · **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**: `e850eaf3-9ac1-4f80-a82f-bec33cebbbc5` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5a8808086a9815b67d4822cd20cf1e8a7a05f002 and 31fe6461b5121dcdaff99c7e4baef52884cd72ff. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/guest_gpu/graphicsRun.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=70056f08-b352-4511-b996-4f11a890dcc3 attempt=1cd44428-2631-400f-8a50-67984cf59a24 batch=1/1 -->
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1190/head:github-bot/gh-1190'
git switch 'github-bot/gh-1190'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1190'
git switch 'github-bot/gh-1190'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1190'
git switch 'github-bot/gh-1190'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1190'
git switch 'main'
git merge --squash 'github-bot/gh-1190'
git switch 'main'
git merge --ff-only 'github-bot/gh-1190'
git switch 'main'
git merge 'github-bot/gh-1190'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.