Add checks to verify all bits set in getXXX functions
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / framework / vulkan / vkQueryUtil.hpp
1 #ifndef _VKQUERYUTIL_HPP
2 #define _VKQUERYUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * Vulkan CTS Framework
5  * --------------------
6  *
7  * Copyright (c) 2015 Google Inc.
8  *
9  * Permission is hereby granted, free of charge, to any person obtaining a
10  * copy of this software and/or associated documentation files (the
11  * "Materials"), to deal in the Materials without restriction, including
12  * without limitation the rights to use, copy, modify, merge, publish,
13  * distribute, sublicense, and/or sell copies of the Materials, and to
14  * permit persons to whom the Materials are furnished to do so, subject to
15  * the following conditions:
16  *
17  * The above copyright notice(s) and this permission notice shall be
18  * included in all copies or substantial portions of the Materials.
19  *
20  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
27  *
28  *//*!
29  * \file
30  * \brief Vulkan query utilities.
31  *//*--------------------------------------------------------------------*/
32
33 #include "vkDefs.hpp"
34 #include "tcuMaybe.hpp"
35 #include "deMemory.h"
36
37 #include <vector>
38
39 namespace vk
40 {
41
42 // API queries
43
44 std::vector<VkPhysicalDevice>                   enumeratePhysicalDevices                                (const InstanceInterface& vk, VkInstance instance);
45 std::vector<VkQueueFamilyProperties>    getPhysicalDeviceQueueFamilyProperties  (const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
46 VkPhysicalDeviceFeatures                                getPhysicalDeviceFeatures                               (const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
47 VkPhysicalDeviceProperties                              getPhysicalDeviceProperties                             (const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
48 VkPhysicalDeviceMemoryProperties                getPhysicalDeviceMemoryProperties               (const InstanceInterface& vk, VkPhysicalDevice physicalDevice);
49 VkFormatProperties                                              getPhysicalDeviceFormatProperties               (const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format);
50 VkImageFormatProperties                                 getPhysicalDeviceImageFormatProperties  (const InstanceInterface& vk, VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags);
51
52 VkMemoryRequirements                                    getBufferMemoryRequirements                             (const DeviceInterface& vk, VkDevice device, VkBuffer buffer);
53 VkMemoryRequirements                                    getImageMemoryRequirements                              (const DeviceInterface& vk, VkDevice device, VkImage image);
54
55 std::vector<VkLayerProperties>                  enumerateInstanceLayerProperties                (const PlatformInterface& vkp);
56 std::vector<VkExtensionProperties>              enumerateInstanceExtensionProperties    (const PlatformInterface& vkp, const char* layerName);
57 std::vector<VkLayerProperties>                  enumerateDeviceLayerProperties                  (const InstanceInterface& vki, VkPhysicalDevice physicalDevice);
58 std::vector<VkExtensionProperties>              enumerateDeviceExtensionProperties              (const InstanceInterface& vki, VkPhysicalDevice physicalDevice, const char* layerName);
59
60 // Feature / extension support
61
62 bool                                                                    isShaderStageSupported                                  (const VkPhysicalDeviceFeatures& deviceFeatures, VkShaderStageFlagBits stage);
63
64 struct RequiredExtension
65 {
66         std::string                             name;
67         tcu::Maybe<deUint32>    minVersion;
68         tcu::Maybe<deUint32>    maxVersion;
69
70         explicit RequiredExtension (const std::string&          name_,
71                                                                 tcu::Maybe<deUint32>    minVersion_ = tcu::nothing<deUint32>(),
72                                                                 tcu::Maybe<deUint32>    maxVersion_ = tcu::nothing<deUint32>())
73                 : name                  (name_)
74                 , minVersion    (minVersion_)
75                 , maxVersion    (maxVersion_)
76         {}
77 };
78
79 bool                                                                    isCompatible                                                    (const VkExtensionProperties& extensionProperties, const RequiredExtension& required);
80
81 template<typename ExtensionIterator>
82 bool                                                                    isExtensionSupported                                    (ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required);
83 bool                                                                    isExtensionSupported                                    (const std::vector<VkExtensionProperties>& extensions, const RequiredExtension& required);
84
85 // Return variable initialization validation
86
87 typedef struct
88 {
89         size_t          offset;
90         size_t          size;
91 } QueryMemberTableEntry;
92 template <typename Context, typename Interface, typename Type>
93 bool validateInitComplete(Context context, void (Interface::*Function)(Context, Type*)const, const Interface& interface, const QueryMemberTableEntry* queryMemberTableEntry)
94 {
95         const QueryMemberTableEntry     *iterator;
96         Type vec[2];
97         deMemset(&vec[0], 0x00, sizeof(Type));
98         deMemset(&vec[1], 0xFF, sizeof(Type));
99
100         (interface.*Function)(context, &vec[0]);
101         (interface.*Function)(context, &vec[1]);
102
103         for (iterator = queryMemberTableEntry; iterator->size != 0; iterator++)
104         {
105                 if (deMemCmp(((deUint8*)(&vec[0]))+iterator->offset, ((deUint8*)(&vec[1]))+iterator->offset, iterator->size) != 0)
106                         return false;
107         }
108
109         return true;
110 }
111
112 // Template implementations
113
114 template<typename ExtensionIterator>
115 bool isExtensionSupported (ExtensionIterator begin, ExtensionIterator end, const RequiredExtension& required)
116 {
117         for (ExtensionIterator cur = begin; cur != end; ++cur)
118         {
119                 if (isCompatible(*cur, required))
120                         return true;
121         }
122         return false;
123 }
124
125 } // vk
126
127 #endif // _VKQUERYUTIL_HPP