Blender  V3.3
bvh.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011-2022 Blender Foundation. */
4 
5 #include "bvh/bvh.h"
6 
7 #include "bvh/bvh2.h"
8 #include "bvh/embree.h"
9 #include "bvh/metal.h"
10 #include "bvh/multi.h"
11 #include "bvh/optix.h"
12 
13 #include "util/log.h"
14 #include "util/progress.h"
15 
17 
18 /* BVH Parameters. */
19 
20 const char *bvh_layout_name(BVHLayout layout)
21 {
22  switch (layout) {
23  case BVH_LAYOUT_NONE:
24  return "NONE";
25  case BVH_LAYOUT_BVH2:
26  return "BVH2";
27  case BVH_LAYOUT_EMBREE:
28  return "EMBREE";
29  case BVH_LAYOUT_OPTIX:
30  return "OPTIX";
31  case BVH_LAYOUT_METAL:
32  return "METAL";
37  return "MULTI";
38  case BVH_LAYOUT_ALL:
39  return "ALL";
40  }
41  LOG(DFATAL) << "Unsupported BVH layout was passed.";
42  return "";
43 }
44 
45 BVHLayout BVHParams::best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
46 {
47  const BVHLayoutMask requested_layout_mask = (BVHLayoutMask)requested_layout;
48  /* Check whether requested layout is supported, if so -- no need to do
49  * any extra computation.
50  */
51  if (supported_layouts & requested_layout_mask) {
52  return requested_layout;
53  }
54  /* Some bit magic to get widest supported BVH layout. */
55  /* This is a mask of supported BVH layouts which are narrower than the
56  * requested one.
57  */
58  BVHLayoutMask allowed_layouts_mask = (supported_layouts & (requested_layout_mask - 1));
59  /* If the requested layout is not supported, choose from the supported layouts instead. */
60  if (allowed_layouts_mask == 0) {
61  allowed_layouts_mask = supported_layouts;
62  }
63  /* We get widest from allowed ones and convert mask to actual layout. */
64  const BVHLayoutMask widest_allowed_layout_mask = __bsr((uint32_t)allowed_layouts_mask);
65  return (BVHLayout)(1 << widest_allowed_layout_mask);
66 }
67 
68 /* BVH */
69 
70 BVH::BVH(const BVHParams &params_,
71  const vector<Geometry *> &geometry_,
72  const vector<Object *> &objects_)
73  : params(params_), geometry(geometry_), objects(objects_)
74 {
75 }
76 
78  const vector<Geometry *> &geometry,
79  const vector<Object *> &objects,
80  Device *device)
81 {
82  switch (params.bvh_layout) {
83  case BVH_LAYOUT_BVH2:
84  return new BVH2(params, geometry, objects);
85  case BVH_LAYOUT_EMBREE:
86 #ifdef WITH_EMBREE
87  return new BVHEmbree(params, geometry, objects);
88 #else
89  break;
90 #endif
91  case BVH_LAYOUT_OPTIX:
92 #ifdef WITH_OPTIX
93  return new BVHOptiX(params, geometry, objects, device);
94 #else
95  (void)device;
96  break;
97 #endif
98  case BVH_LAYOUT_METAL:
99 #ifdef WITH_METAL
100  return bvh_metal_create(params, geometry, objects, device);
101 #else
102  (void)device;
103  break;
104 #endif
109  return new BVHMulti(params, geometry, objects);
110  case BVH_LAYOUT_NONE:
111  case BVH_LAYOUT_ALL:
112  break;
113  }
114  LOG(DFATAL) << "Requested unsupported BVH layout.";
115  return NULL;
116 }
117 
CCL_NAMESPACE_BEGIN const char * bvh_layout_name(BVHLayout layout)
Definition: bvh.cpp:20
Definition: bvh2.h:33
Definition: multi.h:12
static BVHLayout best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
Definition: bvh.cpp:45
BVHLayout bvh_layout
Definition: params.h:80
Definition: bvh/bvh.h:63
vector< Geometry * > geometry
Definition: bvh/bvh.h:66
static BVH * create(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects, Device *device)
Definition: bvh.cpp:77
BVH(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition: bvh.cpp:70
BVHParams params
Definition: bvh/bvh.h:65
vector< Object * > objects
Definition: bvh/bvh.h:67
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
SyclQueue void void size_t num_bytes void
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
@ BVH_LAYOUT_OPTIX
@ BVH_LAYOUT_NONE
@ BVH_LAYOUT_METAL
@ BVH_LAYOUT_EMBREE
@ BVH_LAYOUT_MULTI_OPTIX
@ BVH_LAYOUT_BVH2
@ BVH_LAYOUT_MULTI_METAL
@ BVH_LAYOUT_MULTI_METAL_EMBREE
@ BVH_LAYOUT_ALL
@ BVH_LAYOUT_MULTI_OPTIX_EMBREE
#define LOG(severity)
Definition: log.h:36
int BVHLayoutMask
Definition: params.h:47
CCL_NAMESPACE_BEGIN typedef KernelBVHLayout BVHLayout
Definition: params.h:19
__forceinline uint32_t __bsr(const uint32_t x)
Definition: simd.h:386
unsigned int uint32_t
Definition: stdint.h:80