libsdl-org / SDL

Simple Directmedia Layer
https://libsdl.org
zlib License
9.41k stars 1.75k forks source link

Audio mixers could use SIMD versions #7867

Open icculus opened 1 year ago

icculus commented 1 year ago

I'd be more inclined to add SIMD versions of SDL_MixAudioFormat instead.

Originally posted by @icculus in https://github.com/libsdl-org/SDL/issues/7704#issuecomment-1546728946

The audio mixers are currently simple scalar for-loops, and would be excellent candidates for SIMD versions.

icculus commented 1 year ago

(I'm putting this in the 3.2.0 milestone, but this can slip to 3.x, as it won't need API changes.)

flibitijibibo commented 1 year ago

Since we're looking at this anyway, one possible 3.0 improvement could be adding support for matrix coefficients, expanding the single volume parameter that MixAudioFormat currently has. We have this in FAudio, and have a couple SIMD implementations as well:

https://github.com/FNA-XNA/FAudio/blob/master/src/FAudio_internal_simd.c#L1279

We only work with float though, so unless we only implemented the Generic mixers for each sample format it would probably add quite a few internal functions to keep support for even the common channel permutations...

boris-999 commented 1 year ago

if the code is already 'simple' scalar, wouldn't the compiler already be able to generate sufficient SIMD?

madebr commented 1 year ago

Intel has a compiler that can emit simd for x86/arm/neon: ISPC.

icculus commented 1 year ago

if the code is already 'simple' scalar, wouldn't the compiler already be able to generate sufficient SIMD?

Yes, but in practice it sometimes can't/won't.

We should verify this, though. If GCC/Clang/MSVC will just auto-vectorize this stuff, that's probably good enough.