I have a bunch of *.vert / *.frag files in asset/shaders
dir = assets/shaders/
for i in *.vert *.frag; do glslc $i -o $i.spv; done
This compiles the GLSL shaders into SpirV via shaderc
- Question now is: how do I load these into wgpu::ShaderSource::SpirV ? ShaderSource in wgpu - Rust
- Why don't you use ShaderSource::GLSL ?
I am trying to build things that runs in wasm, and do not want to bundle shaderc.
- Why not write in Wgsl directly ?
Porting existing codebase.
They're just binary files, you should be able to load them as bytes either at runtime if you're bundling or loading the files somehow, or at compile time if you want to include the shaders in the executable.
The docs page you linked to includes links to items that do those two things.
Sorry, I'm not seeing it. Where? Is it just include bytes + convert u8 to u32, or is there some header / format involved ?
The library should handle parsing the file, you just need to load it from the filesystem
And this one does it at compile time
I'm familiar with webgl2, but not wgpu.
I stumbled across Horrors of SPIR-V -- is using spirv a bad decision ?
choice 1: glsl -> (shaderc) -> spirv -> load spirv
choice 2: glsl -> naga -> wgsl -> load wgsl
I am currently going with choice 1; am I better off going with choice 2 ?
I don't think using SPIR-V as an intermediary format is terrible. If it was a huge problem wgpu wouldn't support it.
That being said I'm not particularly familiar with the nitty gritty details so I could be wrong.
The good news is you can always just compile to something else from your original sources so I don't think it's a huge deal either way
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.