Skip to content

Commit

Permalink
Remove NanoRT from comparisons.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbikker committed Nov 10, 2024
1 parent 6e58315 commit 5eb92ed
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 104 deletions.
50 changes: 8 additions & 42 deletions tiny_bvh_fenster.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "external/fenster.h" // https://github.com/zserge/fenster

// #define USE_NANORT // enable to verify correct implementation
// #define USE_EMBREE // enable to verify correct implementation, win64 only for now.
// #define LOADSPONZA

Expand All @@ -9,12 +8,7 @@

using namespace tinybvh;

#if defined(USE_NANORT)
#include "external/nanort.h"
static nanort::BVHAccel<float> accel;
static float* nanort_verts = 0;
static unsigned int* nanort_faces = 0;
#elif defined(USE_EMBREE)
#if defined(USE_EMBREE)
#include "embree4/rtcore.h"
static RTCScene embreeScene;
void embreeError( void* userPtr, enum RTCError error, const char* str )
Expand Down Expand Up @@ -69,21 +63,7 @@ void Init()
sphere_flake( 0, 0, 0, 1.5f );
#endif

#if defined USE_NANORT

// convert data to correct format for NanoRT and build a BVH
// https://github.com/lighttransport/nanort
nanort_verts = new float[verts * 3];
nanort_faces = new unsigned int[verts];
for (int i = 0; i < verts; i++)
nanort_verts[i * 3 + 0] = triangles[i].x, nanort_verts[i * 3 + 1] = triangles[i].y,
nanort_verts[i * 3 + 2] = triangles[i].z, nanort_faces[i] = i; // Note: not using shared vertices.
nanort::TriangleMesh<float> triangle_mesh( nanort_verts, nanort_faces, sizeof( float ) * 3 );
nanort::TriangleSAHPred<float> triangle_pred( nanort_verts, nanort_faces, sizeof( float ) * 3 );
nanort::BVHBuildOptions<float> build_options; // BVH build option(optional)
accel.Build( verts / 3, triangle_mesh, triangle_pred, build_options );

#elif defined USE_EMBREE
#if defined USE_EMBREE

RTCDevice embreeDevice = rtcNewDevice( NULL );
rtcSetDeviceErrorFunction( embreeDevice, embreeError, NULL );
Expand All @@ -110,6 +90,10 @@ void Init()
bvh.Build( triangles, verts / 3 );
#endif

// testing BVH4, BVH8
bvh.Convert( BVH::WALD_32BYTE, BVH::BASIC_BVH4 );
bvh.Convert( BVH::WALD_32BYTE, BVH::BASIC_BVH8 );

#endif

}
Expand Down Expand Up @@ -148,21 +132,7 @@ void Tick( uint32_t* buf )
}

// trace primary rays
#if defined(USE_NANORT)
nanort::Ray<float> ray;
nanort::BVHTraceOptions trace_options; // optional
nanort::TriangleIntersector<float> triangle_intersector( nanort_verts, nanort_faces, sizeof( float ) * 3 );
for (int i = 0; i < N; i += 16)
{
ray.org[0] = rays[i].O.x, ray.org[1] = rays[i].O.y, ray.org[2] = rays[i].O.z;
ray.dir[0] = rays[i].D.x, ray.dir[1] = rays[i].D.y, ray.dir[2] = rays[i].D.z;
ray.min_t = 0, ray.max_t = rays[i].hit.t;
nanort::TriangleIntersection<float> isect;
if (accel.Traverse( ray, triangle_intersector, &isect, trace_options ))
rays[i].hit.t = isect.t, rays[i].hit.prim = isect.prim_id,
rays[i].hit.u = isect.u, rays[i].hit.v = isect.v;
}
#elif defined(USE_EMBREE)
#if defined(USE_EMBREE)
struct RTCRayHit rayhit;
for (int i = 0; i < N; i++)
{
Expand Down Expand Up @@ -195,13 +165,9 @@ void Tick( uint32_t* buf )
bvhvec3 N = normalize( cross( v1 - v0, v2 - v0 ) );
avg += fabs( dot( N, normalize( bvhvec3( 1, 2, 3 ) ) ) );
}
#if defined USE_NANORT
int c = (int)(255.9f * avg); // we trace only every 16th ray with NanoRT
#else
int c = (int)(15.9f * avg);
#endif
buf[pixel_x + pixel_y * SCRWIDTH] = c + (c << 8) + (c << 16);
}
}
ALIGNED_FREE( rays );
}
}
62 changes: 0 additions & 62 deletions tiny_bvh_speedtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
// tests to perform
#define BUILD_REFERENCE
#define BUILD_AVX
// #define NANORT_BUILD // disabled by default to avoid warnings.
#define TRAVERSE_2WAY_ST
#define TRAVERSE_ALT2WAY_ST
#define TRAVERSE_SOA2WAY_ST
#define TRAVERSE_2WAY_MT
#define TRAVERSE_2WAY_MT_PACKET
#define TRAVERSE_2WAY_MT_DIVERGENT
#define TRAVERSE_OPTIMIZED_ST
// #define NANORT_TRAVERSE
// #define EMBREE_BUILD // win64-only for now.
// #define EMBREE_TRAVERSE // win64-only for now.

