blob: 3a2fe2984f3244c35a52af35c040330b6ec81a14 [file] [log] [blame]
John Kessenich54f6e562013-08-03 00:04:10 +00001An OpenGL and OpenGL ES shader front end and validator.
John Kessenicha0af4732012-12-12 21:15:54 +00002
John Kessenich54f6e562013-08-03 00:04:10 +00003There are two components:
John Kessenicha0af4732012-12-12 21:15:54 +00004
John Kessenich54f6e562013-08-03 00:04:10 +000051) A front-end library for programmatic parsing of GLSL/ESSL into an AST.
John Kessenicha0af4732012-12-12 21:15:54 +00006
John Kessenich54f6e562013-08-03 00:04:10 +000072) A standalone wrapper, glslangValidator, that can be used as a shader
8 validation tool.
John Kessenicha0af4732012-12-12 21:15:54 +00009
John Kessenich61c2d142013-10-03 20:23:57 +000010How to add a feature protected by a version/extension/stage/profile: See the
11comment in glslang/MachineIndependent/Versions.cpp.
12
John Kessenich54f6e562013-08-03 00:04:10 +000013Things left to do: See Todo.txt
John Kessenicha0af4732012-12-12 21:15:54 +000014
John Kessenich61c2d142013-10-03 20:23:57 +000015Execution of Standalone Wrapper
16-------------------------------
John Kessenicha0af4732012-12-12 21:15:54 +000017
John Kessenich54f6e562013-08-03 00:04:10 +000018There are binaries in the Install/Windows and Install/Linux directories.
John Kessenicha0af4732012-12-12 21:15:54 +000019
John Kessenich54f6e562013-08-03 00:04:10 +000020To use the standalone binary form, execute glslangValidator, and it will print
21a usage statement. Basic operation is to give it a file containing a shader,
22and it will print out warnings/errors and optionally an AST.
John Kessenicha0af4732012-12-12 21:15:54 +000023
John Kessenichc0275792013-08-09 17:14:49 +000024The applied stage-specific rules are based on the file extension:
25 .vert for a vertex shader
26 .tesc for a tessellation control shader
27 .tese for a tessellation evaluation shader
28 .geom for a geometry shader
29 .frag for a fragment shader
30 .comp for a compute shader
John Kessenicha0af4732012-12-12 21:15:54 +000031
John Kessenich61c2d142013-10-03 20:23:57 +000032There is also a non-shader extension
33 .conf for a configuration file of limits, see usage statement for example
34
35Source: Build and run on Linux
John Kessenicha0af4732012-12-12 21:15:54 +000036-------------------------------
37
John Kessenich54f6e562013-08-03 00:04:10 +000038A simple bash script "BuildLinux.sh" is provided at the root directory
39to do the build and run a test cases. You will need a recent version of
40bison installed.
John Kessenicha0af4732012-12-12 21:15:54 +000041
42Once the executable is generated, it needs to be dynamically linked with the
John Kessenich54f6e562013-08-03 00:04:10 +000043shared object created in lib directory. To achieve that, "cd" to
John Kessenicha0af4732012-12-12 21:15:54 +000044StandAlone directory to update the LD_LIBRARY_PATH as follows
45
46export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./../glslang/MachineIndependent/lib
47
48You can also update LD_LIBRARY_PATH in the .cshrc or .bashrc file, depending on
49the shell you are using. You will need to give the complete path of "lib" directory
50in .cshrc or .bashrc files.
51
John Kessenich54f6e562013-08-03 00:04:10 +000052Source: Build and run on Windows
53--------------------------------
John Kessenicha0af4732012-12-12 21:15:54 +000054
John Kessenich54f6e562013-08-03 00:04:10 +000055Current development is with Visual Studio verion 11 (2012). The solution
56file is in the project's root directory Standalone.sln.
John Kessenicha0af4732012-12-12 21:15:54 +000057
John Kessenich54f6e562013-08-03 00:04:10 +000058Building the StandAlone project (the default) will create glslangValidate.exe and
59copy it into the Test directory and Install directory. This allows local
60test scripts to use either the debug or release version, whichever was
61built last.
John Kessenicha0af4732012-12-12 21:15:54 +000062
John Kessenich54f6e562013-08-03 00:04:10 +000063Windows execution and testing is generally done from within a cygwin
64shell.
John Kessenicha0af4732012-12-12 21:15:54 +000065
John Kessenich54f6e562013-08-03 00:04:10 +000066Note: Despite appearances, the use of a DLL is currently disabled; it
67simply makes a standalone executable from a statically linked library.
John Kessenicha0af4732012-12-12 21:15:54 +000068
John Kessenich2d2f3162013-12-10 00:25:14 +000069Programmatic Interfaces
70-----------------------
John Kessenich4586dbd2013-08-05 15:52:03 +000071
72Another piece of software can programmatically translate shaders to an AST
John Kessenich2d2f3162013-12-10 00:25:14 +000073using one of two different interfaces:
74 - A new C++ class-oriented interface, or
75 - The original C functional interface
John Kessenich4586dbd2013-08-05 15:52:03 +000076
John Kessenich2d2f3162013-12-10 00:25:14 +000077The main() in StandAlone/StandAlone.cpp shows examples using both styles.
John Kessenich4586dbd2013-08-05 15:52:03 +000078
John Kessenich2d2f3162013-12-10 00:25:14 +000079C++ Class Interface (new, preferred):
John Kessenich4586dbd2013-08-05 15:52:03 +000080
John Kessenich2d2f3162013-12-10 00:25:14 +000081 This interface is in roughly the last 1/3 of ShaderLang.h. It is in the
82 glslang namespace and contains the following.
John Kessenich4586dbd2013-08-05 15:52:03 +000083
John Kessenich2d2f3162013-12-10 00:25:14 +000084 const char* GetEsslVersionString();
85 const char* GetGlslVersionString();
86 bool InitializeProcess();
87 void FinalizeProcess();
88
89 class TShader
90 bool parse(...);
91 void setStrings(...);
92 const char* getInfoLog();
93
94 class TProgram
95 void addShader(...);
96 bool link(...);
97 const char* getInfoLog();
98 Reflection queries
99
100 See ShaderLang.h and the usage of it in StandAlone/StandAlone.cpp for more
101 details.
102
103C Functional Interface (orginal):
104
105 This interface is in roughly the first 2/3 of ShaderLang.h, and referred to
106 as the Sh*() interface, as all the entry points start "Sh".
107
108 The Sh*() interface takes a "compiler" call-back object, which it calls after
109 building call back that is passed the AST and can then execute a backend on it.
110
111 The following is a simplified resulting run-time call stack:
112
113 ShCompile(shader, compiler) -> compiler(AST) -> <back end>
114
115 In practice, ShCompile() takes shader strings, default version, and
116 warning/error and other options for controling compilation.
John Kessenich4586dbd2013-08-05 15:52:03 +0000117
118Testing
119-------
120
121"Test" is an active test directory that contains test input and a
122subdirectory baseResults that contains the expected results of the
123tests. Both the tests and baseResults are under source-code control.
124Executing the script ./runtests will generate current results in
125the localResults directory and diff them against the baseResults.
126When you want to update the tracked test results, they need to be
127copied from localResults to baseResults
128
129There are some tests borrowed from LunarGLASS. If LunarGLASS is
130missing, those tests just won't run.
131
132Basic Internal Operation
133------------------------
John Kessenicha0af4732012-12-12 21:15:54 +0000134
John Kessenich2d2f3162013-12-10 00:25:14 +0000135 - Initial lexical analysis is done by the preprocessor in
John Kessenich54f6e562013-08-03 00:04:10 +0000136 MachineIndependent/Preprocessor, and then refined by a GLSL scanner
John Kessenichacc55c22013-08-05 17:09:24 +0000137 in MachineIndependent/Scan.cpp. There is currently no use of flex.
John Kessenicha0af4732012-12-12 21:15:54 +0000138
John Kessenichacc55c22013-08-05 17:09:24 +0000139 - Code is parsed using bison on MachineIndependent/glslang.y with the
140 aid of a symbol table and an AST. The symbol table is not passed on to
John Kessenicha0af4732012-12-12 21:15:54 +0000141 the back-end; the intermediate representation stands on its own.
John Kessenichacc55c22013-08-05 17:09:24 +0000142 The tree is built by the grammar productions, many of which are
143 offloaded into ParseHelper.cpp, and by Intermediate.cpp.
John Kessenicha0af4732012-12-12 21:15:54 +0000144
John Kessenich54f6e562013-08-03 00:04:10 +0000145 - The intermediate representation is very high-level, and represented
John Kessenicha0af4732012-12-12 21:15:54 +0000146 as an in-memory tree. This serves to lose no information from the
147 original program, and to have efficient transfer of the result from
John Kessenich54f6e562013-08-03 00:04:10 +0000148 parsing to the back-end. In the AST, constants are propogated and
John Kessenichacc55c22013-08-05 17:09:24 +0000149 folded, and a very small amount of dead code is eliminated.
John Kessenicha0af4732012-12-12 21:15:54 +0000150
John Kessenichacc55c22013-08-05 17:09:24 +0000151 To aid linking and reflection, the last top-level branch in the AST
152 lists all global symbols.
John Kessenich54f6e562013-08-03 00:04:10 +0000153
154 - The primary algorithm of the back-end compiler is to traverse the
John Kessenicha0af4732012-12-12 21:15:54 +0000155 tree (high-level intermediate representation), and create an internal
John Kessenich54f6e562013-08-03 00:04:10 +0000156 object code representation. There is an example of how to do this
John Kessenichacc55c22013-08-05 17:09:24 +0000157 in MachineIndependent/intermOut.cpp.
John Kessenicha0af4732012-12-12 21:15:54 +0000158
John Kessenich54f6e562013-08-03 00:04:10 +0000159 - Reduction of the tree to a linear byte-code style low-level intermediate
John Kessenicha0af4732012-12-12 21:15:54 +0000160 representation is likely a good way to generate fully optimized code.
John Kessenichacc55c22013-08-05 17:09:24 +0000161
John Kessenich4c706852013-10-11 16:28:43 +0000162 - There is currently some dead old-style linker-type code still lying around.
163
164 - Memory pool: parsing uses types derived from C++ std types, using a
165 custom allocator that puts them in a memory pool. This makes allocation
166 of individual container/contents just few cycles and deallocation free.
167 This pool is popped after the AST is made and processed.
168
169 The use is simple: if you are going to call "new", there are three cases:
170
171 - the object comes from the pool (its base class has the macro
172 POOL_ALLOCATOR_NEW_DELETE in it) and you do not have to call delete
173
174 - it is a TString, in which case call NewPoolTString(), which gets
175 it from the pool, and there is no corresponding delete
176
177 - the object does not come from the pool, and you have to do normal
178 C++ memory management of what you 'new'