rtcore_builder.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2009-2021 Intel Corporation
  2. // SPDX-License-Identifier: Apache-2.0
  3. #pragma once
  4. #include "rtcore_scene.h"
  5. RTC_NAMESPACE_BEGIN
  6. /* Opaque BVH type */
  7. typedef struct RTCBVHTy* RTCBVH;
  8. /* Input build primitives for the builder */
  9. struct RTC_ALIGN(32) RTCBuildPrimitive
  10. {
  11. float lower_x, lower_y, lower_z;
  12. unsigned int geomID;
  13. float upper_x, upper_y, upper_z;
  14. unsigned int primID;
  15. };
  16. /* Opaque thread local allocator type */
  17. typedef struct RTCThreadLocalAllocatorTy* RTCThreadLocalAllocator;
  18. /* Callback to create a node */
  19. typedef void* (*RTCCreateNodeFunction) (RTCThreadLocalAllocator allocator, unsigned int childCount, void* userPtr);
  20. /* Callback to set the pointer to all children */
  21. typedef void (*RTCSetNodeChildrenFunction) (void* nodePtr, void** children, unsigned int childCount, void* userPtr);
  22. /* Callback to set the bounds of all children */
  23. typedef void (*RTCSetNodeBoundsFunction) (void* nodePtr, const struct RTCBounds** bounds, unsigned int childCount, void* userPtr);
  24. /* Callback to create a leaf node */
  25. typedef void* (*RTCCreateLeafFunction) (RTCThreadLocalAllocator allocator, const struct RTCBuildPrimitive* primitives, size_t primitiveCount, void* userPtr);
  26. /* Callback to split a build primitive */
  27. typedef void (*RTCSplitPrimitiveFunction) (const struct RTCBuildPrimitive* primitive, unsigned int dimension, float position, struct RTCBounds* leftBounds, struct RTCBounds* rightBounds, void* userPtr);
  28. /* Build flags */
  29. enum RTCBuildFlags
  30. {
  31. RTC_BUILD_FLAG_NONE = 0,
  32. RTC_BUILD_FLAG_DYNAMIC = (1 << 0),
  33. };
  34. enum RTCBuildConstants
  35. {
  36. RTC_BUILD_MAX_PRIMITIVES_PER_LEAF = 32
  37. };
  38. /* Input for builders */
  39. struct RTCBuildArguments
  40. {
  41. size_t byteSize;
  42. enum RTCBuildQuality buildQuality;
  43. enum RTCBuildFlags buildFlags;
  44. unsigned int maxBranchingFactor;
  45. unsigned int maxDepth;
  46. unsigned int sahBlockSize;
  47. unsigned int minLeafSize;
  48. unsigned int maxLeafSize;
  49. float traversalCost;
  50. float intersectionCost;
  51. RTCBVH bvh;
  52. struct RTCBuildPrimitive* primitives;
  53. size_t primitiveCount;
  54. size_t primitiveArrayCapacity;
  55. RTCCreateNodeFunction createNode;
  56. RTCSetNodeChildrenFunction setNodeChildren;
  57. RTCSetNodeBoundsFunction setNodeBounds;
  58. RTCCreateLeafFunction createLeaf;
  59. RTCSplitPrimitiveFunction splitPrimitive;
  60. RTCProgressMonitorFunction buildProgress;
  61. void* userPtr;
  62. };
  63. /* Returns the default build settings. */
  64. RTC_FORCEINLINE struct RTCBuildArguments rtcDefaultBuildArguments()
  65. {
  66. struct RTCBuildArguments args;
  67. args.byteSize = sizeof(args);
  68. args.buildQuality = RTC_BUILD_QUALITY_MEDIUM;
  69. args.buildFlags = RTC_BUILD_FLAG_NONE;
  70. args.maxBranchingFactor = 2;
  71. args.maxDepth = 32;
  72. args.sahBlockSize = 1;
  73. args.minLeafSize = 1;
  74. args.maxLeafSize = RTC_BUILD_MAX_PRIMITIVES_PER_LEAF;
  75. args.traversalCost = 1.0f;
  76. args.intersectionCost = 1.0f;
  77. args.bvh = NULL;
  78. args.primitives = NULL;
  79. args.primitiveCount = 0;
  80. args.primitiveArrayCapacity = 0;
  81. args.createNode = NULL;
  82. args.setNodeChildren = NULL;
  83. args.setNodeBounds = NULL;
  84. args.createLeaf = NULL;
  85. args.splitPrimitive = NULL;
  86. args.buildProgress = NULL;
  87. args.userPtr = NULL;
  88. return args;
  89. }
  90. /* Creates a new BVH. */
  91. RTC_API RTCBVH rtcNewBVH(RTCDevice device);
  92. /* Builds a BVH. */
  93. RTC_API void* rtcBuildBVH(const struct RTCBuildArguments* args);
  94. /* Allocates memory using the thread local allocator. */
  95. RTC_API void* rtcThreadLocalAlloc(RTCThreadLocalAllocator allocator, size_t bytes, size_t align);
  96. /* Retains the BVH (increments reference count). */
  97. RTC_API void rtcRetainBVH(RTCBVH bvh);
  98. /* Releases the BVH (decrements reference count). */
  99. RTC_API void rtcReleaseBVH(RTCBVH bvh);
  100. RTC_NAMESPACE_END