From f2bb4c617f2ecb0802f9bb01876ef7ca5eba702e Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Tue, 31 Oct 2023 11:14:16 +0100 Subject: [PATCH] Cycles: Apple M3 tuning including hardware raytracing This PR adds tunings for the [newly announced](https://www.youtube.com/watch?v=ctkW3V0Mh-k) M3 family of chips. In particular, MetalRT will be enabled as the automatic default for intersection testing on M3 and beyond to take advantage of hardware raytracing. This will result in significant path-tracing speedups, as well as faster BVH builds. Pull Request: https://projects.blender.org/blender/blender/pulls/114296 --- intern/cycles/device/metal/device.mm | 3 +++ intern/cycles/device/metal/kernel.mm | 6 ++++++ intern/cycles/device/metal/util.h | 1 + intern/cycles/device/metal/util.mm | 3 +++ 4 files changed, 13 insertions(+) diff --git a/intern/cycles/device/metal/device.mm b/intern/cycles/device/metal/device.mm index f3e951a0b26..a472056166c 100644 --- a/intern/cycles/device/metal/device.mm +++ b/intern/cycles/device/metal/device.mm @@ -74,6 +74,9 @@ void device_metal_info(vector &devices) } # endif + /* Use hardware raytracing for faster rendering on architectures that support it. */ + info.use_metalrt_by_default = (MetalInfo::get_apple_gpu_architecture(device) >= APPLE_M3); + devices.push_back(info); device_index++; } diff --git a/intern/cycles/device/metal/kernel.mm b/intern/cycles/device/metal/kernel.mm index 23a16589352..c300fdc9d96 100644 --- a/intern/cycles/device/metal/kernel.mm +++ b/intern/cycles/device/metal/kernel.mm @@ -41,6 +41,12 @@ struct ShaderCache { if (MetalInfo::get_device_vendor(mtlDevice) == METAL_GPU_APPLE) { switch (MetalInfo::get_apple_gpu_architecture(mtlDevice)) { default: + case APPLE_M3: + /* Peak occupancy is achieved through Dynamic Caching on M3 GPUs. */ + for (size_t i = 0; i < DEVICE_KERNEL_NUM; i++) { + occupancy_tuning[i] = {64, 64}; + } + break; case APPLE_M2_BIG: occupancy_tuning[DEVICE_KERNEL_INTEGRATOR_COMPACT_SHADOW_STATES] = {384, 128}; occupancy_tuning[DEVICE_KERNEL_INTEGRATOR_INIT_FROM_CAMERA] = {640, 128}; diff --git a/intern/cycles/device/metal/util.h b/intern/cycles/device/metal/util.h index 0212ee3c5a2..62b5902b1bd 100644 --- a/intern/cycles/device/metal/util.h +++ b/intern/cycles/device/metal/util.h @@ -31,6 +31,7 @@ enum AppleGPUArchitecture { APPLE_M1, APPLE_M2, APPLE_M2_BIG, + APPLE_M3, }; /* Contains static Metal helper functions. */ diff --git a/intern/cycles/device/metal/util.mm b/intern/cycles/device/metal/util.mm index 31f92040d2d..0eb448c15bb 100644 --- a/intern/cycles/device/metal/util.mm +++ b/intern/cycles/device/metal/util.mm @@ -56,6 +56,9 @@ AppleGPUArchitecture MetalInfo::get_apple_gpu_architecture(id device) else if (strstr(device_name, "M2")) { return get_apple_gpu_core_count(device) <= 10 ? APPLE_M2 : APPLE_M2_BIG; } + else if (strstr(device_name, "M3")) { + return APPLE_M3; + } return APPLE_UNKNOWN; }