Home | History | Annotate | Download | only in functional
      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:
     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 
     61 private:
     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 
     83 struct VariableSearchFilter
     84 {
     85 								VariableSearchFilter	(glu::ShaderType shaderType, glu::Storage storage) : m_shaderType(shaderType), m_storage(storage), m_null(false) { }
     86 
     87 	static VariableSearchFilter	intersection			(const VariableSearchFilter& a, const VariableSearchFilter& b);
     88 
     89 	bool						matchesFilter			(const ProgramInterfaceDefinition::Shader* shader) const	{ return !m_null && (m_shaderType == glu::SHADERTYPE_LAST || shader->getType() == m_shaderType);	}
     90 	bool						matchesFilter			(const glu::VariableDeclaration& variable) const			{ return !m_null && (m_storage == glu::STORAGE_LAST || variable.storage == m_storage);				}
     91 	bool						matchesFilter			(const glu::InterfaceBlock& block) const					{ return !m_null && (m_storage == glu::STORAGE_LAST || block.storage == m_storage);				}
     92 
     93 	glu::ShaderType				getShaderTypeFilter		(void) const												{ return m_shaderType;	}
     94 	glu::Storage				getStorageFilter		(void) const												{ return m_storage;		}
     95 
     96 private:
     97 								VariableSearchFilter	(glu::ShaderType shaderType, glu::Storage storage, bool empty) : m_shaderType(shaderType), m_storage(storage), m_null(empty) { }
     98 
     99 	const glu::ShaderType		m_shaderType;
    100 	const glu::Storage			m_storage;
    101 	const bool					m_null;					// !< Null filter does not match any variable
    102 };
    103 
    104 struct ShaderResourceUsage
    105 {
    106 	int numInputs;
    107 	int numInputVectors;
    108 	int numInputComponents;
    109 	int numOutputs;
    110 	int numOutputVectors;
    111 	int numOutputComponents;
    112 
    113 	int numDefaultBlockUniformComponents;
    114 	int numCombinedUniformComponents;
    115 	int numUniformVectors;
    116 
    117 	int numSamplers;
    118 	int numImages;
    119 
    120 	int numAtomicCounterBuffers;
    121 	int numAtomicCounters;
    122 
    123 	int numUniformBlocks;
    124 	int numShaderStorageBlocks;
    125 };
    126 
    127 struct ProgramResourceUsage
    128 {
    129 	int uniformBufferMaxBinding;
    130 	int uniformBufferMaxSize;
    131 	int numUniformBlocks;
    132 	int numCombinedVertexUniformComponents;
    133 	int numCombinedFragmentUniformComponents;
    134 	int shaderStorageBufferMaxBinding;
    135 	int shaderStorageBufferMaxSize;
    136 	int numShaderStorageBlocks;
    137 	int numVaryingComponents;
    138 	int numVaryingVectors;
    139 	int numCombinedSamplers;
    140 	int atomicCounterBufferMaxBinding;
    141 	int atomicCounterBufferMaxSize;
    142 	int numAtomicCounterBuffers;
    143 	int numAtomicCounters;
    144 	int maxImageBinding;
    145 	int numCombinedImages;
    146 	int numCombinedOutputResources;
    147 	int numXFBInterleavedComponents;
    148 	int numXFBSeparateAttribs;
    149 	int numXFBSeparateComponents;
    150 	int fragmentOutputMaxBinding;
    151 };
    152 
    153 } // ProgramInterfaceDefinition
    154 
    155 enum ResourceNameGenerationFlag
    156 {
    157 	RESOURCE_NAME_GENERATION_FLAG_DEFAULT 						= 0x0,
    158 	RESOURCE_NAME_GENERATION_FLAG_TOP_LEVEL_BUFFER_VARIABLE		= 0x1,
    159 	RESOURCE_NAME_GENERATION_FLAG_TRANSFORM_FEEDBACK_VARIABLE	= 0x2,
    160 
    161 	RESOURCE_NAME_GENERATION_FLAG_MASK							= 0x3
    162 };
    163 
    164 std::vector<std::string>							getProgramInterfaceResourceList				(const ProgramInterfaceDefinition::Program* program, ProgramInterface interface);
    165 std::vector<std::string>							getProgramInterfaceBlockMemberResourceList	(const glu::InterfaceBlock& interfaceBlock);
    166 glu::ProgramSources									generateProgramInterfaceProgramSources		(const ProgramInterfaceDefinition::Program* program);
    167 bool												findProgramVariablePathByPathName			(std::vector<ProgramInterfaceDefinition::VariablePathComponent>& typePath, const ProgramInterfaceDefinition::Program* program, const std::string& pathName, const ProgramInterfaceDefinition::VariableSearchFilter& filter);
    168 void												generateVariableTypeResourceNames			(std::vector<std::string>& resources, const std::string& name, const glu::VarType& type, deUint32 resourceNameGenerationFlags);
    169 ProgramInterfaceDefinition::ShaderResourceUsage		getShaderResourceUsage						(const ProgramInterfaceDefinition::Shader* shader);
    170 ProgramInterfaceDefinition::ProgramResourceUsage	getCombinedProgramResourceUsage				(const ProgramInterfaceDefinition::Program* program);
    171 
    172 } // Functional
    173 } // gles31
    174 } // deqp
    175 
    176 #endif // _ES31FPROGRAMINTERFACEDEFINITIONUTIL_HPP
    177