1 Also see the Khronos landing page for glslang as a reference front end:
3 https://www.khronos.org/opengles/sdk/tools/Reference-Compiler/
5 The above page includes where to get binaries, and is kept up to date
6 regarding the feature level of glslang.
11 [![Build Status](https://travis-ci.org/KhronosGroup/glslang.svg?branch=master)](https://travis-ci.org/KhronosGroup/glslang)
13 An OpenGL and OpenGL ES shader front end and validator.
15 There are two components:
17 1. A front-end library for programmatic parsing of GLSL/ESSL into an AST.
19 2. A standalone wrapper, `glslangValidator`, that can be used as a shader
22 How to add a feature protected by a version/extension/stage/profile: See the
23 comment in `glslang/MachineIndependent/Versions.cpp`.
25 Things left to do: See `Todo.txt`
27 Execution of Standalone Wrapper
28 -------------------------------
30 To use the standalone binary form, execute `glslangValidator`, and it will print
31 a usage statement. Basic operation is to give it a file containing a shader,
32 and it will print out warnings/errors and optionally an AST.
34 The applied stage-specific rules are based on the file extension:
35 * `.vert` for a vertex shader
36 * `.tesc` for a tessellation control shader
37 * `.tese` for a tessellation evaluation shader
38 * `.geom` for a geometry shader
39 * `.frag` for a fragment shader
40 * `.comp` for a compute shader
42 There is also a non-shader extension
43 * `.conf` for a configuration file of limits, see usage statement for example
48 CMake: The currently maintained and preferred way of building is through CMake.
49 In MSVC, after running CMake, you may need to use the Configuration Manager to
50 check the INSTALL project.
52 The grammar in glslang/MachineIndependent/glslang.y has to be recompiled with
53 bison if it changes, the output files are committed to the repo to avoid every
54 developer needing to have bison configured to compile the project when grammar
55 changes are quite infrequent. For windows you can get binaries from
56 [GnuWin32](http://gnuwin32.sourceforge.net/packages/bison.htm).
58 The command to rebuild is:
61 bison --defines=MachineIndependent/glslang_tab.cpp.h
62 -t MachineIndependent/glslang.y
63 -o MachineIndependent/glslang_tab.cpp
66 Glslang is adding the ability to test with
67 [Google Test](https://github.com/google/googletest) framework. If you want to
68 build and run those tests, please make sure you have a copy of Google Tests
69 checked out in the `External/` directory:
70 `git clone https://github.com/google/googletest.git`.
72 Programmatic Interfaces
73 -----------------------
75 Another piece of software can programmatically translate shaders to an AST
76 using one of two different interfaces:
77 * A new C++ class-oriented interface, or
78 * The original C functional interface
80 The `main()` in `StandAlone/StandAlone.cpp` shows examples using both styles.
82 ### C++ Class Interface (new, preferred)
84 This interface is in roughly the last 1/3 of `ShaderLang.h`. It is in the
85 glslang namespace and contains the following.
88 const char* GetEsslVersionString();
89 const char* GetGlslVersionString();
90 bool InitializeProcess();
91 void FinalizeProcess();
96 const char* getInfoLog();
101 const char* getInfoLog();
105 See `ShaderLang.h` and the usage of it in `StandAlone/StandAlone.cpp` for more
108 ### C Functional Interface (orignal)
110 This interface is in roughly the first 2/3 of `ShaderLang.h`, and referred to
111 as the `Sh*()` interface, as all the entry points start `Sh`.
113 The `Sh*()` interface takes a "compiler" call-back object, which it calls after
114 building call back that is passed the AST and can then execute a backend on it.
116 The following is a simplified resulting run-time call stack:
119 ShCompile(shader, compiler) -> compiler(AST) -> <back end>
122 In practice, `ShCompile()` takes shader strings, default version, and
123 warning/error and other options for controlling compilation.
128 Test results should always be included with a pull request that modifies
129 functionality. And since glslang added the ability to test with
130 [Google Test](https://github.com/google/googletest) framework,
131 please write your new tests using Google Test.
133 The old (deprecated) testing process is:
135 `Test` is an active test directory that contains test input and a
136 subdirectory `baseResults` that contains the expected results of the
137 tests. Both the tests and `baseResults` are under source-code control.
138 Executing the script `./runtests` will generate current results in
139 the `localResults` directory and `diff` them against the `baseResults`.
141 When you want to update the tracked test results, they need to be
142 copied from `localResults` to `baseResults`. This can be done by
143 the `bump` shell script.
145 The list of files tested comes from `testlist`, and lists input shaders
146 in this directory, which must all be public for this to work. However,
147 you can add your own private list of tests, not tracked here, by using
148 `localtestlist` to list non-tracked tests. This is automatically read
149 by `runtests` and included in the `diff` and `bump` process.
151 Basic Internal Operation
152 ------------------------
154 * Initial lexical analysis is done by the preprocessor in
155 `MachineIndependent/Preprocessor`, and then refined by a GLSL scanner
156 in `MachineIndependent/Scan.cpp`. There is currently no use of flex.
158 * Code is parsed using bison on `MachineIndependent/glslang.y` with the
159 aid of a symbol table and an AST. The symbol table is not passed on to
160 the back-end; the intermediate representation stands on its own.
161 The tree is built by the grammar productions, many of which are
162 offloaded into `ParseHelper.cpp`, and by `Intermediate.cpp`.
164 * The intermediate representation is very high-level, and represented
165 as an in-memory tree. This serves to lose no information from the
166 original program, and to have efficient transfer of the result from
167 parsing to the back-end. In the AST, constants are propogated and
168 folded, and a very small amount of dead code is eliminated.
170 To aid linking and reflection, the last top-level branch in the AST
171 lists all global symbols.
173 * The primary algorithm of the back-end compiler is to traverse the
174 tree (high-level intermediate representation), and create an internal
175 object code representation. There is an example of how to do this
176 in `MachineIndependent/intermOut.cpp`.
178 * Reduction of the tree to a linear byte-code style low-level intermediate
179 representation is likely a good way to generate fully optimized code.
181 * There is currently some dead old-style linker-type code still lying around.
183 * Memory pool: parsing uses types derived from C++ `std` types, using a
184 custom allocator that puts them in a memory pool. This makes allocation
185 of individual container/contents just few cycles and deallocation free.
186 This pool is popped after the AST is made and processed.
188 The use is simple: if you are going to call `new`, there are three cases:
190 - the object comes from the pool (its base class has the macro
191 `POOL_ALLOCATOR_NEW_DELETE` in it) and you do not have to call `delete`
193 - it is a `TString`, in which case call `NewPoolTString()`, which gets
194 it from the pool, and there is no corresponding `delete`
196 - the object does not come from the pool, and you have to do normal
197 C++ memory management of what you `new`