[Bf-blender-cvs] [e688c927eb3] master: Fix T94022: Both options GPU/CPU checked under preferences cause viewport render crash. (ARM/Metal)

Michael Jones noreply at git.blender.org
Mon Dec 13 23:34:56 CET 2021


Commit: e688c927eb3a82b21ba744ec57540ea2cd4f44c8
Author: Michael Jones
Date:   Mon Dec 13 22:20:16 2021 +0000
Branches: master
https://developer.blender.org/rBe688c927eb3a82b21ba744ec57540ea2cd4f44c8

Fix T94022: Both options GPU/CPU checked under preferences cause viewport render crash. (ARM/Metal)

This fixes crash T94022 when selecting live viewport render with both GPU & CPU devices selected. It is caused by incorrect `KernelBVHLayout` assignment. Similar to `BVH_LAYOUT_MULTI_OPTIX` for Optix, this patch adds a `BVH_LAYOUT_MULTI_METAL` to correctly redirect to the correct Metal BVH layout type.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D13561

===================================================================

M	intern/cycles/bvh/bvh.cpp
M	intern/cycles/device/multi/device.cpp
M	intern/cycles/kernel/types.h
M	intern/cycles/scene/geometry.cpp
M	intern/cycles/scene/object.cpp

===================================================================

diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp
index 540bf52f7ac..703639e29f3 100644
--- a/intern/cycles/bvh/bvh.cpp
+++ b/intern/cycles/bvh/bvh.cpp
@@ -44,6 +44,7 @@ const char *bvh_layout_name(BVHLayout layout)
     case BVH_LAYOUT_METAL:
       return "METAL";
     case BVH_LAYOUT_MULTI_OPTIX:
+    case BVH_LAYOUT_MULTI_METAL:
     case BVH_LAYOUT_MULTI_OPTIX_EMBREE:
     case BVH_LAYOUT_MULTI_METAL_EMBREE:
       return "MULTI";
@@ -115,6 +116,7 @@ BVH *BVH::create(const BVHParams &params,
       break;
 #endif
     case BVH_LAYOUT_MULTI_OPTIX:
+    case BVH_LAYOUT_MULTI_METAL:
     case BVH_LAYOUT_MULTI_OPTIX_EMBREE:
     case BVH_LAYOUT_MULTI_METAL_EMBREE:
       return new BVHMulti(params, geometry, objects);
diff --git a/intern/cycles/device/multi/device.cpp b/intern/cycles/device/multi/device.cpp
index baab84f4035..5ec3ef1b785 100644
--- a/intern/cycles/device/multi/device.cpp
+++ b/intern/cycles/device/multi/device.cpp
@@ -124,6 +124,11 @@ class MultiDevice : public Device {
       return BVH_LAYOUT_MULTI_OPTIX;
     }
 
+    /* With multiple Metal devices, every device needs its own acceleration structure */
+    if (bvh_layout_mask == BVH_LAYOUT_METAL) {
+      return BVH_LAYOUT_MULTI_METAL;
+    }
+
     /* When devices do not share a common BVH layout, fall back to creating one for each */
     const BVHLayoutMask BVH_LAYOUT_OPTIX_EMBREE = (BVH_LAYOUT_OPTIX | BVH_LAYOUT_EMBREE);
     if ((bvh_layout_mask_all & BVH_LAYOUT_OPTIX_EMBREE) == BVH_LAYOUT_OPTIX_EMBREE) {
@@ -155,6 +160,7 @@ class MultiDevice : public Device {
     }
 
     assert(bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX ||
+           bvh->params.bvh_layout == BVH_LAYOUT_MULTI_METAL ||
            bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE ||
            bvh->params.bvh_layout == BVH_LAYOUT_MULTI_METAL_EMBREE);
 
@@ -179,6 +185,8 @@ class MultiDevice : public Device {
         BVHParams params = bvh->params;
         if (bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX)
           params.bvh_layout = BVH_LAYOUT_OPTIX;
+        else if (bvh->params.bvh_layout == BVH_LAYOUT_MULTI_METAL)
+          params.bvh_layout = BVH_LAYOUT_METAL;
         else if (bvh->params.bvh_layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE)
           params.bvh_layout = sub.device->info.type == DEVICE_OPTIX ? BVH_LAYOUT_OPTIX :
                                                                       BVH_LAYOUT_EMBREE;
diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h
index c39289224ad..34f909a06d9 100644
--- a/intern/cycles/kernel/types.h
+++ b/intern/cycles/kernel/types.h
@@ -1224,7 +1224,8 @@ typedef enum KernelBVHLayout {
   BVH_LAYOUT_MULTI_OPTIX = (1 << 3),
   BVH_LAYOUT_MULTI_OPTIX_EMBREE = (1 << 4),
   BVH_LAYOUT_METAL = (1 << 5),
-  BVH_LAYOUT_MULTI_METAL_EMBREE = (1 << 6),
+  BVH_LAYOUT_MULTI_METAL = (1 << 6),
+  BVH_LAYOUT_MULTI_METAL_EMBREE = (1 << 7),
 
   /* Default BVH layout to use for CPU. */
   BVH_LAYOUT_AUTO = BVH_LAYOUT_EMBREE,
diff --git a/intern/cycles/scene/geometry.cpp b/intern/cycles/scene/geometry.cpp
index 346b030817f..ca330c5544d 100644
--- a/intern/cycles/scene/geometry.cpp
+++ b/intern/cycles/scene/geometry.cpp
@@ -166,7 +166,7 @@ bool Geometry::need_build_bvh(BVHLayout layout) const
 {
   return is_instanced() || layout == BVH_LAYOUT_OPTIX || layout == BVH_LAYOUT_MULTI_OPTIX ||
          layout == BVH_LAYOUT_METAL || layout == BVH_LAYOUT_MULTI_OPTIX_EMBREE ||
-         layout == BVH_LAYOUT_MULTI_METAL_EMBREE;
+         layout == BVH_LAYOUT_MULTI_METAL || layout == BVH_LAYOUT_MULTI_METAL_EMBREE;
 }
 
 bool Geometry::is_instanced() const
diff --git a/intern/cycles/scene/object.cpp b/intern/cycles/scene/object.cpp
index bf224a81af5..77c6c6614e3 100644
--- a/intern/cycles/scene/object.cpp
+++ b/intern/cycles/scene/object.cpp
@@ -533,7 +533,7 @@ void ObjectManager::device_update_object_transform(UpdateObjectTransformState *s
 void ObjectManager::device_update_prim_offsets(Device *device, DeviceScene *dscene, Scene *scene)
 {
   BVHLayoutMask layout_mask = device->get_bvh_layout_mask();
-  if (layout_mask != BVH_LAYOUT_METAL && layout_mask != BVH_LAYOUT_MULTI_METAL_EMBREE) {
+  if (layout_mask != BVH_LAYOUT_METAL && layout_mask != BVH_LAYOUT_MULTI_METAL && layout_mask != BVH_LAYOUT_MULTI_METAL_EMBREE) {
     return;
   }



More information about the Bf-blender-cvs mailing list