AvPlayer: threaded video decode, fix flickering video #2259

Open
github-bot wants to merge 2 commits from github-bot/gh-2259 into main AGit
Owner

@⁠jgoyvaerts on GitHub · 2026-11-13 19:10 UTC · original
jgoyvaerts:port/avplayer → main · +161 −2 · 6 files · 2 commits · open

AvPlayer, fixes the flickering Astro Bot intro video:

  • Decode video on one thread per CPU. FFmpeg's frame output does not depend on the thread count (framemd5 identical); a 4K intro no longer misses frames on one core.
  • Reuse a returned video buffer only after the GPU work the guest submitted before returning it has completed. Astro Bot copies each frame with a DMA that the command processor runs a frame or two later; with the buffer refilled meanwhile (the recycling from a6f4e8e7), that copy got a later frame. GuestGpu now numbers its submissions and tracks those not yet completed.

Tested: avplayer_file_tests (a new case with a fake GPU fails without the fix). The same change in a Jetsku-based build fixed the intro: a hash of the copied textures matches the frame the game was given.

AI use: the code, tests and this description were written with an LLM (Claude). The tests listed ran on a Linux x86-64 build.

🤖 Generated with Claude Code

**@⁠jgoyvaerts** on GitHub · 2026-11-13 19:10 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259) `jgoyvaerts:port/avplayer` → `main` · +161 −2 · 6 files · 2 commits · open AvPlayer, fixes the flickering Astro Bot intro video: - Decode video on one thread per CPU. FFmpeg's frame output does not depend on the thread count (framemd5 identical); a 4K intro no longer misses frames on one core. - Reuse a returned video buffer only after the GPU work the guest submitted before returning it has completed. Astro Bot copies each frame with a DMA that the command processor runs a frame or two later; with the buffer refilled meanwhile (the recycling from a6f4e8e7), that copy got a later frame. GuestGpu now numbers its submissions and tracks those not yet completed. Tested: `avplayer_file_tests` (a new case with a fake GPU fails without the fix). The same change in a Jetsku-based build fixed the intro: a hash of the copied textures matches the frame the game was given. AI use: the code, tests and this description were written with an LLM (Claude). The tests listed ran on a Linux x86-64 build. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Astro Bot's PlayStation Studios intro is a 3840x2160 H.264 video at
59.94 Hz. One emulated core decodes it at about 40 frames per second,
so the game finds no new frame 1-14 times per second and the video
falls up to ~575 ms behind its audio: the intro stutters.

Let FFmpeg decode video streams with frame and slice threads, one per
CPU. Its decoded frames do not depend on the thread count: for this
video, 510 frame MD5s from one thread and from automatic frame+slice
threads are identical (native FFmpeg, -f framemd5). In game, every
pull now gets a frame (0 misses) and the video stays 30-66 ms behind
its clock. AvPlayerFileTests passes.

Audio streams keep their single decoder thread.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
sceAvPlayerGetVideoData gave a frame's buffer back to the decoder as soon as
the guest took the next frame. The guest's GPU work can still read it then:
Astro Bot copies each intro frame into its own texture with a DMA that the
command processor runs one or two guest frames after the guest took the
frame. Once the decoder had refilled the buffer, that copy read a later
frame. The game's two textures then held frames from different points of the
video, so the intro flickered back and forth.

GuestGpu now numbers its submissions and tracks the ones not yet completed.
The guest gives a buffer back stamped with the work submitted until then
(GuestGpu::SubmittedWork). The decoder writes the buffer again only once the
command processor has completed all of that work (GuestGpu::WaitForWork).
The waiter is woken only when its marker is reached, and stop and seek still
cancel the wait.

Check: AvPlayerFileTests gains a case with a fake guest GPU. A buffer
returned with pending work is neither handed out again nor written until the
work completes, and is reused after it. The case fails without the wait. The
same change in a Jetsku-based build fixed the Astro Bot intro: a content hash
of the copied textures now matches the frame the guest was handed.

Signed-off-by: Jonathan Goyvaerts <[email protected]>
Assisted-by: LLM
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:17:35 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original

Explain Change →

Walkthrough

Guest GPU submissions now receive sequence markers, and callers can wait for work through a marker with cancellation support. The graphics API exposes marker retrieval and waiting. The video player records GPU work associated with returned buffers and waits for completion before reusing them. Video decoder setup now enables automatic frame and slice threading. A test covers holding a video buffer while GPU work remains pending and reusing it after completion.

Suggested reviewers: nmzik

Change: Bug fix

Merge Risk: Moderate · up to 44380

