bgfx/3rdparty/glsl-optimizer/README.md

97 lines
3.5 KiB
Markdown
Raw Normal View History

2012-04-03 23:30:07 -04:00
GLSL optimizer
==============
A C++ library that takes GLSL shaders, does some GPU-independent optimizations on them
2014-10-11 15:32:43 -04:00
and outputs GLSL or Metal source back. Optimizations are function inlining, dead code removal, copy propagation,
2012-04-03 23:30:07 -04:00
constant folding, constant propagation, arithmetic optimizations and so on.
2014-10-11 15:32:43 -04:00
Apparently quite a few mobile platforms are pretty bad at optimizing shaders; and
2012-04-03 23:30:07 -04:00
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](http://aras-p.info/blog/2010/09/29/glsl-optimizer/).
2014-10-11 15:32:43 -04:00
Even for drivers that have decent shader optimization, GLSL optimizer could be useful to just strip away
dead code, make shaders smaller and do uniform/input reflection offline.
2012-10-07 23:41:18 -04:00
Almost all actual code is [Mesa 3D's GLSL](http://cgit.freedesktop.org/mesa/mesa/log/)
2014-10-11 15:32:43 -04:00
compiler; all this library does is spits out optimized GLSL or Metal back, and adds GLES type precision
2012-10-07 23:41:18 -04:00
handling to the optimizer.
2012-04-03 23:30:07 -04:00
This GLSL optimizer is made for [Unity's](http://unity3d.com/) purposes and is built-in
2014-02-11 02:06:13 -05:00
starting with Unity 3.0.
2012-04-03 23:30:07 -04:00
GLSL Optimizer is licensed according to the terms of the MIT license.
2014-10-11 15:32:43 -04:00
See [change log here](Changelog.md).
2014-02-11 02:06:13 -05:00
2012-04-03 23:30:07 -04:00
Usage
-----
2014-02-11 02:06:13 -05:00
Visual Studio 2010 (Windows, x86/x64) and Xcode 5+ (Mac, i386) project files for a static
library are provided in `projects/vs2010/glsl_optimizer.sln` and `projects/xcode5/glsl_optimizer_lib`
2012-04-03 23:30:07 -04:00
respectively.
2014-02-11 02:06:13 -05:00
> Note: only the VS and Xcode project files are maintained and should work at any time.
> There's also a cmake and gyp build system for Linux et al., and some stuff in contrib folder -
> all that may or might not work.
2012-04-03 23:30:07 -04:00
For Linux you can use cmake. Just type "cmake . && make" in the root directory.
This will build the optimizer library and some executable binaries.
Interface for the library is `src/glsl/glsl_optimizer.h`. General usage is:
2014-10-11 15:32:43 -04:00
ctx = glslopt_initialize(targetVersion);
2012-04-03 23:30:07 -04:00
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);
2014-02-11 02:06:13 -05:00
Tests
-----
There's a testing suite for catching regressions, see `tests` folder. In VS, build
and run `glsl_optimizer_tests` project; in Xcode use `projects/xcode5/glsl_optimizer_tests`
project. The test executable requires path to the `tests` folder as an argument.
Each test comes as three text files; input, expected IR dump and expected optimized
2014-10-11 15:32:43 -04:00
GLSL dump. GLES3 tests are also converted into Metal.
2014-02-11 02:06:13 -05:00
If you're making changes to the project and want pull requests accepted easier, I'd
appreciate if there would be no test suite regressions. If you are implementing a
feature, it would be cool to add tests to cover it as well!
2012-04-03 23:30:07 -04:00
Notes
-----
2012-10-07 23:41:18 -04:00
* GLSL versions 1.10 and 1.20 are supported. 1.10 is the default, use #version 120 to specify
2014-10-11 15:32:43 -04:00
1.20. Higher GLSL versions might work, but aren't tested now.
2014-02-11 02:06:13 -05:00
* GLSL ES versions 1.00 and 3.00 are supported.
Dev Notes
---------
Pulling Mesa upstream:
git fetch upstream
git merge upstream/master
sh removeDeletedByUs.sh
# inspect files, git rm unneeded ones, fix conflicts etc.
# git commit
Rebuilding flex/bison parsers:
* When .y/.l files are changed, the parsers are *not* rebuilt automatically,
* Run ./generateParsers.sh to do that. You'll need bison & flex (on Mac, do "Install Command Line Tools" from Xcode)
* I use bison 2.3 and flex 2.5.35 (in OS X 10.8/10.9)