Skip to content

Commit a860789

Browse files
committed
Updating tutorials to 2.2
1 parent ae2c8e7 commit a860789

File tree

59 files changed

+1290
-749
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1290
-749
lines changed

tutorials/01_geom_intersection/main.cpp

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,32 +31,26 @@ class Tutorial : public TutorialBase
3131
CHECK_HIPRT( hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, ctxt ) );
3232

3333
hiprtTriangleMeshPrimitive mesh;
34-
mesh.triangleCount = 2;
35-
mesh.triangleStride = sizeof( hiprtInt3 );
36-
int triangleIndices[] = { 0, 1, 2, 3, 4, 5 };
34+
mesh.triangleCount = 1;
35+
mesh.triangleStride = sizeof( hiprtInt3 );
36+
uint32_t triangleIndices[] = { 0, 1, 2 };
3737
CHECK_ORO(
3838
oroMalloc( reinterpret_cast<oroDeviceptr*>( &mesh.triangleIndices ), mesh.triangleCount * sizeof( hiprtInt3 ) ) );
3939
CHECK_ORO( oroMemcpyHtoD(
4040
reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ),
4141
triangleIndices,
4242
mesh.triangleCount * sizeof( hiprtInt3 ) ) );
4343

44-
mesh.vertexCount = 6;
44+
mesh.vertexCount = 3;
4545
mesh.vertexStride = sizeof( hiprtFloat3 );
46-
hiprtFloat3 vertices[] = {
47-
{ 0.0f, 0.0f, 0.0f },
48-
{ 1.0f, 0.0f, 0.0f },
49-
{ 0.5f, 1.0f, 0.0f },
50-
{ 0.0f, 0.0f, 1.0f },
51-
{ 1.0f, 0.0f, 1.0f },
52-
{ 0.5f, 1.0f, 1.0f } };
46+
hiprtFloat3 vertices[] = { { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 0.5f, 1.0f, 0.0f } };
5347
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &mesh.vertices ), mesh.vertexCount * sizeof( hiprtFloat3 ) ) );
5448
CHECK_ORO( oroMemcpyHtoD(
5549
reinterpret_cast<oroDeviceptr>( mesh.vertices ), vertices, mesh.vertexCount * sizeof( hiprtFloat3 ) ) );
5650

5751
hiprtGeometryBuildInput geomInput;
5852
geomInput.type = hiprtPrimitiveTypeTriangleMesh;
59-
geomInput.triangleMesh.primitive = mesh;
53+
geomInput.primitive.triangleMesh = mesh;
6054

6155
size_t geomTempSize;
6256
hiprtDevicePtr geomTemp;
@@ -72,7 +66,7 @@ class Tutorial : public TutorialBase
7266
oroFunction func;
7367
buildTraceKernelFromBitcode( ctxt, "../common/TutorialKernels.h", "GeomIntersectionKernel", func );
7468

75-
u8* pixels;
69+
uint8_t* pixels;
7670
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &pixels ), m_res.x * m_res.y * 4 ) );
7771

7872
void* args[] = { &geom, &pixels, &m_res };

tutorials/02_scene_intersection/main.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,34 @@ class Tutorial : public TutorialBase
3131
CHECK_HIPRT( hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, ctxt ) );
3232

3333
hiprtTriangleMeshPrimitive mesh;
34-
mesh.triangleCount = 2;
35-
mesh.triangleStride = sizeof( hiprtInt3 );
36-
int triangleIndices[] = { 0, 1, 2, 3, 4, 5 };
34+
mesh.triangleCount = 2;
35+
mesh.triangleStride = sizeof( hiprtInt3 );
36+
uint32_t triangleIndices[] = { 0, 1, 2, 3, 4, 5 };
3737
CHECK_ORO(
3838
oroMalloc( reinterpret_cast<oroDeviceptr*>( &mesh.triangleIndices ), mesh.triangleCount * sizeof( hiprtInt3 ) ) );
3939
CHECK_ORO( oroMemcpyHtoD(
4040
reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ),
4141
triangleIndices,
4242
mesh.triangleCount * sizeof( hiprtInt3 ) ) );
4343

