floooh / sokol-tools

Command line tools for use with sokol headers
MIT License
229 stars 57 forks source link

modf unavailable on WGSL #112

Open Duckonaut opened 11 months ago

Duckonaut commented 11 months ago

When compiling a GLSL shader to WGSL, if the shader is using the modf function, the error unhandled GLSL.std.450 instruction 35 is thrown.

As far as I understand, this is because the modf in GLSL gets compiled to the SPIR-V instruction Modf, (which apparently is deprecated? https://registry.khronos.org/SPIR-V/specs/unified1/GLSL.std.450.html) and is an instruction that returns a single value, while the modf in WGSL returns the fractional and whole parts (https://www.w3.org/TR/WGSL/#modf-builtin) which I would assume is the ModfStruct instruction in SPIR-V.

I don't know if this is on sokol-shdc to handle, or an odd incompatibility with the SPIR-V tools, because I'd imagine it isn't impossible to just use that struct-returning function on wgsl and add a .fract .

Attached is the shader that causes trouble.

modf.txt