rust-simd-noise
Super fast SIMD noise library for Rust. Currently in beta. PRs welcome!
Features
- SSE2, SSE41, and AVX2 instruction sets, along with non SIMD fallback
- AVX2 version also leverages FMA3
- Runtime detection picks the best available instruction set
- Simplex noise, fractal brownian motion, and turbulence
- 2d and 3d
Benchmarks
Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz Single Threaded
2D 1000x1000 FBM Noise, 3 Octaves
- scalar_2d ... bench: 74,207,703 ns/iter (+/- 2,184,952)
- sse2_2d ... bench: 23,863,725 ns/iter (+/- 746,331)
- sse41_2d ... bench: 22,440,765 ns/iter (+/- 995,336)
- avx2_2d ... bench: 12,022,253 ns/iter (+/- 508,793)
3D 100x100x100 FBM Noise, 3 Octaves
- scalar_3d ... bench: 102,543,499 ns/iter (+/- 3,310,472)
- sse2_3d ... bench: 39,991,825 ns/iter (+/- 1,043,332)
- sse41_3d ... bench: 38,852,436 ns/iter (+/- 1,350,831)
- avx2_3d ... bench: 23,231,237 ns/iter (+/- 777,420)
Todo
- AVX512 support
- ARM NEON support
- Voroni, Cell, and other noise types
Usage Notes
By default the Rust compiler will not target AVX2 and SSE41 instructions even if your machine supports them, you have to specify the
target-cpu
in RUSTFLAGS when building your project. For example you can add this to your .cargo/config file
[build]
rustflags = ["-C","target-cpu=native"]
Get a block of noise with runtime SIMD detection
The library will, at runtime, pick the fastest available options between SSE2, SSE41, and AVX2
use *;
// A struct to set up noise parameters
let fractal_settings = FractalSettings ;
// Get a block of 2d 800x600 noise, with no scaling of resulting values
// min and max values are returned so you can apply your own scaling
let = get_2d_noise;
// Get a block of 200x200x200 3d noise
let = get_3d_noise;
// Get a block of noise scaled between -1 and 1
let an_f32_vec = get_2d_scaled_noise;
Call noise functions directly
Sometimes you need something other than a block, like the points on the surface of a sphere. Sometimes you may want to use SSE41 even with AVX2 is available
// get a block of 100x100 sse41 noise, skip runtime detection
let = get_2d_noise;
// send your own SIMD x,y values to the noise functions directly
unsafe