MCPcopy Create free account
hub / github.com/RenderKit/embree / rtcBuildBVHSpatialSAH

Function rtcBuildBVHSpatialSAH

kernels/common/rtcore_builder.cpp:217–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

215 }
216
217 void* rtcBuildBVHSpatialSAH(const RTCBuildArguments* arguments)
218 {
219 BVH* bvh = (BVH*) arguments->bvh;
220 RTCBuildPrimitive* prims = arguments->primitives;
221 size_t primitiveCount = arguments->primitiveCount;
222 RTCCreateNodeFunction createNode = arguments->createNode;
223 RTCSetNodeChildrenFunction setNodeChildren = arguments->setNodeChildren;
224 RTCSetNodeBoundsFunction setNodeBounds = arguments->setNodeBounds;
225 RTCCreateLeafFunction createLeaf = arguments->createLeaf;
226 RTCSplitPrimitiveFunction splitPrimitive = arguments->splitPrimitive;
227 RTCProgressMonitorFunction buildProgress = arguments->buildProgress;
228 void* userPtr = arguments->userPtr;
229
230 std::atomic<size_t> progress(0);
231
232 /* calculate priminfo */
233
234 auto computeBounds = [&](const range<size_t>& r) -> std::pair<CentGeomBBox3fa,unsigned int>
235 {
236 CentGeomBBox3fa bounds(empty);
237 unsigned maxGeomID = 0;
238 for (size_t j=r.begin(); j<r.end(); j++)
239 {
240 bounds.extend((BBox3fa&)prims[j]);
241 maxGeomID = max(maxGeomID,prims[j].geomID);
242 }
243 return std::pair<CentGeomBBox3fa,unsigned int>(bounds,maxGeomID);
244 };
245
246
247 const std::pair<CentGeomBBox3fa,unsigned int> pair =
248 parallel_reduce(size_t(0),primitiveCount,size_t(1024),size_t(1024),std::pair<CentGeomBBox3fa,unsigned int>(CentGeomBBox3fa(empty),0), computeBounds, mergePair);
249
250 CentGeomBBox3fa bounds = pair.first;
251 const unsigned int maxGeomID = pair.second;
252
253 if (unlikely(maxGeomID >= ((unsigned int)1 << (32-RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS))))
254 {
255 /* fallback code for max geomID larger than threshold */
256 return rtcBuildBVHBinnedSAH(arguments);
257 }
258
259 const PrimInfo pinfo(0,primitiveCount,bounds);
260
261 /* function that splits a build primitive */
262 struct Splitter
263 {
264 Splitter (RTCSplitPrimitiveFunction splitPrimitive, unsigned geomID, unsigned primID, void* userPtr)
265 : splitPrimitive(splitPrimitive), geomID(geomID), primID(primID), userPtr(userPtr) {}
266
267 __forceinline void operator() (PrimRef& prim, const size_t dim, const float pos, PrimRef& left_o, PrimRef& right_o) const
268 {
269 prim.geomIDref() &= BVHBuilderBinnedFastSpatialSAH::GEOMID_MASK;
270 splitPrimitive((RTCBuildPrimitive*)&prim,(unsigned)dim,pos,(RTCBounds*)&left_o,(RTCBounds*)&right_o,userPtr);
271 left_o.geomIDref() = geomID; left_o.primIDref() = primID;
272 right_o.geomIDref() = geomID; right_o.primIDref() = primID;
273 }
274

Callers 1

rtcBuildBVHFunction · 0.85

Calls 13

parallel_reduceFunction · 0.85
rtcBuildBVHBinnedSAHFunction · 0.85
SplitterClass · 0.85
buildProgressFunction · 0.85
maxFunction · 0.50
minFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
extendMethod · 0.45
sizeMethod · 0.45
geomIDMethod · 0.45
primIDMethod · 0.45

Tested by

no test coverage detected