Quartz/CoreGraphics is broken. What to do now?

DSP, Plug-in and Host development discussion.
User avatar
Urs
u-he
23477 posts since 8 Aug, 2002 from Berlin

Post Thu Mar 14, 2019 11:43 am

After profiling our UIs, there's only one conclusion left: Quartz Extreme is no more, Apple renders CoreGraphics paths on the CPU. That's on a decent hexacore trashcan Mac. And they do it muuuuuch slower than I can do it myself. But when I do it myself a whopping 10 times faster, the bottleneck is the offscreen graphics context which, when turned into a CGImage, Apple just can't seem to forward to the GPU in time.

So what are you guys doing these days, particularly with OpenGL dead on macOS as well? Metal? Or is there some other API which popped up over the last decade which I conveniently ignored?

Not sure if I need an answer or if I just wanted to vent, but I guess I'd be grateful for some pointers.

mystran
KVRAF
5251 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 2:08 pm

Write an OpenGL code-path (deprecated or not) that resolves the pressing issues, then file a TODO item about replacing said code-path with a Metal alternative "when time permits." :D
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

User avatar
Urs
u-he
23477 posts since 8 Aug, 2002 from Berlin

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 2:29 pm

mystran wrote:
Thu Mar 14, 2019 2:08 pm
Write an OpenGL code-path (deprecated or not) that resolves the pressing issues, then file a TODO item about replacing said code-path with a Metal alternative "when time permits." :D
Argh. I really wish for something a tad more permanent. I've done OpenGL 20 years ago, I know the pains.

Does anyone know if Cairo ist hardware accelerated on old Macs with recent OSes? We got Cairo foing on Linux, maybe it's time to set it up on macOS?

mystran
KVRAF
5251 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 2:35 pm

Urs wrote:
Thu Mar 14, 2019 2:29 pm
mystran wrote:
Thu Mar 14, 2019 2:08 pm
Write an OpenGL code-path (deprecated or not) that resolves the pressing issues, then file a TODO item about replacing said code-path with a Metal alternative "when time permits." :D
Argh. I really wish for something a tad more permanent. I've done OpenGL 20 years ago, I know the pains.
If you're drawing in software and just uploading a texture and drawing a quad, I don't think it's that bad. The main painful part is just getting the context management right, to avoid random crashes. :)

Keep in mind that once you require Metal, you'll also require macOS 10.11 minimum. Whether that's a concern for you, I don't know... but it's something to keep in mind.
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

User avatar
Urs
u-he
23477 posts since 8 Aug, 2002 from Berlin

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 2:48 pm

True.

I guess I want neither OpenGL nor Metal. I want something that doesn't require writing a shader in order to paint a vector UI with some bitmaps thrown in.

Also, I want unicode fonts. And I don't want to parse them into paths first in order to display some text.

In other words, I want a working and viable alternative to CoreGraphics which doesn't take 50% of 3.6GHz CPU to render a path with 500 points at 25Hz.

mystran
KVRAF
5251 posts since 12 Feb, 2006 from Helsinki, Finland

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 2:50 pm

Urs wrote:
Thu Mar 14, 2019 2:48 pm
I guess I want neither OpenGL nor Metal. I want something that doesn't require writing a shader in order to paint a vector UI with some bitmaps thrown in.
Well... you CAN use legacy OpenGL with fixed-function pipeline to avoid the shader. :)
If you'd like Signaldust to return, please ask Katinka Tuisku to resign.

0degree
KVRist
194 posts since 29 Jan, 2017

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 3:30 pm

Urs wrote:
Thu Mar 14, 2019 2:29 pm
mystran wrote:
Thu Mar 14, 2019 2:08 pm
Write an OpenGL code-path (deprecated or not) that resolves the pressing issues, then file a TODO item about replacing said code-path with a Metal alternative "when time permits." :D
Argh. I really wish for something a tad more permanent. I've done OpenGL 20 years ago, I know the pains.

