Skip to content

GLSL optimizer based on Mesa's GLSL2 compiler. Used in Unity for mobile shader optimization.

Notifications You must be signed in to change notification settings

jims/glsl-optimizer

 
 

Repository files navigation

GLSL optimizer

A C++ library that takes GLSL shaders, does some GPU-independent optimizations on them and outputs GLSL back. Optimizations are function inlining, dead code removal, copy propagation, constant folding, constant propagation, arithmetic optimizations and so on.

Apparently quite a few mobile platforms are pretty bad at optimizing GLSL shaders; and unfortunately they also lack offline shader compilers. So using a GLSL optimizer offline before can make the shader run much faster on a platform like that. See performance numbers in this blog post.

Almost all actual code is Mesa 3D's GLSL2 compiler; all this library does is spits out optimized GLSL back.

This GLSL optimizer is made for Unity's purposes and is built-in in Unity 3.0.

Usage

Visual Studio 2008 (Windows, x86) and Xcode 3.2 (Mac, i386) project files for a static library are provided in src/glsl/msvc/mesaglsl2.vcproj and src/glsl/xcode/mesaglsl2 respectively. A Linux Makefile (x86/x86_64) is at src/glsl.

Interface for the library is src/glsl/glsl_optimizer.h. General usage is:

ctx = glslopt_initialize();
for (lots of shaders) {
	shader = glslopt_optimize (ctx, shaderType, shaderSource, options);
	if (glslopt_get_status (shader)) {
		newSource = glslopt_get_output (shader);
	} else {
		errorLog = glslopt_get_log (shader);
	}
	glslopt_shader_delete (shader);
}
glslopt_cleanup (ctx);

Notes

  • I haven't checked if/how it works with higher GLSL versions than the default (1.10?).

About

GLSL optimizer based on Mesa's GLSL2 compiler. Used in Unity for mobile shader optimization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 62.3%
  • C 36.8%
  • Other 0.9%