Add support for Metal shaders in modules

I’m starting some work on GPU accelerated number crunching and want to use Metal compute shaders for that. In contrast to OpenCL/OpenGL, metal shaders get compiled by Xcode at compile time. Adding a .metal file to my Projucer project and enabling compilation for that file in the Projucer works. However if I move my shader file to a module there is no chance to compile it automatically. I guess it should be easy to treat .metal files in modules like .mm files that are automatically enabled for compilation if on Mac OS?

I got it working with some quick changes. I created a pull request on GitHub for it, however I’m not sure if this is a good implementation.
While all other source files in JuceLibraryCode depend on the preprocessors search path and therefore use the #include <module_name/file_name> syntax, the metal preprocessor doesn’t seem to know the search path, so a relative include directive from the JuceLibraryCode folder to the metal file is needed.

This seems to work good but breaks the existing structure. Anyone knows if the metal preprocessor / compiler can get a search path too somehow? Didn’t find anything regarding that.

1 Like

Edit: Found the relevant setting in the Xcode project file and updated the Pull request. This now works seamlessly with really minimal changes to the projucer, it simply treats .metal files in the module like Obj-C files that are only compiled on apple and sets the modules folder as search path to the metal compiler.

1 Like

Yes, please add support for Metal shaders in modules!

Metal shader support comes with JUCE 6


Is that a current feature of JUCE 6 or an upcoming one? I see it listed on the website, as

Support for Metal shaders in JUCE modules

but I don’t see any references to it in the repository…

1 Like