1 | // Copyright 2009-2021 Intel Corporation |
2 | // SPDX-License-Identifier: Apache-2.0 |
3 | |
4 | #pragma once |
5 | |
6 | #include "bvh.h" |
7 | #include "../geometry/triangle.h" |
8 | #include "../geometry/trianglev.h" |
9 | #include "../geometry/trianglei.h" |
10 | #include "../geometry/quadv.h" |
11 | #include "../geometry/quadi.h" |
12 | #include "../geometry/object.h" |
13 | #include "../geometry/instance.h" |
14 | |
15 | namespace embree |
16 | { |
17 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4MeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
18 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4MeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
19 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4MeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
20 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4vMeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
21 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4vMeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
22 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4vMeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
23 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4iMeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
24 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4iMeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
25 | DECLARE_ISA_FUNCTION(Builder*,BVH4Triangle4iMeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
26 | DECLARE_ISA_FUNCTION(Builder*,BVH4Quad4vMeshBuilderMortonGeneral,void* COMMA QuadMesh* COMMA unsigned int COMMA size_t); |
27 | DECLARE_ISA_FUNCTION(Builder*,BVH4Quad4vMeshBuilderSAH,void* COMMA QuadMesh* COMMA unsigned int COMMA size_t); |
28 | DECLARE_ISA_FUNCTION(Builder*,BVH4Quad4vMeshRefitSAH,void* COMMA QuadMesh* COMMA unsigned int COMMA size_t); |
29 | DECLARE_ISA_FUNCTION(Builder*,BVH4VirtualMeshBuilderMortonGeneral,void* COMMA UserGeometry* COMMA unsigned int COMMA size_t); |
30 | DECLARE_ISA_FUNCTION(Builder*,BVH4VirtualMeshBuilderSAH,void* COMMA UserGeometry* COMMA unsigned int COMMA size_t); |
31 | DECLARE_ISA_FUNCTION(Builder*,BVH4VirtualMeshRefitSAH,void* COMMA UserGeometry* COMMA unsigned int COMMA size_t); |
32 | DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshBuilderMortonGeneral,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); |
33 | DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshBuilderSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); |
34 | DECLARE_ISA_FUNCTION(Builder*,BVH4InstanceMeshRefitSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) |
35 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
36 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
37 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4MeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
38 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4vMeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
39 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4vMeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
40 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4vMeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
41 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4iMeshBuilderMortonGeneral,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
42 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4iMeshBuilderSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
43 | DECLARE_ISA_FUNCTION(Builder*,BVH8Triangle4iMeshRefitSAH,void* COMMA TriangleMesh* COMMA unsigned int COMMA size_t); |
44 | DECLARE_ISA_FUNCTION(Builder*,BVH8Quad4vMeshBuilderMortonGeneral,void* COMMA QuadMesh* COMMA unsigned int COMMA size_t); |
45 | DECLARE_ISA_FUNCTION(Builder*,BVH8Quad4vMeshBuilderSAH,void* COMMA QuadMesh* COMMA unsigned int COMMA size_t); |
46 | DECLARE_ISA_FUNCTION(Builder*,BVH8Quad4vMeshRefitSAH,void* COMMA QuadMesh* COMMA unsigned int COMMA size_t); |
47 | DECLARE_ISA_FUNCTION(Builder*,BVH8VirtualMeshBuilderMortonGeneral,void* COMMA UserGeometry* COMMA unsigned int COMMA size_t); |
48 | DECLARE_ISA_FUNCTION(Builder*,BVH8VirtualMeshBuilderSAH,void* COMMA UserGeometry* COMMA unsigned int COMMA size_t); |
49 | DECLARE_ISA_FUNCTION(Builder*,BVH8VirtualMeshRefitSAH,void* COMMA UserGeometry* COMMA unsigned int COMMA size_t); |
50 | DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshBuilderMortonGeneral,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); |
51 | DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshBuilderSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t); |
52 | DECLARE_ISA_FUNCTION(Builder*,BVH8InstanceMeshRefitSAH,void* COMMA Instance* COMMA Geometry::GTypeMask COMMA unsigned int COMMA size_t) |
53 | |
54 | namespace isa |
55 | { |
56 | |
57 | namespace __internal_two_level_builder__ { |
58 | |
59 | template<int N, typename Mesh, typename Primitive> |
60 | struct MortonBuilder {}; |
61 | template<> |
62 | struct MortonBuilder<4,TriangleMesh,Triangle4> { |
63 | MortonBuilder () {} |
64 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4MeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
65 | }; |
66 | template<> |
67 | struct MortonBuilder<4,TriangleMesh,Triangle4v> { |
68 | MortonBuilder () {} |
69 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4vMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
70 | }; |
71 | template<> |
72 | struct MortonBuilder<4,TriangleMesh,Triangle4i> { |
73 | MortonBuilder () {} |
74 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4iMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
75 | }; |
76 | template<> |
77 | struct MortonBuilder<4,QuadMesh,Quad4v> { |
78 | MortonBuilder () {} |
79 | Builder* operator () (void* bvh, QuadMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Quad4vMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
80 | }; |
81 | template<> |
82 | struct MortonBuilder<4,UserGeometry,Object> { |
83 | MortonBuilder () {} |
84 | Builder* operator () (void* bvh, UserGeometry* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4VirtualMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
85 | }; |
86 | template<> |
87 | struct MortonBuilder<4,Instance,InstancePrimitive> { |
88 | MortonBuilder () {} |
89 | Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} |
90 | }; |
91 | template<> |
92 | struct MortonBuilder<8,TriangleMesh,Triangle4> { |
93 | MortonBuilder () {} |
94 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
95 | }; |
96 | template<> |
97 | struct MortonBuilder<8,TriangleMesh,Triangle4v> { |
98 | MortonBuilder () {} |
99 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4vMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
100 | }; |
101 | template<> |
102 | struct MortonBuilder<8,TriangleMesh,Triangle4i> { |
103 | MortonBuilder () {} |
104 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4iMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
105 | }; |
106 | template<> |
107 | struct MortonBuilder<8,QuadMesh,Quad4v> { |
108 | MortonBuilder () {} |
109 | Builder* operator () (void* bvh, QuadMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Quad4vMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
110 | }; |
111 | template<> |
112 | struct MortonBuilder<8,UserGeometry,Object> { |
113 | MortonBuilder () {} |
114 | Builder* operator () (void* bvh, UserGeometry* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8VirtualMeshBuilderMortonGeneral(bvh,mesh,geomID,0);} |
115 | }; |
116 | template<> |
117 | struct MortonBuilder<8,Instance,InstancePrimitive> { |
118 | MortonBuilder () {} |
119 | Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshBuilderMortonGeneral(bvh,mesh,gtype,geomID,0);} |
120 | }; |
121 | |
122 | template<int N, typename Mesh, typename Primitive> |
123 | struct SAHBuilder {}; |
124 | template<> |
125 | struct SAHBuilder<4,TriangleMesh,Triangle4> { |
126 | SAHBuilder () {} |
127 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4MeshBuilderSAH(bvh,mesh,geomID,0);} |
128 | }; |
129 | template<> |
130 | struct SAHBuilder<4,TriangleMesh,Triangle4v> { |
131 | SAHBuilder () {} |
132 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4vMeshBuilderSAH(bvh,mesh,geomID,0);} |
133 | }; |
134 | template<> |
135 | struct SAHBuilder<4,TriangleMesh,Triangle4i> { |
136 | SAHBuilder () {} |
137 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4iMeshBuilderSAH(bvh,mesh,geomID,0);} |
138 | }; |
139 | template<> |
140 | struct SAHBuilder<4,QuadMesh,Quad4v> { |
141 | SAHBuilder () {} |
142 | Builder* operator () (void* bvh, QuadMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Quad4vMeshBuilderSAH(bvh,mesh,geomID,0);} |
143 | }; |
144 | template<> |
145 | struct SAHBuilder<4,UserGeometry,Object> { |
146 | SAHBuilder () {} |
147 | Builder* operator () (void* bvh, UserGeometry* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4VirtualMeshBuilderSAH(bvh,mesh,geomID,0);} |
148 | }; |
149 | template<> |
150 | struct SAHBuilder<4,Instance,InstancePrimitive> { |
151 | SAHBuilder () {} |
152 | Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} |
153 | }; |
154 | template<> |
155 | struct SAHBuilder<8,TriangleMesh,Triangle4> { |
156 | SAHBuilder () {} |
157 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshBuilderSAH(bvh,mesh,geomID,0);} |
158 | }; |
159 | template<> |
160 | struct SAHBuilder<8,TriangleMesh,Triangle4v> { |
161 | SAHBuilder () {} |
162 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4vMeshBuilderSAH(bvh,mesh,geomID,0);} |
163 | }; |
164 | template<> |
165 | struct SAHBuilder<8,TriangleMesh,Triangle4i> { |
166 | SAHBuilder () {} |
167 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4iMeshBuilderSAH(bvh,mesh,geomID,0);} |
168 | }; |
169 | template<> |
170 | struct SAHBuilder<8,QuadMesh,Quad4v> { |
171 | SAHBuilder () {} |
172 | Builder* operator () (void* bvh, QuadMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Quad4vMeshBuilderSAH(bvh,mesh,geomID,0);} |
173 | }; |
174 | template<> |
175 | struct SAHBuilder<8,UserGeometry,Object> { |
176 | SAHBuilder () {} |
177 | Builder* operator () (void* bvh, UserGeometry* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8VirtualMeshBuilderSAH(bvh,mesh,geomID,0);} |
178 | }; |
179 | template<> |
180 | struct SAHBuilder<8,Instance,InstancePrimitive> { |
181 | SAHBuilder () {} |
182 | Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshBuilderSAH(bvh,mesh,gtype,geomID,0);} |
183 | }; |
184 | |
185 | template<int N, typename Mesh, typename Primitive> |
186 | struct RefitBuilder {}; |
187 | template<> |
188 | struct RefitBuilder<4,TriangleMesh,Triangle4> { |
189 | RefitBuilder () {} |
190 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4MeshRefitSAH(bvh,mesh,geomID,0);} |
191 | }; |
192 | template<> |
193 | struct RefitBuilder<4,TriangleMesh,Triangle4v> { |
194 | RefitBuilder () {} |
195 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4vMeshRefitSAH(bvh,mesh,geomID,0);} |
196 | }; |
197 | template<> |
198 | struct RefitBuilder<4,TriangleMesh,Triangle4i> { |
199 | RefitBuilder () {} |
200 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Triangle4iMeshRefitSAH(bvh,mesh,geomID,0);} |
201 | }; |
202 | template<> |
203 | struct RefitBuilder<4,QuadMesh,Quad4v> { |
204 | RefitBuilder () {} |
205 | Builder* operator () (void* bvh, QuadMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4Quad4vMeshRefitSAH(bvh,mesh,geomID,0);} |
206 | }; |
207 | template<> |
208 | struct RefitBuilder<4,UserGeometry,Object> { |
209 | RefitBuilder () {} |
210 | Builder* operator () (void* bvh, UserGeometry* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH4VirtualMeshRefitSAH(bvh,mesh,geomID,0);} |
211 | }; |
212 | template<> |
213 | struct RefitBuilder<4,Instance,InstancePrimitive> { |
214 | RefitBuilder () {} |
215 | Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH4InstanceMeshRefitSAH(bvh,mesh,gtype,geomID,0);} |
216 | }; |
217 | template<> |
218 | struct RefitBuilder<8,TriangleMesh,Triangle4> { |
219 | RefitBuilder () {} |
220 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4MeshRefitSAH(bvh,mesh,geomID,0);} |
221 | }; |
222 | template<> |
223 | struct RefitBuilder<8,TriangleMesh,Triangle4v> { |
224 | RefitBuilder () {} |
225 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4vMeshRefitSAH(bvh,mesh,geomID,0);} |
226 | }; |
227 | template<> |
228 | struct RefitBuilder<8,TriangleMesh,Triangle4i> { |
229 | RefitBuilder () {} |
230 | Builder* operator () (void* bvh, TriangleMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Triangle4iMeshRefitSAH(bvh,mesh,geomID,0);} |
231 | }; |
232 | template<> |
233 | struct RefitBuilder<8,QuadMesh,Quad4v> { |
234 | RefitBuilder () {} |
235 | Builder* operator () (void* bvh, QuadMesh* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8Quad4vMeshRefitSAH(bvh,mesh,geomID,0);} |
236 | }; |
237 | template<> |
238 | struct RefitBuilder<8,UserGeometry,Object> { |
239 | RefitBuilder () {} |
240 | Builder* operator () (void* bvh, UserGeometry* mesh, size_t geomID, Geometry::GTypeMask /*gtype*/) { return BVH8VirtualMeshRefitSAH(bvh,mesh,geomID,0);} |
241 | }; |
242 | template<> |
243 | struct RefitBuilder<8,Instance,InstancePrimitive> { |
244 | RefitBuilder () {} |
245 | Builder* operator () (void* bvh, Instance* mesh, size_t geomID, Geometry::GTypeMask gtype) { return BVH8InstanceMeshRefitSAH(bvh,mesh,gtype,geomID,0);} |
246 | }; |
247 | |
248 | template<int N, typename Mesh, typename Primitive> |
249 | struct MeshBuilder { |
250 | MeshBuilder () {} |
251 | void operator () (void* bvh, Mesh* mesh, size_t geomID, Geometry::GTypeMask gtype, bool useMortonBuilder, Builder*& builder) { |
252 | if(useMortonBuilder) { |
253 | builder = MortonBuilder<N,Mesh,Primitive>()(bvh,mesh,geomID,gtype); |
254 | return; |
255 | } |
256 | switch (mesh->quality) { |
257 | case RTC_BUILD_QUALITY_LOW: builder = MortonBuilder<N,Mesh,Primitive>()(bvh,mesh,geomID,gtype); break; |
258 | case RTC_BUILD_QUALITY_MEDIUM: |
259 | case RTC_BUILD_QUALITY_HIGH: builder = SAHBuilder<N,Mesh,Primitive>()(bvh,mesh,geomID,gtype); break; |
260 | case RTC_BUILD_QUALITY_REFIT: builder = RefitBuilder<N,Mesh,Primitive>()(bvh,mesh,geomID,gtype); break; |
261 | default: throw_RTCError(RTC_ERROR_UNKNOWN,"invalid build quality" ); |
262 | } |
263 | } |
264 | }; |
265 | } |
266 | } |
267 | } |