1 #ifndef _VKTTRANSFORMFEEDBACKFUZZLAYOUTCASE_HPP
2 #define _VKTTRANSFORMFEEDBACKFUZZLAYOUTCASE_HPP
3 /*------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2015 The Khronos Group Inc.
8 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
9 * Copyright (c) 2018 The Khronos Group Inc.
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
25 * \brief Vulkan Transform Feedback Fuzz Layout Tests
26 *//*--------------------------------------------------------------------*/
28 #include "deSharedPtr.hpp"
29 #include "vktTestCase.hpp"
30 #include "tcuDefs.hpp"
31 #include "gluShaderUtil.hpp"
37 namespace TransformFeedback
40 // Interface block details.
44 PRECISION_LOW = (1<<0),
45 PRECISION_MEDIUM = (1<<1),
46 PRECISION_HIGH = (1<<2),
47 PRECISION_MASK = PRECISION_LOW|PRECISION_MEDIUM|PRECISION_HIGH,
49 LAYOUT_XFBBUFFER = (1<<3),
50 LAYOUT_XFBOFFSET = (1<<4),
51 LAYOUT_XFBSTRIDE = (1<<5),
52 LAYOUT_MASK = LAYOUT_XFBBUFFER|LAYOUT_XFBOFFSET|LAYOUT_XFBSTRIDE,
54 FIELD_UNASSIGNED = (1<<6), //!< Interface or struct member is not used in shader.
55 FIELD_MISSING = (1<<7), //!< Interface or struct member will be commented out in shader.
56 FIELD_OPTIONS = FIELD_UNASSIGNED|FIELD_MISSING,
62 LOAD_MATRIX_COMPONENTS = 1,
67 TEST_STAGE_VERTEX = 0,
68 TEST_STAGE_GEOMETRY = 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)
140 const std::string& getName (void) const { return m_name; }
141 const VarType& getType (void) const { return m_type; }
142 deUint32 getFlags (void) const { return m_flags; }
153 typedef std::vector<StructMember>::iterator Iterator;
154 typedef std::vector<StructMember>::const_iterator ConstIterator;
156 StructType (const std::string& typeName) : m_typeName(typeName) {}
157 ~StructType (void) {}
159 const std::string& getTypeName (void) const { return m_typeName; }
160 bool hasTypeName (void) const { return !m_typeName.empty(); }
162 inline Iterator begin (void) { return m_members.begin(); }
163 inline ConstIterator begin (void) const { return m_members.begin(); }
164 inline Iterator end (void) { return m_members.end(); }
165 inline ConstIterator end (void) const { return m_members.end(); }
167 void addMember (const std::string& name, const VarType& type, deUint32 flags = 0);
170 std::string m_typeName;
171 std::vector<StructMember> m_members;
174 class InterfaceBlockMember
177 InterfaceBlockMember (const std::string& name, const VarType& type, deUint32 flags = 0);
179 const std::string& getName (void) const { return m_name; }
180 const VarType& getType (void) const { return m_type; }
181 deUint32 getFlags (void) const { return m_flags; }
192 typedef std::vector<InterfaceBlockMember>::iterator Iterator;
193 typedef std::vector<InterfaceBlockMember>::const_iterator ConstIterator;
195 InterfaceBlock (const std::string& blockName);
197 const std::string& getBlockName (void) const { return m_blockName; }
198 bool hasInstanceName (void) const { return !m_instanceName.empty(); }
199 const std::string& getInstanceName (void) const { return m_instanceName; }
200 bool isArray (void) const { return m_arraySize > 0; }
201 int getArraySize (void) const { return m_arraySize; }
202 int getXfbBuffer (void) const { return m_xfbBuffer; }
203 deUint32 getFlags (void) const { return m_flags; }
205 void setInstanceName (const std::string& name) { m_instanceName = name; }
206 void setFlags (deUint32 flags) { m_flags = flags; }
207 void setFlag (deUint32 flag) { m_flags |= flag; }
208 void setArraySize (int arraySize) { m_arraySize = arraySize; }
209 void setXfbBuffer (int xfbBuffer) { m_xfbBuffer = xfbBuffer; }
210 void addInterfaceMember (const InterfaceBlockMember& interfaceBlockMember) { m_members.push_back(interfaceBlockMember); }
212 inline Iterator begin (void) { return m_members.begin(); }
213 inline ConstIterator begin (void) const { return m_members.begin(); }
214 inline Iterator end (void) { return m_members.end(); }
215 inline ConstIterator end (void) const { return m_members.end(); }
218 std::string m_blockName;
219 std::string m_instanceName;
220 std::vector<InterfaceBlockMember> m_members;
222 int m_arraySize; //!< Array size or 0 if not interface block array.
226 typedef de::SharedPtr<StructType> StructTypeSP;
227 typedef de::SharedPtr<InterfaceBlock> InterfaceBlockSP;
229 class ShaderInterface
232 ShaderInterface (void);
233 ~ShaderInterface (void);
235 StructType& allocStruct (const std::string& name);
236 void getNamedStructs (std::vector<const StructType*>& structs) const;
238 InterfaceBlock& allocBlock (const std::string& name);
240 int getNumInterfaceBlocks (void) const { return (int)m_interfaceBlocks.size(); }
241 const InterfaceBlock& getInterfaceBlock (int ndx) const { return *m_interfaceBlocks[ndx]; }
242 InterfaceBlock& getInterfaceBlockForModify (int ndx) { return *m_interfaceBlocks[ndx]; }
245 std::vector<StructTypeSP> m_structs;
246 std::vector<InterfaceBlockSP> m_interfaceBlocks;
249 struct BlockLayoutEntry
251 BlockLayoutEntry (void)
256 , blockDeclarationNdx (-1)
268 std::vector<int> activeInterfaceIndices;
269 int blockDeclarationNdx;
271 // Location are not used for transform feedback, but they must be not overlap to pass GLSL compiler
276 struct InterfaceLayoutEntry
278 InterfaceLayoutEntry (void)
279 : type (glu::TYPE_LAST)
299 // Location are not used for transform feedback, but they must be not overlap to pass GLSL compiler
304 class InterfaceLayout
307 std::vector<BlockLayoutEntry> blocks;
308 std::vector<InterfaceLayoutEntry> interfaces;
310 int getInterfaceLayoutIndex (int blockDeclarationNdx, const std::string& name) const;
311 int getBlockLayoutIndex (int blockDeclarationNdx, int instanceNdx) const;
314 typedef std::vector<vk::VkDeviceSize> DeviceSizeVector;
316 class InterfaceBlockCase : public vkt::TestCase
319 InterfaceBlockCase (tcu::TestContext& testCtx,
320 const std::string& name,
321 const std::string& description,
322 MatrixLoadFlags matrixLoadFlag,
323 TestStageFlags testStageFlag,
324 bool shuffleInterfaceMembers = false);
325 ~InterfaceBlockCase (void);
327 virtual void delayedInit (void);
328 virtual void initPrograms (vk::SourceCollections& programCollection) const;
329 virtual TestInstance* createInstance (Context& context) const;
332 ShaderInterface m_interface;
333 MatrixLoadFlags m_matrixLoadFlag;
334 TestStageFlags m_testStageFlags;
335 bool m_shuffleInterfaceMembers; //!< Used with explicit offsets to test out of order member offsets
336 deUint32 m_locationsRequired;
339 std::string m_vertShaderSource;
340 std::string m_geomShaderSource;
342 std::vector<deUint8> m_data; //!< Data.
343 DeviceSizeVector m_tfBufBindingSizes;
344 DeviceSizeVector m_tfBufBindingOffsets;
345 std::map<int, void*> m_blockPointers; //!< Reference block pointers.
346 InterfaceLayout m_interfaceLayout; //!< interface layout.
349 } // TransformFeedback
352 #endif // _VKTTRANSFORMFEEDBACKFUZZLAYOUTCASE_HPP