The change fixes video buffer reuse, but waiting on a global GPU marker can stall video delivery behind unrelated compute work. A stop or seek during a pending wait can also free texture memory the GPU may still be reading. Both should be resolved or explicitly accepted before merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the two main changes: threaded video decoding in AvPlayer and a fix for flickering video. The changeset matches both. Frame and slice threading is set in OpenCodec, and GPU-aware buffe…
Description check Passed The description states the purpose (fixing the flickering Astro Bot intro video). It explains the two changes: per-CPU video decoding threads and delaying buffer reuse until submitted GPU work complet…
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.
Full details: Title check

Explanation

The title names the two main changes: threaded video decoding in AvPlayer and a fix for flickering video. The changeset matches both. Frame and slice threading is set in OpenCodec, and GPU-aware buffer reuse addresses the flicker. The title is short and specific, though it bundles two changes.

Full details: Description check

Explanation

The description states the purpose (fixing the flickering Astro Bot intro video). It explains the two changes: per-CPU video decoding threads and delaying buffer reuse until submitted GPU work completes. It also names the tests run and the AI-use disclosure. This matches the changeset files, including GuestGpu submission tracking, agc.cpp/agc.h wait APIs, avPlayer.cpp buffer handling, and the new test in AvPlayerFileTests.cpp.

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-13 19:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#issuecomment-6862550235) <!-- 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/2259?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-buttons-v1/explain-change-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-buttons-v1/explain-change.svg" alt="Explain Change →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> <br> Guest GPU submissions now receive sequence markers, and callers can wait for work through a marker with cancellation support. The graphics API exposes marker retrieval and waiting. The video player records GPU work associated with returned buffers and waits for completion before reusing them. Video decoder setup now enables automatic frame and slice threading. A test covers holding a video buffer while GPU work remains pending and reusing it after completion. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> <!-- change_assessment_commit:"443804ca9f84fca126908e815973dd0131615217" --> <!-- change_assessment_priority:{"version":1,"urgency":"p2","manual":false} --> **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-normal-16.svg" width="16" height="16" align="absmiddle" alt=""></picture> Moderate</strong> · up to <code>44380</code></summary> <dl> <dd> <br> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🟡 Moderate** · up to `44380` --> <!-- final_review_risk_coverage:{"sourceCommitId":"443804ca9f84fca126908e815973dd0131615217","coveredCommitId":"443804ca9f84fca126908e815973dd0131615217","kind":"reviewed"} --> The change fixes video buffer reuse, but waiting on a global GPU marker can stall video delivery behind unrelated compute work. A stop or seek during a pending wait can also free texture memory the GPU may still be reading. Both should be resolved or explicitly accepted before merge. <!-- 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> 4</strong></summary> <dl> <dd> <br> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title names the two main changes: threaded video decoding in AvPlayer and a fix for flickering video. The changeset matches both. Frame and slice threading is set in OpenCodec, and GPU-aware buffe… | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description states the purpose (fixing the flickering Astro Bot intro video). It explains the two changes: per-CPU video decoding threads and delaying buffer reuse until submitted GPU work complet… | | 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. | <details> <summary><strong>Full details: Title check</strong></summary> <dl> <dd> <br> **Explanation** The title names the two main changes: threaded video decoding in AvPlayer and a fix for flickering video. The changeset matches both. Frame and slice threading is set in OpenCodec, and GPU-aware buffer reuse addresses the flicker. The title is short and specific, though it bundles two changes. </dd> </dl> </details> <details> <summary><strong>Full details: Description check</strong></summary> <dl> <dd> <br> **Explanation** The description states the purpose (fixing the flickering Astro Bot intro video). It explains the two changes: per-CPU video decoding threads and delaying buffer reuse until submitted GPU work completes. It also names the tests run and the AI-use disclosure. This matches the changeset files, including GuestGpu submission tracking, agc.cpp/agc.h wait APIs, avPlayer.cpp buffer handling, and the new test in AvPlayerFileTests.cpp. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=2259)! 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> <br> - [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> <!-- tips_end -->
@ -981,0 +986,4 @@
// The guest's GPU work may still read the frame it gives back (Astro Bot copies each one
// with a DMA the command processor runs up to two frames later): the decoder writes the
// buffer again only once all work submitted until now has completed.
current_video->buffer->gpu_work = Graphics::SubmittedGpuWork();
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original · edited 2026-11-13 19:28 UTC

Major · Stability & Availability · Heavy lift

Buffer reuse waits for unrelated compute submissions.

