From 00a88cc88b7373c9f61883dc5114e323e026c738 Mon Sep 17 00:00:00 2001 From: Jacco Bikker Date: Sat, 25 Jan 2025 13:29:44 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index b2d56bf..e83169f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# dev +This is the **development branch** for tinybvh. + # tinybvh Single-header BVH construction and traversal library written as "Sane C++" (or "C with classes"). Some C++11 is used, e.g. for threading. The library has no dependencies. From c2473fbe3ed4c489088f5cc478dfa2e51681100b Mon Sep 17 00:00:00 2001 From: Jacco Bikker Date: Sat, 25 Jan 2025 18:48:12 +0100 Subject: [PATCH 2/5] Resolve issue #95. --- tiny_bvh.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tiny_bvh.h b/tiny_bvh.h index 3b87b1a..329a767 100644 --- a/tiny_bvh.h +++ b/tiny_bvh.h @@ -159,7 +159,7 @@ THE SOFTWARE. // library version #define TINY_BVH_VERSION_MAJOR 1 #define TINY_BVH_VERSION_MINOR 3 -#define TINY_BVH_VERSION_SUB 2 +#define TINY_BVH_VERSION_SUB 3 // ============================================================================ // @@ -440,8 +440,8 @@ inline bvhdbl3 operator*( double b, const bvhdbl3& a ) { return bvhdbl3( b * a.x inline bvhdbl3 operator/( double b, const bvhdbl3& a ) { return bvhdbl3( b / a.x, b / a.y, b / a.z ); } inline bvhdbl3 operator*=( bvhdbl3& a, const double b ) { return bvhdbl3( a.x * b, a.y * b, a.z * b ); } -static double tinybvh_length( const bvhdbl3& a ) { return sqrt( a.x * a.x + a.y * a.y + a.z * a.z ); } -static bvhdbl3 tinybvh_normalize( const bvhdbl3& a ) +double tinybvh_length( const bvhdbl3& a ) { return sqrt( a.x * a.x + a.y * a.y + a.z * a.z ); } +bvhdbl3 tinybvh_normalize( const bvhdbl3& a ) { double l = tinybvh_length( a ), rl = l == 0 ? 0 : (1.0 / l); return a * rl; @@ -502,6 +502,7 @@ typedef bvhvec4 SIMDVEC4; #endif // error handling +#define FATAL_ERROR(s) FATAL_ERROR_IF(1,s) #define FATAL_ERROR_IF(c,s) if (c) { fprintf( stderr, \ "Fatal error in tiny_bvh.h, line %i:\n%s\n", __LINE__, s ); exit( 1 ); } @@ -5560,6 +5561,30 @@ bool BVH4_CPU::IsOccluded( const Ray& ray ) const #endif // BVH_USENEON +#if !defined( BVH_USEAVX ) && !defined( BVH_USENEON ) + +int32_t BVH_SoA::Intersect( Ray& ray ) const +{ + FATAL_ERROR( "BVH_SoA::Intersect: Requires AVX or NEON." ); +} + +bool BVH_SoA::IsOccluded( const Ray& ray ) const +{ + FATAL_ERROR( "BVH_SoA::IsOccluded: Requires AVX or NEON." ); +} + +int32_t BVH4_CPU::Intersect( Ray& ray ) const +{ + FATAL_ERROR( "BVH4_CPU::Intersect: Requires AVX or NEON." ); +} + +bool BVH4_CPU::IsOccluded( const Ray& ray ) const +{ + FATAL_ERROR( "BVH4_CPU::IsOccluded: Requires AVX or NEON." ); +} + +#endif + // ============================================================================ // // D O U B L E P R E C I S I O N S U P P O R T From 268d8e59bd937b91e5d87aadf24c98ff8885fd6c Mon Sep 17 00:00:00 2001 From: Jacco Bikker Date: Sat, 25 Jan 2025 18:48:29 +0100 Subject: [PATCH 3/5] Version bump for bug fix. --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index e83169f..67c2810 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,3 @@ -# dev -This is the **development branch** for tinybvh. - # tinybvh Single-header BVH construction and traversal library written as "Sane C++" (or "C with classes"). Some C++11 is used, e.g. for threading. The library has no dependencies. @@ -72,7 +69,7 @@ The **performance measurement tool** can be compiled with: ````g++ -std=c++20 -mavx -Ofast tiny_bvh_speedtest.cpp -o tiny_bvh_speedtest```` -# Version 1.3.2 +# Version 1.3.3 Version 1.3.0 changed the names of vector math functions, which are now prepended with ````tinybvh_````, e.g. ````tinybvh_cross````, ````tinybvh_normalize````. This avoids name clashes in applications that override the vector types with their own. Basically tinybvh evades these so you don't have to. From c094138552fffe6df88315cc2d50cf1507bf1ac4 Mon Sep 17 00:00:00 2001 From: Jacco Bikker Date: Sat, 25 Jan 2025 18:48:51 +0100 Subject: [PATCH 4/5] Minor cleanup. --- tiny_bvh_anim.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tiny_bvh_anim.cpp b/tiny_bvh_anim.cpp index 662cd8f..1f2fd2e 100644 --- a/tiny_bvh_anim.cpp +++ b/tiny_bvh_anim.cpp @@ -8,6 +8,7 @@ #define INSTCOUNT (GRIDSIZE * GRIDSIZE * GRIDSIZE) #define TINYBVH_IMPLEMENTATION +#define TINYBVH_NO_SIMD #define INST_IDX_BITS 8 // override default; space for 256 instances. #include "tiny_bvh.h" #include @@ -17,7 +18,7 @@ using namespace tinybvh; struct Sphere { bvhvec3 pos; float r; }; -BVH4_CPU sponza; +BVH sponza; BVH obj; // custom geometry BVH must be regular BVH layout. BVH tlas; // TLAS must for now be in regular BVH layout. BVHBase* bvhList[] = { &sponza, &obj }; @@ -148,7 +149,7 @@ void TraceWorkerThread( uint32_t* buf, int threadIdx ) // setup primary ray const float u = (float)pixel_x / SCRWIDTH, v = (float)pixel_y / SCRHEIGHT; const bvhvec3 D = tinybvh_normalize( p1 + u * (p2 - p1) + v * (p3 - p1) - eye ); - Ray ray( eye, D, 1e30f ); + Ray ray( eye, D ); tlas.Intersect( ray ); if (ray.hit.t < 10000) { From 957a75e5e506fd96ab9d890f9866dba2af2da4b1 Mon Sep 17 00:00:00 2001 From: Jacco Bikker Date: Sat, 25 Jan 2025 18:48:58 +0100 Subject: [PATCH 5/5] Minor cleanup. --- tiny_bvh_collide.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tiny_bvh_collide.cpp b/tiny_bvh_collide.cpp index 8673751..7764f26 100644 --- a/tiny_bvh_collide.cpp +++ b/tiny_bvh_collide.cpp @@ -104,7 +104,6 @@ void TraceWorkerThread( uint32_t* buf, int threadIdx ) while (tile < tiles) { const int tx = tile % xtiles, ty = tile / xtiles; - unsigned seed = (tile + 17) * 171717 + frameIdx * 1023; const bvhvec3 L = tinybvh_normalize( bvhvec3( 1, 2, 3 ) ); for (int y = 0; y < TILESIZE; y++) for (int x = 0; x < TILESIZE; x++) { @@ -117,7 +116,6 @@ void TraceWorkerThread( uint32_t* buf, int threadIdx ) tlas.Intersect( ray ); if (ray.hit.t < 10000) { - uint32_t pixel_x = tx * 4 + x, pixel_y = ty * 4 + y; #if INST_IDX_BITS == 32 // instance and primitive index are stored in separate fields uint32_t primIdx = ray.hit.prim; @@ -158,7 +156,7 @@ void TraceWorkerThread( uint32_t* buf, int threadIdx ) void Tick( float delta_time_s, fenster& f, uint32_t* buf ) { // handle user input and update camera - bool moved = UpdateCamera( delta_time_s, f ) || frameIdx++ == 0; + UpdateCamera( delta_time_s, f ); // clear the screen with a debug-friendly color for (int i = 0; i < SCRWIDTH * SCRHEIGHT; i++) buf[i] = 0xaaaaff;