Home | History | Annotate | Download | only in MachineIndependent
      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 
     37 #ifndef _INITIALIZE_INCLUDED_
     38 #define _INITIALIZE_INCLUDED_
     39 
     40 #include "../Include/ResourceLimits.h"
     41 #include "../Include/Common.h"
     42 #include "../Include/ShHandle.h"
     43 #include "SymbolTable.h"
     44 #include "Versions.h"
     45 
     46 namespace glslang {
     47 
     48 //
     49 // This is made to hold parseable strings for almost all the built-in
     50 // functions and variables for one specific combination of version
     51 // and profile.  (Some still need to be added programmatically.)
     52 // This is a base class for language-specific derivations, which
     53 // can be used for language independent builtins.
     54 //
     55 // The strings are organized by
     56 //    commonBuiltins:  intersection of all stages' built-ins, processed just once
     57 //    stageBuiltins[]: anything a stage needs that's not in commonBuiltins
     58 //
     59 class TBuiltInParseables {
     60 public:
     61     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
     62     TBuiltInParseables();
     63     virtual ~TBuiltInParseables();
     64     virtual void initialize(int version, EProfile, const SpvVersion& spvVersion) = 0;
     65     virtual void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage) = 0;
     66     virtual const TString& getCommonString() const { return commonBuiltins; }
     67     virtual const TString& getStageString(EShLanguage language) const { return stageBuiltins[language]; }
     68 
     69     virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable) = 0;
     70 
     71     virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources) = 0;
     72 
     73 protected:
     74     TString commonBuiltins;
     75     TString stageBuiltins[EShLangCount];
     76 };
     77 
     78 //
     79 // This is a GLSL specific derivation of TBuiltInParseables.  To present a stable
     80 // interface and match other similar code, it is called TBuiltIns, rather
     81 // than TBuiltInParseablesGlsl.
     82 //
     83 class TBuiltIns : public TBuiltInParseables {
     84 public:
     85     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
     86     TBuiltIns();
     87     virtual ~TBuiltIns();
     88     void initialize(int version, EProfile, const SpvVersion& spvVersion);
     89     void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage);
     90 
     91     void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable);
     92 
     93     void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources);
     94 
     95 protected:
     96     void add2ndGenerationSamplingImaging(int version, EProfile profile, const SpvVersion& spvVersion);
     97     void addSubpassSampling(TSampler, const TString& typeName, int version, EProfile profile);
     98     void addQueryFunctions(TSampler, const TString& typeName, int version, EProfile profile);
     99     void addImageFunctions(TSampler, const TString& typeName, int version, EProfile profile);
    100     void addSamplingFunctions(TSampler, const TString& typeName, int version, EProfile profile);
    101     void addGatherFunctions(TSampler, const TString& typeName, int version, EProfile profile);
    102 
    103     // Helpers for making textual representations of the permutations
    104     // of texturing/imaging functions.
    105     const char* postfixes[5];
    106     const char* prefixes[EbtNumTypes];
    107     int dimMap[EsdNumDims];
    108 };
    109 
    110 } // end namespace glslang
    111 
    112 #endif // _INITIALIZE_INCLUDED_
    113