Expand All @@ -36,14 +34,6 @@ bvhvec4 triangles[259 /* level 3 */ * 6 * 2 * 49 * 3]{};
int verts = 0;
BVH bvh;

#ifdef NANORT_BUILD
using namespace std; // ugly, sorry
#include "external/nanort.h"
static nanort::BVHAccel<float> accel;
static float* nanort_verts = 0;
static unsigned int* nanort_faces = 0;
#endif

#if defined EMBREE_BUILD || defined EMBREE_TRAVERSE
#include "embree4/rtcore.h"
static RTCScene embreeScene;
Expand Down Expand Up @@ -181,32 +171,6 @@ int main()
#endif
#endif

#ifdef NANORT_BUILD

// convert data to correct format for NanoRT and build a BVH
// https://github.com/lighttransport/nanort
nanort_verts = new float[verts * 3];
nanort_faces = new unsigned int[verts];
for (int i = 0; i < verts; i++)
nanort_verts[i * 3 + 0] = triangles[i].x,
nanort_verts[i * 3 + 1] = triangles[i].y,
nanort_verts[i * 3 + 2] = triangles[i].z,
nanort_faces[i] = i; // Note: not using shared vertices.
nanort::TriangleMesh<float> triangle_mesh( nanort_verts, nanort_faces, sizeof( float ) * 3 );
nanort::TriangleSAHPred<float> triangle_pred( nanort_verts, nanort_faces, sizeof( float ) * 3 );
nanort::BVHBuildOptions<float> build_options; // BVH build option(optional)
// measure single-core nanort bvh construction time - default settings
printf( "- NanoRT builder: " );
t.reset();
for (int pass = 0; pass < 3; pass++)
accel.Build( verts / 3, triangle_mesh, triangle_pred, build_options );
float nanoBuildTime = t.elapsed() / 3.0f;
printf( "%7.2fms for %7i triangles ", nanoBuildTime * 1000.0f, verts / 3 );
nanort::BVHBuildStatistics stats = accel.GetStatistics();
printf( "- %6d nodes\n", stats.num_leaf_nodes );

#endif

#if defined EMBREE_BUILD || defined EMBREE_TRAVERSE

// convert data to correct format for Embree and build a BVH
Expand Down Expand Up @@ -401,32 +365,6 @@ int main()

#endif

#if defined NANORT_TRAVERSE && defined NANORT_BUILD

// trace every 16th ray using NanoRT to estimate average performance
printf( "- CPU, coherent, NanoRT BVH, NanoRT ST: " );
nanort::Ray<float> ray;
nanort::BVHTraceOptions trace_options; // library default options
nanort::TriangleIntersector<float> triangle_intersector( nanort_verts, nanort_faces, sizeof( float ) * 3 );
t.reset();
for (int i = 0; i < N; i += 16)
{
ray.org[0] = rays[i].O.x, ray.org[1] = rays[i].O.y, ray.org[2] = rays[i].O.z;
ray.dir[0] = rays[i].D.x, ray.dir[1] = rays[i].D.y, ray.dir[2] = rays[i].D.z;
ray.min_t = 0, ray.max_t = rays[i].hit.t;
nanort::TriangleIntersection<float> isect;
bool hit = accel.Traverse( ray, triangle_intersector, &isect, trace_options );
if (hit)
rays[i].hit.t = isect.t,
rays[i].hit.u = isect.u, rays[i].hit.v = isect.v,
rays[i].hit.prim = isect.prim_id;
}
float traceTimeNano = t.elapsed();
float krays = ((float)N / 16.0f) / traceTimeNano;
printf( "%6.1fms for %6.2fM rays => %6.2fKRay/s\n", traceTimeNano * 1000, (float)N * 1e-6f / 16.0f, krays * 1e-3f );

#endif

#ifdef TRAVERSE_2WAY_MT_DIVERGENT

// shuffle rays for the next experiment - TODO: replace by random bounce
Expand Down

0 comments on commit 5eb92ed

Please sign in to comment.