123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
- // Copyright 2009-2021 Intel Corporation
- // SPDX-License-Identifier: Apache-2.0
- #pragma once
- #include "heuristic_binning_array_aligned.h"
- #include "heuristic_spatial_array.h"
- #include "heuristic_openmerge_array.h"
- #if defined(__AVX512F__) && !defined(__AVX512VL__) // KNL
- # define NUM_OBJECT_BINS 16
- # define NUM_SPATIAL_BINS 16
- #else
- # define NUM_OBJECT_BINS 32
- # define NUM_SPATIAL_BINS 16
- #endif
- namespace embree
- {
- namespace isa
- {
- MAYBE_UNUSED static const float travCost = 1.0f;
- MAYBE_UNUSED static const size_t DEFAULT_SINGLE_THREAD_THRESHOLD = 1024;
- struct GeneralBVHBuilder
- {
- static const size_t MAX_BRANCHING_FACTOR = 16; //!< maximum supported BVH branching factor
- static const size_t MIN_LARGE_LEAF_LEVELS = 8; //!< create balanced tree of we are that many levels before the maximum tree depth
-
- /*! settings for SAH builder */
- struct Settings
- {
- /*! default settings */
- Settings ()
- : branchingFactor(2), maxDepth(32), logBlockSize(0), minLeafSize(1), maxLeafSize(7),
- travCost(1.0f), intCost(1.0f), singleThreadThreshold(1024), primrefarrayalloc(inf) {}
- /*! initialize settings from API settings */
- Settings (const RTCBuildArguments& settings)
- : branchingFactor(2), maxDepth(32), logBlockSize(0), minLeafSize(1), maxLeafSize(7),
- travCost(1.0f), intCost(1.0f), singleThreadThreshold(1024), primrefarrayalloc(inf)
- {
- if (RTC_BUILD_ARGUMENTS_HAS(settings,maxBranchingFactor)) branchingFactor = settings.maxBranchingFactor;
- if (RTC_BUILD_ARGUMENTS_HAS(settings,maxDepth )) maxDepth = settings.maxDepth;
- if (RTC_BUILD_ARGUMENTS_HAS(settings,sahBlockSize )) logBlockSize = bsr(settings.sahBlockSize);
- if (RTC_BUILD_ARGUMENTS_HAS(settings,minLeafSize )) minLeafSize = settings.minLeafSize;
- if (RTC_BUILD_ARGUMENTS_HAS(settings,maxLeafSize )) maxLeafSize = settings.maxLeafSize;
- if (RTC_BUILD_ARGUMENTS_HAS(settings,traversalCost )) travCost = settings.traversalCost;
- if (RTC_BUILD_ARGUMENTS_HAS(settings,intersectionCost )) intCost = settings.intersectionCost;
- minLeafSize = min(minLeafSize,maxLeafSize);
- }
- Settings (size_t sahBlockSize, size_t minLeafSize, size_t maxLeafSize, float travCost, float intCost, size_t singleThreadThreshold, size_t primrefarrayalloc = inf)
- : branchingFactor(2), maxDepth(32), logBlockSize(bsr(sahBlockSize)), minLeafSize(minLeafSize), maxLeafSize(maxLeafSize),
- travCost(travCost), intCost(intCost), singleThreadThreshold(singleThreadThreshold), primrefarrayalloc(primrefarrayalloc)
- {
- minLeafSize = min(minLeafSize,maxLeafSize);
- }
- public:
- size_t branchingFactor; //!< branching factor of BVH to build
- size_t maxDepth; //!< maximum depth of BVH to build
- size_t logBlockSize; //!< log2 of blocksize for SAH heuristic
- size_t minLeafSize; //!< minimum size of a leaf
- size_t maxLeafSize; //!< maximum size of a leaf
- float travCost; //!< estimated cost of one traversal step
- float intCost; //!< estimated cost of one primitive intersection
- size_t singleThreadThreshold; //!< threshold when we switch to single threaded build
- size_t primrefarrayalloc; //!< builder uses prim ref array to allocate nodes and leaves when a subtree of that size is finished
- };
- /*! recursive state of builder */
- template<typename Set, typename Split>
- struct BuildRecordT
- {
- public:
- __forceinline BuildRecordT () {}
- __forceinline BuildRecordT (size_t depth)
- : depth(depth), alloc_barrier(false), prims(empty) {}
- __forceinline BuildRecordT (size_t depth, const Set& prims)
- : depth(depth), alloc_barrier(false), prims(prims) {}
- __forceinline BBox3fa bounds() const { return prims.geomBounds; }
- __forceinline friend bool operator< (const BuildRecordT& a, const BuildRecordT& b) { return a.prims.size() < b.prims.size(); }
- __forceinline friend bool operator> (const BuildRecordT& a, const BuildRecordT& b) { return a.prims.size() > b.prims.size(); }
- __forceinline size_t size() const { return prims.size(); }
- public:
- size_t depth; //!< Depth of the root of this subtree.
- bool alloc_barrier; //!< barrier used to reuse primref-array blocks to allocate nodes
- Set prims; //!< The list of primitives.
- };
- template<typename PrimRef, typename Set>
- struct DefaultCanCreateLeafFunc
- {
- __forceinline bool operator()(const PrimRef*, const Set&) const { return true; }
- };
- template<typename PrimRef, typename Set>
- struct DefaultCanCreateLeafSplitFunc
- {
- __forceinline void operator()(PrimRef*, const Set&, Set&, Set&) const { }
- };
- template<typename BuildRecord,
- typename Heuristic,
- typename Set,
- typename PrimRef,
- typename ReductionTy,
- typename Allocator,
- typename CreateAllocFunc,
- typename CreateNodeFunc,
- typename UpdateNodeFunc,
- typename CreateLeafFunc,
- typename CanCreateLeafFunc,
- typename CanCreateLeafSplitFunc,
- typename ProgressMonitor>
- class BuilderT
- {
- friend struct GeneralBVHBuilder;
- BuilderT (PrimRef* prims,
- Heuristic& heuristic,
- const CreateAllocFunc& createAlloc,
- const CreateNodeFunc& createNode,
- const UpdateNodeFunc& updateNode,
- const CreateLeafFunc& createLeaf,
- const CanCreateLeafFunc& canCreateLeaf,
- const CanCreateLeafSplitFunc& canCreateLeafSplit,
- const ProgressMonitor& progressMonitor,
- const Settings& settings) :
- cfg(settings),
- prims(prims),
- heuristic(heuristic),
- createAlloc(createAlloc),
- createNode(createNode),
- updateNode(updateNode),
- createLeaf(createLeaf),
- canCreateLeaf(canCreateLeaf),
- canCreateLeafSplit(canCreateLeafSplit),
- progressMonitor(progressMonitor)
- {
- if (cfg.branchingFactor > MAX_BRANCHING_FACTOR)
- throw_RTCError(RTC_ERROR_UNKNOWN,"bvh_builder: branching factor too large");
- }
- const ReductionTy createLargeLeaf(const BuildRecord& current, Allocator alloc)
- {
- /* this should never occur but is a fatal error */
- if (current.depth > cfg.maxDepth)
- throw_RTCError(RTC_ERROR_UNKNOWN,"depth limit reached");
- /* create leaf for few primitives */
- if (current.prims.size() <= cfg.maxLeafSize && canCreateLeaf(prims,current.prims))
- return createLeaf(prims,current.prims,alloc);
- /* fill all children by always splitting the largest one */
- ReductionTy values[MAX_BRANCHING_FACTOR];
- BuildRecord children[MAX_BRANCHING_FACTOR];
- size_t numChildren = 1;
- children[0] = current;
- do {
- /* find best child with largest bounding box area */
- size_t bestChild = -1;
- size_t bestSize = 0;
- for (size_t i=0; i<numChildren; i++)
- {
- /* ignore leaves as they cannot get split */
- if (children[i].prims.size() <= cfg.maxLeafSize && canCreateLeaf(prims,children[i].prims))
- continue;
- /* remember child with largest size */
- if (children[i].prims.size() > bestSize) {
- bestSize = children[i].prims.size();
- bestChild = i;
- }
- }
- if (bestChild == (size_t)-1) break;
- /*! split best child into left and right child */
- BuildRecord left(current.depth+1);
- BuildRecord right(current.depth+1);
- if (!canCreateLeaf(prims,children[bestChild].prims)) {
- canCreateLeafSplit(prims,children[bestChild].prims,left.prims,right.prims);
- } else {
- heuristic.splitFallback(children[bestChild].prims,left.prims,right.prims);
- }
- /* add new children left and right */
- children[bestChild] = children[numChildren-1];
- children[numChildren-1] = left;
- children[numChildren+0] = right;
- numChildren++;
- } while (numChildren < cfg.branchingFactor);
- /* set barrier for primrefarrayalloc */
- if (unlikely(current.size() > cfg.primrefarrayalloc))
- for (size_t i=0; i<numChildren; i++)
- children[i].alloc_barrier = children[i].size() <= cfg.primrefarrayalloc;
- /* create node */
- auto node = createNode(children,numChildren,alloc);
- /* recurse into each child and perform reduction */
- for (size_t i=0; i<numChildren; i++)
- values[i] = createLargeLeaf(children[i],alloc);
- /* perform reduction */
- return updateNode(current,children,node,values,numChildren);
- }
- const ReductionTy recurse(BuildRecord& current, Allocator alloc, bool toplevel)
- {
- /* get thread local allocator */
- if (!alloc)
- alloc = createAlloc();
- /* call memory monitor function to signal progress */
- if (toplevel && current.size() <= cfg.singleThreadThreshold)
- progressMonitor(current.size());
- /*! find best split */
- auto split = heuristic.find(current.prims,cfg.logBlockSize);
- /*! compute leaf and split cost */
- const float leafSAH = cfg.intCost*current.prims.leafSAH(cfg.logBlockSize);
- const float splitSAH = cfg.travCost*halfArea(current.prims.geomBounds)+cfg.intCost*split.splitSAH();
- assert((current.prims.size() == 0) || ((leafSAH >= 0) && (splitSAH >= 0)));
- /*! create a leaf node when threshold reached or SAH tells us to stop */
- if (current.prims.size() <= cfg.minLeafSize || current.depth+MIN_LARGE_LEAF_LEVELS >= cfg.maxDepth || (current.prims.size() <= cfg.maxLeafSize && leafSAH <= splitSAH)) {
- heuristic.deterministic_order(current.prims);
- return createLargeLeaf(current,alloc);
- }
- /*! perform initial split */
- Set lprims,rprims;
- heuristic.split(split,current.prims,lprims,rprims);
-
- /*! initialize child list with initial split */
- ReductionTy values[MAX_BRANCHING_FACTOR];
- BuildRecord children[MAX_BRANCHING_FACTOR];
- children[0] = BuildRecord(current.depth+1,lprims);
- children[1] = BuildRecord(current.depth+1,rprims);
- size_t numChildren = 2;
- /*! split until node is full or SAH tells us to stop */
- while (numChildren < cfg.branchingFactor)
- {
- /*! find best child to split */
- float bestArea = neg_inf;
- ssize_t bestChild = -1;
- for (size_t i=0; i<numChildren; i++)
- {
- /* ignore leaves as they cannot get split */
- if (children[i].prims.size() <= cfg.minLeafSize) continue;
- /* find child with largest surface area */
- if (halfArea(children[i].prims.geomBounds) > bestArea) {
- bestChild = i;
- bestArea = halfArea(children[i].prims.geomBounds);
- }
- }
- if (bestChild == -1) break;
- /* perform best found split */
- BuildRecord& brecord = children[bestChild];
- BuildRecord lrecord(current.depth+1);
- BuildRecord rrecord(current.depth+1);
- auto split = heuristic.find(brecord.prims,cfg.logBlockSize);
- heuristic.split(split,brecord.prims,lrecord.prims,rrecord.prims);
- children[bestChild ] = lrecord;
- children[numChildren] = rrecord;
- numChildren++;
- }
- /* set barrier for primrefarrayalloc */
- if (unlikely(current.size() > cfg.primrefarrayalloc))
- for (size_t i=0; i<numChildren; i++)
- children[i].alloc_barrier = children[i].size() <= cfg.primrefarrayalloc;
- /* sort buildrecords for faster shadow ray traversal */
- std::sort(&children[0],&children[numChildren],std::greater<BuildRecord>());
- /*! create an inner node */
- auto node = createNode(children,numChildren,alloc);
- /* spawn tasks */
- if (current.size() > cfg.singleThreadThreshold)
- {
- /*! parallel_for is faster than spawning sub-tasks */
- parallel_for(size_t(0), numChildren, [&] (const range<size_t>& r) { // FIXME: no range here
- for (size_t i=r.begin(); i<r.end(); i++) {
- values[i] = recurse(children[i],nullptr,true);
- _mm_mfence(); // to allow non-temporal stores during build
- }
- });
- return updateNode(current,children,node,values,numChildren);
- }
- /* recurse into each child */
- else
- {
- for (size_t i=0; i<numChildren; i++)
- values[i] = recurse(children[i],alloc,false);
- return updateNode(current,children,node,values,numChildren);
- }
- }
- private:
- Settings cfg;
- PrimRef* prims;
- Heuristic& heuristic;
- const CreateAllocFunc& createAlloc;
- const CreateNodeFunc& createNode;
- const UpdateNodeFunc& updateNode;
- const CreateLeafFunc& createLeaf;
- const CanCreateLeafFunc& canCreateLeaf;
- const CanCreateLeafSplitFunc& canCreateLeafSplit;
- const ProgressMonitor& progressMonitor;
- };
- template<
- typename ReductionTy,
- typename Heuristic,
- typename Set,
- typename PrimRef,
- typename CreateAllocFunc,
- typename CreateNodeFunc,
- typename UpdateNodeFunc,
- typename CreateLeafFunc,
- typename ProgressMonitor>
- __noinline static ReductionTy build(Heuristic& heuristic,
- PrimRef* prims,
- const Set& set,
- CreateAllocFunc createAlloc,
- CreateNodeFunc createNode, UpdateNodeFunc updateNode,
- const CreateLeafFunc& createLeaf,
- const ProgressMonitor& progressMonitor,
- const Settings& settings)
- {
- typedef BuildRecordT<Set,typename Heuristic::Split> BuildRecord;
- typedef BuilderT<
- BuildRecord,
- Heuristic,
- Set,
- PrimRef,
- ReductionTy,
- decltype(createAlloc()),
- CreateAllocFunc,
- CreateNodeFunc,
- UpdateNodeFunc,
- CreateLeafFunc,
- DefaultCanCreateLeafFunc<PrimRef, Set>,
- DefaultCanCreateLeafSplitFunc<PrimRef, Set>,
- ProgressMonitor> Builder;
- /* instantiate builder */
- Builder builder(prims,
- heuristic,
- createAlloc,
- createNode,
- updateNode,
- createLeaf,
- DefaultCanCreateLeafFunc<PrimRef, Set>(),
- DefaultCanCreateLeafSplitFunc<PrimRef, Set>(),
- progressMonitor,
- settings);
- /* build hierarchy */
- BuildRecord record(1,set);
- const ReductionTy root = builder.recurse(record,nullptr,true);
- _mm_mfence(); // to allow non-temporal stores during build
- return root;
- }
- template<
- typename ReductionTy,
- typename Heuristic,
- typename Set,
- typename PrimRef,
- typename CreateAllocFunc,
- typename CreateNodeFunc,
- typename UpdateNodeFunc,
- typename CreateLeafFunc,
- typename CanCreateLeafFunc,
- typename CanCreateLeafSplitFunc,
- typename ProgressMonitor>
- __noinline static ReductionTy build(Heuristic& heuristic,
- PrimRef* prims,
- const Set& set,
- CreateAllocFunc createAlloc,
- CreateNodeFunc createNode, UpdateNodeFunc updateNode,
- const CreateLeafFunc& createLeaf,
- const CanCreateLeafFunc& canCreateLeaf,
- const CanCreateLeafSplitFunc& canCreateLeafSplit,
- const ProgressMonitor& progressMonitor,
- const Settings& settings)
- {
- typedef BuildRecordT<Set,typename Heuristic::Split> BuildRecord;
- typedef BuilderT<
- BuildRecord,
- Heuristic,
- Set,
- PrimRef,
- ReductionTy,
- decltype(createAlloc()),
- CreateAllocFunc,
- CreateNodeFunc,
- UpdateNodeFunc,
- CreateLeafFunc,
- CanCreateLeafFunc,
- CanCreateLeafSplitFunc,
- ProgressMonitor> Builder;
- /* instantiate builder */
- Builder builder(prims,
- heuristic,
- createAlloc,
- createNode,
- updateNode,
- createLeaf,
- canCreateLeaf,
- canCreateLeafSplit,
- progressMonitor,
- settings);
- /* build hierarchy */
- BuildRecord record(1,set);
- const ReductionTy root = builder.recurse(record,nullptr,true);
- _mm_mfence(); // to allow non-temporal stores during build
- return root;
- }
- };
- /* SAH builder that operates on an array of BuildRecords */
- struct BVHBuilderBinnedSAH
- {
- typedef PrimInfoRange Set;
- typedef HeuristicArrayBinningSAH<PrimRef,NUM_OBJECT_BINS> Heuristic;
- typedef GeneralBVHBuilder::BuildRecordT<Set,typename Heuristic::Split> BuildRecord;
- typedef GeneralBVHBuilder::Settings Settings;
- /*! special builder that propagates reduction over the tree */
- template<
- typename ReductionTy,
- typename CreateAllocFunc,
- typename CreateNodeFunc,
- typename UpdateNodeFunc,
- typename CreateLeafFunc,
- typename ProgressMonitor>
- static ReductionTy build(CreateAllocFunc createAlloc,
- CreateNodeFunc createNode, UpdateNodeFunc updateNode,
- const CreateLeafFunc& createLeaf,
- const ProgressMonitor& progressMonitor,
- PrimRef* prims, const PrimInfo& pinfo,
- const Settings& settings)
- {
- Heuristic heuristic(prims);
- return GeneralBVHBuilder::build<ReductionTy,Heuristic,Set,PrimRef>(
- heuristic,
- prims,
- PrimInfoRange(0,pinfo.size(),pinfo),
- createAlloc,
- createNode,
- updateNode,
- createLeaf,
- progressMonitor,
- settings);
- }
- /*! special builder that propagates reduction over the tree */
- template<
- typename ReductionTy,
- typename CreateAllocFunc,
- typename CreateNodeFunc,
- typename UpdateNodeFunc,
- typename CreateLeafFunc,
- typename CanCreateLeafFunc,
- typename CanCreateLeafSplitFunc,
- typename ProgressMonitor>
- static ReductionTy build(CreateAllocFunc createAlloc,
- CreateNodeFunc createNode, UpdateNodeFunc updateNode,
- const CreateLeafFunc& createLeaf,
- const CanCreateLeafFunc& canCreateLeaf,
- const CanCreateLeafSplitFunc& canCreateLeafSplit,
- const ProgressMonitor& progressMonitor,
- PrimRef* prims, const PrimInfo& pinfo,
- const Settings& settings)
- {
- Heuristic heuristic(prims);
- return GeneralBVHBuilder::build<ReductionTy,Heuristic,Set,PrimRef>(
- heuristic,
- prims,
- PrimInfoRange(0,pinfo.size(),pinfo),
- createAlloc,
- createNode,
- updateNode,
- createLeaf,
- canCreateLeaf,
- canCreateLeafSplit,
- progressMonitor,
- settings);
- }
- };
- /* Spatial SAH builder that operates on an double-buffered array of BuildRecords */
- struct BVHBuilderBinnedFastSpatialSAH
- {
- typedef PrimInfoExtRange Set;
- typedef Split2<BinSplit<NUM_OBJECT_BINS>,SpatialBinSplit<NUM_SPATIAL_BINS> > Split;
- typedef GeneralBVHBuilder::BuildRecordT<Set,Split> BuildRecord;
- typedef GeneralBVHBuilder::Settings Settings;
- static const unsigned int GEOMID_MASK = 0xFFFFFFFF >> RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS;
- static const unsigned int SPLITS_MASK = 0xFFFFFFFF << (32-RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS);
- template<typename ReductionTy, typename UserCreateLeaf>
- struct CreateLeafExt
- {
- __forceinline CreateLeafExt (const UserCreateLeaf userCreateLeaf)
- : userCreateLeaf(userCreateLeaf) {}
- // __noinline is workaround for ICC2016 compiler bug
- template<typename Allocator>
- __noinline ReductionTy operator() (PrimRef* prims, const range<size_t>& range, Allocator alloc) const
- {
- for (size_t i=range.begin(); i<range.end(); i++)
- prims[i].lower.u &= GEOMID_MASK;
- return userCreateLeaf(prims,range,alloc);
- }
- const UserCreateLeaf userCreateLeaf;
- };
- /*! special builder that propagates reduction over the tree */
- template<
- typename ReductionTy,
- typename CreateAllocFunc,
- typename CreateNodeFunc,
- typename UpdateNodeFunc,
- typename CreateLeafFunc,
- typename SplitPrimitiveFunc,
- typename ProgressMonitor>
- static ReductionTy build(CreateAllocFunc createAlloc,
- CreateNodeFunc createNode,
- UpdateNodeFunc updateNode,
- const CreateLeafFunc& createLeaf,
- SplitPrimitiveFunc splitPrimitive,
- ProgressMonitor progressMonitor,
- PrimRef* prims,
- const size_t extSize,
- const PrimInfo& pinfo,
- const Settings& settings)
- {
- typedef HeuristicArraySpatialSAH<SplitPrimitiveFunc,PrimRef,NUM_OBJECT_BINS,NUM_SPATIAL_BINS> Heuristic;
- Heuristic heuristic(splitPrimitive,prims,pinfo);
- /* calculate total surface area */ // FIXME: this sum is not deterministic
- const float A = (float) parallel_reduce(size_t(0),pinfo.size(),0.0, [&] (const range<size_t>& r) -> double {
- double A = 0.0f;
- for (size_t i=r.begin(); i<r.end(); i++)
- {
- PrimRef& prim = prims[i];
- A += area(prim.bounds());
- }
- return A;
- },std::plus<double>());
- /* calculate maximum number of spatial splits per primitive */
- const unsigned int maxSplits = ((size_t)1 << RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS)-1;
- const float f = 10.0f;
- const float invA = 1.0f / A;
- parallel_for( size_t(0), pinfo.size(), [&](const range<size_t>& r) {
- for (size_t i=r.begin(); i<r.end(); i++)
- {
- PrimRef& prim = prims[i];
- assert((prim.geomID() & SPLITS_MASK) == 0);
- // FIXME: is there a better general heuristic ?
- const float nf = ceilf(f*pinfo.size()*area(prim.bounds()) * invA);
- unsigned int n = 4+min((int)maxSplits-4, max(1, (int)(nf)));
- prim.lower.u |= n << (32-RESERVED_NUM_SPATIAL_SPLITS_GEOMID_BITS);
- }
- });
- return GeneralBVHBuilder::build<ReductionTy,Heuristic,Set,PrimRef>(
- heuristic,
- prims,
- PrimInfoExtRange(0,pinfo.size(),extSize,pinfo),
- createAlloc,
- createNode,
- updateNode,
- CreateLeafExt<ReductionTy,CreateLeafFunc>(createLeaf),
- progressMonitor,
- settings);
- }
- };
- /* Open/Merge SAH builder that operates on an array of BuildRecords */
- struct BVHBuilderBinnedOpenMergeSAH
- {
- static const size_t NUM_OBJECT_BINS_HQ = 32;
- typedef PrimInfoExtRange Set;
- typedef BinSplit<NUM_OBJECT_BINS_HQ> Split;
- typedef GeneralBVHBuilder::BuildRecordT<Set,Split> BuildRecord;
- typedef GeneralBVHBuilder::Settings Settings;
-
- /*! special builder that propagates reduction over the tree */
- template<
- typename ReductionTy,
- typename BuildRef,
- typename CreateAllocFunc,
- typename CreateNodeFunc,
- typename UpdateNodeFunc,
- typename CreateLeafFunc,
- typename NodeOpenerFunc,
- typename ProgressMonitor>
-
- static ReductionTy build(CreateAllocFunc createAlloc,
- CreateNodeFunc createNode,
- UpdateNodeFunc updateNode,
- const CreateLeafFunc& createLeaf,
- NodeOpenerFunc nodeOpenerFunc,
- ProgressMonitor progressMonitor,
- BuildRef* prims,
- const size_t extSize,
- const PrimInfo& pinfo,
- const Settings& settings)
- {
- typedef HeuristicArrayOpenMergeSAH<NodeOpenerFunc,BuildRef,NUM_OBJECT_BINS_HQ> Heuristic;
- Heuristic heuristic(nodeOpenerFunc,prims,settings.branchingFactor);
- return GeneralBVHBuilder::build<ReductionTy,Heuristic,Set,BuildRef>(
- heuristic,
- prims,
- PrimInfoExtRange(0,pinfo.size(),extSize,pinfo),
- createAlloc,
- createNode,
- updateNode,
- createLeaf,
- progressMonitor,
- settings);
- }
- };
- }
- }
|