verpeteren / rust-simd-noise

SIMD noise library for Rust
https://crates.io/crates/simdnoise
250 stars 20 forks source link

WebAssembly status? #12

Open rektide opened 4 years ago

rektide commented 4 years ago

Hi there hello thanks for the wonderful wonderful library.

What's the current status of using rust-simd-noise in WebAssembly? What are the main opportunities for the future? Are there any easy wins that a newcomer to this library might try to crack out?

jackmott commented 4 years ago

No idea on web assembly. I see this: https://github.com/WebAssembly/simd/issues/31 If you want to figure out if it is possible and make rust-simd-noise work with it that would be cool

rektide commented 4 years ago

Thanks for the fast reply. I'm not really sure how this works myself. Some additional potentially useful points of info that I've gathered:

I do note that Rust already has a std::arch::wasm32, and that it has a pretty extensive list of simd operations & one struct, a v128. I tried to get a better feeling for whether your/jackmott's underlying simdeez library was using similar std::arch::x86_64 &c crates to power itself, or whether it uses some other technique. I didn't see any __builtin_[...] usage, which seems to be the focus of that open webassembly/simd#31 ticket. I think I'm starting to see some of how these x86_64 instructions are used,... barely.

Also noted, browsers & LLVM support for wasm simd is looking fairly good.

jackmott commented 4 years ago

Aha, so yes my simdeez library does use std::arch::x86_64, so I think the way forward is to add a wasm32.rs file here: https://github.com/jackmott/simdeez/tree/master/src and fill in the implementation for all of the SIMD trait functions. Then, update the macros/attributes such that when you do a wasm build, it builds only the wasm version of everything. When that is done, SIMD Noise should then automatically work with WASM (or nearly so)

If you need quick primer on SIMD in Rust I've got a video: https://www.youtube.com/watch?v=4Gs_CA_vm3o&t=1113s

I may actually start filling out the wasm32 stuff in a branch of simdeez tonight. some of it will be easy, for sure a few functions will be harder to figure out how to best do wasm32 equivalents, and making sure everything builds properly with wasm builds will take some time since I'm totally unfamiliar with that universe.

jackmott commented 4 years ago

Allright I've started a SIMDeez wasm branch, part of the work will be pretty mechanical, going through every function in https://github.com/jackmott/simdeez/blob/wasm/src/wasm32.rs and replacing the sse2 intrinsic with the wasm intrinsic, or some combination thereof to get the same result. I did the first one (for absolute value) already. Then I will need to work out how to set compile time cfg stuff appropriately, might need to refactor some things to make that less ridiculous.

if you want to contribute on this create an issue over in the simdeez repo and we can chat.

lukabavdaz commented 3 years ago

I'm interested in running rust-simd-noise on wasm as well. Most likely I won't have time in the near future to implement the wasm intrinsic myself (never worked with simd before). Is there a way to run the noise algorithms without simd on wasm?

EDIT: The most recent version of the library compiles and works well on wasm (using nightly rust). It seems the commit that makes scalar the default for wasm (23c690578a2ce2bc5f9d6eb7faf730ea909baa47) is not included on crates.io yet.