Blender V5.0
bvh.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2010 NVIDIA Corporation
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Adapted code from NVIDIA Corporation. */
7
8#include "bvh/bvh.h"
9
10#include "bvh/bvh2.h"
11#include "bvh/multi.h"
12
13#ifdef WITH_EMBREE
14# include "bvh/embree.h"
15#endif
16#ifdef WITH_HIPRT
17# include "bvh/hiprt.h"
18#endif
19#ifdef WITH_METAL
20# include "bvh/metal.h"
21#endif
22#ifdef WITH_OPTIX
23# include "bvh/optix.h"
24#endif
25
26#include "util/log.h"
27
29
30/* BVH Parameters. */
31
32const 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";
40 return "EMBREE";
42 return "OPTIX";
44 return "METAL";
46 return "HIPRT";
48 return "EMBREEGPU";
57 return "MULTI";
58 case BVH_LAYOUT_ALL:
59 return "ALL";
60 }
61 LOG_DFATAL << "Unsupported BVH layout was passed.";
62 return "";
63}
64
65BVHLayout BVHParams::best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
66{
67 const BVHLayoutMask requested_layout_mask = (BVHLayoutMask)requested_layout;
68 /* Check whether requested layout is supported, if so -- no need to do
69 * any extra computation.
70 */
71 if (supported_layouts & requested_layout_mask) {
72 return requested_layout;
73 }
74 /* Some bit magic to get widest supported BVH layout. */
75 /* This is a mask of supported BVH layouts which are narrower than the
76 * requested one.
77 */
78 BVHLayoutMask allowed_layouts_mask = (supported_layouts & (requested_layout_mask - 1));
79 /* If the requested layout is not supported, choose from the supported layouts instead. */
80 if (allowed_layouts_mask == 0) {
81 allowed_layouts_mask = supported_layouts;
82 }
83 /* We get widest from allowed ones and convert mask to actual layout. */
84 const BVHLayoutMask widest_allowed_layout_mask = __bsr((uint32_t)allowed_layouts_mask);
85 return (BVHLayout)(1 << widest_allowed_layout_mask);
86}
87
88/* BVH */
89
90BVH::BVH(const BVHParams &params_,
91 const vector<Geometry *> &geometry_,
92 const vector<Object *> &objects_)
93 : params(params_), geometry(geometry_), objects(objects_)
94{
95}
96
100 Device *device)
101{
102 switch (params.bvh_layout) {
103 case BVH_LAYOUT_BVH2:
104 return make_unique<BVH2>(params, geometry, objects);
107#ifdef WITH_EMBREE
108 return make_unique<BVHEmbree>(params, geometry, objects);
109#else
110 break;
111#endif
112 case BVH_LAYOUT_OPTIX:
113#ifdef WITH_OPTIX
114 return make_unique<BVHOptiX>(params, geometry, objects, device);
115#else
116 (void)device;
117 break;
118#endif
119 case BVH_LAYOUT_METAL:
120#ifdef WITH_METAL
121 return bvh_metal_create(params, geometry, objects, device);
122#else
123 (void)device;
124 break;
125#endif
126 case BVH_LAYOUT_HIPRT:
127#ifdef WITH_HIPRT
128 return make_unique<BVHHIPRT>(params, geometry, objects, device);
129#else
130 (void)device;
131 break;
132#endif
141 return make_unique<BVHMulti>(params, geometry, objects);
142 case BVH_LAYOUT_NONE:
143 case BVH_LAYOUT_ALL:
144 break;
145 }
146 LOG_DFATAL << "Requested unsupported BVH layout.";
147 return nullptr;
148}
149
CCL_NAMESPACE_BEGIN const char * bvh_layout_name(BVHLayout layout)
Definition bvh.cpp:32
static BVHLayout best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
Definition bvh.cpp:65
static unique_ptr< BVH > create(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects, Device *device)
Definition bvh.cpp:97
vector< Geometry * > geometry
Definition bvh/bvh.h:70
BVH(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition bvh.cpp:90
BVHParams params
Definition bvh/bvh.h:69
vector< Object * > objects
Definition bvh/bvh.h:71
#define CCL_NAMESPACE_END
@ BVH_LAYOUT_OPTIX
@ BVH_LAYOUT_MULTI_HIPRT_EMBREE
@ BVH_LAYOUT_NONE
@ BVH_LAYOUT_MULTI_EMBREEGPU
@ BVH_LAYOUT_METAL
@ BVH_LAYOUT_MULTI_HIPRT
@ BVH_LAYOUT_HIPRT
@ BVH_LAYOUT_EMBREE
@ BVH_LAYOUT_MULTI_OPTIX
@ BVH_LAYOUT_BVH2
@ BVH_LAYOUT_EMBREEGPU
@ BVH_LAYOUT_MULTI_METAL
@ BVH_LAYOUT_MULTI_METAL_EMBREE
@ BVH_LAYOUT_MULTI_EMBREEGPU_EMBREE
@ BVH_LAYOUT_ALL
@ BVH_LAYOUT_MULTI_OPTIX_EMBREE
#define LOG_DFATAL
Definition log.h:100
int BVHLayoutMask
Definition params.h:50
KernelBVHLayout BVHLayout
Definition params.h:22
__forceinline uint32_t __bsr(const uint32_t x)
Definition simd.h:407