From 5eb92ed059d9ff4e5e689acd1e9431ac85c0d4b8 Mon Sep 17 00:00:00 2001 From: Jacco Bikker Date: Sun, 10 Nov 2024 11:32:54 +0100 Subject: [PATCH] Remove NanoRT from comparisons. --- tiny_bvh_fenster.cpp | 50 ++++++---------------------------- tiny_bvh_speedtest.cpp | 62 ------------------------------------------ 2 files changed, 8 insertions(+), 104 deletions(-) diff --git a/tiny_bvh_fenster.cpp b/tiny_bvh_fenster.cpp index a5f49c1..56fc5b1 100644 --- a/tiny_bvh_fenster.cpp +++ b/tiny_bvh_fenster.cpp @@ -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 @@ -9,12 +8,7 @@ using namespace tinybvh; -#if defined(USE_NANORT) -#include "external/nanort.h" -static nanort::BVHAccel 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 ) @@ -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 triangle_mesh( nanort_verts, nanort_faces, sizeof( float ) * 3 ); - nanort::TriangleSAHPred triangle_pred( nanort_verts, nanort_faces, sizeof( float ) * 3 ); - nanort::BVHBuildOptions 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 ); @@ -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 } @@ -148,21 +132,7 @@ void Tick( uint32_t* buf ) } // trace primary rays -#if defined(USE_NANORT) - nanort::Ray ray; - nanort::BVHTraceOptions trace_options; // optional - nanort::TriangleIntersector 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 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++) { @@ -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 ); -} +} \ No newline at end of file diff --git a/tiny_bvh_speedtest.cpp b/tiny_bvh_speedtest.cpp index eede4e4..b8903e0 100644 --- a/tiny_bvh_speedtest.cpp +++ b/tiny_bvh_speedtest.cpp @@ -18,7 +18,6 @@ // 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 @@ -26,7 +25,6 @@ #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. @@ -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 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; @@ -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 triangle_mesh( nanort_verts, nanort_faces, sizeof( float ) * 3 ); - nanort::TriangleSAHPred triangle_pred( nanort_verts, nanort_faces, sizeof( float ) * 3 ); - nanort::BVHBuildOptions 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 @@ -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 ray; - nanort::BVHTraceOptions trace_options; // library default options - nanort::TriangleIntersector 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 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