1 #ifndef _VKTUNIFORMBLOCKCASE_HPP
2 #define _VKTUNIFORMBLOCKCASE_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 The Khronos Group Inc.
8 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 * \brief Uniform block tests.
25 *//*--------------------------------------------------------------------*/
27 #include "deSharedPtr.hpp"
28 #include "vktTestCase.hpp"
29 #include "tcuDefs.hpp"
30 #include "gluShaderUtil.hpp"
39 // Uniform block details.
43 PRECISION_LOW = (1<<0),
44 PRECISION_MEDIUM = (1<<1),
45 PRECISION_HIGH = (1<<2),
46 PRECISION_MASK = PRECISION_LOW|PRECISION_MEDIUM|PRECISION_HIGH,
48 LAYOUT_SHARED = (1<<3),
49 LAYOUT_PACKED = (1<<4),
50 LAYOUT_STD140 = (1<<5),
51 LAYOUT_ROW_MAJOR = (1<<6),
52 LAYOUT_COLUMN_MAJOR = (1<<7), //!< \note Lack of both flags means column-major matrix.
53 LAYOUT_OFFSET = (1<<8),
54 LAYOUT_MASK = LAYOUT_SHARED|LAYOUT_PACKED|LAYOUT_STD140|LAYOUT_ROW_MAJOR|LAYOUT_COLUMN_MAJOR|LAYOUT_OFFSET,
56 DECLARE_VERTEX = (1<<9),
57 DECLARE_FRAGMENT = (1<<10),
58 DECLARE_BOTH = DECLARE_VERTEX|DECLARE_FRAGMENT,
60 UNUSED_VERTEX = (1<<11), //!< Uniform or struct member is not read in vertex shader.
61 UNUSED_FRAGMENT = (1<<12), //!< Uniform or struct member is not read in fragment shader.
62 UNUSED_BOTH = UNUSED_VERTEX|UNUSED_FRAGMENT
68 LOAD_MATRIX_COMPONENTS = 1,
77 VarType (const VarType& other);
78 VarType (glu::DataType basicType, deUint32 flags);
79 VarType (const VarType& elementType, int arraySize);
80 explicit VarType (const StructType* structPtr, deUint32 flags = 0u);
83 bool isBasicType (void) const { return m_type == TYPE_BASIC; }
84 bool isArrayType (void) const { return m_type == TYPE_ARRAY; }
85 bool isStructType (void) const { return m_type == TYPE_STRUCT; }
87 deUint32 getFlags (void) const { return m_flags; }
88 glu::DataType getBasicType (void) const { return m_data.basicType; }
90 const VarType& getElementType (void) const { return *m_data.array.elementType; }
91 int getArraySize (void) const { return m_data.array.size; }
93 const StructType& getStruct (void) const { return *m_data.structPtr; }
95 VarType& operator= (const VarType& other);
111 glu::DataType basicType;
114 VarType* elementType;
117 const StructType* structPtr;
121 array.elementType = DE_NULL;
130 StructMember (const std::string& name, const VarType& type, deUint32 flags)
131 : m_name(name), m_type(type), m_flags(flags)
137 const std::string& getName (void) const { return m_name; }
138 const VarType& getType (void) const { return m_type; }
139 deUint32 getFlags (void) const { return m_flags; }
150 typedef std::vector<StructMember>::iterator Iterator;
151 typedef std::vector<StructMember>::const_iterator ConstIterator;
153 StructType (const std::string& typeName) : m_typeName(typeName) {}
154 ~StructType (void) {}
156 const std::string& getTypeName (void) const { return m_typeName; }
157 bool hasTypeName (void) const { return !m_typeName.empty(); }
159 inline Iterator begin (void) { return m_members.begin(); }
160 inline ConstIterator begin (void) const { return m_members.begin(); }
161 inline Iterator end (void) { return m_members.end(); }
162 inline ConstIterator end (void) const { return m_members.end(); }
164 void addMember (const std::string& name, const VarType& type, deUint32 flags = 0);
167 std::string m_typeName;
168 std::vector<StructMember> m_members;
174 Uniform (const std::string& name, const VarType& type, deUint32 flags = 0);
176 const std::string& getName (void) const { return m_name; }
177 const VarType& getType (void) const { return m_type; }
178 deUint32 getFlags (void) const { return m_flags; }
189 typedef std::vector<Uniform>::iterator Iterator;
190 typedef std::vector<Uniform>::const_iterator ConstIterator;
192 UniformBlock (const std::string& blockName);
194 const std::string& getBlockName (void) const { return m_blockName; }
195 const std::string& getInstanceName (void) const { return m_instanceName; }
196 bool hasInstanceName (void) const { return !m_instanceName.empty(); }
197 bool isArray (void) const { return m_arraySize > 0; }
198 int getArraySize (void) const { return m_arraySize; }
199 deUint32 getFlags (void) const { return m_flags; }
201 void setInstanceName (const std::string& name) { m_instanceName = name; }
202 void setFlags (deUint32 flags) { m_flags = flags; }
203 void setArraySize (int arraySize) { m_arraySize = arraySize; }
204 void addUniform (const Uniform& uniform) { m_uniforms.push_back(uniform); }
206 inline Iterator begin (void) { return m_uniforms.begin(); }
207 inline ConstIterator begin (void) const { return m_uniforms.begin(); }
208 inline Iterator end (void) { return m_uniforms.end(); }
209 inline ConstIterator end (void) const { return m_uniforms.end(); }
212 std::string m_blockName;
213 std::string m_instanceName;
214 std::vector<Uniform> m_uniforms;
215 int m_arraySize; //!< Array size or 0 if not interface block array.
219 typedef de::SharedPtr<StructType> StructTypeSP;
220 typedef de::SharedPtr<UniformBlock> UniformBlockSP;
222 class ShaderInterface
225 ShaderInterface (void);
226 ~ShaderInterface (void);
228 StructType& allocStruct (const std::string& name);
229 void getNamedStructs (std::vector<const StructType*>& structs) const;
231 UniformBlock& allocBlock (const std::string& name);
233 int getNumUniformBlocks (void) const { return (int)m_uniformBlocks.size(); }
234 const UniformBlock& getUniformBlock (int ndx) const { return *m_uniformBlocks[ndx]; }
237 std::vector<StructTypeSP> m_structs;
238 std::vector<UniformBlockSP> m_uniformBlocks;
241 struct BlockLayoutEntry
243 BlockLayoutEntry (void)
245 , blockDeclarationNdx (-1)
253 std::vector<int> activeUniformIndices;
254 int blockDeclarationNdx;
259 struct UniformLayoutEntry
261 UniformLayoutEntry (void)
262 : type (glu::TYPE_LAST)
287 std::vector<BlockLayoutEntry> blocks;
288 std::vector<UniformLayoutEntry> uniforms;
290 int getUniformLayoutIndex (int blockDeclarationNdx, const std::string& name) const;
291 int getBlockLayoutIndex (int blockDeclarationNdx, int instanceNdx) const;
294 class UniformBlockCase : public vkt::TestCase
299 BUFFERMODE_SINGLE = 0, //!< Single buffer shared between uniform blocks.
300 BUFFERMODE_PER_BLOCK, //!< Per-block buffers
305 UniformBlockCase (tcu::TestContext& testCtx,
306 const std::string& name,
307 const std::string& description,
308 BufferMode bufferMode,
309 MatrixLoadFlags matrixLoadFlag,
310 bool shuffleUniformMembers = false);
311 ~UniformBlockCase (void);
313 virtual void initPrograms (vk::SourceCollections& programCollection) const;
314 virtual TestInstance* createInstance (Context& context) const;
319 BufferMode m_bufferMode;
320 ShaderInterface m_interface;
321 MatrixLoadFlags m_matrixLoadFlag;
322 const bool m_shuffleUniformMembers; //!< Used with explicit offsets to test out of order member offsets
325 std::string m_vertShaderSource;
326 std::string m_fragShaderSource;
328 std::vector<deUint8> m_data; //!< Data.
329 std::map<int, void*> m_blockPointers; //!< Reference block pointers.
330 UniformLayout m_uniformLayout; //!< std140 layout.
336 #endif // _VKTUNIFORMBLOCKCASE_HPP