Add checks to verify all bits set in getXXX functions
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiFeatureInfo.cpp
1 /*-------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015 Google Inc.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and/or associated documentation files (the
9  * "Materials"), to deal in the Materials without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Materials, and to
12  * permit persons to whom the Materials are furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice(s) and this permission notice shall be
16  * included in all copies or substantial portions of the Materials.
17  *
18  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
25  *
26  *//*!
27  * \file
28  * \brief Api Feature Query tests
29  *//*--------------------------------------------------------------------*/
30
31 #include "vktApiFeatureInfo.hpp"
32
33 #include "vktTestCaseUtil.hpp"
34 #include "vktTestGroupUtil.hpp"
35
36 #include "vkPlatform.hpp"
37 #include "vkStrUtil.hpp"
38 #include "vkRef.hpp"
39 #include "vkDeviceUtil.hpp"
40 #include "vkQueryUtil.hpp"
41 #include "vkImageUtil.hpp"
42
43 #include "tcuTestLog.hpp"
44 #include "tcuFormatUtil.hpp"
45 #include "tcuTextureUtil.hpp"
46
47 #include "deUniquePtr.hpp"
48 #include "deStringUtil.hpp"
49 #include "deSTLUtil.hpp"
50 #include "deMemory.h"
51 #include "deMath.h"
52
53 namespace vkt
54 {
55 namespace api
56 {
57 namespace
58 {
59
60 using namespace vk;
61 using std::vector;
62 using std::string;
63 using tcu::TestLog;
64 using tcu::ScopedLogSection;
65
66 enum
67 {
68         GUARD_SIZE                                                              = 0x20,                 //!< Number of bytes to check
69         GUARD_VALUE                                                             = 0xcd,                 //!< Data pattern
70 };
71
72 static const VkDeviceSize MINIMUM_REQUIRED_IMAGE_RESOURCE_SIZE =        (1LLU<<31);     //!< Minimum value for VkImageFormatProperties::maxResourceSize (2GiB)
73
74 enum LimitFormat
75 {
76         LIMIT_FORMAT_SIGNED_INT,
77         LIMIT_FORMAT_UNSIGNED_INT,
78         LIMIT_FORMAT_FLOAT,
79         LIMIT_FORMAT_DEVICE_SIZE,
80
81         LIMIT_FORMAT_LAST
82 };
83
84 enum LimitType
85 {
86         LIMIT_TYPE_MIN,
87         LIMIT_TYPE_MAX,
88         LIMIT_TYPE_NONE,
89
90         LIMIT_TYPE_LAST
91 };
92
93 #define LIMIT(_X_)              DE_OFFSET_OF(VkPhysicalDeviceLimits, _X_),(char*)(#_X_)
94 #define FEATURE(_X_)    DE_OFFSET_OF(VkPhysicalDeviceFeatures, _X_)
95
96 bool validateFeatureLimits(VkPhysicalDeviceProperties* properties, VkPhysicalDeviceFeatures* features, TestLog& log)
97 {
98         bool                                    limitsOk        = true;
99         VkPhysicalDeviceLimits* limits          = &properties->limits;
100         struct FeatureLimitTable
101         {
102                 deUint32                offset;
103                 char*                   name;
104                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
105                 deInt32                 intVal;                         //!< Format is SIGNED_INT
106                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
107                 float                   floatVal;                       //!< Format is FLOAT
108                 LimitFormat             format;
109                 LimitType               type;
110                 deInt32                 unsuppTableNdx;
111         } featureLimitTable[] =   //!< From gitlab.khronos.org/vulkan/vulkan.git:doc/specs/vulkan/chapters/features.txt@63b23f3bb3ecd211cd6e448e2001ce1088dacd35
112         {
113                 { LIMIT(maxImageDimension1D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
114                 { LIMIT(maxImageDimension2D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
115                 { LIMIT(maxImageDimension3D),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
116                 { LIMIT(maxImageDimensionCube),                                                         4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
117                 { LIMIT(maxImageArrayLayers),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
118                 { LIMIT(maxTexelBufferElements),                                                        65536, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
119                 { LIMIT(maxUniformBufferRange),                                                         16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
120                 { LIMIT(maxStorageBufferRange),                                                         0, 0, 0, 0, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
121                 { LIMIT(maxPushConstantsSize),                                                          128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
122                 { LIMIT(maxMemoryAllocationCount),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
123                 { LIMIT(maxSamplerAllocationCount),                                                     0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE , -1 },
124                 { LIMIT(bufferImageGranularity),                                                        0, 0, 131072, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
125                 { LIMIT(sparseAddressSpaceSize),                                                        0, 0, 2UL*1024*1024*1024, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
126                 { LIMIT(maxBoundDescriptorSets),                                                        4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
127                 { LIMIT(maxPerStageDescriptorSamplers),                                         16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
128                 { LIMIT(maxPerStageDescriptorUniformBuffers),                           12, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
129                 { LIMIT(maxPerStageDescriptorStorageBuffers),                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
130                 { LIMIT(maxPerStageDescriptorSampledImages),                            16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
131                 { LIMIT(maxPerStageDescriptorStorageImages),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
132                 { LIMIT(maxPerStageDescriptorInputAttachments),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
133                 { LIMIT(maxPerStageResources),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE , -1 },
134                 { LIMIT(maxDescriptorSetSamplers),                                                      96, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
135                 { LIMIT(maxDescriptorSetUniformBuffers),                                        72, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
136                 { LIMIT(maxDescriptorSetUniformBuffersDynamic),                         8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
137                 { LIMIT(maxDescriptorSetStorageBuffers),                                        24, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
138                 { LIMIT(maxDescriptorSetStorageBuffersDynamic),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
139                 { LIMIT(maxDescriptorSetSampledImages),                                         96, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
140                 { LIMIT(maxDescriptorSetStorageImages),                                         24, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
141                 { LIMIT(maxDescriptorSetInputAttachments),                                      0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE  , -1 },
142                 { LIMIT(maxVertexInputAttributes),                                                      16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
143                 { LIMIT(maxVertexInputBindings),                                                        16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
144                 { LIMIT(maxVertexInputAttributeOffset),                                         2047, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
145                 { LIMIT(maxVertexInputBindingStride),                                           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
146                 { LIMIT(maxVertexOutputComponents),                                                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
147                 { LIMIT(maxTessellationGenerationLevel),                                        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
148                 { LIMIT(maxTessellationPatchSize),                                                      32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
149                 { LIMIT(maxTessellationControlPerVertexInputComponents),        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
150                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
151                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        120, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
152                 { LIMIT(maxTessellationControlTotalOutputComponents),           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
153                 { LIMIT(maxTessellationEvaluationInputComponents),                      64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
154                 { LIMIT(maxTessellationEvaluationOutputComponents),                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
155                 { LIMIT(maxGeometryShaderInvocations),                                          32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
156                 { LIMIT(maxGeometryInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
157                 { LIMIT(maxGeometryOutputComponents),                                           64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
158                 { LIMIT(maxGeometryOutputVertices),                                                     256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
159                 { LIMIT(maxGeometryTotalOutputComponents),                                      1024, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
160                 { LIMIT(maxFragmentInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
161                 { LIMIT(maxFragmentOutputAttachments),                                          4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
162                 { LIMIT(maxFragmentDualSrcAttachments),                                         1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
163                 { LIMIT(maxFragmentCombinedOutputResources),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
164                 { LIMIT(maxComputeSharedMemorySize),                                            16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
165                 { LIMIT(maxComputeWorkGroupCount[0]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
166                 { LIMIT(maxComputeWorkGroupCount[1]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
167                 { LIMIT(maxComputeWorkGroupCount[2]),                                           65535,  0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
168                 { LIMIT(maxComputeWorkGroupInvocations),                                        128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
169                 { LIMIT(maxComputeWorkGroupSize[0]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
170                 { LIMIT(maxComputeWorkGroupSize[1]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
171                 { LIMIT(maxComputeWorkGroupSize[2]),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
172                 { LIMIT(subPixelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
173                 { LIMIT(subTexelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
174                 { LIMIT(mipmapPrecisionBits),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
175                 { LIMIT(maxDrawIndexedIndexValue),                                                      (deUint32)~0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
176                 { LIMIT(maxDrawIndirectCount),                                                          65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
177                 { LIMIT(maxSamplerLodBias),                                                                     0, 0, 0, 2.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
178                 { LIMIT(maxSamplerAnisotropy),                                                          0, 0, 0, 16.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
179                 { LIMIT(maxViewports),                                                                          16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
180                 { LIMIT(maxViewportDimensions[0]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
181                 { LIMIT(maxViewportDimensions[1]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
182                 { LIMIT(viewportBoundsRange[0]),                                                        0, 0, 0, -8192.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
183                 { LIMIT(viewportBoundsRange[1]),                                                        0, 0, 0, 8191.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
184                 { LIMIT(viewportSubPixelBits),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
185                 { LIMIT(minMemoryMapAlignment),                                                         64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
186                 { LIMIT(minTexelBufferOffsetAlignment),                                         256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MAX, -1 },
187                 { LIMIT(minUniformBufferOffsetAlignment),                                       256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MAX, -1 },
188                 { LIMIT(minStorageBufferOffsetAlignment),                                       256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MAX, -1 },
189                 { LIMIT(minTexelOffset),                                                                        0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
190                 { LIMIT(maxTexelOffset),                                                                        7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
191                 { LIMIT(minTexelGatherOffset),                                                          0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
192                 { LIMIT(maxTexelGatherOffset),                                                          7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
193                 { LIMIT(minInterpolationOffset),                                                        0, 0, 0, -0.5f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
194                 { LIMIT(maxInterpolationOffset),                                                        0, 0, 0, 0.5f - (1.0f/deFloatPow(2.0f, (float)limits->subPixelInterpolationOffsetBits)), LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
195                 { LIMIT(subPixelInterpolationOffsetBits),                                       4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
196                 { LIMIT(maxFramebufferWidth),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
197                 { LIMIT(maxFramebufferHeight),                                                          4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
198                 { LIMIT(maxFramebufferLayers),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
199                 { LIMIT(framebufferColorSampleCounts),                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
200                 { LIMIT(framebufferDepthSampleCounts),                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
201                 { LIMIT(framebufferStencilSampleCounts),                                        0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
202                 { LIMIT(framebufferNoAttachmentsSampleCounts),                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
203                 { LIMIT(maxColorAttachments),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
204                 { LIMIT(sampledImageColorSampleCounts),                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
205                 { LIMIT(sampledImageIntegerSampleCounts),                                       4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
206                 { LIMIT(sampledImageDepthSampleCounts),                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
207                 { LIMIT(sampledImageStencilSampleCounts),                                       4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
208                 { LIMIT(storageImageSampleCounts),                                                      4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
209                 { LIMIT(maxSampleMaskWords),                                                            1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
210                 { LIMIT(timestampComputeAndGraphics),                                           0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
211                 { LIMIT(timestampPeriod),                                                                       0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
212                 { LIMIT(maxClipDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
213                 { LIMIT(maxCullDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
214                 { LIMIT(maxCombinedClipAndCullDistances),                                       8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
215                 { LIMIT(discreteQueuePriorities),                                                       8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
216                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
217                 { LIMIT(pointSizeRange[1]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
218                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
219                 { LIMIT(pointSizeRange[1]),                                                                     0, 0, 0, 64.0f - limits->pointSizeGranularity , LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
220                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
221                 { LIMIT(lineWidthRange[1]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
222                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
223                 { LIMIT(lineWidthRange[1]),                                                                     0, 0, 0, 8.0f - limits->lineWidthGranularity, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
224                 { LIMIT(pointSizeGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
225                 { LIMIT(lineWidthGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
226                 { LIMIT(strictLines),                                                                           0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_NONE, -1 },
227                 { LIMIT(standardSampleLocations),                                                       0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_NONE, -1 },
228                 { LIMIT(optimalBufferCopyOffsetAlignment),                                      0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_NONE, -1 },
229                 { LIMIT(optimalBufferCopyRowPitchAlignment),                            0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_NONE, -1 },
230                 { LIMIT(nonCoherentAtomSize),                                                           0, 0, 128, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
231         };
232
233         struct UnsupportedFeatureLimitTable
234         {
235                 deUint32                limitOffset;
236                 char*                   name;
237                 deUint32                featureOffset;
238                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
239                 deInt32                 intVal;                         //!< Format is SIGNED_INT
240                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
241                 float                   floatVal;                       //!< Format is FLOAT
242         } unsupportedFeatureTable[] =
243         {
244                 { LIMIT(sparseAddressSpaceSize),                                                        FEATURE(sparseBinding),                                 0, 0, 0, 0.0f },
245                 { LIMIT(maxTessellationGenerationLevel),                                        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
246                 { LIMIT(maxTessellationPatchSize),                                                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
247                 { LIMIT(maxTessellationControlPerVertexInputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
248                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
249                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
250                 { LIMIT(maxTessellationControlTotalOutputComponents),           FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
251                 { LIMIT(maxTessellationEvaluationInputComponents),                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
252                 { LIMIT(maxTessellationEvaluationOutputComponents),                     FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
253                 { LIMIT(maxGeometryShaderInvocations),                                          FEATURE(geometryShader),                                0, 0, 0, 0.0f },
254                 { LIMIT(maxGeometryInputComponents),                                            FEATURE(geometryShader),                                0, 0, 0, 0.0f },
255                 { LIMIT(maxGeometryOutputComponents),                                           FEATURE(geometryShader),                                0, 0, 0, 0.0f },
256                 { LIMIT(maxGeometryOutputVertices),                                                     FEATURE(geometryShader),                                0, 0, 0, 0.0f },
257                 { LIMIT(maxGeometryTotalOutputComponents),                                      FEATURE(geometryShader),                                0, 0, 0, 0.0f },
258                 { LIMIT(maxFragmentDualSrcAttachments),                                         FEATURE(dualSrcBlend),                                  0, 0, 0, 0.0f },
259                 { LIMIT(maxDrawIndexedIndexValue),                                                      FEATURE(fullDrawIndexUint32),                   (1<<24)-1, 0, 0, 0.0f },
260                 { LIMIT(maxDrawIndirectCount),                                                          FEATURE(multiDrawIndirect),                             1, 0, 0, 0.0f },
261                 { LIMIT(maxSamplerAnisotropy),                                                          FEATURE(samplerAnisotropy),                             1, 0, 0, 0.0f },
262                 { LIMIT(maxViewports),                                                                          FEATURE(multiViewport),                                 1, 0, 0, 0.0f },
263                 { LIMIT(minTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
264                 { LIMIT(maxTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
265                 { LIMIT(minInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
266                 { LIMIT(maxInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
267                 { LIMIT(subPixelInterpolationOffsetBits),                                       FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
268                 { LIMIT(storageImageSampleCounts),                                                      FEATURE(shaderStorageImageMultisample), 0, 0, 0, 0.0f },
269                 { LIMIT(maxClipDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
270                 { LIMIT(maxCullDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
271                 { LIMIT(maxCombinedClipAndCullDistances),                                       FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
272                 { LIMIT(pointSizeRange[0]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
273                 { LIMIT(pointSizeRange[1]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
274                 { LIMIT(lineWidthRange[0]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
275                 { LIMIT(lineWidthRange[1]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
276                 { LIMIT(pointSizeGranularity),                                                          FEATURE(largePoints),                                   0, 0, 0, 0.0f },
277                 { LIMIT(lineWidthGranularity),                                                          FEATURE(wideLines),                                             0, 0, 0, 0.0f }
278         };
279
280         log << TestLog::Message << *limits << TestLog::EndMessage;
281
282         //!< First build a map from limit to unsupported table index
283         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
284         {
285                 for (deUint32 unsuppNdx = 0; unsuppNdx < DE_LENGTH_OF_ARRAY(unsupportedFeatureTable); unsuppNdx++)
286                 {
287                         if (unsupportedFeatureTable[unsuppNdx].limitOffset == featureLimitTable[ndx].offset)
288                         {
289                                 featureLimitTable[ndx].unsuppTableNdx = unsuppNdx;
290                                 break;
291                         }
292                 }
293         }
294
295         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
296         {
297                 switch (featureLimitTable[ndx].format)
298                 {
299                         case LIMIT_FORMAT_UNSIGNED_INT:
300                         {
301                                 deUint32 limitToCheck = featureLimitTable[ndx].uintVal;
302                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
303                                 {
304                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
305                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].uintVal;
306                                 }
307
308                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
309                                 {
310
311                                         if (*((deUint32*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
312                                         {
313                                                 log << TestLog::Message << "limit Validation failed " << featureLimitTable[ndx].name
314                                                         << " not valid-limit type MIN - actual is "
315                                                         << *((deUint32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
316                                                 limitsOk = false;
317                                         }
318                                 }
319                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
320                                 {
321                                         if (*((deUint32*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
322                                         {
323                                                 log << TestLog::Message << "limit validation failed,  " << featureLimitTable[ndx].name
324                                                         << " not valid-limit type MAX - actual is "
325                                                         << *((deUint32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
326                                                 limitsOk = false;
327                                         }
328                                 }
329                                 break;
330                         }
331
332                         case LIMIT_FORMAT_FLOAT:
333                         {
334                                 float limitToCheck = featureLimitTable[ndx].floatVal;
335                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
336                                 {
337                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
338                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].floatVal;
339                                 }
340
341                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
342                                 {
343                                         if (*((float*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
344                                         {
345                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
346                                                         << " not valid-limit type MIN - actual is "
347                                                         << *((float*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
348                                                 limitsOk = false;
349                                         }
350                                 }
351                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
352                                 {
353                                         if (*((float*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
354                                         {
355                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
356                                                         << " not valid-limit type MAX actual is "
357                                                         << *((float*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
358                                                 limitsOk = false;
359                                         }
360                                 }
361                                 break;
362                         }
363
364                         case LIMIT_FORMAT_SIGNED_INT:
365                         {
366                                 deInt32 limitToCheck = featureLimitTable[ndx].intVal;
367                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
368                                 {
369                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
370                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].intVal;
371                                 }
372                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
373                                 {
374                                         if (*((deInt32*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
375                                         {
376                                                 log << TestLog::Message <<  "limit validation failed, " << featureLimitTable[ndx].name
377                                                         << " not valid-limit type MIN actual is "
378                                                         << *((deInt32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
379                                                 limitsOk = false;
380                                         }
381                                 }
382                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
383                                 {
384                                         if (*((deInt32*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
385                                         {
386                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
387                                                         << " not valid-limit type MAX actual is "
388                                                         << *((deInt32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
389                                                 limitsOk = false;
390                                         }
391                                 }
392                                 break;
393                         }
394
395                         case LIMIT_FORMAT_DEVICE_SIZE:
396                         {
397                                 deUint64 limitToCheck = featureLimitTable[ndx].deviceSizeVal;
398                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
399                                 {
400                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
401                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].deviceSizeVal;
402                                 }
403
404                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
405                                 {
406                                         if (*((deUint64*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
407                                         {
408                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
409                                                         << " not valid-limit type MIN actual is "
410                                                         << *((deUint64*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
411                                                 limitsOk = false;
412                                         }
413                                 }
414                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
415                                 {
416                                         if (*((deUint64*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
417                                         {
418                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
419                                                         << " not valid-limit type MAX actual is "
420                                                         << *((deUint64*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
421                                                 limitsOk = false;
422                                         }
423                                 }
424                                 break;
425                         }
426
427                         default:
428                                 DE_ASSERT(0);
429                                 limitsOk = false;
430                 }
431         }
432
433         return limitsOk;
434 }
435
436 tcu::TestStatus enumeratePhysicalDevices (Context& context)
437 {
438         TestLog&                                                log             = context.getTestContext().getLog();
439         const vector<VkPhysicalDevice>  devices = enumeratePhysicalDevices(context.getInstanceInterface(), context.getInstance());
440
441         log << TestLog::Integer("NumDevices", "Number of devices", "", QP_KEY_TAG_NONE, deInt64(devices.size()));
442
443         for (size_t ndx = 0; ndx < devices.size(); ndx++)
444                 log << TestLog::Message << ndx << ": " << devices[ndx] << TestLog::EndMessage;
445
446         return tcu::TestStatus::pass("Enumerating devices succeeded");
447 }
448
449 tcu::TestStatus enumerateInstanceLayers (Context& context)
450 {
451         TestLog&                                                log                     = context.getTestContext().getLog();
452         const vector<VkLayerProperties> properties      = enumerateInstanceLayerProperties(context.getPlatformInterface());
453
454         for (size_t ndx = 0; ndx < properties.size(); ndx++)
455                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
456
457         return tcu::TestStatus::pass("Enumerating layers succeeded");
458 }
459
460 tcu::TestStatus enumerateInstanceExtensions (Context& context)
461 {
462         TestLog&        log             = context.getTestContext().getLog();
463
464         {
465                 const ScopedLogSection                          section         (log, "Global", "Global Extensions");
466                 const vector<VkExtensionProperties>     properties      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), DE_NULL);
467
468                 for (size_t ndx = 0; ndx < properties.size(); ndx++)
469                         log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
470         }
471
472         {
473                 const vector<VkLayerProperties> layers  = enumerateInstanceLayerProperties(context.getPlatformInterface());
474
475                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
476                 {
477                         const ScopedLogSection                          section         (log, layer->layerName, string("Layer: ") + layer->layerName);
478                         const vector<VkExtensionProperties>     properties      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), layer->layerName);
479
480                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
481                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
482                 }
483         }
484
485         return tcu::TestStatus::pass("Enumerating extensions succeeded");
486 }
487
488 tcu::TestStatus enumerateDeviceLayers (Context& context)
489 {
490         TestLog&                                                log                     = context.getTestContext().getLog();
491         const vector<VkLayerProperties> properties      = vk::enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
492
493         for (size_t ndx = 0; ndx < properties.size(); ndx++)
494                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
495
496         return tcu::TestStatus::pass("Enumerating layers succeeded");
497 }
498
499 tcu::TestStatus enumerateDeviceExtensions (Context& context)
500 {
501         TestLog&        log             = context.getTestContext().getLog();
502
503         {
504                 const ScopedLogSection                          section         (log, "Global", "Global Extensions");
505                 const vector<VkExtensionProperties>     properties      = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), DE_NULL);
506
507                 for (size_t ndx = 0; ndx < properties.size(); ndx++)
508                         log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
509         }
510
511         {
512                 const vector<VkLayerProperties> layers  = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
513
514                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
515                 {
516                         const ScopedLogSection                          section         (log, layer->layerName, string("Layer: ") + layer->layerName);
517                         const vector<VkExtensionProperties>     properties      = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), layer->layerName);
518
519                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
520                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
521                 }
522         }
523
524         return tcu::TestStatus::pass("Enumerating extensions succeeded");
525 }
526
527 #define VK_SIZE_OF(STRUCT, MEMBER)                                      (sizeof(((STRUCT*)0)->MEMBER))
528 #define OFFSET_TABLE_ENTRY(STRUCT, MEMBER)                      { DE_OFFSET_OF(STRUCT, MEMBER), VK_SIZE_OF(STRUCT, MEMBER) }
529
530 tcu::TestStatus deviceFeatures (Context& context)
531 {
532         TestLog&                                                log                     = context.getTestContext().getLog();
533         VkPhysicalDeviceFeatures*               features;
534         deUint8                                                 buffer[sizeof(VkPhysicalDeviceFeatures) + GUARD_SIZE];
535
536         const QueryMemberTableEntry featureOffsetTable[] =
537         {
538                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, robustBufferAccess),
539                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fullDrawIndexUint32),
540                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, imageCubeArray),
541                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, independentBlend),
542                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, geometryShader),
543                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, tessellationShader),
544                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sampleRateShading),
545                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, dualSrcBlend),
546                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, logicOp),
547                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, multiDrawIndirect),
548                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, drawIndirectFirstInstance),
549                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthClamp),
550                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthBiasClamp),
551                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fillModeNonSolid),
552                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthBounds),
553                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, wideLines),
554                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, largePoints),
555                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, alphaToOne),
556                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, multiViewport),
557                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, samplerAnisotropy),
558                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionETC2),
559                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionASTC_LDR),
560                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionBC),
561                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, occlusionQueryPrecise),
562                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, pipelineStatisticsQuery),
563                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, vertexPipelineStoresAndAtomics),
564                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fragmentStoresAndAtomics),
565                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderTessellationAndGeometryPointSize),
566                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderImageGatherExtended),
567                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageExtendedFormats),
568                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageMultisample),
569                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageReadWithoutFormat),
570                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageWriteWithoutFormat),
571                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderUniformBufferArrayDynamicIndexing),
572                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderSampledImageArrayDynamicIndexing),
573                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageBufferArrayDynamicIndexing),
574                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageArrayDynamicIndexing),
575                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderClipDistance),
576                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderCullDistance),
577                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderFloat64),
578                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderInt64),
579                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderInt16),
580                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderResourceResidency),
581                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderResourceMinLod),
582                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseBinding),
583                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyBuffer),
584                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyImage2D),
585                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyImage3D),
586                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency2Samples),
587                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency4Samples),
588                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency8Samples),
589                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency16Samples),
590                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyAliased),
591                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, variableMultisampleRate),
592                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, inheritedQueries),
593                 { 0, 0 }
594         };
595
596
597         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
598         features = reinterpret_cast<VkPhysicalDeviceFeatures*>(buffer);
599
600         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), features);
601
602         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
603                 << TestLog::Message << *features << TestLog::EndMessage;
604
605         if (!features->robustBufferAccess)
606                 return tcu::TestStatus::fail("robustBufferAccess is not supported");
607
608         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
609         {
610                 if (buffer[ndx + sizeof(VkPhysicalDeviceFeatures)] != GUARD_VALUE)
611                 {
612                         log << TestLog::Message << "deviceFeatures - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
613                         return tcu::TestStatus::fail("deviceFeatures buffer overflow");
614                 }
615         }
616
617         if (!validateInitComplete(context.getPhysicalDevice(), &InstanceInterface::getPhysicalDeviceFeatures, context.getInstanceInterface(), featureOffsetTable))
618         {
619                 log << TestLog::Message << "deviceFeatures - VkPhysicalDeviceFeatures not completely initialized" << TestLog::EndMessage;
620                 return tcu::TestStatus::fail("deviceFeatures incomplete initialization");
621         }
622
623
624         return tcu::TestStatus::pass("Query succeeded");
625 }
626
627 tcu::TestStatus deviceProperties (Context& context)
628 {
629         TestLog&                                                log                     = context.getTestContext().getLog();
630         VkPhysicalDeviceProperties*             props;
631         VkPhysicalDeviceFeatures                features;
632         deUint8                                                 buffer[sizeof(VkPhysicalDeviceProperties) + GUARD_SIZE];
633
634         const QueryMemberTableEntry limitOffsetTable[] =
635         {
636                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxImageDimension1D),
637                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxImageDimension2D),
638                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxImageDimension3D),
639                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxImageDimensionCube),
640                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxImageArrayLayers),
641                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTexelBufferElements),
642                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxUniformBufferRange),
643                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxStorageBufferRange),
644                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPushConstantsSize),
645                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxMemoryAllocationCount),
646                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxSamplerAllocationCount),
647                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, bufferImageGranularity),
648                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, sparseAddressSpaceSize),
649                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxBoundDescriptorSets),
650                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPerStageDescriptorSamplers),
651                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPerStageDescriptorUniformBuffers),
652                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPerStageDescriptorStorageBuffers),
653                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPerStageDescriptorSampledImages),
654                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPerStageDescriptorStorageImages),
655                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPerStageDescriptorInputAttachments),
656                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxPerStageResources),
657                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetSamplers),
658                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetUniformBuffers),
659                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetUniformBuffersDynamic),
660                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetStorageBuffers),
661                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetStorageBuffersDynamic),
662                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetSampledImages),
663                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetStorageImages),
664                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDescriptorSetInputAttachments),
665                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxVertexInputAttributes),
666                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxVertexInputBindings),
667                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxVertexInputAttributeOffset),
668                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxVertexInputBindingStride),
669                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxVertexOutputComponents),
670                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationGenerationLevel),
671                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationPatchSize),
672                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationControlPerVertexInputComponents),
673                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationControlPerVertexOutputComponents),
674                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationControlPerPatchOutputComponents),
675                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationControlTotalOutputComponents),
676                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationEvaluationInputComponents),
677                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTessellationEvaluationOutputComponents),
678                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxGeometryShaderInvocations),
679                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxGeometryInputComponents),
680                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxGeometryOutputComponents),
681                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxGeometryOutputVertices),
682                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxGeometryTotalOutputComponents),
683                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxFragmentInputComponents),
684                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxFragmentOutputAttachments),
685                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxFragmentDualSrcAttachments),
686                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxFragmentCombinedOutputResources),
687                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxComputeSharedMemorySize),
688                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxComputeWorkGroupCount[3]),
689                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxComputeWorkGroupInvocations),
690                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxComputeWorkGroupSize[3]),
691                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, subPixelPrecisionBits),
692                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, subTexelPrecisionBits),
693                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, mipmapPrecisionBits),
694                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDrawIndexedIndexValue),
695                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxDrawIndirectCount),
696                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxSamplerLodBias),
697                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxSamplerAnisotropy),
698                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxViewports),
699                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxViewportDimensions[2]),
700                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, viewportBoundsRange[2]),
701                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, viewportSubPixelBits),
702                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, minMemoryMapAlignment),
703                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, minTexelBufferOffsetAlignment),
704                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, minUniformBufferOffsetAlignment),
705                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, minStorageBufferOffsetAlignment),
706                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, minTexelOffset),
707                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTexelOffset),
708                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, minTexelGatherOffset),
709                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxTexelGatherOffset),
710                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, minInterpolationOffset),
711                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxInterpolationOffset),
712                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, subPixelInterpolationOffsetBits),
713                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxFramebufferWidth),
714                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxFramebufferHeight),
715                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxFramebufferLayers),
716                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, framebufferColorSampleCounts),
717                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, framebufferDepthSampleCounts),
718                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, framebufferStencilSampleCounts),
719                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, framebufferNoAttachmentsSampleCounts),
720                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxColorAttachments),
721                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, sampledImageColorSampleCounts),
722                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, sampledImageIntegerSampleCounts),
723                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, sampledImageDepthSampleCounts),
724                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, sampledImageStencilSampleCounts),
725                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, storageImageSampleCounts),
726                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxSampleMaskWords),
727                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, timestampComputeAndGraphics),
728                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, timestampPeriod),
729                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxClipDistances),
730                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxCullDistances),
731                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, maxCombinedClipAndCullDistances),
732                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, discreteQueuePriorities),
733                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, pointSizeRange[2]),
734                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, lineWidthRange[2]),
735                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, pointSizeGranularity),
736                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, lineWidthGranularity),
737                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, strictLines),
738                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, standardSampleLocations),
739                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, optimalBufferCopyOffsetAlignment),
740                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, optimalBufferCopyRowPitchAlignment),
741                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceLimits, nonCoherentAtomSize),
742                 { 0, 0 }
743         };
744
745         props = reinterpret_cast<VkPhysicalDeviceProperties*>(buffer);
746         deMemset(props, GUARD_VALUE, sizeof(buffer));
747
748         context.getInstanceInterface().getPhysicalDeviceProperties(context.getPhysicalDevice(), props);
749         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &features);
750
751         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
752                 << TestLog::Message << *props << TestLog::EndMessage;
753
754         if (!validateFeatureLimits(props, &features, log))
755                 return tcu::TestStatus::fail("deviceProperties - feature limits failed");
756
757         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
758         {
759                 if (buffer[ndx + sizeof(VkPhysicalDeviceProperties)] != GUARD_VALUE)
760                 {
761                         log << TestLog::Message << "deviceProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
762                         return tcu::TestStatus::fail("deviceProperties buffer overflow");
763                 }
764         }
765
766         if (!validateInitComplete(context.getPhysicalDevice(), &InstanceInterface::getPhysicalDeviceProperties, context.getInstanceInterface(), limitOffsetTable))
767         {
768                 log << TestLog::Message << "deviceProperties - VkPhysicalDeviceProperties not completely initialized" << TestLog::EndMessage;
769                 return tcu::TestStatus::fail("deviceProperties incomplete initialization");
770         }
771
772         return tcu::TestStatus::pass("DeviceProperites query succeeded");
773 }
774
775 tcu::TestStatus deviceQueueFamilyProperties (Context& context)
776 {
777         TestLog&                                                                log                                     = context.getTestContext().getLog();
778         const vector<VkQueueFamilyProperties>   queueProperties         = getPhysicalDeviceQueueFamilyProperties(context.getInstanceInterface(), context.getPhysicalDevice());
779
780         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage;
781
782         for (size_t queueNdx = 0; queueNdx < queueProperties.size(); queueNdx++)
783                 log << TestLog::Message << queueNdx << ": " << queueProperties[queueNdx] << TestLog::EndMessage;
784
785         return tcu::TestStatus::pass("Querying queue properties succeeded");
786 }
787
788 tcu::TestStatus deviceMemoryProperties (Context& context)
789 {
790         TestLog&                                                        log                     = context.getTestContext().getLog();
791         VkPhysicalDeviceMemoryProperties*       memProps;
792         deUint8                                                         buffer[sizeof(VkPhysicalDeviceMemoryProperties) + GUARD_SIZE];
793
794         memProps = reinterpret_cast<VkPhysicalDeviceMemoryProperties*>(buffer);
795         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
796
797         context.getInstanceInterface().getPhysicalDeviceMemoryProperties(context.getPhysicalDevice(), memProps);
798
799         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
800                 << TestLog::Message << *memProps << TestLog::EndMessage;
801
802         for (deInt32 ndx = 0; ndx < GUARD_SIZE; ndx++)
803         {
804                 if (buffer[ndx + sizeof(VkPhysicalDeviceMemoryProperties)] != GUARD_VALUE)
805                 {
806                         log << TestLog::Message << "deviceMemoryProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
807                         return tcu::TestStatus::fail("deviceMemoryProperties buffer overflow");
808                 }
809         }
810
811         return tcu::TestStatus::pass("Querying memory properties succeeded");
812 }
813
814 // \todo [2016-01-22 pyry] Optimize by doing format -> flags mapping instead
815
816 VkFormatFeatureFlags getRequiredOptimalTilingFeatures (VkFormat format)
817 {
818         static const VkFormat s_requiredSampledImageBlitSrcFormats[] =
819         {
820                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
821                 VK_FORMAT_R5G6B5_UNORM_PACK16,
822                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
823                 VK_FORMAT_R8_UNORM,
824                 VK_FORMAT_R8_SNORM,
825                 VK_FORMAT_R8_UINT,
826                 VK_FORMAT_R8_SINT,
827                 VK_FORMAT_R8G8_UNORM,
828                 VK_FORMAT_R8G8_SNORM,
829                 VK_FORMAT_R8G8_UINT,
830                 VK_FORMAT_R8G8_SINT,
831                 VK_FORMAT_R8G8B8A8_UNORM,
832                 VK_FORMAT_R8G8B8A8_SNORM,
833                 VK_FORMAT_R8G8B8A8_UINT,
834                 VK_FORMAT_R8G8B8A8_SINT,
835                 VK_FORMAT_R8G8B8A8_SRGB,
836                 VK_FORMAT_B8G8R8A8_UNORM,
837                 VK_FORMAT_B8G8R8A8_SRGB,
838                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
839                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
840                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
841                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
842                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
843                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
844                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
845                 VK_FORMAT_R16_UINT,
846                 VK_FORMAT_R16_SINT,
847                 VK_FORMAT_R16_SFLOAT,
848                 VK_FORMAT_R16G16_UINT,
849                 VK_FORMAT_R16G16_SINT,
850                 VK_FORMAT_R16G16_SFLOAT,
851                 VK_FORMAT_R16G16B16A16_UINT,
852                 VK_FORMAT_R16G16B16A16_SINT,
853                 VK_FORMAT_R16G16B16A16_SFLOAT,
854                 VK_FORMAT_R32_UINT,
855                 VK_FORMAT_R32_SINT,
856                 VK_FORMAT_R32_SFLOAT,
857                 VK_FORMAT_R32G32_UINT,
858                 VK_FORMAT_R32G32_SINT,
859                 VK_FORMAT_R32G32_SFLOAT,
860                 VK_FORMAT_R32G32B32A32_UINT,
861                 VK_FORMAT_R32G32B32A32_SINT,
862                 VK_FORMAT_R32G32B32A32_SFLOAT,
863                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
864                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
865                 VK_FORMAT_D16_UNORM,
866                 VK_FORMAT_D32_SFLOAT
867         };
868         static const VkFormat s_requiredStorageImageFormats[] =
869         {
870                 VK_FORMAT_R8G8B8A8_UNORM,
871                 VK_FORMAT_R8G8B8A8_SNORM,
872                 VK_FORMAT_R8G8B8A8_UINT,
873                 VK_FORMAT_R8G8B8A8_SINT,
874                 VK_FORMAT_R16G16B16A16_UINT,
875                 VK_FORMAT_R16G16B16A16_SINT,
876                 VK_FORMAT_R16G16B16A16_SFLOAT,
877                 VK_FORMAT_R32_UINT,
878                 VK_FORMAT_R32_SINT,
879                 VK_FORMAT_R32_SFLOAT,
880                 VK_FORMAT_R32G32_UINT,
881                 VK_FORMAT_R32G32_SINT,
882                 VK_FORMAT_R32G32_SFLOAT,
883                 VK_FORMAT_R32G32B32A32_UINT,
884                 VK_FORMAT_R32G32B32A32_SINT,
885                 VK_FORMAT_R32G32B32A32_SFLOAT
886         };
887         static const VkFormat s_requiredStorageImageAtomicFormats[] =
888         {
889                 VK_FORMAT_R32_UINT,
890                 VK_FORMAT_R32_SINT
891         };
892         static const VkFormat s_requiredColorAttachmentBlitDstFormats[] =
893         {
894                 VK_FORMAT_R5G6B5_UNORM_PACK16,
895                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
896                 VK_FORMAT_R8_UNORM,
897                 VK_FORMAT_R8_UINT,
898                 VK_FORMAT_R8_SINT,
899                 VK_FORMAT_R8G8_UNORM,
900                 VK_FORMAT_R8G8_UINT,
901                 VK_FORMAT_R8G8_SINT,
902                 VK_FORMAT_R8G8B8A8_UNORM,
903                 VK_FORMAT_R8G8B8A8_UINT,
904                 VK_FORMAT_R8G8B8A8_SINT,
905                 VK_FORMAT_R8G8B8A8_SRGB,
906                 VK_FORMAT_B8G8R8A8_UNORM,
907                 VK_FORMAT_B8G8R8A8_SRGB,
908                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
909                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
910                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
911                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
912                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
913                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
914                 VK_FORMAT_R16_UINT,
915                 VK_FORMAT_R16_SINT,
916                 VK_FORMAT_R16_SFLOAT,
917                 VK_FORMAT_R16G16_UINT,
918                 VK_FORMAT_R16G16_SINT,
919                 VK_FORMAT_R16G16_SFLOAT,
920                 VK_FORMAT_R16G16B16A16_UINT,
921                 VK_FORMAT_R16G16B16A16_SINT,
922                 VK_FORMAT_R16G16B16A16_SFLOAT,
923                 VK_FORMAT_R32_UINT,
924                 VK_FORMAT_R32_SINT,
925                 VK_FORMAT_R32_SFLOAT,
926                 VK_FORMAT_R32G32_UINT,
927                 VK_FORMAT_R32G32_SINT,
928                 VK_FORMAT_R32G32_SFLOAT,
929                 VK_FORMAT_R32G32B32A32_UINT,
930                 VK_FORMAT_R32G32B32A32_SINT,
931                 VK_FORMAT_R32G32B32A32_SFLOAT
932         };
933         static const VkFormat s_requiredColorAttachmentBlendFormats[] =
934         {
935                 VK_FORMAT_R5G6B5_UNORM_PACK16,
936                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
937                 VK_FORMAT_R8_UNORM,
938                 VK_FORMAT_R8G8_UNORM,
939                 VK_FORMAT_R8G8B8A8_UNORM,
940                 VK_FORMAT_R8G8B8A8_SRGB,
941                 VK_FORMAT_B8G8R8A8_UNORM,
942                 VK_FORMAT_B8G8R8A8_SRGB,
943                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
944                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
945                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
946                 VK_FORMAT_R16_SFLOAT,
947                 VK_FORMAT_R16G16_SFLOAT,
948                 VK_FORMAT_R16G16B16A16_SFLOAT
949         };
950         static const VkFormat s_requiredDepthStencilAttachmentFormats[] =
951         {
952                 VK_FORMAT_D16_UNORM
953         };
954
955         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
956
957         if (de::contains(DE_ARRAY_BEGIN(s_requiredSampledImageBlitSrcFormats), DE_ARRAY_END(s_requiredSampledImageBlitSrcFormats), format))
958                 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT|VK_FORMAT_FEATURE_BLIT_SRC_BIT;
959
960         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageFormats), DE_ARRAY_END(s_requiredStorageImageFormats), format))
961                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
962
963         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageAtomicFormats), DE_ARRAY_END(s_requiredStorageImageAtomicFormats), format))
964                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
965
966         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlitDstFormats), DE_ARRAY_END(s_requiredColorAttachmentBlitDstFormats), format))
967                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT|VK_FORMAT_FEATURE_BLIT_DST_BIT;
968
969         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlendFormats), DE_ARRAY_END(s_requiredColorAttachmentBlendFormats), format))
970                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
971
972         if (de::contains(DE_ARRAY_BEGIN(s_requiredDepthStencilAttachmentFormats), DE_ARRAY_END(s_requiredDepthStencilAttachmentFormats), format))
973                 flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
974
975         return flags;
976 }
977
978 VkFormatFeatureFlags getRequiredBufferFeatures (VkFormat format)
979 {
980         static const VkFormat s_requiredVertexBufferFormats[] =
981         {
982                 VK_FORMAT_R8_UNORM,
983                 VK_FORMAT_R8_SNORM,
984                 VK_FORMAT_R8_UINT,
985                 VK_FORMAT_R8_SINT,
986                 VK_FORMAT_R8G8_UNORM,
987                 VK_FORMAT_R8G8_SNORM,
988                 VK_FORMAT_R8G8_UINT,
989                 VK_FORMAT_R8G8_SINT,
990                 VK_FORMAT_R8G8B8A8_UNORM,
991                 VK_FORMAT_R8G8B8A8_SNORM,
992                 VK_FORMAT_R8G8B8A8_UINT,
993                 VK_FORMAT_R8G8B8A8_SINT,
994                 VK_FORMAT_B8G8R8A8_UNORM,
995                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
996                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
997                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
998                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
999                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1000                 VK_FORMAT_R16_UNORM,
1001                 VK_FORMAT_R16_SNORM,
1002                 VK_FORMAT_R16_UINT,
1003                 VK_FORMAT_R16_SINT,
1004                 VK_FORMAT_R16_SFLOAT,
1005                 VK_FORMAT_R16G16_UNORM,
1006                 VK_FORMAT_R16G16_SNORM,
1007                 VK_FORMAT_R16G16_UINT,
1008                 VK_FORMAT_R16G16_SINT,
1009                 VK_FORMAT_R16G16_SFLOAT,
1010                 VK_FORMAT_R16G16B16A16_UNORM,
1011                 VK_FORMAT_R16G16B16A16_SNORM,
1012                 VK_FORMAT_R16G16B16A16_UINT,
1013                 VK_FORMAT_R16G16B16A16_SINT,
1014                 VK_FORMAT_R16G16B16A16_SFLOAT,
1015                 VK_FORMAT_R32_UINT,
1016                 VK_FORMAT_R32_SINT,
1017                 VK_FORMAT_R32_SFLOAT,
1018                 VK_FORMAT_R32G32_UINT,
1019                 VK_FORMAT_R32G32_SINT,
1020                 VK_FORMAT_R32G32_SFLOAT,
1021                 VK_FORMAT_R32G32B32_UINT,
1022                 VK_FORMAT_R32G32B32_SINT,
1023                 VK_FORMAT_R32G32B32_SFLOAT,
1024                 VK_FORMAT_R32G32B32A32_UINT,
1025                 VK_FORMAT_R32G32B32A32_SINT,
1026                 VK_FORMAT_R32G32B32A32_SFLOAT
1027         };
1028         static const VkFormat s_requiredUniformTexelBufferFormats[] =
1029         {
1030                 VK_FORMAT_R8_UNORM,
1031                 VK_FORMAT_R8_SNORM,
1032                 VK_FORMAT_R8_UINT,
1033                 VK_FORMAT_R8_SINT,
1034                 VK_FORMAT_R8G8_UNORM,
1035                 VK_FORMAT_R8G8_SNORM,
1036                 VK_FORMAT_R8G8_UINT,
1037                 VK_FORMAT_R8G8_SINT,
1038                 VK_FORMAT_R8G8B8A8_UNORM,
1039                 VK_FORMAT_R8G8B8A8_SNORM,
1040                 VK_FORMAT_R8G8B8A8_UINT,
1041                 VK_FORMAT_R8G8B8A8_SINT,
1042                 VK_FORMAT_B8G8R8A8_UNORM,
1043                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1044                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1045                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1046                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1047                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1048                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1049                 VK_FORMAT_R16_UINT,
1050                 VK_FORMAT_R16_SINT,
1051                 VK_FORMAT_R16_SFLOAT,
1052                 VK_FORMAT_R16G16_UINT,
1053                 VK_FORMAT_R16G16_SINT,
1054                 VK_FORMAT_R16G16_SFLOAT,
1055                 VK_FORMAT_R16G16B16A16_UINT,
1056                 VK_FORMAT_R16G16B16A16_SINT,
1057                 VK_FORMAT_R16G16B16A16_SFLOAT,
1058                 VK_FORMAT_R32_UINT,
1059                 VK_FORMAT_R32_SINT,
1060                 VK_FORMAT_R32_SFLOAT,
1061                 VK_FORMAT_R32G32_UINT,
1062                 VK_FORMAT_R32G32_SINT,
1063                 VK_FORMAT_R32G32_SFLOAT,
1064                 VK_FORMAT_R32G32B32A32_UINT,
1065                 VK_FORMAT_R32G32B32A32_SINT,
1066                 VK_FORMAT_R32G32B32A32_SFLOAT,
1067                 VK_FORMAT_B10G11R11_UFLOAT_PACK32
1068         };
1069         static const VkFormat s_requiredStorageTexelBufferFormats[] =
1070         {
1071                 VK_FORMAT_R8G8B8A8_UNORM,
1072                 VK_FORMAT_R8G8B8A8_SNORM,
1073                 VK_FORMAT_R8G8B8A8_UINT,
1074                 VK_FORMAT_R8G8B8A8_SINT,
1075                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1076                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1077                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1078                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1079                 VK_FORMAT_R16G16B16A16_UINT,
1080                 VK_FORMAT_R16G16B16A16_SINT,
1081                 VK_FORMAT_R16G16B16A16_SFLOAT,
1082                 VK_FORMAT_R32_UINT,
1083                 VK_FORMAT_R32_SINT,
1084                 VK_FORMAT_R32_SFLOAT,
1085                 VK_FORMAT_R32G32_UINT,
1086                 VK_FORMAT_R32G32_SINT,
1087                 VK_FORMAT_R32G32_SFLOAT,
1088                 VK_FORMAT_R32G32B32A32_UINT,
1089                 VK_FORMAT_R32G32B32A32_SINT,
1090                 VK_FORMAT_R32G32B32A32_SFLOAT
1091         };
1092         static const VkFormat s_requiredStorageTexelBufferAtomicFormats[] =
1093         {
1094                 VK_FORMAT_R32_UINT,
1095                 VK_FORMAT_R32_SINT
1096         };
1097
1098         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
1099
1100         if (de::contains(DE_ARRAY_BEGIN(s_requiredVertexBufferFormats), DE_ARRAY_END(s_requiredVertexBufferFormats), format))
1101                 flags |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
1102
1103         if (de::contains(DE_ARRAY_BEGIN(s_requiredUniformTexelBufferFormats), DE_ARRAY_END(s_requiredUniformTexelBufferFormats), format))
1104                 flags |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
1105
1106         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferFormats), DE_ARRAY_END(s_requiredStorageTexelBufferFormats), format))
1107                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
1108
1109         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferAtomicFormats), DE_ARRAY_END(s_requiredStorageTexelBufferAtomicFormats), format))
1110                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
1111
1112         return flags;
1113 }
1114
1115 tcu::TestStatus formatProperties (Context& context, VkFormat format)
1116 {
1117         TestLog&                                        log                             = context.getTestContext().getLog();
1118         const VkFormatProperties        properties              = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
1119         bool                                            allOk                   = true;
1120
1121         const struct
1122         {
1123                 VkFormatFeatureFlags VkFormatProperties::*      field;
1124                 const char*                                                                     fieldName;
1125                 VkFormatFeatureFlags                                            requiredFeatures;
1126         } fields[] =
1127         {
1128                 { &VkFormatProperties::linearTilingFeatures,    "linearTilingFeatures",         (VkFormatFeatureFlags)0                                         },
1129                 { &VkFormatProperties::optimalTilingFeatures,   "optimalTilingFeatures",        getRequiredOptimalTilingFeatures(format)        },
1130                 { &VkFormatProperties::bufferFeatures,                  "buffeFeatures",                        getRequiredBufferFeatures(format)                       }
1131         };
1132
1133         log << TestLog::Message << properties << TestLog::EndMessage;
1134
1135         for (int fieldNdx = 0; fieldNdx < DE_LENGTH_OF_ARRAY(fields); fieldNdx++)
1136         {
1137                 const char* const                               fieldName       = fields[fieldNdx].fieldName;
1138                 const VkFormatFeatureFlags              supported       = properties.*fields[fieldNdx].field;
1139                 const VkFormatFeatureFlags              required        = fields[fieldNdx].requiredFeatures;
1140
1141                 if ((supported & required) != required)
1142                 {
1143                         log << TestLog::Message << "ERROR in " << fieldName << ":\n"
1144                                                                     << "  required: " << getFormatFeatureFlagsStr(required) << "\n  "
1145                                                                         << "  missing: " << getFormatFeatureFlagsStr(~supported & required)
1146                                 << TestLog::EndMessage;
1147                         allOk = false;
1148                 }
1149         }
1150
1151         if (allOk)
1152                 return tcu::TestStatus::pass("Query and validation passed");
1153         else
1154                 return tcu::TestStatus::fail("Required features not supported");
1155 }
1156
1157 bool optimalTilingFeaturesSupported (Context& context, VkFormat format, VkFormatFeatureFlags features)
1158 {
1159         const VkFormatProperties        properties      = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
1160
1161         return (properties.optimalTilingFeatures & features) == features;
1162 }
1163
1164 bool optimalTilingFeaturesSupportedForAll (Context& context, const VkFormat* begin, const VkFormat* end, VkFormatFeatureFlags features)
1165 {
1166         for (const VkFormat* cur = begin; cur != end; ++cur)
1167         {
1168                 if (!optimalTilingFeaturesSupported(context, *cur, features))
1169                         return false;
1170         }
1171
1172         return true;
1173 }
1174
1175 tcu::TestStatus testDepthStencilSupported (Context& context)
1176 {
1177         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
1178                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1179                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_X8_D24_UNORM_PACK32 or VK_FORMAT_D32_SFLOAT");
1180
1181         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
1182                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1183                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT");
1184
1185         return tcu::TestStatus::pass("Required depth/stencil formats supported");
1186 }
1187
1188 tcu::TestStatus testCompressedFormatsSupported (Context& context)
1189 {
1190         static const VkFormat s_allBcFormats[] =
1191         {
1192                 VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1193                 VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1194                 VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1195                 VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1196                 VK_FORMAT_BC2_UNORM_BLOCK,
1197                 VK_FORMAT_BC2_SRGB_BLOCK,
1198                 VK_FORMAT_BC3_UNORM_BLOCK,
1199                 VK_FORMAT_BC3_SRGB_BLOCK,
1200                 VK_FORMAT_BC4_UNORM_BLOCK,
1201                 VK_FORMAT_BC4_SNORM_BLOCK,
1202                 VK_FORMAT_BC5_UNORM_BLOCK,
1203                 VK_FORMAT_BC5_SNORM_BLOCK,
1204                 VK_FORMAT_BC6H_UFLOAT_BLOCK,
1205                 VK_FORMAT_BC6H_SFLOAT_BLOCK,
1206                 VK_FORMAT_BC7_UNORM_BLOCK,
1207                 VK_FORMAT_BC7_SRGB_BLOCK,
1208         };
1209         static const VkFormat s_allEtc2Formats[] =
1210         {
1211                 VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
1212                 VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
1213                 VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
1214                 VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
1215                 VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
1216                 VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
1217                 VK_FORMAT_EAC_R11_UNORM_BLOCK,
1218                 VK_FORMAT_EAC_R11_SNORM_BLOCK,
1219                 VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
1220                 VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
1221         };
1222         static const VkFormat s_allAstcLdrFormats[] =
1223         {
1224                 VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
1225                 VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
1226                 VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
1227                 VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
1228                 VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
1229                 VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
1230                 VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
1231                 VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
1232                 VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
1233                 VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
1234                 VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
1235                 VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
1236                 VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
1237                 VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
1238                 VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
1239                 VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
1240                 VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
1241                 VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
1242                 VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
1243                 VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
1244                 VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
1245                 VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
1246                 VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
1247                 VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
1248                 VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
1249                 VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
1250                 VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
1251                 VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
1252         };
1253
1254         static const struct
1255         {
1256                 const char*                                                                     setName;
1257                 const char*                                                                     featureName;
1258                 const VkBool32 VkPhysicalDeviceFeatures::*      feature;
1259                 const VkFormat*                                                         formatsBegin;
1260                 const VkFormat*                                                         formatsEnd;
1261         } s_compressedFormatSets[] =
1262         {
1263                 { "BC",                 "textureCompressionBC",                 &VkPhysicalDeviceFeatures::textureCompressionBC,                DE_ARRAY_BEGIN(s_allBcFormats),                 DE_ARRAY_END(s_allBcFormats)            },
1264                 { "ETC2",               "textureCompressionETC2",               &VkPhysicalDeviceFeatures::textureCompressionETC2,              DE_ARRAY_BEGIN(s_allEtc2Formats),               DE_ARRAY_END(s_allEtc2Formats)          },
1265                 { "ASTC LDR",   "textureCompressionASTC_LDR",   &VkPhysicalDeviceFeatures::textureCompressionASTC_LDR,  DE_ARRAY_BEGIN(s_allAstcLdrFormats),    DE_ARRAY_END(s_allAstcLdrFormats)       },
1266         };
1267
1268         TestLog&                                                log                                     = context.getTestContext().getLog();
1269         const VkPhysicalDeviceFeatures& features                        = context.getDeviceFeatures();
1270         int                                                             numSupportedSets        = 0;
1271         int                                                             numErrors                       = 0;
1272         int                                                             numWarnings                     = 0;
1273
1274         for (int setNdx = 0; setNdx < DE_LENGTH_OF_ARRAY(s_compressedFormatSets); ++setNdx)
1275         {
1276                 const char* const       setName                 = s_compressedFormatSets[setNdx].setName;
1277                 const char* const       featureName             = s_compressedFormatSets[setNdx].featureName;
1278                 const bool                      featureBitSet   = features.*s_compressedFormatSets[setNdx].feature == VK_TRUE;
1279                 const bool                      allSupported    = optimalTilingFeaturesSupportedForAll(context,
1280                                                                                                                                                                    s_compressedFormatSets[setNdx].formatsBegin,
1281                                                                                                                                                                    s_compressedFormatSets[setNdx].formatsEnd,
1282                                                                                                                                                                    VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
1283
1284                 if (featureBitSet && !allSupported)
1285                 {
1286                         log << TestLog::Message << "ERROR: " << featureName << " = VK_TRUE but " << setName << " formats not supported" << TestLog::EndMessage;
1287                         numErrors += 1;
1288                 }
1289                 else if (allSupported && !featureBitSet)
1290                 {
1291                         log << TestLog::Message << "WARNING: " << setName << " formats supported but " << featureName << " = VK_FALSE" << TestLog::EndMessage;
1292                         numWarnings += 1;
1293                 }
1294
1295                 if (featureBitSet)
1296                 {
1297                         log << TestLog::Message << "All " << setName << " formats are supported" << TestLog::EndMessage;
1298                         numSupportedSets += 1;
1299                 }
1300                 else
1301                         log << TestLog::Message << setName << " formats are not supported" << TestLog::EndMessage;
1302         }
1303
1304         if (numSupportedSets == 0)
1305         {
1306                 log << TestLog::Message << "No compressed format sets supported" << TestLog::EndMessage;
1307                 numErrors += 1;
1308         }
1309
1310         if (numErrors > 0)
1311                 return tcu::TestStatus::fail("Compressed format support not valid");
1312         else if (numWarnings > 0)
1313                 return tcu::TestStatus(QP_TEST_RESULT_QUALITY_WARNING, "Found inconsistencies in compressed format support");
1314         else
1315                 return tcu::TestStatus::pass("Compressed texture format support is valid");
1316 }
1317
1318 void createFormatTests (tcu::TestCaseGroup* testGroup)
1319 {
1320         DE_STATIC_ASSERT(VK_FORMAT_UNDEFINED == 0);
1321
1322         for (deUint32 formatNdx = VK_FORMAT_UNDEFINED+1; formatNdx < VK_FORMAT_LAST; ++formatNdx)
1323         {
1324                 const VkFormat          format                  = (VkFormat)formatNdx;
1325                 const char* const       enumName                = getFormatName(format);
1326                 const string            caseName                = de::toLower(string(enumName).substr(10));
1327
1328                 addFunctionCase(testGroup, caseName, enumName, formatProperties, format);
1329         }
1330
1331         addFunctionCase(testGroup, "depth_stencil",                     "",     testDepthStencilSupported);
1332         addFunctionCase(testGroup, "compressed_formats",        "",     testCompressedFormatsSupported);
1333 }
1334
1335 VkImageUsageFlags getValidImageUsageFlags (VkFormat, VkFormatFeatureFlags supportedFeatures)
1336 {
1337         VkImageUsageFlags       flags   = (VkImageUsageFlags)0;
1338
1339         // If format is supported at all, it must be valid transfer src+dst
1340         if (supportedFeatures != 0)
1341                 flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1342
1343         if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
1344                 flags |= VK_IMAGE_USAGE_SAMPLED_BIT;
1345
1346         if ((supportedFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) != 0)
1347                 flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
1348
1349         if ((supportedFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)
1350                 flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1351
1352         if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
1353                 flags |= VK_IMAGE_USAGE_STORAGE_BIT;
1354
1355         return flags;
1356 }
1357
1358 bool isValidImageUsageFlagCombination (VkImageUsageFlags usage)
1359 {
1360         return usage != 0;
1361 }
1362
1363 VkImageCreateFlags getValidImageCreateFlags (const VkPhysicalDeviceFeatures& deviceFeatures, VkFormat, VkFormatFeatureFlags, VkImageType type, VkImageUsageFlags usage)
1364 {
1365         VkImageCreateFlags      flags   = (VkImageCreateFlags)0;
1366
1367         if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
1368         {
1369                 flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
1370
1371                 if (type == VK_IMAGE_TYPE_2D)
1372                         flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
1373         }
1374
1375         if ((usage & (VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT)) != 0 &&
1376                 (usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)
1377         {
1378                 if (deviceFeatures.sparseBinding)
1379                         flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT|VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
1380
1381                 if (deviceFeatures.sparseResidencyAliased)
1382                         flags |= VK_IMAGE_CREATE_SPARSE_ALIASED_BIT;
1383         }
1384
1385         return flags;
1386 }
1387
1388 bool isValidImageCreateFlagCombination (VkImageCreateFlags)
1389 {
1390         return true;
1391 }
1392
1393 bool isRequiredImageParameterCombination (const VkPhysicalDeviceFeatures&       deviceFeatures,
1394                                                                                   const VkFormat                                        format,
1395                                                                                   const VkFormatProperties&                     formatProperties,
1396                                                                                   const VkImageType                                     imageType,
1397                                                                                   const VkImageTiling                           imageTiling,
1398                                                                                   const VkImageUsageFlags                       usageFlags,
1399                                                                                   const VkImageCreateFlags                      createFlags)
1400 {
1401         DE_UNREF(deviceFeatures);
1402         DE_UNREF(formatProperties);
1403         DE_UNREF(createFlags);
1404
1405         // Linear images can have arbitrary limitations
1406         if (imageTiling == VK_IMAGE_TILING_LINEAR)
1407                 return false;
1408
1409         // Support for other usages for compressed formats is optional
1410         if (isCompressedFormat(format) &&
1411                 (usageFlags & ~(VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT)) != 0)
1412                 return false;
1413
1414         // Support for 1D, and sliced 3D compressed formats is optional
1415         if (isCompressedFormat(format) && (imageType == VK_IMAGE_TYPE_1D || imageType == VK_IMAGE_TYPE_3D))
1416                 return false;
1417
1418         DE_ASSERT(deviceFeatures.sparseBinding || (createFlags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT|VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)) == 0);
1419         DE_ASSERT(deviceFeatures.sparseResidencyAliased || (createFlags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) == 0);
1420
1421         return true;
1422 }
1423
1424 VkSampleCountFlags getRequiredOptimalTilingSampleCounts (const VkPhysicalDeviceLimits&  deviceLimits,
1425                                                                                                                  const VkFormat                                 format,
1426                                                                                                                  const VkImageUsageFlags                usageFlags)
1427 {
1428         if (!isCompressedFormat(format))
1429         {
1430                 const tcu::TextureFormat                tcuFormat       = mapVkFormat(format);
1431
1432                 if (usageFlags & VK_IMAGE_USAGE_STORAGE_BIT)
1433                         return deviceLimits.storageImageSampleCounts;
1434                 else if (tcuFormat.order == tcu::TextureFormat::D)
1435                         return deviceLimits.sampledImageDepthSampleCounts;
1436                 else if (tcuFormat.order == tcu::TextureFormat::S)
1437                         return deviceLimits.sampledImageStencilSampleCounts;
1438                 else if (tcuFormat.order == tcu::TextureFormat::DS)
1439                         return deviceLimits.sampledImageDepthSampleCounts & deviceLimits.sampledImageStencilSampleCounts;
1440                 else
1441                 {
1442                         const tcu::TextureChannelClass  chnClass        = tcu::getTextureChannelClass(tcuFormat.type);
1443
1444                         if (chnClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ||
1445                                 chnClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
1446                                 return deviceLimits.sampledImageIntegerSampleCounts;
1447                         else
1448                                 return deviceLimits.sampledImageColorSampleCounts;
1449                 }
1450         }
1451         else
1452                 return VK_SAMPLE_COUNT_1_BIT;
1453 }
1454
1455 struct ImageFormatPropertyCase
1456 {
1457         VkFormat                format;
1458         VkImageType             imageType;
1459         VkImageTiling   tiling;
1460
1461         ImageFormatPropertyCase (VkFormat format_, VkImageType imageType_, VkImageTiling tiling_)
1462                 : format        (format_)
1463                 , imageType     (imageType_)
1464                 , tiling        (tiling_)
1465         {}
1466
1467         ImageFormatPropertyCase (void)
1468                 : format        (VK_FORMAT_LAST)
1469                 , imageType     (VK_IMAGE_TYPE_LAST)
1470                 , tiling        (VK_IMAGE_TILING_LAST)
1471         {}
1472 };
1473
1474 tcu::TestStatus imageFormatProperties (Context& context, ImageFormatPropertyCase params)
1475 {
1476         TestLog&                                                log                                     = context.getTestContext().getLog();
1477         const VkFormat                                  format                          = params.format;
1478         const VkImageType                               imageType                       = params.imageType;
1479         const VkImageTiling                             tiling                          = params.tiling;
1480         const VkPhysicalDeviceFeatures& deviceFeatures          = context.getDeviceFeatures();
1481         const VkPhysicalDeviceLimits&   deviceLimits            = context.getDeviceProperties().limits;
1482         const VkFormatProperties                formatProperties        = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
1483
1484         const VkFormatFeatureFlags              supportedFeatures       = tiling == VK_IMAGE_TILING_LINEAR ? formatProperties.linearTilingFeatures : formatProperties.optimalTilingFeatures;
1485         const VkImageUsageFlags                 usageFlagSet            = getValidImageUsageFlags(format, supportedFeatures);
1486
1487         for (VkImageUsageFlags curUsageFlags = 0; curUsageFlags <= usageFlagSet; curUsageFlags++)
1488         {
1489                 if ((curUsageFlags & ~usageFlagSet) != 0 ||
1490                         !isValidImageUsageFlagCombination(curUsageFlags))
1491                         continue;
1492
1493                 const VkImageCreateFlags        createFlagSet           = getValidImageCreateFlags(deviceFeatures, format, supportedFeatures, imageType, curUsageFlags);
1494
1495                 for (VkImageCreateFlags curCreateFlags = 0; curCreateFlags <= createFlagSet; curCreateFlags++)
1496                 {
1497                         if ((curCreateFlags & ~createFlagSet) != 0 ||
1498                                 !isValidImageCreateFlagCombination(curCreateFlags))
1499                                 continue;
1500
1501                         const bool      isRequiredCombination   = isRequiredImageParameterCombination(deviceFeatures,
1502                                                                                                                                                                           format,
1503                                                                                                                                                                           formatProperties,
1504                                                                                                                                                                           imageType,
1505                                                                                                                                                                           tiling,
1506                                                                                                                                                                           curUsageFlags,
1507                                                                                                                                                                           curCreateFlags);
1508
1509                         log << TestLog::Message << "Testing " << getImageTypeStr(imageType) << ", "
1510                                                                         << getImageTilingStr(tiling) << ", "
1511                                                                         << getImageUsageFlagsStr(curUsageFlags) << ", "
1512                                                                         << getImageCreateFlagsStr(curCreateFlags)
1513                                 << TestLog::EndMessage;
1514
1515                         try
1516                         {
1517                                 const VkImageFormatProperties   properties                      = getPhysicalDeviceImageFormatProperties(context.getInstanceInterface(),
1518                                                                                                                                                                                                                          context.getPhysicalDevice(),
1519                                                                                                                                                                                                                          format,
1520                                                                                                                                                                                                                          imageType,
1521                                                                                                                                                                                                                          tiling,
1522                                                                                                                                                                                                                          curUsageFlags,
1523                                                                                                                                                                                                                          curCreateFlags);
1524                                 const deUint32                                  fullMipPyramidSize      = de::max(de::max(deLog2Ceil32(properties.maxExtent.width),
1525                                                                                                                                                                           deLog2Ceil32(properties.maxExtent.height)),
1526                                                                                                                                                           deLog2Ceil32(properties.maxExtent.depth)) + 1;
1527
1528                                 log << TestLog::Message << properties << "\n" << TestLog::EndMessage;
1529
1530                                 TCU_CHECK(imageType != VK_IMAGE_TYPE_1D || (properties.maxExtent.width >= 1 && properties.maxExtent.height == 1 && properties.maxExtent.depth == 1));
1531                                 TCU_CHECK(imageType != VK_IMAGE_TYPE_2D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth == 1));
1532                                 TCU_CHECK(imageType != VK_IMAGE_TYPE_3D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth >= 1));
1533
1534                                 if (tiling == VK_IMAGE_TILING_OPTIMAL)
1535                                 {
1536                                         const VkSampleCountFlags        requiredSampleCounts    = getRequiredOptimalTilingSampleCounts(deviceLimits, format, curUsageFlags);
1537                                         TCU_CHECK((properties.sampleCounts & requiredSampleCounts) == requiredSampleCounts);
1538                                 }
1539                                 else
1540                                         TCU_CHECK(properties.sampleCounts == VK_SAMPLE_COUNT_1_BIT);
1541
1542                                 if (isRequiredCombination)
1543                                 {
1544                                         TCU_CHECK(imageType != VK_IMAGE_TYPE_1D || (properties.maxExtent.width  >= deviceLimits.maxImageDimension1D));
1545                                         TCU_CHECK(imageType != VK_IMAGE_TYPE_2D || (properties.maxExtent.width  >= deviceLimits.maxImageDimension2D &&
1546                                                                                                                                 properties.maxExtent.height     >= deviceLimits.maxImageDimension2D));
1547                                         TCU_CHECK(imageType != VK_IMAGE_TYPE_3D || (properties.maxExtent.width  >= deviceLimits.maxImageDimension3D &&
1548                                                                                                                                 properties.maxExtent.height     >= deviceLimits.maxImageDimension3D &&
1549                                                                                                                                 properties.maxExtent.depth      >= deviceLimits.maxImageDimension3D));
1550                                         TCU_CHECK(properties.maxMipLevels == fullMipPyramidSize);
1551                                         TCU_CHECK(imageType != VK_IMAGE_TYPE_3D || properties.maxArrayLayers == 1);
1552                                         TCU_CHECK(imageType == VK_IMAGE_TYPE_3D || properties.maxArrayLayers >= deviceLimits.maxImageArrayLayers);
1553                                 }
1554                                 else
1555                                 {
1556                                         TCU_CHECK(properties.maxMipLevels == 1 || properties.maxMipLevels == fullMipPyramidSize);
1557                                         TCU_CHECK(properties.maxArrayLayers >= 1);
1558                                 }
1559
1560                                 TCU_CHECK(properties.maxResourceSize >= (VkDeviceSize)MINIMUM_REQUIRED_IMAGE_RESOURCE_SIZE);
1561                         }
1562                         catch (const Error& error)
1563                         {
1564                                 if (error.getError() == VK_ERROR_FORMAT_NOT_SUPPORTED)
1565                                 {
1566                                         log << TestLog::Message << "Got VK_ERROR_FORMAT_NOT_SUPPORTED" << TestLog::EndMessage;
1567
1568                                         if (isRequiredCombination)
1569                                                 TCU_FAIL("VK_ERROR_FORMAT_NOT_SUPPORTED returned for required image parameter combination");
1570                                 }
1571                                 else
1572                                         throw;
1573                         }
1574                 }
1575         }
1576
1577         return tcu::TestStatus::pass("All queries succeeded");
1578 }
1579
1580 void createImageFormatTypeTilingTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
1581 {
1582         DE_ASSERT(params.format == VK_FORMAT_LAST);
1583
1584         for (deUint32 formatNdx = VK_FORMAT_UNDEFINED+1; formatNdx < VK_FORMAT_LAST; ++formatNdx)
1585         {
1586                 const VkFormat          format                  = (VkFormat)formatNdx;
1587                 const char* const       enumName                = getFormatName(format);
1588                 const string            caseName                = de::toLower(string(enumName).substr(10));
1589
1590                 params.format = format;
1591
1592                 addFunctionCase(testGroup, caseName, enumName, imageFormatProperties, params);
1593         }
1594 }
1595
1596 void createImageFormatTypeTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
1597 {
1598         DE_ASSERT(params.tiling == VK_IMAGE_TILING_LAST);
1599
1600         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "optimal",     "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(VK_FORMAT_LAST, params.imageType, VK_IMAGE_TILING_OPTIMAL)));
1601         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "linear",      "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(VK_FORMAT_LAST, params.imageType, VK_IMAGE_TILING_LINEAR)));
1602 }
1603
1604 void createImageFormatTests (tcu::TestCaseGroup* testGroup)
1605 {
1606         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "1d", "", createImageFormatTypeTests, ImageFormatPropertyCase(VK_FORMAT_LAST, VK_IMAGE_TYPE_1D, VK_IMAGE_TILING_LAST)));
1607         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "2d", "", createImageFormatTypeTests, ImageFormatPropertyCase(VK_FORMAT_LAST, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_LAST)));
1608         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "3d", "", createImageFormatTypeTests, ImageFormatPropertyCase(VK_FORMAT_LAST, VK_IMAGE_TYPE_3D, VK_IMAGE_TILING_LAST)));
1609 }
1610
1611 } // anonymous
1612
1613 tcu::TestCaseGroup* createFeatureInfoTests (tcu::TestContext& testCtx)
1614 {
1615         de::MovePtr<tcu::TestCaseGroup> infoTests       (new tcu::TestCaseGroup(testCtx, "info", "Platform Information Tests"));
1616
1617         {
1618                 de::MovePtr<tcu::TestCaseGroup> instanceInfoTests       (new tcu::TestCaseGroup(testCtx, "instance", "Instance Information Tests"));
1619
1620                 addFunctionCase(instanceInfoTests.get(), "physical_devices",            "Physical devices",                     enumeratePhysicalDevices);
1621                 addFunctionCase(instanceInfoTests.get(), "layers",                                      "Layers",                                       enumerateInstanceLayers);
1622                 addFunctionCase(instanceInfoTests.get(), "extensions",                          "Extensions",                           enumerateInstanceExtensions);
1623
1624                 infoTests->addChild(instanceInfoTests.release());
1625         }
1626
1627         {
1628                 de::MovePtr<tcu::TestCaseGroup> deviceInfoTests (new tcu::TestCaseGroup(testCtx, "device", "Device Information Tests"));
1629
1630                 addFunctionCase(deviceInfoTests.get(), "features",                                      "Device Features",                      deviceFeatures);
1631                 addFunctionCase(deviceInfoTests.get(), "properties",                            "Device Properties",            deviceProperties);
1632                 addFunctionCase(deviceInfoTests.get(), "queue_family_properties",       "Queue family properties",      deviceQueueFamilyProperties);
1633                 addFunctionCase(deviceInfoTests.get(), "memory_properties",                     "Memory properties",            deviceMemoryProperties);
1634                 addFunctionCase(deviceInfoTests.get(), "layers",                                        "Layers",                                       enumerateDeviceLayers);
1635                 addFunctionCase(deviceInfoTests.get(), "extensions",                            "Extensions",                           enumerateDeviceExtensions);
1636
1637                 infoTests->addChild(deviceInfoTests.release());
1638         }
1639
1640         infoTests->addChild(createTestGroup(testCtx, "format_properties",               "VkGetPhysicalDeviceFormatProperties() Tests",          createFormatTests));
1641         infoTests->addChild(createTestGroup(testCtx, "image_format_properties", "VkGetPhysicalDeviceImageFormatProperties() Tests",     createImageFormatTests));
1642
1643         return infoTests.release();
1644 }
1645
1646 } // api
1647 } // vkt