44-
mesh.vertexCount = 6;
45-
mesh.vertexStride = sizeof( hiprtFloat3 );
46-
const float s = 0.5f;
47-
const float t = 0.8f;
48-
hiprtFloat3 vertices[] = {
49-
{ s, s, 0.0f },
50-
{ s + t * s, -s * s, 0.0f },
51-
{ s - t * s, -s * s, 0.0f },
52-
{ -s, s, 0.0f },
53-
{ -s + t * s, -s * s, 0.0f },
54-
{ -s - t * s, -s * s, 0.0f } };
44+
mesh.vertexCount = 6;
45+
mesh.vertexStride = sizeof( hiprtFloat3 );
46+
constexpr float S = 0.5f;
47+
constexpr float T = 0.8f;
48+
hiprtFloat3 vertices[] = {
49+
{ S, S, 0.0f },
50+
{ S + T * S, -S * S, 0.0f },
51+
{ S - T * S, -S * S, 0.0f },
52+
{ -S, S, 0.0f },
53+
{ -S + T * S, -S * S, 0.0f },
54+
{ -S - T * S, -S * S, 0.0f } };
5555
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &mesh.vertices ), mesh.vertexCount * sizeof( hiprtFloat3 ) ) );
5656
CHECK_ORO( oroMemcpyHtoD(
5757
reinterpret_cast<oroDeviceptr>( mesh.vertices ), vertices, mesh.vertexCount * sizeof( hiprtFloat3 ) ) );
5858

5959
hiprtGeometryBuildInput geomInput;
6060
geomInput.type = hiprtPrimitiveTypeTriangleMesh;
61-
geomInput.triangleMesh.primitive = mesh;
61+
geomInput.primitive.triangleMesh = mesh;
6262

6363
size_t geomTempSize;
6464
hiprtDevicePtr geomTemp;
@@ -71,14 +71,17 @@ class Tutorial : public TutorialBase
7171
CHECK_HIPRT( hiprtCreateGeometry( ctxt, geomInput, options, geom ) );
7272
CHECK_HIPRT( hiprtBuildGeometry( ctxt, hiprtBuildOperationBuild, geomInput, options, geomTemp, 0, geom ) );
7373

74+
hiprtInstance instance;
75+
instance.type = hiprtInstanceTypeGeometry;
76+
instance.geometry = geom;
77+
7478
hiprtSceneBuildInput sceneInput;
7579
sceneInput.instanceCount = 1;
7680
sceneInput.instanceMasks = nullptr;
7781
sceneInput.instanceTransformHeaders = nullptr;
78-
hiprtDevicePtr geoms[] = { geom };
79-
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &sceneInput.instanceGeometries ), sizeof( hiprtDevicePtr ) ) );
82+
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &sceneInput.instances ), sizeof( hiprtInstance ) ) );
8083
CHECK_ORO(
81-
oroMemcpyHtoD( reinterpret_cast<oroDeviceptr>( sceneInput.instanceGeometries ), geoms, sizeof( hiprtDevicePtr ) ) );
84+
oroMemcpyHtoD( reinterpret_cast<oroDeviceptr>( sceneInput.instances ), &instance, sizeof( hiprtInstance ) ) );
8285

8386
hiprtFrameSRT frame;
8487
frame.translation = make_hiprtFloat3( 0.0f, 0.0f, 0.0f );
@@ -101,14 +104,14 @@ class Tutorial : public TutorialBase
101104
oroFunction func;
102105
buildTraceKernelFromBitcode( ctxt, "../common/TutorialKernels.h", "SceneIntersectionKernel", func );
103106

104-
u8* pixels;
107+
uint8_t* pixels;
105108
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &pixels ), m_res.x * m_res.y * 4 ) );
106109

107110
void* args[] = { &scene, &pixels, &m_res };
108111
launchKernel( func, m_res.x, m_res.y, args );
109112
writeImage( "02_scene_intersection.png", m_res.x, m_res.y, pixels );
110113

