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;
getCommonString()66     virtual const TString& getCommonString() const { return commonBuiltins; }
getStageString(EShLanguage language)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     virtual void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources) = 0;
71 
72 protected:
73     TString commonBuiltins;
74     TString stageBuiltins[EShLangCount];
75 };
76 
77 //
78 // This is a GLSL specific derivation of TBuiltInParseables.  To present a stable
79 // interface and match other similar code, it is called TBuiltIns, rather
80 // than TBuiltInParseablesGlsl.
81 //
82 class TBuiltIns : public TBuiltInParseables {
83 public:
84     POOL_ALLOCATOR_NEW_DELETE(GetThreadPoolAllocator())
85     TBuiltIns();
86     virtual ~TBuiltIns();
87     void initialize(int version, EProfile, const SpvVersion& spvVersion);
88     void initialize(const TBuiltInResource& resources, int version, EProfile, const SpvVersion& spvVersion, EShLanguage);
89 
90     void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable);
91     void identifyBuiltIns(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage language, TSymbolTable& symbolTable, const TBuiltInResource &resources);
92 
93 protected:
94     void addTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion);
95     void relateTabledBuiltins(int version, EProfile profile, const SpvVersion& spvVersion, EShLanguage, TSymbolTable&);
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