xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fProgramInterfaceDefinitionUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP
2 #define _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES 3.1 Module
5  * -------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *//*!
22  * \file
23  * \brief Program interface utilities
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "tes31TestCase.hpp"
28 #include "gluShaderProgram.hpp"
29 #include "es31fProgramInterfaceDefinition.hpp"
30 
31 namespace deqp
32 {
33 namespace gles31
34 {
35 namespace Functional
36 {
37 namespace ProgramInterfaceDefinition
38 {
39 
40 class Program;
41 
42 class VariablePathComponent
43 {
44 public:
VariablePathComponent(void)45     VariablePathComponent(void) : m_type(TYPE_LAST)
46     {
47     }
VariablePathComponent(const glu::VarType * type)48     VariablePathComponent(const glu::VarType *type) : m_type(TYPE_TYPE)
49     {
50         m_data.type = type;
51     }
VariablePathComponent(const glu::InterfaceBlock * block)52     VariablePathComponent(const glu::InterfaceBlock *block) : m_type(TYPE_INTERFACEBLOCK)
53     {
54         m_data.block = block;
55     }
VariablePathComponent(const glu::VariableDeclaration * decl)56     VariablePathComponent(const glu::VariableDeclaration *decl) : m_type(TYPE_DECLARATION)
57     {
58         m_data.declaration = decl;
59     }
60 
VariablePathComponent(const VariablePathComponent & other)61     VariablePathComponent(const VariablePathComponent &other) : m_data(other.m_data), m_type(other.m_type)
62     {
63     }
operator =(const VariablePathComponent & other)64     VariablePathComponent &operator=(const VariablePathComponent &other)
65     {
66         m_type = other.m_type;
67         m_data = other.m_data;
68         return *this;
69     }
70 
isVariableType(void) const71     bool isVariableType(void) const
72     {
73         return m_type == TYPE_TYPE;
74     }
isInterfaceBlock(void) const75     bool isInterfaceBlock(void) const
76     {
77         return m_type == TYPE_INTERFACEBLOCK;
78     }
isDeclaration(void) const79     bool isDeclaration(void) const
80     {
81         return m_type == TYPE_DECLARATION;
82     }
83 
getVariableType(void) const84     const glu::VarType *getVariableType(void) const
85     {
86         DE_ASSERT(isVariableType());
87         return m_data.type;
88     }
getInterfaceBlock(void) const89     const glu::InterfaceBlock *getInterfaceBlock(void) const
90     {
91         DE_ASSERT(isInterfaceBlock());
92         return m_data.block;
93     }
getDeclaration(void) const94     const glu::VariableDeclaration *getDeclaration(void) const
95     {
96         DE_ASSERT(isDeclaration());
97         return m_data.declaration;
98     }
99 
100 private:
101     enum Type
102     {
103         TYPE_TYPE,
104         TYPE_INTERFACEBLOCK,
105         TYPE_DECLARATION,
106 
107         TYPE_LAST
108     };
109 
110     union Data
111     {
112         const glu::VarType *type;
113         const glu::InterfaceBlock *block;
114         const glu::VariableDeclaration *declaration;
115 
Data(void)116         Data(void) : type(DE_NULL)
117         {
118         }
119     } m_data;
120 
121     Type m_type;
122 };
123 
124 struct VariableSearchFilter
125 {
126 private:
127     VariableSearchFilter(void);
128 
129 public:
130     static VariableSearchFilter createShaderTypeFilter(glu::ShaderType);
131     static VariableSearchFilter createStorageFilter(glu::Storage);
132     static VariableSearchFilter createShaderTypeStorageFilter(glu::ShaderType, glu::Storage);
133 
134     static VariableSearchFilter logicalOr(const VariableSearchFilter &a, const VariableSearchFilter &b);
135     static VariableSearchFilter logicalAnd(const VariableSearchFilter &a, const VariableSearchFilter &b);
136 
137     bool matchesFilter(const ProgramInterfaceDefinition::Shader *shader) const;
138     bool matchesFilter(const glu::VariableDeclaration &variable) const;
139     bool matchesFilter(const glu::InterfaceBlock &block) const;
140 
getShaderTypeBitsdeqp::gles31::Functional::ProgramInterfaceDefinition::VariableSearchFilter141     uint32_t getShaderTypeBits(void) const
142     {
143         return m_shaderTypeBits;
144     }
getStorageBitsdeqp::gles31::Functional::ProgramInterfaceDefinition::VariableSearchFilter145     uint32_t getStorageBits(void) const
146     {
147         return m_storageBits;
148     }
149 
150 private:
151     uint32_t m_shaderTypeBits;
152     uint32_t m_storageBits;
153 };
154 
155 struct ShaderResourceUsage
156 {
157     int numInputs;
158     int numInputVectors;
159     int numInputComponents;
160     int numOutputs;
161     int numOutputVectors;
162     int numOutputComponents;
163     int numPatchInputComponents;
164     int numPatchOutputComponents;
165 
166     int numDefaultBlockUniformComponents;
167     int numCombinedUniformComponents;
168     int numUniformVectors;
169 
170     int numSamplers;
171     int numImages;
172 
173     int numAtomicCounterBuffers;
174     int numAtomicCounters;
175 
176     int numUniformBlocks;
177     int numShaderStorageBlocks;
178 };
179 
180 struct ProgramResourceUsage
181 {
182     int uniformBufferMaxBinding;
183     int uniformBufferMaxSize;
184     int numUniformBlocks;
185     int numCombinedVertexUniformComponents;
186     int numCombinedFragmentUniformComponents;
187     int numCombinedGeometryUniformComponents;
188     int numCombinedTessControlUniformComponents;
189     int numCombinedTessEvalUniformComponents;
190     int shaderStorageBufferMaxBinding;
191     int shaderStorageBufferMaxSize;
192     int numShaderStorageBlocks;
193     int numVaryingComponents;
194     int numVaryingVectors;
195     int numCombinedSamplers;
196     int atomicCounterBufferMaxBinding;
197     int atomicCounterBufferMaxSize;
198     int numAtomicCounterBuffers;
199     int numAtomicCounters;
200     int maxImageBinding;
201     int numCombinedImages;
202     int numCombinedOutputResources;
203     int numXFBInterleavedComponents;
204     int numXFBSeparateAttribs;
205     int numXFBSeparateComponents;
206     int fragmentOutputMaxBinding;
207 };
208 
209 } // namespace ProgramInterfaceDefinition
210 
211 enum ResourceNameGenerationFlag
212 {
213     RESOURCE_NAME_GENERATION_FLAG_DEFAULT                     = 0x0,
214     RESOURCE_NAME_GENERATION_FLAG_TOP_LEVEL_BUFFER_VARIABLE   = 0x1,
215     RESOURCE_NAME_GENERATION_FLAG_TRANSFORM_FEEDBACK_VARIABLE = 0x2,
216 
217     RESOURCE_NAME_GENERATION_FLAG_MASK = 0x3
218 };
219 
220 bool programContainsIOBlocks(const ProgramInterfaceDefinition::Program *program);
221 bool shaderContainsIOBlocks(const ProgramInterfaceDefinition::Shader *shader);
222 glu::ShaderType getProgramTransformFeedbackStage(const ProgramInterfaceDefinition::Program *program);
223 std::vector<std::string> getProgramInterfaceResourceList(const ProgramInterfaceDefinition::Program *program,
224                                                          ProgramInterface interface);
225 std::vector<std::string> getProgramInterfaceBlockMemberResourceList(const glu::InterfaceBlock &interfaceBlock);
226 const char *getUnusedZeroUniformName();
227 glu::ProgramSources generateProgramInterfaceProgramSources(const ProgramInterfaceDefinition::Program *program);
228 bool findProgramVariablePathByPathName(std::vector<ProgramInterfaceDefinition::VariablePathComponent> &typePath,
229                                        const ProgramInterfaceDefinition::Program *program, const std::string &pathName,
230                                        const ProgramInterfaceDefinition::VariableSearchFilter &filter);
231 void generateVariableTypeResourceNames(std::vector<std::string> &resources, const std::string &name,
232                                        const glu::VarType &type, uint32_t resourceNameGenerationFlags);
233 ProgramInterfaceDefinition::ShaderResourceUsage getShaderResourceUsage(
234     const ProgramInterfaceDefinition::Program *program, const ProgramInterfaceDefinition::Shader *shader);
235 ProgramInterfaceDefinition::ProgramResourceUsage getCombinedProgramResourceUsage(
236     const ProgramInterfaceDefinition::Program *program);
237 
238 } // namespace Functional
239 } // namespace gles31
240 } // namespace deqp
241 
242 #endif // _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP
243