Is there interest in supporting a Metal version of Cycles for MacOS?

Nothing presentable yet, it’s a huge mess at the moment. Most of the Obj-C required is pretty simple, the lion’s share of the work is bringing all of the current compute kernel code into Metal without having to reimplement and maintain a parallel implementation of all of Cycle’s kernels for Metal. I already have the settings UI implemented for selecting which Metal device you want to render with and exposing those device names back to the UI via the python UI bindings which is cool but like I said, the rest of the work is very Metal-heavy. :metal:

9 Likes

Yea I understand not being presentable. But if there were some example code, perhaps I could help write codegen or other stuff that might speed process along. I’m a pretty experienced software engineer, and could lend a hand doing dirty work, if that’s of interest. I just need some template of stuff to jump off of.

5 Likes

I’ll post here as soon as anything goes up and I’d love to have other sets of eyes on it

10 Likes

@DrewFitz:
I don’t think I got any further than you are, but for what it’s worth, this is the source code of my attempt at getting Cycles to run on Metal:

6 Likes

@StefanW, looking over your changes, was your strategy to mirror the OpenCL code, rather than the Optix code? Just making sure I understood what you were attempting to do.

I was taking OpenCL as the starting point, yes. I guess you got to start somewhere :slight_smile:
Maybe I’m jaded, but our Optix/CUDA kernels are so big, I wouldn’t be surprised if it was too big for the Metal compiler. A split kernel like OpenCL is using it might be easier to digest for the compiler.

Also, when developing the Metal kernel on a Mac, odds are you’re using an AMD GPU, so rebooting the same machine into Linux or Windows would give you OpenCL as comparison, not Optix.

@StefanW I haven’t actually gotten anywhere. Also I’m on a 13" MBP, so no discrete GPU, just the built in Intel. So I’m really gimp’d, and just wanted some more rendering horsepower.

I know nothing about graphics programming, and was reading up about it for the first time. I also don’t know the difference between a split and unikernel, though presumably it’s just level of modularity etc.

I would guess we just need to implement the basic primitives and the renderer handles the rest? So the base stuff in device.h and device_split_kernel.h?

We would need to translate the OpenCL shaders into Metal shading language, and “that should be it”?

Quick update: I finally got a successful metal library compiled, but when I tried to create the render pipelines from it, the driver hangs endlessly waiting for LLVM to compile and optimize it for the current GPU. I’ve reported this to Apple and am looking to move to the split kernel implementation to hopefully make each pipeline more digestible for Metal.

17 Likes

Here’s a link to my WIP branch if anyone would like to see what I’ve done so far. Keep in mind this is a very early proof-of-concept implementation https://github.com/DrewFitz/Blender

16 Likes

You can add a target to your generated Xcode project to build the metal library by adding a custom build phase with the following commands:

xcrun -sdk macosx metal -std=macos-metal2.2 -c intern/cycles/device/Shaders.metal -o $DERIVED_FILE_DIR/Shaders.air -Iintern/cycles
xcrun -sdk macosx metallib $DERIVED_FILE_DIR/Shaders.air -o $DERIVED_FILE_DIR/Shaders.metallib
12 Likes

That’s awesome. I believe!

Glad to see some work being done on Metal. I’m a super long-time iOS engineer (11 years, ugh…), and while my deep graphics knowledge is limited, I’m happy to help out with any of the higher level interface/Swift stuff if need be.

9 Likes

Does anyone know what else could be done to get this endeavor more support? Like campaigning somewhere or joining forces with other forums?

4 Likes

Update: messing with the split kernel implementation, having a bit of trouble with the atomics usage in that shader code given how Metal implements its flavor of C++ atomics but that should be fine with a bit more tinkering. Will push to github when anything significant is working.

18 Likes

You are a hope for all mac-trapped humanity! How can we give some donations to you?

6 Likes

Wow, I’m also believing! Thanks for all your hard work! I wish I could help you, I’m only a UI designer… sigh :pensive:

2 Likes

Hey is there an update on the metal support. I would also donate some money if you can make it work. Or can I install the file from GitHub?

1 Like

Thank you @DrewFitz for all your work. I downloaded the code from GitHub yesterday. @GianniSim, to install this, you would have to “build” Blender from the code. There are some resources about that if you’re not sure what “compiling a program from sources” might mean: https://wiki.blender.org/wiki/Building_Blender/Mac

I can build the latest Blender 2.90 okay, but building the Metal project gave me an error. The error was related to Python not being found and apparently might be an issue with my environment variables, but I haven’t been able to troubleshoot it yet after working on it all day yesterday.

I have some decent Python skills and know C, but don’t really know anything about Metal. I would love to contribute some labor, but I do have to teach myself the framework first. I fear I may be too ambitious and not helpful enough, but thank you for your work and I hope I can support in some way. But first I have to fix my own system…

1 Like

There’s not much point to building it for now since none of it actually works yet. I normally wouldn’t even share code in this state but I figured people would want to poke around and maybe some Metal experts would have some pointers.

I’ll be posting more updates this week, I’ve been busy buying a house and moving! As for donations, I’d rather people donate what they’d like to organizations fighting for racial justice. I’m extremely lucky to have a stable, well-paying day job so it would be much more motivating to me to know my work on this is inspiring people to help others that need it more.

16 Likes

I have one of these

Would using my cpu/gpu via cloud computing help with time?
Furthermore, would pooling resources help with testing?

1 Like