oF with Metal Compute Shader, is it possible?

Hello!
Currently, macOS does not support openGL 4.3 so we can’t use compute shader.
So I came up an idea to use Metal shader for calucation and transport the result back to openGL.

Metal compute shader
https://developer.apple.com/documentation/metal/performing_calculations_on_a_gpu

Does anyone have an experience like this?
We can use OpenGL and Metal API simultaneously, but I’m not sure about the impact of video memory sharing/copying. I found ofxMetal which draws ofBoxPrimitive with Metal texture attached, so it seems possible. I haven’t tried compiling though.

It would be good to say good-bye to Ping-pong shader finally.

1 Like

my memory is hazy, but I think ofxArKit uses a metal shader internally –

some info on some of the steps of mixing gl and metal

https://developer.apple.com/documentation/metal/metal_sample_code_library/mixing_metal_and_opengl_rendering_in_a_view

2 Likes

@dimitre
Thank you for the info. Wow, didn’t know this GL on Metal exist.
It even has GLFW support. Incredible.
Negative point is that it has a lot of missing functions.
Have you managed to use GL 4.6 + oF (on macOS)?

@zach
It has a Metal shader indeed, Shader.metal is the one.
It seems very helpful as a real-world example how to use Metal together with oF.
I will look into it.
Thank you!

Hey @hrs no I never tried.

Hey thanks all for posting about this! I’ve been wondering about it for quite a while and its been a low priority so I haven’t had a chance to look at it. But its really fun to know that this exists in case I need it some day!

1 Like

Hi everybody,

sorry for not undertanding exactly your posts.

After writing glsl shaders (up to version 410) for many OF apps, on Windows, Ubuntu and old mac’s, I am going to buy a new mac m1 but I can’t understand if these shaders of mine will still run on the brand new mac.

On the other hand, since OF 0.11.1 we have support for Big Sur and in fact, the OSX version of OF has the shader examples with GLSL code as for the other platforms. If such shaders are in the package they should work, I guess.

So my question is:

Do any OF apps with OpenGL and GLSL code that run on OF 0.11.2 on Windows and Ubuntu run also on Big Sur and Monterey or do we have translate all the glsl code to metal, even that one include in the addons?

Thannks so much,

Paolo

glsl shaders work on osx as well as windows and linux – thinking specifically of fragment and vertex shaders. I think there is a maximum OpenGL version osx supports (I can’t recall offhand) but in general I have no problems going back and forth…

edit : sorry after reading this, I realize you are speaking specifically about compute shaders. I’m less clear on that (I generally only use fragment and vertex shaders). in terms of vert and fragment shaders, no translation is necessary and should work across platforms.

Thanks so much @zach,

I was exactly meaning fragment and vertex shaders, I didn’t express myself correctly in the post!

Cheers