@@ -105,10 +105,11 @@ class Tutorial : public TutorialBase
105105
106106void Tutorial::buildBvh ( hiprtGeometryBuildInput& buildInput )
107107{
108- std::vector<hiprtBvhNode> nodes;
108+ std::vector<hiprtInternalNode> internalNodes;
109+ std::vector<Aabb> primBoxes;
109110 if ( buildInput.type == hiprtPrimitiveTypeTriangleMesh )
110111 {
111- std::vector<Aabb> primBoxes ( buildInput.primitive .triangleMesh .triangleCount );
112+ primBoxes. resize ( buildInput.primitive .triangleMesh .triangleCount );
112113 std::vector<uint8_t > verticesRaw (
113114 buildInput.primitive .triangleMesh .vertexCount * buildInput.primitive .triangleMesh .vertexStride );
114115 std::vector<uint8_t > trianglesRaw (
@@ -136,11 +137,11 @@ void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput )
136137 primBoxes[i].grow ( v1 );
137138 primBoxes[i].grow ( v2 );
138139 }
139- BvhBuilder::build ( buildInput.primitive .triangleMesh .triangleCount , primBoxes, nodes );
140+ BvhBuilder::build ( buildInput.primitive .triangleMesh .triangleCount , primBoxes, internalNodes );
140141 }
141142 else if ( buildInput.type == hiprtPrimitiveTypeAABBList )
142143 {
143- std::vector<Aabb> primBoxes ( buildInput.primitive .aabbList .aabbCount );
144+ primBoxes. resize ( buildInput.primitive .aabbList .aabbCount );
144145 std::vector<uint8_t > primBoxesRaw ( buildInput.primitive .aabbList .aabbCount * buildInput.primitive .aabbList .aabbStride );
145146 CHECK_ORO ( oroMemcpyDtoH (
146147 primBoxesRaw.data (),
@@ -153,13 +154,32 @@ void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput )
153154 primBoxes[i].m_min = make_float3 ( ptr[0 ] );
154155 primBoxes[i].m_max = make_float3 ( ptr[1 ] );
155156 }
156- BvhBuilder::build ( buildInput.primitive .aabbList .aabbCount , primBoxes, nodes );
157+ BvhBuilder::build ( buildInput.primitive .aabbList .aabbCount , primBoxes, internalNodes );
157158 }
158- CHECK_ORO (
159- oroMalloc ( reinterpret_cast <oroDeviceptr*>( &buildInput.nodeList .nodes ), nodes.size () * sizeof ( hiprtBvhNode ) ) );
159+
160+ std::vector<hiprtLeafNode> leafNodes ( primBoxes.size () );
161+ for ( uint32_t i = 0 ; i < primBoxes.size (); ++i )
162+ {
163+ leafNodes[i].primID = i;
164+ leafNodes[i].aabbMin = primBoxes[i].m_min ;
165+ leafNodes[i].aabbMax = primBoxes[i].m_max ;
166+ }
167+
168+ buildInput.nodeList .nodeCount = static_cast <uint32_t >( leafNodes.size () );
169+
170+ CHECK_ORO ( oroMalloc (
171+ reinterpret_cast <oroDeviceptr*>( &buildInput.nodeList .leafNodes ), leafNodes.size () * sizeof ( hiprtLeafNode ) ) );
172+ CHECK_ORO ( oroMemcpyHtoD (
173+ reinterpret_cast <oroDeviceptr>( buildInput.nodeList .leafNodes ),
174+ leafNodes.data (),
175+ leafNodes.size () * sizeof ( hiprtLeafNode ) ) );
176+ CHECK_ORO ( oroMalloc (
177+ reinterpret_cast <oroDeviceptr*>( &buildInput.nodeList .internalNodes ),
178+ internalNodes.size () * sizeof ( hiprtInternalNode ) ) );
160179 CHECK_ORO ( oroMemcpyHtoD (
161- reinterpret_cast <oroDeviceptr>( buildInput.nodeList .nodes ), nodes.data (), nodes.size () * sizeof ( hiprtBvhNode ) ) );
162- buildInput.nodeList .nodeCount = static_cast <uint32_t >( nodes.size () );
180+ reinterpret_cast <oroDeviceptr>( buildInput.nodeList .internalNodes ),
181+ internalNodes.data (),
182+ internalNodes.size () * sizeof ( hiprtInternalNode ) ) );
163183}
164184
165185int main ( int argc, char ** argv )
0 commit comments