111-
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( sceneInput.instanceGeometries ) ) );
114+
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( sceneInput.instances ) ) );
112115
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( sceneInput.instanceFrames ) ) );
113116
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ) ) );
114117
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.vertices ) ) );

tutorials/03_custom_intersection/main.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ class Tutorial : public TutorialBase
2727
public:
2828
void run()
2929
{
30-
constexpr u32 SphereCount = 8 * 2;
31-
hiprtFloat4 spheres[SphereCount];
32-
for ( int i = 0; i < SphereCount / 2; i++ )
30+
constexpr uint32_t SphereCount = 8 * 2;
31+
hiprtFloat4 spheres[SphereCount];
32+
for ( uint32_t i = 0; i < SphereCount / 2; i++ )
3333
{
3434
float r = 0.1f;
3535
float t = i / (float)( SphereCount / 2 ) * 2.f * 3.1415f;
36-
spheres[i] = { sin( t ) * 0.4f, cos( t ) * 0.4f, 0.f, r };
36+
spheres[i] = { sinf( t ) * 0.4f, cosf( t ) * 0.4f, 0.f, r };
3737
}
38-
for ( int i = 0; i < SphereCount / 2; i++ )
38+
for ( uint32_t i = 0; i < SphereCount / 2; i++ )
3939
{
4040
float r = 0.1f;
4141
float t = i / (float)( SphereCount / 2 ) * 2.f * 3.1415f + 0.2f;
42-
spheres[i + SphereCount / 2] = { sin( t ) * 0.35f, cos( t ) * 0.35f, 0.4f, r };
42+
spheres[i + SphereCount / 2] = { sinf( t ) * 0.35f, cosf( t ) * 0.35f, 0.4f, r };
4343
}
4444

4545
hiprtContext ctxt;
@@ -49,7 +49,7 @@ class Tutorial : public TutorialBase
4949
list.aabbCount = SphereCount;
5050
list.aabbStride = 2 * sizeof( hiprtFloat4 );
5151
hiprtFloat4 aabbs[2 * SphereCount];
52-
for ( int i = 0; i < SphereCount; i++ )
52+
for ( uint32_t i = 0; i < SphereCount; i++ )
5353
{
5454
const hiprtFloat4& c = spheres[i];
5555
aabbs[i * 2 + 0] = { c.x - c.w, c.y - c.w, c.z - c.w, 0.0f };
@@ -61,7 +61,7 @@ class Tutorial : public TutorialBase
6161

6262
hiprtGeometryBuildInput geomInput;
6363
geomInput.type = hiprtPrimitiveTypeAABBList;
64-
geomInput.aabbList.primitive = list;
64+
geomInput.primitive.aabbList = list;
6565
geomInput.geomType = 0;
6666

6767
size_t geomTempSize;
@@ -93,7 +93,7 @@ class Tutorial : public TutorialBase
9393
buildTraceKernelFromBitcode(
9494
ctxt, "../common/TutorialKernels.h", "CustomIntersectionKernel", func, nullptr, &funcNameSets, 1, 1 );
9595

96-
u8* pixels;
96+
uint8_t* pixels;
9797
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &pixels ), m_res.x * m_res.y * 4 ) );
9898

9999
void* args[] = { &geom, &pixels, &funcTable, &m_res };

