Repository navigation
[Metal] Present a copy of each flip's frame: Poppy Playtime title flicker - #51
Merged
Merged
Conversation
…e flip The window thread sampled the guest's display image on its own queue, unordered against the guest's GPU work. A double-buffered title that starts its next frame in the buffer still on screen (its safe-for-rendering wait is answered once that buffer's own flip was shown) then had its half-drawn, cleared frame presented: Poppy Playtime's title menu went black in ~10% of window captures. Every flip, GPU or CPU, now blits its frame into a presenter-owned texture in the same command buffer as the flip, fenced after the passes that drew it and before anything the guest records after the flip (the copy SHARPEMU_FLIP_AHEAD already used). The frame is promoted only once that command buffer completed, and a pool texture is reused only when it is not presented, queued or being encoded and its last presentation finished, so the window thread never samples a copy being written. The guest is not held back; the cost is one blit per flip. SHARPEMU_METAL_V2_PRESENT_SNAPSHOT=0 presents the display image live. Poppy title, 160 window shots each: 0/160 black with the snapshot, 31/160 with it off.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before submitting
Please read our contribution guidelines before opening a pull request:
➡️ CONTRIBUTING.md
Summary
Stacked on #49 (it changes the same presenter and VideoOut files); retarget to
mainonce that merges.Poppy Playtime Chapter 1's title menu flickered: the whole game image went black for a frame, with the perf overlay still drawn. It happens on main as well (17 of 160 rapid window captures).
Cause: the game has two display buffers and starts drawing its next frame into the one still on screen, because its
sceAgcDcbWaitUntilSafeForRenderingis answered as soon as that buffer's own flip was shown. The window thread samples the display buffer on its own command queue, unordered against the guest's rendering, so a present that lands after the redraw began shows the cleared frame.Fix: every flip now hands the presenter a copy of its frame, blitted in the command stream at the flip (the pool that
SHARPEMU_FLIP_AHEADalready used), and the presenter promotes it only once that command buffer completed. The window thread never samples a display buffer the guest can still write. Cost: one blit per flip and the pool's textures (4 in use in Poppy and Demon's Souls, 8.1 MB each at 1080p; at most 7). No wait is added on the guest or the GPU worker.SHARPEMU_METAL_V2_PRESENT_SNAPSHOT=0presents the display image directly as before.Tried first and rejected: making the safe-for-rendering wait hold while the buffer is on screen. It removes the flicker too, but stops the worker from recording the next frame while the previous one executes; Demon's Souls dropped from 248 to about 183 flips in the same 30 s segment.
Testing
SHARPEMU_METAL_V2_PRESENT_SNAPSHOT=0.TheSnapshotHandsThePresenterAFrameARedrawOfTheDisplayBufferDoesNotChange;MetalFlipCopyTests2 of 2 withSHARPEMU_TEST_REQUIRE_DEVICE=1.dotnet test SharpEmu.slnx -c Release: every assembly passes (Libs 10639, Gpu.Metal 2074, ShaderCompiler.Metal 4833, ShaderCompiler 2550).uvx reuse lintclean.Not covered
Checklist
CONTRIBUTING.md.N/A.N/A).