1 #ifndef _VKTMEMORYMODELSHAREDLAYOUTCASE_HPP 2 #define _VKTMEMORYMODELSHAREDLAYOUTCASE_HPP 3 /*------------------------------------------------------------------------ 4 * Vulkan Conformance Tests 5 * ------------------------ 6 * 7 * Copyright (c) 2021 The Khronos Group Inc. 8 * Copyright (c) 2021 Google LLC. 9 * 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 13 * 14 * http://www.apache.org/licenses/LICENSE-2.0 15 * 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. 21 * 22 *//*! 23 * \file 24 * \brief Shared memory layout tests. 25 *//*--------------------------------------------------------------------*/ 26 27 #include "vktTestCase.hpp" 28 #include "tcuDefs.hpp" 29 #include "gluShaderUtil.hpp" 30 #include "gluVarType.hpp" 31 32 #include "deRandom.hpp" 33 #include "deSharedPtr.hpp" 34 35 #include <vector> 36 37 namespace vkt 38 { 39 namespace MemoryModel 40 { 41 typedef de::SharedPtr<glu::StructType> NamedStructSP; 42 43 struct SharedStructVarEntry 44 { SharedStructVarEntryvkt::MemoryModel::SharedStructVarEntry45 SharedStructVarEntry(glu::DataType type_, int arraySize_) 46 : type(type_), arraySize(arraySize_) {} 47 48 glu::DataType type; 49 int arraySize; 50 }; 51 52 struct SharedStructVar 53 { 54 std::string name; 55 glu::VarType type; 56 int arraySize; 57 int topLevelArraySize; 58 std::vector<SharedStructVarEntry> entries; 59 60 // Contains all the values assigned to the variable. 61 std::vector<std::string> entryValues; 62 }; 63 64 class SharedStruct 65 { 66 public: 67 typedef std::vector<SharedStructVar>::iterator iterator; 68 typedef std::vector<SharedStructVar>::const_iterator const_iterator; 69 SharedStruct(const std::string name,const std::string instanceName)70 SharedStruct (const std::string name, const std::string instanceName) 71 : m_name(name), m_instanceName(instanceName) {} 72 getName(void) const73 const std::string getName (void) const { return m_name; } getInstanceName(void) const74 const std::string getInstanceName (void) const { return m_instanceName; } 75 addMember(SharedStructVar var)76 void addMember (SharedStructVar var) { m_members.push_back(var); } getNumMembers(void)77 int getNumMembers (void) { return static_cast<int>(m_members.size()); } 78 begin(void)79 inline iterator begin (void) { return m_members.begin(); } begin(void) const80 inline const_iterator begin (void) const { return m_members.begin(); } end(void)81 inline iterator end (void) { return m_members.end(); } end(void) const82 inline const_iterator end (void) const { return m_members.end(); } 83 84 private: 85 // Shared struct name 86 std::string m_name; 87 88 // Shared struct instance name 89 std::string m_instanceName; 90 91 // Contains the members of this struct. 92 std::vector<SharedStructVar> m_members; 93 }; 94 95 class ShaderInterface 96 { 97 public: ShaderInterface(void)98 ShaderInterface (void) {} ~ShaderInterface(void)99 ~ShaderInterface (void) {} 100 101 SharedStruct& allocSharedObject (const std::string& name, const std::string& instanceName); 102 NamedStructSP allocStruct (const std::string& name); 103 getStructs(void)104 std::vector<NamedStructSP>& getStructs (void) { return m_structs; } getNumStructs(void)105 int getNumStructs (void) { return static_cast<int>(m_structs.size()); } 106 getNumSharedObjects(void) const107 int getNumSharedObjects (void) const { return static_cast<int>(m_sharedMemoryObjects.size()); } getSharedObjects(void)108 std::vector<SharedStruct>& getSharedObjects (void) { return m_sharedMemoryObjects; } getSharedObjects(void) const109 const std::vector<SharedStruct>& getSharedObjects (void) const { return m_sharedMemoryObjects; } 110 enable8BitTypes(bool enabled)111 void enable8BitTypes (bool enabled) { m_8BitTypesEnabled = enabled; } enable16BitTypes(bool enabled)112 void enable16BitTypes (bool enabled) { m_16BitTypesEnabled = enabled; } is8BitTypesEnabled(void) const113 bool is8BitTypesEnabled (void) const { return m_8BitTypesEnabled; } is16BitTypesEnabled(void) const114 bool is16BitTypesEnabled (void) const { return m_16BitTypesEnabled; } 115 private: 116 ShaderInterface (const ShaderInterface&); 117 ShaderInterface& operator= (const ShaderInterface&); 118 119 std::vector<NamedStructSP> m_structs; 120 std::vector<SharedStruct> m_sharedMemoryObjects; 121 bool m_8BitTypesEnabled; 122 bool m_16BitTypesEnabled; 123 }; 124 125 class SharedLayoutCaseInstance : public TestInstance 126 { 127 public: SharedLayoutCaseInstance(Context & context)128 SharedLayoutCaseInstance(Context& context) 129 : TestInstance(context) {} ~SharedLayoutCaseInstance(void)130 virtual ~SharedLayoutCaseInstance(void) {} 131 virtual tcu::TestStatus iterate(void); 132 }; 133 134 class SharedLayoutCase : public vkt::TestCase 135 { 136 public: SharedLayoutCase(tcu::TestContext & testCtx,const char * name,const char * description)137 SharedLayoutCase (tcu::TestContext& testCtx, const char* name, const char* description) 138 : TestCase(testCtx, name, description) {} ~SharedLayoutCase(void)139 virtual ~SharedLayoutCase (void) {} 140 virtual void delayedInit (void); 141 virtual void initPrograms (vk::SourceCollections& programCollection) const; 142 virtual TestInstance* createInstance (Context& context) const; 143 virtual void checkSupport (Context& context) const; 144 145 protected: 146 ShaderInterface m_interface; 147 std::string m_computeShaderSrc; 148 149 private: 150 SharedLayoutCase (const SharedLayoutCase&); 151 SharedLayoutCase& operator= (const SharedLayoutCase&); 152 }; 153 154 class RandomSharedLayoutCase : public SharedLayoutCase 155 { 156 public: 157 RandomSharedLayoutCase (tcu::TestContext& testCtx, const char* name, const char* description, 158 deUint32 features, deUint32 seed); 159 160 private: 161 void generateSharedMemoryObject (de::Random& rnd); 162 void generateSharedMemoryVar (de::Random& rnd, SharedStruct& object); 163 glu::VarType generateType (de::Random& rnd, int typeDepth, bool arrayOk); 164 165 deUint32 m_features; 166 int m_maxArrayLength; 167 deUint32 m_seed; 168 169 const int m_maxSharedObjects = 3; 170 const int m_maxSharedObjectMembers = 4; 171 const int m_maxStructMembers = 3; 172 }; 173 174 } // MemoryModel 175 } // vkt 176 177 #endif // _VKTMEMORYMODELSHAREDLAYOUTCASE_HPP 178