Update (Nov 7): a few things below have changed since this was posted. Windows are now presented through their own CAMetalLayer instead of a grid of CAMetalLayer tiles (the tiles made fullscreen crawl), JUCE_METAL_RENDERER_TILE_SIZE is gone, paint() now only records (path outlines and new glyphs are prepared on the background queue), and the branch was rewritten as a single commit on top of 9.0.5. Details and new numbers in this reply.
Hi all,
At UVI our plugin UIs have a lot of small things moving at the same time (meters, LEDs, waveforms, knobs), and on macOS that has always been more expensive than it should be with JUCE. So we’ve been working on a Metal rendering engine for JUCE on macOS, and we’d like to get it upstream.
Full disclosure on how it was made: the code was written with Claude Opus 5.5, with me driving it. I set the goals and constraints (match CoreGraphics, never be slower than it, stay a drop-in LowLevelGraphicsContext), pointed it at how other renderers solve each problem instead of inventing things, reviewed the design choices, and asked for measurements at every step. That’s also why there’s a separate repo with all the tools we used to check pixels and timings: we didn’t want to rely on anything we couldn’t measure.
It’s on a branch of our fork, one commit on top of 9.0.5:
The tools we used to test and measure it are here:
Why
On macOS today you have two options and neither is great for plugin UIs with lots of small things animating (meters, LEDs, knobs):
- The default CoreGraphics path goes through a layer-backed NSView, and AppKit merges every dirty rect of the window into a single bounding box. Two meters in opposite corners repainting at 60 Hz means the whole window gets repainted at 60 Hz.
- JUCE_COREGRAPHICS_RENDER_WITH_MULTIPLE_PAINT_CALLS fixes that (it keeps the dirty rects separate and draws into a CAMetalLayer), but it still rasterises everything with CoreGraphics on the CPU and then uploads and blits the whole window every frame, so it ends up slower.
The Metal renderer keeps the exact list of dirty rects like the second one, but does the drawing on the GPU.
How it works
- It’s a LowLevelGraphicsContext used by NSViewComponentPeer, enabled with JUCE_METAL_RENDERER=1 (off by default). It shows up as a “Metal Renderer” rendering engine and is picked by default when a Metal device is there. You can switch engines at runtime like before (Software, CoreGraphics, CoreGraphics Metal Layer, Metal).
- paint() runs on the message thread as usual and only records instances (one quad per shape/glyph/image). Encoding and submission happen on a background queue, up to three frames in flight.
- The window keeps a retained texture. Only the dirty rects are repainted into it, in one traversal of the component tree.
The window is presented as a grid of CAMetalLayer tiles (128 pt by default, JUCE_METAL_RENDERER_TILE_SIZE) and a frame only presents the tiles it touched, because WindowServer’s cost follows the area that changes.Now: the window is presented through its own CAMetalLayer, the retained texture being copied into a drawable each frame.- Rects, rounded rects, ellipses and lines are drawn analytically with exact pixel-area anti-aliasing. Strokes only shade the band around the outline, not the inside.
- Arbitrary paths (fills, strokes, path clips) use coverage counting: edges are accumulated into a float texture and summed per row, which gives exact area coverage for both winding rules.
- Text: glyphs are rasterised once through JUCE’s own CoreGraphics context into an atlas (with LRU eviction) and placed the way CoreGraphics places them, so text looks identical to the CoreGraphics renderer. Large text goes through the glyph outlines and coverage counting.
- Linear and radial gradients are interpolated per pixel like CGGradient. Tiled image fills, image clips, clipToPath, transparency layers and the four blend modes are all done on the GPU.
- Opaque shapes are drawn first with depth, so the pixels they hide are never shaded, and draws are reordered into a few batches when they don’t overlap.
- Images modified every frame (scopes, meters drawn into an Image) reuse their textures instead of allocating new ones.
What still goes through JUCE’s software renderer (drawn into a small image and composited):
- colour glyphs (emoji, COLR fonts)
- image fills using a single-channel image, or with a degenerate transform
- images bigger than 16384 px, or images whose texture couldn’t be created
In the GraphicsDemo and our own UIs none of those come up.
Matching CoreGraphics
We matched the pixel output against CoreGraphics rather than the software renderer, since that’s what macOS users see today. On every GraphicsDemo test (all clip modes) plus extra scenes (text at fractional scales, thin strokes, blend modes, gradients, transformed shapes and images), most tests differ from CoreGraphics on less than 0.1% of the pixels. Where CoreGraphics isn’t exact itself (curve flattening, rotated edges), we stay within 1/255 of the exact pixel area instead of copying its error.
Numbers (M1 MacBook Pro, 60 Hz)
How we measured: DemoRunner built in Release from the branch, GraphicsDemo with its default settings (position and rotation animated, no clipping), the engine switched at runtime from DemoRunner’s settings. For each engine and each of the 14 tests: 2 s to settle, then a 6 s window. CPU is the process CPU time (all threads) divided by the frames drawn; GPU is the union of each process’s GPU intervals in an Instruments trace (Metal Application + GPU), divided the same way. Frame rate is the demo’s own “Actual FPS”. The scripts that do all this are in the bench repo.
Per test, app CPU / app GPU in ms per frame (60 fps unless noted):
| Test | CoreGraphics | Metal | OpenGL | Software | CG Metal Layer |
|---|---|---|---|---|---|
| Paths: Radial Gradients | 2.3 / 0.33 | 2.1 / 0.87 | 3.3 / 1.44 | 6.2 / 0.38 | 6.4 / 0.46 |
| Paths: Linear Gradients | 2.6 / 0.34 | 3.3 / 0.96 | 3.4 / 1.42 | 6.3 / 0.40 | 6.2 / 0.46 |
| Paths: Solid | 3.1 / 0.31 | 3.3 / 0.92 | 3.4 / 1.44 | 5.6 / 0.40 | 5.3 / 0.57 |
| Fill Types: Rectangles | 3.0 / 0.25 | 2.9 / 0.86 | 3.0 / 1.41 | 6.3 / 0.38 | 6.2 / 0.51 |
| Paths: Stroked | 2.7 / 0.22 | 3.1 / 0.85 | 3.7 / 1.49 | 5.8 / 0.39 | 5.2 / 0.56 |
| Images: RGB | 2.8 / 0.24 | 2.9 / 0.90 | 2.7 / 1.41 | 6.9 / 0.32 | 9.3 / 0.49 |
| Images: RGB Tiled | 14.4 / 0.60 | 3.2 / 1.07 | 2.7 / 1.42 | 9.6 / 0.35 | 13.6 / 0.46 |
| Images: ARGB | 2.6 / 0.24 | 3.2 / 0.78 | 2.7 / 1.40 | 6.8 / 0.33 | 8.8 / 0.48 |
| Images: ARGB Tiled | 14.0 / 0.54 | 3.1 / 1.03 | 2.7 / 1.42 | 9.0 / 0.33 | 13.7 / 0.44 |
| Blur | 6.2 / 0.44 | 5.3 / 0.85 | 5.4 / 1.60 | 9.5 / 0.49 | 11.9 / 0.59 |
| Glyphs | 3.3 / 0.21 | 3.1 / 0.53 | 2.9 / 1.37 | 5.1 / 0.39 | 4.0 / 0.50 |
| SVG | 4.2 / 1.33 | 3.8 / 1.08 | 9.1 / 8.34 | 25.8 / 0.29 (30 fps) | 43.8 / 0.44 (19 fps) |
| Lines | 3.8 / 0.97 | 3.1 / 1.07 | 4.3 / 2.03 | 6.9 / 0.35 | 6.4 / 0.46 |
| Shapes | 3.1 / 0.26 | 2.5 / 0.73 | 3.2 / 1.42 | 6.0 / 0.38 | 5.9 / 0.57 |
Things worth pointing out:
- Metal and stock CoreGraphics are level on CPU. On GPU, Metal is ~0.6 ms per frame above on these light scenes, about the same on every test, which points to a fixed cost per frame (most likely presenting the tiles and the retained texture) rather than the drawing itself. That’s the next thing we want to bring down.
- Metal is the flattest: its worst test is 6.2 ms (Blur, where the demo itself computes the blur on the CPU). CoreGraphics jumps to 14-15 ms on tiled images, OpenGL to 17.5 ms on SVG, and the two CPU-based engines can’t hold 60 fps on SVG.
- Against JUCE’s OpenGL renderer, Metal is lower on every column: app GPU -37%, WindowServer CPU -25%, WindowServer GPU -40%.
- Where Metal’s own time goes (its JUCE_METAL_RENDERER_STATS output on these tests): ~0.4 ms of paint() recording on the message thread, ~0.3 ms of encoding on a background thread, ~0.9 ms of GPU of which 0.2 ms is the copy into the tiles and 0.3-0.4 ms the path coverage on the path tests.
A window with 1,200 widgets (rounded rect, outline and a label each), closer to a real plugin UI. Labels are cached (see the side note below), except for the CoreGraphics frame rate with 2 areas, which was measured without the cache:
| Load | Engine | fps | Paint | CPU+GPU power |
|---|---|---|---|---|
| 2 areas repainting | CoreGraphics | ~30 | ~18 ms per repaint (whole window) | ~1.3 W |
| 2 areas repainting | Metal | 60 | < 1 ms (the 2 areas) | ~0.2-0.3 W |
| 8 areas repainting | CoreGraphics | ~1.35 W | ||
| 8 areas repainting | Metal | 60 | ~0.25 W | |
| Whole window | CoreGraphics | 60 | 5.1 ms | ~2.1 W |
| Whole window | Metal | 60 | 2.9 ms | ~1.45 W |
Power is the whole machine (CPU + GPU, powermetrics), so it includes WindowServer; idle is ~0.15 W. With 2 or 8 small areas, CoreGraphics repaints the merged bounding box, i.e. the whole window, every time.
Side note we ran into while measuring: with more than 128 different labels on screen, Graphics::drawText’s arrangement cache misses on every frame and text layout becomes ~90% of the message thread, whatever the renderer. Without caching the labels, CoreGraphics drops to ~34 fps on whole-window repaints and Metal spends 12 ms per frame in paint(), almost all of it in drawText.
Testing
- The bench repo renders the same scenes through each engine, captures the window as WindowServer shows it, and compares the captures pixel by pixel (CoreGraphics, Software and Metal).
- There are self-checking scenes for partial repaints (stale content shows up immediately) and for images rewritten every frame.
- Everything above also runs clean with the Metal validation layer, including live resize.
Status
- Off unless JUCE_METAL_RENDERER is set, so it doesn’t change anything for existing projects.
- On light scenes there’s still a fixed GPU cost of about 0.5 ms per frame above stock CoreGraphics. That’s what we want to look at next.
- The bench tools aren’t specific to Metal: they compare any engine against CoreGraphics, the software renderer or the exact pixel area, and report CPU/GPU time per frame. They could be useful for Direct2D too.
JUCE team, we’re happy to reshape this however suits you (names, file layout, options, splitting it into smaller pieces) and to keep working on it with you.

