diff --git a/tutorials/07_custom_bvh_import/main.cpp b/tutorials/07_custom_bvh_import/main.cpp index 69d56ec..303e221 100644 --- a/tutorials/07_custom_bvh_import/main.cpp +++ b/tutorials/07_custom_bvh_import/main.cpp @@ -59,9 +59,12 @@ class Tutorial : public TutorialBase geomInput.primitive.triangleMesh = mesh; buildBvh( geomInput ); - hiprtDevicePtr geomTemp = nullptr; + size_t geomTempSize; + hiprtDevicePtr geomTemp; hiprtBuildOptions options; options.buildFlags = hiprtBuildFlagBitCustomBvhImport; + CHECK_HIPRT( hiprtGetGeometryBuildTemporaryBufferSize( ctxt, geomInput, options, geomTempSize ) ); + CHECK_ORO( oroMalloc( reinterpret_cast( &geomTemp ), geomTempSize ) ); hiprtGeometry geom; CHECK_HIPRT( hiprtCreateGeometry( ctxt, geomInput, options, geom ) ); @@ -97,6 +100,8 @@ class Tutorial : public TutorialBase CHECK_ORO( oroFree( reinterpret_cast( mesh.triangleIndices ) ) ); CHECK_ORO( oroFree( reinterpret_cast( mesh.vertices ) ) ); CHECK_ORO( oroFree( reinterpret_cast( pixels ) ) ); + CHECK_ORO( oroFree( reinterpret_cast( geomInput.nodeList.leafNodes ) ) ); + CHECK_ORO( oroFree( reinterpret_cast( geomInput.nodeList.internalNodes ) ) ); CHECK_HIPRT( hiprtDestroyGeometry( ctxt, geom ) ); CHECK_HIPRT( hiprtDestroyContext( ctxt ) ); @@ -105,10 +110,11 @@ class Tutorial : public TutorialBase void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput ) { - std::vector nodes; + std::vector internalNodes; + std::vector primBoxes; if ( buildInput.type == hiprtPrimitiveTypeTriangleMesh ) { - std::vector primBoxes( buildInput.primitive.triangleMesh.triangleCount ); + primBoxes.resize( buildInput.primitive.triangleMesh.triangleCount ); std::vector verticesRaw( buildInput.primitive.triangleMesh.vertexCount * buildInput.primitive.triangleMesh.vertexStride ); std::vector trianglesRaw( @@ -136,11 +142,11 @@ void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput ) primBoxes[i].grow( v1 ); primBoxes[i].grow( v2 ); } - BvhBuilder::build( buildInput.primitive.triangleMesh.triangleCount, primBoxes, nodes ); + BvhBuilder::build( buildInput.primitive.triangleMesh.triangleCount, primBoxes, internalNodes ); } else if ( buildInput.type == hiprtPrimitiveTypeAABBList ) { - std::vector primBoxes( buildInput.primitive.aabbList.aabbCount ); + primBoxes.resize( buildInput.primitive.aabbList.aabbCount ); std::vector primBoxesRaw( buildInput.primitive.aabbList.aabbCount * buildInput.primitive.aabbList.aabbStride ); CHECK_ORO( oroMemcpyDtoH( primBoxesRaw.data(), @@ -153,13 +159,32 @@ void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput ) primBoxes[i].m_min = make_float3( ptr[0] ); primBoxes[i].m_max = make_float3( ptr[1] ); } - BvhBuilder::build( buildInput.primitive.aabbList.aabbCount, primBoxes, nodes ); + BvhBuilder::build( buildInput.primitive.aabbList.aabbCount, primBoxes, internalNodes ); } - CHECK_ORO( - oroMalloc( reinterpret_cast( &buildInput.nodeList.nodes ), nodes.size() * sizeof( hiprtBvhNode ) ) ); + + std::vector leafNodes( primBoxes.size() ); + for ( uint32_t i = 0; i < primBoxes.size(); ++i ) + { + leafNodes[i].primID = i; + leafNodes[i].aabbMin = primBoxes[i].m_min; + leafNodes[i].aabbMax = primBoxes[i].m_max; + } + + buildInput.nodeList.nodeCount = static_cast( leafNodes.size() ); + + CHECK_ORO( oroMalloc( + reinterpret_cast( &buildInput.nodeList.leafNodes ), leafNodes.size() * sizeof( hiprtLeafNode ) ) ); + CHECK_ORO( oroMemcpyHtoD( + reinterpret_cast( buildInput.nodeList.leafNodes ), + leafNodes.data(), + leafNodes.size() * sizeof( hiprtLeafNode ) ) ); + CHECK_ORO( oroMalloc( + reinterpret_cast( &buildInput.nodeList.internalNodes ), + internalNodes.size() * sizeof( hiprtInternalNode ) ) ); CHECK_ORO( oroMemcpyHtoD( - reinterpret_cast( buildInput.nodeList.nodes ), nodes.data(), nodes.size() * sizeof( hiprtBvhNode ) ) ); - buildInput.nodeList.nodeCount = static_cast( nodes.size() ); + reinterpret_cast( buildInput.nodeList.internalNodes ), + internalNodes.data(), + internalNodes.size() * sizeof( hiprtInternalNode ) ) ); } int main( int argc, char** argv ) diff --git a/tutorials/17_hiprt_hip/premake5.lua b/tutorials/17_hiprt_hip/premake5.lua index 8283088..1efcd55 100644 --- a/tutorials/17_hiprt_hip/premake5.lua +++ b/tutorials/17_hiprt_hip/premake5.lua @@ -29,5 +29,5 @@ project "17_hiprt_hip" files { "./**.h", "./**.cpp"} files { "../../hiprt/*.h"} - links {"hiprt0200564"} + links {"hiprt0300064"} targetdir "../dist/bin/%{cfg.buildcfg}" diff --git a/tutorials/common/BvhBuilder.h b/tutorials/common/BvhBuilder.h index d904f66..0b4e52e 100644 --- a/tutorials/common/BvhBuilder.h +++ b/tutorials/common/BvhBuilder.h @@ -44,7 +44,7 @@ class BvhBuilder BvhBuilder( void ) = delete; BvhBuilder& operator=( const BvhBuilder& ) = delete; - static void build( uint32_t nPrims, const std::vector& primBoxes, std::vector& nodes ) + static void build( uint32_t nPrims, const std::vector& primBoxes, std::vector& nodes ) { assert( nPrims >= 2 ); std::vector rightBoxes( nPrims ); @@ -70,7 +70,7 @@ class BvhBuilder std::queue queue; queue.push( QueueEntry( 0, 0, nPrims, box ) ); - nodes.push_back( hiprtBvhNode() ); + nodes.push_back( hiprtInternalNode() ); while ( !queue.empty() ) { int nodeIndex = queue.front().m_nodeIndex; @@ -141,13 +141,8 @@ class BvhBuilder } } - nodes[nodeIndex].childAabbsMin[0] = minLeftBox.m_min; - nodes[nodeIndex].childAabbsMax[0] = minLeftBox.m_max; - nodes[nodeIndex].childAabbsMin[1] = minRightBox.m_min; - nodes[nodeIndex].childAabbsMax[1] = minRightBox.m_max; - nodes[nodeIndex].childIndices[2] = hiprtInvalidValue; - nodes[nodeIndex].childIndices[3] = hiprtInvalidValue; - + nodes[nodeIndex].aabbMin = min( minLeftBox.m_min, minRightBox.m_min ); + nodes[nodeIndex].aabbMax = max( minLeftBox.m_max, minRightBox.m_max ); if ( minIndex - begin == 1 ) { nodes[nodeIndex].childIndices[0] = indices[minAxis][begin]; @@ -158,7 +153,7 @@ class BvhBuilder nodes[nodeIndex].childIndices[0] = static_cast( nodes.size() ); nodes[nodeIndex].childNodeTypes[0] = hiprtBvhNodeTypeInternal; queue.push( QueueEntry( nodes[nodeIndex].childIndices[0], begin, minIndex, minLeftBox ) ); - nodes.push_back( hiprtBvhNode() ); + nodes.push_back( hiprtInternalNode() ); } if ( end - minIndex == 1 ) @@ -171,7 +166,7 @@ class BvhBuilder nodes[nodeIndex].childIndices[1] = static_cast( nodes.size() ); nodes[nodeIndex].childNodeTypes[1] = hiprtBvhNodeTypeInternal; queue.push( QueueEntry( nodes[nodeIndex].childIndices[1], minIndex, end, minRightBox ) ); - nodes.push_back( hiprtBvhNode() ); + nodes.push_back( hiprtInternalNode() ); } } } diff --git a/tutorials/common/SceneDemo.cpp b/tutorials/common/SceneDemo.cpp index e70f9d2..79b787c 100644 --- a/tutorials/common/SceneDemo.cpp +++ b/tutorials/common/SceneDemo.cpp @@ -53,7 +53,8 @@ void SceneDemo::createScene( std::optional frame, hiprtBuildFlags bvhBuildFlag ) { - hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, scene.m_ctx ); + CHECK_HIPRT( hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, scene.m_ctx ) ); + CHECK_HIPRT( hiprtSetLogLevel( scene.m_ctx, hiprtLogLevelError ) ); tinyobj::attrib_t attrib; std::vector shapes; @@ -367,7 +368,8 @@ void SceneDemo::createScene( OrochiUtils::free( geomInput.primitive.triangleMesh.vertices ); if ( bvhBuildFlag == hiprtBuildFlagBitCustomBvhImport ) { - OrochiUtils::free( geomInput.nodeList.nodes ); + OrochiUtils::free( geomInput.nodeList.leafNodes ); + OrochiUtils::free( geomInput.nodeList.internalNodes ); OrochiUtils::free( geomInput.primitive.triangleMesh.trianglePairIndices ); } } diff --git a/tutorials/common/TutorialBase.cpp b/tutorials/common/TutorialBase.cpp index 9899e25..949a386 100644 --- a/tutorials/common/TutorialBase.cpp +++ b/tutorials/common/TutorialBase.cpp @@ -82,7 +82,6 @@ void TutorialBase::init( uint32_t deviceIndex ) m_ctxtInput.ctxt = oroGetRawCtx( m_oroCtx ); m_ctxtInput.device = oroGetRawDevice( m_oroDevice ); - hiprtSetLogLevel( hiprtLogLevelError ); } bool TutorialBase::readSourceCode( diff --git a/tutorials/common/dependency.lua b/tutorials/common/dependency.lua index 051f617..fa71fc6 100644 --- a/tutorials/common/dependency.lua +++ b/tutorials/common/dependency.lua @@ -12,5 +12,5 @@ if os.ishost("linux") then end files { "../../hiprt/*.h"} -links {"hiprt0200564"} +links {"hiprt0300064"}