RetroArch
ShaderLang.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2002-2005 3Dlabs Inc. Ltd.
3 // Copyright (C) 2013-2016 LunarG, Inc.
4 //
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
11 // Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 //
14 // Redistributions in binary form must reproduce the above
15 // copyright notice, this list of conditions and the following
16 // disclaimer in the documentation and/or other materials provided
17 // with the distribution.
18 //
19 // Neither the name of 3Dlabs Inc. Ltd. nor the names of its
20 // contributors may be used to endorse or promote products derived
21 // from this software without specific prior written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26 // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27 // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 // POSSIBILITY OF SUCH DAMAGE.
35 //
36 #ifndef _COMPILER_INTERFACE_INCLUDED_
37 #define _COMPILER_INTERFACE_INCLUDED_
38 
39 #include "../Include/ResourceLimits.h"
40 #include "../MachineIndependent/Versions.h"
41 
42 #include <cstring>
43 #include <vector>
44 
45 #ifdef _WIN32
46 #define C_DECL __cdecl
47 //#ifdef SH_EXPORTING
48 // #define SH_IMPORT_EXPORT __declspec(dllexport)
49 //#else
50 // #define SH_IMPORT_EXPORT __declspec(dllimport)
51 //#endif
52 #define SH_IMPORT_EXPORT
53 #else
54 #define SH_IMPORT_EXPORT
55 #ifndef __fastcall
56 #define __fastcall
57 #endif
58 #define C_DECL
59 #endif
60 
61 //
62 // This is the platform independent interface between an OGL driver
63 // and the shading language compiler/linker.
64 //
65 
66 #ifdef __cplusplus
67  extern "C" {
68 #endif
69 
70 // This should always increase, as some paths to do not consume
71 // a more major number.
72 // It should increment by one when new functionality is added.
73 #define GLSLANG_MINOR_VERSION 7
74 
75 //
76 // Call before doing any other compiler/linker operations.
77 //
78 // (Call once per process, not once per thread.)
79 //
81 
82 //
83 // Call this at process shutdown to clean up memory.
84 //
86 
87 //
88 // Types of languages the compiler can consume.
89 //
90 typedef enum {
98 } EShLanguage; // would be better as stage, but this is ancient now
99 
100 typedef enum {
108 
109 namespace glslang {
110 
111 class TType;
112 
113 typedef enum {
117 } EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead
118 
119 typedef enum {
123 } EShClient;
124 
125 typedef enum {
127  EShTargetSpv, // preferred spelling
128  EshTargetSpv = EShTargetSpv, // legacy spelling
130 
131 typedef enum {
132  EShTargetVulkan_1_0 = (1 << 22),
133  EShTargetVulkan_1_1 = (1 << 22) | (1 << 12),
136 
138 
139 typedef enum {
140  EShTargetSpv_1_0 = (1 << 16),
141  EShTargetSpv_1_3 = (1 << 16) | (3 << 8),
143 
145  EShSource languageFamily; // redundant information with other input, this one overrides when not EShSourceNone
146  EShLanguage stage; // redundant information with other input, this one overrides when not EShSourceNone
148  int dialectVersion; // version of client's language definition, not the client (when not EShClientNone)
149 };
150 
151 struct TClient {
153  EShTargetClientVersion version; // version of client itself (not the client's input dialect)
154 };
155 
156 struct TTarget {
158  EShTargetLanguageVersion version; // version to target, if SPIR-V, defined by "word 1" of the SPIR-V header
159  bool hlslFunctionality1; // can target hlsl_functionality1 extension(s)
160 };
161 
162 // All source/client/target versions and settings.
163 // Can override previous methods of setting, when items are set here.
164 // Expected to grow, as more are added, rather than growing parameter lists.
165 struct TEnvironment {
166  TInputLanguage input; // definition of the input language
167  TClient client; // what client is the overall compilation being done for?
168  TTarget target; // what to generate
169 };
170 
171 const char* StageName(EShLanguage);
172 
173 } // end namespace glslang
174 
175 //
176 // Types of output the linker will create.
177 //
178 typedef enum {
181 } EShExecutable;
182 
183 //
184 // Optimization level for the compiler.
185 //
186 typedef enum {
189  EShOptSimple, // Optimizations that can be done quickly
190  EShOptFull, // Optimizations that will take more time
192 
193 //
194 // Texture and Sampler transformation mode.
195 //
196 typedef enum {
197  EShTexSampTransKeep, // keep textures and samplers as is (default)
198  EShTexSampTransUpgradeTextureRemoveSampler, // change texture w/o embeded sampler into sampled texture and throw away all samplers
200 
201 //
202 // Message choices for what errors and warnings are given.
203 //
205  EShMsgDefault = 0, // default is to give all required errors and extra warnings
206  EShMsgRelaxedErrors = (1 << 0), // be liberal in accepting input
207  EShMsgSuppressWarnings = (1 << 1), // suppress all warnings, except those required by the specification
208  EShMsgAST = (1 << 2), // print the AST intermediate representation
209  EShMsgSpvRules = (1 << 3), // issue messages for SPIR-V generation
210  EShMsgVulkanRules = (1 << 4), // issue messages for Vulkan-requirements of GLSL for SPIR-V
211  EShMsgOnlyPreprocessor = (1 << 5), // only print out errors produced by the preprocessor
212  EShMsgReadHlsl = (1 << 6), // use HLSL parsing rules and semantics
213  EShMsgCascadingErrors = (1 << 7), // get cascading errors; risks error-recovery issues, instead of an early exit
214  EShMsgKeepUncalled = (1 << 8), // for testing, don't eliminate uncalled functions
215  EShMsgHlslOffsets = (1 << 9), // allow block offsets to follow HLSL rules instead of GLSL rules
216  EShMsgDebugInfo = (1 << 10), // save debug information
217  EShMsgHlslEnable16BitTypes = (1 << 11), // enable use of 16-bit types in SPIR-V for HLSL
218  EShMsgHlslLegalization = (1 << 12), // enable HLSL Legalization messages
219 };
220 
221 //
222 // Build a table for bindings. This can be used for locating
223 // attributes, uniforms, globals, etc., as needed.
224 //
225 typedef struct {
226  const char* name;
227  int binding;
228 } ShBinding;
229 
230 typedef struct {
232  ShBinding* bindings; // array of bindings
234 
235 //
236 // ShHandle held by but opaque to the driver. It is allocated,
237 // managed, and de-allocated by the compiler/linker. It's contents
238 // are defined by and used by the compiler and linker. For example,
239 // symbol table information and object code passed from the compiler
240 // to the linker can be stored where ShHandle points.
241 //
242 // If handle creation fails, 0 will be returned.
243 //
244 typedef void* ShHandle;
245 
246 //
247 // Driver calls these to create and destroy compiler/linker
248 // objects.
249 //
250 SH_IMPORT_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int debugOptions); // one per shader
251 SH_IMPORT_EXPORT ShHandle ShConstructLinker(const EShExecutable, int debugOptions); // one per shader pair
252 SH_IMPORT_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object)
254 
255 //
256 // The return value of ShCompile is boolean, non-zero indicating
257 // success.
258 //
259 // The info-log should be written by ShCompile into
260 // ShHandle, so it can answer future queries.
261 //
263  const ShHandle,
264  const char* const shaderStrings[],
265  const int numStrings,
266  const int* lengths,
267  const EShOptimizationLevel,
268  const TBuiltInResource *resources,
269  int debugOptions,
270  int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
271  bool forwardCompatible = false, // give errors for use of deprecated features
272  EShMessages messages = EShMsgDefault // warnings and errors
273  );
274 
276  const ShHandle, // linker object
277  const ShHandle h[], // compiler objects to link together
278  const int numHandles);
279 
280 //
281 // ShSetEncrpytionMethod is a place-holder for specifying
282 // how source code is encrypted.
283 //
285 
286 //
287 // All the following return 0 if the information is not
288 // available in the object passed down, or the object is bad.
289 //
290 SH_IMPORT_EXPORT const char* ShGetInfoLog(const ShHandle);
291 SH_IMPORT_EXPORT const void* ShGetExecutable(const ShHandle);
292 SH_IMPORT_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing
293 SH_IMPORT_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings
294 //
295 // Tell the linker to never assign a vertex attribute to this list of physical attributes
296 //
298 
299 //
300 // Returns the location ID of the named uniform.
301 // Returns -1 if error.
302 //
303 SH_IMPORT_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
304 
305 #ifdef __cplusplus
306  } // end extern "C"
307 #endif
308 
310 //
311 // Deferred-Lowering C++ Interface
312 // -----------------------------------
313 //
314 // Below is a new alternate C++ interface, which deprecates the above
315 // opaque handle-based interface.
316 //
317 // The below is further designed to handle multiple compilation units per stage, where
318 // the intermediate results, including the parse tree, are preserved until link time,
319 // rather than the above interface which is designed to have each compilation unit
320 // lowered at compile time. In the above model, linking occurs on the lowered results,
321 // whereas in this model intra-stage linking can occur at the parse tree
322 // (treeRoot in TIntermediate) level, and then a full stage can be lowered.
323 //
324 
325 #include <list>
326 #include <string>
327 #include <utility>
328 
329 class TCompiler;
330 class TInfoSink;
331 
332 namespace glslang {
333 
334 const char* GetEsslVersionString();
335 const char* GetGlslVersionString();
336 int GetKhronosToolId();
337 
338 class TIntermediate;
339 class TProgram;
340 class TPoolAllocator;
341 
342 // Call this exactly once per process before using anything else
343 bool InitializeProcess();
344 
345 // Call once per process to tear down everything
346 void FinalizeProcess();
347 
348 // Resource type for IO resolver
357 };
358 
359 // Make one TShader per shader that you will link into a program. Then
360 // - provide the shader through setStrings() or setStringsWithLengths()
361 // - optionally call setEnv*(), see below for more detail
362 // - optionally use setPreamble() to set a special shader string that will be
363 // processed before all others but won't affect the validity of #version
364 // - call parse(): source language and target environment must be selected
365 // either by correct setting of EShMessages sent to parse(), or by
366 // explicitly calling setEnv*()
367 // - query the info logs
368 //
369 // N.B.: Does not yet support having the same TShader instance being linked into
370 // multiple programs.
371 //
372 // N.B.: Destruct a linked program *before* destructing the shaders linked into it.
373 //
374 class TShader {
375 public:
376  explicit TShader(EShLanguage);
377  virtual ~TShader();
378  void setStrings(const char* const* s, int n);
379  void setStringsWithLengths(const char* const* s, const int* l, int n);
381  const char* const* s, const int* l, const char* const* names, int n);
382  void setPreamble(const char* s) { preamble = s; }
383  void setEntryPoint(const char* entryPoint);
384  void setSourceEntryPoint(const char* sourceEntryPointName);
385  void addProcesses(const std::vector<std::string>&);
386 
387  // IO resolver binding data: see comments in ShaderLang.cpp
388  void setShiftBinding(TResourceType res, unsigned int base);
389  void setShiftSamplerBinding(unsigned int base); // DEPRECATED: use setShiftBinding
390  void setShiftTextureBinding(unsigned int base); // DEPRECATED: use setShiftBinding
391  void setShiftImageBinding(unsigned int base); // DEPRECATED: use setShiftBinding
392  void setShiftUboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
393  void setShiftUavBinding(unsigned int base); // DEPRECATED: use setShiftBinding
394  void setShiftCbufferBinding(unsigned int base); // synonym for setShiftUboBinding
395  void setShiftSsboBinding(unsigned int base); // DEPRECATED: use setShiftBinding
396  void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set);
397  void setResourceSetBinding(const std::vector<std::string>& base);
398  void setAutoMapBindings(bool map);
399  void setAutoMapLocations(bool map);
400  void setInvertY(bool invert);
401  void setHlslIoMapping(bool hlslIoMap);
402  void setFlattenUniformArrays(bool flatten);
403  void setNoStorageFormat(bool useUnknownFormat);
405 
406  // For setting up the environment (cleared to nothingness in the constructor).
407  // These must be called so that parsing is done for the right source language and
408  // target environment, either indirectly through TranslateEnvironment() based on
409  // EShMessages et. al., or directly by the user.
410  void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version)
411  {
413  environment.input.stage = envStage;
414  environment.input.dialect = client;
416  }
418  {
419  environment.client.client = client;
421  }
423  {
424  environment.target.language = lang;
426  }
429 
430  // Interface to #include handlers.
431  //
432  // To support #include, a client of Glslang does the following:
433  // 1. Call setStringsWithNames to set the source strings and associated
434  // names. For example, the names could be the names of the files
435  // containing the shader sources.
436  // 2. Call parse with an Includer.
437  //
438  // When the Glslang parser encounters an #include directive, it calls
439  // the Includer's include method with the requested include name
440  // together with the current string name. The returned IncludeResult
441  // contains the fully resolved name of the included source, together
442  // with the source text that should replace the #include directive
443  // in the source stream. After parsing that source, Glslang will
444  // release the IncludeResult object.
445  class Includer {
446  public:
447  // An IncludeResult contains the resolved name and content of a source
448  // inclusion.
449  struct IncludeResult {
450  IncludeResult(const std::string& headerName, const char* const headerData, const size_t headerLength, void* userData) :
452  // For a successful inclusion, the fully resolved name of the requested
453  // include. For example, in a file system-based includer, full resolution
454  // should convert a relative path name into an absolute path name.
455  // For a failed inclusion, this is an empty string.
457  // The content and byte length of the requested inclusion. The
458  // Includer producing this IncludeResult retains ownership of the
459  // storage.
460  // For a failed inclusion, the header
461  // field points to a string containing error details.
462  const char* const headerData;
463  const size_t headerLength;
464  // Include resolver's context.
465  void* userData;
466  protected:
468  IncludeResult();
469  };
470 
471  // For both include methods below:
472  //
473  // Resolves an inclusion request by name, current source name,
474  // and include depth.
475  // On success, returns an IncludeResult containing the resolved name
476  // and content of the include.
477  // On failure, returns a nullptr, or an IncludeResult
478  // with an empty string for the headerName and error details in the
479  // header field.
480  // The Includer retains ownership of the contents
481  // of the returned IncludeResult value, and those contents must
482  // remain valid until the releaseInclude method is called on that
483  // IncludeResult object.
484  //
485  // Note "local" vs. "system" is not an "either/or": "local" is an
486  // extra thing to do over "system". Both might get called, as per
487  // the C++ specification.
488 
489  // For the "system" or <>-style includes; search the "system" paths.
490  virtual IncludeResult* includeSystem(const char* /*headerName*/,
491  const char* /*includerName*/,
492  size_t /*inclusionDepth*/) { return nullptr; }
493 
494  // For the "local"-only aspect of a "" include. Should not search in the
495  // "system" paths, because on returning a failure, the parser will
496  // call includeSystem() to look in the "system" locations.
497  virtual IncludeResult* includeLocal(const char* /*headerName*/,
498  const char* /*includerName*/,
499  size_t /*inclusionDepth*/) { return nullptr; }
500 
501  // Signals that the parser will no longer use the contents of the
502  // specified IncludeResult.
503  virtual void releaseInclude(IncludeResult*) = 0;
504  virtual ~Includer() {}
505  };
506 
507  // Fail all Includer searches
508  class ForbidIncluder : public Includer {
509  public:
510  virtual void releaseInclude(IncludeResult*) override { }
511  };
512 
513  bool parse(const TBuiltInResource*, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
514  bool forwardCompatible, EShMessages, Includer&);
515 
516  bool parse(const TBuiltInResource* res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
517  bool forwardCompatible, EShMessages messages)
518  {
519  TShader::ForbidIncluder includer;
520  return parse(res, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, includer);
521  }
522 
523  // Equivalent to parse() without a default profile and without forcing defaults.
524  bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
525  {
526  return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages);
527  }
528 
529  bool parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages,
530  Includer& includer)
531  {
532  return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages, includer);
533  }
534 
535  bool preprocess(const TBuiltInResource* builtInResources,
536  int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile,
537  bool forwardCompatible, EShMessages message, std::string* outputString,
538  Includer& includer);
539 
540  const char* getInfoLog();
541  const char* getInfoDebugLog();
542  EShLanguage getStage() const { return stage; }
544 
545 protected:
551  // strings and lengths follow the standard for glShaderSource:
552  // strings is an array of numStrings pointers to string data.
553  // lengths can be null, but if not it is an array of numStrings
554  // integers containing the length of the associated strings.
555  // if lengths is null or lengths[n] < 0 the associated strings[n] is
556  // assumed to be null-terminated.
557  // stringNames is the optional names for all the strings. If stringNames
558  // is null, then none of the strings has name. If a certain element in
559  // stringNames is null, then the corresponding string does not have name.
560  const char* const* strings;
561  const int* lengths;
562  const char* const* stringNames;
563  const char* preamble;
565 
566  // a function in the source string can be renamed FROM this TO the name given in setEntryPoint.
568 
570 
571  friend class TProgram;
572 
573 private:
575 };
576 
577 class TReflection;
578 class TIoMapper;
579 
580 // Allows to customize the binding layout after linking.
581 // All used uniform variables will invoke at least validateBinding.
582 // If validateBinding returned true then the other resolveBinding,
583 // resolveSet, and resolveLocation are invoked to resolve the binding
584 // and descriptor set index respectively.
585 //
586 // Invocations happen in a particular order:
587 // 1) all shader inputs
588 // 2) all shader outputs
589 // 3) all uniforms with binding and set already defined
590 // 4) all uniforms with binding but no set defined
591 // 5) all uniforms with set but no binding defined
592 // 6) all uniforms with no binding and no set defined
593 //
594 // mapIO will use this resolver in two phases. The first
595 // phase is a notification phase, calling the corresponging
596 // notifiy callbacks, this phase ends with a call to endNotifications.
597 // Phase two starts directly after the call to endNotifications
598 // and calls all other callbacks to validate and to get the
599 // bindings, sets, locations, component and color indices.
600 //
601 // NOTE: that still limit checks are applied to bindings and sets
602 // and may result in an error.
604 {
605 public:
606  virtual ~TIoMapResolver() {}
607 
608  // Should return true if the resulting/current binding would be okay.
609  // Basic idea is to do aliasing binding checks with this.
610  virtual bool validateBinding(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
611  // Should return a value >= 0 if the current binding should be overridden.
612  // Return -1 if the current binding (including no binding) should be kept.
613  virtual int resolveBinding(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
614  // Should return a value >= 0 if the current set should be overridden.
615  // Return -1 if the current set (including no set) should be kept.
616  virtual int resolveSet(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
617  // Should return a value >= 0 if the current location should be overridden.
618  // Return -1 if the current location (including no location) should be kept.
619  virtual int resolveUniformLocation(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
620  // Should return true if the resulting/current setup would be okay.
621  // Basic idea is to do aliasing checks and reject invalid semantic names.
622  virtual bool validateInOut(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
623  // Should return a value >= 0 if the current location should be overridden.
624  // Return -1 if the current location (including no location) should be kept.
625  virtual int resolveInOutLocation(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
626  // Should return a value >= 0 if the current component index should be overridden.
627  // Return -1 if the current component index (including no index) should be kept.
628  virtual int resolveInOutComponent(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
629  // Should return a value >= 0 if the current color index should be overridden.
630  // Return -1 if the current color index (including no index) should be kept.
631  virtual int resolveInOutIndex(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
632  // Notification of a uniform variable
633  virtual void notifyBinding(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
634  // Notification of a in or out variable
635  virtual void notifyInOut(EShLanguage stage, const char* name, const TType& type, bool is_live) = 0;
636  // Called by mapIO when it has finished the notify pass
637  virtual void endNotifications(EShLanguage stage) = 0;
638  // Called by mapIO when it starts its notify pass for the given stage
639  virtual void beginNotifications(EShLanguage stage) = 0;
640  // Called by mipIO when it starts its resolve pass for the given stage
641  virtual void beginResolve(EShLanguage stage) = 0;
642  // Called by mapIO when it has finished the resolve pass
643  virtual void endResolve(EShLanguage stage) = 0;
644 };
645 
646 // Make one TProgram per set of shaders that will get linked together. Add all
647 // the shaders that are to be linked together. After calling shader.parse()
648 // for all shaders, call link().
649 //
650 // N.B.: Destruct a linked program *before* destructing the shaders linked into it.
651 //
652 class TProgram {
653 public:
654  TProgram();
655  virtual ~TProgram();
656  void addShader(TShader* shader) { stages[shader->stage].push_back(shader); }
657 
658  // Link Validation interface
659  bool link(EShMessages);
660  const char* getInfoLog();
661  const char* getInfoDebugLog();
662 
663  TIntermediate* getIntermediate(EShLanguage stage) const { return intermediate[stage]; }
664 
665  // Reflection Interface
666  bool buildReflection(); // call first, to do liveness analysis, index mapping, etc.; returns false on failure
667  int getNumLiveUniformVariables() const; // can be used for glGetProgramiv(GL_ACTIVE_UNIFORMS)
668  int getNumLiveUniformBlocks() const; // can be used for glGetProgramiv(GL_ACTIVE_UNIFORM_BLOCKS)
669  const char* getUniformName(int index) const; // can be used for "name" part of glGetActiveUniform()
670  const char* getUniformBlockName(int blockIndex) const; // can be used for glGetActiveUniformBlockName()
671  int getUniformBlockSize(int blockIndex) const; // can be used for glGetActiveUniformBlockiv(UNIFORM_BLOCK_DATA_SIZE)
672  int getUniformIndex(const char* name) const; // can be used for glGetUniformIndices()
673  int getUniformBinding(int index) const; // returns the binding number
674  int getUniformBlockBinding(int index) const; // returns the block binding number
675  int getUniformBlockIndex(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_BLOCK_INDEX)
676  int getUniformBlockCounterIndex(int index) const; // returns block index of associated counter.
677  int getUniformType(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_TYPE)
678  int getUniformBufferOffset(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_OFFSET)
679  int getUniformArraySize(int index) const; // can be used for glGetActiveUniformsiv(GL_UNIFORM_SIZE)
680  int getNumLiveAttributes() const; // can be used for glGetProgramiv(GL_ACTIVE_ATTRIBUTES)
681  unsigned getLocalSize(int dim) const; // return dim'th local size
682  const char *getAttributeName(int index) const; // can be used for glGetActiveAttrib()
683  int getAttributeType(int index) const; // can be used for glGetActiveAttrib()
684  const TType* getUniformTType(int index) const; // returns a TType*
685  const TType* getUniformBlockTType(int index) const; // returns a TType*
686  const TType* getAttributeTType(int index) const; // returns a TType*
687 
688  void dumpReflection();
689 
690  // I/O mapping: apply base offsets and map live unbound variables
691  // If resolver is not provided it uses the previous approach
692  // and respects auto assignment and offsets.
693  bool mapIO(TIoMapResolver* resolver = NULL);
694 
695 protected:
697 
699  std::list<TShader*> stages[EShLangCount];
701  bool newedIntermediate[EShLangCount]; // track which intermediate were "new" versus reusing a singleton unit in a stage
705  bool linked;
706 
707 private:
708  TProgram(TProgram&);
710 };
711 
712 } // end namespace glslang
713 
714 #endif // _COMPILER_INTERFACE_INCLUDED_
TEnvironment environment
Definition: ShaderLang.h:569
TReflection * reflection
Definition: ShaderLang.h:703
TIntermediate * intermediate[EShLangCount]
Definition: ShaderLang.h:700
void setEnvTargetHlslFunctionality1()
Definition: ShaderLang.h:427
Definition: ShaderLang.h:189
Definition: ShaderLang.h:127
Definition: ShaderLang.h:445
GLuint shader
Definition: glext.h:6670
void setNoStorageFormat(bool useUnknownFormat)
Definition: ShaderLang.cpp:1701
void FinalizeProcess()
Definition: ShaderLang.cpp:1595
EShTargetClientVersion
Definition: ShaderLang.h:131
void setStringsWithLengths(const char *const *s, const int *l, int n)
Definition: ShaderLang.cpp:1637
GLuint const GLchar * name
Definition: glext.h:6671
void setAutoMapLocations(bool map)
Definition: ShaderLang.cpp:1697
Definition: Versions.h:53
void setFlattenUniformArrays(bool flatten)
Definition: ShaderLang.cpp:1700
Definition: ShaderLang.h:92
SH_IMPORT_EXPORT int ShInitialize()
Definition: ShaderLang.cpp:1194
const std::string headerName
Definition: ShaderLang.h:456
virtual int resolveSet(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
EShSource languageFamily
Definition: ShaderLang.h:145
EShTextureSamplerTransformMode
Definition: ShaderLang.h:196
Definition: ShaderLang.h:94
bool linked
Definition: ShaderLang.h:705
Definition: ShaderLang.h:603
GLenum mode
Definition: glext.h:6857
const char * getAttributeName(int index) const
Definition: ShaderLang.cpp:1920
virtual ~TIoMapResolver()
Definition: ShaderLang.h:606
Definition: ShaderLang.h:208
TCompiler * compiler
Definition: ShaderLang.h:548
Definition: InfoSink.h:138
int getUniformBlockCounterIndex(int index) const
Definition: ShaderLang.cpp:1915
IncludeResult & operator=(const IncludeResult &)
EShClient dialect
Definition: ShaderLang.h:147
EShLanguage
Definition: ShaderLang.h:90
Definition: ShaderLang.h:95
bool newedIntermediate[EShLangCount]
Definition: ShaderLang.h:701
void setShiftBinding(TResourceType res, unsigned int base)
Definition: ShaderLang.cpp:1669
virtual IncludeResult * includeSystem(const char *, const char *, size_t)
Definition: ShaderLang.h:490
void setResourceSetBinding(const std::vector< std::string > &base)
Definition: ShaderLang.cpp:1702
SH_IMPORT_EXPORT ShHandle ShConstructUniformMap()
Definition: ShaderLang.cpp:1241
const char * preamble
Definition: ShaderLang.h:563
int numStrings
Definition: ShaderLang.h:564
void setEnvInput(EShSource lang, EShLanguage envStage, EShClient client, int version)
Definition: ShaderLang.h:410
SH_IMPORT_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char *name)
Definition: ShaderLang.cpp:1544
void setEntryPoint(const char *entryPoint)
Definition: ShaderLang.cpp:1653
void setShiftSsboBinding(unsigned int base)
Definition: ShaderLang.cpp:1691
ShBinding * bindings
Definition: ShaderLang.h:232
bool parse(const TBuiltInResource *res, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile, bool forwardCompatible, EShMessages messages)
Definition: ShaderLang.h:516
Definition: ShaderLang.h:354
std::string sourceEntryPointName
Definition: ShaderLang.h:567
GLuint res
Definition: glext.h:10520
void * ShHandle
Definition: ShaderLang.h:244
Definition: ShaderLang.h:140
int numBindings
Definition: ShaderLang.h:231
Definition: ShaderLang.h:225
EShLanguage stage
Definition: ShaderLang.h:547
Definition: ShHandle.h:89
EShTargetLanguageVersion
Definition: ShaderLang.h:139
Definition: ShaderLang.h:151
Definition: localintermediate.h:210
SH_IMPORT_EXPORT const char * ShGetInfoLog(const ShHandle)
Definition: ShaderLang.cpp:1441
Definition: ShaderLang.h:179
EShLanguageMask
Definition: ShaderLang.h:100
int getUniformType(int index) const
Definition: ShaderLang.cpp:1916
Definition: ShaderLang.h:133
Definition: ResourceLimits.h:52
const char *const * stringNames
Definition: ShaderLang.h:562
Definition: ShaderLang.h:180
GLdouble s
Definition: glext.h:6390
int getUniformArraySize(int index) const
Definition: ShaderLang.cpp:1918
IncludeResult(const std::string &headerName, const char *const headerData, const size_t headerLength, void *userData)
Definition: ShaderLang.h:450
EShClient
Definition: ShaderLang.h:119
const char * GetGlslVersionString()
Definition: ShaderLang.cpp:1580
Definition: ShaderLang.h:102
SH_IMPORT_EXPORT int ShLinkExt(const ShHandle, const ShHandle h[], const int numHandles)
Definition: ShaderLang.cpp:1380
const int * lengths
Definition: ShaderLang.h:561
SH_IMPORT_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int debugOptions)
Definition: ShaderLang.cpp:1221
GLsizei const GLchar *const * string
Definition: glext.h:6699
void addShader(TShader *shader)
Definition: ShaderLang.h:656
void setHlslIoMapping(bool hlslIoMap)
Definition: ShaderLang.cpp:1699
int getAttributeType(int index) const
Definition: ShaderLang.cpp:1921
#define __fastcall
Definition: ShaderLang.h:56
Definition: ShaderLang.h:197
EShTargetClientVersion EshTargetClientVersion
Definition: ShaderLang.h:137
const char * entryPoint
Definition: Hlsl.FromFile.cpp:45
const char * GetEsslVersionString()
Definition: ShaderLang.cpp:1575
GLsizei GLenum GLenum GLuint GLenum GLsizei * lengths
Definition: glext.h:8420
virtual void endResolve(EShLanguage stage)=0
void setShiftUboBinding(unsigned int base)
Definition: ShaderLang.cpp:1685
TIoMapper * ioMapper
Definition: ShaderLang.h:704
Definition: ShaderLang.h:508
TShader & operator=(TShader &)
virtual void endNotifications(EShLanguage stage)=0
TPoolAllocator * pool
Definition: ShaderLang.h:546
Definition: ShaderLang.h:374
TResourceType
Definition: ShaderLang.h:349
SH_IMPORT_EXPORT int __fastcall ShFinalize()
Definition: ShaderLang.cpp:1269
GLuint GLuint GLsizei count
Definition: glext.h:6292
bool mapIO(TIoMapResolver *resolver=NULL)
Definition: ShaderLang.cpp:1932
Definition: ShaderLang.h:101
Definition: ShaderLang.h:165
virtual int resolveUniformLocation(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
const char * getUniformName(int index) const
Definition: ShaderLang.cpp:1908
virtual ~TShader()
Definition: ShaderLang.cpp:1622
static GX2AttribVar attributes[]
Definition: bokeh.c:713
SH_IMPORT_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable *)
Definition: ShaderLang.cpp:1486
Definition: ShaderLang.h:144
TShader(EShLanguage)
Definition: ShaderLang.cpp:1606
TClient client
Definition: ShaderLang.h:167
EShOptimizationLevel
Definition: ShaderLang.h:186
int getUniformIndex(const char *name) const
Definition: ShaderLang.cpp:1911
void setShiftBindingForSet(TResourceType res, unsigned int base, unsigned int set)
Definition: ShaderLang.cpp:1674
void dumpReflection()
Definition: ShaderLang.cpp:1927
virtual void notifyInOut(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
const char * name
Definition: ShaderLang.h:226
Definition: ShaderLang.h:207
EShTargetClientVersion version
Definition: ShaderLang.h:153
Definition: ShaderLang.h:187
Definition: ShaderLang.h:214
void setInvertY(bool invert)
Definition: ShaderLang.cpp:1695
Definition: ShaderLang.h:106
bool parse(const TBuiltInResource *builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages)
Definition: ShaderLang.h:524
TIntermediate * intermediate
Definition: ShaderLang.h:549
virtual void notifyBinding(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
#define NULL
Pointer to 0.
Definition: gctypes.h:65
Definition: ShaderLang.h:353
SH_IMPORT_EXPORT ShHandle ShConstructLinker(const EShExecutable, int debugOptions)
Definition: ShaderLang.cpp:1231
GLenum type
Definition: glext.h:6233
Definition: ShaderLang.h:122
Definition: ShaderLang.h:190
bool l
Definition: connect_wiiupro.c:37
Definition: Types.h:1169
TInfoSink * infoSink
Definition: ShaderLang.h:550
int getNumLiveUniformBlocks() const
Definition: ShaderLang.cpp:1907
int getUniformBlockBinding(int index) const
Definition: ShaderLang.cpp:1913
EProfile
Definition: Versions.h:51
Definition: ShaderLang.h:449
Definition: reflection.h:95
virtual ~Includer()
Definition: ShaderLang.h:504
Definition: ShaderLang.h:96
Definition: ShaderLang.h:230
TIntermediate * getIntermediate(EShLanguage stage) const
Definition: ShaderLang.h:663
version
Definition: setup.py:6
void setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode)
Definition: ShaderLang.cpp:1703
SH_IMPORT_EXPORT int ShCompile(const ShHandle, const char *const shaderStrings[], const int numStrings, const int *lengths, const EShOptimizationLevel, const TBuiltInResource *resources, int debugOptions, int defaultVersion=110, bool forwardCompatible=false, EShMessages messages=EShMsgDefault)
Definition: ShaderLang.cpp:1326
void setShiftImageBinding(unsigned int base)
Definition: ShaderLang.cpp:1683
int binding
Definition: ShaderLang.h:227
int getUniformBufferOffset(int index) const
Definition: ShaderLang.cpp:1917
virtual IncludeResult * includeLocal(const char *, const char *, size_t)
Definition: ShaderLang.h:497
void setEnvClient(EShClient client, EShTargetClientVersion version)
Definition: ShaderLang.h:417
virtual int resolveInOutIndex(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
TInputLanguage input
Definition: ShaderLang.h:166
virtual bool validateInOut(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
TProgram & operator=(TProgram &)
Definition: ShaderLang.h:115
bool parse(const TBuiltInResource *builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages, Includer &includer)
Definition: ShaderLang.h:529
int GetKhronosToolId()
Definition: ShaderLang.cpp:1585
int getNumLiveAttributes() const
Definition: ShaderLang.cpp:1919
const char *const headerData
Definition: ShaderLang.h:462
virtual void beginNotifications(EShLanguage stage)=0
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:6233
int getUniformBinding(int index) const
Definition: ShaderLang.cpp:1912
void setSourceEntryPoint(const char *sourceEntryPointName)
Definition: ShaderLang.cpp:1658
EShLanguage getStage() const
Definition: ShaderLang.h:542
void setAutoMapBindings(bool map)
Definition: ShaderLang.cpp:1693
void setStringsWithLengthsAndNames(const char *const *s, const int *l, const char *const *names, int n)
Definition: ShaderLang.cpp:1644
virtual void beginResolve(EShLanguage stage)=0
void setPreamble(const char *s)
Definition: ShaderLang.h:382
const char * getInfoDebugLog()
Definition: ShaderLang.cpp:1880
Definition: ShaderLang.h:104
virtual void releaseInclude(IncludeResult *) override
Definition: ShaderLang.h:510
Definition: ShaderLang.h:212
EShTargetLanguage
Definition: ShaderLang.h:125
Definition: ShaderLang.h:352
int getUniformBlockSize(int blockIndex) const
Definition: ShaderLang.cpp:1910
int getNumLiveUniformVariables() const
Definition: ShaderLang.cpp:1906
EShTargetLanguage language
Definition: ShaderLang.h:157
virtual void releaseInclude(IncludeResult *)=0
#define SH_IMPORT_EXPORT
Definition: ShaderLang.h:54
void setShiftUavBinding(unsigned int base)
Definition: ShaderLang.cpp:1689
SH_IMPORT_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count)
Definition: ShaderLang.cpp:1523
Definition: arrays.h:46
virtual int resolveBinding(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
Definition: ShaderLang.h:116
GLuint index
Definition: glext.h:6671
bool buildReflection()
Definition: ShaderLang.cpp:1889
void addProcesses(const std::vector< std::string > &)
Definition: ShaderLang.cpp:1663
Definition: ShaderLang.h:211
const char * getUniformBlockName(int blockIndex) const
Definition: ShaderLang.cpp:1909
virtual bool validateBinding(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
int dialectVersion
Definition: ShaderLang.h:148
Definition: ShaderLang.h:217
EShClient client
Definition: ShaderLang.h:152
TProgram()
Definition: ShaderLang.cpp:1759
bool linkStage(EShLanguage, EShMessages)
Definition: ShaderLang.cpp:1813
void setShiftTextureBinding(unsigned int base)
Definition: ShaderLang.cpp:1681
bool preprocess(const TBuiltInResource *builtInResources, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile, bool forwardCompatible, EShMessages message, std::string *outputString, Includer &includer)
Definition: ShaderLang.cpp:1729
GLbitfield stages
Definition: glext.h:8287
Definition: ShaderLang.h:355
Definition: PoolAlloc.h:147
GLuint GLuint * names
Definition: glext.h:12452
int getUniformBlockIndex(int index) const
Definition: ShaderLang.cpp:1914
EShLanguage stage
Definition: ShaderLang.h:146
bool getEnvTargetHlslFunctionality1() const
Definition: ShaderLang.h:428
Definition: ShaderLang.h:141
SH_IMPORT_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable *)
Definition: ShaderLang.cpp:1505
const TType * getUniformTType(int index) const
Definition: ShaderLang.cpp:1923
void setShiftCbufferBinding(unsigned int base)
Definition: ShaderLang.cpp:1687
bool link(EShMessages)
Definition: ShaderLang.cpp:1788
void setEnvTarget(EShTargetLanguage lang, EShTargetLanguageVersion version)
Definition: ShaderLang.h:422
Definition: ShaderLang.h:105
const char * getInfoLog()
Definition: ShaderLang.cpp:1875
Definition: ShaderLang.h:206
Definition: ShaderLang.h:356
SH_IMPORT_EXPORT const void * ShGetExecutable(const ShHandle)
Definition: ShaderLang.cpp:1464
Definition: ShaderLang.h:218
SH_IMPORT_EXPORT void ShDestruct(ShHandle)
Definition: ShaderLang.cpp:1251
Definition: ShaderLang.h:198
TInfoSink * infoSink
Definition: ShaderLang.h:702
Definition: ShaderLang.h:351
TPoolAllocator * pool
Definition: ShaderLang.h:698
GLboolean invert
Definition: glext.h:6381
const size_t headerLength
Definition: ShaderLang.h:463
virtual ~TProgram()
Definition: ShaderLang.cpp:1769
TIntermediate * getIntermediate() const
Definition: ShaderLang.h:543
EShTargetLanguageVersion version
Definition: ShaderLang.h:158
const char * StageName(EShLanguage stage)
Definition: Versions.cpp:474
virtual int resolveInOutLocation(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
SH_IMPORT_EXPORT void ShSetEncryptionMethod(ShHandle)
Definition: ShaderLang.cpp:1432
const char * getInfoLog()
Definition: ShaderLang.cpp:1749
virtual int resolveInOutComponent(EShLanguage stage, const char *name, const TType &type, bool is_live)=0
Definition: ShaderLang.h:209
const TType * getUniformBlockTType(int index) const
Definition: ShaderLang.cpp:1924
Definition: ShaderLang.h:134
bool parse(const TBuiltInResource *, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile, bool forwardCompatible, EShMessages, Includer &)
Definition: ShaderLang.cpp:1710
const char *const * strings
Definition: ShaderLang.h:560
void setStrings(const char *const *s, int n)
Definition: ShaderLang.cpp:1630
EShMessages
Definition: ShaderLang.h:204
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:8390
Definition: ShaderLang.h:216
void setShiftSamplerBinding(unsigned int base)
Definition: ShaderLang.cpp:1679
EShSource
Definition: ShaderLang.h:113
Definition: ShaderLang.h:132
bool InitializeProcess()
Definition: ShaderLang.cpp:1590
Definition: ShaderLang.h:213
Definition: iomapper.h:52
Definition: ShaderLang.h:91
unsigned getLocalSize(int dim) const
Definition: ShaderLang.cpp:1925
Definition: ShaderLang.h:156
Definition: ShaderLang.h:210
Definition: ShaderLang.h:128
Definition: ShaderLang.h:652
Definition: ShaderLang.h:121
Definition: ShaderLang.h:120
GLdouble n
Definition: glext.h:8396
Definition: ShaderLang.h:205
Definition: ShaderLang.h:188
Definition: ShaderLang.h:350
bool hlslFunctionality1
Definition: ShaderLang.h:159
Definition: ShaderLang.h:215
TTarget target
Definition: ShaderLang.h:168
Definition: ShaderLang.h:126
const char * getInfoDebugLog()
Definition: ShaderLang.cpp:1754
const TType * getAttributeTType(int index) const
Definition: ShaderLang.cpp:1922
Definition: ShaderLang.h:103
Definition: ShaderLang.h:114
Definition: ShaderLang.h:93
EShExecutable
Definition: ShaderLang.h:178
Definition: ShaderLang.h:97
void * userData
Definition: ShaderLang.h:465