tutorials/04_compaction/main.cpp

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//
2+
// Copyright (c) 2021-2023 Advanced Micro Devices, Inc. All rights reserved.
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
//
22+
23+
#include <numeric>
24+
#include <tutorials/common/CornellBox.h>
25+
#include <tutorials/common/TutorialBase.h>
26+
27+
class Tutorial : public TutorialBase
28+
{
29+
public:
30+
void run()
31+
{
32+
hiprtContext ctxt;
33+
CHECK_HIPRT( hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, ctxt ) );
34+
35+
hiprtTriangleMeshPrimitive mesh;
36+
mesh.triangleCount = CornellBoxTriangleCount;
37+
mesh.triangleStride = sizeof( hiprtInt3 );
38+
std::array<uint32_t, 3 * CornellBoxTriangleCount> triangleIndices;
39+
std::iota( triangleIndices.begin(), triangleIndices.end(), 0 );
40+
CHECK_ORO(
41+
oroMalloc( reinterpret_cast<oroDeviceptr*>( &mesh.triangleIndices ), mesh.triangleCount * sizeof( hiprtInt3 ) ) );
42+
CHECK_ORO( oroMemcpyHtoD(
43+
reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ),
44+
triangleIndices.data(),
45+
mesh.triangleCount * sizeof( hiprtInt3 ) ) );
46+
47+
mesh.vertexCount = 3 * mesh.triangleCount;
48+
mesh.vertexStride = sizeof( hiprtFloat3 );
49+
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &mesh.vertices ), mesh.vertexCount * sizeof( hiprtFloat3 ) ) );
50+
CHECK_ORO( oroMemcpyHtoD(
51+
reinterpret_cast<oroDeviceptr>( mesh.vertices ),
52+
const_cast<hiprtFloat3*>( cornellBoxVertices.data() ),
53+
mesh.vertexCount * sizeof( hiprtFloat3 ) ) );
54+
55+
hiprtGeometryBuildInput geomInput;
56+
geomInput.type = hiprtPrimitiveTypeTriangleMesh;
57+
geomInput.primitive.triangleMesh = mesh;
58+
59+
size_t geomTempSize;
60+
hiprtDevicePtr geomTemp;
61+
hiprtBuildOptions options;
62+
options.buildFlags = hiprtBuildFlagBitPreferFastBuild;
63+
CHECK_HIPRT( hiprtGetGeometryBuildTemporaryBufferSize( ctxt, geomInput, options, geomTempSize ) );
64+
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &geomTemp ), geomTempSize ) );
65+
66+
hiprtGeometry geom;
67+
CHECK_HIPRT( hiprtCreateGeometry( ctxt, geomInput, options, geom ) );
68+
CHECK_HIPRT( hiprtBuildGeometry( ctxt, hiprtBuildOperationBuild, geomInput, options, geomTemp, 0, geom ) );
69+
CHECK_HIPRT( hiprtCompactGeometry( ctxt, 0, geom, geom ) );
70+
71+
oroFunction func;
72+
buildTraceKernelFromBitcode( ctxt, "../common/TutorialKernels.h", "CornellBoxKernel", func );
73+
74+
uint8_t* pixels;
75+
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &pixels ), m_res.x * m_res.y * 4 ) );
76+
77+
void* args[] = { &geom, &pixels, &m_res };
78+
launchKernel( func, m_res.x, m_res.y, args );
79+
writeImage( "04_compaction.png", m_res.x, m_res.y, pixels );
80+
81+
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ) ) );
82+
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.vertices ) ) );
83+
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( geomTemp ) ) );
84+
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( pixels ) ) );
85+
86+
CHECK_HIPRT( hiprtDestroyGeometry( ctxt, geom ) );
87+
CHECK_HIPRT( hiprtDestroyContext( ctxt ) );
88+
}
89+
};
90+
91+
int main( int argc, char** argv )
92+
{
93+
Tutorial tutorial;
94+
tutorial.init( 0 );
95+
tutorial.run();
96+
97+
return 0;
98+
}

tutorials/13_batch_build/premake5.lua renamed to tutorials/04_compaction/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project "13_batch_build"
1+
project "04_compaction"
22
cppdialect "C++17"
33
kind "ConsoleApp"
44
location "../build"

tutorials/04_global_stack/main.cpp renamed to tutorials/05_global_stack/main.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ class Tutorial : public TutorialBase
3232
hiprtContext ctxt;
3333
CHECK_HIPRT( hiprtCreateContext( HIPRT_API_VERSION, m_ctxtInput, ctxt ) );
3434

