// // 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. // #ifndef GLSLANG_SHADERLANG_H_ #define GLSLANG_SHADERLANG_H_ #include <stddef.h> #include "KHR/khrplatform.h" #include <array> #include <map> #include <set> #include <string> #include <vector> // // This is the platform independent interface between an OGL driver // and the shading language compiler. // // Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h #include "ShaderVars.h" // Version number for shader translation API. // It is incremented every time the API changes. #define ANGLE_SH_VERSION … enum ShShaderSpec { … }; enum ShShaderOutput { … }; struct ShCompileOptionsMetal { … }; // For ANGLE_shader_pixel_local_storage. // Instructs the compiler which pixel local storage configuration to generate code for. enum class ShPixelLocalStorageType : uint8_t { … }; // For ANGLE_shader_pixel_local_storage_coherent. // Instructs the compiler which fragment synchronization method to use, if any. enum class ShFragmentSynchronizationType : uint8_t { … }; struct ShPixelLocalStorageOptions { … }; struct ShCompileOptions { … }; // The 64 bits hash function. The first parameter is the input string; the // second parameter is the string length. ShHashFunction64; // // Implementation dependent built-in resources (constants and extensions). // The names for these resources has been obtained by stripping gl_/GL_. // struct ShBuiltInResources { … }; // // ShHandle held by but opaque to the driver. It is allocated, // managed, and de-allocated by the compiler. Its contents // are defined by and used by the compiler. // // If handle creation fails, 0 will be returned. // ShHandle; namespace sh { BinaryBlob; ShaderBinaryBlob; // // Driver must call this first, once, before doing any other compiler operations. // If the function succeeds, the return value is true, else false. // bool Initialize(); // // Driver should call this at shutdown. // If the function succeeds, the return value is true, else false. // bool Finalize(); // // Initialize built-in resources with minimum expected values. // Parameters: // resources: The object to initialize. Will be comparable with memcmp. // void InitBuiltInResources(ShBuiltInResources *resources); // // Returns a copy of the current ShBuiltInResources stored in the compiler. // Parameters: // handle: Specifies the handle of the compiler to be used. ShBuiltInResources GetBuiltInResources(const ShHandle handle); // // Returns the a concatenated list of the items in ShBuiltInResources as a null-terminated string. // This function must be updated whenever ShBuiltInResources is changed. // Parameters: // handle: Specifies the handle of the compiler to be used. const std::string &GetBuiltInResourcesString(const ShHandle handle); // // Driver calls these to create and destroy compiler objects. // // Returns the handle of constructed compiler, null if the requested compiler is not supported. // Parameters: // type: Specifies the type of shader - GL_FRAGMENT_SHADER or GL_VERTEX_SHADER. // spec: Specifies the language spec the compiler must conform to - SH_GLES2_SPEC or SH_WEBGL_SPEC. // output: Specifies the output code type - for example SH_ESSL_OUTPUT, SH_GLSL_OUTPUT, // SH_HLSL_3_0_OUTPUT or SH_HLSL_4_1_OUTPUT. Note: Each output type may only // be supported in some configurations. // resources: Specifies the built-in resources. ShHandle ConstructCompiler(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources *resources); void Destruct(ShHandle handle); // // Compiles the given shader source. // If the function succeeds, the return value is true, else false. // Parameters: // handle: Specifies the handle of compiler to be used. // shaderStrings: Specifies an array of pointers to null-terminated strings containing the shader // source code. // numStrings: Specifies the number of elements in shaderStrings array. // compileOptions: A mask of compile options defined above. bool Compile(const ShHandle handle, const char *const shaderStrings[], size_t numStrings, const ShCompileOptions &compileOptions); // Clears the results from the previous compilation. void ClearResults(const ShHandle handle); // Return the version of the shader language. int GetShaderVersion(const ShHandle handle); // Return the currently set language output type. ShShaderOutput GetShaderOutputType(const ShHandle handle); // Returns null-terminated information log for a compiled shader. // Parameters: // handle: Specifies the compiler const std::string &GetInfoLog(const ShHandle handle); // Returns null-terminated object code for a compiled shader. Only valid for output types that // generate human-readable code (GLSL, ESSL or HLSL). // Parameters: // handle: Specifies the compiler const std::string &GetObjectCode(const ShHandle handle); // Returns object binary blob for a compiled shader. Only valid for output types that // generate binary blob (SPIR-V). // Parameters: // handle: Specifies the compiler const BinaryBlob &GetObjectBinaryBlob(const ShHandle handle); // Returns a full binary for a compiled shader, to be loaded with glShaderBinary during runtime. // Parameters: // handle: Specifies the compiler bool GetShaderBinary(const ShHandle handle, const char *const shaderStrings[], size_t numStrings, const ShCompileOptions &compileOptions, ShaderBinaryBlob *const binaryOut); // Returns a (original_name, hash) map containing all the user defined names in the shader, // including variable names, function names, struct names, and struct field names. // Parameters: // handle: Specifies the compiler const std::map<std::string, std::string> *GetNameHashingMap(const ShHandle handle); // Shader variable inspection. // Returns a pointer to a list of variables of the designated type. // (See ShaderVars.h for type definitions, included above) // Returns NULL on failure. // Parameters: // handle: Specifies the compiler const std::vector<sh::ShaderVariable> *GetUniforms(const ShHandle handle); const std::vector<sh::ShaderVariable> *GetVaryings(const ShHandle handle); const std::vector<sh::ShaderVariable> *GetInputVaryings(const ShHandle handle); const std::vector<sh::ShaderVariable> *GetOutputVaryings(const ShHandle handle); const std::vector<sh::ShaderVariable> *GetAttributes(const ShHandle handle); const std::vector<sh::ShaderVariable> *GetOutputVariables(const ShHandle handle); const std::vector<sh::InterfaceBlock> *GetInterfaceBlocks(const ShHandle handle); const std::vector<sh::InterfaceBlock> *GetUniformBlocks(const ShHandle handle); const std::vector<sh::InterfaceBlock> *GetShaderStorageBlocks(const ShHandle handle); sh::WorkGroupSize GetComputeShaderLocalGroupSize(const ShHandle handle); // Returns the number of views specified through the num_views layout qualifier. If num_views is // not set, the function returns -1. int GetVertexShaderNumViews(const ShHandle handle); // Returns specialization constant usage bits uint32_t GetShaderSpecConstUsageBits(const ShHandle handle); // Returns true if the passed in variables pack in maxVectors followingthe packing rules from the // GLSL 1.017 spec, Appendix A, section 7. // Returns false otherwise. Also look at the enforcePackingRestrictions flag above. // Parameters: // maxVectors: the available rows of registers. // variables: an array of variables. bool CheckVariablesWithinPackingLimits(int maxVectors, const std::vector<sh::ShaderVariable> &variables); // Gives the compiler-assigned register for a shader storage block. // The method writes the value to the output variable "indexOut". // Returns true if it found a valid shader storage block, false otherwise. // Parameters: // handle: Specifies the compiler // shaderStorageBlockName: Specifies the shader storage block // indexOut: output variable that stores the assigned register bool GetShaderStorageBlockRegister(const ShHandle handle, const std::string &shaderStorageBlockName, unsigned int *indexOut); // Gives the compiler-assigned register for a uniform block. // The method writes the value to the output variable "indexOut". // Returns true if it found a valid uniform block, false otherwise. // Parameters: // handle: Specifies the compiler // uniformBlockName: Specifies the uniform block // indexOut: output variable that stores the assigned register bool GetUniformBlockRegister(const ShHandle handle, const std::string &uniformBlockName, unsigned int *indexOut); bool ShouldUniformBlockUseStructuredBuffer(const ShHandle handle, const std::string &uniformBlockName); const std::set<std::string> *GetSlowCompilingUniformBlockSet(const ShHandle handle); // Gives a map from uniform names to compiler-assigned registers in the default uniform block. // Note that the map contains also registers of samplers that have been extracted from structs. const std::map<std::string, unsigned int> *GetUniformRegisterMap(const ShHandle handle); // Sampler, image and atomic counters share registers(t type and u type), // GetReadonlyImage2DRegisterIndex and GetImage2DRegisterIndex return the first index into // a range of reserved registers for image2D/iimage2D/uimage2D variables. // Parameters: handle: Specifies the compiler unsigned int GetReadonlyImage2DRegisterIndex(const ShHandle handle); unsigned int GetImage2DRegisterIndex(const ShHandle handle); // The method records these used function names related with image2D/iimage2D/uimage2D, these // functions will be dynamically generated. // Parameters: // handle: Specifies the compiler const std::set<std::string> *GetUsedImage2DFunctionNames(const ShHandle handle); uint8_t GetClipDistanceArraySize(const ShHandle handle); uint8_t GetCullDistanceArraySize(const ShHandle handle); GLenum GetGeometryShaderInputPrimitiveType(const ShHandle handle); GLenum GetGeometryShaderOutputPrimitiveType(const ShHandle handle); int GetGeometryShaderInvocations(const ShHandle handle); int GetGeometryShaderMaxVertices(const ShHandle handle); unsigned int GetShaderSharedMemorySize(const ShHandle handle); int GetTessControlShaderVertices(const ShHandle handle); GLenum GetTessGenMode(const ShHandle handle); GLenum GetTessGenSpacing(const ShHandle handle); GLenum GetTessGenVertexOrder(const ShHandle handle); GLenum GetTessGenPointMode(const ShHandle handle); // Returns a bitset of sh::MetadataFlags. This bundles various bits purely for convenience. uint32_t GetMetadataFlags(const ShHandle handle); // Returns the blend equation list supported in the fragment shader. This is a bitset of // gl::BlendEquationType, and can only include bits from KHR_blend_equation_advanced. uint32_t GetAdvancedBlendEquations(const ShHandle handle); // // Helper function to identify specs that are based on the WebGL spec. // inline bool IsWebGLBasedSpec(ShShaderSpec spec) { … } // // Helper function to identify DesktopGL specs // inline bool IsDesktopGLSpec(ShShaderSpec spec) { … } // Can't prefix with just _ because then we might introduce a double underscore, which is not safe // in GLSL (ESSL 3.00.6 section 3.8: All identifiers containing a double underscore are reserved for // use by the underlying implementation). u is short for user-defined. extern const char kUserDefinedNamePrefix[]; enum class MetadataFlags { … }; namespace vk { // Specialization constant ids enum class SpecializationConstantId : uint32_t { … }; enum class SpecConstUsage : uint32_t { … }; enum ColorAttachmentDitherControl { … }; namespace spirv { enum NonSemanticInstruction { … }; // The non-semantic instruction id has many bits available. With kNonSemanticOverview, they are // used to provide additional overview details. Providing this information in the instruction's // payload require OpConstants and recovering those, which is unnecessary complexity. constexpr uint32_t kNonSemanticInstructionBits = …; constexpr uint32_t kNonSemanticInstructionMask = …; constexpr uint32_t kOverviewHasSampleRateShadingMask = …; constexpr uint32_t kOverviewHasSampleIDMask = …; constexpr uint32_t kOverviewHasOutputPerVertexMask = …; enum ReservedIds { … }; } // namespace spirv // Packing information for driver uniform's misc field: // - 1 bit for whether surface rotation results in swapped axes // - 5 bits for advanced blend equation // - 6 bits for sample count // - 8 bits for enabled clip planes // - 1 bit for whether depth should be transformed to Vulkan clip space // - 1 bit for whether alpha to coverage is enabled // - 10 bits unused constexpr uint32_t kDriverUniformsMiscSwapXYMask = …; constexpr uint32_t kDriverUniformsMiscAdvancedBlendEquationOffset = …; constexpr uint32_t kDriverUniformsMiscAdvancedBlendEquationMask = …; constexpr uint32_t kDriverUniformsMiscSampleCountOffset = …; constexpr uint32_t kDriverUniformsMiscSampleCountMask = …; constexpr uint32_t kDriverUniformsMiscEnabledClipPlanesOffset = …; constexpr uint32_t kDriverUniformsMiscEnabledClipPlanesMask = …; constexpr uint32_t kDriverUniformsMiscTransformDepthOffset = …; constexpr uint32_t kDriverUniformsMiscTransformDepthMask = …; constexpr uint32_t kDriverUniformsMiscAlphaToCoverageOffset = …; constexpr uint32_t kDriverUniformsMiscAlphaToCoverageMask = …; } // namespace vk namespace mtl { // Specialization constant to enable multisampled rendering behavior. extern const char kMultisampledRenderingConstName[]; // Specialization constant to emulate rasterizer discard. extern const char kRasterizerDiscardEnabledConstName[]; // Specialization constant to enable depth write in fragment shaders. extern const char kDepthWriteEnabledConstName[]; // Specialization constant to enable alpha to coverage. extern const char kEmulateAlphaToCoverageConstName[]; // Specialization constant to write helper sample mask output. extern const char kWriteHelperSampleMaskConstName[]; // Specialization constant to enable sample mask output. extern const char kSampleMaskWriteEnabledConstName[]; } // namespace mtl } // namespace sh #endif // GLSLANG_SHADERLANG_H_