Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions tutorials/07_custom_bvh_import/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<oroDeviceptr*>( &geomTemp ), geomTempSize ) );

hiprtGeometry geom;
CHECK_HIPRT( hiprtCreateGeometry( ctxt, geomInput, options, geom ) );
Expand Down Expand Up @@ -97,6 +100,8 @@ class Tutorial : public TutorialBase
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ) ) );
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.vertices ) ) );
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( pixels ) ) );
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( geomInput.nodeList.leafNodes ) ) );
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( geomInput.nodeList.internalNodes ) ) );

CHECK_HIPRT( hiprtDestroyGeometry( ctxt, geom ) );
CHECK_HIPRT( hiprtDestroyContext( ctxt ) );
Expand All @@ -105,10 +110,11 @@ class Tutorial : public TutorialBase

void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput )
{
std::vector<hiprtBvhNode> nodes;
std::vector<hiprtInternalNode> internalNodes;
std::vector<Aabb> primBoxes;
if ( buildInput.type == hiprtPrimitiveTypeTriangleMesh )
{
std::vector<Aabb> primBoxes( buildInput.primitive.triangleMesh.triangleCount );
primBoxes.resize( buildInput.primitive.triangleMesh.triangleCount );
std::vector<uint8_t> verticesRaw(
buildInput.primitive.triangleMesh.vertexCount * buildInput.primitive.triangleMesh.vertexStride );
std::vector<uint8_t> trianglesRaw(
Expand Down Expand Up @@ -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<Aabb> primBoxes( buildInput.primitive.aabbList.aabbCount );
primBoxes.resize( buildInput.primitive.aabbList.aabbCount );
std::vector<uint8_t> primBoxesRaw( buildInput.primitive.aabbList.aabbCount * buildInput.primitive.aabbList.aabbStride );
CHECK_ORO( oroMemcpyDtoH(
primBoxesRaw.data(),
Expand All @@ -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<oroDeviceptr*>( &buildInput.nodeList.nodes ), nodes.size() * sizeof( hiprtBvhNode ) ) );

std::vector<hiprtLeafNode> 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<uint32_t>( leafNodes.size() );

CHECK_ORO( oroMalloc(
reinterpret_cast<oroDeviceptr*>( &buildInput.nodeList.leafNodes ), leafNodes.size() * sizeof( hiprtLeafNode ) ) );
CHECK_ORO( oroMemcpyHtoD(
reinterpret_cast<oroDeviceptr>( buildInput.nodeList.leafNodes ),
leafNodes.data(),
leafNodes.size() * sizeof( hiprtLeafNode ) ) );
CHECK_ORO( oroMalloc(
reinterpret_cast<oroDeviceptr*>( &buildInput.nodeList.internalNodes ),
internalNodes.size() * sizeof( hiprtInternalNode ) ) );
CHECK_ORO( oroMemcpyHtoD(
reinterpret_cast<oroDeviceptr>( buildInput.nodeList.nodes ), nodes.data(), nodes.size() * sizeof( hiprtBvhNode ) ) );
buildInput.nodeList.nodeCount = static_cast<uint32_t>( nodes.size() );
reinterpret_cast<oroDeviceptr>( buildInput.nodeList.internalNodes ),
internalNodes.data(),
internalNodes.size() * sizeof( hiprtInternalNode ) ) );
}

int main( int argc, char** argv )
Expand Down
2 changes: 1 addition & 1 deletion tutorials/17_hiprt_hip/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ project "17_hiprt_hip"
files { "./**.h", "./**.cpp"}
files { "../../hiprt/*.h"}

links {"hiprt0200564"}
links {"hiprt0300064"}
targetdir "../dist/bin/%{cfg.buildcfg}"
17 changes: 6 additions & 11 deletions tutorials/common/BvhBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BvhBuilder
BvhBuilder( void ) = delete;
BvhBuilder& operator=( const BvhBuilder& ) = delete;

static void build( uint32_t nPrims, const std::vector<Aabb>& primBoxes, std::vector<hiprtBvhNode>& nodes )
static void build( uint32_t nPrims, const std::vector<Aabb>& primBoxes, std::vector<hiprtInternalNode>& nodes )
{
assert( nPrims >= 2 );
std::vector<Aabb> rightBoxes( nPrims );
Expand All @@ -70,7 +70,7 @@ class BvhBuilder

std::queue<QueueEntry> 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;
Expand Down Expand Up @@ -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];
Expand All @@ -158,7 +153,7 @@ class BvhBuilder
nodes[nodeIndex].childIndices[0] = static_cast<int>( 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 )
Expand All @@ -171,7 +166,7 @@ class BvhBuilder
nodes[nodeIndex].childIndices[1] = static_cast<int>( 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() );
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions tutorials/common/SceneDemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ void SceneDemo::createScene(
std::optional<hiprtFrameSRT> 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<tinyobj::shape_t> shapes;
Expand Down Expand Up @@ -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 );
}
}
Expand Down
1 change: 0 additions & 1 deletion tutorials/common/TutorialBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tutorials/common/dependency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ if os.ishost("linux") then
end

files { "../../hiprt/*.h"}
links {"hiprt0200564"}
links {"hiprt0300064"}