Skip to content

CoreGraphics: Use double-buffering#343

Open
madsmtm wants to merge 2 commits intomasterfrom
apple-buffering
Open

CoreGraphics: Use double-buffering#343
madsmtm wants to merge 2 commits intomasterfrom
apple-buffering

Conversation

@madsmtm
Copy link
Member

@madsmtm madsmtm commented Mar 5, 2026

We currently create a new Vec each time next_buffer is called on macOS/iOS, which is inefficient, we should instead re-use previous buffers.

Double-buffering seems to be enough here, but in degenerate cases such as the following:

let buffer = surface.next_buffer().unwrap();
buffer.present().unwrap();
// Render again right after!
let buffer = surface.next_buffer().unwrap();
buffer.present().unwrap();

The buffer is still referenced by QuartzCore somewhere, so we need to keep a (potentially infinite) queue of buffers around to be sure that we don't write to a buffer that's in use. Note that there is no way to wait for the buffers to be released since the release happens on the main thread (and besides, we probably don't want to wait either?).

All of this might be overly pedantic, I haven't yet found a case where the buffer is actually read from by QuartzCore while being the back buffer (unlike with IOSurface).

Tested on:

  • macOS 15.7.3 M2
  • macOS 10.12.6 Intel
  • iOS simulator

Should help with #83.
Extracted from #329 (since that one may be more difficult to land).

@madsmtm madsmtm added enhancement New feature or request DS - CoreGraphics macOS/iOS/tvOS/watchOS/visionOS backend labels Mar 5, 2026
@madsmtm madsmtm added this to the Softbuffer v0.5 milestone Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DS - CoreGraphics macOS/iOS/tvOS/watchOS/visionOS backend enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

1 participant