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
31namespace deqp
32{
33namespace gles31
34{
35namespace Functional
36{
37namespace ProgramInterfaceDefinition
38{
39
40class Program;
41
42class VariablePathComponent
43{
44public:
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;	}
49
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; }
52
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;						}
56
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;	}
60
61private:
62	enum Type
63	{
64		TYPE_TYPE,
65		TYPE_INTERFACEBLOCK,
66		TYPE_DECLARATION,
67
68		TYPE_LAST
69	};
70
71	union Data
72	{
73		const glu::VarType*				type;
74		const glu::InterfaceBlock*		block;
75		const glu::VariableDeclaration*	declaration;
76
77		Data (void) : type(DE_NULL) { }
78	} m_data;
79
80	Type m_type;
81};
82
83struct VariableSearchFilter
84{
85private:
86								VariableSearchFilter			(void);
87
88public:
89	static VariableSearchFilter	createShaderTypeFilter			(glu::ShaderType);
90	static VariableSearchFilter	createStorageFilter				(glu::Storage);
91	static VariableSearchFilter	createShaderTypeStorageFilter	(glu::ShaderType, glu::Storage);
92
93	static VariableSearchFilter	logicalOr						(const VariableSearchFilter& a, const VariableSearchFilter& b);
94	static VariableSearchFilter	logicalAnd						(const VariableSearchFilter& a, const VariableSearchFilter& b);
95
96	bool						matchesFilter					(const ProgramInterfaceDefinition::Shader* shader) const;
97	bool						matchesFilter					(const glu::VariableDeclaration& variable) const;
98	bool						matchesFilter					(const glu::InterfaceBlock& block) const;
99
100	deUint32					getShaderTypeBits				(void) const { return m_shaderTypeBits;	};
101	deUint32					getStorageBits					(void) const { return m_storageBits;	};
102private:
103	deUint32					m_shaderTypeBits;
104	deUint32					m_storageBits;
105};
106
107struct ShaderResourceUsage
108{
109	int numInputs;
110	int numInputVectors;
111	int numInputComponents;
112	int numOutputs;
113	int numOutputVectors;
114	int numOutputComponents;
115	int numPatchInputComponents;
116	int numPatchOutputComponents;
117
118	int numDefaultBlockUniformComponents;
119	int numCombinedUniformComponents;
120	int numUniformVectors;
121
122	int numSamplers;
123	int numImages;
124
125	int numAtomicCounterBuffers;
126	int numAtomicCounters;
127
128	int numUniformBlocks;
129	int numShaderStorageBlocks;
130};
131
132struct ProgramResourceUsage
133{
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;
152	int maxImageBinding;
153	int numCombinedImages;
154	int numCombinedOutputResources;
155	int numXFBInterleavedComponents;
156	int numXFBSeparateAttribs;
157	int numXFBSeparateComponents;
158	int fragmentOutputMaxBinding;
159};
160
161} // ProgramInterfaceDefinition
162
163enum ResourceNameGenerationFlag
164{
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,
168
169	RESOURCE_NAME_GENERATION_FLAG_MASK							= 0x3
170};
171
172bool												programContainsIOBlocks						(const ProgramInterfaceDefinition::Program* program);
173bool												shaderContainsIOBlocks						(const ProgramInterfaceDefinition::Shader* shader);
174glu::ShaderType										getProgramTransformFeedbackStage			(const ProgramInterfaceDefinition::Program* program);
175std::vector<std::string>							getProgramInterfaceResourceList				(const ProgramInterfaceDefinition::Program* program, ProgramInterface interface);
176std::vector<std::string>							getProgramInterfaceBlockMemberResourceList	(const glu::InterfaceBlock& interfaceBlock);
177const char*											getDummyZeroUniformName						();
178glu::ProgramSources									generateProgramInterfaceProgramSources		(const ProgramInterfaceDefinition::Program* program);
179bool												findProgramVariablePathByPathName			(std::vector<ProgramInterfaceDefinition::VariablePathComponent>& typePath, const ProgramInterfaceDefinition::Program* program, const std::string& pathName, const ProgramInterfaceDefinition::VariableSearchFilter& filter);
180void												generateVariableTypeResourceNames			(std::vector<std::string>& resources, const std::string& name, const glu::VarType& type, deUint32 resourceNameGenerationFlags);
181ProgramInterfaceDefinition::ShaderResourceUsage		getShaderResourceUsage						(const ProgramInterfaceDefinition::Program* program, const ProgramInterfaceDefinition::Shader* shader);
182ProgramInterfaceDefinition::ProgramResourceUsage	getCombinedProgramResourceUsage				(const ProgramInterfaceDefinition::Program* program);
183
184} // Functional
185} // gles31
186} // deqp
187
188#endif // _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP
189