1// Copyright 2009-2021 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#include "bvh.h"
5#include "../builders/bvh_builder_sah.h"
6#include "../builders/bvh_builder_msmblur.h"
7
8namespace embree
9{
10 namespace isa
11 {
12 /************************************************************************************/
13 /************************************************************************************/
14 /************************************************************************************/
15 /************************************************************************************/
16
17 template<int N>
18 struct BVHNBuilderVirtual
19 {
20 typedef BVHN<N> BVH;
21 typedef typename BVH::NodeRef NodeRef;
22 typedef FastAllocator::CachedAllocator Allocator;
23
24 struct BVHNBuilderV {
25 NodeRef build(FastAllocator* allocator, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings);
26 virtual NodeRef createLeaf (const PrimRef* prims, const range<size_t>& set, const Allocator& alloc) = 0;
27 };
28
29 template<typename CreateLeafFunc>
30 struct BVHNBuilderT : public BVHNBuilderV
31 {
32 BVHNBuilderT (CreateLeafFunc createLeafFunc)
33 : createLeafFunc(createLeafFunc) {}
34
35 NodeRef createLeaf (const PrimRef* prims, const range<size_t>& set, const Allocator& alloc) {
36 return createLeafFunc(prims,set,alloc);
37 }
38
39 private:
40 CreateLeafFunc createLeafFunc;
41 };
42
43 template<typename CreateLeafFunc>
44 static NodeRef build(FastAllocator* allocator, CreateLeafFunc createLeaf, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings) {
45 return BVHNBuilderT<CreateLeafFunc>(createLeaf).build(allocator,progress,prims,pinfo,settings);
46 }
47 };
48
49 template<int N>
50 struct BVHNBuilderQuantizedVirtual
51 {
52 typedef BVHN<N> BVH;
53 typedef typename BVH::NodeRef NodeRef;
54 typedef FastAllocator::CachedAllocator Allocator;
55
56 struct BVHNBuilderV {
57 NodeRef build(FastAllocator* allocator, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings);
58 virtual NodeRef createLeaf (const PrimRef* prims, const range<size_t>& set, const Allocator& alloc) = 0;
59 };
60
61 template<typename CreateLeafFunc>
62 struct BVHNBuilderT : public BVHNBuilderV
63 {
64 BVHNBuilderT (CreateLeafFunc createLeafFunc)
65 : createLeafFunc(createLeafFunc) {}
66
67 NodeRef createLeaf (const PrimRef* prims, const range<size_t>& set, const Allocator& alloc) {
68 return createLeafFunc(prims,set,alloc);
69 }
70
71 private:
72 CreateLeafFunc createLeafFunc;
73 };
74
75 template<typename CreateLeafFunc>
76 static NodeRef build(FastAllocator* allocator, CreateLeafFunc createLeaf, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings) {
77 return BVHNBuilderT<CreateLeafFunc>(createLeaf).build(allocator,progress,prims,pinfo,settings);
78 }
79 };
80
81 template<int N>
82 struct BVHNBuilderMblurVirtual
83 {
84 typedef BVHN<N> BVH;
85 typedef typename BVH::AABBNodeMB AABBNodeMB;
86 typedef typename BVH::NodeRef NodeRef;
87 typedef typename BVH::NodeRecordMB NodeRecordMB;
88 typedef FastAllocator::CachedAllocator Allocator;
89
90 struct BVHNBuilderV {
91 NodeRecordMB build(FastAllocator* allocator, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings, const BBox1f& timeRange);
92 virtual NodeRecordMB createLeaf (const PrimRef* prims, const range<size_t>& set, const Allocator& alloc) = 0;
93 };
94
95 template<typename CreateLeafFunc>
96 struct BVHNBuilderT : public BVHNBuilderV
97 {
98 BVHNBuilderT (CreateLeafFunc createLeafFunc)
99 : createLeafFunc(createLeafFunc) {}
100
101 NodeRecordMB createLeaf (const PrimRef* prims, const range<size_t>& set, const Allocator& alloc) {
102 return createLeafFunc(prims,set,alloc);
103 }
104
105 private:
106 CreateLeafFunc createLeafFunc;
107 };
108
109 template<typename CreateLeafFunc>
110 static NodeRecordMB build(FastAllocator* allocator, CreateLeafFunc createLeaf, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings, const BBox1f& timeRange) {
111 return BVHNBuilderT<CreateLeafFunc>(createLeaf).build(allocator,progress,prims,pinfo,settings,timeRange);
112 }
113 };
114 }
115}
116