#ifndef _VKQUERYUTIL_HPP #define _VKQUERYUTIL_HPP /*------------------------------------------------------------------------- * Vulkan CTS Framework * -------------------- * * Copyright (c) 2015 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * *//*! * \file * \brief Vulkan query utilities. *//*--------------------------------------------------------------------*/ #include "vkDefs.hpp" #include "tcuMaybe.hpp" #include "deMemory.h" #include namespace vk { // API queries std::vector enumeratePhysicalDevices (const InstanceInterface& vk, VkInstance instance); std::vector getPhysicalDeviceQueueFamilyProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); VkPhysicalDeviceFeatures getPhysicalDeviceFeatures (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); VkPhysicalDeviceProperties getPhysicalDeviceProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); VkPhysicalDeviceMemoryProperties getPhysicalDeviceMemoryProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice); VkFormatProperties getPhysicalDeviceFormatProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format); VkImageFormatProperties getPhysicalDeviceImageFormatProperties (const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags); std::vector getPhysicalDeviceSparseImageFormatProperties(const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling); VkMemoryRequirements getBufferMemoryRequirements (const DeviceInterface& vk, VkDevice device, VkBuffer buffer); VkMemoryRequirements getImageMemoryRequirements (const DeviceInterface& vk, VkDevice device, VkImage image); std::vector enumerateInstanceLayerProperties (const PlatformInterface& vkp); std::vector enumerateInstanceExtensionProperties (const PlatformInterface& vkp, const char* layerName); std::vector enumerateDeviceLayerProperties (const InstanceInterface& vki, VkPhysicalDevice physicalDevice); std::vector enumerateDeviceExtensionProperties (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, const char* layerName); // Feature / extension support bool isShaderStageSupported (const VkPhysicalDeviceFeatures& deviceFeatures, VkShaderStageFlagBits stage); struct RequiredExtension { std::string name; tcu::Maybe minVersion; tcu::Maybe maxVersion; explicit RequiredExtension (const std::string& name_, tcu::Maybe minVersion_ = tcu::nothing(), tcu::Maybe maxVersion_ = tcu::nothing()) : name (name_) , minVersion (minVersion_) , maxVersion (maxVersion_) {} }; struct RequiredLayer { std::string name; tcu::Maybe minSpecVersion; tcu::Maybe maxSpecVersion; tcu::Maybe minImplVersion; tcu::Maybe maxImplVersion; explicit RequiredLayer (const std::string& name_, tcu::Maybe minSpecVersion_ = tcu::nothing(), tcu::Maybe maxSpecVersion_ = tcu::nothing(), tcu::Maybe minImplVersion_ = tcu::nothing(), tcu::Maybe maxImplVersion_ = tcu::nothing()) : name (name_) , minSpecVersion(minSpecVersion_) , maxSpecVersion(maxSpecVersion_) , minImplVersion(minImplVersion_) , maxImplVersion(maxImplVersion_) {} }; bool isCompatible (const VkExtensionProperties& extensionProperties, const RequiredExtension& required); bool isCompatible (const VkLayerProperties& layerProperties, const RequiredLayer& required); template bool isExtensionSupported (ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required); bool isExtensionSupported (const std::vector& extensions, const RequiredExtension& required); template bool isLayerSupported (LayerIterator begin, LayerIterator end, const RequiredLayer& required); bool isLayerSupported (const std::vector& layers, const RequiredLayer& required); // Return variable initialization validation typedef struct { size_t offset; size_t size; } QueryMemberTableEntry; template bool validateInitComplete(Context context, void (Interface::*Function)(Context, Type*)const, const Interface& interface, const QueryMemberTableEntry* queryMemberTableEntry) { const QueryMemberTableEntry *iterator; Type vec[2]; deMemset(&vec[0], 0x00, sizeof(Type)); deMemset(&vec[1], 0xFF, sizeof(Type)); (interface.*Function)(context, &vec[0]); (interface.*Function)(context, &vec[1]); for (iterator = queryMemberTableEntry; iterator->size != 0; iterator++) { if (deMemCmp(((deUint8*)(&vec[0]))+iterator->offset, ((deUint8*)(&vec[1]))+iterator->offset, iterator->size) != 0) return false; } return true; } // Template implementations template bool isExtensionSupported (ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required) { for (ExtensionIterator cur = begin; cur != end; ++cur) { if (isCompatible(*cur, required)) return true; } return false; } template bool isLayerSupported (LayerIterator begin, LayerIterator end, const RequiredLayer& required) { for (LayerIterator cur = begin; cur != end; ++cur) { if (isCompatible(*cur, required)) return true; } return false; } } // vk #endif // _VKQUERYUTIL_HPP