Blender  V2.93
bvh.cpp
Go to the documentation of this file.
1 /*
2  * Adapted from code copyright 2009-2010 NVIDIA Corporation
3  * Modifications Copyright 2011, Blender Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include "bvh/bvh.h"
19 
20 #include "bvh/bvh2.h"
21 #include "bvh/bvh_embree.h"
22 #include "bvh/bvh_multi.h"
23 #include "bvh/bvh_optix.h"
24 
25 #include "util/util_logging.h"
26 #include "util/util_progress.h"
27 
29 
30 /* BVH Parameters. */
31 
32 const char *bvh_layout_name(BVHLayout layout)
33 {
34  switch (layout) {
35  case BVH_LAYOUT_NONE:
36  return "NONE";
37  case BVH_LAYOUT_BVH2:
38  return "BVH2";
39  case BVH_LAYOUT_EMBREE:
40  return "EMBREE";
41  case BVH_LAYOUT_OPTIX:
42  return "OPTIX";
45  return "MULTI";
46  case BVH_LAYOUT_ALL:
47  return "ALL";
48  }
49  LOG(DFATAL) << "Unsupported BVH layout was passed.";
50  return "";
51 }
52 
53 BVHLayout BVHParams::best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
54 {
55  const BVHLayoutMask requested_layout_mask = (BVHLayoutMask)requested_layout;
56  /* Check whether requested layout is supported, if so -- no need to do
57  * any extra computation.
58  */
59  if (supported_layouts & requested_layout_mask) {
60  return requested_layout;
61  }
62  /* Some bit magic to get widest supported BVH layout. */
63  /* This is a mask of supported BVH layouts which are narrower than the
64  * requested one.
65  */
66  BVHLayoutMask allowed_layouts_mask = (supported_layouts & (requested_layout_mask - 1));
67  /* If the requested layout is not supported, choose from the supported layouts instead. */
68  if (allowed_layouts_mask == 0) {
69  allowed_layouts_mask = supported_layouts;
70  }
71  /* We get widest from allowed ones and convert mask to actual layout. */
72  const BVHLayoutMask widest_allowed_layout_mask = __bsr((uint32_t)allowed_layouts_mask);
73  return (BVHLayout)(1 << widest_allowed_layout_mask);
74 }
75 
76 /* BVH */
77 
78 BVH::BVH(const BVHParams &params_,
79  const vector<Geometry *> &geometry_,
80  const vector<Object *> &objects_)
81  : params(params_), geometry(geometry_), objects(objects_)
82 {
83 }
84 
86  const vector<Geometry *> &geometry,
87  const vector<Object *> &objects,
88  Device *device)
89 {
90  switch (params.bvh_layout) {
91  case BVH_LAYOUT_BVH2:
92  return new BVH2(params, geometry, objects);
93  case BVH_LAYOUT_EMBREE:
94 #ifdef WITH_EMBREE
95  return new BVHEmbree(params, geometry, objects);
96 #else
97  break;
98 #endif
99  case BVH_LAYOUT_OPTIX:
100 #ifdef WITH_OPTIX
101  return new BVHOptiX(params, geometry, objects, device);
102 #else
103  (void)device;
104  break;
105 #endif
108  return new BVHMulti(params, geometry, objects);
109  case BVH_LAYOUT_NONE:
110  case BVH_LAYOUT_ALL:
111  break;
112  }
113  LOG(DFATAL) << "Requested unsupported BVH layout.";
114  return NULL;
115 }
116 
CCL_NAMESPACE_BEGIN const char * bvh_layout_name(BVHLayout layout)
Definition: bvh.cpp:32
int BVHLayoutMask
Definition: bvh_params.h:39
CCL_NAMESPACE_BEGIN typedef KernelBVHLayout BVHLayout
Definition: bvh_params.h:32
Definition: bvh2.h:46
static BVHLayout best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
Definition: bvh.cpp:53
BVHLayout bvh_layout
Definition: bvh_params.h:70
Definition: bvh/bvh.h:80
vector< Geometry * > geometry
Definition: bvh/bvh.h:83
static BVH * create(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects, Device *device)
Definition: bvh.cpp:85
BVH(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition: bvh.cpp:78
BVHParams params
Definition: bvh/bvh.h:82
vector< Object * > objects
Definition: bvh/bvh.h:84
Definition: device.h:293
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
#define CCL_NAMESPACE_END
@ BVH_LAYOUT_OPTIX
@ BVH_LAYOUT_NONE
@ BVH_LAYOUT_EMBREE
@ BVH_LAYOUT_MULTI_OPTIX
@ BVH_LAYOUT_BVH2
@ BVH_LAYOUT_ALL
@ BVH_LAYOUT_MULTI_OPTIX_EMBREE
unsigned int uint32_t
Definition: stdint.h:83
#define LOG(severity)
Definition: util_logging.h:49
__forceinline uint32_t __bsr(const uint32_t x)
Definition: util_simd.h:376