Closed seivan closed 3 months ago
Maybe some time in the future, but only as offline tool similar to sokol-shdc (https://github.com/floooh/sokol-tools/blob/master/docs/sokol-shdc.md)
Adding a runtime shader compiler to sokol-gfx would add too much bloat to the library. But there's a feature request to turn sokol-shdc into a library: https://github.com/floooh/sokol-tools/issues/34 - so sokol-gfx would still take backend specific shader input, but applications could link against this library to get a runtime compilation solution. This would easily increase the binary size of an application executable by at least 10x though (from a few hundred KBytes to several MBytes).
I'm rolling around the idea in my head to switch the offline shader authoring language from GLSL to WGSL one day, if Tint is up to the task. Currently Tint is already used in sokol-shdc, but only for translating SPIRV into WGSL.
But Tint could also be used to translate WGSL into the various target shader languages, it's just unclear at the moment if Tint can support all requires targets (mainly HLSL5 and GLSL es300), because Tint has been written for WebGPU, but D3D11 and GLES3 aren't exactly 'first class' WebGPU backends.
If Tint can completely replace the combination of glslangValidator, SPIRVTools and SPIRVCross currently used in sokol-shdc, that would be a pretty big win. It's not very high on the priority list though.
and outputting specific swift shader code is a hassle
Btw: sokol-shdc has the bare_yaml
target for such situations where a target language isn't directly supported. This gives you the output shaders as files, and a reflection file in a simple YAML format (you don't need a full YAML parser to parse this file). You can then either load this data at runtime, or use your own offline tool to generate Swift code.
This has been done for Rusts wgpu project that also does cross platform rendering. Except it supports using WGSL without any modification for each platform and does so at runtime with naga. I am sure you can pre-compile at boot if necessary or even at build, but it would be nice for having it at runtime just for ease of use.
This means a single wgsl file can be used cross platform for all backends (dx11, vulkan, metal, webgl and wgpu)
This is also much better than generating outputs per language as well. I am currently trying to make sokol work with Swift and having to deal with build times and outputting specific swift shader code is a hassle. Being runtime generated and working out of the box would be a much smoother experience.