Blender V4.3
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/embree.h"
12#include "bvh/hiprt.h"
13#include "bvh/metal.h"
14#include "bvh/multi.h"
15#include "bvh/optix.h"
16
17#include "util/log.h"
18#include "util/progress.h"
19
21
22/* BVH Parameters. */
23
24const char *bvh_layout_name(BVHLayout layout)
25{
26 switch (layout) {
27 case BVH_LAYOUT_NONE:
28 return "NONE";
29 case BVH_LAYOUT_BVH2:
30 return "BVH2";
32 return "EMBREE";
34 return "OPTIX";
36 return "METAL";
38 return "HIPRT";
40 return "EMBREEGPU";
49 return "MULTI";
50 case BVH_LAYOUT_ALL:
51 return "ALL";
52 }
53 LOG(DFATAL) << "Unsupported BVH layout was passed.";
54 return "";
55}
56
57BVHLayout BVHParams::best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
58{
59 const BVHLayoutMask requested_layout_mask = (BVHLayoutMask)requested_layout;
60 /* Check whether requested layout is supported, if so -- no need to do
61 * any extra computation.
62 */
63 if (supported_layouts & requested_layout_mask) {
64 return requested_layout;
65 }
66 /* Some bit magic to get widest supported BVH layout. */
67 /* This is a mask of supported BVH layouts which are narrower than the
68 * requested one.
69 */
70 BVHLayoutMask allowed_layouts_mask = (supported_layouts & (requested_layout_mask - 1));
71 /* If the requested layout is not supported, choose from the supported layouts instead. */
72 if (allowed_layouts_mask == 0) {
73 allowed_layouts_mask = supported_layouts;
74 }
75 /* We get widest from allowed ones and convert mask to actual layout. */
76 const BVHLayoutMask widest_allowed_layout_mask = __bsr((uint32_t)allowed_layouts_mask);
77 return (BVHLayout)(1 << widest_allowed_layout_mask);
78}
79
80/* BVH */
81
82BVH::BVH(const BVHParams &params_,
83 const vector<Geometry *> &geometry_,
84 const vector<Object *> &objects_)
85 : params(params_), geometry(geometry_), objects(objects_)
86{
87}
88
90 const vector<Geometry *> &geometry,
91 const vector<Object *> &objects,
92 Device *device)
93{
94 switch (params.bvh_layout) {
95 case BVH_LAYOUT_BVH2:
96 return new BVH2(params, geometry, objects);
99#ifdef WITH_EMBREE
100 return new BVHEmbree(params, geometry, objects);
101#else
102 break;
103#endif
104 case BVH_LAYOUT_OPTIX:
105#ifdef WITH_OPTIX
106 return new BVHOptiX(params, geometry, objects, device);
107#else
108 (void)device;
109 break;
110#endif
111 case BVH_LAYOUT_METAL:
112#ifdef WITH_METAL
113 return bvh_metal_create(params, geometry, objects, device);
114#else
115 (void)device;
116 break;
117#endif
118 case BVH_LAYOUT_HIPRT:
119#ifdef WITH_HIPRT
120 return new BVHHIPRT(params, geometry, objects, device);
121#else
122 (void)device;
123 break;
124#endif
133 return new BVHMulti(params, geometry, objects);
134 case BVH_LAYOUT_NONE:
135 case BVH_LAYOUT_ALL:
136 break;
137 }
138 LOG(DFATAL) << "Requested unsupported BVH layout.";
139 return NULL;
140}
141
CCL_NAMESPACE_BEGIN const char * bvh_layout_name(BVHLayout layout)
Definition bvh.cpp:24
Definition bvh2.h:36
static BVHLayout best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
Definition bvh.cpp:57
BVHLayout bvh_layout
Definition params.h:84
Definition bvh/bvh.h:66
static BVH * create(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects, Device *device)
Definition bvh.cpp:89
BVH(const BVHParams &params, const vector< Geometry * > &geometry, const vector< Object * > &objects)
Definition bvh.cpp:82
BVHParams params
Definition bvh/bvh.h:68
#define CCL_NAMESPACE_END
#define NULL
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
@ 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(severity)
Definition log.h:33
int BVHLayoutMask
Definition params.h:51
CCL_NAMESPACE_BEGIN typedef KernelBVHLayout BVHLayout
Definition params.h:23
__forceinline uint32_t __bsr(const uint32_t x)
Definition simd.h:406
unsigned int uint32_t
Definition stdint.h:80