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 void getPackedBytes (std::vector<deUint8>& bytes) const = 0;
53 virtual size_t getByteSize (void) const = 0;
56 typedef de::SharedPtr<BufferInterface> BufferSp;
57 typedef de::MovePtr<vk::Allocation> AllocationMp;
58 typedef de::SharedPtr<vk::Allocation> AllocationSp;
63 Resource(const BufferSp& buffer_, vk::VkDescriptorType descriptorType_ = vk::VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
65 , descriptorType(descriptorType_)
69 virtual const BufferSp& getBuffer () const { return buffer; }
70 virtual void getBytes (std::vector<deUint8>& bytes) const { buffer->getBytes(bytes); }
71 virtual size_t getByteSize (void) const { return buffer->getByteSize(); }
73 virtual void setDescriptorType (vk::VkDescriptorType type) { descriptorType = type; }
74 virtual vk::VkDescriptorType getDescriptorType () const { return descriptorType; }
78 vk::VkDescriptorType descriptorType;
81 typedef bool (*VerifyIOFunc) (const std::vector<Resource>& inputs,
82 const std::vector<AllocationSp>& outputAllocations,
83 const std::vector<Resource>& expectedOutputs,
92 bool empty (void) const
94 return valuesBuffer.empty();
97 size_t getValuesCount (void) const
99 return sizesBuffer.size();
102 size_t getValueSize (const size_t valueIndex) const
104 return sizesBuffer[valueIndex];
107 const void* getValuesBuffer (void) const
109 if (valuesBuffer.size() == 0)
112 return static_cast<const void*>(&valuesBuffer[0]);
116 void append (const T value)
118 append(&value, sizeof(value));
121 void append (const void* buf, const size_t byteSize)
123 DE_ASSERT(byteSize > 0);
125 valuesBuffer.resize(valuesBuffer.size() + byteSize);
126 deMemcpy(&valuesBuffer[valuesBuffer.size() - byteSize], buf, byteSize);
128 sizesBuffer.push_back(byteSize);
132 std::vector<deUint8> valuesBuffer;
133 std::vector<size_t> sizesBuffer;
136 enum Extension8BitStorageFeatureBits
138 EXT8BITSTORAGEFEATURES_STORAGE_BUFFER = (1u << 1),
139 EXT8BITSTORAGEFEATURES_UNIFORM_STORAGE_BUFFER = (1u << 2),
140 EXT8BITSTORAGEFEATURES_PUSH_CONSTANT = (1u << 3),
142 typedef deUint32 Extension8BitStorageFeatures;
144 enum Extension16BitStorageFeatureBits
146 EXT16BITSTORAGEFEATURES_UNIFORM_BUFFER_BLOCK = (1u << 1),
147 EXT16BITSTORAGEFEATURES_UNIFORM = (1u << 2),
148 EXT16BITSTORAGEFEATURES_PUSH_CONSTANT = (1u << 3),
149 EXT16BITSTORAGEFEATURES_INPUT_OUTPUT = (1u << 4),
151 typedef deUint32 Extension16BitStorageFeatures;
153 enum ExtensionVariablePointersFeaturesBits
155 EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS_STORAGEBUFFER = (1u << 1),
156 EXTVARIABLEPOINTERSFEATURES_VARIABLE_POINTERS = (1u << 2),
158 typedef deUint32 ExtensionVariablePointersFeatures;
160 struct VulkanFeatures
162 vk::VkPhysicalDeviceFeatures coreFeatures;
163 Extension16BitStorageFeatures ext16BitStorage;
164 ExtensionVariablePointersFeatures extVariablePointers;
165 Extension8BitStorageFeatures ext8BitStorage;
167 VulkanFeatures (void)
168 : coreFeatures (vk::VkPhysicalDeviceFeatures())
169 , ext16BitStorage (0)
170 , extVariablePointers (0)
173 deMemset(&coreFeatures, 0, sizeof(coreFeatures));
177 // Returns true if the given 8bit storage extension features in `toCheck` are all supported.
178 bool is8BitStorageFeaturesSupported (const Context& context,
179 Extension8BitStorageFeatures toCheck);
181 // Returns true if the given 16bit storage extension features in `toCheck` are all supported.
182 bool isCoreFeaturesSupported (const Context& context,
183 const vk::VkPhysicalDeviceFeatures& toCheck,
184 const char** missingFeature);
186 // Returns true if the given 16bit storage extension features in `toCheck` are all supported.
187 bool is16BitStorageFeaturesSupported (const Context& context,
188 Extension16BitStorageFeatures toCheck);
190 // Returns true if the given variable pointers extension features in `toCheck` are all supported.
191 bool isVariablePointersFeaturesSupported (const Context& context,
192 ExtensionVariablePointersFeatures toCheck);
194 deUint32 getMinRequiredVulkanVersion (const vk::SpirvVersion version);
196 std::string getVulkanName (const deUint32 version);
201 #endif // _VKTSPVASMUTILS_HPP