Does anyone know if Cairo ist hardware accelerated on old Macs with recent OSes? We got Cairo foing on Linux, maybe it's time to set it up on macOS?
There was some project like Cairo OpenGL but it was experimental/abandoned so it’s still CPU only. Bitwig is based on Cairo and they are lagging badly on MacOSes :(
OpenGL is deprecated...How can you not love Apple?

flocked
KVRist
64 posts since 27 Nov, 2018

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 11:26 pm

I think moving to Metal is the most future proof on MacOS.

https://moltengl.com/moltengl/
There is this which converts OpenGL ES to Metal. Not sure how hard it would be for you to convert your initial code from OpenGL to OpenGL ES.

Alternative for the future you could might use Vulcan on Windows and Linux and use MoltenVK, which converts Vulcan to Metal and is open source.
https://github.com/KhronosGroup/MoltenVK

Both SDK are quite feature complete and get update frequently. They get used by other bigger companies and seem easy to implement.

juha_p
KVRian
542 posts since 21 Feb, 2006 from FI

Re: Quartz/CoreGraphics is broken. What to do now?

Post Thu Mar 14, 2019 11:54 pm

Hmm... this change was reported to come about 9 months ago - https://appleinsider.com/articles/18/06 ... tes-opengl

quikquak
KVRian
522 posts since 6 Aug, 2005 from England

Re: Quartz/CoreGraphics is broken. What to do now?

Post Fri Mar 15, 2019 12:08 am

OpenGL was redacted. Thankfully there’s this...
https://www.phoronix.com/scan.php?page= ... ed-MVK-App

arne
KVRist
143 posts since 21 Aug, 2004

Re: Quartz/CoreGraphics is broken. What to do now?

Post Fri Mar 15, 2019 12:35 am

Check out CALayers and its property drawsAsynchronously. CoreGraphics may use the GPU instead of the CPU when rendering into such a configured CALayer. It's not documented though, so may change anytime.

User avatar
Urs
u-he
23477 posts since 8 Aug, 2002 from Berlin

Re: Quartz/CoreGraphics is broken. What to do now?

Post Fri Mar 15, 2019 1:22 am

arne wrote:
Fri Mar 15, 2019 12:35 am
Check out CALayers and its property drawsAsynchronously. CoreGraphics may use the GPU instead of the CPU when rendering into such a configured CALayer. It's not documented though, so may change anytime.
Thanks Arne,

I read into CALayers last night, but it seems they work best if they are immutable objects. What really slows us down on Mac are dynamic elements: Waveshape/Envelope displays, spectrum, anything that uses a lot of bezier paths and can't be cached.

But maybe I got that wrong. Maybe one can draw into a CALayer and then have it paint asynchronously later? In that case I might give it a shot!

- U

arne
KVRist
143 posts since 21 Aug, 2004

Re: Quartz/CoreGraphics is broken. What to do now?

Post Fri Mar 15, 2019 1:26 am

Yes, you can setup your NSView so that it draws into a CALayer. VSTGUI is using it. After creating the view you just call [nsView setWantsLayer:YES]; and nsView.layer.drawsAsynchronously = YES; No other code change required to check it out.

User avatar
Urs
u-he
23477 posts since 8 Aug, 2002 from Berlin

Re: Quartz/CoreGraphics is broken. What to do now?

Post Fri Mar 15, 2019 1:30 am

flocked wrote:
Thu Mar 14, 2019 11:26 pm
I think moving to Metal is the most future proof on MacOS.

https://moltengl.com/moltengl/
There is this which converts OpenGL ES to Metal. Not sure how hard it would be for you to convert your initial code from OpenGL to OpenGL ES.

Alternative for the future you could might use Vulcan on Windows and Linux and use MoltenVK, which converts Vulcan to Metal and is open source.
https://github.com/KhronosGroup/MoltenVK

Both SDK are quite feature complete and get update frequently. They get used by other bigger companies and seem easy to implement.
That sounds great! As I said, my OpenGl experience was 20 years ago and pre-dates shaders and stuff. How hard is it these days to render a full unicode set of fonts? Like, using a TrueType font for all the ordinary UI stuff and getting a fallback font from the system for user edited text which can contain *any* unicode glyph?

User avatar
Urs
u-he
23477 posts since 8 Aug, 2002 from Berlin

Re: Quartz/CoreGraphics is broken. What to do now?

Post Fri Mar 15, 2019 1:32 am

arne wrote:
Fri Mar 15, 2019 1:26 am
Yes, you can setup your NSView so that it draws into a CALayer. VSTGUI is using it. After creating the view you just call [nsView setWantsLayer:YES]; and nsView.layer.drawsAsynchronously = YES; No other code change required to check it out.
Oi, that would be easy. I'll check this out!

Thanks!

Return to “DSP and Plug-in Development”