Cycles: enable Metal GPU rendering

This adds the remaining bits to enable Metal on macOS. There are still
performance optimizations and other improvements planned, but it should
now be ready for early testing.

This is currently only enabled on in Arm builds for M1 GPUs. It is not
yet working on AMD or Intel GPUs.

Ref T92212

Differential Revision: https://developer.blender.org/D13503
This commit is contained in:
Brecht Van Lommel
2021-12-13 13:48:36 +01:00
committed by Brecht Van Lommel
parent 8ba6302696
commit 3f96555123
4 changed files with 19 additions and 6 deletions

View File

@@ -463,6 +463,11 @@ if(NOT APPLE)
mark_as_advanced(CYCLES_HIP_BINARIES_ARCH) mark_as_advanced(CYCLES_HIP_BINARIES_ARCH)
endif() endif()
# Apple Metal
if(APPLE)
option(WITH_CYCLES_DEVICE_METAL "Enable Cycles Apple Metal compute support" ON)
endif()
# Draw Manager # Draw Manager
option(WITH_DRAW_DEBUG "Add extra debug capabilities to Draw Manager" OFF) option(WITH_DRAW_DEBUG "Add extra debug capabilities to Draw Manager" OFF)
mark_as_advanced(WITH_DRAW_DEBUG) mark_as_advanced(WITH_DRAW_DEBUG)

View File

@@ -61,6 +61,7 @@ set(WITH_MEM_JEMALLOC ON CACHE BOOL "" FORCE)
# platform dependent options # platform dependent options
if(APPLE) if(APPLE)
set(WITH_COREAUDIO ON CACHE BOOL "" FORCE) set(WITH_COREAUDIO ON CACHE BOOL "" FORCE)
set(WITH_CYCLES_DEVICE_METAL ON CACHE BOOL "" FORCE)
endif() endif()
if(NOT WIN32) if(NOT WIN32)
set(WITH_JACK ON CACHE BOOL "" FORCE) set(WITH_JACK ON CACHE BOOL "" FORCE)

View File

@@ -556,12 +556,17 @@ endif()
########################################################################### ###########################################################################
if(WITH_CYCLES_DEVICE_METAL) if(WITH_CYCLES_DEVICE_METAL)
FIND_LIBRARY(METAL_LIBRARY Metal) find_library(METAL_LIBRARY Metal)
if (METAL_LIBRARY)
message(STATUS "Found Metal: ${METAL_LIBRARY}") # This file was added in the 12.0 SDK, use it as a way to detect the version.
else() if (METAL_LIBRARY AND NOT EXISTS "${METAL_LIBRARY}/Headers/MTLFunctionStitching.h")
message(STATUS "Metal version too old, must be SDK 12.0 or newer, disabling WITH_CYCLES_DEVICE_METAL")
set(WITH_CYCLES_DEVICE_METAL OFF)
elseif (NOT METAL_LIBRARY)
message(STATUS "Metal not found, disabling WITH_CYCLES_DEVICE_METAL") message(STATUS "Metal not found, disabling WITH_CYCLES_DEVICE_METAL")
set(WITH_CYCLES_DEVICE_METAL OFF) set(WITH_CYCLES_DEVICE_METAL OFF)
else()
message(STATUS "Found Metal: ${METAL_LIBRARY}")
endif() endif()
endif() endif()

View File

@@ -596,9 +596,11 @@ class USERPREF_PT_system_cycles_devices(SystemPanel, CenterAlignMixIn, Panel):
@classmethod @classmethod
def poll(cls, _context): def poll(cls, _context):
# No GPU rendering on macOS currently. # No GPU rendering on macOS x86_64 currently.
import platform
import sys import sys
return bpy.app.build_options.cycles and sys.platform != "darwin" return bpy.app.build_options.cycles and \
(sys.platform != "darwin" or platform.machine() == "arm64")
def draw_centered(self, context, layout): def draw_centered(self, context, layout):
prefs = context.preferences prefs = context.preferences