1 #ifndef _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP
2 #define _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES 3.1 Module
5 * -------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief Program interface utilities
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tes31TestCase.hpp"
28 #include "gluShaderProgram.hpp"
29 #include "es31fProgramInterfaceDefinition.hpp"
37 namespace ProgramInterfaceDefinition
42 class VariablePathComponent
45 VariablePathComponent (void) :m_type(TYPE_LAST) { }
46 VariablePathComponent (const glu::VarType* type) :m_type(TYPE_TYPE) { m_data.type = type; }
47 VariablePathComponent (const glu::InterfaceBlock* block) :m_type(TYPE_INTERFACEBLOCK) { m_data.block = block; }
48 VariablePathComponent (const glu::VariableDeclaration* decl) :m_type(TYPE_DECLARATION) { m_data.declaration = decl; }
50 VariablePathComponent (const VariablePathComponent& other) : m_data(other.m_data), m_type(other.m_type) { }
51 VariablePathComponent& operator= (const VariablePathComponent& other) { m_type = other.m_type; m_data = other.m_data; return *this; }
53 bool isVariableType (void) const { return m_type == TYPE_TYPE; }
54 bool isInterfaceBlock (void) const { return m_type == TYPE_INTERFACEBLOCK; }
55 bool isDeclaration (void) const { return m_type == TYPE_DECLARATION; }
57 const glu::VarType* getVariableType (void) const { DE_ASSERT(isVariableType()); return m_data.type; }
58 const glu::InterfaceBlock* getInterfaceBlock (void) const { DE_ASSERT(isInterfaceBlock()); return m_data.block; }
59 const glu::VariableDeclaration* getDeclaration (void) const { DE_ASSERT(isDeclaration()); return m_data.declaration; }
73 const glu::VarType* type;
74 const glu::InterfaceBlock* block;
75 const glu::VariableDeclaration* declaration;
77 Data (void) : type(DE_NULL) { }
83 struct VariableSearchFilter
86 VariableSearchFilter (void);
89 static VariableSearchFilter createShaderTypeFilter (glu::ShaderType);
90 static VariableSearchFilter createStorageFilter (glu::Storage);
91 static VariableSearchFilter createShaderTypeStorageFilter (glu::ShaderType, glu::Storage);
93 static VariableSearchFilter logicalOr (const VariableSearchFilter& a, const VariableSearchFilter& b);
94 static VariableSearchFilter logicalAnd (const VariableSearchFilter& a, const VariableSearchFilter& b);
96 bool matchesFilter (const ProgramInterfaceDefinition::Shader* shader) const;
97 bool matchesFilter (const glu::VariableDeclaration& variable) const;
98 bool matchesFilter (const glu::InterfaceBlock& block) const;
100 deUint32 getShaderTypeBits (void) const { return m_shaderTypeBits; };
101 deUint32 getStorageBits (void) const { return m_storageBits; };
103 deUint32 m_shaderTypeBits;
104 deUint32 m_storageBits;
107 struct ShaderResourceUsage
111 int numInputComponents;
113 int numOutputVectors;
114 int numOutputComponents;
115 int numPatchInputComponents;
116 int numPatchOutputComponents;
118 int numDefaultBlockUniformComponents;
119 int numCombinedUniformComponents;
120 int numUniformVectors;
125 int numAtomicCounterBuffers;
126 int numAtomicCounters;
128 int numUniformBlocks;
129 int numShaderStorageBlocks;
132 struct ProgramResourceUsage
134 int uniformBufferMaxBinding;
135 int uniformBufferMaxSize;
136 int numUniformBlocks;
137 int numCombinedVertexUniformComponents;
138 int numCombinedFragmentUniformComponents;
139 int numCombinedGeometryUniformComponents;
140 int numCombinedTessControlUniformComponents;
141 int numCombinedTessEvalUniformComponents;
142 int shaderStorageBufferMaxBinding;
143 int shaderStorageBufferMaxSize;
144 int numShaderStorageBlocks;
145 int numVaryingComponents;
146 int numVaryingVectors;
147 int numCombinedSamplers;
148 int atomicCounterBufferMaxBinding;
149 int atomicCounterBufferMaxSize;
150 int numAtomicCounterBuffers;
151 int numAtomicCounters;
153 int numCombinedImages;
154 int numCombinedOutputResources;
155 int numXFBInterleavedComponents;
156 int numXFBSeparateAttribs;
157 int numXFBSeparateComponents;
158 int fragmentOutputMaxBinding;
161 } // ProgramInterfaceDefinition
163 enum ResourceNameGenerationFlag
165 RESOURCE_NAME_GENERATION_FLAG_DEFAULT = 0x0,
166 RESOURCE_NAME_GENERATION_FLAG_TOP_LEVEL_BUFFER_VARIABLE = 0x1,
167 RESOURCE_NAME_GENERATION_FLAG_TRANSFORM_FEEDBACK_VARIABLE = 0x2,
169 RESOURCE_NAME_GENERATION_FLAG_MASK = 0x3
172 bool programContainsIOBlocks (const ProgramInterfaceDefinition::Program* program);
173 bool shaderContainsIOBlocks (const ProgramInterfaceDefinition::Shader* shader);
174 glu::ShaderType getProgramTransformFeedbackStage (const ProgramInterfaceDefinition::Program* program);
175 std::vector<std::string> getProgramInterfaceResourceList (const ProgramInterfaceDefinition::Program* program, ProgramInterface interface);
176 std::vector<std::string> getProgramInterfaceBlockMemberResourceList (const glu::InterfaceBlock& interfaceBlock);
177 const char* getDummyZeroUniformName ();
178 glu::ProgramSources generateProgramInterfaceProgramSources (const ProgramInterfaceDefinition::Program* program);
179 bool findProgramVariablePathByPathName (std::vector<ProgramInterfaceDefinition::VariablePathComponent>& typePath, const ProgramInterfaceDefinition::Program* program, const std::string& pathName, const ProgramInterfaceDefinition::VariableSearchFilter& filter);
180 void generateVariableTypeResourceNames (std::vector<std::string>& resources, const std::string& name, const glu::VarType& type, deUint32 resourceNameGenerationFlags);
181 ProgramInterfaceDefinition::ShaderResourceUsage getShaderResourceUsage (const ProgramInterfaceDefinition::Program* program, const ProgramInterfaceDefinition::Shader* shader);
182 ProgramInterfaceDefinition::ProgramResourceUsage getCombinedProgramResourceUsage (const ProgramInterfaceDefinition::Program* program);
188 #endif // _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP