/src/shaderc/third_party/glslang/glslang/Public/ShaderLang.h
Line | Count | Source |
1 | | // |
2 | | // Copyright (C) 2002-2005 3Dlabs Inc. Ltd. |
3 | | // Copyright (C) 2013-2016 LunarG, Inc. |
4 | | // Copyright (C) 2015-2018 Google, Inc. |
5 | | // |
6 | | // All rights reserved. |
7 | | // |
8 | | // Redistribution and use in source and binary forms, with or without |
9 | | // modification, are permitted provided that the following conditions |
10 | | // are met: |
11 | | // |
12 | | // Redistributions of source code must retain the above copyright |
13 | | // notice, this list of conditions and the following disclaimer. |
14 | | // |
15 | | // Redistributions in binary form must reproduce the above |
16 | | // copyright notice, this list of conditions and the following |
17 | | // disclaimer in the documentation and/or other materials provided |
18 | | // with the distribution. |
19 | | // |
20 | | // Neither the name of 3Dlabs Inc. Ltd. nor the names of its |
21 | | // contributors may be used to endorse or promote products derived |
22 | | // from this software without specific prior written permission. |
23 | | // |
24 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
25 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
26 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
27 | | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
28 | | // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
29 | | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
30 | | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
31 | | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
32 | | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
33 | | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
34 | | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | | // POSSIBILITY OF SUCH DAMAGE. |
36 | | // |
37 | | #ifndef _COMPILER_INTERFACE_INCLUDED_ |
38 | | #define _COMPILER_INTERFACE_INCLUDED_ |
39 | | |
40 | | #include "../Include/ResourceLimits.h" |
41 | | #include "../Include/visibility.h" |
42 | | #include "../MachineIndependent/Versions.h" |
43 | | |
44 | | #include <cstring> |
45 | | #include <vector> |
46 | | |
47 | | #ifdef _WIN32 |
48 | | #define C_DECL __cdecl |
49 | | #else |
50 | | #define C_DECL |
51 | | #endif |
52 | | |
53 | | // |
54 | | // This is the platform independent interface between an OGL driver |
55 | | // and the shading language compiler/linker. |
56 | | // |
57 | | |
58 | | #ifdef __cplusplus |
59 | | extern "C" { |
60 | | #endif |
61 | | |
62 | | // |
63 | | // Call before doing any other compiler/linker operations. |
64 | | // |
65 | | // (Call once per process, not once per thread.) |
66 | | // |
67 | | GLSLANG_EXPORT int ShInitialize(); |
68 | | |
69 | | // |
70 | | // Call this at process shutdown to clean up memory. |
71 | | // |
72 | | GLSLANG_EXPORT int ShFinalize(); |
73 | | |
74 | | // |
75 | | // Types of languages the compiler can consume. |
76 | | // |
77 | | typedef enum { |
78 | | EShLangVertex, |
79 | | EShLangTessControl, |
80 | | EShLangTessEvaluation, |
81 | | EShLangGeometry, |
82 | | EShLangFragment, |
83 | | EShLangCompute, |
84 | | EShLangRayGen, |
85 | | EShLangRayGenNV = EShLangRayGen, |
86 | | EShLangIntersect, |
87 | | EShLangIntersectNV = EShLangIntersect, |
88 | | EShLangAnyHit, |
89 | | EShLangAnyHitNV = EShLangAnyHit, |
90 | | EShLangClosestHit, |
91 | | EShLangClosestHitNV = EShLangClosestHit, |
92 | | EShLangMiss, |
93 | | EShLangMissNV = EShLangMiss, |
94 | | EShLangCallable, |
95 | | EShLangCallableNV = EShLangCallable, |
96 | | EShLangTask, |
97 | | EShLangTaskNV = EShLangTask, |
98 | | EShLangMesh, |
99 | | EShLangMeshNV = EShLangMesh, |
100 | | LAST_ELEMENT_MARKER(EShLangCount), |
101 | | } EShLanguage; // would be better as stage, but this is ancient now |
102 | | |
103 | | typedef enum : unsigned { |
104 | | EShLangVertexMask = (1 << EShLangVertex), |
105 | | EShLangTessControlMask = (1 << EShLangTessControl), |
106 | | EShLangTessEvaluationMask = (1 << EShLangTessEvaluation), |
107 | | EShLangGeometryMask = (1 << EShLangGeometry), |
108 | | EShLangFragmentMask = (1 << EShLangFragment), |
109 | | EShLangComputeMask = (1 << EShLangCompute), |
110 | | EShLangRayGenMask = (1 << EShLangRayGen), |
111 | | EShLangRayGenNVMask = EShLangRayGenMask, |
112 | | EShLangIntersectMask = (1 << EShLangIntersect), |
113 | | EShLangIntersectNVMask = EShLangIntersectMask, |
114 | | EShLangAnyHitMask = (1 << EShLangAnyHit), |
115 | | EShLangAnyHitNVMask = EShLangAnyHitMask, |
116 | | EShLangClosestHitMask = (1 << EShLangClosestHit), |
117 | | EShLangClosestHitNVMask = EShLangClosestHitMask, |
118 | | EShLangMissMask = (1 << EShLangMiss), |
119 | | EShLangMissNVMask = EShLangMissMask, |
120 | | EShLangCallableMask = (1 << EShLangCallable), |
121 | | EShLangCallableNVMask = EShLangCallableMask, |
122 | | EShLangTaskMask = (1 << EShLangTask), |
123 | | EShLangTaskNVMask = EShLangTaskMask, |
124 | | EShLangMeshMask = (1 << EShLangMesh), |
125 | | EShLangMeshNVMask = EShLangMeshMask, |
126 | | LAST_ELEMENT_MARKER(EShLanguageMaskCount), |
127 | | } EShLanguageMask; |
128 | | |
129 | | namespace glslang { |
130 | | |
131 | | class TType; |
132 | | |
133 | | typedef enum { |
134 | | EShSourceNone, |
135 | | EShSourceGlsl, // GLSL, includes ESSL (OpenGL ES GLSL) |
136 | | EShSourceHlsl, // HLSL (deprecated, see issue #4210) |
137 | | LAST_ELEMENT_MARKER(EShSourceCount), |
138 | | } EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead |
139 | | |
140 | | typedef enum { |
141 | | EShClientNone, // use when there is no client, e.g. for validation |
142 | | EShClientVulkan, // as GLSL dialect, specifies KHR_vulkan_glsl extension |
143 | | EShClientOpenGL, // as GLSL dialect, specifies ARB_gl_spirv extension |
144 | | LAST_ELEMENT_MARKER(EShClientCount), |
145 | | } EShClient; |
146 | | |
147 | | typedef enum { |
148 | | EShTargetNone, |
149 | | EShTargetSpv, // SPIR-V (preferred spelling) |
150 | | EshTargetSpv = EShTargetSpv, // legacy spelling |
151 | | LAST_ELEMENT_MARKER(EShTargetCount), |
152 | | } EShTargetLanguage; |
153 | | |
154 | | typedef enum { |
155 | | EShTargetVulkan_1_0 = (1 << 22), // Vulkan 1.0 |
156 | | EShTargetVulkan_1_1 = (1 << 22) | (1 << 12), // Vulkan 1.1 |
157 | | EShTargetVulkan_1_2 = (1 << 22) | (2 << 12), // Vulkan 1.2 |
158 | | EShTargetVulkan_1_3 = (1 << 22) | (3 << 12), // Vulkan 1.3 |
159 | | EShTargetVulkan_1_4 = (1 << 22) | (4 << 12), // Vulkan 1.4 |
160 | | EShTargetOpenGL_450 = 450, // OpenGL |
161 | | LAST_ELEMENT_MARKER(EShTargetClientVersionCount = 6), |
162 | | } EShTargetClientVersion; |
163 | | |
164 | | typedef EShTargetClientVersion EshTargetClientVersion; |
165 | | |
166 | | typedef enum { |
167 | | EShTargetSpv_1_0 = (1 << 16), // SPIR-V 1.0 |
168 | | EShTargetSpv_1_1 = (1 << 16) | (1 << 8), // SPIR-V 1.1 |
169 | | EShTargetSpv_1_2 = (1 << 16) | (2 << 8), // SPIR-V 1.2 |
170 | | EShTargetSpv_1_3 = (1 << 16) | (3 << 8), // SPIR-V 1.3 |
171 | | EShTargetSpv_1_4 = (1 << 16) | (4 << 8), // SPIR-V 1.4 |
172 | | EShTargetSpv_1_5 = (1 << 16) | (5 << 8), // SPIR-V 1.5 |
173 | | EShTargetSpv_1_6 = (1 << 16) | (6 << 8), // SPIR-V 1.6 |
174 | | LAST_ELEMENT_MARKER(EShTargetLanguageVersionCount = 7), |
175 | | } EShTargetLanguageVersion; |
176 | | |
177 | | // |
178 | | // Following are a series of helper enums for managing layouts and qualifiers, |
179 | | // used for TPublicType, TType, others. |
180 | | // |
181 | | |
182 | | enum TLayoutPacking { |
183 | | ElpNone, |
184 | | ElpShared, // default, but different than saying nothing |
185 | | ElpStd140, |
186 | | ElpStd430, |
187 | | ElpPacked, |
188 | | ElpScalar, |
189 | | ElpCount // If expanding, see bitfield width below |
190 | | }; |
191 | | |
192 | | struct TInputLanguage { |
193 | | EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone |
194 | | EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone |
195 | | EShClient dialect; |
196 | | int dialectVersion; // version of client's language definition, not the client (when not EShClientNone) |
197 | | bool vulkanRulesRelaxed; |
198 | | }; |
199 | | |
200 | | struct TClient { |
201 | | EShClient client; |
202 | | EShTargetClientVersion version; // version of client itself (not the client's input dialect) |
203 | | }; |
204 | | |
205 | | struct TTarget { |
206 | | EShTargetLanguage language; |
207 | | EShTargetLanguageVersion version; // version to target, if SPIR-V, defined by "word 1" of the SPIR-V header |
208 | | bool hlslFunctionality1; // can target hlsl_functionality1 extension(s) |
209 | | }; |
210 | | |
211 | | // All source/client/target versions and settings. |
212 | | // Can override previous methods of setting, when items are set here. |
213 | | // Expected to grow, as more are added, rather than growing parameter lists. |
214 | | struct TEnvironment { |
215 | | TInputLanguage input; // definition of the input language |
216 | | TClient client; // what client is the overall compilation being done for? |
217 | | TTarget target; // what to generate |
218 | | }; |
219 | | |
220 | | GLSLANG_EXPORT const char* StageName(EShLanguage); |
221 | | |
222 | | } // end namespace glslang |
223 | | |
224 | | // |
225 | | // Types of output the linker will create. |
226 | | // |
227 | | typedef enum { |
228 | | EShExVertexFragment, |
229 | | EShExFragment |
230 | | } EShExecutable; |
231 | | |
232 | | // |
233 | | // Optimization level for the compiler. |
234 | | // |
235 | | typedef enum { |
236 | | EShOptNoGeneration, |
237 | | EShOptNone, |
238 | | EShOptSimple, // Optimizations that can be done quickly |
239 | | EShOptFull, // Optimizations that will take more time |
240 | | LAST_ELEMENT_MARKER(EshOptLevelCount), |
241 | | } EShOptimizationLevel; |
242 | | |
243 | | // |
244 | | // Texture and Sampler transformation mode. |
245 | | // |
246 | | typedef enum { |
247 | | EShTexSampTransKeep, // keep textures and samplers as is (default) |
248 | | EShTexSampTransUpgradeTextureRemoveSampler, // change texture w/o embeded sampler into sampled texture and throw away all samplers |
249 | | LAST_ELEMENT_MARKER(EShTexSampTransCount), |
250 | | } EShTextureSamplerTransformMode; |
251 | | |
252 | | // |
253 | | // Message choices for what errors and warnings are given. |
254 | | // |
255 | | enum EShMessages : unsigned { |
256 | | EShMsgDefault = 0, // default is to give all required errors and extra warnings |
257 | | EShMsgRelaxedErrors = (1 << 0), // be liberal in accepting input |
258 | | EShMsgSuppressWarnings = (1 << 1), // suppress all warnings, except those required by the specification |
259 | | EShMsgAST = (1 << 2), // print the AST intermediate representation |
260 | | EShMsgSpvRules = (1 << 3), // issue messages for SPIR-V generation |
261 | | EShMsgVulkanRules = (1 << 4), // issue messages for Vulkan-requirements of GLSL for SPIR-V |
262 | | EShMsgOnlyPreprocessor = (1 << 5), // only print out errors produced by the preprocessor |
263 | | EShMsgReadHlsl = (1 << 6), // use HLSL parsing rules and semantics (deprecated, see issue #4210) |
264 | | EShMsgCascadingErrors = (1 << 7), // get cascading errors; risks error-recovery issues, instead of an early exit |
265 | | EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions |
266 | | EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules (deprecated, see issue #4210) |
267 | | EShMsgDebugInfo = (1 << 10), // save debug information |
268 | | EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL (deprecated, see issue #4210) |
269 | | EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages (deprecated, see issue #4210) |
270 | | EShMsgHlslDX9Compatible = (1 << 13), // enable HLSL DX9 compatible mode (for samplers and semantics) (deprecated, see issue #4210) |
271 | | EShMsgBuiltinSymbolTable = (1 << 14), // print the builtin symbol table |
272 | | EShMsgEnhanced = (1 << 15), // enhanced message readability |
273 | | EShMsgAbsolutePath = (1 << 16), // Output Absolute path for messages |
274 | | EShMsgDisplayErrorColumn = (1 << 17), // Display error message column aswell as line |
275 | | EShMsgLinkTimeOptimization = (1 << 18), // perform cross-stage optimizations during linking |
276 | | EShMsgValidateCrossStageIO = (1 << 19), // validate shader inputs have matching outputs in previous stage |
277 | | EShMsgRelaxSetBindingLimits = (1 << 20), // relax layout(set/binding) limits |
278 | | LAST_ELEMENT_MARKER(EShMsgCount), |
279 | | }; |
280 | | |
281 | | // |
282 | | // Options for building reflection |
283 | | // |
284 | | typedef enum { |
285 | | EShReflectionDefault = 0, // default is original behaviour before options were added |
286 | | EShReflectionStrictArraySuffix = (1 << 0), // reflection will follow stricter rules for array-of-structs suffixes |
287 | | EShReflectionBasicArraySuffix = (1 << 1), // arrays of basic types will be appended with [0] as in GL reflection |
288 | | EShReflectionIntermediateIO = (1 << 2), // reflect inputs and outputs to program, even with no vertex shader |
289 | | EShReflectionSeparateBuffers = (1 << 3), // buffer variables and buffer blocks are reflected separately |
290 | | EShReflectionAllBlockVariables = (1 << 4), // reflect all variables in blocks, even if they are inactive |
291 | | EShReflectionUnwrapIOBlocks = (1 << 5), // unwrap input/output blocks the same as with uniform blocks |
292 | | EShReflectionAllIOVariables = (1 << 6), // reflect all input/output variables, even if they are inactive |
293 | | EShReflectionSharedStd140SSBO = (1 << 7), // Apply std140/shared rules for ubo to ssbo |
294 | | EShReflectionSharedStd140UBO = (1 << 8), // Apply std140/shared rules for ubo to ssbo |
295 | | LAST_ELEMENT_MARKER(EShReflectionCount), |
296 | | } EShReflectionOptions; |
297 | | |
298 | | // |
299 | | // Build a table for bindings. This can be used for locating |
300 | | // attributes, uniforms, globals, etc., as needed. |
301 | | // |
302 | | typedef struct { |
303 | | const char* name; |
304 | | int binding; |
305 | | } ShBinding; |
306 | | |
307 | | typedef struct { |
308 | | int numBindings; |
309 | | ShBinding* bindings; // array of bindings |
310 | | } ShBindingTable; |
311 | | |
312 | | // |
313 | | // ShHandle held by but opaque to the driver. It is allocated, |
314 | | // managed, and de-allocated by the compiler/linker. Its contents |
315 | | // are defined by and used by the compiler and linker. For example, |
316 | | // symbol table information and object code passed from the compiler |
317 | | // to the linker can be stored where ShHandle points. |
318 | | // |
319 | | // If handle creation fails, 0 will be returned. |
320 | | // |
321 | | typedef void* ShHandle; |
322 | | |
323 | | // |
324 | | // Driver calls these to create and destroy compiler/linker |
325 | | // objects. |
326 | | // |
327 | | GLSLANG_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int /*debugOptions unused*/); // one per shader |
328 | | GLSLANG_EXPORT ShHandle ShConstructLinker(const EShExecutable, int /*debugOptions unused*/); // one per shader pair |
329 | | GLSLANG_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object) |
330 | | GLSLANG_EXPORT void ShDestruct(ShHandle); |
331 | | |
332 | | // |
333 | | // The return value of ShCompile is boolean, non-zero indicating |
334 | | // success. |
335 | | // |
336 | | // The info-log should be written by ShCompile into |
337 | | // ShHandle, so it can answer future queries. |
338 | | // |
339 | | GLSLANG_EXPORT int ShCompile(const ShHandle, const char* const shaderStrings[], const int numStrings, |
340 | | const int* lengths, const EShOptimizationLevel, const TBuiltInResource* resources, |
341 | | int, // debugOptions unused |
342 | | int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader |
343 | | bool forwardCompatible = false, // give errors for use of deprecated features |
344 | | EShMessages messages = EShMsgDefault, // warnings and errors |
345 | | const char* fileName = nullptr |
346 | | ); |
347 | | |
348 | | GLSLANG_EXPORT int ShLinkExt( |
349 | | const ShHandle, // linker object |
350 | | const ShHandle h[], // compiler objects to link together |
351 | | const int numHandles); |
352 | | |
353 | | // |
354 | | // ShSetEncrpytionMethod is a place-holder for specifying |
355 | | // how source code is encrypted. |
356 | | // |
357 | | GLSLANG_EXPORT void ShSetEncryptionMethod(ShHandle); |
358 | | |
359 | | // |
360 | | // All the following return 0 if the information is not |
361 | | // available in the object passed down, or the object is bad. |
362 | | // |
363 | | GLSLANG_EXPORT const char* ShGetInfoLog(const ShHandle); |
364 | | GLSLANG_EXPORT const void* ShGetExecutable(const ShHandle); |
365 | | GLSLANG_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing |
366 | | GLSLANG_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings |
367 | | // |
368 | | // Tell the linker to never assign a vertex attribute to this list of physical attributes |
369 | | // |
370 | | GLSLANG_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count); |
371 | | |
372 | | // |
373 | | // Returns the location ID of the named uniform. |
374 | | // Returns -1 if error. |
375 | | // |
376 | | GLSLANG_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name); |
377 | | |
378 | | #ifdef __cplusplus |
379 | | } // end extern "C" |
380 | | #endif |
381 | | |
382 | | //////////////////////////////////////////////////////////////////////////////////////////// |
383 | | // |
384 | | // Deferred-Lowering C++ Interface |
385 | | // ----------------------------------- |
386 | | // |
387 | | // Below is a new alternate C++ interface, which deprecates the above |
388 | | // opaque handle-based interface. |
389 | | // |
390 | | // The below is further designed to handle multiple compilation units per stage, where |
391 | | // the intermediate results, including the parse tree, are preserved until link time, |
392 | | // rather than the above interface which is designed to have each compilation unit |
393 | | // lowered at compile time. In the above model, linking occurs on the lowered results, |
394 | | // whereas in this model intra-stage linking can occur at the parse tree |
395 | | // (treeRoot in TIntermediate) level, and then a full stage can be lowered. |
396 | | // |
397 | | |
398 | | #include <list> |
399 | | #include <string> |
400 | | #include <utility> |
401 | | |
402 | | class TCompiler; |
403 | | class TInfoSink; |
404 | | |
405 | | namespace glslang { |
406 | | |
407 | | struct Version { |
408 | | int major; |
409 | | int minor; |
410 | | int patch; |
411 | | const char* flavor; |
412 | | }; |
413 | | |
414 | | GLSLANG_EXPORT Version GetVersion(); |
415 | | GLSLANG_EXPORT const char* GetEsslVersionString(); |
416 | | GLSLANG_EXPORT const char* GetGlslVersionString(); |
417 | | GLSLANG_EXPORT int GetKhronosToolId(); |
418 | | |
419 | | class TIntermediate; |
420 | | class TProgram; |
421 | | class TPoolAllocator; |
422 | | class TIoMapResolver; |
423 | | |
424 | | // Call this exactly once per process before using anything else |
425 | | GLSLANG_EXPORT bool InitializeProcess(); |
426 | | |
427 | | // Call once per process to tear down everything |
428 | | GLSLANG_EXPORT void FinalizeProcess(); |
429 | | |
430 | | // Resource type for IO resolver |
431 | | enum TResourceType { |
432 | | EResSampler, |
433 | | EResTexture, |
434 | | EResImage, |
435 | | EResUbo, |
436 | | EResSsbo, |
437 | | EResUav, |
438 | | EResCombinedSampler, |
439 | | EResAs, |
440 | | EResTensor, |
441 | | EResCount |
442 | | }; |
443 | | |
444 | | enum TBlockStorageClass |
445 | | { |
446 | | EbsUniform = 0, |
447 | | EbsStorageBuffer, |
448 | | EbsPushConstant, |
449 | | EbsNone, // not a uniform or buffer variable |
450 | | EbsCount, |
451 | | }; |
452 | | |
453 | | // Make one TShader per shader that you will link into a program. Then |
454 | | // - provide the shader through setStrings() or setStringsWithLengths() |
455 | | // - optionally call setEnv*(), see below for more detail |
456 | | // - optionally use setPreamble() to set a special shader string that will be |
457 | | // processed before all others but won't affect the validity of #version |
458 | | // - optionally call addProcesses() for each setting/transform, |
459 | | // see comment for class TProcesses |
460 | | // - call parse(): source language and target environment must be selected |
461 | | // either by correct setting of EShMessages sent to parse(), or by |
462 | | // explicitly calling setEnv*() |
463 | | // - query the info logs |
464 | | // |
465 | | // N.B.: Does not yet support having the same TShader instance being linked into |
466 | | // multiple programs. |
467 | | // |
468 | | // N.B.: Destruct a linked program *before* destructing the shaders linked into it. |
469 | | // |
470 | | class GLSLANG_EXPORT TShader { |
471 | | public: |
472 | | explicit TShader(EShLanguage); |
473 | | virtual ~TShader(); |
474 | | void setStrings(const char* const* s, int n); |
475 | | void setStringsWithLengths( |
476 | | const char* const* s, const int* l, int n); |
477 | | void setStringsWithLengthsAndNames( |
478 | | const char* const* s, const int* l, const char* const* names, int n); |
479 | 11.0k | void setPreamble(const char* s) { preamble = s; } |
480 | | void setEntryPoint(const char* entryPoint); |
481 | | void setSourceEntryPoint(const char* sourceEntryPointName); |
482 | | void addProcesses(const std::vector<std::string>&); |
483 | | void setUniqueId(unsigned long long id); |
484 | | void setOverrideVersion(int version); |
485 | | void setDebugInfo(bool debugInfo); |
486 | | |
487 | | // IO resolver binding data: see comments in ShaderLang.cpp |
488 | | void setShiftBinding(TResourceType res, unsigned int base); |
489 | | void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding |
490 | | void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding |
491 | | void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding |
492 | | void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding |
493 | | void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding |
494 | | void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding |
495 | | void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding |
496 | | void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set); |
497 | | void setResourceSetBinding(const std::vector<std::string>& base); |
498 | | void setAutoMapBindings(bool map); |
499 | | void setAutoMapLocations(bool map); |
500 | | void setBindingsPerResourceType(); |
501 | | void addUniformLocationOverride(const char* name, int loc); |
502 | | void setUniformLocationBase(int base); |
503 | | void setInvertY(bool invert); |
504 | | void setDxPositionW(bool dxPosW); |
505 | | void setEnhancedMsgs(); |
506 | | #ifdef ENABLE_HLSL |
507 | | void setHlslIoMapping(bool hlslIoMap); // deprecated, see issue #4210 |
508 | | void setFlattenUniformArrays(bool flatten); // deprecated, see issue #4210 |
509 | | #endif |
510 | | void setNoStorageFormat(bool useUnknownFormat); |
511 | | void setNanMinMaxClamp(bool nanMinMaxClamp); |
512 | | void setDiscardIsTerminate(bool discardIsTerminate); |
513 | | void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode); |
514 | | void addBlockStorageOverride(const char* nameStr, glslang::TBlockStorageClass backing); |
515 | | |
516 | | void setGlobalUniformBlockName(const char* name); |
517 | | void setAtomicCounterBlockName(const char* name); |
518 | | void setGlobalUniformSet(unsigned int set); |
519 | | void setGlobalUniformBinding(unsigned int binding); |
520 | | void setAtomicCounterBlockSet(unsigned int set); |
521 | | void setAtomicCounterBlockBinding(unsigned int binding); |
522 | | |
523 | | void addSourceText(const char* text, size_t len); |
524 | | void setSourceFile(const char* file); |
525 | | |
526 | | // For setting up the environment (cleared to nothingness in the constructor). |
527 | | // These must be called so that parsing is done for the right source language and |
528 | | // target environment, either indirectly through TranslateEnvironment() based on |
529 | | // EShMessages et. al., or directly by the user. |
530 | | // |
531 | | // setEnvInput: The input source language and stage. If generating code for a |
532 | | // specific client, the input client semantics to use and the |
533 | | // version of that client's input semantics to use, otherwise |
534 | | // use EShClientNone and version of 0, e.g. for validation mode. |
535 | | // Note 'version' does not describe the target environment, |
536 | | // just the version of the source dialect to compile under. |
537 | | // For example, to choose the Vulkan dialect of GLSL defined by |
538 | | // version 100 of the KHR_vulkan_glsl extension: lang = EShSourceGlsl, |
539 | | // dialect = EShClientVulkan, and version = 100. |
540 | | // |
541 | | // See the definitions of TEnvironment, EShSource, EShLanguage, |
542 | | // and EShClient for choices and more detail. |
543 | | // |
544 | | // setEnvClient: The client that will be hosting the execution, and its version. |
545 | | // Note 'version' is not the version of the languages involved, but |
546 | | // the version of the client environment. |
547 | | // Use EShClientNone and version of 0 if there is no client, e.g. |
548 | | // for validation mode. |
549 | | // |
550 | | // See EShTargetClientVersion for choices. |
551 | | // |
552 | | // setEnvTarget: The language to translate to when generating code, and that |
553 | | // language's version. |
554 | | // Use EShTargetNone and version of 0 if there is no client, e.g. |
555 | | // for validation mode. |
556 | | // |
557 | | void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version) |
558 | 0 | { |
559 | 0 | environment.input.languageFamily = lang; |
560 | 0 | environment.input.stage = envStage; |
561 | 0 | environment.input.dialect = client; |
562 | 0 | environment.input.dialectVersion = version; |
563 | 0 | } |
564 | | void setEnvClient(EShClient client, EShTargetClientVersion version) |
565 | 11.0k | { |
566 | 11.0k | environment.client.client = client; |
567 | 11.0k | environment.client.version = version; |
568 | 11.0k | } |
569 | | void setEnvTarget(EShTargetLanguage lang, EShTargetLanguageVersion version) |
570 | 5.56k | { |
571 | 5.56k | environment.target.language = lang; |
572 | 5.56k | environment.target.version = version; |
573 | 5.56k | } |
574 | | |
575 | 0 | void getStrings(const char* const* &s, int& n) { s = strings; n = numStrings; } |
576 | | |
577 | | #ifdef ENABLE_HLSL |
578 | 2.04k | void setEnvTargetHlslFunctionality1() { environment.target.hlslFunctionality1 = true; } // deprecated, see issue #4210 |
579 | | bool getEnvTargetHlslFunctionality1() const { return environment.target.hlslFunctionality1; } // deprecated, see issue #4210 |
580 | | #else |
581 | 0 | bool getEnvTargetHlslFunctionality1() const { return false; } |
582 | | #endif |
583 | | |
584 | 0 | void setEnvInputVulkanRulesRelaxed() { environment.input.vulkanRulesRelaxed = true; } |
585 | 0 | bool getEnvInputVulkanRulesRelaxed() const { return environment.input.vulkanRulesRelaxed; } |
586 | | |
587 | 0 | void setCompileOnly() { compileOnly = true; } |
588 | 0 | bool getCompileOnly() const { return compileOnly; } |
589 | | |
590 | | // Interface to #include handlers. |
591 | | // |
592 | | // To support #include, a client of Glslang does the following: |
593 | | // 1. Call setStringsWithNames to set the source strings and associated |
594 | | // names. For example, the names could be the names of the files |
595 | | // containing the shader sources. |
596 | | // 2. Call parse with an Includer. |
597 | | // |
598 | | // When the Glslang parser encounters an #include directive, it calls |
599 | | // the Includer's include method with the requested include name |
600 | | // together with the current string name. The returned IncludeResult |
601 | | // contains the fully resolved name of the included source, together |
602 | | // with the source text that should replace the #include directive |
603 | | // in the source stream. After parsing that source, Glslang will |
604 | | // release the IncludeResult object. |
605 | | class Includer { |
606 | | public: |
607 | | // An IncludeResult contains the resolved name and content of a source |
608 | | // inclusion. |
609 | | struct IncludeResult { |
610 | | IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) : |
611 | 1.20k | headerName(headerName), headerData(headerData), headerLength(headerLength), userData(userData) { } |
612 | | // For a successful inclusion, the fully resolved name of the requested |
613 | | // include. For example, in a file system-based includer, full resolution |
614 | | // should convert a relative path name into an absolute path name. |
615 | | // For a failed inclusion, this is an empty string. |
616 | | const std::string headerName; |
617 | | // The content and byte length of the requested inclusion. The |
618 | | // Includer producing this IncludeResult retains ownership of the |
619 | | // storage. |
620 | | // For a failed inclusion, the header |
621 | | // field points to a string containing error details. |
622 | | const char* const headerData; |
623 | | const size_t headerLength; |
624 | | // Include resolver's context. |
625 | | void* userData; |
626 | | protected: |
627 | | IncludeResult& operator=(const IncludeResult&); |
628 | | IncludeResult(); |
629 | | }; |
630 | | |
631 | | // For both include methods below: |
632 | | // |
633 | | // Resolves an inclusion request by name, current source name, |
634 | | // and include depth. |
635 | | // On success, returns an IncludeResult containing the resolved name |
636 | | // and content of the include. |
637 | | // On failure, returns a nullptr, or an IncludeResult |
638 | | // with an empty string for the headerName and error details in the |
639 | | // header field. |
640 | | // The Includer retains ownership of the contents |
641 | | // of the returned IncludeResult value, and those contents must |
642 | | // remain valid until the releaseInclude method is called on that |
643 | | // IncludeResult object. |
644 | | // |
645 | | // Note "local" vs. "system" is not an "either/or": "local" is an |
646 | | // extra thing to do over "system". Both might get called, as per |
647 | | // the C++ specification. |
648 | | |
649 | | // For the "system" or <>-style includes; search the "system" paths. |
650 | | virtual IncludeResult* includeSystem(const char* /*headerName*/, |
651 | | const char* /*includerName*/, |
652 | 0 | size_t /*inclusionDepth*/) { return nullptr; } |
653 | | |
654 | | // For the "local"-only aspect of a "" include. Should not search in the |
655 | | // "system" paths, because on returning a failure, the parser will |
656 | | // call includeSystem() to look in the "system" locations. |
657 | | virtual IncludeResult* includeLocal(const char* /*headerName*/, |
658 | | const char* /*includerName*/, |
659 | 0 | size_t /*inclusionDepth*/) { return nullptr; } |
660 | | |
661 | | // Signals that the parser will no longer use the contents of the |
662 | | // specified IncludeResult. |
663 | | virtual void releaseInclude(IncludeResult*) = 0; |
664 | 10.9k | virtual ~Includer() {} |
665 | | }; |
666 | | |
667 | | // Fail all Includer searches |
668 | | class ForbidIncluder : public Includer { |
669 | | public: |
670 | 0 | virtual void releaseInclude(IncludeResult*) override { } |
671 | | }; |
672 | | |
673 | | bool parse( |
674 | | const TBuiltInResource*, int defaultVersion, EProfile defaultProfile, |
675 | | bool forceDefaultVersionAndProfile, bool forwardCompatible, |
676 | | EShMessages, Includer&); |
677 | | |
678 | | bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile, |
679 | | bool forwardCompatible, EShMessages messages) |
680 | 0 | { |
681 | 0 | TShader::ForbidIncluder includer; |
682 | 0 | return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer); |
683 | 0 | } |
684 | | |
685 | | // Equivalent to parse() without a default profile and without forcing defaults. |
686 | | bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages) |
687 | 0 | { |
688 | 0 | return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages); |
689 | 0 | } |
690 | | |
691 | | bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages, |
692 | | Includer& includer) |
693 | 0 | { |
694 | 0 | return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages, includer); |
695 | 0 | } |
696 | | |
697 | | // NOTE: Doing just preprocessing to obtain a correct preprocessed shader string |
698 | | // is not an officially supported or fully working path. |
699 | | bool preprocess( |
700 | | const TBuiltInResource* builtInResources, int defaultVersion, |
701 | | EProfile defaultProfile, bool forceDefaultVersionAndProfile, |
702 | | bool forwardCompatible, EShMessages message, std::string* outputString, |
703 | | Includer& includer); |
704 | | |
705 | | const char* getInfoLog(); |
706 | | const char* getInfoDebugLog(); |
707 | 0 | EShLanguage getStage() const { return stage; } |
708 | 0 | TIntermediate* getIntermediate() const { return intermediate; } |
709 | | |
710 | | protected: |
711 | | TPoolAllocator* pool; |
712 | | EShLanguage stage; |
713 | | TCompiler* compiler; |
714 | | TIntermediate* intermediate; |
715 | | TInfoSink* infoSink; |
716 | | // strings and lengths follow the standard for glShaderSource: |
717 | | // strings is an array of numStrings pointers to string data. |
718 | | // lengths can be null, but if not it is an array of numStrings |
719 | | // integers containing the length of the associated strings. |
720 | | // if lengths is null or lengths[n] < 0 the associated strings[n] is |
721 | | // assumed to be null-terminated. |
722 | | // stringNames is the optional names for all the strings. If stringNames |
723 | | // is null, then none of the strings has name. If a certain element in |
724 | | // stringNames is null, then the corresponding string does not have name. |
725 | | const char* const* strings; // explicit code to compile, see previous comment |
726 | | const int* lengths; |
727 | | const char* const* stringNames; |
728 | | int numStrings; // size of the above arrays |
729 | | const char* preamble; // string of implicit code to compile before the explicitly provided code |
730 | | |
731 | | // a function in the source string can be renamed FROM this TO the name given in setEntryPoint. |
732 | | std::string sourceEntryPointName; |
733 | | |
734 | | // overrides #version in shader source or default version if #version isn't present |
735 | | int overrideVersion; |
736 | | |
737 | | TEnvironment environment; |
738 | | |
739 | | // Indicates this shader is meant to be used without linking |
740 | | bool compileOnly = false; |
741 | | |
742 | | friend class TProgram; |
743 | | |
744 | | private: |
745 | | TShader& operator=(TShader&); |
746 | | }; |
747 | | |
748 | | // |
749 | | // A reflection database and its interface, consistent with the OpenGL API reflection queries. |
750 | | // |
751 | | |
752 | | // Data needed for just a single object at the granularity exchanged by the reflection API |
753 | | class GLSLANG_EXPORT TObjectReflection { |
754 | | public: |
755 | | TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex); |
756 | | |
757 | 0 | const TType* getType() const { return type; } |
758 | | int getBinding() const; |
759 | | void dump() const; |
760 | 0 | static TObjectReflection badReflection() { return TObjectReflection(); } |
761 | | |
762 | | unsigned int layoutLocation() const; |
763 | | |
764 | | std::string name; |
765 | | int offset; |
766 | | int glDefineType; |
767 | | int size; // data size in bytes for a block, array size for a (non-block) object that's an array |
768 | | int index; |
769 | | int counterIndex; |
770 | | int numMembers; |
771 | | int arrayStride; // stride of an array variable |
772 | | int topLevelArraySize; // size of the top-level variable in a storage buffer member |
773 | | int topLevelArrayStride; // stride of the top-level variable in a storage buffer member |
774 | | EShLanguageMask stages; |
775 | | |
776 | | protected: |
777 | | TObjectReflection() |
778 | | : offset(-1), glDefineType(-1), size(-1), index(-1), counterIndex(-1), numMembers(-1), arrayStride(0), |
779 | | topLevelArrayStride(0), stages(EShLanguageMask(0)), type(nullptr) |
780 | 0 | { |
781 | 0 | } |
782 | | |
783 | | const TType* type; |
784 | | }; |
785 | | |
786 | | class TReflection; |
787 | | class TIoMapper; |
788 | | class TIntermSymbol; |
789 | | |
790 | | struct GLSLANG_EXPORT TVarEntryInfo { |
791 | | long long id; |
792 | | TIntermSymbol* symbol; |
793 | | bool live; |
794 | | TLayoutPacking upgradedToPushConstantPacking; // ElpNone means it hasn't been upgraded |
795 | | int newBinding; |
796 | | int newSet; |
797 | | int newLocation; |
798 | | int newComponent; |
799 | | int newIndex; |
800 | | EShLanguage stage; |
801 | | |
802 | 0 | void clearNewAssignments() { |
803 | 0 | upgradedToPushConstantPacking = ElpNone; |
804 | 0 | newBinding = -1; |
805 | 0 | newSet = -1; |
806 | 0 | newLocation = -1; |
807 | 0 | newComponent = -1; |
808 | 0 | newIndex = -1; |
809 | 0 | } |
810 | | |
811 | | struct TOrderById { |
812 | 0 | inline bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r) { return l.id < r.id; } |
813 | | }; |
814 | | |
815 | | struct TOrderByPriority { |
816 | | // ordering: |
817 | | // 1) has both binding and set |
818 | | // 2) has binding but no set |
819 | | // 3) has no binding but set |
820 | | // 4) has no binding and no set |
821 | | bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r); |
822 | | }; |
823 | | |
824 | | struct TOrderByPriorityAndLive { |
825 | | // ordering: |
826 | | // 1) do live variables first |
827 | | // 2) has both binding and set |
828 | | // 3) has binding but no set |
829 | | // 4) has no binding but set |
830 | | // 5) has no binding and no set |
831 | | bool operator()(const TVarEntryInfo& l, const TVarEntryInfo& r); |
832 | | }; |
833 | | }; |
834 | | |
835 | | |
836 | | // Allows to customize the binding layout after linking. |
837 | | // All used uniform variables will invoke at least validateBinding. |
838 | | // If validateBinding returned true then the other resolveBinding, |
839 | | // resolveSet, and resolveLocation are invoked to resolve the binding |
840 | | // and descriptor set index respectively. |
841 | | // |
842 | | // Invocations happen in a particular order: |
843 | | // 1) all shader inputs |
844 | | // 2) all shader outputs |
845 | | // 3) all uniforms with binding and set already defined |
846 | | // 4) all uniforms with binding but no set defined |
847 | | // 5) all uniforms with set but no binding defined |
848 | | // 6) all uniforms with no binding and no set defined |
849 | | // |
850 | | // mapIO will use this resolver in two phases. The first |
851 | | // phase is a notification phase, calling the corresponging |
852 | | // notifiy callbacks, this phase ends with a call to endNotifications. |
853 | | // Phase two starts directly after the call to endNotifications |
854 | | // and calls all other callbacks to validate and to get the |
855 | | // bindings, sets, locations, component and color indices. |
856 | | // |
857 | | // NOTE: that still limit checks are applied to bindings and sets |
858 | | // and may result in an error. |
859 | | class GLSLANG_EXPORT TIoMapResolver { |
860 | | public: |
861 | 0 | virtual ~TIoMapResolver() {} |
862 | | |
863 | | // Should return true if the resulting/current binding would be okay. |
864 | | // Basic idea is to do aliasing binding checks with this. |
865 | | virtual bool validateBinding(EShLanguage stage, TVarEntryInfo& ent) = 0; |
866 | | // Should return a value >= 0 if the current binding should be overridden. |
867 | | // Return -1 if the current binding (including no binding) should be kept. |
868 | | virtual int resolveBinding(EShLanguage stage, TVarEntryInfo& ent) = 0; |
869 | | // Should return a value >= 0 if the current set should be overridden. |
870 | | // Return -1 if the current set (including no set) should be kept. |
871 | | virtual int resolveSet(EShLanguage stage, TVarEntryInfo& ent) = 0; |
872 | | // Should return a value >= 0 if the current location should be overridden. |
873 | | // Return -1 if the current location (including no location) should be kept. |
874 | | virtual int resolveUniformLocation(EShLanguage stage, TVarEntryInfo& ent) = 0; |
875 | | // Should return true if the resulting/current setup would be okay. |
876 | | // Basic idea is to do aliasing checks and reject invalid semantic names. |
877 | | virtual bool validateInOut(EShLanguage stage, TVarEntryInfo& ent) = 0; |
878 | | // Should return a value >= 0 if the current location should be overridden. |
879 | | // Return -1 if the current location (including no location) should be kept. |
880 | | virtual int resolveInOutLocation(EShLanguage stage, TVarEntryInfo& ent) = 0; |
881 | | // Should return a value >= 0 if the current component index should be overridden. |
882 | | // Return -1 if the current component index (including no index) should be kept. |
883 | | virtual int resolveInOutComponent(EShLanguage stage, TVarEntryInfo& ent) = 0; |
884 | | // Should return a value >= 0 if the current color index should be overridden. |
885 | | // Return -1 if the current color index (including no index) should be kept. |
886 | | virtual int resolveInOutIndex(EShLanguage stage, TVarEntryInfo& ent) = 0; |
887 | | // Notification of a uniform variable |
888 | | virtual void notifyBinding(EShLanguage stage, TVarEntryInfo& ent) = 0; |
889 | | // Notification of a in or out variable |
890 | | virtual void notifyInOut(EShLanguage stage, TVarEntryInfo& ent) = 0; |
891 | | // Called by mapIO when it starts its notify pass for the given stage |
892 | | virtual void beginNotifications(EShLanguage stage) = 0; |
893 | | // Called by mapIO when it has finished the notify pass |
894 | | virtual void endNotifications(EShLanguage stage) = 0; |
895 | | // Called by mipIO when it starts its resolve pass for the given stage |
896 | | virtual void beginResolve(EShLanguage stage) = 0; |
897 | | // Called by mapIO when it has finished the resolve pass |
898 | | virtual void endResolve(EShLanguage stage) = 0; |
899 | | // Called by mapIO when it starts its symbol collect for teh given stage |
900 | | virtual void beginCollect(EShLanguage stage) = 0; |
901 | | // Called by mapIO when it has finished the symbol collect |
902 | | virtual void endCollect(EShLanguage stage) = 0; |
903 | | // Called by TSlotCollector to resolve storage locations or bindings |
904 | | virtual void reserverStorageSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0; |
905 | | // Called by TSlotCollector to resolve resource locations or bindings |
906 | | virtual void reserverResourceSlot(TVarEntryInfo& ent, TInfoSink& infoSink) = 0; |
907 | | // Called by mapIO.addStage to set shader stage mask to mark a stage be added to this pipeline |
908 | | virtual void addStage(EShLanguage stage, TIntermediate& stageIntermediate) = 0; |
909 | | }; |
910 | | |
911 | | // I/O mapper |
912 | | class TIoMapper { |
913 | | public: |
914 | 0 | TIoMapper() {} |
915 | 0 | virtual ~TIoMapper() {} |
916 | | // grow the reflection stage by stage |
917 | | bool virtual addStage(EShLanguage, TIntermediate&, TInfoSink&, TIoMapResolver*); |
918 | 0 | bool virtual doMap(TIoMapResolver*, TInfoSink&) { return true; } |
919 | 0 | bool virtual setAutoPushConstantBlock(const char*, unsigned int, TLayoutPacking) { return false; } |
920 | | }; |
921 | | |
922 | | // Get the default GLSL IO mapper |
923 | | GLSLANG_EXPORT TIoMapper* GetGlslIoMapper(); |
924 | | |
925 | | // Make one TProgram per set of shaders that will get linked together. Add all |
926 | | // the shaders that are to be linked together. After calling shader.parse() |
927 | | // for all shaders, call link(). |
928 | | // |
929 | | // N.B.: Destruct a linked program *before* destructing the shaders linked into it. |
930 | | // |
931 | | class GLSLANG_EXPORT TProgram { |
932 | | public: |
933 | | TProgram(); |
934 | | virtual ~TProgram(); |
935 | 438 | void addShader(TShader* shader) { stages[shader->stage].push_back(shader); } |
936 | 0 | std::list<TShader*>& getShaders(EShLanguage stage) { return stages[stage]; } |
937 | | // Link Validation interface |
938 | | bool link(EShMessages); |
939 | | const char* getInfoLog(); |
940 | | const char* getInfoDebugLog(); |
941 | | |
942 | 436 | TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; } |
943 | | |
944 | | // Reflection Interface |
945 | | |
946 | | // call first, to do liveness analysis, index mapping, etc.; returns false on failure |
947 | | bool buildReflection(int opts = EShReflectionDefault); |
948 | | unsigned getLocalSize(int dim) const; // return dim'th local size |
949 | | unsigned getTileShadingRateQCOM(int dim) const; // return dim'th tile shading rate QCOM |
950 | | int getReflectionIndex(const char *name) const; |
951 | | int getReflectionPipeIOIndex(const char* name, const bool inOrOut) const; |
952 | | int getNumUniformVariables() const; |
953 | | const TObjectReflection& getUniform(int index) const; |
954 | | int getNumUniformBlocks() const; |
955 | | const TObjectReflection& getUniformBlock(int index) const; |
956 | | int getNumPipeInputs() const; |
957 | | const TObjectReflection& getPipeInput(int index) const; |
958 | | int getNumPipeOutputs() const; |
959 | | const TObjectReflection& getPipeOutput(int index) const; |
960 | | int getNumBufferVariables() const; |
961 | | const TObjectReflection& getBufferVariable(int index) const; |
962 | | int getNumBufferBlocks() const; |
963 | | const TObjectReflection& getBufferBlock(int index) const; |
964 | | int getNumAtomicCounters() const; |
965 | | const TObjectReflection& getAtomicCounter(int index) const; |
966 | | |
967 | | // Legacy Reflection Interface - expressed in terms of above interface |
968 | | |
969 | | // can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS) |
970 | 0 | int getNumLiveUniformVariables() const { return getNumUniformVariables(); } |
971 | | |
972 | | // can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS) |
973 | 0 | int getNumLiveUniformBlocks() const { return getNumUniformBlocks(); } |
974 | | |
975 | | // can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES) |
976 | 0 | int getNumLiveAttributes() const { return getNumPipeInputs(); } |
977 | | |
978 | | // can be used for glGetUniformIndices() |
979 | 0 | int getUniformIndex(const char *name) const { return getReflectionIndex(name); } |
980 | | |
981 | | int getPipeIOIndex(const char *name, const bool inOrOut) const |
982 | 0 | { return getReflectionPipeIOIndex(name, inOrOut); } |
983 | | |
984 | | // can be used for "name" part of glGetActiveUniform() |
985 | 0 | const char *getUniformName(int index) const { return getUniform(index).name.c_str(); } |
986 | | |
987 | | // returns the binding number |
988 | 0 | int getUniformBinding(int index) const { return getUniform(index).getBinding(); } |
989 | | |
990 | | // returns Shaders Stages where a Uniform is present |
991 | 0 | EShLanguageMask getUniformStages(int index) const { return getUniform(index).stages; } |
992 | | |
993 | | // can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX) |
994 | 0 | int getUniformBlockIndex(int index) const { return getUniform(index).index; } |
995 | | |
996 | | // can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE) |
997 | 0 | int getUniformType(int index) const { return getUniform(index).glDefineType; } |
998 | | |
999 | | // can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET) |
1000 | 0 | int getUniformBufferOffset(int index) const { return getUniform(index).offset; } |
1001 | | |
1002 | | // can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE) |
1003 | 0 | int getUniformArraySize(int index) const { return getUniform(index).size; } |
1004 | | |
1005 | | // returns a TType* |
1006 | 0 | const TType *getUniformTType(int index) const { return getUniform(index).getType(); } |
1007 | | |
1008 | | // can be used for glGetActiveUniformBlockName() |
1009 | 0 | const char *getUniformBlockName(int index) const { return getUniformBlock(index).name.c_str(); } |
1010 | | |
1011 | | // can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE) |
1012 | 0 | int getUniformBlockSize(int index) const { return getUniformBlock(index).size; } |
1013 | | |
1014 | | // returns the block binding number |
1015 | 0 | int getUniformBlockBinding(int index) const { return getUniformBlock(index).getBinding(); } |
1016 | | |
1017 | | // returns block index of associated counter. |
1018 | 0 | int getUniformBlockCounterIndex(int index) const { return getUniformBlock(index).counterIndex; } |
1019 | | |
1020 | | // returns a TType* |
1021 | 0 | const TType *getUniformBlockTType(int index) const { return getUniformBlock(index).getType(); } |
1022 | | |
1023 | | // can be used for glGetActiveAttrib() |
1024 | 0 | const char *getAttributeName(int index) const { return getPipeInput(index).name.c_str(); } |
1025 | | |
1026 | | // can be used for glGetActiveAttrib() |
1027 | 0 | int getAttributeType(int index) const { return getPipeInput(index).glDefineType; } |
1028 | | |
1029 | | // returns a TType* |
1030 | 0 | const TType *getAttributeTType(int index) const { return getPipeInput(index).getType(); } |
1031 | | |
1032 | | void dumpReflection(); |
1033 | | |
1034 | | // Get the IO resolver to use for mapIO |
1035 | | TIoMapResolver* getGlslIoResolver(EShLanguage stage); |
1036 | | |
1037 | | // I/O mapping: apply base offsets and map live unbound variables |
1038 | | // If resolver is not provided it uses the previous approach |
1039 | | // and respects auto assignment and offsets. |
1040 | | bool mapIO(TIoMapResolver* pResolver = nullptr, TIoMapper* pIoMapper = nullptr); |
1041 | | |
1042 | | protected: |
1043 | | bool linkStage(EShLanguage, EShMessages); |
1044 | | bool crossStageCheck(EShMessages); |
1045 | | |
1046 | | TPoolAllocator* pool; |
1047 | | std::list<TShader*> stages[EShLangCount]; |
1048 | | TIntermediate* intermediate[EShLangCount]; |
1049 | | bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage |
1050 | | TInfoSink* infoSink; |
1051 | | TReflection* reflection; |
1052 | | bool linked; |
1053 | | |
1054 | | private: |
1055 | | TProgram(TProgram&); |
1056 | | TProgram& operator=(TProgram&); |
1057 | | }; |
1058 | | |
1059 | | } // end namespace glslang |
1060 | | |
1061 | | #endif // _COMPILER_INTERFACE_INCLUDED_ |