2 ms·
I took a very different approach for porting my WebGPU shaders over: I have far too many shaders to port (sometimes pretty massive ones! [0]), so I used Naga [1
by Jasper_ 5y ago
I took a very different approach for porting my WebGPU shaders over: I have far too many shaders to port (sometimes pretty massive ones! [0]), so I used Naga [1] at to runtime-translate my GLSL shaders to WGSL. I had to get involved a bit upstream to fix quite a few different bugs in the implementation, but once I got it working I was really happy with the result. It's quite fast, it compiles to a pretty light-weight WebAssembly module, and it works surprisingly well.
[0] https://github.com/magcius/noclip.website/blob/e15f8045cf2622e1dc383e924ebe7ca25982ec0b/src/SourceEngine/Materials.ts#L1104-L1948 https://github.com/magcius/noclip.website/blob/e15f8045cf262...
[1] https://github.com/gfx-rs/naga/ https://github.com/gfx-rs/naga/
- wrnr 5y agoCool project, there is also someone working on making wgsl and glsl together: https://github.com/scoopr/naga-include-poc https://github.com/scoopr/naga-include-poc
- saurik 5y agoWhy do you do this translation at runtime--causing every user to have to re-execute it--instead of at compile-time? Is there some kind of per-user optimization this makes possible?
- mrec 5y agoNot GP, but shader translation depends heavily on device capabilities and the current pipeline state. In principle I think it's possible to cache a lot of this on the client, so that it only has to be run once per install (or per device fingerprint change) rather than once per execution, but I don't think that's implemented yet.