bvh_builder.h 4.7 KB

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