xref: /aosp_15_r20/external/angle/src/compiler/translator/Compiler.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2002 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker 
7*8975f5c5SAndroid Build Coastguard Worker #ifndef COMPILER_TRANSLATOR_COMPILER_H_
8*8975f5c5SAndroid Build Coastguard Worker #define COMPILER_TRANSLATOR_COMPILER_H_
9*8975f5c5SAndroid Build Coastguard Worker 
10*8975f5c5SAndroid Build Coastguard Worker //
11*8975f5c5SAndroid Build Coastguard Worker // Machine independent part of the compiler private objects
12*8975f5c5SAndroid Build Coastguard Worker // sent as ShHandle to the driver.
13*8975f5c5SAndroid Build Coastguard Worker //
14*8975f5c5SAndroid Build Coastguard Worker // This should not be included by driver code.
15*8975f5c5SAndroid Build Coastguard Worker //
16*8975f5c5SAndroid Build Coastguard Worker 
17*8975f5c5SAndroid Build Coastguard Worker #include <GLSLANG/ShaderVars.h>
18*8975f5c5SAndroid Build Coastguard Worker 
19*8975f5c5SAndroid Build Coastguard Worker #include "common/PackedEnums.h"
20*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/BuiltInFunctionEmulator.h"
21*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/CallDAG.h"
22*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/Diagnostics.h"
23*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/ExtensionBehavior.h"
24*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/HashNames.h"
25*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/InfoSink.h"
26*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/Pragma.h"
27*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/SymbolTable.h"
28*8975f5c5SAndroid Build Coastguard Worker #include "compiler/translator/ValidateAST.h"
29*8975f5c5SAndroid Build Coastguard Worker 
30*8975f5c5SAndroid Build Coastguard Worker namespace sh
31*8975f5c5SAndroid Build Coastguard Worker {
32*8975f5c5SAndroid Build Coastguard Worker 
33*8975f5c5SAndroid Build Coastguard Worker class TCompiler;
34*8975f5c5SAndroid Build Coastguard Worker class TParseContext;
35*8975f5c5SAndroid Build Coastguard Worker #ifdef ANGLE_ENABLE_HLSL
36*8975f5c5SAndroid Build Coastguard Worker class TranslatorHLSL;
37*8975f5c5SAndroid Build Coastguard Worker #endif  // ANGLE_ENABLE_HLSL
38*8975f5c5SAndroid Build Coastguard Worker #ifdef ANGLE_ENABLE_METAL
39*8975f5c5SAndroid Build Coastguard Worker class TranslatorMSL;
40*8975f5c5SAndroid Build Coastguard Worker #endif  // ANGLE_ENABLE_METAL
41*8975f5c5SAndroid Build Coastguard Worker 
42*8975f5c5SAndroid Build Coastguard Worker using MetadataFlagBits   = angle::PackedEnumBitSet<sh::MetadataFlags, uint32_t>;
43*8975f5c5SAndroid Build Coastguard Worker using SpecConstUsageBits = angle::PackedEnumBitSet<vk::SpecConstUsage, uint32_t>;
44*8975f5c5SAndroid Build Coastguard Worker 
45*8975f5c5SAndroid Build Coastguard Worker //
46*8975f5c5SAndroid Build Coastguard Worker // Helper function to check if the shader type is GLSL.
47*8975f5c5SAndroid Build Coastguard Worker //
48*8975f5c5SAndroid Build Coastguard Worker bool IsGLSL130OrNewer(ShShaderOutput output);
49*8975f5c5SAndroid Build Coastguard Worker bool IsGLSL420OrNewer(ShShaderOutput output);
50*8975f5c5SAndroid Build Coastguard Worker bool IsGLSL410OrOlder(ShShaderOutput output);
51*8975f5c5SAndroid Build Coastguard Worker 
52*8975f5c5SAndroid Build Coastguard Worker //
53*8975f5c5SAndroid Build Coastguard Worker // Helper function to check if the invariant qualifier can be removed.
54*8975f5c5SAndroid Build Coastguard Worker //
55*8975f5c5SAndroid Build Coastguard Worker bool RemoveInvariant(sh::GLenum shaderType,
56*8975f5c5SAndroid Build Coastguard Worker                      int shaderVersion,
57*8975f5c5SAndroid Build Coastguard Worker                      ShShaderOutput outputType,
58*8975f5c5SAndroid Build Coastguard Worker                      const ShCompileOptions &compileOptions);
59*8975f5c5SAndroid Build Coastguard Worker 
60*8975f5c5SAndroid Build Coastguard Worker //
61*8975f5c5SAndroid Build Coastguard Worker // The base class used to back handles returned to the driver.
62*8975f5c5SAndroid Build Coastguard Worker //
63*8975f5c5SAndroid Build Coastguard Worker class TShHandleBase
64*8975f5c5SAndroid Build Coastguard Worker {
65*8975f5c5SAndroid Build Coastguard Worker   public:
66*8975f5c5SAndroid Build Coastguard Worker     TShHandleBase();
67*8975f5c5SAndroid Build Coastguard Worker     virtual ~TShHandleBase();
getAsCompiler()68*8975f5c5SAndroid Build Coastguard Worker     virtual TCompiler *getAsCompiler() { return nullptr; }
69*8975f5c5SAndroid Build Coastguard Worker #ifdef ANGLE_ENABLE_HLSL
getAsTranslatorHLSL()70*8975f5c5SAndroid Build Coastguard Worker     virtual TranslatorHLSL *getAsTranslatorHLSL() { return nullptr; }
71*8975f5c5SAndroid Build Coastguard Worker #endif  // ANGLE_ENABLE_HLSL
72*8975f5c5SAndroid Build Coastguard Worker #ifdef ANGLE_ENABLE_METAL
getAsTranslatorMSL()73*8975f5c5SAndroid Build Coastguard Worker     virtual TranslatorMSL *getAsTranslatorMSL() { return nullptr; }
74*8975f5c5SAndroid Build Coastguard Worker #endif  // ANGLE_ENABLE_METAL
75*8975f5c5SAndroid Build Coastguard Worker 
76*8975f5c5SAndroid Build Coastguard Worker   protected:
77*8975f5c5SAndroid Build Coastguard Worker     // Memory allocator. Allocates and tracks memory required by the compiler.
78*8975f5c5SAndroid Build Coastguard Worker     // Deallocates all memory when compiler is destructed.
79*8975f5c5SAndroid Build Coastguard Worker     angle::PoolAllocator allocator;
80*8975f5c5SAndroid Build Coastguard Worker };
81*8975f5c5SAndroid Build Coastguard Worker 
82*8975f5c5SAndroid Build Coastguard Worker struct TFunctionMetadata
83*8975f5c5SAndroid Build Coastguard Worker {
84*8975f5c5SAndroid Build Coastguard Worker     bool used = false;
85*8975f5c5SAndroid Build Coastguard Worker };
86*8975f5c5SAndroid Build Coastguard Worker 
87*8975f5c5SAndroid Build Coastguard Worker //
88*8975f5c5SAndroid Build Coastguard Worker // The base class for the machine dependent compiler to derive from
89*8975f5c5SAndroid Build Coastguard Worker // for managing object code from the compile.
90*8975f5c5SAndroid Build Coastguard Worker //
91*8975f5c5SAndroid Build Coastguard Worker class TCompiler : public TShHandleBase
92*8975f5c5SAndroid Build Coastguard Worker {
93*8975f5c5SAndroid Build Coastguard Worker   public:
94*8975f5c5SAndroid Build Coastguard Worker     TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
95*8975f5c5SAndroid Build Coastguard Worker     ~TCompiler() override;
getAsCompiler()96*8975f5c5SAndroid Build Coastguard Worker     TCompiler *getAsCompiler() override { return this; }
97*8975f5c5SAndroid Build Coastguard Worker 
98*8975f5c5SAndroid Build Coastguard Worker     bool Init(const ShBuiltInResources &resources);
99*8975f5c5SAndroid Build Coastguard Worker 
100*8975f5c5SAndroid Build Coastguard Worker     // compileTreeForTesting should be used only when tests require access to
101*8975f5c5SAndroid Build Coastguard Worker     // the AST. Users of this function need to manually manage the global pool
102*8975f5c5SAndroid Build Coastguard Worker     // allocator. Returns nullptr whenever there are compilation errors.
103*8975f5c5SAndroid Build Coastguard Worker     TIntermBlock *compileTreeForTesting(const char *const shaderStrings[],
104*8975f5c5SAndroid Build Coastguard Worker                                         size_t numStrings,
105*8975f5c5SAndroid Build Coastguard Worker                                         const ShCompileOptions &compileOptions);
106*8975f5c5SAndroid Build Coastguard Worker 
107*8975f5c5SAndroid Build Coastguard Worker     bool compile(const char *const shaderStrings[],
108*8975f5c5SAndroid Build Coastguard Worker                  size_t numStrings,
109*8975f5c5SAndroid Build Coastguard Worker                  const ShCompileOptions &compileOptions);
110*8975f5c5SAndroid Build Coastguard Worker 
111*8975f5c5SAndroid Build Coastguard Worker     // Get results of the last compilation.
getShaderVersion()112*8975f5c5SAndroid Build Coastguard Worker     int getShaderVersion() const { return mShaderVersion; }
getInfoSink()113*8975f5c5SAndroid Build Coastguard Worker     TInfoSink &getInfoSink() { return mInfoSink; }
114*8975f5c5SAndroid Build Coastguard Worker 
specifyEarlyFragmentTests()115*8975f5c5SAndroid Build Coastguard Worker     bool specifyEarlyFragmentTests() { return mEarlyFragmentTestsSpecified = true; }
isEarlyFragmentTestsSpecified()116*8975f5c5SAndroid Build Coastguard Worker     bool isEarlyFragmentTestsSpecified() const { return mEarlyFragmentTestsSpecified; }
getMetadataFlags()117*8975f5c5SAndroid Build Coastguard Worker     MetadataFlagBits getMetadataFlags() const { return mMetadataFlags; }
getSpecConstUsageBits()118*8975f5c5SAndroid Build Coastguard Worker     SpecConstUsageBits getSpecConstUsageBits() const { return mSpecConstUsageBits; }
119*8975f5c5SAndroid Build Coastguard Worker 
isComputeShaderLocalSizeDeclared()120*8975f5c5SAndroid Build Coastguard Worker     bool isComputeShaderLocalSizeDeclared() const { return mComputeShaderLocalSizeDeclared; }
getComputeShaderLocalSize()121*8975f5c5SAndroid Build Coastguard Worker     const sh::WorkGroupSize &getComputeShaderLocalSize() const { return mComputeShaderLocalSize; }
getNumViews()122*8975f5c5SAndroid Build Coastguard Worker     int getNumViews() const { return mNumViews; }
123*8975f5c5SAndroid Build Coastguard Worker 
124*8975f5c5SAndroid Build Coastguard Worker     // Clears the results from the previous compilation.
125*8975f5c5SAndroid Build Coastguard Worker     void clearResults();
126*8975f5c5SAndroid Build Coastguard Worker 
getAttributes()127*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::ShaderVariable> &getAttributes() const { return mAttributes; }
getOutputVariables()128*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::ShaderVariable> &getOutputVariables() const { return mOutputVariables; }
getUniforms()129*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::ShaderVariable> &getUniforms() const { return mUniforms; }
getInputVaryings()130*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::ShaderVariable> &getInputVaryings() const { return mInputVaryings; }
getOutputVaryings()131*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::ShaderVariable> &getOutputVaryings() const { return mOutputVaryings; }
getInterfaceBlocks()132*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return mInterfaceBlocks; }
getUniformBlocks()133*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::InterfaceBlock> &getUniformBlocks() const { return mUniformBlocks; }
getShaderStorageBlocks()134*8975f5c5SAndroid Build Coastguard Worker     const std::vector<sh::InterfaceBlock> &getShaderStorageBlocks() const
135*8975f5c5SAndroid Build Coastguard Worker     {
136*8975f5c5SAndroid Build Coastguard Worker         return mShaderStorageBlocks;
137*8975f5c5SAndroid Build Coastguard Worker     }
138*8975f5c5SAndroid Build Coastguard Worker 
getHashFunction()139*8975f5c5SAndroid Build Coastguard Worker     ShHashFunction64 getHashFunction() const { return mResources.HashFunction; }
getNameMap()140*8975f5c5SAndroid Build Coastguard Worker     NameMap &getNameMap() { return mNameMap; }
getSymbolTable()141*8975f5c5SAndroid Build Coastguard Worker     TSymbolTable &getSymbolTable() { return mSymbolTable; }
getShaderSpec()142*8975f5c5SAndroid Build Coastguard Worker     ShShaderSpec getShaderSpec() const { return mShaderSpec; }
getOutputType()143*8975f5c5SAndroid Build Coastguard Worker     ShShaderOutput getOutputType() const { return mOutputType; }
getBuiltInResources()144*8975f5c5SAndroid Build Coastguard Worker     const ShBuiltInResources &getBuiltInResources() const { return mResources; }
getBuiltInResourcesString()145*8975f5c5SAndroid Build Coastguard Worker     const std::string &getBuiltInResourcesString() const { return mBuiltInResourcesString; }
146*8975f5c5SAndroid Build Coastguard Worker 
147*8975f5c5SAndroid Build Coastguard Worker     bool isHighPrecisionSupported() const;
148*8975f5c5SAndroid Build Coastguard Worker 
149*8975f5c5SAndroid Build Coastguard Worker     bool shouldRunLoopAndIndexingValidation(const ShCompileOptions &compileOptions) const;
150*8975f5c5SAndroid Build Coastguard Worker     bool shouldLimitTypeSizes() const;
151*8975f5c5SAndroid Build Coastguard Worker 
152*8975f5c5SAndroid Build Coastguard Worker     // Get the resources set by InitBuiltInSymbolTable
153*8975f5c5SAndroid Build Coastguard Worker     const ShBuiltInResources &getResources() const;
154*8975f5c5SAndroid Build Coastguard Worker 
getPragma()155*8975f5c5SAndroid Build Coastguard Worker     const TPragma &getPragma() const { return mPragma; }
156*8975f5c5SAndroid Build Coastguard Worker 
getGeometryShaderMaxVertices()157*8975f5c5SAndroid Build Coastguard Worker     int getGeometryShaderMaxVertices() const { return mGeometryShaderMaxVertices; }
getGeometryShaderInvocations()158*8975f5c5SAndroid Build Coastguard Worker     int getGeometryShaderInvocations() const { return mGeometryShaderInvocations; }
getGeometryShaderInputPrimitiveType()159*8975f5c5SAndroid Build Coastguard Worker     TLayoutPrimitiveType getGeometryShaderInputPrimitiveType() const
160*8975f5c5SAndroid Build Coastguard Worker     {
161*8975f5c5SAndroid Build Coastguard Worker         return mGeometryShaderInputPrimitiveType;
162*8975f5c5SAndroid Build Coastguard Worker     }
getGeometryShaderOutputPrimitiveType()163*8975f5c5SAndroid Build Coastguard Worker     TLayoutPrimitiveType getGeometryShaderOutputPrimitiveType() const
164*8975f5c5SAndroid Build Coastguard Worker     {
165*8975f5c5SAndroid Build Coastguard Worker         return mGeometryShaderOutputPrimitiveType;
166*8975f5c5SAndroid Build Coastguard Worker     }
167*8975f5c5SAndroid Build Coastguard Worker 
168*8975f5c5SAndroid Build Coastguard Worker     unsigned int getStructSize(const ShaderVariable &var) const;
169*8975f5c5SAndroid Build Coastguard Worker 
getTessControlShaderOutputVertices()170*8975f5c5SAndroid Build Coastguard Worker     int getTessControlShaderOutputVertices() const { return mTessControlShaderOutputVertices; }
getTessEvaluationShaderInputPrimitiveType()171*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType getTessEvaluationShaderInputPrimitiveType() const
172*8975f5c5SAndroid Build Coastguard Worker     {
173*8975f5c5SAndroid Build Coastguard Worker         return mTessEvaluationShaderInputPrimitiveType;
174*8975f5c5SAndroid Build Coastguard Worker     }
getTessEvaluationShaderInputVertexSpacingType()175*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType getTessEvaluationShaderInputVertexSpacingType() const
176*8975f5c5SAndroid Build Coastguard Worker     {
177*8975f5c5SAndroid Build Coastguard Worker         return mTessEvaluationShaderInputVertexSpacingType;
178*8975f5c5SAndroid Build Coastguard Worker     }
getTessEvaluationShaderInputOrderingType()179*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType getTessEvaluationShaderInputOrderingType() const
180*8975f5c5SAndroid Build Coastguard Worker     {
181*8975f5c5SAndroid Build Coastguard Worker         return mTessEvaluationShaderInputOrderingType;
182*8975f5c5SAndroid Build Coastguard Worker     }
getTessEvaluationShaderInputPointType()183*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType getTessEvaluationShaderInputPointType() const
184*8975f5c5SAndroid Build Coastguard Worker     {
185*8975f5c5SAndroid Build Coastguard Worker         return mTessEvaluationShaderInputPointType;
186*8975f5c5SAndroid Build Coastguard Worker     }
187*8975f5c5SAndroid Build Coastguard Worker 
hasAnyPreciseType()188*8975f5c5SAndroid Build Coastguard Worker     bool hasAnyPreciseType() const { return mHasAnyPreciseType; }
189*8975f5c5SAndroid Build Coastguard Worker 
getAdvancedBlendEquations()190*8975f5c5SAndroid Build Coastguard Worker     AdvancedBlendEquations getAdvancedBlendEquations() const { return mAdvancedBlendEquations; }
191*8975f5c5SAndroid Build Coastguard Worker 
hasPixelLocalStorageUniforms()192*8975f5c5SAndroid Build Coastguard Worker     bool hasPixelLocalStorageUniforms() const { return !mPixelLocalStorageFormats.empty(); }
GetPixelLocalStorageFormats()193*8975f5c5SAndroid Build Coastguard Worker     const std::vector<ShPixelLocalStorageFormat> &GetPixelLocalStorageFormats() const
194*8975f5c5SAndroid Build Coastguard Worker     {
195*8975f5c5SAndroid Build Coastguard Worker         return mPixelLocalStorageFormats;
196*8975f5c5SAndroid Build Coastguard Worker     }
197*8975f5c5SAndroid Build Coastguard Worker 
getPixelLocalStorageType()198*8975f5c5SAndroid Build Coastguard Worker     ShPixelLocalStorageType getPixelLocalStorageType() const { return mCompileOptions.pls.type; }
199*8975f5c5SAndroid Build Coastguard Worker 
200*8975f5c5SAndroid Build Coastguard Worker     unsigned int getSharedMemorySize() const;
201*8975f5c5SAndroid Build Coastguard Worker 
getShaderType()202*8975f5c5SAndroid Build Coastguard Worker     sh::GLenum getShaderType() const { return mShaderType; }
203*8975f5c5SAndroid Build Coastguard Worker 
204*8975f5c5SAndroid Build Coastguard Worker     // Generate a self-contained binary representation of the shader.
205*8975f5c5SAndroid Build Coastguard Worker     bool getShaderBinary(const ShHandle compilerHandle,
206*8975f5c5SAndroid Build Coastguard Worker                          const char *const shaderStrings[],
207*8975f5c5SAndroid Build Coastguard Worker                          size_t numStrings,
208*8975f5c5SAndroid Build Coastguard Worker                          const ShCompileOptions &compileOptions,
209*8975f5c5SAndroid Build Coastguard Worker                          ShaderBinaryBlob *const binaryOut);
210*8975f5c5SAndroid Build Coastguard Worker 
211*8975f5c5SAndroid Build Coastguard Worker     // Validate the AST and produce errors if it is inconsistent.
212*8975f5c5SAndroid Build Coastguard Worker     bool validateAST(TIntermNode *root);
213*8975f5c5SAndroid Build Coastguard Worker     // Some transformations may need to temporarily disable validation until they are complete.  A
214*8975f5c5SAndroid Build Coastguard Worker     // set of disable/enable helpers are used for this purpose.
215*8975f5c5SAndroid Build Coastguard Worker     bool disableValidateFunctionCall();
216*8975f5c5SAndroid Build Coastguard Worker     void restoreValidateFunctionCall(bool enable);
217*8975f5c5SAndroid Build Coastguard Worker     bool disableValidateVariableReferences();
218*8975f5c5SAndroid Build Coastguard Worker     void restoreValidateVariableReferences(bool enable);
219*8975f5c5SAndroid Build Coastguard Worker     // When the AST is post-processed (such as to determine precise-ness of intermediate nodes),
220*8975f5c5SAndroid Build Coastguard Worker     // it's expected to no longer transform.
221*8975f5c5SAndroid Build Coastguard Worker     void enableValidateNoMoreTransformations();
222*8975f5c5SAndroid Build Coastguard Worker 
areClipDistanceOrCullDistanceUsed()223*8975f5c5SAndroid Build Coastguard Worker     bool areClipDistanceOrCullDistanceUsed() const
224*8975f5c5SAndroid Build Coastguard Worker     {
225*8975f5c5SAndroid Build Coastguard Worker         return mClipDistanceSize > 0 || mCullDistanceSize > 0;
226*8975f5c5SAndroid Build Coastguard Worker     }
227*8975f5c5SAndroid Build Coastguard Worker 
getClipDistanceArraySize()228*8975f5c5SAndroid Build Coastguard Worker     uint8_t getClipDistanceArraySize() const { return mClipDistanceSize; }
229*8975f5c5SAndroid Build Coastguard Worker 
getCullDistanceArraySize()230*8975f5c5SAndroid Build Coastguard Worker     uint8_t getCullDistanceArraySize() const { return mCullDistanceSize; }
231*8975f5c5SAndroid Build Coastguard Worker 
usesDerivatives()232*8975f5c5SAndroid Build Coastguard Worker     bool usesDerivatives() const { return mUsesDerivatives; }
233*8975f5c5SAndroid Build Coastguard Worker 
supportsAttributeAliasing()234*8975f5c5SAndroid Build Coastguard Worker     bool supportsAttributeAliasing() const
235*8975f5c5SAndroid Build Coastguard Worker     {
236*8975f5c5SAndroid Build Coastguard Worker         return mShaderVersion == 100 && !IsWebGLBasedSpec(mShaderSpec);
237*8975f5c5SAndroid Build Coastguard Worker     }
238*8975f5c5SAndroid Build Coastguard Worker 
239*8975f5c5SAndroid Build Coastguard Worker   protected:
240*8975f5c5SAndroid Build Coastguard Worker     // Add emulated functions to the built-in function emulator.
initBuiltInFunctionEmulator(BuiltInFunctionEmulator * emu,const ShCompileOptions & compileOptions)241*8975f5c5SAndroid Build Coastguard Worker     virtual void initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu,
242*8975f5c5SAndroid Build Coastguard Worker                                              const ShCompileOptions &compileOptions)
243*8975f5c5SAndroid Build Coastguard Worker     {}
244*8975f5c5SAndroid Build Coastguard Worker     // Translate to object code. May generate performance warnings through the diagnostics.
245*8975f5c5SAndroid Build Coastguard Worker     [[nodiscard]] virtual bool translate(TIntermBlock *root,
246*8975f5c5SAndroid Build Coastguard Worker                                          const ShCompileOptions &compileOptions,
247*8975f5c5SAndroid Build Coastguard Worker                                          PerformanceDiagnostics *perfDiagnostics) = 0;
248*8975f5c5SAndroid Build Coastguard Worker     // Get built-in extensions with default behavior.
249*8975f5c5SAndroid Build Coastguard Worker     const TExtensionBehavior &getExtensionBehavior() const;
250*8975f5c5SAndroid Build Coastguard Worker     const char *getSourcePath() const;
251*8975f5c5SAndroid Build Coastguard Worker     // Relies on collectVariables having been called.
252*8975f5c5SAndroid Build Coastguard Worker     bool isVaryingDefined(const char *varyingName);
253*8975f5c5SAndroid Build Coastguard Worker 
254*8975f5c5SAndroid Build Coastguard Worker     const BuiltInFunctionEmulator &getBuiltInFunctionEmulator() const;
255*8975f5c5SAndroid Build Coastguard Worker 
256*8975f5c5SAndroid Build Coastguard Worker     virtual bool shouldFlattenPragmaStdglInvariantAll() = 0;
257*8975f5c5SAndroid Build Coastguard Worker 
258*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::ShaderVariable> mAttributes;
259*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::ShaderVariable> mOutputVariables;
260*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::ShaderVariable> mUniforms;
261*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::ShaderVariable> mInputVaryings;
262*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::ShaderVariable> mOutputVaryings;
263*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::ShaderVariable> mSharedVariables;
264*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::InterfaceBlock> mInterfaceBlocks;
265*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::InterfaceBlock> mUniformBlocks;
266*8975f5c5SAndroid Build Coastguard Worker     std::vector<sh::InterfaceBlock> mShaderStorageBlocks;
267*8975f5c5SAndroid Build Coastguard Worker 
268*8975f5c5SAndroid Build Coastguard Worker     // Track what should be validated given passes currently applied.
269*8975f5c5SAndroid Build Coastguard Worker     ValidateASTOptions mValidateASTOptions;
270*8975f5c5SAndroid Build Coastguard Worker 
271*8975f5c5SAndroid Build Coastguard Worker     MetadataFlagBits mMetadataFlags;
272*8975f5c5SAndroid Build Coastguard Worker 
273*8975f5c5SAndroid Build Coastguard Worker     // Specialization constant usage bits
274*8975f5c5SAndroid Build Coastguard Worker     SpecConstUsageBits mSpecConstUsageBits;
275*8975f5c5SAndroid Build Coastguard Worker 
276*8975f5c5SAndroid Build Coastguard Worker   private:
277*8975f5c5SAndroid Build Coastguard Worker     // Initialize symbol-table with built-in symbols.
278*8975f5c5SAndroid Build Coastguard Worker     bool initBuiltInSymbolTable(const ShBuiltInResources &resources);
279*8975f5c5SAndroid Build Coastguard Worker     // Compute the string representation of the built-in resources
280*8975f5c5SAndroid Build Coastguard Worker     void setResourceString();
281*8975f5c5SAndroid Build Coastguard Worker     // Return false if the call depth is exceeded.
282*8975f5c5SAndroid Build Coastguard Worker     bool checkCallDepth();
283*8975f5c5SAndroid Build Coastguard Worker     // Insert statements to reference all members in unused uniform blocks with standard and shared
284*8975f5c5SAndroid Build Coastguard Worker     // layout. This is to work around a Mac driver that treats unused standard/shared
285*8975f5c5SAndroid Build Coastguard Worker     // uniform blocks as inactive.
286*8975f5c5SAndroid Build Coastguard Worker     [[nodiscard]] bool useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root);
287*8975f5c5SAndroid Build Coastguard Worker     // Insert statements to initialize output variables in the beginning of main().
288*8975f5c5SAndroid Build Coastguard Worker     // This is to avoid undefined behaviors.
289*8975f5c5SAndroid Build Coastguard Worker     [[nodiscard]] bool initializeOutputVariables(TIntermBlock *root);
290*8975f5c5SAndroid Build Coastguard Worker     // Insert gl_Position = vec4(0,0,0,0) to the beginning of main().
291*8975f5c5SAndroid Build Coastguard Worker     // It is to work around a Linux driver bug where missing this causes compile failure
292*8975f5c5SAndroid Build Coastguard Worker     // while spec says it is allowed.
293*8975f5c5SAndroid Build Coastguard Worker     // This function should only be applied to vertex shaders.
294*8975f5c5SAndroid Build Coastguard Worker     [[nodiscard]] bool initializeGLPosition(TIntermBlock *root);
295*8975f5c5SAndroid Build Coastguard Worker     // Return true if the maximum expression complexity is below the limit.
296*8975f5c5SAndroid Build Coastguard Worker     bool limitExpressionComplexity(TIntermBlock *root);
297*8975f5c5SAndroid Build Coastguard Worker     // Creates the function call DAG for further analysis, returning false if there is a recursion
298*8975f5c5SAndroid Build Coastguard Worker     bool initCallDag(TIntermNode *root);
299*8975f5c5SAndroid Build Coastguard Worker     // Return false if "main" doesn't exist
300*8975f5c5SAndroid Build Coastguard Worker     bool tagUsedFunctions();
301*8975f5c5SAndroid Build Coastguard Worker     void internalTagUsedFunction(size_t index);
302*8975f5c5SAndroid Build Coastguard Worker 
303*8975f5c5SAndroid Build Coastguard Worker     void collectInterfaceBlocks();
304*8975f5c5SAndroid Build Coastguard Worker 
305*8975f5c5SAndroid Build Coastguard Worker     bool mVariablesCollected;
306*8975f5c5SAndroid Build Coastguard Worker 
307*8975f5c5SAndroid Build Coastguard Worker     bool mGLPositionInitialized;
308*8975f5c5SAndroid Build Coastguard Worker 
309*8975f5c5SAndroid Build Coastguard Worker     // Removes unused function declarations and prototypes from the AST
310*8975f5c5SAndroid Build Coastguard Worker     bool pruneUnusedFunctions(TIntermBlock *root);
311*8975f5c5SAndroid Build Coastguard Worker 
312*8975f5c5SAndroid Build Coastguard Worker     TIntermBlock *compileTreeImpl(const char *const shaderStrings[],
313*8975f5c5SAndroid Build Coastguard Worker                                   size_t numStrings,
314*8975f5c5SAndroid Build Coastguard Worker                                   const ShCompileOptions &compileOptions);
315*8975f5c5SAndroid Build Coastguard Worker 
316*8975f5c5SAndroid Build Coastguard Worker     // Fetches and stores shader metadata that is not stored within the AST itself, such as shader
317*8975f5c5SAndroid Build Coastguard Worker     // version.
318*8975f5c5SAndroid Build Coastguard Worker     void setASTMetadata(const TParseContext &parseContext);
319*8975f5c5SAndroid Build Coastguard Worker 
320*8975f5c5SAndroid Build Coastguard Worker     // Check if shader version meets the requirement.
321*8975f5c5SAndroid Build Coastguard Worker     bool checkShaderVersion(TParseContext *parseContext);
322*8975f5c5SAndroid Build Coastguard Worker 
323*8975f5c5SAndroid Build Coastguard Worker     // Does checks that need to be run after parsing is complete and returns true if they pass.
324*8975f5c5SAndroid Build Coastguard Worker     bool checkAndSimplifyAST(TIntermBlock *root,
325*8975f5c5SAndroid Build Coastguard Worker                              const TParseContext &parseContext,
326*8975f5c5SAndroid Build Coastguard Worker                              const ShCompileOptions &compileOptions);
327*8975f5c5SAndroid Build Coastguard Worker 
328*8975f5c5SAndroid Build Coastguard Worker     bool postParseChecks(const TParseContext &parseContext);
329*8975f5c5SAndroid Build Coastguard Worker 
330*8975f5c5SAndroid Build Coastguard Worker     sh::GLenum mShaderType;
331*8975f5c5SAndroid Build Coastguard Worker     ShShaderSpec mShaderSpec;
332*8975f5c5SAndroid Build Coastguard Worker     ShShaderOutput mOutputType;
333*8975f5c5SAndroid Build Coastguard Worker 
334*8975f5c5SAndroid Build Coastguard Worker     CallDAG mCallDag;
335*8975f5c5SAndroid Build Coastguard Worker     std::vector<TFunctionMetadata> mFunctionMetadata;
336*8975f5c5SAndroid Build Coastguard Worker 
337*8975f5c5SAndroid Build Coastguard Worker     ShBuiltInResources mResources;
338*8975f5c5SAndroid Build Coastguard Worker     std::string mBuiltInResourcesString;
339*8975f5c5SAndroid Build Coastguard Worker 
340*8975f5c5SAndroid Build Coastguard Worker     // Built-in symbol table for the given language, spec, and resources.
341*8975f5c5SAndroid Build Coastguard Worker     // It is preserved from compile-to-compile.
342*8975f5c5SAndroid Build Coastguard Worker     TSymbolTable mSymbolTable;
343*8975f5c5SAndroid Build Coastguard Worker     // Built-in extensions with default behavior.
344*8975f5c5SAndroid Build Coastguard Worker     TExtensionBehavior mExtensionBehavior;
345*8975f5c5SAndroid Build Coastguard Worker 
346*8975f5c5SAndroid Build Coastguard Worker     BuiltInFunctionEmulator mBuiltInFunctionEmulator;
347*8975f5c5SAndroid Build Coastguard Worker 
348*8975f5c5SAndroid Build Coastguard Worker     // Results of compilation.
349*8975f5c5SAndroid Build Coastguard Worker     int mShaderVersion;
350*8975f5c5SAndroid Build Coastguard Worker     TInfoSink mInfoSink;  // Output sink.
351*8975f5c5SAndroid Build Coastguard Worker     TDiagnostics mDiagnostics;
352*8975f5c5SAndroid Build Coastguard Worker     const char *mSourcePath;  // Path of source file or NULL
353*8975f5c5SAndroid Build Coastguard Worker 
354*8975f5c5SAndroid Build Coastguard Worker     // Fragment shader early fragment tests
355*8975f5c5SAndroid Build Coastguard Worker     bool mEarlyFragmentTestsSpecified;
356*8975f5c5SAndroid Build Coastguard Worker 
357*8975f5c5SAndroid Build Coastguard Worker     // compute shader local group size
358*8975f5c5SAndroid Build Coastguard Worker     bool mComputeShaderLocalSizeDeclared;
359*8975f5c5SAndroid Build Coastguard Worker     sh::WorkGroupSize mComputeShaderLocalSize;
360*8975f5c5SAndroid Build Coastguard Worker 
361*8975f5c5SAndroid Build Coastguard Worker     // GL_OVR_multiview num_views.
362*8975f5c5SAndroid Build Coastguard Worker     int mNumViews;
363*8975f5c5SAndroid Build Coastguard Worker 
364*8975f5c5SAndroid Build Coastguard Worker     // Track gl_ClipDistance / gl_CullDistance usage.
365*8975f5c5SAndroid Build Coastguard Worker     uint8_t mClipDistanceSize;
366*8975f5c5SAndroid Build Coastguard Worker     uint8_t mCullDistanceSize;
367*8975f5c5SAndroid Build Coastguard Worker 
368*8975f5c5SAndroid Build Coastguard Worker     // geometry shader parameters.
369*8975f5c5SAndroid Build Coastguard Worker     int mGeometryShaderMaxVertices;
370*8975f5c5SAndroid Build Coastguard Worker     int mGeometryShaderInvocations;
371*8975f5c5SAndroid Build Coastguard Worker     TLayoutPrimitiveType mGeometryShaderInputPrimitiveType;
372*8975f5c5SAndroid Build Coastguard Worker     TLayoutPrimitiveType mGeometryShaderOutputPrimitiveType;
373*8975f5c5SAndroid Build Coastguard Worker 
374*8975f5c5SAndroid Build Coastguard Worker     // tesssellation shader parameters
375*8975f5c5SAndroid Build Coastguard Worker     int mTessControlShaderOutputVertices;
376*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType mTessEvaluationShaderInputPrimitiveType;
377*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType mTessEvaluationShaderInputVertexSpacingType;
378*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType mTessEvaluationShaderInputOrderingType;
379*8975f5c5SAndroid Build Coastguard Worker     TLayoutTessEvaluationType mTessEvaluationShaderInputPointType;
380*8975f5c5SAndroid Build Coastguard Worker 
381*8975f5c5SAndroid Build Coastguard Worker     bool mHasAnyPreciseType;
382*8975f5c5SAndroid Build Coastguard Worker 
383*8975f5c5SAndroid Build Coastguard Worker     // advanced blend equation parameters
384*8975f5c5SAndroid Build Coastguard Worker     AdvancedBlendEquations mAdvancedBlendEquations;
385*8975f5c5SAndroid Build Coastguard Worker 
386*8975f5c5SAndroid Build Coastguard Worker     // ANGLE_shader_pixel_local_storage: A mapping from binding index to the PLS uniform format at
387*8975f5c5SAndroid Build Coastguard Worker     // that index.
388*8975f5c5SAndroid Build Coastguard Worker     std::vector<ShPixelLocalStorageFormat> mPixelLocalStorageFormats;
389*8975f5c5SAndroid Build Coastguard Worker 
390*8975f5c5SAndroid Build Coastguard Worker     // Fragment shader uses screen-space derivatives
391*8975f5c5SAndroid Build Coastguard Worker     bool mUsesDerivatives;
392*8975f5c5SAndroid Build Coastguard Worker 
393*8975f5c5SAndroid Build Coastguard Worker     // name hashing.
394*8975f5c5SAndroid Build Coastguard Worker     NameMap mNameMap;
395*8975f5c5SAndroid Build Coastguard Worker 
396*8975f5c5SAndroid Build Coastguard Worker     TPragma mPragma;
397*8975f5c5SAndroid Build Coastguard Worker 
398*8975f5c5SAndroid Build Coastguard Worker     ShCompileOptions mCompileOptions;
399*8975f5c5SAndroid Build Coastguard Worker };
400*8975f5c5SAndroid Build Coastguard Worker 
401*8975f5c5SAndroid Build Coastguard Worker //
402*8975f5c5SAndroid Build Coastguard Worker // This is the interface between the machine independent code
403*8975f5c5SAndroid Build Coastguard Worker // and the machine dependent code.
404*8975f5c5SAndroid Build Coastguard Worker //
405*8975f5c5SAndroid Build Coastguard Worker // The machine dependent code should derive from the classes
406*8975f5c5SAndroid Build Coastguard Worker // above. Then Construct*() and Delete*() will create and
407*8975f5c5SAndroid Build Coastguard Worker // destroy the machine dependent objects, which contain the
408*8975f5c5SAndroid Build Coastguard Worker // above machine independent information.
409*8975f5c5SAndroid Build Coastguard Worker //
410*8975f5c5SAndroid Build Coastguard Worker TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
411*8975f5c5SAndroid Build Coastguard Worker void DeleteCompiler(TCompiler *);
412*8975f5c5SAndroid Build Coastguard Worker 
413*8975f5c5SAndroid Build Coastguard Worker struct ShaderDumpHeader
414*8975f5c5SAndroid Build Coastguard Worker {
415*8975f5c5SAndroid Build Coastguard Worker     uint32_t type;
416*8975f5c5SAndroid Build Coastguard Worker     uint32_t spec;
417*8975f5c5SAndroid Build Coastguard Worker     uint32_t output;
418*8975f5c5SAndroid Build Coastguard Worker     uint8_t basicCompileOptions[32];
419*8975f5c5SAndroid Build Coastguard Worker     uint8_t metalCompileOptions[32];
420*8975f5c5SAndroid Build Coastguard Worker     uint8_t plsCompileOptions[32];
421*8975f5c5SAndroid Build Coastguard Worker     uint8_t padding[20];
422*8975f5c5SAndroid Build Coastguard Worker };
423*8975f5c5SAndroid Build Coastguard Worker static_assert(sizeof(ShaderDumpHeader) == 128);
424*8975f5c5SAndroid Build Coastguard Worker 
425*8975f5c5SAndroid Build Coastguard Worker }  // namespace sh
426*8975f5c5SAndroid Build Coastguard Worker 
427*8975f5c5SAndroid Build Coastguard Worker #endif  // COMPILER_TRANSLATOR_COMPILER_H_
428