1 #ifndef _GLUVARTYPE_HPP
2 #define _GLUVARTYPE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES Utilities
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 Shader variable type.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "gluShaderUtil.hpp"
38 /*--------------------------------------------------------------------*//*!
39 * \brief Shader variable type.
41 * Variable type represents data type. No storage qualifiers are supported
42 * since they are associated to a declaration, not to the variable type.
44 * \note Structs are handled using struct pointers since it is often desirable
45 * to maintain unique list of struct declarations.
46 *//*--------------------------------------------------------------------*/
51 VarType (const VarType& other);
53 VarType (DataType basicType, Precision precision); //!< Basic type constructor.
54 VarType (const VarType& elementType, int arraySize); //!< Array type constructor.
55 explicit VarType (const StructType* structPtr); //!< Struct type constructor.
58 bool isBasicType (void) const { return m_type == TYPE_BASIC; }
59 bool isArrayType (void) const { return m_type == TYPE_ARRAY; }
60 bool isStructType (void) const { return m_type == TYPE_STRUCT; }
62 DataType getBasicType (void) const { DE_ASSERT(isBasicType()); return m_data.basic.type; }
63 Precision getPrecision (void) const { DE_ASSERT(isBasicType()); return m_data.basic.precision; }
65 const VarType& getElementType (void) const { DE_ASSERT(isArrayType()); return *m_data.array.elementType; }
66 int getArraySize (void) const { DE_ASSERT(isArrayType()); return m_data.array.size; }
68 const StructType* getStructPtr (void) const { DE_ASSERT(isStructType()); return m_data.structPtr; }
70 int getScalarSize (void) const;
72 VarType& operator= (const VarType& other);
74 bool operator== (const VarType& other) const;
75 bool operator!= (const VarType& other) const;
79 UNSIZED_ARRAY = -1 //!< Array length for unsized arrays.
105 VarType* elementType;
110 const StructType* structPtr;
114 array.elementType = DE_NULL;
120 template <typename T>
121 inline VarType varTypeOf (Precision prec = PRECISION_LAST) { return VarType(dataTypeOf<T>(), prec); }
126 StructMember (const char* name, const VarType& type) : m_name(name), m_type(type) {}
127 StructMember (void) {}
129 const char* getName (void) const { return m_name.c_str(); }
130 const VarType& getType (void) const { return m_type; }
132 bool operator== (const StructMember& other) const;
133 bool operator!= (const StructMember& other) const;
143 typedef std::vector<StructMember>::iterator Iterator;
144 typedef std::vector<StructMember>::const_iterator ConstIterator;
146 StructType (const char* typeName) : m_typeName(typeName) {}
147 ~StructType (void) {}
149 bool hasTypeName (void) const { return !m_typeName.empty(); }
150 const char* getTypeName (void) const { return hasTypeName() ? m_typeName.c_str() : DE_NULL; }
152 void addMember (const char* name, const VarType& type);
154 int getNumMembers (void) const { return (int)m_members.size(); }
155 const StructMember& getMember (int ndx) const { return m_members[ndx]; }
157 inline Iterator begin (void) { return m_members.begin(); }
158 inline ConstIterator begin (void) const { return m_members.begin(); }
159 inline Iterator end (void) { return m_members.end(); }
160 inline ConstIterator end (void) const { return m_members.end(); }
162 bool operator== (const StructType& other) const;
163 bool operator!= (const StructType& other) const;
166 std::string m_typeName;
167 std::vector<StructMember> m_members;
180 const char* getStorageName (Storage storage);
184 INTERPOLATION_SMOOTH = 0,
186 INTERPOLATION_CENTROID,
190 const char* getInterpolationName (Interpolation interpolation);
194 FORMATLAYOUT_RGBA32F = 0,
195 FORMATLAYOUT_RGBA16F,
198 FORMATLAYOUT_RGBA8_SNORM,
200 FORMATLAYOUT_RGBA32I,
201 FORMATLAYOUT_RGBA16I,
205 FORMATLAYOUT_RGBA32UI,
206 FORMATLAYOUT_RGBA16UI,
207 FORMATLAYOUT_RGBA8UI,
213 const char* getFormatLayoutName (FormatLayout layout);
215 enum MemoryAccessQualifier
217 MEMORYACCESSQUALIFIER_COHERENT_BIT = 0x01,
218 MEMORYACCESSQUALIFIER_VOLATILE_BIT = 0x02,
219 MEMORYACCESSQUALIFIER_RESTRICT_BIT = 0x04,
220 MEMORYACCESSQUALIFIER_READONLY_BIT = 0x08,
221 MEMORYACCESSQUALIFIER_WRITEONLY_BIT = 0x10,
223 MEMORYACCESSQUALIFIER_MASK = (MEMORYACCESSQUALIFIER_WRITEONLY_BIT << 1) - 1
226 const char* getMemoryAccessQualifierName (MemoryAccessQualifier qualifier);
230 MATRIXORDER_COLUMN_MAJOR = 0,
231 MATRIXORDER_ROW_MAJOR,
236 const char* getMatrixOrderName (MatrixOrder qualifier);
238 // Declaration utilities.
242 Layout (int location_ = -1, int binding_ = -1, int offset_ = -1, FormatLayout format_ = FORMATLAYOUT_LAST, MatrixOrder matrixOrder_ = MATRIXORDER_LAST);
244 bool operator== (const Layout& other) const;
245 bool operator!= (const Layout& other) const;
251 MatrixOrder matrixOrder;
254 struct VariableDeclaration
256 VariableDeclaration (const VarType& varType_, const std::string& name_, Storage storage_ = STORAGE_LAST, Interpolation interpolation_ = INTERPOLATION_LAST, const Layout& layout_ = Layout(), deUint32 memoryAccessQualifierBits_ = 0);
258 bool operator== (const VariableDeclaration& other) const;
259 bool operator!= (const VariableDeclaration& other) const;
262 Interpolation interpolation;
265 deUint32 memoryAccessQualifierBits;
269 struct InterfaceBlock
271 InterfaceBlock (void);
275 int memoryAccessQualifierFlags;
276 std::string interfaceName;
277 std::string instanceName;
278 std::vector<glu::VariableDeclaration> variables;
279 std::vector<int> dimensions;
282 //! Internals for declare() utilities.
289 Indent (int level_) : level(level_) {}
292 struct DeclareStructTypePtr
294 DeclareStructTypePtr (const StructType* structPtr_, int indentLevel_) : structPtr(structPtr_), indentLevel(indentLevel_) {}
296 const StructType* structPtr;
300 struct DeclareStructType
302 DeclareStructType (const StructType& structType_, int indentLevel_) : structType(structType_), indentLevel(indentLevel_) {}
304 StructType structType;
308 struct DeclareVariable
310 DeclareVariable (const VarType& varType_, const std::string& name_, int indentLevel_) : varType(varType_), name(name_), indentLevel(indentLevel_) {}
317 std::ostream& operator<< (std::ostream& str, const Indent& indent);
318 std::ostream& operator<< (std::ostream& str, const DeclareStructTypePtr& decl);
319 std::ostream& operator<< (std::ostream& str, const DeclareStructType& decl);
320 std::ostream& operator<< (std::ostream& str, const DeclareVariable& decl);
324 inline decl::Indent indent (int indentLevel) { return decl::Indent(indentLevel); }
325 inline decl::DeclareStructTypePtr declare (const StructType* structPtr, int indentLevel = 0) { return decl::DeclareStructTypePtr (structPtr, indentLevel); }
326 inline decl::DeclareStructType declare (const StructType& structType, int indentLevel = 0) { return decl::DeclareStructType (structType, indentLevel); }
327 inline decl::DeclareVariable declare (const VarType& varType, const std::string& name, int indentLevel = 0) { return decl::DeclareVariable (varType, name, indentLevel); }
329 std::ostream& operator<< (std::ostream& str, const Layout& decl);
330 std::ostream& operator<< (std::ostream& str, const VariableDeclaration& decl);
334 #endif // _GLUVARTYPE_HPP