35-
constexpr u32 StackSize = 64u;
36-
constexpr u32 SharedStackSize = 16u;
37-
constexpr u32 BlockWidth = 8u;
38-
constexpr u32 BlockHeight = 8u;
39-
constexpr u32 BlockSize = BlockWidth * BlockHeight;
40-
std::string BlockSizeDef = "-D BLOCK_SIZE=" + std::to_string( BlockSize );
41-
std::string SharedStackSizeDef = "-D SHARED_STACK_SIZE=" + std::to_string( SharedStackSize );
35+
constexpr uint32_t StackSize = 64u;
36+
constexpr uint32_t SharedStackSize = 16u;
37+
constexpr uint32_t BlockWidth = 8u;
38+
constexpr uint32_t BlockHeight = 8u;
39+
constexpr uint32_t BlockSize = BlockWidth * BlockHeight;
40+
std::string BlockSizeDef = "-D BLOCK_SIZE=" + std::to_string( BlockSize );
41+
std::string SharedStackSizeDef = "-D SHARED_STACK_SIZE=" + std::to_string( SharedStackSize );
4242

4343
std::vector<const char*> opts;
4444
opts.push_back( BlockSizeDef.c_str() );
@@ -47,7 +47,7 @@ class Tutorial : public TutorialBase
4747
hiprtTriangleMeshPrimitive mesh;
4848
mesh.triangleCount = CornellBoxTriangleCount;
4949
mesh.triangleStride = sizeof( hiprtInt3 );
50-
std::array<int, 3 * CornellBoxTriangleCount> triangleIndices;
50+
std::array<uint32_t, 3 * CornellBoxTriangleCount> triangleIndices;
5151
std::iota( triangleIndices.begin(), triangleIndices.end(), 0 );
5252
CHECK_ORO(
5353
oroMalloc( reinterpret_cast<oroDeviceptr*>( &mesh.triangleIndices ), mesh.triangleCount * sizeof( hiprtInt3 ) ) );
@@ -66,7 +66,7 @@ class Tutorial : public TutorialBase
6666

6767
hiprtGeometryBuildInput geomInput;
6868
geomInput.type = hiprtPrimitiveTypeTriangleMesh;
69-
geomInput.triangleMesh.primitive = mesh;
69+
geomInput.primitive.triangleMesh = mesh;
7070

7171
size_t geomTempSize;
7272
hiprtDevicePtr geomTemp;
@@ -82,16 +82,17 @@ class Tutorial : public TutorialBase
8282
oroFunction func;
8383
buildTraceKernelFromBitcode( ctxt, "../common/TutorialKernels.h", "SharedStackKernel", func, &opts );
8484

85-
u8* pixels;
85+
uint8_t* pixels;
8686
CHECK_ORO( oroMalloc( reinterpret_cast<oroDeviceptr*>( &pixels ), m_res.x * m_res.y * 4 ) );
8787

88-
hiprtGlobalStackBufferInput stackBufferInput{ hiprtStackTypeGlobal, StackSize, static_cast<u32>( m_res.x * m_res.y ) };
89-
hiprtGlobalStackBuffer stackBuffer;
90-
CHECK_HIPRT( hiprtCreateGlobalStackBuffer( ctxt, stackBufferInput, &stackBuffer ) );
88+
hiprtGlobalStackBufferInput stackBufferInput{
89+
hiprtStackTypeGlobal, hiprtStackEntryTypeInteger, StackSize, static_cast<uint32_t>( m_res.x * m_res.y ) };
90+
hiprtGlobalStackBuffer stackBuffer;
91+
CHECK_HIPRT( hiprtCreateGlobalStackBuffer( ctxt, stackBufferInput, stackBuffer ) );
9192

9293
void* args[] = { &geom, &pixels, &m_res, &stackBuffer };
9394
launchKernel( func, m_res.x, m_res.y, BlockWidth, BlockHeight, args );
94-
writeImage( "04_global_stack.png", m_res.x, m_res.y, pixels );
95+
writeImage( "05_global_stack.png", m_res.x, m_res.y, pixels );
9596

9697
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.triangleIndices ) ) );
9798
CHECK_ORO( oroFree( reinterpret_cast<oroDeviceptr>( mesh.vertices ) ) );

tutorials/04_global_stack/premake5.lua renamed to tutorials/05_global_stack/premake5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
project "04_global_stack"
1+
project "05_global_stack"
22
cppdialect "C++17"
33
kind "ConsoleApp"
44
location "../build"

0 commit comments

Comments
 (0)