SubmittedGpuWork() records the last submission sequence on every queue, including compute. WaitForGpuWork in ReceiveFrames then waits for all of them before the buffer can be reused. Video delivery stalls until every earlier compute submission completes.

If a compute submission waits on a guest signal that is issued only after more video frames are delivered, the stall does not end. The decoder waits on that compute submission, no new frame reaches Video(), and the guest does not issue the signal. Delivery resumes only after stop or seek. Even without a circular wait, a long-running compute submission delays video delivery for its full duration.

Track the readers of each buffer and wait only for submissions that can read it. Do not use a global queue-wide marker for buffer reuse.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-13 19:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#discussion_r4567561547) · edited 2026-11-13 19:28 UTC <!-- coderabbit-ai-generated:v1 --> **<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** · **Stability & Availability** · **Heavy lift** **Buffer reuse waits for unrelated compute submissions.** `SubmittedGpuWork()` records the last submission sequence on every queue, including compute. `WaitForGpuWork` in `ReceiveFrames` then waits for all of them before the buffer can be reused. Video delivery stalls until every earlier compute submission completes. If a compute submission waits on a guest signal that is issued only after more video frames are delivered, the stall does not end. The decoder waits on that compute submission, no new frame reaches `Video()`, and the guest does not issue the signal. Delivery resumes only after stop or seek. Even without a circular wait, a long-running compute submission delays video delivery for its full duration. Track the readers of each buffer and wait only for submissions that can read it. Do not use a global queue-wide marker for buffer reuse. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:3964376ac17484b462a56496 --> <!-- This is an auto-generated reply by CodeRabbit -->
@ -1407,1 +1427,4 @@
}
if ((*buffer)->gpu_work != 0) {
if (!Graphics::WaitForGpuWork((*buffer)->gpu_work, worker_stop)) {
buffers.Push(std::move(*buffer));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original · edited 2026-11-13 19:29 UTC

Major · Stability & Availability · Heavy lift

Do not destroy video buffers that still have pending GPU work.

The GPU wait at line 1429 can be cancelled by worker_stop. The buffer then returns to video_buffers with gpu_work still set. ResetNoLock() clears that pool at line 1065. The WorkQueue::Clear() call destroys each unique_ptr<GuestBuffer>. GuestBuffer::Reset() then calls deallocate_texture on the buffer, even though the buffer's own comment says the GPU may still read it.

This can release texture memory while a submitted GPU operation still reads it. The repository does not show that the guest-supplied deallocator defers physical reuse. A safe fix needs a retirement path. Buffers with nonzero gpu_work should move to a separate list, and their deallocation should wait until that work completes. A localized diff is not established by the inspected code.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-13 19:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#discussion_r4567561561) · edited 2026-11-13 19:29 UTC <!-- coderabbit-ai-generated:v1 --> **<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** · **Stability & Availability** · **Heavy lift** **Do not destroy video buffers that still have pending GPU work.** The GPU wait at line 1429 can be cancelled by `worker_stop`. The buffer then returns to `video_buffers` with `gpu_work` still set. `ResetNoLock()` clears that pool at line 1065. The `WorkQueue::Clear()` call destroys each `unique_ptr<GuestBuffer>`. `GuestBuffer::Reset()` then calls `deallocate_texture` on the buffer, even though the buffer's own comment says the GPU may still read it. This can release texture memory while a submitted GPU operation still reads it. The repository does not show that the guest-supplied deallocator defers physical reuse. A safe fix needs a retirement path. Buffers with nonzero `gpu_work` should move to a separate list, and their deallocation should wait until that work completes. A localized diff is not established by the inspected code. <!-- fingerprinting:phantom:poseidon:wombat61 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:c75ee42adcacb3ef04012a74 --> <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-13 19:16 UTC · original · reviewed

Actionable comments posted: 2

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 58ca8d1d7f and 443804ca9f.

Files selected for processing: 6

  • src/graphics/guest_gpu/graphicsRun.cpp
  • src/graphics/guest_gpu/graphicsRun.h
  • src/libs/agc.cpp
  • src/libs/agc.h
  • src/libs/avPlayer.cpp
  • tests/AvPlayerFileTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-11-13 19:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#pullrequestreview-5896679538) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 2** <h6> <details> <summary><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="12" height="12" align="absmiddle" alt=""></picture> Review info</summary> <dl> <dd> <br> <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> <br> - **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/58ca8d1d7fd621196a60c0a2bda664f4672815d7/.coderabbit.yaml>) - **Commit**: [58ca8d1](<https://github.com/KytyPS5/KytyPS5/commit/58ca8d1d7fd621196a60c0a2bda664f4672815d7>) - **Layers**: Repository YAML - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `2ab80a75-ab22-4512-8db7-a6c23f8000ff` </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> <br> Reviewing files that changed from the base of the PR and between 58ca8d1d7fd621196a60c0a2bda664f4672815d7 and 443804ca9f84fca126908e815973dd0131615217. </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: 6</summary> <dl> <dd> <br> * `src/graphics/guest_gpu/graphicsRun.cpp` * `src/graphics/guest_gpu/graphicsRun.h` * `src/libs/agc.cpp` * `src/libs/agc.h` * `src/libs/avPlayer.cpp` * `tests/AvPlayerFileTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </dd> </dl> </details> </h6> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=009bc85e-71f5-4c9d-ba7c-2ff9fd93d3af attempt=25409441-105a-4c8f-bc44-1970fdee12b2 batch=1/1 -->
@ -981,0 +986,4 @@
// The guest's GPU work may still read the frame it gives back (Astro Bot copies each one
// with a DMA the command processor runs up to two frames later): the decoder writes the
// buffer again only once all work submitted until now has completed.
current_video->buffer->gpu_work = Graphics::SubmittedGpuWork();
Author
Owner

@⁠jgoyvaerts on GitHub · 2026-11-13 19:28 UTC · original

The wait is deliberately conservative, since the buffer's readers aren't known (here it is a CP DMA on the graphics queue, but a game could sample the frame from compute). It covers only work admitted before the buffer was given back, and the decoder blocks only when every other buffer is in use. Stalling for good would need a submission admitted before the release to block until the game has received more frames than are decoded ahead. Video delivery never blocks the guest, and we haven't seen that pattern. Tracking actual readers would need the buffer cache to record reads of AvPlayer ranges. That's possible as a follow-up if you prefer it.

**@⁠jgoyvaerts** on GitHub · 2026-11-13 19:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#discussion_r4567690831) The wait is deliberately conservative, since the buffer's readers aren't known (here it is a CP DMA on the graphics queue, but a game could sample the frame from compute). It covers only work admitted before the buffer was given back, and the decoder blocks only when every other buffer is in use. Stalling for good would need a submission admitted before the release to block until the game has received more frames than are decoded ahead. Video delivery never blocks the guest, and we haven't seen that pattern. Tracking actual readers would need the buffer cache to record reads of AvPlayer ranges. That's possible as a follow-up if you prefer it.
@ -1407,1 +1427,4 @@
}
if ((*buffer)->gpu_work != 0) {
if (!Graphics::WaitForGpuWork((*buffer)->gpu_work, worker_stop)) {
buffers.Push(std::move(*buffer));
Author
Owner

@⁠jgoyvaerts on GitHub · 2026-11-13 19:28 UTC · original

This is pre-existing. Before this PR, buffers returned by Video() sat in the same pool and ResetNoLock() freed them the same way, while GPU work could still read them. This PR doesn't change when buffers are freed. A buffer whose wait was cancelled goes back to the pool exactly as before. Deferring those frees until the work completes would need a blocking or deferred free on the guest thread (Stop/Close). I'd keep that as a separate change.

**@⁠jgoyvaerts** on GitHub · 2026-11-13 19:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#discussion_r4567691302) This is pre-existing. Before this PR, buffers returned by `Video()` sat in the same pool and `ResetNoLock()` freed them the same way, while GPU work could still read them. This PR doesn't change when buffers are freed. A buffer whose wait was cancelled goes back to the pool exactly as before. Deferring those frees until the work completes would need a blocking or deferred free on the guest thread (Stop/Close). I'd keep that as a separate change.
@ -981,0 +986,4 @@
// The guest's GPU work may still read the frame it gives back (Astro Bot copies each one
// with a DMA the command processor runs up to two frames later): the decoder writes the
// buffer again only once all work submitted until now has completed.
current_video->buffer->gpu_work = Graphics::SubmittedGpuWork();
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-13 19:29 UTC · original

@⁠jgoyvaerts Thanks for the explanation. The conservative wait makes sense while buffer readers are unknown, including possible compute readers.

My comment overstated the effect: the decoder waits on the selected buffer, but Video() can still deliver frames that are ready. A long-running earlier submission can delay future output, and a circular wait remains possible, but I have not established an affected game.

I agree that reader tracking can be a follow-up rather than a requirement for this PR. I’m not marking the concern as addressed because the conservative wait remains.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-13 19:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#discussion_r4567695869) <!-- coderabbit-ai-generated:v1 --> @⁠jgoyvaerts Thanks for the explanation. The conservative wait makes sense while buffer readers are unknown, including possible compute readers. My comment overstated the effect: the decoder waits on the selected buffer, but `Video()` can still deliver frames that are ready. A long-running earlier submission can delay future output, and a circular wait remains possible, but I have not established an affected game. I agree that reader tracking can be a follow-up rather than a requirement for this PR. I’m not marking the concern as addressed because the conservative wait remains. --- > 📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
@ -1407,1 +1427,4 @@
}
if ((*buffer)->gpu_work != 0) {
if (!Graphics::WaitForGpuWork((*buffer)->gpu_work, worker_stop)) {
buffers.Push(std::move(*buffer));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-11-13 19:29 UTC · original

Analysis chain

Script executed:

#!/bin/bash
set -u
repo="KytyPS5/KytyPS5"
pr="2259"
base=$(gh api "repos/$repo/pulls/$pr" --jq '.base.sha') || exit 1
head=$(gh api "repos/$repo/pulls/$pr" --jq '.head.sha') || exit 1
printf 'PR base: %s\nPR head: %s\n' "$base" "$head"
basefile=$(mktemp --suffix=.cpp)
if ! git show "$base:src/libs/avPlayer.cpp" > "$basefile" 2>/dev/null; then
  gh api "repos/$repo/contents/src/libs/avPlayer.cpp?ref=$base" --jq .content | base64 --decode > "$basefile" || exit 1
fi
printf '\n--- Base outline ---\n'
ast-grep outline "$basefile" --items all --match 'Source|GuestBuffer|WorkQueue' || true
printf '\n--- Base buffer lifecycle ---\n'
rg -n -C 8 'video_buffers\.Push|video_buffers\.Clear|current_video\.reset|void StopWorkers\(|void ResetNoLock\(|~GuestBuffer\(|void Reset\(' "$basefile"
printf '\n--- PR patch for avPlayer.cpp ---\n'
gh api --paginate "repos/$repo/pulls/$pr/files" --jq '.[] | select(.filename == "src/libs/avPlayer.cpp") | .patch'
rm -f "$basefile"

Length of output: 9366


@jgoyvaerts You’re right. The base already returned video buffers to the pool and cleared that pool without a GPU completion wait. I withdraw this as a regression finding.

The potential teardown risk remains, but it can be addressed separately.


📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings.

Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-11-13 19:29 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/2259#discussion_r4567701525) <!-- coderabbit-ai-generated:v1 --> <details> <summary>Analysis chain</summary> <dl> <dd> <br> Script executed: ```shell #!/bin/bash set -u repo="KytyPS5/KytyPS5" pr="2259" base=$(gh api "repos/$repo/pulls/$pr" --jq '.base.sha') || exit 1 head=$(gh api "repos/$repo/pulls/$pr" --jq '.head.sha') || exit 1 printf 'PR base: %s\nPR head: %s\n' "$base" "$head" basefile=$(mktemp --suffix=.cpp) if ! git show "$base:src/libs/avPlayer.cpp" > "$basefile" 2>/dev/null; then gh api "repos/$repo/contents/src/libs/avPlayer.cpp?ref=$base" --jq .content | base64 --decode > "$basefile" || exit 1 fi printf '\n--- Base outline ---\n' ast-grep outline "$basefile" --items all --match 'Source|GuestBuffer|WorkQueue' || true printf '\n--- Base buffer lifecycle ---\n' rg -n -C 8 'video_buffers\.Push|video_buffers\.Clear|current_video\.reset|void StopWorkers\(|void ResetNoLock\(|~GuestBuffer\(|void Reset\(' "$basefile" printf '\n--- PR patch for avPlayer.cpp ---\n' gh api --paginate "repos/$repo/pulls/$pr/files" --jq '.[] | select(.filename == "src/libs/avPlayer.cpp") | .patch' rm -f "$basefile" ``` Length of output: 9366 --- </dd> </dl> </details> `@jgoyvaerts` You’re right. The base already returned video buffers to the pool and cleared that pool without a GPU completion wait. I withdraw this as a regression finding. The potential teardown risk remains, but it can be addressed separately. --- > 📝 Learnings were not changed: only organization members or users with write access to this repository can add or remove learnings. <!-- <review_comment_withdrawn> --> Review thread resolved. <sub><i>You are interacting with an AI system.</i></sub> <!-- This is an auto-generated reply by CodeRabbit -->
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/2259/head:github-bot/gh-2259'
git switch 'github-bot/gh-2259'

Merge

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