Home | History | Annotate | Download | only in vulkan
      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 
     32 namespace vk
     33 {
     34 
     35 // API queries
     36 
     37 std::vector<VkPhysicalDevice>				enumeratePhysicalDevices					(const InstanceInterface& vk, VkInstance instance);
     38 std::vector<VkQueueFamilyProperties>		getPhysicalDeviceQueueFamilyProperties		(const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
     39 VkPhysicalDeviceFeatures					getPhysicalDeviceFeatures					(const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
     40 VkPhysicalDeviceProperties					getPhysicalDeviceProperties					(const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
     41 VkPhysicalDeviceMemoryProperties			getPhysicalDeviceMemoryProperties			(const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
     42 VkFormatProperties							getPhysicalDeviceFormatProperties			(const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format);
     43 VkImageFormatProperties						getPhysicalDeviceImageFormatProperties		(const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags);
     44 std::vector<VkSparseImageFormatProperties>	getPhysicalDeviceSparseImageFormatProperties(const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkSampleCountFlagBits samples, VkImageUsageFlags usage, VkImageTiling tiling);
     45 
     46 VkMemoryRequirements						getBufferMemoryRequirements					(const DeviceInterface& vk, VkDevice device, VkBuffer buffer);
     47 VkMemoryRequirements						getImageMemoryRequirements					(const DeviceInterface& vk, VkDevice device, VkImage image);
     48 
     49 std::vector<VkLayerProperties>				enumerateInstanceLayerProperties			(const PlatformInterface& vkp);
     50 std::vector<VkExtensionProperties>			enumerateInstanceExtensionProperties		(const PlatformInterface& vkp, const char* layerName);
     51 std::vector<VkLayerProperties>				enumerateDeviceLayerProperties				(const InstanceInterface& vki, VkPhysicalDevice physicalDevice);
     52 std::vector<VkExtensionProperties>			enumerateDeviceExtensionProperties			(const InstanceInterface& vki, VkPhysicalDevice physicalDevice, const char* layerName);
     53 
     54 // Feature / extension support
     55 
     56 bool										isShaderStageSupported						(const VkPhysicalDeviceFeatures& deviceFeatures, VkShaderStageFlagBits stage);
     57 
     58 struct RequiredExtension
     59 {
     60 	std::string				name;
     61 	tcu::Maybe<deUint32>	minVersion;
     62 	tcu::Maybe<deUint32>	maxVersion;
     63 
     64 	explicit RequiredExtension (const std::string&		name_,
     65 								tcu::Maybe<deUint32>	minVersion_ = tcu::nothing<deUint32>(),
     66 								tcu::Maybe<deUint32>	maxVersion_ = tcu::nothing<deUint32>())
     67 		: name			(name_)
     68 		, minVersion	(minVersion_)
     69 		, maxVersion	(maxVersion_)
     70 	{}
     71 };
     72 
     73 struct RequiredLayer
     74 {
     75 	std::string				name;
     76 	tcu::Maybe<deUint32>	minSpecVersion;
     77 	tcu::Maybe<deUint32>	maxSpecVersion;
     78 	tcu::Maybe<deUint32>	minImplVersion;
     79 	tcu::Maybe<deUint32>	maxImplVersion;
     80 
     81 	explicit RequiredLayer (const std::string&			name_,
     82 							tcu::Maybe<deUint32>		minSpecVersion_		= tcu::nothing<deUint32>(),
     83 							tcu::Maybe<deUint32>		maxSpecVersion_		= tcu::nothing<deUint32>(),
     84 							tcu::Maybe<deUint32>		minImplVersion_		= tcu::nothing<deUint32>(),
     85 							tcu::Maybe<deUint32>		maxImplVersion_		= tcu::nothing<deUint32>())
     86 		: name			(name_)
     87 		, minSpecVersion(minSpecVersion_)
     88 		, maxSpecVersion(maxSpecVersion_)
     89 		, minImplVersion(minImplVersion_)
     90 		, maxImplVersion(maxImplVersion_)
     91 	{}
     92 };
     93 
     94 bool										isCompatible							(const VkExtensionProperties& extensionProperties, const RequiredExtension& required);
     95 bool										isCompatible							(const VkLayerProperties& layerProperties, const RequiredLayer& required);
     96 
     97 template<typename ExtensionIterator>
     98 bool										isExtensionSupported					(ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required);
     99 bool										isExtensionSupported					(const std::vector<VkExtensionProperties>& extensions, const RequiredExtension& required);
    100 
    101 template<typename LayerIterator>
    102 bool										isLayerSupported						(LayerIterator begin, LayerIterator end, const RequiredLayer& required);
    103 bool										isLayerSupported						(const std::vector<VkLayerProperties>& layers, const RequiredLayer& required);
    104 
    105 // Return variable initialization validation
    106 
    107 typedef struct
    108 {
    109 	size_t		offset;
    110 	size_t		size;
    111 } QueryMemberTableEntry;
    112 
    113 template <typename Context, typename Interface, typename Type>
    114 bool validateInitComplete(Context context, void (Interface::*Function)(Context, Type*)const, const Interface& interface, const QueryMemberTableEntry* queryMemberTableEntry)
    115 {
    116 	const QueryMemberTableEntry	*iterator;
    117 	Type vec[2];
    118 	deMemset(&vec[0], 0x00, sizeof(Type));
    119 	deMemset(&vec[1], 0xFF, sizeof(Type));
    120 
    121 	(interface.*Function)(context, &vec[0]);
    122 	(interface.*Function)(context, &vec[1]);
    123 
    124 	for (iterator = queryMemberTableEntry; iterator->size != 0; iterator++)
    125 	{
    126 		if (deMemCmp(((deUint8*)(&vec[0]))+iterator->offset, ((deUint8*)(&vec[1]))+iterator->offset, iterator->size) != 0)
    127 			return false;
    128 	}
    129 
    130 	return true;
    131 }
    132 
    133 // Template implementations
    134 
    135 template<typename ExtensionIterator>
    136 bool isExtensionSupported (ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required)
    137 {
    138 	for (ExtensionIterator cur = begin; cur != end; ++cur)
    139 	{
    140 		if (isCompatible(*cur, required))
    141 			return true;
    142 	}
    143 	return false;
    144 }
    145 
    146 template<typename LayerIterator>
    147 bool isLayerSupported (LayerIterator begin, LayerIterator end, const RequiredLayer& required)
    148 {
    149 	for (LayerIterator cur = begin; cur != end; ++cur)
    150 	{
    151 		if (isCompatible(*cur, required))
    152 			return true;
    153 	}
    154 	return false;
    155 }
    156 
    157 } // vk
    158 
    159 #endif // _VKQUERYUTIL_HPP
    160