// // Copyright 2002 The ANGLE Project Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. //
class TCompiler; class TParseContext; #ifdef ANGLE_ENABLE_HLSL class TranslatorHLSL; #endif// ANGLE_ENABLE_HLSL #ifdef ANGLE_ENABLE_METAL class TranslatorMetalDirect; #endif// ANGLE_ENABLE_METAL
using SpecConstUsageBits = angle::PackedEnumBitSet<vk::SpecConstUsage, uint32_t>;
// // Helper function to check if the shader type is GLSL. // bool IsGLSL130OrNewer(ShShaderOutput output); bool IsGLSL420OrNewer(ShShaderOutput output); bool IsGLSL410OrOlder(ShShaderOutput output);
// // Helper function to check if the invariant qualifier can be removed. // bool RemoveInvariant(sh::GLenum shaderType, int shaderVersion,
ShShaderOutput outputType, const ShCompileOptions &compileOptions);
// // The base class used to back handles returned to the driver. // class TShHandleBase
{ public:
TShHandleBase(); virtual ~TShHandleBase(); virtual TCompiler *getAsCompiler() { return 0; } #ifdef ANGLE_ENABLE_HLSL virtual TranslatorHLSL *getAsTranslatorHLSL() { return 0; } #endif// ANGLE_ENABLE_HLSL #ifdef ANGLE_ENABLE_METAL virtual TranslatorMetalDirect *getAsTranslatorMetalDirect() { return nullptr; } #endif// ANGLE_ENABLE_METAL
protected: // Memory allocator. Allocates and tracks memory required by the compiler. // Deallocates all memory when compiler is destructed.
angle::PoolAllocator allocator;
};
struct TFunctionMetadata
{ bool used = false;
};
// // The base class for the machine dependent compiler to derive from // for managing object code from the compile. // class TCompiler : public TShHandleBase
{ public:
TCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
~TCompiler() override;
TCompiler *getAsCompiler() override { returnthis; }
bool Init(const ShBuiltInResources &resources);
// compileTreeForTesting should be used only when tests require access to // the AST. Users of this function need to manually manage the global pool // allocator. Returns nullptr whenever there are compilation errors.
TIntermBlock *compileTreeForTesting(constchar *const shaderStrings[],
size_t numStrings, const ShCompileOptions &compileOptions);
// Validate the AST and produce errors if it is inconsistent. bool validateAST(TIntermNode *root); // Some transformations may need to temporarily disable validation until they are complete. A // set of disable/enable helpers are used for this purpose. bool disableValidateFunctionCall(); void restoreValidateFunctionCall(bool enable); bool disableValidateVariableReferences(); void restoreValidateVariableReferences(bool enable); // When the AST is post-processed (such as to determine precise-ness of intermediate nodes), // it's expected to no longer transform. void enableValidateNoMoreTransformations();
protected: // Add emulated functions to the built-in function emulator. virtualvoid initBuiltInFunctionEmulator(BuiltInFunctionEmulator *emu, const ShCompileOptions &compileOptions)
{} // Translate to object code. May generate performance warnings through the diagnostics.
[[nodiscard]] virtualbool translate(TIntermBlock *root, const ShCompileOptions &compileOptions,
PerformanceDiagnostics *perfDiagnostics) = 0; // Get built-in extensions with default behavior. const TExtensionBehavior &getExtensionBehavior() const; constchar *getSourcePath() const; // Relies on collectVariables having been called. bool isVaryingDefined(constchar *varyingName);
private: // Initialize symbol-table with built-in symbols. bool initBuiltInSymbolTable(const ShBuiltInResources &resources); // Compute the string representation of the built-in resources void setResourceString(); // Return false if the call depth is exceeded. bool checkCallDepth(); // Insert statements to reference all members in unused uniform blocks with standard and shared // layout. This is to work around a Mac driver that treats unused standard/shared // uniform blocks as inactive.
[[nodiscard]] bool useAllMembersInUnusedStandardAndSharedBlocks(TIntermBlock *root); // Insert statements to initialize output variables in the beginning of main(). // This is to avoid undefined behaviors.
[[nodiscard]] bool initializeOutputVariables(TIntermBlock *root); // Insert gl_Position = vec4(0,0,0,0) to the beginning of main(). // It is to work around a Linux driver bug where missing this causes compile failure // while spec says it is allowed. // This function should only be applied to vertex shaders.
[[nodiscard]] bool initializeGLPosition(TIntermBlock *root); // Return true if the maximum expression complexity is below the limit. bool limitExpressionComplexity(TIntermBlock *root); // Creates the function call DAG for further analysis, returning false if there is a recursion bool initCallDag(TIntermNode *root); // Return false if "main" doesn't exist bool tagUsedFunctions(); void internalTagUsedFunction(size_t index);
void collectInterfaceBlocks();
bool mVariablesCollected;
bool mGLPositionInitialized;
// Removes unused function declarations and prototypes from the AST bool pruneUnusedFunctions(TIntermBlock *root);
// Fetches and stores shader metadata that is not stored within the AST itself, such as shader // version. void setASTMetadata(const TParseContext &parseContext);
// Check if shader version meets the requirement. bool checkShaderVersion(TParseContext *parseContext);
// Does checks that need to be run after parsing is complete and returns true if they pass. bool checkAndSimplifyAST(TIntermBlock *root, const TParseContext &parseContext, const ShCompileOptions &compileOptions);
// Built-in symbol table for the given language, spec, and resources. // It is preserved from compile-to-compile.
TSymbolTable mSymbolTable; // Built-in extensions with default behavior.
TExtensionBehavior mExtensionBehavior;
BuiltInFunctionEmulator mBuiltInFunctionEmulator;
// Results of compilation. int mShaderVersion;
TInfoSink mInfoSink; // Output sink.
TDiagnostics mDiagnostics; constchar *mSourcePath; // Path of source file or NULL
// Fragment shader early fragment tests bool mEarlyFragmentTestsSpecified;
// Fragment shader has the discard instruction bool mHasDiscard;
// Whether per-sample shading is enabled by the shader. In OpenGL, this keyword should // implicitly trigger per-sample shading without the API enabling it. bool mEnablesPerSampleShading;
// compute shader local group size bool mComputeShaderLocalSizeDeclared;
sh::WorkGroupSize mComputeShaderLocalSize;
// GL_OVR_multiview num_views. int mNumViews;
// geometry shader parameters. int mGeometryShaderMaxVertices; int mGeometryShaderInvocations;
TLayoutPrimitiveType mGeometryShaderInputPrimitiveType;
TLayoutPrimitiveType mGeometryShaderOutputPrimitiveType;
// // This is the interface between the machine independent code // and the machine dependent code. // // The machine dependent code should derive from the classes // above. Then Construct*() and Delete*() will create and // destroy the machine dependent objects, which contain the // above machine independent information. //
TCompiler *ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output); void DeleteCompiler(TCompiler *);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.