1 #ifndef _VKTSPVASMUTILS_HPP
2 #define _VKTSPVASMUTILS_HPP
3 /*-------------------------------------------------------------------------
4 * Vulkan Conformance Tests
5 * ------------------------
7 * Copyright (c) 2017 Google Inc.
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 Utilities for Vulkan SPIR-V assembly tests
24 *//*--------------------------------------------------------------------*/
27 #include "vkMemUtil.hpp"
29 #include "vkTypeUtil.hpp"
30 #include "vktTestCase.hpp"
33 #include "deUniquePtr.hpp"
34 #include "deSharedPtr.hpp"
41 namespace SpirVAssembly
43 /*--------------------------------------------------------------------*//*!
44 * \brief Abstract class for an input/output storage buffer object
45 *//*--------------------------------------------------------------------*/
49 virtual ~BufferInterface (void) {}
51 virtual void getBytes (std::vector<deUint8>& bytes) const = 0;
52 virtual size_t getByteSize (void) const = 0;
55 typedef de::SharedPtr<BufferInterface> BufferSp;
56 typedef de::MovePtr<vk::Allocation> AllocationMp;
57 typedef de::SharedPtr<vk::Allocation> AllocationSp;
62 Resource(const BufferSp& buffer_, vk::VkDescriptorType descriptorType_ = vk::VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
64 , descriptorType(descriptorType_)
68 virtual const BufferSp& getBuffer () const { return buffer; }
69 virtual void getBytes (std::vector<deUint8>& bytes) const { buffer->getBytes(bytes); }
70 virtual size_t getByteSize (void) const { return buffer->getByteSize(); }
72 virtual void setDescriptorType (vk::VkDescriptorType type) { descriptorType = type; }
73 virtual vk::VkDescriptorType getDescriptorType () const { return descriptorType; }
77 vk::VkDescriptorType descriptorType;
80 typedef bool (*VerifyIOFunc) (const std::vector<Resource>& inputs,
81 const std::vector<AllocationSp>& outputAllocations,
82 const std::vector<Resource>& expectedOutputs,
91 bool empty (void) const
93 return valuesBuffer.empty();
96 size_t getValuesCount (void) const
98 return sizesBuffer.size();
101 size_t getValueSize (const size_t valueIndex) const
103 return sizesBuffer[valueIndex];
106 const void* getValuesBuffer (void) const
108 if (valuesBuffer.size() == 0)
111 return static_cast<const void*>(&valuesBuffer[0]);
115 void append (const T value)
117 append(&value, sizeof(value));
120 void append (const void* buf, const size_t byteSize)
122 DE_ASSERT(byteSize > 0);
124 valuesBuffer.resize(valuesBuffer.size() + byteSize);
125 deMemcpy(&valuesBuffer[valuesBuffer.size() - byteSize], buf, byteSize);
127 sizesBuffer.push_back(byteSize);
131 std::vector<deUint8> valuesBuffer;
132 std::vector<size_t> sizesBuffer;
135 enum Extension8BitStorageFeatureBits
137 EXT8BITSTORAGEFEATURES_STORAGE_BUFFER = (1u << 1),
138 EXT8BITSTORAGEFEATURES_UNIFORM_STORAGE_BUFFER = (1u << 2),
139 EXT8BITSTORAGEFEATURES_PUSH_CONSTANT = (1u << 3),
141 typedef deUint32 Extension8BitStorageFeatures;
143 enum Extension16BitStorageFeatureBits
145 EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK = (1u << 1),
146 EXT16BITSTORAGEFEATURES_UNIFORM = (1u << 2),
147 EXT16BITSTORAGEFEATURES_PUSH_CONSTANT = (1u << 3),
148 EXT16BITSTORAGEFEATURES_INPUT_OUTPUT = (1u << 4),
150 typedef deUint32 Extension16BitStorageFeatures;
152 enum ExtensionVariablePointersFeaturesBits
154 EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS_STORAGEBUFFER = (1u << 1),
155 EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS = (1u << 2),
157 typedef deUint32 ExtensionVariablePointersFeatures;
159 struct VulkanFeatures
161 vk::VkPhysicalDeviceFeatures coreFeatures;
162 Extension16BitStorageFeatures ext16BitStorage;
163 ExtensionVariablePointersFeatures extVariablePointers;
164 Extension8BitStorageFeatures ext8BitStorage;
166 VulkanFeatures (void)
167 : coreFeatures (vk::VkPhysicalDeviceFeatures())
168 , ext16BitStorage (0)
169 , extVariablePointers (0)
172 deMemset(&coreFeatures, 0, sizeof(coreFeatures));
176 // Returns true if the given 8bit storage extension features in `toCheck` are all supported.
177 bool is8BitStorageFeaturesSupported (const Context& context,
178 Extension8BitStorageFeatures toCheck);
180 // Returns true if the given 16bit storage extension features in `toCheck` are all supported.
181 bool isCoreFeaturesSupported (const Context& context,
182 const vk::VkPhysicalDeviceFeatures& toCheck,
183 const char** missingFeature);
185 // Returns true if the given 16bit storage extension features in `toCheck` are all supported.
186 bool is16BitStorageFeaturesSupported (const Context& context,
187 Extension16BitStorageFeatures toCheck);
189 // Returns true if the given variable pointers extension features in `toCheck` are all supported.
190 bool isVariablePointersFeaturesSupported (const Context& context,
191 ExtensionVariablePointersFeatures toCheck);
193 deUint32 getMinRequiredVulkanVersion (const vk::SpirvVersion version);
195 std::string getVulkanName (const deUint32 version);
200 #endif // _VKTSPVASMUTILS_HPP