• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..27-Oct-2020-

External/H03-May-2022-

OGLCompilersDLL/H03-May-2022-21683

SPIRV/H03-May-2022-22,91217,489

StandAlone/H03-May-2022-2,8472,128

Test/H07-May-2022-473,416456,757

build_overrides/H27-Oct-2020-3835

glslang/H03-May-2022-72,88956,113

gtests/H03-May-2022-4,5473,206

hlsl/H03-May-2022-18,43212,356

kokoro/H27-Oct-2020-414299

ndk_test/H27-Oct-2020-3919

.appveyor.ymlH A D27-Oct-20202.5 KiB9579

.clang-formatH A D27-Oct-2020379 1413

.gitattributesH A D27-Oct-2020523 1815

.gitignoreH A D27-Oct-202096 1110

.travis.ymlH A D27-Oct-20204.1 KiB129113

Android.mkH A D27-Oct-20203.7 KiB10191

BUILD.bazelH A D27-Oct-20205.8 KiB246230

BUILD.gnH A D27-Oct-20208 KiB248229

CODE_OF_CONDUCT.mdH A D27-Oct-2020280 21

ChooseMSVCCRT.cmakeH A D27-Oct-20203.8 KiB10694

README.mdH A D27-Oct-202013.9 KiB382279

WORKSPACEH A D27-Oct-20201.1 KiB2824

_config.ymlH A D27-Oct-202026 11

known_good.jsonH A D27-Oct-2020501 1918

known_good_khr.jsonH A D27-Oct-2020464 1918

make-revisionH A D27-Oct-2020174 75

update_glslang_sources.pyH A D27-Oct-20205 KiB156103

README.md

