floooh / sokol-tools

Command line tools for use with sokol headers
MIT License
219 stars 54 forks source link

Unoptimized/Debug builds with dead code elimination disabled? #122

Open jakubtomsu opened 5 months ago

jakubtomsu commented 5 months ago

Currently the sokol-shdc compiler aggressively eliminates dead code, which is a bit annoying when iterating on shaders. That's because it also removes all of the uniform and texture slots from the generated headers.

I looked into the source but unfortunately couldn't find a way to disable it in the backend. Maybe there is a way to somehow still generate the binding slots correctly even if they compile out..?

floooh commented 5 months ago

That's a surprisingly tricky topic because the removal can happen in different stages (starting at the initial GLSL to SPIRV compilation, but even as late as in the actual sokol application - for instance GL driver GLSL compilers are free to remove unused bindings as well).

In the past there was also a situation where unused vertex attributes were dropped by the SPIRVTools optimizer passes, but that had been fixed in this commit:

https://github.com/floooh/sokol-tools/commit/16492a01b47657e62088df5a9c8b5b5fd47b0e25

The optionally generated reflection-info functions (only in the C code generation so far) are also a (somewhat awkward) way to deal with the problem, but that's not a great solution for iterating and experimenting.

Long story short, I haven't found a good solution for this. Unfortunately it's not as easy as disabling all optimizations. Unrelated to that I have thought about a command line option to disable the SPIRVTools optimizer passes completely (here: https://github.com/floooh/sokol-tools/blob/6362c8fa26013f6113b6689a40f8b19774afac46/src/shdc/spirv.cc#L119-L164), but that alone definitely won't solve the issue that unused binding declarations are removed.