// // Copyright (C) 2002-2005 3Dlabs Inc. Ltd. // Copyright (C) 2013-2016 LunarG, Inc. // Copyright (C) 2015-2018 Google, Inc. // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // Redistributions in binary form must reproduce the above // copyright notice, this list of conditions and the following // disclaimer in the documentation and/or other materials provided // with the distribution. // // Neither the name of 3Dlabs Inc. Ltd. nor the names of its // contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. // #ifndef _COMPILER_INTERFACE_INCLUDED_ #define _COMPILER_INTERFACE_INCLUDED_ #include "../Include/ResourceLimits.h" #include "../Include/visibility.h" #include "../MachineIndependent/Versions.h" #include <cstring> #include <vector> #ifdef _WIN32 #define C_DECL … #else #define C_DECL #endif // // This is the platform independent interface between an OGL driver // and the shading language compiler/linker. // #ifdef __cplusplus extern "C" { #endif // // Call before doing any other compiler/linker operations. // // (Call once per process, not once per thread.) // GLSLANG_EXPORT int ShInitialize(); // // Call this at process shutdown to clean up memory. // GLSLANG_EXPORT int ShFinalize(); // // Types of languages the compiler can consume. // EShLanguage; // would be better as stage, but this is ancient now EShLanguageMask; namespace glslang { class TType; EShSource; // if EShLanguage were EShStage, this could be EShLanguage instead EShClient; EShTargetLanguage; EShTargetClientVersion; EshTargetClientVersion; EShTargetLanguageVersion; struct TInputLanguage { … }; struct TClient { … }; struct TTarget { … }; // All source/client/target versions and settings. // Can override previous methods of setting, when items are set here. // Expected to grow, as more are added, rather than growing parameter lists. struct TEnvironment { … }; GLSLANG_EXPORT const char* StageName(EShLanguage); } // end namespace glslang // // Types of output the linker will create. // EShExecutable; // // Optimization level for the compiler. // EShOptimizationLevel; // // Texture and Sampler transformation mode. // EShTextureSamplerTransformMode; // // Message choices for what errors and warnings are given. // enum EShMessages : unsigned { … }; // // Options for building reflection // EShReflectionOptions; // // Build a table for bindings. This can be used for locating // attributes, uniforms, globals, etc., as needed. // ShBinding; ShBindingTable; // // ShHandle held by but opaque to the driver. It is allocated, // managed, and de-allocated by the compiler/linker. Its contents // are defined by and used by the compiler and linker. For example, // symbol table information and object code passed from the compiler // to the linker can be stored where ShHandle points. // // If handle creation fails, 0 will be returned. // ShHandle; // // Driver calls these to create and destroy compiler/linker // objects. // GLSLANG_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int /*debugOptions unused*/); // one per shader GLSLANG_EXPORT ShHandle ShConstructLinker(const EShExecutable, int /*debugOptions unused*/); // one per shader pair GLSLANG_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object) GLSLANG_EXPORT void ShDestruct(ShHandle); // // The return value of ShCompile is boolean, non-zero indicating // success. // // The info-log should be written by ShCompile into // ShHandle, so it can answer future queries. // GLSLANG_EXPORT int ShCompile(const ShHandle, const char* const shaderStrings[], const int numStrings, const int* lengths, const EShOptimizationLevel, const TBuiltInResource* resources, int, // debugOptions unused int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader bool forwardCompatible = false, // give errors for use of deprecated features EShMessages messages = EShMsgDefault, // warnings and errors const char* fileName = nullptr ); GLSLANG_EXPORT int ShLinkExt( const ShHandle, // linker object const ShHandle h[], // compiler objects to link together const int numHandles); // // ShSetEncrpytionMethod is a place-holder for specifying // how source code is encrypted. // GLSLANG_EXPORT void ShSetEncryptionMethod(ShHandle); // // All the following return 0 if the information is not // available in the object passed down, or the object is bad. // GLSLANG_EXPORT const char* ShGetInfoLog(const ShHandle); GLSLANG_EXPORT const void* ShGetExecutable(const ShHandle); GLSLANG_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing GLSLANG_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings // // Tell the linker to never assign a vertex attribute to this list of physical attributes // GLSLANG_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count); // // Returns the location ID of the named uniform. // Returns -1 if error. // GLSLANG_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name); #ifdef __cplusplus } // end extern "C" #endif //////////////////////////////////////////////////////////////////////////////////////////// // // Deferred-Lowering C++ Interface // ----------------------------------- // // Below is a new alternate C++ interface, which deprecates the above // opaque handle-based interface. // // The below is further designed to handle multiple compilation units per stage, where // the intermediate results, including the parse tree, are preserved until link time, // rather than the above interface which is designed to have each compilation unit // lowered at compile time. In the above model, linking occurs on the lowered results, // whereas in this model intra-stage linking can occur at the parse tree // (treeRoot in TIntermediate) level, and then a full stage can be lowered. // #include <list> #include <string> #include <utility> class TCompiler; class TInfoSink; namespace glslang { struct Version { … }; GLSLANG_EXPORT Version GetVersion(); GLSLANG_EXPORT const char* GetEsslVersionString(); GLSLANG_EXPORT const char* GetGlslVersionString(); GLSLANG_EXPORT int GetKhronosToolId(); class TIntermediate; class TProgram; class TPoolAllocator; // Call this exactly once per process before using anything else GLSLANG_EXPORT bool InitializeProcess(); // Call once per process to tear down everything GLSLANG_EXPORT void FinalizeProcess(); // Resource type for IO resolver enum TResourceType { … }; enum TBlockStorageClass { … }; // Make one TShader per shader that you will link into a program. Then // - provide the shader through setStrings() or setStringsWithLengths() // - optionally call setEnv*(), see below for more detail // - optionally use setPreamble() to set a special shader string that will be // processed before all others but won't affect the validity of #version // - optionally call addProcesses() for each setting/transform, // see comment for class TProcesses // - call parse(): source language and target environment must be selected // either by correct setting of EShMessages sent to parse(), or by // explicitly calling setEnv*() // - query the info logs // // N.B.: Does not yet support having the same TShader instance being linked into // multiple programs. // // N.B.: Destruct a linked program *before* destructing the shaders linked into it. // class TShader { … }; // // A reflection database and its interface, consistent with the OpenGL API reflection queries. // // Data needed for just a single object at the granularity exchanged by the reflection API class TObjectReflection { … }; class TReflection; class TIoMapper; struct TVarEntryInfo; // Allows to customize the binding layout after linking. // All used uniform variables will invoke at least validateBinding. // If validateBinding returned true then the other resolveBinding, // resolveSet, and resolveLocation are invoked to resolve the binding // and descriptor set index respectively. // // Invocations happen in a particular order: // 1) all shader inputs // 2) all shader outputs // 3) all uniforms with binding and set already defined // 4) all uniforms with binding but no set defined // 5) all uniforms with set but no binding defined // 6) all uniforms with no binding and no set defined // // mapIO will use this resolver in two phases. The first // phase is a notification phase, calling the corresponging // notifiy callbacks, this phase ends with a call to endNotifications. // Phase two starts directly after the call to endNotifications // and calls all other callbacks to validate and to get the // bindings, sets, locations, component and color indices. // // NOTE: that still limit checks are applied to bindings and sets // and may result in an error. class TIoMapResolver { … }; // Make one TProgram per set of shaders that will get linked together. Add all // the shaders that are to be linked together. After calling shader.parse() // for all shaders, call link(). // // N.B.: Destruct a linked program *before* destructing the shaders linked into it. // class TProgram { … }; } // end namespace glslang #endif // _COMPILER_INTERFACE_INCLUDED_