grovesNL / spirv_cross

Safe Rust wrapper around SPIRV-Cross
Apache License 2.0
87 stars 42 forks source link

Wasm32 Example #136

Closed Nazariglez closed 4 years ago

Nazariglez commented 4 years ago

Hi Joshua, I'm trying to use this crate with a cross-platform "framework" I'm developing but I wasn't able to make it work with wasm32.

Can you give me a hint or a simple example of a wasm32 project to do it? Is this supported?

Thanks

grovesNL commented 4 years ago

Hi @Nazariglez! In general you should be able to use spirv_cross as you would normally in Rust. The only difference is that we require an additional JavaScript and WebAssebly file to be loaded (which contains the C++ portion).

To understand how to do this, it might be easiest to follow the steps from in gfx quad example to see how we load and use spirv_cross in wasm in that example.

Long term I hope we'll catch up to SPIRV-Cross with the naga project in gfx which will be much easier to use from wasm32.

Nazariglez commented 4 years ago

It works like a charm!

Naga looks great thought, it will simplify a lot all this process. I don't know if you know it but kha.tech uses https://github.com/Kode/krafix as a shader compiler and it works really well, maybe we can get some ideas from there.

I think that I can close this issue, thank you so much!

grovesNL commented 4 years ago

Awesome :+1: glad it works well for you. I forgot to mention that only the GLSL compiler is supported in the wasm build at the moment (mostly so the filesize of the wasm build is smaller), but we could easily expose MSL and HLSL too if you need them.

Thanks for the link to krafix! It looks like it also uses SPIRV-Cross internally.

Nazariglez commented 4 years ago

GLSL is enough, I'm using spirv and glow (eventually I'll add WebGPU) to get running the same code in mobile, desktop and web. You work is awesome, thanks!