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 An OpenGL and OpenGL ES shader front end and validator.
13 There are two components:
15 1. A front-end library for programmatic parsing of GLSL/ESSL into an AST.
17 2. A standalone wrapper, `glslangValidator`, that can be used as a shader
20 How to add a feature protected by a version/extension/stage/profile: See the
21 comment in `glslang/MachineIndependent/Versions.cpp`.
23 Things left to do: See `Todo.txt`
25 Execution of Standalone Wrapper
26 -------------------------------
28 To use the standalone binary form, execute `glslangValidator`, and it will print
29 a usage statement. Basic operation is to give it a file containing a shader,
30 and it will print out warnings/errors and optionally an AST.
32 The applied stage-specific rules are based on the file extension:
33 * `.vert` for a vertex shader
34 * `.tesc` for a tessellation control shader
35 * `.tese` for a tessellation evaluation shader
36 * `.geom` for a geometry shader
37 * `.frag` for a fragment shader
38 * `.comp` for a compute shader
40 There is also a non-shader extension
41 * `.conf` for a configuration file of limits, see usage statement for example
46 CMake: The currently maintained and preferred way of building is through CMake.
47 In MSVC, after running CMake, you may need to use the Configuration Manager to
48 check the INSTALL project.
50 Note there are some legacy build methods still intermingled within the directory
51 structure (make, MSVC), but these are no longer maintained, having been
54 Programmatic Interfaces
55 -----------------------
57 Another piece of software can programmatically translate shaders to an AST
58 using one of two different interfaces:
59 * A new C++ class-oriented interface, or
60 * The original C functional interface
62 The `main()` in `StandAlone/StandAlone.cpp` shows examples using both styles.
64 ### C++ Class Interface (new, preferred)
66 This interface is in roughly the last 1/3 of `ShaderLang.h`. It is in the
67 glslang namespace and contains the following.
70 const char* GetEsslVersionString();
71 const char* GetGlslVersionString();
72 bool InitializeProcess();
73 void FinalizeProcess();
78 const char* getInfoLog();
83 const char* getInfoLog();
87 See `ShaderLang.h` and the usage of it in `StandAlone/StandAlone.cpp` for more
90 ### C Functional Interface (orginal)
92 This interface is in roughly the first 2/3 of `ShaderLang.h`, and referred to
93 as the `Sh*()` interface, as all the entry points start `Sh`.
95 The `Sh*()` interface takes a "compiler" call-back object, which it calls after
96 building call back that is passed the AST and can then execute a backend on it.
98 The following is a simplified resulting run-time call stack:
101 ShCompile(shader, compiler) -> compiler(AST) -> <back end>
104 In practice, `ShCompile()` takes shader strings, default version, and
105 warning/error and other options for controling compilation.
110 Test results should always be included with a pull request that modifies
111 functionality. There is a simple process for doing this, described here:
113 `Test` is an active test directory that contains test input and a
114 subdirectory `baseResults` that contains the expected results of the
115 tests. Both the tests and `baseResults` are under source-code control.
116 Executing the script `./runtests` will generate current results in
117 the `localResults` directory and `diff` them against the `baseResults`.
119 When you want to update the tracked test results, they need to be
120 copied from `localResults` to `baseResults`. This can be done by
121 the `bump` shell script.
123 The list of files tested comes from `testlist`, and lists input shaders
124 in this directory, which must all be public for this to work. However,
125 you can add your own private list of tests, not tracked here, by using
126 `localtestlist` to list non-tracked tests. This is automatically read
127 by `runtests` and included in the `diff` and `bump` process.
129 Basic Internal Operation
130 ------------------------
132 * Initial lexical analysis is done by the preprocessor in
133 `MachineIndependent/Preprocessor`, and then refined by a GLSL scanner
134 in `MachineIndependent/Scan.cpp`. There is currently no use of flex.
136 * Code is parsed using bison on `MachineIndependent/glslang.y` with the
137 aid of a symbol table and an AST. The symbol table is not passed on to
138 the back-end; the intermediate representation stands on its own.
139 The tree is built by the grammar productions, many of which are
140 offloaded into `ParseHelper.cpp`, and by `Intermediate.cpp`.
142 * The intermediate representation is very high-level, and represented
143 as an in-memory tree. This serves to lose no information from the
144 original program, and to have efficient transfer of the result from
145 parsing to the back-end. In the AST, constants are propogated and
146 folded, and a very small amount of dead code is eliminated.
148 To aid linking and reflection, the last top-level branch in the AST
149 lists all global symbols.
151 * The primary algorithm of the back-end compiler is to traverse the
152 tree (high-level intermediate representation), and create an internal
153 object code representation. There is an example of how to do this
154 in `MachineIndependent/intermOut.cpp`.
156 * Reduction of the tree to a linear byte-code style low-level intermediate
157 representation is likely a good way to generate fully optimized code.
159 * There is currently some dead old-style linker-type code still lying around.
161 * Memory pool: parsing uses types derived from C++ `std` types, using a
162 custom allocator that puts them in a memory pool. This makes allocation
163 of individual container/contents just few cycles and deallocation free.
164 This pool is popped after the AST is made and processed.
166 The use is simple: if you are going to call `new`, there are three cases:
168 - the object comes from the pool (its base class has the macro
169 `POOL_ALLOCATOR_NEW_DELETE` in it) and you do not have to call `delete`
171 - it is a `TString`, in which case call `NewPoolTString()`, which gets
172 it from the pool, and there is no corresponding `delete`
174 - the object does not come from the pool, and you have to do normal
175 C++ memory management of what you `new`