1Also see the Khronos landing page for glslang as a reference front end:
2
3https://www.khronos.org/opengles/sdk/tools/Reference-Compiler/
4
5The above page includes where to get binaries, and is kept up to date
6regarding the feature level of glslang.
7
8glslang
9=======
10
11[![Build Status](https://travis-ci.org/KhronosGroup/glslang.svg?branch=master)](https://travis-ci.org/KhronosGroup/glslang)
12[![Build status](https://ci.appveyor.com/api/projects/status/q6fi9cb0qnhkla68/branch/master?svg=true)](https://ci.appveyor.com/project/Khronoswebmaster/glslang/branch/master)
13
14An OpenGL and OpenGL ES shader front end and validator.
15
16There are several components:
17
181. A GLSL/ESSL front-end for reference validation and translation of GLSL/ESSL into an AST.
19
202. An HLSL front-end for translation of a broad generic HLL into the AST. See [issue 362](https://github.com/KhronosGroup/glslang/issues/362) and [issue 701](https://github.com/KhronosGroup/glslang/issues/701) for current status.
21
223. A SPIR-V back end for translating the AST to SPIR-V.
23
244. A standalone wrapper, `glslangValidator`, that can be used as a command-line tool for the above.
25
26How to add a feature protected by a version/extension/stage/profile:  See the
27comment in `glslang/MachineIndependent/Versions.cpp`.
28
29Tasks waiting to be done are documented as GitHub issues.
30
31Execution of Standalone Wrapper
32-------------------------------
33
34To use the standalone binary form, execute `glslangValidator`, and it will print
35a usage statement.  Basic operation is to give it a file containing a shader,
36and it will print out warnings/errors and optionally an AST.
37
38The applied stage-specific rules are based on the file extension:
39* `.vert` for a vertex shader
40* `.tesc` for a tessellation control shader
41* `.tese` for a tessellation evaluation shader
42* `.geom` for a geometry shader
43* `.frag` for a fragment shader
44* `.comp` for a compute shader
45
46There is also a non-shader extension
47* `.conf` for a configuration file of limits, see usage statement for example
48
49Building
50--------
51
52Instead of building manually, you can also download the binaries for your
53platform directly from the [master-tot release][master-tot-release] on GitHub.
54Those binaries are automatically uploaded by the buildbots after successful
55testing and they always reflect the current top of the tree of the master
56branch.
57
58### Dependencies
59
60* A C++11 compiler.
61  (For MSVS: 2015 is recommended, 2013 is fully supported/tested, and 2010 support is attempted, but not tested.)
62* [CMake][cmake]: for generating compilation targets.
63* make: _Linux_, ninja is an alternative, if configured.
64* [Python 3.x][python]: for executing SPIRV-Tools scripts. (Optional if not using SPIRV-Tools and the 'External' subdirectory does not exist.)
65* [bison][bison]: _optional_, but needed when changing the grammar (glslang.y).
66* [googletest][googletest]: _optional_, but should use if making any changes to glslang.
67
68### Build steps
69
70The following steps assume a Bash shell. On Windows, that could be the Git Bash
71shell or some other shell of your choosing.
72
73#### 1) Check-Out this project
74
75```bash
76cd <parent of where you want glslang to be>
77git clone https://github.com/KhronosGroup/glslang.git
78```
79
80#### 2) Check-Out External Projects
81
82```bash
83cd <the directory glslang was cloned to, "External" will be a subdirectory>
84git clone https://github.com/google/googletest.git External/googletest
85```
86
87If you want to use googletest with Visual Studio 2013, you also need to check out an older version:
88
89```bash
90# to use googletest with Visual Studio 2013
91cd External/googletest
92git checkout 440527a61e1c91188195f7de212c63c77e8f0a45
93cd ../..
94```
95
96If you wish to assure that SPIR-V generated from HLSL is legal for Vulkan,
97or wish to invoke -Os to reduce SPIR-V size from HLSL or GLSL, install
98spirv-tools with this:
99
100```bash
101./update_glslang_sources.py
102```
103
104#### 3) Configure
105
106Assume the source directory is `$SOURCE_DIR` and the build directory is
107`$BUILD_DIR`. First ensure the build directory exists, then navigate to it:
108
109```bash
110mkdir -p $BUILD_DIR
111cd $BUILD_DIR
112```
113
114For building on Linux:
115
116```bash
117cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$(pwd)/install" $SOURCE_DIR
118# "Release" (for CMAKE_BUILD_TYPE) could also be "Debug" or "RelWithDebInfo"
119```
120
121For building on Windows:
122
123```bash
124cmake $SOURCE_DIR -DCMAKE_INSTALL_PREFIX="$(pwd)/install"
125# The CMAKE_INSTALL_PREFIX part is for testing (explained later).
126```
127
128The CMake GUI also works for Windows (version 3.4.1 tested).
129
130Also, consider using `git config --global core.fileMode false` (or with `--local`) on Windows
131to prevent the addition of execution permission on files.
132
133#### 4) Build and Install
134
135```bash
136# for Linux:
137make -j4 install
138
139# for Windows:
140cmake --build . --config Release --target install
141# "Release" (for --config) could also be "Debug", "MinSizeRel", or "RelWithDebInfo"
142```
143
144If using MSVC, after running CMake to configure, use the
145Configuration Manager to check the `INSTALL` project.
146
147### If you need to change the GLSL grammar
148
149The grammar in `glslang/MachineIndependent/glslang.y` has to be recompiled with
150bison if it changes, the output files are committed to the repo to avoid every
151developer needing to have bison configured to compile the project when grammar
152changes are quite infrequent. For windows you can get binaries from
153[GnuWin32][bison-gnu-win32].
154
155The command to rebuild is:
156
157```bash
158m4 -P MachineIndependent/glslang.m4 > MachineIndependent/glslang.y
159bison --defines=MachineIndependent/glslang_tab.cpp.h
160      -t MachineIndependent/glslang.y
161      -o MachineIndependent/glslang_tab.cpp
162```
163
164The above commands are also available in the bash script in `updateGrammar`,
165when executed from the glslang subdirectory of the glslang repository.
166With no arguments it builds the full grammar, and with a "web" argument,
167the web grammar subset (see more about the web subset in the next section).
168
169### Building to WASM for the Web and Node
170
171Use the steps in [Build Steps](#build-steps), with the following notes/exceptions:
172* For building the web subset of core glslang:
173  + execute `updateGrammar web` from the glslang subdirectory
174    (or if using your own scripts, `m4` needs a `-DGLSLANG_WEB` argument)
175  + set `-DENABLE_HLSL=OFF -DBUILD_TESTING=OFF -DENABLE_OPT=OFF -DINSTALL_GTEST=OFF`
176  + turn on `-DENABLE_GLSLANG_WEB=ON`
177  + optionally, for GLSL compilation error messages, turn on `-DENABLE_GLSLANG_WEB_DEVEL=ON`
178* `emsdk` needs to be present in your executable search path, *PATH* for
179  Bash-like enivironments
180  + [Instructions located
181    here](https://emscripten.org/docs/getting_started/downloads.html#sdk-download-and-install)
182* Wrap cmake call: `emcmake cmake`
183* To get a fully minimized build, make sure to use `brotli` to compress the .js
184  and .wasm files
185
186Example:
187
188```sh
189emcmake cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_GLSLANG_WEB=ON \
190    -DENABLE_HLSL=OFF -DBUILD_TESTING=OFF -DENABLE_OPT=OFF -DINSTALL_GTEST=OFF ..
191```
192
193Testing
194-------
195
196Right now, there are two test harnesses existing in glslang: one is [Google
197Test](gtests/), one is the [`runtests` script](Test/runtests). The former
198runs unit tests and single-shader single-threaded integration tests, while
199the latter runs multiple-shader linking tests and multi-threaded tests.
200
201### Running tests
202
203The [`runtests` script](Test/runtests) requires compiled binaries to be
204installed into `$BUILD_DIR/install`. Please make sure you have supplied the
205correct configuration to CMake (using `-DCMAKE_INSTALL_PREFIX`) when building;
206otherwise, you may want to modify the path in the `runtests` script.
207
208Running Google Test-backed tests:
209
210```bash
211cd $BUILD_DIR
212
213# for Linux:
214ctest
215
216# for Windows:
217ctest -C {Debug|Release|RelWithDebInfo|MinSizeRel}
218
219# or, run the test binary directly
220# (which gives more fine-grained control like filtering):
221<dir-to-glslangtests-in-build-dir>/glslangtests
222```
223
224Running `runtests` script-backed tests:
225
226```bash
227cd $SOURCE_DIR/Test && ./runtests
228```
229
230### Contributing tests
231
232Test results should always be included with a pull request that modifies
233functionality.
234
235If you are writing unit tests, please use the Google Test framework and
236place the tests under the `gtests/` directory.
237
238Integration tests are placed in the `Test/` directory. It contains test input
239and a subdirectory `baseResults/` that contains the expected results of the
240tests.  Both the tests and `baseResults/` are under source-code control.
241
242Google Test runs those integration tests by reading the test input, compiling
243them, and then compare against the expected results in `baseResults/`. The
244integration tests to run via Google Test is registered in various
245`gtests/*.FromFile.cpp` source files. `glslangtests` provides a command-line
246option `--update-mode`, which, if supplied, will overwrite the golden files
247under the `baseResults/` directory with real output from that invocation.
248For more information, please check `gtests/` directory's
249[README](gtests/README.md).
250
251For the `runtests` script, it will generate current results in the
252`localResults/` directory and `diff` them against the `baseResults/`.
253When you want to update the tracked test results, they need to be
254copied from `localResults/` to `baseResults/`.  This can be done by
255the `bump` shell script.
256
257You can add your own private list of tests, not tracked publicly, by using
258`localtestlist` to list non-tracked tests.  This is automatically read
259by `runtests` and included in the `diff` and `bump` process.
260
261Programmatic Interfaces
262-----------------------
263
264Another piece of software can programmatically translate shaders to an AST
265using one of two different interfaces:
266* A new C++ class-oriented interface, or
267* The original C functional interface
268
269The `main()` in `StandAlone/StandAlone.cpp` shows examples using both styles.
270
271### C++ Class Interface (new, preferred)
272
273This interface is in roughly the last 1/3 of `ShaderLang.h`.  It is in the
274glslang namespace and contains the following, here with suggested calls
275for generating SPIR-V:
276
277```cxx
278const char* GetEsslVersionString();
279const char* GetGlslVersionString();
280bool InitializeProcess();
281void FinalizeProcess();
282
283class TShader
284    setStrings(...);
285    setEnvInput(EShSourceHlsl or EShSourceGlsl, stage,  EShClientVulkan or EShClientOpenGL, 100);
286    setEnvClient(EShClientVulkan or EShClientOpenGL, EShTargetVulkan_1_0 or EShTargetVulkan_1_1 or EShTargetOpenGL_450);
287    setEnvTarget(EShTargetSpv, EShTargetSpv_1_0 or EShTargetSpv_1_3);
288    bool parse(...);
289    const char* getInfoLog();
290
291class TProgram
292    void addShader(...);
293    bool link(...);
294    const char* getInfoLog();
295    Reflection queries
296```
297
298For just validating (not generating code), subsitute these calls:
299
300```cxx
301    setEnvInput(EShSourceHlsl or EShSourceGlsl, stage,  EShClientNone, 0);
302    setEnvClient(EShClientNone, 0);
303    setEnvTarget(EShTargetNone, 0);
304```
305
306See `ShaderLang.h` and the usage of it in `StandAlone/StandAlone.cpp` for more
307details. There is a block comment giving more detail above the calls for
308`setEnvInput, setEnvClient, and setEnvTarget`.
309
310### C Functional Interface (original)
311
312This interface is in roughly the first 2/3 of `ShaderLang.h`, and referred to
313as the `Sh*()` interface, as all the entry points start `Sh`.
314
315The `Sh*()` interface takes a "compiler" call-back object, which it calls after
316building call back that is passed the AST and can then execute a backend on it.
317
318The following is a simplified resulting run-time call stack:
319
320```c
321ShCompile(shader, compiler) -> compiler(AST) -> <back end>
322```
323
324In practice, `ShCompile()` takes shader strings, default version, and
325warning/error and other options for controlling compilation.
326
327Basic Internal Operation
328------------------------
329
330* Initial lexical analysis is done by the preprocessor in
331  `MachineIndependent/Preprocessor`, and then refined by a GLSL scanner
332  in `MachineIndependent/Scan.cpp`.  There is currently no use of flex.
333
334* Code is parsed using bison on `MachineIndependent/glslang.y` with the
335  aid of a symbol table and an AST.  The symbol table is not passed on to
336  the back-end; the intermediate representation stands on its own.
337  The tree is built by the grammar productions, many of which are
338  offloaded into `ParseHelper.cpp`, and by `Intermediate.cpp`.
339
340* The intermediate representation is very high-level, and represented
341  as an in-memory tree.   This serves to lose no information from the
342  original program, and to have efficient transfer of the result from
343  parsing to the back-end.  In the AST, constants are propogated and
344  folded, and a very small amount of dead code is eliminated.
345
346  To aid linking and reflection, the last top-level branch in the AST
347  lists all global symbols.
348
349* The primary algorithm of the back-end compiler is to traverse the
350  tree (high-level intermediate representation), and create an internal
351  object code representation.  There is an example of how to do this
352  in `MachineIndependent/intermOut.cpp`.
353
354* Reduction of the tree to a linear byte-code style low-level intermediate
355  representation is likely a good way to generate fully optimized code.
356
357* There is currently some dead old-style linker-type code still lying around.
358
359* Memory pool: parsing uses types derived from C++ `std` types, using a
360  custom allocator that puts them in a memory pool.  This makes allocation
361  of individual container/contents just few cycles and deallocation free.
362  This pool is popped after the AST is made and processed.
363
364  The use is simple: if you are going to call `new`, there are three cases:
365
366  - the object comes from the pool (its base class has the macro
367    `POOL_ALLOCATOR_NEW_DELETE` in it) and you do not have to call `delete`
368
369  - it is a `TString`, in which case call `NewPoolTString()`, which gets
370    it from the pool, and there is no corresponding `delete`
371
372  - the object does not come from the pool, and you have to do normal
373    C++ memory management of what you `new`
374
375
376[cmake]: https://cmake.org/
377[python]: https://www.python.org/
378[bison]: https://www.gnu.org/software/bison/
379[googletest]: https://github.com/google/googletest
380[bison-gnu-win32]: http://gnuwin32.sourceforge.net/packages/bison.htm
381[master-tot-release]: https://github.com/KhronosGroup/glslang/releases/tag/master-tot
382