Skip to content

Commit 7624f6b

Browse files
committed
Update for HIPRT-v3
1 parent 8be6e0d commit 7624f6b

6 files changed

Lines changed: 43 additions & 24 deletions

File tree

tutorials/07_custom_bvh_import/main.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,11 @@ class Tutorial : public TutorialBase
105105

106106
void 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

165185
int main( int argc, char** argv )

tutorials/17_hiprt_hip/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ project "17_hiprt_hip"
2929
files { "./**.h", "./**.cpp"}
3030
files { "../../hiprt/*.h"}
3131

32-
links {"hiprt0200564"}
32+
links {"hiprt0300064"}
3333
targetdir "../dist/bin/%{cfg.buildcfg}"

tutorials/common/BvhBuilder.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class BvhBuilder
4444
BvhBuilder( void ) = delete;
4545
BvhBuilder& operator=( const BvhBuilder& ) = delete;
4646

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

7171
std::queue<QueueEntry> queue;
7272
queue.push( QueueEntry( 0, 0, nPrims, box ) );
73-
nodes.push_back( hiprtBvhNode() );
73+
nodes.push_back( hiprtInternalNode() );
7474
while ( !queue.empty() )
7575
{
7676
int nodeIndex = queue.front().m_nodeIndex;
@@ -141,12 +141,10 @@ class BvhBuilder
141141
}
142142
}
143143

144-
nodes[nodeIndex].childAabbsMin[0] = minLeftBox.m_min;
145-
nodes[nodeIndex].childAabbsMax[0] = minLeftBox.m_max;
146-
nodes[nodeIndex].childAabbsMin[1] = minRightBox.m_min;
147-
nodes[nodeIndex].childAabbsMax[1] = minRightBox.m_max;
148-
nodes[nodeIndex].childIndices[2] = hiprtInvalidValue;
149-
nodes[nodeIndex].childIndices[3] = hiprtInvalidValue;
144+
nodes[nodeIndex].aabbMin = min( minLeftBox.m_min, minRightBox.m_min );
145+
nodes[nodeIndex].aabbMax = max( minLeftBox.m_max, minRightBox.m_max );
146+
for ( uint32_t k = 2; k < 2; ++k )
147+
nodes[nodeIndex].childIndices[k] = hiprtInvalidValue;
150148

151149
if ( minIndex - begin == 1 )
152150
{
@@ -158,7 +156,7 @@ class BvhBuilder
158156
nodes[nodeIndex].childIndices[0] = static_cast<int>( nodes.size() );
159157
nodes[nodeIndex].childNodeTypes[0] = hiprtBvhNodeTypeInternal;
160158
queue.push( QueueEntry( nodes[nodeIndex].childIndices[0], begin, minIndex, minLeftBox ) );
161-
nodes.push_back( hiprtBvhNode() );
159+
nodes.push_back( hiprtInternalNode() );
162160
}
163161

164162
if ( end - minIndex == 1 )
@@ -171,7 +169,7 @@ class BvhBuilder
171169
nodes[nodeIndex].childIndices[1] = static_cast<int>( nodes.size() );
172170
nodes[nodeIndex].childNodeTypes[1] = hiprtBvhNodeTypeInternal;
173171
queue.push( QueueEntry( nodes[nodeIndex].childIndices[1], minIndex, end, minRightBox ) );
174-
nodes.push_back( hiprtBvhNode() );
172+
nodes.push_back( hiprtInternalNode() );
175173
}
176174
}
177175
}

tutorials/common/SceneDemo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ void SceneDemo::createScene(
5353
std::optional<hiprtFrameSRT> frame,
5454
hiprtBuildFlags bvhBuildFlag )
5555
{
56-
hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, scene.m_ctx );
56+
CHECK_HIPRT( hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, scene.m_ctx ) );
57+
CHECK_HIPRT( hiprtSetLogLevel( scene.m_ctx, hiprtLogLevelError ) );
5758

5859
tinyobj::attrib_t attrib;
5960
std::vector<tinyobj::shape_t> shapes;
@@ -367,7 +368,8 @@ void SceneDemo::createScene(
367368
OrochiUtils::free( geomInput.primitive.triangleMesh.vertices );
368369
if ( bvhBuildFlag == hiprtBuildFlagBitCustomBvhImport )
369370
{
370-
OrochiUtils::free( geomInput.nodeList.nodes );
371+
OrochiUtils::free( geomInput.nodeList.leafNodes );
372+
OrochiUtils::free( geomInput.nodeList.internalNodes );
371373
OrochiUtils::free( geomInput.primitive.triangleMesh.trianglePairIndices );
372374
}
373375
}

tutorials/common/TutorialBase.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ void TutorialBase::init( uint32_t deviceIndex )
8282

8383
m_ctxtInput.ctxt = oroGetRawCtx( m_oroCtx );
8484
m_ctxtInput.device = oroGetRawDevice( m_oroDevice );
85-
hiprtSetLogLevel( hiprtLogLevelError );
8685
}
8786

8887
bool TutorialBase::readSourceCode(

tutorials/common/dependency.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ if os.ishost("linux") then
1212
end
1313

1414
files { "../../hiprt/*.h"}
15-
links {"hiprt0200564"}
15+
links {"hiprt0300064"}
1616

0 commit comments

Comments
 (0)