Skip to content

Commit 2442d0d

Browse files
authored
Merge pull request #49 from GPUOpen-LibrariesAndSDKs/feature/HRT-0-03000
HIPRT-v3
2 parents 8be6e0d + 3d46cb7 commit 2442d0d

6 files changed

Lines changed: 47 additions & 26 deletions

File tree

tutorials/07_custom_bvh_import/main.cpp

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ class Tutorial : public TutorialBase
5959
geomInput.primitive.triangleMesh = mesh;
6060
buildBvh( geomInput );
6161

62-
hiprtDevicePtr geomTemp = nullptr;
62+
size_t geomTempSize;
63+
hiprtDevicePtr geomTemp;
6364
hiprtBuildOptions options;
6465
options.buildFlags = hiprtBuildFlagBitCustomBvhImport;
66+
CHECK_HIPRT( hiprtGetGeometryBuildTemporaryBufferSize( ctxt, geomInput, options, geomTempSize ) );
67+
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &geomTemp ), geomTempSize ) );
6568

6669
hiprtGeometry geom;
6770
CHECK_HIPRT( hiprtCreateGeometry( ctxt, geomInput, options, geom ) );
@@ -97,6 +100,8 @@ class Tutorial : public TutorialBase
97100
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ) ) );
98101
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.vertices ) ) );
99102
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( pixels ) ) );
103+
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( geomInput.nodeList.leafNodes ) ) );
104+
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( geomInput.nodeList.internalNodes ) ) );
100105

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

106111
void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput )
107112
{
108-
std::vector<hiprtBvhNode> nodes;
113+
std::vector<hiprtInternalNode> internalNodes;
114+
std::vector<Aabb> primBoxes;
109115
if ( buildInput.type == hiprtPrimitiveTypeTriangleMesh )
110116
{
111-
std::vector<Aabb> primBoxes( buildInput.primitive.triangleMesh.triangleCount );
117+
primBoxes.resize( buildInput.primitive.triangleMesh.triangleCount );
112118
std::vector<uint8_t> verticesRaw(
113119
buildInput.primitive.triangleMesh.vertexCount * buildInput.primitive.triangleMesh.vertexStride );
114120
std::vector<uint8_t> trianglesRaw(
@@ -136,11 +142,11 @@ void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput )
136142
primBoxes[i].grow( v1 );
137143
primBoxes[i].grow( v2 );
138144
}
139-
BvhBuilder::build( buildInput.primitive.triangleMesh.triangleCount, primBoxes, nodes );
145+
BvhBuilder::build( buildInput.primitive.triangleMesh.triangleCount, primBoxes, internalNodes );
140146
}
141147
else if ( buildInput.type == hiprtPrimitiveTypeAABBList )
142148
{
143-
std::vector<Aabb> primBoxes( buildInput.primitive.aabbList.aabbCount );
149+
primBoxes.resize( buildInput.primitive.aabbList.aabbCount );
144150
std::vector<uint8_t> primBoxesRaw( buildInput.primitive.aabbList.aabbCount * buildInput.primitive.aabbList.aabbStride );
145151
CHECK_ORO( oroMemcpyDtoH(
146152
primBoxesRaw.data(),
@@ -153,13 +159,32 @@ void Tutorial::buildBvh( hiprtGeometryBuildInput& buildInput )
153159
primBoxes[i].m_min = make_float3( ptr[0] );
154160
primBoxes[i].m_max = make_float3( ptr[1] );
155161
}
156-
BvhBuilder::build( buildInput.primitive.aabbList.aabbCount, primBoxes, nodes );
162+
BvhBuilder::build( buildInput.primitive.aabbList.aabbCount, primBoxes, internalNodes );
157163
}
158-
CHECK_ORO(
159-
oroMalloc( reinterpret_cast<oroDeviceptr*>( &buildInput.nodeList.nodes ), nodes.size() * sizeof( hiprtBvhNode ) ) );
164+
165+
std::vector<hiprtLeafNode> leafNodes( primBoxes.size() );
166+
for ( uint32_t i = 0; i < primBoxes.size(); ++i )
167+
{
168+
leafNodes[i].primID = i;
169+
leafNodes[i].aabbMin = primBoxes[i].m_min;
170+
leafNodes[i].aabbMax = primBoxes[i].m_max;
171+
}
172+
173+
buildInput.nodeList.nodeCount = static_cast<uint32_t>( leafNodes.size() );
174+
175+
CHECK_ORO( oroMalloc(
176+
reinterpret_cast<oroDeviceptr*>( &buildInput.nodeList.leafNodes ), leafNodes.size() * sizeof( hiprtLeafNode ) ) );
177+
CHECK_ORO( oroMemcpyHtoD(
178+
reinterpret_cast<oroDeviceptr>( buildInput.nodeList.leafNodes ),
179+
leafNodes.data(),
180+
leafNodes.size() * sizeof( hiprtLeafNode ) ) );
181+
CHECK_ORO( oroMalloc(
182+
reinterpret_cast<oroDeviceptr*>( &buildInput.nodeList.internalNodes ),
183+
internalNodes.size() * sizeof( hiprtInternalNode ) ) );
160184
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() );
185+
reinterpret_cast<oroDeviceptr>( buildInput.nodeList.internalNodes ),
186+
internalNodes.data(),
187+
internalNodes.size() * sizeof( hiprtInternalNode ) ) );
163188
}
164189

165190
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: 6 additions & 11 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,13 +141,8 @@ 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;
150-
144+
nodes[nodeIndex].aabbMin = min( minLeftBox.m_min, minRightBox.m_min );
145+
nodes[nodeIndex].aabbMax = max( minLeftBox.m_max, minRightBox.m_max );
151146
if ( minIndex - begin == 1 )
152147
{
153148
nodes[nodeIndex].childIndices[0] = indices[minAxis][begin];
@@ -158,7 +153,7 @@ class BvhBuilder
158153
nodes[nodeIndex].childIndices[0] = static_cast<int>( nodes.size() );
159154
nodes[nodeIndex].childNodeTypes[0] = hiprtBvhNodeTypeInternal;
160155
queue.push( QueueEntry( nodes[nodeIndex].childIndices[0], begin, minIndex, minLeftBox ) );
161-
nodes.push_back( hiprtBvhNode() );
156+
nodes.push_back( hiprtInternalNode() );
162157
}
163158

164159
if ( end - minIndex == 1 )
@@ -171,7 +166,7 @@ class BvhBuilder
171166
nodes[nodeIndex].childIndices[1] = static_cast<int>( nodes.size() );
172167
nodes[nodeIndex].childNodeTypes[1] = hiprtBvhNodeTypeInternal;
173168
queue.push( QueueEntry( nodes[nodeIndex].childIndices[1], minIndex, end, minRightBox ) );
174-
nodes.push_back( hiprtBvhNode() );
169+
nodes.push_back( hiprtInternalNode() );
175170
}
176171
}
177172
}

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)