bvh_builder.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  3. // //
  4. // Licensed under the Apache License, Version 2.0 (the "License"); //
  5. // you may not use this file except in compliance with the License. //
  6. // You may obtain a copy of the License at //
  7. // //
  8. // http://www.apache.org/licenses/LICENSE-2.0 //
  9. // //
  10. // Unless required by applicable law or agreed to in writing, software //
  11. // distributed under the License is distributed on an "AS IS" BASIS, //
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
  13. // See the License for the specific language governing permissions and //
  14. // limitations under the License. //
  15. // ======================================================================== //
  16. #include "bvh.h"
  17. #include "../builders/bvh_builder_sah.h"
  18. namespace embree
  19. {
  20. namespace isa
  21. {
  22. template<int N>
  23. struct BVHNBuilderVirtual
  24. {
  25. typedef BVHN<N> BVH;
  26. typedef typename BVH::NodeRef NodeRef;
  27. typedef FastAllocator::ThreadLocal2 Allocator;
  28. struct BVHNBuilderV {
  29. NodeRef build(FastAllocator* allocator, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings);
  30. virtual NodeRef createLeaf (const BVHBuilderBinnedSAH::BuildRecord& current, Allocator* alloc) = 0;
  31. };
  32. template<typename CreateLeafFunc>
  33. struct BVHNBuilderT : public BVHNBuilderV
  34. {
  35. BVHNBuilderT (CreateLeafFunc createLeafFunc)
  36. : createLeafFunc(createLeafFunc) {}
  37. NodeRef createLeaf (const BVHBuilderBinnedSAH::BuildRecord& current, Allocator* alloc) {
  38. return createLeafFunc(current,alloc);
  39. }
  40. private:
  41. CreateLeafFunc createLeafFunc;
  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. template<int N>
  49. struct BVHNBuilderQuantizedVirtual
  50. {
  51. typedef BVHN<N> BVH;
  52. typedef typename BVH::NodeRef NodeRef;
  53. typedef FastAllocator::ThreadLocal2 Allocator;
  54. struct BVHNBuilderV {
  55. NodeRef build(FastAllocator* allocator, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings);
  56. virtual NodeRef createLeaf (const BVHBuilderBinnedSAH::BuildRecord& current, Allocator* alloc) = 0;
  57. };
  58. template<typename CreateLeafFunc>
  59. struct BVHNBuilderT : public BVHNBuilderV
  60. {
  61. BVHNBuilderT (CreateLeafFunc createLeafFunc)
  62. : createLeafFunc(createLeafFunc) {}
  63. NodeRef createLeaf (const BVHBuilderBinnedSAH::BuildRecord& current, Allocator* alloc) {
  64. return createLeafFunc(current,alloc);
  65. }
  66. private:
  67. CreateLeafFunc createLeafFunc;
  68. };
  69. template<typename CreateLeafFunc>
  70. static NodeRef build(FastAllocator* allocator, CreateLeafFunc createLeaf, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings) {
  71. return BVHNBuilderT<CreateLeafFunc>(createLeaf).build(allocator,progress,prims,pinfo,settings);
  72. }
  73. };
  74. template<int N>
  75. struct BVHNBuilderMblurVirtual
  76. {
  77. typedef BVHN<N> BVH;
  78. typedef typename BVH::AlignedNodeMB AlignedNodeMB;
  79. typedef typename BVH::NodeRef NodeRef;
  80. typedef FastAllocator::ThreadLocal2 Allocator;
  81. struct BVHNBuilderV {
  82. std::tuple<NodeRef,LBBox3fa> build(FastAllocator* allocator, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings);
  83. virtual std::pair<NodeRef,LBBox3fa> createLeaf (const BVHBuilderBinnedSAH::BuildRecord& current, Allocator* alloc) = 0;
  84. };
  85. template<typename CreateLeafFunc>
  86. struct BVHNBuilderT : public BVHNBuilderV
  87. {
  88. BVHNBuilderT (CreateLeafFunc createLeafFunc)
  89. : createLeafFunc(createLeafFunc) {}
  90. std::pair<NodeRef,LBBox3fa> createLeaf (const BVHBuilderBinnedSAH::BuildRecord& current, Allocator* alloc) {
  91. return createLeafFunc(current,alloc);
  92. }
  93. private:
  94. CreateLeafFunc createLeafFunc;
  95. };
  96. template<typename CreateLeafFunc>
  97. static std::tuple<NodeRef,LBBox3fa> build(FastAllocator* allocator, CreateLeafFunc createLeaf, BuildProgressMonitor& progress, PrimRef* prims, const PrimInfo& pinfo, GeneralBVHBuilder::Settings settings) {
  98. return BVHNBuilderT<CreateLeafFunc>(createLeaf).build(allocator,progress,prims,pinfo,settings);
  99. }
  100. };
  101. }
  102. }