MCPcopy Create free account
hub / github.com/RenderKit/embree / build

Function build

tutorials/bvh_builder/bvh_builder_device.cpp:91–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 };
90
91 void build(RTCBuildQuality quality, avector<RTCBuildPrimitive>& prims_i, char* cfg, size_t extraSpace = 0)
92 {
93 rtcSetDeviceMemoryMonitorFunction(g_device,memoryMonitor,nullptr);
94
95 RTCBVH bvh = rtcNewBVH(g_device);
96
97 avector<RTCBuildPrimitive> prims;
98 prims.reserve(prims_i.size()+extraSpace);
99 prims.resize(prims_i.size());
100
101 /* settings for BVH build */
102 RTCBuildArguments arguments = rtcDefaultBuildArguments();
103 arguments.byteSize = sizeof(arguments);
104 arguments.buildFlags = RTC_BUILD_FLAG_DYNAMIC;
105 arguments.buildQuality = quality;
106 arguments.maxBranchingFactor = 2;
107 arguments.maxDepth = 1024;
108 arguments.sahBlockSize = 1;
109 arguments.minLeafSize = 1;
110 arguments.maxLeafSize = 1;
111 arguments.traversalCost = 1.0f;
112 arguments.intersectionCost = 1.0f;
113 arguments.bvh = bvh;
114 arguments.primitives = prims.data();
115 arguments.primitiveCount = prims.size();
116 arguments.primitiveArrayCapacity = prims.capacity();
117 arguments.createNode = InnerNode::create;
118 arguments.setNodeChildren = InnerNode::setChildren;
119 arguments.setNodeBounds = InnerNode::setBounds;
120 arguments.createLeaf = LeafNode::create;
121 arguments.splitPrimitive = splitPrimitive;
122 arguments.buildProgress = buildProgress;
123 arguments.userPtr = nullptr;
124
125 for (size_t i=0; i<10; i++)
126 {
127 /* we recreate the prims array here, as the builders modify this array */
128 for (size_t j=0; j<prims.size(); j++) prims[j] = prims_i[j];
129
130 std::cout << "iteration " << i << ": building BVH over " << prims.size() << " primitives, " << std::flush;
131 double t0 = getSeconds();
132 Node* root = (Node*) rtcBuildBVH(&arguments);
133 double t1 = getSeconds();
134 const float sah = root ? root->sah() : 0.0f;
135 std::cout << 1000.0f*(t1-t0) << "ms, " << 1E-6*double(prims.size())/(t1-t0) << " Mprims/s, sah = " << sah << " [DONE]" << std::endl;
136 }
137
138 rtcReleaseBVH(bvh);
139 }
140
141 /* called by the C++ code for initialization */
142 extern "C" void device_init (char* cfg)

Callers 1

device_initFunction · 0.70

Calls 12

rtcNewBVHFunction · 0.85
rtcDefaultBuildArgumentsFunction · 0.85
getSecondsFunction · 0.85
rtcBuildBVHFunction · 0.85
rtcReleaseBVHFunction · 0.85
reserveMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
capacityMethod · 0.45
sahMethod · 0.45

Tested by

no test coverage detected