1 // 2 // Copyright 2022 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // CompiledShaderState.h: 7 // Defines a struct containing any data that is needed to build 8 // a CompiledShaderState from a TCompiler. 9 // 10 11 #ifndef COMMON_COMPILEDSHADERSTATE_H_ 12 #define COMMON_COMPILEDSHADERSTATE_H_ 13 14 #include "common/BinaryStream.h" 15 #include "common/Optional.h" 16 #include "common/PackedEnums.h" 17 18 #include <GLSLANG/ShaderLang.h> 19 #include <GLSLANG/ShaderVars.h> 20 21 #include <memory> 22 #include <string> 23 24 namespace sh 25 { 26 struct BlockMemberInfo; 27 28 using CompilerMetadataFlags = angle::PackedEnumBitSet<sh::MetadataFlags, uint32_t>; 29 } // namespace sh 30 31 namespace gl 32 { 33 34 // @todo this type is also defined in compiler/Compiler.h and libANGLE/renderer_utils.h. Move this 35 // to a single common definition? 36 using SpecConstUsageBits = angle::PackedEnumBitSet<sh::vk::SpecConstUsage, uint32_t>; 37 38 // Helper functions for serializing shader variables 39 void WriteShaderVar(gl::BinaryOutputStream *stream, const sh::ShaderVariable &var); 40 void LoadShaderVar(gl::BinaryInputStream *stream, sh::ShaderVariable *var); 41 42 void WriteShInterfaceBlock(gl::BinaryOutputStream *stream, const sh::InterfaceBlock &block); 43 void LoadShInterfaceBlock(gl::BinaryInputStream *stream, sh::InterfaceBlock *block); 44 45 bool CompareShaderVar(const sh::ShaderVariable &x, const sh::ShaderVariable &y); 46 47 struct CompiledShaderState 48 { 49 CompiledShaderState(gl::ShaderType shaderType); 50 ~CompiledShaderState(); 51 52 void buildCompiledShaderState(const ShHandle compilerHandle, const bool isBinaryOutput); 53 54 void serialize(gl::BinaryOutputStream &stream) const; 55 void deserialize(gl::BinaryInputStream &stream); 56 hasValidGeometryShaderInputPrimitiveTypeCompiledShaderState57 bool hasValidGeometryShaderInputPrimitiveType() const 58 { 59 return metadataFlags[sh::MetadataFlags::HasValidGeometryShaderInputPrimitiveType]; 60 } hasValidGeometryShaderOutputPrimitiveTypeCompiledShaderState61 bool hasValidGeometryShaderOutputPrimitiveType() const 62 { 63 return metadataFlags[sh::MetadataFlags::HasValidGeometryShaderOutputPrimitiveType]; 64 } hasValidGeometryShaderMaxVerticesCompiledShaderState65 bool hasValidGeometryShaderMaxVertices() const 66 { 67 return metadataFlags[sh::MetadataFlags::HasValidGeometryShaderMaxVertices]; 68 } 69 70 const gl::ShaderType shaderType; 71 72 int shaderVersion; 73 std::string translatedSource; 74 sh::BinaryBlob compiledBinary; 75 sh::WorkGroupSize localSize; 76 77 std::vector<sh::ShaderVariable> inputVaryings; 78 std::vector<sh::ShaderVariable> outputVaryings; 79 std::vector<sh::ShaderVariable> uniforms; 80 std::vector<sh::InterfaceBlock> uniformBlocks; 81 std::vector<sh::InterfaceBlock> shaderStorageBlocks; 82 std::vector<sh::ShaderVariable> allAttributes; 83 std::vector<sh::ShaderVariable> activeAttributes; 84 std::vector<sh::ShaderVariable> activeOutputVariables; 85 86 sh::CompilerMetadataFlags metadataFlags; 87 gl::BlendEquationBitSet advancedBlendEquations; 88 SpecConstUsageBits specConstUsageBits; 89 90 // GL_OVR_multiview / GL_OVR_multiview2 91 int numViews; 92 93 // Geometry Shader 94 gl::PrimitiveMode geometryShaderInputPrimitiveType; 95 gl::PrimitiveMode geometryShaderOutputPrimitiveType; 96 GLint geometryShaderMaxVertices; 97 int geometryShaderInvocations; 98 99 // Tessellation Shader 100 int tessControlShaderVertices; 101 GLenum tessGenMode; 102 GLenum tessGenSpacing; 103 GLenum tessGenVertexOrder; 104 GLenum tessGenPointMode; 105 106 // ANGLE_shader_pixel_local_storage: A mapping from binding index to the PLS uniform format at 107 // that index. 108 std::vector<ShPixelLocalStorageFormat> pixelLocalStorageFormats; 109 }; 110 111 using SharedCompiledShaderState = std::shared_ptr<CompiledShaderState>; 112 } // namespace gl 113 114 #endif // COMMON_COMPILEDSHADERSTATE_H_ 115