1
\$\begingroup\$

I've tried to find a reputable optimizing compiler for GLSL that takes source shaders, performs what optimizations it can statically assume, and outputs a minified GLSL file with optimizations, stripped local variable names, and unnecessary content like comments/extra whitespace.

The goal is to transpile GLSL into a portable, obfuscated source file that has been optimized enough so that local device compilers can optimize the shaders at game startup while still maintaining simple and readable GLSL for development.

I'm searching for a solution in my development pipeline in lieu of HLSL's precompiled intermediate representation or Vulkan's SPIR-V intermediate representation. Am I wrong in my assumptions about shipping shaders for OpenGL, is there a best practice for optimizing and shipping shaders with a release build?

\$\endgroup\$
2
\$\begingroup\$

Unity's ArasP has written an optimizer that could possibly do what you need: https://github.com/aras-p/glsl-optimizer

You could also save the driver's compiled shader binary using OpenGL extension GL_ARB_get_program_binary on the first run and use it on subsequent runs to reduce loading hitches. The binary is hardware and driver dependent so you can't ship those.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ It looks very promising, but I would love to find something that has tested support for more recent versions than GLSL 1.1/1.2. GLSL 3.3 and 4.0 are six years old now, it would be fantastic if they had verified support for it. \$\endgroup\$ – user5665 Apr 5 '16 at 10:59
  • \$\begingroup\$ I've played around with it for a bit now and I can say that it actually fairs pretty well with newer versions of GLSL and is the most mature GLSL I've seen thus far \$\endgroup\$ – user5665 Apr 6 '16 at 2:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy