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_MASK = LAYOUT_SHARED|LAYOUT_PACKED|LAYOUT_STD140|LAYOUT_ROW_MAJOR|LAYOUT_COLUMN_MAJOR,
55 DECLARE_VERTEX = (1<<8),
56 DECLARE_FRAGMENT = (1<<9),
57 DECLARE_BOTH = DECLARE_VERTEX|DECLARE_FRAGMENT,
59 UNUSED_VERTEX = (1<<10), //!< Uniform or struct member is not read in vertex shader.
60 UNUSED_FRAGMENT = (1<<11), //!< Uniform or struct member is not read in fragment shader.
61 UNUSED_BOTH = UNUSED_VERTEX|UNUSED_FRAGMENT
70 VarType (const VarType& other);
71 VarType (glu::DataType basicType, deUint32 flags);
72 VarType (const VarType& elementType, int arraySize);
73 explicit VarType (const StructType* structPtr);
76 bool isBasicType (void) const { return m_type == TYPE_BASIC; }
77 bool isArrayType (void) const { return m_type == TYPE_ARRAY; }
78 bool isStructType (void) const { return m_type == TYPE_STRUCT; }
80 deUint32 getFlags (void) const { return m_flags; }
81 glu::DataType getBasicType (void) const { return m_data.basicType; }
83 const VarType& getElementType (void) const { return *m_data.array.elementType; }
84 int getArraySize (void) const { return m_data.array.size; }
86 const StructType& getStruct (void) const { return *m_data.structPtr; }
88 VarType& operator= (const VarType& other);
104 glu::DataType basicType;
107 VarType* elementType;
110 const StructType* structPtr;
114 array.elementType = DE_NULL;
123 StructMember (const std::string& name, const VarType& type, deUint32 flags)
124 : m_name(name), m_type(type), m_flags(flags)
130 const std::string& getName (void) const { return m_name; }
131 const VarType& getType (void) const { return m_type; }
132 deUint32 getFlags (void) const { return m_flags; }
143 typedef std::vector<StructMember>::iterator Iterator;
144 typedef std::vector<StructMember>::const_iterator ConstIterator;
146 StructType (const std::string& typeName) : m_typeName(typeName) {}
147 ~StructType (void) {}
149 const std::string& getTypeName (void) const { return m_typeName; }
150 bool hasTypeName (void) const { return !m_typeName.empty(); }
152 inline Iterator begin (void) { return m_members.begin(); }
153 inline ConstIterator begin (void) const { return m_members.begin(); }
154 inline Iterator end (void) { return m_members.end(); }
155 inline ConstIterator end (void) const { return m_members.end(); }
157 void addMember (const std::string& name, const VarType& type, deUint32 flags = 0);
160 std::string m_typeName;
161 std::vector<StructMember> m_members;
167 Uniform (const std::string& name, const VarType& type, deUint32 flags = 0);
169 const std::string& getName (void) const { return m_name; }
170 const VarType& getType (void) const { return m_type; }
171 deUint32 getFlags (void) const { return m_flags; }
182 typedef std::vector<Uniform>::iterator Iterator;
183 typedef std::vector<Uniform>::const_iterator ConstIterator;
185 UniformBlock (const std::string& blockName);
187 const std::string& getBlockName (void) const { return m_blockName; }
188 const std::string& getInstanceName (void) const { return m_instanceName; }
189 bool hasInstanceName (void) const { return !m_instanceName.empty(); }
190 bool isArray (void) const { return m_arraySize > 0; }
191 int getArraySize (void) const { return m_arraySize; }
192 deUint32 getFlags (void) const { return m_flags; }
194 void setInstanceName (const std::string& name) { m_instanceName = name; }
195 void setFlags (deUint32 flags) { m_flags = flags; }
196 void setArraySize (int arraySize) { m_arraySize = arraySize; }
197 void addUniform (const Uniform& uniform) { m_uniforms.push_back(uniform); }
199 inline Iterator begin (void) { return m_uniforms.begin(); }
200 inline ConstIterator begin (void) const { return m_uniforms.begin(); }
201 inline Iterator end (void) { return m_uniforms.end(); }
202 inline ConstIterator end (void) const { return m_uniforms.end(); }
205 std::string m_blockName;
206 std::string m_instanceName;
207 std::vector<Uniform> m_uniforms;
208 int m_arraySize; //!< Array size or 0 if not interface block array.
212 typedef de::SharedPtr<StructType> StructTypeSP;
213 typedef de::SharedPtr<UniformBlock> UniformBlockSP;
215 class ShaderInterface
218 ShaderInterface (void);
219 ~ShaderInterface (void);
221 StructType& allocStruct (const std::string& name);
222 void getNamedStructs (std::vector<const StructType*>& structs) const;
224 UniformBlock& allocBlock (const std::string& name);
226 int getNumUniformBlocks (void) const { return (int)m_uniformBlocks.size(); }
227 const UniformBlock& getUniformBlock (int ndx) const { return *m_uniformBlocks[ndx]; }
230 std::vector<StructTypeSP> m_structs;
231 std::vector<UniformBlockSP> m_uniformBlocks;
234 struct BlockLayoutEntry
236 BlockLayoutEntry (void)
238 , blockDeclarationNdx (-1)
246 std::vector<int> activeUniformIndices;
247 int blockDeclarationNdx;
252 struct UniformLayoutEntry
254 UniformLayoutEntry (void)
255 : type (glu::TYPE_LAST)
280 std::vector<BlockLayoutEntry> blocks;
281 std::vector<UniformLayoutEntry> uniforms;
283 int getUniformLayoutIndex (int blockDeclarationNdx, const std::string& name) const;
284 int getBlockLayoutIndex (int blockDeclarationNdx, int instanceNdx) const;
287 class UniformBlockCase : public vkt::TestCase
292 BUFFERMODE_SINGLE = 0, //!< Single buffer shared between uniform blocks.
293 BUFFERMODE_PER_BLOCK, //!< Per-block buffers
298 UniformBlockCase (tcu::TestContext& testCtx,
299 const std::string& name,
300 const std::string& description,
301 BufferMode bufferMode);
302 ~UniformBlockCase (void);
304 virtual void initPrograms (vk::SourceCollections& programCollection) const;
305 virtual TestInstance* createInstance (Context& context) const;
310 BufferMode m_bufferMode;
311 ShaderInterface m_interface;
314 std::string m_vertShaderSource;
315 std::string m_fragShaderSource;
317 std::vector<deUint8> m_data; //!< Data.
318 std::map<int, void*> m_blockPointers; //!< Reference block pointers.
319 UniformLayout m_uniformLayout; //!< std140 layout.
325 #endif // _VKTUNIFORMBLOCKCASE_HPP