SIMD hull collision (#93)

SIMD based hull collision inspired by example code from @cairnc in #54 

<img width="1676" height="1332" alt="image"
src="https://github.com/user-attachments/assets/58b137bd-bf7b-4c99-863c-64341b973a3d"
/>

- Fixed #78
- Fixed #85 and fixed CI to error on UB.
- Updated benchmarks
- Added AMD scalar benchmarks
- Added Neon benchmarks
- More determinism unit tests
- Sample leak detection
- Added b3Body_AllowFastRotation
- Added b3Body_IsFastRotationAllowed
- Bumped b3HullData version
- Bumped b3CompoundData version
This commit is contained in:
Erin Catto 2026-07-18 22:43:03 -07:00 • committed by GitHub
commit c37cfe4cd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
84 changed files with 3898 additions and 1151 deletions

View file

@ -1,6 +1,16 @@
// SPDX-FileCopyrightText: 2025 Erin Catto
// SPDX-License-Identifier: MIT
#if defined( _MSC_VER )
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#define _CRTDBG_MAP_ALLOC
// stdlib before crtdbg so the malloc->_malloc_dbg remap lands after the real prototype
#include <stdlib.h>
#include <crtdbg.h>
#endif
#include "gfx/debug_adapter.h"
#include "gfx/keycodes.h"
#include "gfx/renderer.h"
@ -18,6 +28,12 @@
#include <string.h>
#include <thread>
#ifdef TRACY_ENABLE
#include <tracy/Tracy.hpp>
#else
#define FrameMark
#endif
#if defined( _WIN32 )
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
@ -32,6 +48,7 @@ static SampleContext s_context;
static int s_frame = 0;
static int s_frameLimit = -1;
static int s_sampleOverride = -1;
static int s_exitCode = 0;
static int CompareSamples( const void* a, const void* b )
{
@ -75,6 +92,10 @@ static void OnDrawUI( void )
static void OnInit( void )
{
#ifdef TRACY_ENABLE
tracy::StartupProfiler();
#endif
#if defined( _WIN32 )
timeBeginPeriod( 1 );
#endif
@ -307,12 +328,17 @@ static void OnEvent( const sapp_event* e )
}
}
// Pace the loop to 60 Hz so the fixed 1/60 physics step plays at real time on any
// display. Sleep the bulk of the idle time, then spin the last bit since sleep wakes
// are only accurate to about a millisecond.
// This limits the render rate to the simulation rate. Physics debugging
// ergonomics require render frames and simulation frames to be one to one.
// I don't recommend this setup for games, where a decoupled render
// and simulation rate is desirable.
static void LimitFrameRate( uint64_t frameStart )
{
const float targetMs = 1000.0f / 60.0f;
// By limiting to the simulation hertz, this allows me to run the simulation
// at 240Hz and render at that rate when using a 240Hz monitor. It also allows
// me to run a 10Hz simulation in at the wall clock rate.
float hertz = b3ClampFloat(s_context.hertz, 5.0f, 1000.0f);
const float targetMs = 1000.0f / hertz;
const float spinMs = 2.0f;
int sleepMs = (int)( targetMs - spinMs - b3GetMilliseconds( frameStart ) );
@ -424,6 +450,9 @@ static void OnFrame( void )
sg_commit();
++s_frame;
// For the Tracy profiler
FrameMark;
if ( s_frameLimit < 0 )
{
LimitFrameRate( frameStart );
@ -447,7 +476,13 @@ static void OnCleanup( void )
timeEndPeriod( 1 );
#endif
exit( errors == 0 ? 0 : 1 );
#ifdef TRACY_ENABLE
tracy::ShutdownProfiler();
#endif
// Return instead of exit so sokol frees its own window and context. main
// dumps CRT leaks once sapp_run returns, past that teardown.
s_exitCode = errors == 0 ? 0 : 1;
}
static void OnAppLog( const char* tag, uint32_t logLevel, uint32_t logItemId, const char* message, uint32_t lineNumber,
@ -469,7 +504,7 @@ static void OnAppLog( const char* tag, uint32_t logLevel, uint32_t logItemId, co
}
}
sapp_desc sokol_main( int argc, char** argv )
static sapp_desc BuildAppDesc( int argc, char** argv )
{
for ( int i = 1; i < argc; ++i )
{
@ -528,3 +563,23 @@ sapp_desc sokol_main( int argc, char** argv )
return desc;
}
// We own main (SOKOL_NO_ENTRY) so the leak dump can run after sapp_run returns,
// once sokol has torn down its window and context. On Windows sapp_run returns
// after that teardown; on macOS it may not return, so the dump is Windows only.
int main( int argc, char** argv )
{
#if defined( _MSC_VER )
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
#endif
sapp_desc desc = BuildAppDesc( argc, argv );
sapp_run( &desc );
#if defined( _MSC_VER )
_CrtDumpMemoryLeaks();
#endif
return s_exitCode;
}