Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Metal double-buffering at 120 fps

Tags:

ios

metal

Is there a way to get double-buffering at 120Hz (ProMotion) instead of triple buffering? I'm trying to minimize UI latency.

When I use Xcode's iOS Game template (which renders a rotating cube), I still get triple-buffering at 120hz, despite the trivial amount of work. It's double-buffered at 60hz.

To reproduce:

  1. Create a new project in Xcode using File → New → Project
  2. Select iOS → Game
  3. Select Swift / Metal
  4. In GameViewController add mtkView.preferredFramesPerSecond = 120
  5. Product → Profile
  6. Select Metal System Trace
  7. Observe: triple buffering (3 colors for frames):

Image showing triple buffering in Instruments

Looking at the graph, it seems the GPU finishes well within the time required for double-buffering.

Here's a useful video to watch for some background: https://developer.apple.com/videos/play/wwdc2015/233/

like image 496
Taylor Avatar asked Jan 18 '26 09:01

Taylor


1 Answers

Apps can control the max number Metal of drawables CAMetalLayer.maximumDrawableCount. Setting this to 2 will force double buffering (3 is the default). Be aware that this makes it more likely -[CAMetalLayer nextDrawable] (or MTKView equivalents) will return nil, forcing you to drop a frame.

like image 189
endomachi Avatar answered Jan 20 '26 01:01

endomachi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!