1#ifndef _VKQUERYUTIL_HPP 2#define _VKQUERYUTIL_HPP 3/*------------------------------------------------------------------------- 4 * Vulkan CTS Framework 5 * -------------------- 6 * 7 * Copyright (c) 2015 Google Inc. 8 * 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 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 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. 20 * 21 *//*! 22 * \file 23 * \brief Vulkan query utilities. 24 *//*--------------------------------------------------------------------*/ 25 26#include "vkDefs.hpp" 27#include "tcuMaybe.hpp" 28#include "deMemory.h" 29 30#include <vector> 31 32namespace vk 33{ 34 35// API queries 36 37std::vector<VkPhysicalDevice> enumeratePhysicalDevices (const InstanceInterface& vk, VkInstance instance); 38std::vector<VkQueueFamilyProperties> getPhysicalDeviceQueueFamilyProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); 39VkPhysicalDeviceFeatures getPhysicalDeviceFeatures (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); 40VkPhysicalDeviceProperties getPhysicalDeviceProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); 41VkPhysicalDeviceMemoryProperties getPhysicalDeviceMemoryProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); 42VkFormatProperties getPhysicalDeviceFormatProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format); 43VkImageFormatProperties getPhysicalDeviceImageFormatProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags); 44std::vector<VkSparseImageFormatProperties> getPhysicalDeviceSparseImageFormatProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling); 45 46VkMemoryRequirements getBufferMemoryRequirements (const DeviceInterface& vk, VkDevice device, VkBuffer buffer); 47VkMemoryRequirements getImageMemoryRequirements (const DeviceInterface& vk, VkDevice device, VkImage image); 48std::vector<VkSparseImageMemoryRequirements> getImageSparseMemoryRequirements (const DeviceInterface& vk, VkDevice device, VkImage image); 49 50std::vector<VkLayerProperties> enumerateInstanceLayerProperties (const PlatformInterface& vkp); 51std::vector<VkExtensionProperties> enumerateInstanceExtensionProperties (const PlatformInterface& vkp, const char* layerName); 52std::vector<VkLayerProperties> enumerateDeviceLayerProperties (const InstanceInterface& vki, VkPhysicalDevice physicalDevice); 53std::vector<VkExtensionProperties> enumerateDeviceExtensionProperties (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, const char* layerName); 54 55// Feature / extension support 56 57bool isShaderStageSupported (const VkPhysicalDeviceFeatures& deviceFeatures, VkShaderStageFlagBits stage); 58 59struct RequiredExtension 60{ 61 std::string name; 62 tcu::Maybe<deUint32> minVersion; 63 tcu::Maybe<deUint32> maxVersion; 64 65 explicit RequiredExtension (const std::string& name_, 66 tcu::Maybe<deUint32> minVersion_ = tcu::nothing<deUint32>(), 67 tcu::Maybe<deUint32> maxVersion_ = tcu::nothing<deUint32>()) 68 : name (name_) 69 , minVersion (minVersion_) 70 , maxVersion (maxVersion_) 71 {} 72}; 73 74struct RequiredLayer 75{ 76 std::string name; 77 tcu::Maybe<deUint32> minSpecVersion; 78 tcu::Maybe<deUint32> maxSpecVersion; 79 tcu::Maybe<deUint32> minImplVersion; 80 tcu::Maybe<deUint32> maxImplVersion; 81 82 explicit RequiredLayer (const std::string& name_, 83 tcu::Maybe<deUint32> minSpecVersion_ = tcu::nothing<deUint32>(), 84 tcu::Maybe<deUint32> maxSpecVersion_ = tcu::nothing<deUint32>(), 85 tcu::Maybe<deUint32> minImplVersion_ = tcu::nothing<deUint32>(), 86 tcu::Maybe<deUint32> maxImplVersion_ = tcu::nothing<deUint32>()) 87 : name (name_) 88 , minSpecVersion(minSpecVersion_) 89 , maxSpecVersion(maxSpecVersion_) 90 , minImplVersion(minImplVersion_) 91 , maxImplVersion(maxImplVersion_) 92 {} 93}; 94 95bool isCompatible (const VkExtensionProperties& extensionProperties, const RequiredExtension& required); 96bool isCompatible (const VkLayerProperties& layerProperties, const RequiredLayer& required); 97 98template<typename ExtensionIterator> 99bool isExtensionSupported (ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required); 100bool isExtensionSupported (const std::vector<VkExtensionProperties>& extensions, const RequiredExtension& required); 101 102template<typename LayerIterator> 103bool isLayerSupported (LayerIterator begin, LayerIterator end, const RequiredLayer& required); 104bool isLayerSupported (const std::vector<VkLayerProperties>& layers, const RequiredLayer& required); 105 106namespace ValidateQueryBits 107{ 108 109typedef struct 110{ 111 size_t offset; 112 size_t size; 113} QueryMemberTableEntry; 114 115template <typename Context, typename Interface, typename Type> 116//!< Return variable initialization validation 117bool validateInitComplete(Context context, void (Interface::*Function)(Context, Type*)const, const Interface& interface, const QueryMemberTableEntry* queryMemberTableEntry) 118{ 119 const QueryMemberTableEntry *iterator; 120 Type vec[2]; 121 deMemset(&vec[0], 0x00, sizeof(Type)); 122 deMemset(&vec[1], 0xFF, sizeof(Type)); 123 124 (interface.*Function)(context, &vec[0]); 125 (interface.*Function)(context, &vec[1]); 126 127 for (iterator = queryMemberTableEntry; iterator->size != 0; iterator++) 128 { 129 if (deMemCmp(((deUint8*)(&vec[0]))+iterator->offset, ((deUint8*)(&vec[1]))+iterator->offset, iterator->size) != 0) 130 return false; 131 } 132 133 return true; 134} 135 136template<typename IterT> 137//! Overwrite a range of objects with an 8-bit pattern. 138inline void fillBits (IterT beg, const IterT end, const deUint8 pattern = 0xdeu) 139{ 140 for (; beg < end; ++beg) 141 deMemset(&(*beg), static_cast<int>(pattern), sizeof(*beg)); 142} 143 144template<typename IterT> 145//! Verify that each byte of a range of objects is equal to an 8-bit pattern. 146bool checkBits (IterT beg, const IterT end, const deUint8 pattern = 0xdeu) 147{ 148 for (; beg < end; ++beg) 149 { 150 const deUint8* elementBytes = reinterpret_cast<const deUint8*>(&(*beg)); 151 for (std::size_t i = 0u; i < sizeof(*beg); ++i) 152 { 153 if (elementBytes[i] != pattern) 154 return false; 155 } 156 } 157 return true; 158} 159 160} // ValidateQueryBits 161 162// Template implementations 163 164template<typename ExtensionIterator> 165bool isExtensionSupported (ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required) 166{ 167 for (ExtensionIterator cur = begin; cur != end; ++cur) 168 { 169 if (isCompatible(*cur, required)) 170 return true; 171 } 172 return false; 173} 174 175template<typename LayerIterator> 176bool isLayerSupported (LayerIterator begin, LayerIterator end, const RequiredLayer& required) 177{ 178 for (LayerIterator cur = begin; cur != end; ++cur) 179 { 180 if (isCompatible(*cur, required)) 181 return true; 182 } 183 return false; 184} 185 186} // vk 187 188#endif // _VKQUERYUTIL_HPP 189