Written in C, powered by Vulkan and AVX (or SSE), shown on screen with raylib.
(videos below are quite heavily compressed)
example-1.mp4
example-2.mp4
- C compiler:
- C99 standard;
- unless SIMD is disabled through build options:
- AVX or SSE intrinsics (
immintrin.h
andxmmintrin.h
respectively); - one of:
aligned_alloc
(C11 standard);_aligned_malloc
(Windows);posix_memalign
(POSIX)
- AVX or SSE intrinsics (
- (optional) OpenMP.
- Vulkan SDK, including
glslc
and validation layers. Only Vulkan 1.0 features are used. - CMake version 3.20 or later.
If you don't have raylib installed on your system, it will be built with this project. For more information on building raylib please refer to https://github.com/raysan5/raylib/tree/4.2.0#build-and-installation.
- Linux:
- GCC 12.1;
- Clang 15;
- TCC 0.9:
- raylib is provided externally;
SIMD_SET
isnone
.
- Windows:
- MinGW-w64 10.
Target nbody-bench
uses Linux-only monotonic clock and therefore is not available on other platforms.
git clone --recurse-submodules https://github.com/Urist-McDeveloper/nbody.git
cd nbody
Then build like any other CMake project. Example on Linux:
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make
SIMD_SET
(defaultAVX
) -- which SIMD instruction set to use; possible values:AVX
,SSE
ornone
.
Base controls:
Q
orESC
to quitSPACE
to pause/unpause
Camera controls:
WASD
to move- Press middle mouse button to drag the screen
- Scroll mouse wheel to zoom
Simulation controls:
TAB
to switch between CPU and GPU simulationLEFT
to decrease simulation speed (fewer updates per second)RIGHT
to increase simulation speed (more updates per second)UP
to increase simulation step (less accurate, simulation speeds up)DOWN
to decrease simulation step (more accurate, simulation slows down)
By changing some macros:
WINDOW_WIDTH
andWINDOW_HEIGHT
(src/main.c) -- self explanatory;PARTICLE_COUNT
(src/main.c) -- you guessed it, particle count;- The entirety of include/galaxy.h
- Select optimal VkPhysicalDevice, not the first one in the list
- Write Vulkan renderer so that particle data never has to leave GPU
- Allow setting simulation parameters through command line arguments
- Write tests that actually test something
Done:
- Make GPU simulation respect simulation step change
- Use specialization constants to make sure CPU and GPU simulations always have the same parameters
- Make GPU buffers device-local for performance improvements
- Allow performing multiple updates in a single UpdateWorld_GPU call by chaining pipeline dispatches
- Use AVX for CPU simulation
- Add CMake option to disable AVX and fall back to SSE
- A moving camera would be nice