4c9c20f1af0a5c0a8ceeae39de7b8a6ec3c908af
[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  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Api Feature Query tests
22  *//*--------------------------------------------------------------------*/
23
24 #include "vktApiFeatureInfo.hpp"
25
26 #include "vktTestCaseUtil.hpp"
27 #include "vktTestGroupUtil.hpp"
28
29 #include "vkPlatform.hpp"
30 #include "vkStrUtil.hpp"
31 #include "vkRef.hpp"
32 #include "vkDeviceUtil.hpp"
33 #include "vkQueryUtil.hpp"
34 #include "vkImageUtil.hpp"
35 #include "vkApiVersion.hpp"
36
37 #include "tcuTestLog.hpp"
38 #include "tcuFormatUtil.hpp"
39 #include "tcuTextureUtil.hpp"
40 #include "tcuResultCollector.hpp"
41
42 #include "deUniquePtr.hpp"
43 #include "deString.h"
44 #include "deStringUtil.hpp"
45 #include "deSTLUtil.hpp"
46 #include "deMemory.h"
47 #include "deMath.h"
48
49 #include <vector>
50 #include <set>
51 #include <string>
52
53 namespace vkt
54 {
55 namespace api
56 {
57 namespace
58 {
59
60 using namespace vk;
61 using std::vector;
62 using std::set;
63 using std::string;
64 using tcu::TestLog;
65 using tcu::ScopedLogSection;
66
67 enum
68 {
69         GUARD_SIZE                                                              = 0x20,                 //!< Number of bytes to check
70         GUARD_VALUE                                                             = 0xcd,                 //!< Data pattern
71 };
72
73 static const VkDeviceSize MINIMUM_REQUIRED_IMAGE_RESOURCE_SIZE =        (1LLU<<31);     //!< Minimum value for VkImageFormatProperties::maxResourceSize (2GiB)
74
75 enum LimitFormat
76 {
77         LIMIT_FORMAT_SIGNED_INT,
78         LIMIT_FORMAT_UNSIGNED_INT,
79         LIMIT_FORMAT_FLOAT,
80         LIMIT_FORMAT_DEVICE_SIZE,
81         LIMIT_FORMAT_BITMASK,
82
83         LIMIT_FORMAT_LAST
84 };
85
86 enum LimitType
87 {
88         LIMIT_TYPE_MIN,
89         LIMIT_TYPE_MAX,
90         LIMIT_TYPE_NONE,
91
92         LIMIT_TYPE_LAST
93 };
94
95 #define LIMIT(_X_)              DE_OFFSET_OF(VkPhysicalDeviceLimits, _X_), (const char*)(#_X_)
96 #define FEATURE(_X_)    DE_OFFSET_OF(VkPhysicalDeviceFeatures, _X_)
97
98 inline bool isExtensionSupported (const vector<string>& extensionStrings, const string& extensionName)
99 {
100         return de::contains(extensionStrings.begin(), extensionStrings.end(), extensionName);
101 }
102
103 bool validateFeatureLimits(VkPhysicalDeviceProperties* properties, VkPhysicalDeviceFeatures* features, TestLog& log)
104 {
105         bool                                            limitsOk        = true;
106         VkPhysicalDeviceLimits*         limits          = &properties->limits;
107         struct FeatureLimitTable
108         {
109                 deUint32                offset;
110                 const char*             name;
111                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
112                 deInt32                 intVal;                         //!< Format is SIGNED_INT
113                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
114                 float                   floatVal;                       //!< Format is FLOAT
115                 LimitFormat             format;
116                 LimitType               type;
117                 deInt32                 unsuppTableNdx;
118         } featureLimitTable[] =   //!< Based on 1.0.28 Vulkan spec
119         {
120                 { LIMIT(maxImageDimension1D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
121                 { LIMIT(maxImageDimension2D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
122                 { LIMIT(maxImageDimension3D),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
123                 { LIMIT(maxImageDimensionCube),                                                         4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
124                 { LIMIT(maxImageArrayLayers),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
125                 { LIMIT(maxTexelBufferElements),                                                        65536, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
126                 { LIMIT(maxUniformBufferRange),                                                         16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
127                 { LIMIT(maxStorageBufferRange),                                                         0, 0, 0, 0, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
128                 { LIMIT(maxPushConstantsSize),                                                          128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
129                 { LIMIT(maxMemoryAllocationCount),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
130                 { LIMIT(maxSamplerAllocationCount),                                                     0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE , -1 },
131                 { LIMIT(bufferImageGranularity),                                                        0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
132                 { LIMIT(bufferImageGranularity),                                                        0, 0, 131072, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
133                 { LIMIT(sparseAddressSpaceSize),                                                        0, 0, 2UL*1024*1024*1024, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
134                 { LIMIT(maxBoundDescriptorSets),                                                        4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
135                 { LIMIT(maxPerStageDescriptorSamplers),                                         16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
136                 { LIMIT(maxPerStageDescriptorUniformBuffers),                           12, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
137                 { LIMIT(maxPerStageDescriptorStorageBuffers),                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
138                 { LIMIT(maxPerStageDescriptorSampledImages),                            16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
139                 { LIMIT(maxPerStageDescriptorStorageImages),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
140                 { LIMIT(maxPerStageDescriptorInputAttachments),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
141                 { LIMIT(maxPerStageResources),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE , -1 },
142                 { LIMIT(maxDescriptorSetSamplers),                                                      96, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
143                 { LIMIT(maxDescriptorSetUniformBuffers),                                        72, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
144                 { LIMIT(maxDescriptorSetUniformBuffersDynamic),                         8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
145                 { LIMIT(maxDescriptorSetStorageBuffers),                                        24, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
146                 { LIMIT(maxDescriptorSetStorageBuffersDynamic),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
147                 { LIMIT(maxDescriptorSetSampledImages),                                         96, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
148                 { LIMIT(maxDescriptorSetStorageImages),                                         24, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
149                 { LIMIT(maxDescriptorSetInputAttachments),                                      0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE  , -1 },
150                 { LIMIT(maxVertexInputAttributes),                                                      16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
151                 { LIMIT(maxVertexInputBindings),                                                        16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
152                 { LIMIT(maxVertexInputAttributeOffset),                                         2047, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
153                 { LIMIT(maxVertexInputBindingStride),                                           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
154                 { LIMIT(maxVertexOutputComponents),                                                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
155                 { LIMIT(maxTessellationGenerationLevel),                                        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
156                 { LIMIT(maxTessellationPatchSize),                                                      32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
157                 { LIMIT(maxTessellationControlPerVertexInputComponents),        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
158                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
159                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        120, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
160                 { LIMIT(maxTessellationControlTotalOutputComponents),           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
161                 { LIMIT(maxTessellationEvaluationInputComponents),                      64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
162                 { LIMIT(maxTessellationEvaluationOutputComponents),                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
163                 { LIMIT(maxGeometryShaderInvocations),                                          32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
164                 { LIMIT(maxGeometryInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
165                 { LIMIT(maxGeometryOutputComponents),                                           64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
166                 { LIMIT(maxGeometryOutputVertices),                                                     256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
167                 { LIMIT(maxGeometryTotalOutputComponents),                                      1024, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
168                 { LIMIT(maxFragmentInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
169                 { LIMIT(maxFragmentOutputAttachments),                                          4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
170                 { LIMIT(maxFragmentDualSrcAttachments),                                         1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
171                 { LIMIT(maxFragmentCombinedOutputResources),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
172                 { LIMIT(maxComputeSharedMemorySize),                                            16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
173                 { LIMIT(maxComputeWorkGroupCount[0]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
174                 { LIMIT(maxComputeWorkGroupCount[1]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
175                 { LIMIT(maxComputeWorkGroupCount[2]),                                           65535,  0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
176                 { LIMIT(maxComputeWorkGroupInvocations),                                        128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
177                 { LIMIT(maxComputeWorkGroupSize[0]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
178                 { LIMIT(maxComputeWorkGroupSize[1]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
179                 { LIMIT(maxComputeWorkGroupSize[2]),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
180                 { LIMIT(subPixelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
181                 { LIMIT(subTexelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
182                 { LIMIT(mipmapPrecisionBits),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
183                 { LIMIT(maxDrawIndexedIndexValue),                                                      (deUint32)~0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
184                 { LIMIT(maxDrawIndirectCount),                                                          65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
185                 { LIMIT(maxSamplerLodBias),                                                                     0, 0, 0, 2.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
186                 { LIMIT(maxSamplerAnisotropy),                                                          0, 0, 0, 16.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
187                 { LIMIT(maxViewports),                                                                          16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
188                 { LIMIT(maxViewportDimensions[0]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
189                 { LIMIT(maxViewportDimensions[1]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
190                 { LIMIT(viewportBoundsRange[0]),                                                        0, 0, 0, -8192.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
191                 { LIMIT(viewportBoundsRange[1]),                                                        0, 0, 0, 8191.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
192                 { LIMIT(viewportSubPixelBits),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
193                 { LIMIT(minMemoryMapAlignment),                                                         64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
194                 { LIMIT(minTexelBufferOffsetAlignment),                                         0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
195                 { LIMIT(minTexelBufferOffsetAlignment),                                         0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
196                 { LIMIT(minUniformBufferOffsetAlignment),                                       0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
197                 { LIMIT(minUniformBufferOffsetAlignment),                                       0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
198                 { LIMIT(minStorageBufferOffsetAlignment),                                       0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
199                 { LIMIT(minStorageBufferOffsetAlignment),                                       0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
200                 { LIMIT(minTexelOffset),                                                                        0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
201                 { LIMIT(maxTexelOffset),                                                                        7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
202                 { LIMIT(minTexelGatherOffset),                                                          0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
203                 { LIMIT(maxTexelGatherOffset),                                                          7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
204                 { LIMIT(minInterpolationOffset),                                                        0, 0, 0, -0.5f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
205                 { LIMIT(maxInterpolationOffset),                                                        0, 0, 0, 0.5f - (1.0f/deFloatPow(2.0f, (float)limits->subPixelInterpolationOffsetBits)), LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
206                 { LIMIT(subPixelInterpolationOffsetBits),                                       4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
207                 { LIMIT(maxFramebufferWidth),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
208                 { LIMIT(maxFramebufferHeight),                                                          4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
209                 { LIMIT(maxFramebufferLayers),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
210                 { LIMIT(framebufferColorSampleCounts),                                          VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
211                 { LIMIT(framebufferDepthSampleCounts),                                          VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
212                 { LIMIT(framebufferStencilSampleCounts),                                        VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
213                 { LIMIT(framebufferNoAttachmentsSampleCounts),                          VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
214                 { LIMIT(maxColorAttachments),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
215                 { LIMIT(sampledImageColorSampleCounts),                                         VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
216                 { LIMIT(sampledImageIntegerSampleCounts),                                       VK_SAMPLE_COUNT_1_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
217                 { LIMIT(sampledImageDepthSampleCounts),                                         VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
218                 { LIMIT(sampledImageStencilSampleCounts),                                       VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
219                 { LIMIT(storageImageSampleCounts),                                                      VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
220                 { LIMIT(maxSampleMaskWords),                                                            1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
221                 { LIMIT(timestampComputeAndGraphics),                                           0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
222                 { LIMIT(timestampPeriod),                                                                       0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
223                 { LIMIT(maxClipDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
224                 { LIMIT(maxCullDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
225                 { LIMIT(maxCombinedClipAndCullDistances),                                       8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
226                 { LIMIT(discreteQueuePriorities),                                                       8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
227                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 0.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
228                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
229                 { LIMIT(pointSizeRange[1]),                                                                     0, 0, 0, 64.0f - limits->pointSizeGranularity , LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
230                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 0.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
231                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
232                 { LIMIT(lineWidthRange[1]),                                                                     0, 0, 0, 8.0f - limits->lineWidthGranularity, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
233                 { LIMIT(pointSizeGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
234                 { LIMIT(lineWidthGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
235                 { LIMIT(strictLines),                                                                           0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
236                 { LIMIT(standardSampleLocations),                                                       0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
237                 { LIMIT(optimalBufferCopyOffsetAlignment),                                      0, 0, 0, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_NONE, -1 },
238                 { LIMIT(optimalBufferCopyRowPitchAlignment),                            0, 0, 0, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_NONE, -1 },
239                 { LIMIT(nonCoherentAtomSize),                                                           0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
240                 { LIMIT(nonCoherentAtomSize),                                                           0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
241         };
242
243         const struct UnsupportedFeatureLimitTable
244         {
245                 deUint32                limitOffset;
246                 const char*             name;
247                 deUint32                featureOffset;
248                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
249                 deInt32                 intVal;                         //!< Format is SIGNED_INT
250                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
251                 float                   floatVal;                       //!< Format is FLOAT
252         } unsupportedFeatureTable[] =
253         {
254                 { LIMIT(sparseAddressSpaceSize),                                                        FEATURE(sparseBinding),                                 0, 0, 0, 0.0f },
255                 { LIMIT(maxTessellationGenerationLevel),                                        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
256                 { LIMIT(maxTessellationPatchSize),                                                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
257                 { LIMIT(maxTessellationControlPerVertexInputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
258                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
259                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
260                 { LIMIT(maxTessellationControlTotalOutputComponents),           FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
261                 { LIMIT(maxTessellationEvaluationInputComponents),                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
262                 { LIMIT(maxTessellationEvaluationOutputComponents),                     FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
263                 { LIMIT(maxGeometryShaderInvocations),                                          FEATURE(geometryShader),                                0, 0, 0, 0.0f },
264                 { LIMIT(maxGeometryInputComponents),                                            FEATURE(geometryShader),                                0, 0, 0, 0.0f },
265                 { LIMIT(maxGeometryOutputComponents),                                           FEATURE(geometryShader),                                0, 0, 0, 0.0f },
266                 { LIMIT(maxGeometryOutputVertices),                                                     FEATURE(geometryShader),                                0, 0, 0, 0.0f },
267                 { LIMIT(maxGeometryTotalOutputComponents),                                      FEATURE(geometryShader),                                0, 0, 0, 0.0f },
268                 { LIMIT(maxFragmentDualSrcAttachments),                                         FEATURE(dualSrcBlend),                                  0, 0, 0, 0.0f },
269                 { LIMIT(maxDrawIndexedIndexValue),                                                      FEATURE(fullDrawIndexUint32),                   (1<<24)-1, 0, 0, 0.0f },
270                 { LIMIT(maxDrawIndirectCount),                                                          FEATURE(multiDrawIndirect),                             1, 0, 0, 0.0f },
271                 { LIMIT(maxSamplerAnisotropy),                                                          FEATURE(samplerAnisotropy),                             1, 0, 0, 0.0f },
272                 { LIMIT(maxViewports),                                                                          FEATURE(multiViewport),                                 1, 0, 0, 0.0f },
273                 { LIMIT(minTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
274                 { LIMIT(maxTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
275                 { LIMIT(minInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
276                 { LIMIT(maxInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
277                 { LIMIT(subPixelInterpolationOffsetBits),                                       FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
278                 { LIMIT(storageImageSampleCounts),                                                      FEATURE(shaderStorageImageMultisample), VK_SAMPLE_COUNT_1_BIT, 0, 0, 0.0f },
279                 { LIMIT(maxClipDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
280                 { LIMIT(maxCullDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
281                 { LIMIT(maxCombinedClipAndCullDistances),                                       FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
282                 { LIMIT(pointSizeRange[0]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
283                 { LIMIT(pointSizeRange[1]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
284                 { LIMIT(lineWidthRange[0]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
285                 { LIMIT(lineWidthRange[1]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
286                 { LIMIT(pointSizeGranularity),                                                          FEATURE(largePoints),                                   0, 0, 0, 0.0f },
287                 { LIMIT(lineWidthGranularity),                                                          FEATURE(wideLines),                                             0, 0, 0, 0.0f }
288         };
289
290         log << TestLog::Message << *limits << TestLog::EndMessage;
291
292         //!< First build a map from limit to unsupported table index
293         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
294         {
295                 for (deUint32 unsuppNdx = 0; unsuppNdx < DE_LENGTH_OF_ARRAY(unsupportedFeatureTable); unsuppNdx++)
296                 {
297                         if (unsupportedFeatureTable[unsuppNdx].limitOffset == featureLimitTable[ndx].offset)
298                         {
299                                 featureLimitTable[ndx].unsuppTableNdx = unsuppNdx;
300                                 break;
301                         }
302                 }
303         }
304
305         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
306         {
307                 switch (featureLimitTable[ndx].format)
308                 {
309                         case LIMIT_FORMAT_UNSIGNED_INT:
310                         {
311                                 deUint32 limitToCheck = featureLimitTable[ndx].uintVal;
312                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
313                                 {
314                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
315                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].uintVal;
316                                 }
317
318                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
319                                 {
320
321                                         if (*((deUint32*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
322                                         {
323                                                 log << TestLog::Message << "limit Validation failed " << featureLimitTable[ndx].name
324                                                         << " not valid-limit type MIN - actual is "
325                                                         << *((deUint32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
326                                                 limitsOk = false;
327                                         }
328                                 }
329                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
330                                 {
331                                         if (*((deUint32*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
332                                         {
333                                                 log << TestLog::Message << "limit validation failed,  " << featureLimitTable[ndx].name
334                                                         << " not valid-limit type MAX - actual is "
335                                                         << *((deUint32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
336                                                 limitsOk = false;
337                                         }
338                                 }
339                                 break;
340                         }
341
342                         case LIMIT_FORMAT_FLOAT:
343                         {
344                                 float limitToCheck = featureLimitTable[ndx].floatVal;
345                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
346                                 {
347                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
348                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].floatVal;
349                                 }
350
351                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
352                                 {
353                                         if (*((float*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
354                                         {
355                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
356                                                         << " not valid-limit type MIN - actual is "
357                                                         << *((float*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
358                                                 limitsOk = false;
359                                         }
360                                 }
361                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
362                                 {
363                                         if (*((float*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
364                                         {
365                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
366                                                         << " not valid-limit type MAX actual is "
367                                                         << *((float*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
368                                                 limitsOk = false;
369                                         }
370                                 }
371                                 break;
372                         }
373
374                         case LIMIT_FORMAT_SIGNED_INT:
375                         {
376                                 deInt32 limitToCheck = featureLimitTable[ndx].intVal;
377                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
378                                 {
379                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
380                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].intVal;
381                                 }
382                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
383                                 {
384                                         if (*((deInt32*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
385                                         {
386                                                 log << TestLog::Message <<  "limit validation failed, " << featureLimitTable[ndx].name
387                                                         << " not valid-limit type MIN actual is "
388                                                         << *((deInt32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
389                                                 limitsOk = false;
390                                         }
391                                 }
392                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
393                                 {
394                                         if (*((deInt32*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
395                                         {
396                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
397                                                         << " not valid-limit type MAX actual is "
398                                                         << *((deInt32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
399                                                 limitsOk = false;
400                                         }
401                                 }
402                                 break;
403                         }
404
405                         case LIMIT_FORMAT_DEVICE_SIZE:
406                         {
407                                 deUint64 limitToCheck = featureLimitTable[ndx].deviceSizeVal;
408                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
409                                 {
410                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
411                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].deviceSizeVal;
412                                 }
413
414                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
415                                 {
416                                         if (*((deUint64*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
417                                         {
418                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
419                                                         << " not valid-limit type MIN actual is "
420                                                         << *((deUint64*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
421                                                 limitsOk = false;
422                                         }
423                                 }
424                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
425                                 {
426                                         if (*((deUint64*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
427                                         {
428                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
429                                                         << " not valid-limit type MAX actual is "
430                                                         << *((deUint64*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
431                                                 limitsOk = false;
432                                         }
433                                 }
434                                 break;
435                         }
436
437                         case LIMIT_FORMAT_BITMASK:
438                         {
439                                 deUint32 limitToCheck = featureLimitTable[ndx].uintVal;
440                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
441                                 {
442                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
443                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].uintVal;
444                                 }
445
446                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
447                                 {
448                                         if ((*((deUint32*)((deUint8*)limits+featureLimitTable[ndx].offset)) & limitToCheck) != limitToCheck)
449                                         {
450                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
451                                                         << " not valid-limit type bitmask actual is "
452                                                         << *((deUint64*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
453                                                 limitsOk = false;
454                                         }
455                                 }
456                                 break;
457                         }
458
459                         default:
460                                 DE_ASSERT(0);
461                                 limitsOk = false;
462                 }
463         }
464
465         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(limits->maxViewportDimensions); ndx++)
466         {
467                 if (limits->maxImageDimension2D > limits->maxViewportDimensions[ndx])
468                 {
469                         log << TestLog::Message << "limit validation failed, maxImageDimension2D of " << limits->maxImageDimension2D
470                                 << "is larger than maxViewportDimension[" << ndx << "] of " << limits->maxViewportDimensions[ndx] << TestLog::EndMessage;
471                         limitsOk = false;
472                 }
473         }
474
475         if (limits->viewportBoundsRange[0] > -2 * limits->maxViewportDimensions[0])
476         {
477                 log << TestLog::Message << "limit validation failed, viewPortBoundsRange[0] of " << limits->viewportBoundsRange[0]
478                         << "is larger than -2*maxViewportDimension[0] of " << -2*limits->maxViewportDimensions[0] << TestLog::EndMessage;
479                 limitsOk = false;
480         }
481
482         if (limits->viewportBoundsRange[1] < 2 * limits->maxViewportDimensions[1] - 1)
483         {
484                 log << TestLog::Message << "limit validation failed, viewportBoundsRange[1] of " << limits->viewportBoundsRange[1]
485                         << "is less than 2*maxViewportDimension[1] of " << 2*limits->maxViewportDimensions[1] << TestLog::EndMessage;
486                 limitsOk = false;
487         }
488
489         return limitsOk;
490 }
491
492 template<typename T>
493 class CheckIncompleteResult
494 {
495 public:
496         virtual                 ~CheckIncompleteResult  (void) {}
497         virtual void    getResult                               (Context& context, T* data) = 0;
498
499         void operator() (Context& context, tcu::ResultCollector& results, const std::size_t expectedCompleteSize)
500         {
501                 if (expectedCompleteSize == 0)
502                         return;
503
504                 vector<T>               outputData      (expectedCompleteSize);
505                 const deUint32  usedSize        = static_cast<deUint32>(expectedCompleteSize / 3);
506
507                 ValidateQueryBits::fillBits(outputData.begin(), outputData.end());      // unused entries should have this pattern intact
508                 m_count         = usedSize;
509                 m_result        = VK_SUCCESS;
510
511                 getResult(context, &outputData[0]);                                                                     // update m_count and m_result
512
513                 if (m_count != usedSize || m_result != VK_INCOMPLETE || !ValidateQueryBits::checkBits(outputData.begin() + m_count, outputData.end()))
514                         results.fail("Query didn't return VK_INCOMPLETE");
515         }
516
517 protected:
518         deUint32        m_count;
519         VkResult        m_result;
520 };
521
522 struct CheckEnumeratePhysicalDevicesIncompleteResult : public CheckIncompleteResult<VkPhysicalDevice>
523 {
524         void getResult (Context& context, VkPhysicalDevice* data)
525         {
526                 m_result = context.getInstanceInterface().enumeratePhysicalDevices(context.getInstance(), &m_count, data);
527         }
528 };
529
530 struct CheckEnumerateInstanceLayerPropertiesIncompleteResult : public CheckIncompleteResult<VkLayerProperties>
531 {
532         void getResult (Context& context, VkLayerProperties* data)
533         {
534                 m_result = context.getPlatformInterface().enumerateInstanceLayerProperties(&m_count, data);
535         }
536 };
537
538 struct CheckEnumerateDeviceLayerPropertiesIncompleteResult : public CheckIncompleteResult<VkLayerProperties>
539 {
540         void getResult (Context& context, VkLayerProperties* data)
541         {
542                 m_result = context.getInstanceInterface().enumerateDeviceLayerProperties(context.getPhysicalDevice(), &m_count, data);
543         }
544 };
545
546 struct CheckEnumerateInstanceExtensionPropertiesIncompleteResult : public CheckIncompleteResult<VkExtensionProperties>
547 {
548         CheckEnumerateInstanceExtensionPropertiesIncompleteResult (std::string layerName = std::string()) : m_layerName(layerName) {}
549
550         void getResult (Context& context, VkExtensionProperties* data)
551         {
552                 const char* pLayerName = (m_layerName.length() != 0 ? m_layerName.c_str() : DE_NULL);
553                 m_result = context.getPlatformInterface().enumerateInstanceExtensionProperties(pLayerName, &m_count, data);
554         }
555
556 private:
557         const std::string       m_layerName;
558 };
559
560 struct CheckEnumerateDeviceExtensionPropertiesIncompleteResult : public CheckIncompleteResult<VkExtensionProperties>
561 {
562         CheckEnumerateDeviceExtensionPropertiesIncompleteResult (std::string layerName = std::string()) : m_layerName(layerName) {}
563
564         void getResult (Context& context, VkExtensionProperties* data)
565         {
566                 const char* pLayerName = (m_layerName.length() != 0 ? m_layerName.c_str() : DE_NULL);
567                 m_result = context.getInstanceInterface().enumerateDeviceExtensionProperties(context.getPhysicalDevice(), pLayerName, &m_count, data);
568         }
569
570 private:
571         const std::string       m_layerName;
572 };
573
574 tcu::TestStatus enumeratePhysicalDevices (Context& context)
575 {
576         TestLog&                                                log             = context.getTestContext().getLog();
577         tcu::ResultCollector                    results (log);
578         const vector<VkPhysicalDevice>  devices = enumeratePhysicalDevices(context.getInstanceInterface(), context.getInstance());
579
580         log << TestLog::Integer("NumDevices", "Number of devices", "", QP_KEY_TAG_NONE, deInt64(devices.size()));
581
582         for (size_t ndx = 0; ndx < devices.size(); ndx++)
583                 log << TestLog::Message << ndx << ": " << devices[ndx] << TestLog::EndMessage;
584
585         CheckEnumeratePhysicalDevicesIncompleteResult()(context, results, devices.size());
586
587         return tcu::TestStatus(results.getResult(), results.getMessage());
588 }
589
590 template<typename T>
591 void collectDuplicates (set<T>& duplicates, const vector<T>& values)
592 {
593         set<T> seen;
594
595         for (size_t ndx = 0; ndx < values.size(); ndx++)
596         {
597                 const T& value = values[ndx];
598
599                 if (!seen.insert(value).second)
600                         duplicates.insert(value);
601         }
602 }
603
604 void checkDuplicates (tcu::ResultCollector& results, const char* what, const vector<string>& values)
605 {
606         set<string> duplicates;
607
608         collectDuplicates(duplicates, values);
609
610         for (set<string>::const_iterator iter = duplicates.begin(); iter != duplicates.end(); ++iter)
611         {
612                 std::ostringstream msg;
613                 msg << "Duplicate " << what << ": " << *iter;
614                 results.fail(msg.str());
615         }
616 }
617
618 void checkDuplicateExtensions (tcu::ResultCollector& results, const vector<string>& extensions)
619 {
620         checkDuplicates(results, "extension", extensions);
621 }
622
623 void checkDuplicateLayers (tcu::ResultCollector& results, const vector<string>& layers)
624 {
625         checkDuplicates(results, "layer", layers);
626 }
627
628 void checkKhrExtensions (tcu::ResultCollector&          results,
629                                                  const vector<string>&          extensions,
630                                                  const int                                      numAllowedKhrExtensions,
631                                                  const char* const*                     allowedKhrExtensions)
632 {
633         const set<string>       allowedExtSet           (allowedKhrExtensions, allowedKhrExtensions+numAllowedKhrExtensions);
634
635         for (vector<string>::const_iterator extIter = extensions.begin(); extIter != extensions.end(); ++extIter)
636         {
637                 // Only Khronos-controlled extensions are checked
638                 if ((de::beginsWith(*extIter, "VK_KHR_") || de::beginsWith(*extIter, "VK_KHX_")) &&
639                         !de::contains(allowedExtSet, *extIter))
640                 {
641                         results.fail("Unknown KHR extension " + *extIter);
642                 }
643         }
644 }
645
646 void checkInstanceExtensions (tcu::ResultCollector& results, const vector<string>& extensions)
647 {
648         static const char* s_allowedInstanceKhrExtensions[] =
649         {
650                 "VK_KHR_surface",
651                 "VK_KHR_display",
652                 "VK_KHR_android_surface",
653                 "VK_KHR_mir_surface",
654                 "VK_KHR_wayland_surface",
655                 "VK_KHR_win32_surface",
656                 "VK_KHR_xcb_surface",
657                 "VK_KHR_xlib_surface",
658                 "VK_KHR_get_physical_device_properties2",
659         };
660
661         checkKhrExtensions(results, extensions, DE_LENGTH_OF_ARRAY(s_allowedInstanceKhrExtensions), s_allowedInstanceKhrExtensions);
662         checkDuplicateExtensions(results, extensions);
663 }
664
665 void checkDeviceExtensions (tcu::ResultCollector& results, const vector<string>& extensions)
666 {
667         static const char* s_allowedInstanceKhrExtensions[] =
668         {
669                 "VK_KHR_swapchain",
670                 "VK_KHR_display_swapchain",
671                 "VK_KHR_sampler_mirror_clamp_to_edge",
672                 "VK_KHR_shader_draw_parameters",
673         };
674
675         checkKhrExtensions(results, extensions, DE_LENGTH_OF_ARRAY(s_allowedInstanceKhrExtensions), s_allowedInstanceKhrExtensions);
676         checkDuplicateExtensions(results, extensions);
677 }
678
679 tcu::TestStatus enumerateInstanceLayers (Context& context)
680 {
681         TestLog&                                                log                                     = context.getTestContext().getLog();
682         tcu::ResultCollector                    results                         (log);
683         const vector<VkLayerProperties> properties                      = enumerateInstanceLayerProperties(context.getPlatformInterface());
684         vector<string>                                  layerNames;
685
686         for (size_t ndx = 0; ndx < properties.size(); ndx++)
687         {
688                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
689
690                 layerNames.push_back(properties[ndx].layerName);
691         }
692
693         checkDuplicateLayers(results, layerNames);
694         CheckEnumerateInstanceLayerPropertiesIncompleteResult()(context, results, layerNames.size());
695
696         return tcu::TestStatus(results.getResult(), results.getMessage());
697 }
698
699 tcu::TestStatus enumerateInstanceExtensions (Context& context)
700 {
701         TestLog&                                log             = context.getTestContext().getLog();
702         tcu::ResultCollector    results (log);
703
704         {
705                 const ScopedLogSection                          section         (log, "Global", "Global Extensions");
706                 const vector<VkExtensionProperties>     properties      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), DE_NULL);
707                 vector<string>                                          extensionNames;
708
709                 for (size_t ndx = 0; ndx < properties.size(); ndx++)
710                 {
711                         log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
712
713                         extensionNames.push_back(properties[ndx].extensionName);
714                 }
715
716                 checkInstanceExtensions(results, extensionNames);
717                 CheckEnumerateInstanceExtensionPropertiesIncompleteResult()(context, results, properties.size());
718         }
719
720         {
721                 const vector<VkLayerProperties> layers  = enumerateInstanceLayerProperties(context.getPlatformInterface());
722
723                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
724                 {
725                         const ScopedLogSection                          section                         (log, layer->layerName, string("Layer: ") + layer->layerName);
726                         const vector<VkExtensionProperties>     properties                      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), layer->layerName);
727                         vector<string>                                          extensionNames;
728
729                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
730                         {
731                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
732
733                                 extensionNames.push_back(properties[extNdx].extensionName);
734                         }
735
736                         checkInstanceExtensions(results, extensionNames);
737                         CheckEnumerateInstanceExtensionPropertiesIncompleteResult(layer->layerName)(context, results, properties.size());
738                 }
739         }
740
741         return tcu::TestStatus(results.getResult(), results.getMessage());
742 }
743
744 tcu::TestStatus enumerateDeviceLayers (Context& context)
745 {
746         TestLog&                                                log                     = context.getTestContext().getLog();
747         tcu::ResultCollector                    results         (log);
748         const vector<VkLayerProperties> properties      = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
749         vector<string>                                  layerNames;
750
751         for (size_t ndx = 0; ndx < properties.size(); ndx++)
752         {
753                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
754
755                 layerNames.push_back(properties[ndx].layerName);
756         }
757
758         checkDuplicateLayers(results, layerNames);
759         CheckEnumerateDeviceLayerPropertiesIncompleteResult()(context, results, layerNames.size());
760
761         return tcu::TestStatus(results.getResult(), results.getMessage());
762 }
763
764 tcu::TestStatus enumerateDeviceExtensions (Context& context)
765 {
766         TestLog&                                log             = context.getTestContext().getLog();
767         tcu::ResultCollector    results (log);
768
769         {
770                 const ScopedLogSection                          section         (log, "Global", "Global Extensions");
771                 const vector<VkExtensionProperties>     properties      = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), DE_NULL);
772                 vector<string>                                          extensionNames;
773
774                 for (size_t ndx = 0; ndx < properties.size(); ndx++)
775                 {
776                         log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
777
778                         extensionNames.push_back(properties[ndx].extensionName);
779                 }
780
781                 checkDeviceExtensions(results, extensionNames);
782                 CheckEnumerateDeviceExtensionPropertiesIncompleteResult()(context, results, properties.size());
783         }
784
785         {
786                 const vector<VkLayerProperties> layers  = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
787
788                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
789                 {
790                         const ScopedLogSection                          section         (log, layer->layerName, string("Layer: ") + layer->layerName);
791                         const vector<VkExtensionProperties>     properties      = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), layer->layerName);
792                         vector<string>                                          extensionNames;
793
794                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
795                         {
796                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
797
798
799                                 extensionNames.push_back(properties[extNdx].extensionName);
800                         }
801
802                         checkDeviceExtensions(results, extensionNames);
803                         CheckEnumerateDeviceExtensionPropertiesIncompleteResult(layer->layerName)(context, results, properties.size());
804                 }
805         }
806
807         return tcu::TestStatus(results.getResult(), results.getMessage());
808 }
809
810 #define VK_SIZE_OF(STRUCT, MEMBER)                                      (sizeof(((STRUCT*)0)->MEMBER))
811 #define OFFSET_TABLE_ENTRY(STRUCT, MEMBER)                      { (size_t)DE_OFFSET_OF(STRUCT, MEMBER), VK_SIZE_OF(STRUCT, MEMBER) }
812
813 tcu::TestStatus deviceFeatures (Context& context)
814 {
815         using namespace ValidateQueryBits;
816
817         TestLog&                                                log                     = context.getTestContext().getLog();
818         VkPhysicalDeviceFeatures*               features;
819         deUint8                                                 buffer[sizeof(VkPhysicalDeviceFeatures) + GUARD_SIZE];
820
821         const QueryMemberTableEntry featureOffsetTable[] =
822         {
823                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, robustBufferAccess),
824                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fullDrawIndexUint32),
825                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, imageCubeArray),
826                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, independentBlend),
827                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, geometryShader),
828                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, tessellationShader),
829                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sampleRateShading),
830                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, dualSrcBlend),
831                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, logicOp),
832                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, multiDrawIndirect),
833                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, drawIndirectFirstInstance),
834                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthClamp),
835                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthBiasClamp),
836                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fillModeNonSolid),
837                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthBounds),
838                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, wideLines),
839                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, largePoints),
840                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, alphaToOne),
841                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, multiViewport),
842                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, samplerAnisotropy),
843                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionETC2),
844                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionASTC_LDR),
845                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionBC),
846                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, occlusionQueryPrecise),
847                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, pipelineStatisticsQuery),
848                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, vertexPipelineStoresAndAtomics),
849                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fragmentStoresAndAtomics),
850                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderTessellationAndGeometryPointSize),
851                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderImageGatherExtended),
852                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageExtendedFormats),
853                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageMultisample),
854                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageReadWithoutFormat),
855                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageWriteWithoutFormat),
856                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderUniformBufferArrayDynamicIndexing),
857                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderSampledImageArrayDynamicIndexing),
858                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageBufferArrayDynamicIndexing),
859                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageArrayDynamicIndexing),
860                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderClipDistance),
861                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderCullDistance),
862                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderFloat64),
863                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderInt64),
864                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderInt16),
865                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderResourceResidency),
866                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderResourceMinLod),
867                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseBinding),
868                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyBuffer),
869                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyImage2D),
870                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyImage3D),
871                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency2Samples),
872                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency4Samples),
873                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency8Samples),
874                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency16Samples),
875                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyAliased),
876                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, variableMultisampleRate),
877                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, inheritedQueries),
878                 { 0, 0 }
879         };
880
881         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
882         features = reinterpret_cast<VkPhysicalDeviceFeatures*>(buffer);
883
884         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), features);
885
886         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
887                 << TestLog::Message << *features << TestLog::EndMessage;
888
889         // Requirements and dependencies
890         {
891                 if (!features->robustBufferAccess)
892                         return tcu::TestStatus::fail("robustBufferAccess is not supported");
893
894                 // multiViewport requires MultiViewport (SPIR-V capability) support, which depends on Geometry
895                 if (features->multiViewport && !features->geometryShader)
896                         return tcu::TestStatus::fail("multiViewport is supported but geometryShader is not");
897         }
898
899         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
900         {
901                 if (buffer[ndx + sizeof(VkPhysicalDeviceFeatures)] != GUARD_VALUE)
902                 {
903                         log << TestLog::Message << "deviceFeatures - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
904                         return tcu::TestStatus::fail("deviceFeatures buffer overflow");
905                 }
906         }
907
908         if (!validateInitComplete(context.getPhysicalDevice(), &InstanceInterface::getPhysicalDeviceFeatures, context.getInstanceInterface(), featureOffsetTable))
909         {
910                 log << TestLog::Message << "deviceFeatures - VkPhysicalDeviceFeatures not completely initialized" << TestLog::EndMessage;
911                 return tcu::TestStatus::fail("deviceFeatures incomplete initialization");
912         }
913
914         return tcu::TestStatus::pass("Query succeeded");
915 }
916
917 tcu::TestStatus deviceProperties (Context& context)
918 {
919         using namespace ValidateQueryBits;
920
921         TestLog&                                                log                     = context.getTestContext().getLog();
922         VkPhysicalDeviceProperties*             props;
923         VkPhysicalDeviceFeatures                features;
924         deUint8                                                 buffer[sizeof(VkPhysicalDeviceProperties) + GUARD_SIZE];
925
926         const QueryMemberTableEntry physicalDevicePropertiesOffsetTable[] =
927         {
928                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, apiVersion),
929                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, driverVersion),
930                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, vendorID),
931                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, deviceID),
932                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, deviceType),
933                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, pipelineCacheUUID),
934                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimension1D),
935                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimension2D),
936                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimension3D),
937                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimensionCube),
938                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageArrayLayers),
939                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTexelBufferElements),
940                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxUniformBufferRange),
941                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxStorageBufferRange),
942                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPushConstantsSize),
943                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxMemoryAllocationCount),
944                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSamplerAllocationCount),
945                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.bufferImageGranularity),
946                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sparseAddressSpaceSize),
947                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxBoundDescriptorSets),
948                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorSamplers),
949                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorUniformBuffers),
950                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorStorageBuffers),
951                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorSampledImages),
952                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorStorageImages),
953                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorInputAttachments),
954                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageResources),
955                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetSamplers),
956                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetUniformBuffers),
957                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetUniformBuffersDynamic),
958                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetStorageBuffers),
959                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetStorageBuffersDynamic),
960                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetSampledImages),
961                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetStorageImages),
962                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetInputAttachments),
963                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputAttributes),
964                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputBindings),
965                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputAttributeOffset),
966                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputBindingStride),
967                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexOutputComponents),
968                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationGenerationLevel),
969                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationPatchSize),
970                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlPerVertexInputComponents),
971                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlPerVertexOutputComponents),
972                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlPerPatchOutputComponents),
973                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlTotalOutputComponents),
974                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationEvaluationInputComponents),
975                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationEvaluationOutputComponents),
976                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryShaderInvocations),
977                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryInputComponents),
978                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryOutputComponents),
979                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryOutputVertices),
980                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryTotalOutputComponents),
981                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentInputComponents),
982                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentOutputAttachments),
983                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentDualSrcAttachments),
984                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentCombinedOutputResources),
985                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeSharedMemorySize),
986                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeWorkGroupCount[3]),
987                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeWorkGroupInvocations),
988                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeWorkGroupSize[3]),
989                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.subPixelPrecisionBits),
990                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.subTexelPrecisionBits),
991                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.mipmapPrecisionBits),
992                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDrawIndexedIndexValue),
993                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDrawIndirectCount),
994                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSamplerLodBias),
995                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSamplerAnisotropy),
996                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxViewports),
997                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxViewportDimensions[2]),
998                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.viewportBoundsRange[2]),
999                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.viewportSubPixelBits),
1000                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minMemoryMapAlignment),
1001                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minTexelBufferOffsetAlignment),
1002                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minUniformBufferOffsetAlignment),
1003                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minStorageBufferOffsetAlignment),
1004                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minTexelOffset),
1005                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTexelOffset),
1006                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minTexelGatherOffset),
1007                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTexelGatherOffset),
1008                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minInterpolationOffset),
1009                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxInterpolationOffset),
1010                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.subPixelInterpolationOffsetBits),
1011                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFramebufferWidth),
1012                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFramebufferHeight),
1013                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFramebufferLayers),
1014                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferColorSampleCounts),
1015                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferDepthSampleCounts),
1016                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferStencilSampleCounts),
1017                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferNoAttachmentsSampleCounts),
1018                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxColorAttachments),
1019                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageColorSampleCounts),
1020                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageIntegerSampleCounts),
1021                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageDepthSampleCounts),
1022                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageStencilSampleCounts),
1023                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.storageImageSampleCounts),
1024                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSampleMaskWords),
1025                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.timestampComputeAndGraphics),
1026                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.timestampPeriod),
1027                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxClipDistances),
1028                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxCullDistances),
1029                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxCombinedClipAndCullDistances),
1030                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.discreteQueuePriorities),
1031                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.pointSizeRange[2]),
1032                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.lineWidthRange[2]),
1033                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.pointSizeGranularity),
1034                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.lineWidthGranularity),
1035                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.strictLines),
1036                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.standardSampleLocations),
1037                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.optimalBufferCopyOffsetAlignment),
1038                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.optimalBufferCopyRowPitchAlignment),
1039                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.nonCoherentAtomSize),
1040                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyStandard2DBlockShape),
1041                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyStandard2DMultisampleBlockShape),
1042                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyStandard3DBlockShape),
1043                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyAlignedMipSize),
1044                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyNonResidentStrict),
1045                 { 0, 0 }
1046         };
1047
1048         props = reinterpret_cast<VkPhysicalDeviceProperties*>(buffer);
1049         deMemset(props, GUARD_VALUE, sizeof(buffer));
1050
1051         context.getInstanceInterface().getPhysicalDeviceProperties(context.getPhysicalDevice(), props);
1052         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &features);
1053
1054         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
1055                 << TestLog::Message << *props << TestLog::EndMessage;
1056
1057         if (!validateFeatureLimits(props, &features, log))
1058                 return tcu::TestStatus::fail("deviceProperties - feature limits failed");
1059
1060         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
1061         {
1062                 if (buffer[ndx + sizeof(VkPhysicalDeviceProperties)] != GUARD_VALUE)
1063                 {
1064                         log << TestLog::Message << "deviceProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
1065                         return tcu::TestStatus::fail("deviceProperties buffer overflow");
1066                 }
1067         }
1068
1069         if (!validateInitComplete(context.getPhysicalDevice(), &InstanceInterface::getPhysicalDeviceProperties, context.getInstanceInterface(), physicalDevicePropertiesOffsetTable))
1070         {
1071                 log << TestLog::Message << "deviceProperties - VkPhysicalDeviceProperties not completely initialized" << TestLog::EndMessage;
1072                 return tcu::TestStatus::fail("deviceProperties incomplete initialization");
1073         }
1074
1075         // Check if deviceName string is properly terminated.
1076         if (deStrnlen(props->deviceName, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE) == VK_MAX_PHYSICAL_DEVICE_NAME_SIZE)
1077         {
1078                 log << TestLog::Message << "deviceProperties - VkPhysicalDeviceProperties deviceName not properly initialized" << TestLog::EndMessage;
1079                 return tcu::TestStatus::fail("deviceProperties incomplete initialization");
1080         }
1081
1082         {
1083                 const ApiVersion deviceVersion = unpackVersion(props->apiVersion);
1084                 const ApiVersion deqpVersion = unpackVersion(VK_API_VERSION);
1085
1086                 if (deviceVersion.majorNum != deqpVersion.majorNum)
1087                 {
1088                         log << TestLog::Message << "deviceProperties - API Major Version " << deviceVersion.majorNum << " is not valid" << TestLog::EndMessage;
1089                         return tcu::TestStatus::fail("deviceProperties apiVersion not valid");
1090                 }
1091
1092                 if (deviceVersion.minorNum > deqpVersion.minorNum)
1093                 {
1094                         log << TestLog::Message << "deviceProperties - API Minor Version " << deviceVersion.minorNum << " is not valid for this version of dEQP" << TestLog::EndMessage;
1095                         return tcu::TestStatus::fail("deviceProperties apiVersion not valid");
1096                 }
1097         }
1098
1099         return tcu::TestStatus::pass("DeviceProperites query succeeded");
1100 }
1101
1102 tcu::TestStatus deviceQueueFamilyProperties (Context& context)
1103 {
1104         TestLog&                                                                log                                     = context.getTestContext().getLog();
1105         const vector<VkQueueFamilyProperties>   queueProperties         = getPhysicalDeviceQueueFamilyProperties(context.getInstanceInterface(), context.getPhysicalDevice());
1106
1107         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage;
1108
1109         for (size_t queueNdx = 0; queueNdx < queueProperties.size(); queueNdx++)
1110                 log << TestLog::Message << queueNdx << ": " << queueProperties[queueNdx] << TestLog::EndMessage;
1111
1112         return tcu::TestStatus::pass("Querying queue properties succeeded");
1113 }
1114
1115 tcu::TestStatus deviceMemoryProperties (Context& context)
1116 {
1117         TestLog&                                                        log                     = context.getTestContext().getLog();
1118         VkPhysicalDeviceMemoryProperties*       memProps;
1119         deUint8                                                         buffer[sizeof(VkPhysicalDeviceMemoryProperties) + GUARD_SIZE];
1120
1121         memProps = reinterpret_cast<VkPhysicalDeviceMemoryProperties*>(buffer);
1122         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
1123
1124         context.getInstanceInterface().getPhysicalDeviceMemoryProperties(context.getPhysicalDevice(), memProps);
1125
1126         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
1127                 << TestLog::Message << *memProps << TestLog::EndMessage;
1128
1129         for (deInt32 ndx = 0; ndx < GUARD_SIZE; ndx++)
1130         {
1131                 if (buffer[ndx + sizeof(VkPhysicalDeviceMemoryProperties)] != GUARD_VALUE)
1132                 {
1133                         log << TestLog::Message << "deviceMemoryProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
1134                         return tcu::TestStatus::fail("deviceMemoryProperties buffer overflow");
1135                 }
1136         }
1137
1138         if (memProps->memoryHeapCount >= VK_MAX_MEMORY_HEAPS)
1139         {
1140                 log << TestLog::Message << "deviceMemoryProperties - HeapCount larger than " << (deUint32)VK_MAX_MEMORY_HEAPS << TestLog::EndMessage;
1141                 return tcu::TestStatus::fail("deviceMemoryProperties HeapCount too large");
1142         }
1143
1144         if (memProps->memoryHeapCount == 1)
1145         {
1146                 if ((memProps->memoryHeaps[0].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) == 0)
1147                 {
1148                         log << TestLog::Message << "deviceMemoryProperties - Single heap is not marked DEVICE_LOCAL" << TestLog::EndMessage;
1149                         return tcu::TestStatus::fail("deviceMemoryProperties invalid HeapFlags");
1150                 }
1151         }
1152
1153         const VkMemoryPropertyFlags validPropertyFlags[] =
1154         {
1155                 0,
1156                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
1157                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1158                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
1159                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1160                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1161                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
1162                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1163                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT
1164         };
1165
1166         const VkMemoryPropertyFlags requiredPropertyFlags[] =
1167         {
1168                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
1169         };
1170
1171         bool requiredFlagsFound[DE_LENGTH_OF_ARRAY(requiredPropertyFlags)];
1172         std::fill(DE_ARRAY_BEGIN(requiredFlagsFound), DE_ARRAY_END(requiredFlagsFound), false);
1173
1174         for (deUint32 memoryNdx = 0; memoryNdx < memProps->memoryTypeCount; memoryNdx++)
1175         {
1176                 bool validPropTypeFound = false;
1177
1178                 if (memProps->memoryTypes[memoryNdx].heapIndex >= memProps->memoryHeapCount)
1179                 {
1180                         log << TestLog::Message << "deviceMemoryProperties - heapIndex " << memProps->memoryTypes[memoryNdx].heapIndex << " larger than heapCount" << TestLog::EndMessage;
1181                         return tcu::TestStatus::fail("deviceMemoryProperties - invalid heapIndex");
1182                 }
1183
1184                 const VkMemoryPropertyFlags bitsToCheck = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT|VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT;
1185
1186                 for (const VkMemoryPropertyFlags* requiredFlagsIterator = DE_ARRAY_BEGIN(requiredPropertyFlags); requiredFlagsIterator != DE_ARRAY_END(requiredPropertyFlags); requiredFlagsIterator++)
1187                         if ((memProps->memoryTypes[memoryNdx].propertyFlags & *requiredFlagsIterator) == *requiredFlagsIterator)
1188                                 requiredFlagsFound[requiredFlagsIterator - DE_ARRAY_BEGIN(requiredPropertyFlags)] = true;
1189
1190                 if (de::contains(DE_ARRAY_BEGIN(validPropertyFlags), DE_ARRAY_END(validPropertyFlags), memProps->memoryTypes[memoryNdx].propertyFlags & bitsToCheck))
1191                         validPropTypeFound = true;
1192
1193                 if (!validPropTypeFound)
1194                 {
1195                         log << TestLog::Message << "deviceMemoryProperties - propertyFlags "
1196                                 << memProps->memoryTypes[memoryNdx].propertyFlags << " not valid" << TestLog::EndMessage;
1197                         return tcu::TestStatus::fail("deviceMemoryProperties propertyFlags not valid");
1198                 }
1199
1200                 if (memProps->memoryTypes[memoryNdx].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
1201                 {
1202                         if ((memProps->memoryHeaps[memProps->memoryTypes[memoryNdx].heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) == 0)
1203                         {
1204                                 log << TestLog::Message << "deviceMemoryProperties - DEVICE_LOCAL memory type references heap which is not DEVICE_LOCAL" << TestLog::EndMessage;
1205                                 return tcu::TestStatus::fail("deviceMemoryProperties inconsistent memoryType and HeapFlags");
1206                         }
1207                 }
1208                 else
1209                 {
1210                         if (memProps->memoryHeaps[memProps->memoryTypes[memoryNdx].heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
1211                         {
1212                                 log << TestLog::Message << "deviceMemoryProperties - non-DEVICE_LOCAL memory type references heap with is DEVICE_LOCAL" << TestLog::EndMessage;
1213                                 return tcu::TestStatus::fail("deviceMemoryProperties inconsistent memoryType and HeapFlags");
1214                         }
1215                 }
1216         }
1217
1218         bool* requiredFlagsFoundIterator = std::find(DE_ARRAY_BEGIN(requiredFlagsFound), DE_ARRAY_END(requiredFlagsFound), false);
1219         if (requiredFlagsFoundIterator != DE_ARRAY_END(requiredFlagsFound))
1220         {
1221                 DE_ASSERT(requiredFlagsFoundIterator - DE_ARRAY_BEGIN(requiredFlagsFound) <= DE_LENGTH_OF_ARRAY(requiredPropertyFlags));
1222                 log << TestLog::Message << "deviceMemoryProperties - required property flags "
1223                         << getMemoryPropertyFlagsStr(requiredPropertyFlags[requiredFlagsFoundIterator - DE_ARRAY_BEGIN(requiredFlagsFound)]) << " not found" << TestLog::EndMessage;
1224
1225                 return tcu::TestStatus::fail("deviceMemoryProperties propertyFlags not valid");
1226         }
1227
1228         return tcu::TestStatus::pass("Querying memory properties succeeded");
1229 }
1230
1231 // \todo [2016-01-22 pyry] Optimize by doing format -> flags mapping instead
1232
1233 VkFormatFeatureFlags getRequiredOptimalTilingFeatures (VkFormat format)
1234 {
1235         static const VkFormat s_requiredSampledImageBlitSrcFormats[] =
1236         {
1237                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1238                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1239                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1240                 VK_FORMAT_R8_UNORM,
1241                 VK_FORMAT_R8_SNORM,
1242                 VK_FORMAT_R8_UINT,
1243                 VK_FORMAT_R8_SINT,
1244                 VK_FORMAT_R8G8_UNORM,
1245                 VK_FORMAT_R8G8_SNORM,
1246                 VK_FORMAT_R8G8_UINT,
1247                 VK_FORMAT_R8G8_SINT,
1248                 VK_FORMAT_R8G8B8A8_UNORM,
1249                 VK_FORMAT_R8G8B8A8_SNORM,
1250                 VK_FORMAT_R8G8B8A8_UINT,
1251                 VK_FORMAT_R8G8B8A8_SINT,
1252                 VK_FORMAT_R8G8B8A8_SRGB,
1253                 VK_FORMAT_B8G8R8A8_UNORM,
1254                 VK_FORMAT_B8G8R8A8_SRGB,
1255                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1256                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1257                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1258                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1259                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1260                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1261                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1262                 VK_FORMAT_R16_UINT,
1263                 VK_FORMAT_R16_SINT,
1264                 VK_FORMAT_R16_SFLOAT,
1265                 VK_FORMAT_R16G16_UINT,
1266                 VK_FORMAT_R16G16_SINT,
1267                 VK_FORMAT_R16G16_SFLOAT,
1268                 VK_FORMAT_R16G16B16A16_UINT,
1269                 VK_FORMAT_R16G16B16A16_SINT,
1270                 VK_FORMAT_R16G16B16A16_SFLOAT,
1271                 VK_FORMAT_R32_UINT,
1272                 VK_FORMAT_R32_SINT,
1273                 VK_FORMAT_R32_SFLOAT,
1274                 VK_FORMAT_R32G32_UINT,
1275                 VK_FORMAT_R32G32_SINT,
1276                 VK_FORMAT_R32G32_SFLOAT,
1277                 VK_FORMAT_R32G32B32A32_UINT,
1278                 VK_FORMAT_R32G32B32A32_SINT,
1279                 VK_FORMAT_R32G32B32A32_SFLOAT,
1280                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1281                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1282                 VK_FORMAT_D16_UNORM,
1283                 VK_FORMAT_D32_SFLOAT
1284         };
1285         static const VkFormat s_requiredSampledImageFilterLinearFormats[] =
1286         {
1287                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1288                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1289                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1290                 VK_FORMAT_R8_UNORM,
1291                 VK_FORMAT_R8_SNORM,
1292                 VK_FORMAT_R8G8_UNORM,
1293                 VK_FORMAT_R8G8_SNORM,
1294                 VK_FORMAT_R8G8B8A8_UNORM,
1295                 VK_FORMAT_R8G8B8A8_SNORM,
1296                 VK_FORMAT_R8G8B8A8_SRGB,
1297                 VK_FORMAT_B8G8R8A8_UNORM,
1298                 VK_FORMAT_B8G8R8A8_SRGB,
1299                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1300                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1301                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1302                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1303                 VK_FORMAT_R16_SFLOAT,
1304                 VK_FORMAT_R16G16_SFLOAT,
1305                 VK_FORMAT_R16G16B16A16_SFLOAT,
1306                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1307                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1308         };
1309         static const VkFormat s_requiredStorageImageFormats[] =
1310         {
1311                 VK_FORMAT_R8G8B8A8_UNORM,
1312                 VK_FORMAT_R8G8B8A8_SNORM,
1313                 VK_FORMAT_R8G8B8A8_UINT,
1314                 VK_FORMAT_R8G8B8A8_SINT,
1315                 VK_FORMAT_R16G16B16A16_UINT,
1316                 VK_FORMAT_R16G16B16A16_SINT,
1317                 VK_FORMAT_R16G16B16A16_SFLOAT,
1318                 VK_FORMAT_R32_UINT,
1319                 VK_FORMAT_R32_SINT,
1320                 VK_FORMAT_R32_SFLOAT,
1321                 VK_FORMAT_R32G32_UINT,
1322                 VK_FORMAT_R32G32_SINT,
1323                 VK_FORMAT_R32G32_SFLOAT,
1324                 VK_FORMAT_R32G32B32A32_UINT,
1325                 VK_FORMAT_R32G32B32A32_SINT,
1326                 VK_FORMAT_R32G32B32A32_SFLOAT
1327         };
1328         static const VkFormat s_requiredStorageImageAtomicFormats[] =
1329         {
1330                 VK_FORMAT_R32_UINT,
1331                 VK_FORMAT_R32_SINT
1332         };
1333         static const VkFormat s_requiredColorAttachmentBlitDstFormats[] =
1334         {
1335                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1336                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1337                 VK_FORMAT_R8_UNORM,
1338                 VK_FORMAT_R8_UINT,
1339                 VK_FORMAT_R8_SINT,
1340                 VK_FORMAT_R8G8_UNORM,
1341                 VK_FORMAT_R8G8_UINT,
1342                 VK_FORMAT_R8G8_SINT,
1343                 VK_FORMAT_R8G8B8A8_UNORM,
1344                 VK_FORMAT_R8G8B8A8_UINT,
1345                 VK_FORMAT_R8G8B8A8_SINT,
1346                 VK_FORMAT_R8G8B8A8_SRGB,
1347                 VK_FORMAT_B8G8R8A8_UNORM,
1348                 VK_FORMAT_B8G8R8A8_SRGB,
1349                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1350                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1351                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1352                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1353                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1354                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1355                 VK_FORMAT_R16_UINT,
1356                 VK_FORMAT_R16_SINT,
1357                 VK_FORMAT_R16_SFLOAT,
1358                 VK_FORMAT_R16G16_UINT,
1359                 VK_FORMAT_R16G16_SINT,
1360                 VK_FORMAT_R16G16_SFLOAT,
1361                 VK_FORMAT_R16G16B16A16_UINT,
1362                 VK_FORMAT_R16G16B16A16_SINT,
1363                 VK_FORMAT_R16G16B16A16_SFLOAT,
1364                 VK_FORMAT_R32_UINT,
1365                 VK_FORMAT_R32_SINT,
1366                 VK_FORMAT_R32_SFLOAT,
1367                 VK_FORMAT_R32G32_UINT,
1368                 VK_FORMAT_R32G32_SINT,
1369                 VK_FORMAT_R32G32_SFLOAT,
1370                 VK_FORMAT_R32G32B32A32_UINT,
1371                 VK_FORMAT_R32G32B32A32_SINT,
1372                 VK_FORMAT_R32G32B32A32_SFLOAT
1373         };
1374         static const VkFormat s_requiredColorAttachmentBlendFormats[] =
1375         {
1376                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1377                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1378                 VK_FORMAT_R8_UNORM,
1379                 VK_FORMAT_R8G8_UNORM,
1380                 VK_FORMAT_R8G8B8A8_UNORM,
1381                 VK_FORMAT_R8G8B8A8_SRGB,
1382                 VK_FORMAT_B8G8R8A8_UNORM,
1383                 VK_FORMAT_B8G8R8A8_SRGB,
1384                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1385                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1386                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1387                 VK_FORMAT_R16_SFLOAT,
1388                 VK_FORMAT_R16G16_SFLOAT,
1389                 VK_FORMAT_R16G16B16A16_SFLOAT
1390         };
1391         static const VkFormat s_requiredDepthStencilAttachmentFormats[] =
1392         {
1393                 VK_FORMAT_D16_UNORM
1394         };
1395
1396         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
1397
1398         if (de::contains(DE_ARRAY_BEGIN(s_requiredSampledImageBlitSrcFormats), DE_ARRAY_END(s_requiredSampledImageBlitSrcFormats), format))
1399                 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT|VK_FORMAT_FEATURE_BLIT_SRC_BIT;
1400
1401         if (de::contains(DE_ARRAY_BEGIN(s_requiredSampledImageFilterLinearFormats), DE_ARRAY_END(s_requiredSampledImageFilterLinearFormats), format))
1402                 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
1403
1404         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageFormats), DE_ARRAY_END(s_requiredStorageImageFormats), format))
1405                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
1406
1407         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageAtomicFormats), DE_ARRAY_END(s_requiredStorageImageAtomicFormats), format))
1408                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
1409
1410         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlitDstFormats), DE_ARRAY_END(s_requiredColorAttachmentBlitDstFormats), format))
1411                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT|VK_FORMAT_FEATURE_BLIT_DST_BIT;
1412
1413         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlendFormats), DE_ARRAY_END(s_requiredColorAttachmentBlendFormats), format))
1414                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
1415
1416         if (de::contains(DE_ARRAY_BEGIN(s_requiredDepthStencilAttachmentFormats), DE_ARRAY_END(s_requiredDepthStencilAttachmentFormats), format))
1417                 flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
1418
1419         return flags;
1420 }
1421
1422 VkFormatFeatureFlags getRequiredBufferFeatures (VkFormat format)
1423 {
1424         static const VkFormat s_requiredVertexBufferFormats[] =
1425         {
1426                 VK_FORMAT_R8_UNORM,
1427                 VK_FORMAT_R8_SNORM,
1428                 VK_FORMAT_R8_UINT,
1429                 VK_FORMAT_R8_SINT,
1430                 VK_FORMAT_R8G8_UNORM,
1431                 VK_FORMAT_R8G8_SNORM,
1432                 VK_FORMAT_R8G8_UINT,
1433                 VK_FORMAT_R8G8_SINT,
1434                 VK_FORMAT_R8G8B8A8_UNORM,
1435                 VK_FORMAT_R8G8B8A8_SNORM,
1436                 VK_FORMAT_R8G8B8A8_UINT,
1437                 VK_FORMAT_R8G8B8A8_SINT,
1438                 VK_FORMAT_B8G8R8A8_UNORM,
1439                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1440                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1441                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1442                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1443                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1444                 VK_FORMAT_R16_UNORM,
1445                 VK_FORMAT_R16_SNORM,
1446                 VK_FORMAT_R16_UINT,
1447                 VK_FORMAT_R16_SINT,
1448                 VK_FORMAT_R16_SFLOAT,
1449                 VK_FORMAT_R16G16_UNORM,
1450                 VK_FORMAT_R16G16_SNORM,
1451                 VK_FORMAT_R16G16_UINT,
1452                 VK_FORMAT_R16G16_SINT,
1453                 VK_FORMAT_R16G16_SFLOAT,
1454                 VK_FORMAT_R16G16B16A16_UNORM,
1455                 VK_FORMAT_R16G16B16A16_SNORM,
1456                 VK_FORMAT_R16G16B16A16_UINT,
1457                 VK_FORMAT_R16G16B16A16_SINT,
1458                 VK_FORMAT_R16G16B16A16_SFLOAT,
1459                 VK_FORMAT_R32_UINT,
1460                 VK_FORMAT_R32_SINT,
1461                 VK_FORMAT_R32_SFLOAT,
1462                 VK_FORMAT_R32G32_UINT,
1463                 VK_FORMAT_R32G32_SINT,
1464                 VK_FORMAT_R32G32_SFLOAT,
1465                 VK_FORMAT_R32G32B32_UINT,
1466                 VK_FORMAT_R32G32B32_SINT,
1467                 VK_FORMAT_R32G32B32_SFLOAT,
1468                 VK_FORMAT_R32G32B32A32_UINT,
1469                 VK_FORMAT_R32G32B32A32_SINT,
1470                 VK_FORMAT_R32G32B32A32_SFLOAT
1471         };
1472         static const VkFormat s_requiredUniformTexelBufferFormats[] =
1473         {
1474                 VK_FORMAT_R8_UNORM,
1475                 VK_FORMAT_R8_SNORM,
1476                 VK_FORMAT_R8_UINT,
1477                 VK_FORMAT_R8_SINT,
1478                 VK_FORMAT_R8G8_UNORM,
1479                 VK_FORMAT_R8G8_SNORM,
1480                 VK_FORMAT_R8G8_UINT,
1481                 VK_FORMAT_R8G8_SINT,
1482                 VK_FORMAT_R8G8B8A8_UNORM,
1483                 VK_FORMAT_R8G8B8A8_SNORM,
1484                 VK_FORMAT_R8G8B8A8_UINT,
1485                 VK_FORMAT_R8G8B8A8_SINT,
1486                 VK_FORMAT_B8G8R8A8_UNORM,
1487                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1488                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1489                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1490                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1491                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1492                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1493                 VK_FORMAT_R16_UINT,
1494                 VK_FORMAT_R16_SINT,
1495                 VK_FORMAT_R16_SFLOAT,
1496                 VK_FORMAT_R16G16_UINT,
1497                 VK_FORMAT_R16G16_SINT,
1498                 VK_FORMAT_R16G16_SFLOAT,
1499                 VK_FORMAT_R16G16B16A16_UINT,
1500                 VK_FORMAT_R16G16B16A16_SINT,
1501                 VK_FORMAT_R16G16B16A16_SFLOAT,
1502                 VK_FORMAT_R32_UINT,
1503                 VK_FORMAT_R32_SINT,
1504                 VK_FORMAT_R32_SFLOAT,
1505                 VK_FORMAT_R32G32_UINT,
1506                 VK_FORMAT_R32G32_SINT,
1507                 VK_FORMAT_R32G32_SFLOAT,
1508                 VK_FORMAT_R32G32B32A32_UINT,
1509                 VK_FORMAT_R32G32B32A32_SINT,
1510                 VK_FORMAT_R32G32B32A32_SFLOAT,
1511                 VK_FORMAT_B10G11R11_UFLOAT_PACK32
1512         };
1513         static const VkFormat s_requiredStorageTexelBufferFormats[] =
1514         {
1515                 VK_FORMAT_R8G8B8A8_UNORM,
1516                 VK_FORMAT_R8G8B8A8_SNORM,
1517                 VK_FORMAT_R8G8B8A8_UINT,
1518                 VK_FORMAT_R8G8B8A8_SINT,
1519                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1520                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1521                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1522                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1523                 VK_FORMAT_R16G16B16A16_UINT,
1524                 VK_FORMAT_R16G16B16A16_SINT,
1525                 VK_FORMAT_R16G16B16A16_SFLOAT,
1526                 VK_FORMAT_R32_UINT,
1527                 VK_FORMAT_R32_SINT,
1528                 VK_FORMAT_R32_SFLOAT,
1529                 VK_FORMAT_R32G32_UINT,
1530                 VK_FORMAT_R32G32_SINT,
1531                 VK_FORMAT_R32G32_SFLOAT,
1532                 VK_FORMAT_R32G32B32A32_UINT,
1533                 VK_FORMAT_R32G32B32A32_SINT,
1534                 VK_FORMAT_R32G32B32A32_SFLOAT
1535         };
1536         static const VkFormat s_requiredStorageTexelBufferAtomicFormats[] =
1537         {
1538                 VK_FORMAT_R32_UINT,
1539                 VK_FORMAT_R32_SINT
1540         };
1541
1542         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
1543
1544         if (de::contains(DE_ARRAY_BEGIN(s_requiredVertexBufferFormats), DE_ARRAY_END(s_requiredVertexBufferFormats), format))
1545                 flags |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
1546
1547         if (de::contains(DE_ARRAY_BEGIN(s_requiredUniformTexelBufferFormats), DE_ARRAY_END(s_requiredUniformTexelBufferFormats), format))
1548                 flags |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
1549
1550         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferFormats), DE_ARRAY_END(s_requiredStorageTexelBufferFormats), format))
1551                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
1552
1553         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferAtomicFormats), DE_ARRAY_END(s_requiredStorageTexelBufferAtomicFormats), format))
1554                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
1555
1556         return flags;
1557 }
1558
1559 tcu::TestStatus formatProperties (Context& context, VkFormat format)
1560 {
1561         TestLog&                                        log                             = context.getTestContext().getLog();
1562         const VkFormatProperties        properties              = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
1563         bool                                            allOk                   = true;
1564
1565         const struct
1566         {
1567                 VkFormatFeatureFlags VkFormatProperties::*      field;
1568                 const char*                                                                     fieldName;
1569                 VkFormatFeatureFlags                                            requiredFeatures;
1570         } fields[] =
1571         {
1572                 { &VkFormatProperties::linearTilingFeatures,    "linearTilingFeatures",         (VkFormatFeatureFlags)0                                         },
1573                 { &VkFormatProperties::optimalTilingFeatures,   "optimalTilingFeatures",        getRequiredOptimalTilingFeatures(format)        },
1574                 { &VkFormatProperties::bufferFeatures,                  "buffeFeatures",                        getRequiredBufferFeatures(format)                       }
1575         };
1576
1577         log << TestLog::Message << properties << TestLog::EndMessage;
1578
1579         for (int fieldNdx = 0; fieldNdx < DE_LENGTH_OF_ARRAY(fields); fieldNdx++)
1580         {
1581                 const char* const                               fieldName       = fields[fieldNdx].fieldName;
1582                 const VkFormatFeatureFlags              supported       = properties.*fields[fieldNdx].field;
1583                 const VkFormatFeatureFlags              required        = fields[fieldNdx].requiredFeatures;
1584
1585                 if ((supported & required) != required)
1586                 {
1587                         log << TestLog::Message << "ERROR in " << fieldName << ":\n"
1588                                                                     << "  required: " << getFormatFeatureFlagsStr(required) << "\n  "
1589                                                                         << "  missing: " << getFormatFeatureFlagsStr(~supported & required)
1590                                 << TestLog::EndMessage;
1591                         allOk = false;
1592                 }
1593         }
1594
1595         if (allOk)
1596                 return tcu::TestStatus::pass("Query and validation passed");
1597         else
1598                 return tcu::TestStatus::fail("Required features not supported");
1599 }
1600
1601 bool optimalTilingFeaturesSupported (Context& context, VkFormat format, VkFormatFeatureFlags features)
1602 {
1603         const VkFormatProperties        properties      = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
1604
1605         return (properties.optimalTilingFeatures & features) == features;
1606 }
1607
1608 bool optimalTilingFeaturesSupportedForAll (Context& context, const VkFormat* begin, const VkFormat* end, VkFormatFeatureFlags features)
1609 {
1610         for (const VkFormat* cur = begin; cur != end; ++cur)
1611         {
1612                 if (!optimalTilingFeaturesSupported(context, *cur, features))
1613                         return false;
1614         }
1615
1616         return true;
1617 }
1618
1619 tcu::TestStatus testDepthStencilSupported (Context& context)
1620 {
1621         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
1622                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1623                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_X8_D24_UNORM_PACK32 or VK_FORMAT_D32_SFLOAT");
1624
1625         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
1626                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1627                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT");
1628
1629         return tcu::TestStatus::pass("Required depth/stencil formats supported");
1630 }
1631
1632 tcu::TestStatus testCompressedFormatsSupported (Context& context)
1633 {
1634         static const VkFormat s_allBcFormats[] =
1635         {
1636                 VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1637                 VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1638                 VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1639                 VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1640                 VK_FORMAT_BC2_UNORM_BLOCK,
1641                 VK_FORMAT_BC2_SRGB_BLOCK,
1642                 VK_FORMAT_BC3_UNORM_BLOCK,
1643                 VK_FORMAT_BC3_SRGB_BLOCK,
1644                 VK_FORMAT_BC4_UNORM_BLOCK,
1645                 VK_FORMAT_BC4_SNORM_BLOCK,
1646                 VK_FORMAT_BC5_UNORM_BLOCK,
1647                 VK_FORMAT_BC5_SNORM_BLOCK,
1648                 VK_FORMAT_BC6H_UFLOAT_BLOCK,
1649                 VK_FORMAT_BC6H_SFLOAT_BLOCK,
1650                 VK_FORMAT_BC7_UNORM_BLOCK,
1651                 VK_FORMAT_BC7_SRGB_BLOCK,
1652         };
1653         static const VkFormat s_allEtc2Formats[] =
1654         {
1655                 VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
1656                 VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
1657                 VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
1658                 VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
1659                 VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
1660                 VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
1661                 VK_FORMAT_EAC_R11_UNORM_BLOCK,
1662                 VK_FORMAT_EAC_R11_SNORM_BLOCK,
1663                 VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
1664                 VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
1665         };
1666         static const VkFormat s_allAstcLdrFormats[] =
1667         {
1668                 VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
1669                 VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
1670                 VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
1671                 VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
1672                 VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
1673                 VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
1674                 VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
1675                 VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
1676                 VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
1677                 VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
1678                 VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
1679                 VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
1680                 VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
1681                 VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
1682                 VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
1683                 VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
1684                 VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
1685                 VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
1686                 VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
1687                 VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
1688                 VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
1689                 VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
1690                 VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
1691                 VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
1692                 VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
1693                 VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
1694                 VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
1695                 VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
1696         };
1697
1698         static const struct
1699         {
1700                 const char*                                                                     setName;
1701                 const char*                                                                     featureName;
1702                 const VkBool32 VkPhysicalDeviceFeatures::*      feature;
1703                 const VkFormat*                                                         formatsBegin;
1704                 const VkFormat*                                                         formatsEnd;
1705         } s_compressedFormatSets[] =
1706         {
1707                 { "BC",                 "textureCompressionBC",                 &VkPhysicalDeviceFeatures::textureCompressionBC,                DE_ARRAY_BEGIN(s_allBcFormats),                 DE_ARRAY_END(s_allBcFormats)            },
1708                 { "ETC2",               "textureCompressionETC2",               &VkPhysicalDeviceFeatures::textureCompressionETC2,              DE_ARRAY_BEGIN(s_allEtc2Formats),               DE_ARRAY_END(s_allEtc2Formats)          },
1709                 { "ASTC LDR",   "textureCompressionASTC_LDR",   &VkPhysicalDeviceFeatures::textureCompressionASTC_LDR,  DE_ARRAY_BEGIN(s_allAstcLdrFormats),    DE_ARRAY_END(s_allAstcLdrFormats)       },
1710         };
1711
1712         TestLog&                                                log                                     = context.getTestContext().getLog();
1713         const VkPhysicalDeviceFeatures& features                        = context.getDeviceFeatures();
1714         int                                                             numSupportedSets        = 0;
1715         int                                                             numErrors                       = 0;
1716         int                                                             numWarnings                     = 0;
1717
1718         for (int setNdx = 0; setNdx < DE_LENGTH_OF_ARRAY(s_compressedFormatSets); ++setNdx)
1719         {
1720                 const char* const       setName                 = s_compressedFormatSets[setNdx].setName;
1721                 const char* const       featureName             = s_compressedFormatSets[setNdx].featureName;
1722                 const bool                      featureBitSet   = features.*s_compressedFormatSets[setNdx].feature == VK_TRUE;
1723                 const bool                      allSupported    = optimalTilingFeaturesSupportedForAll(context,
1724                                                                                                                                                                    s_compressedFormatSets[setNdx].formatsBegin,
1725                                                                                                                                                                    s_compressedFormatSets[setNdx].formatsEnd,
1726                                                                                                                                                                    VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
1727
1728                 if (featureBitSet && !allSupported)
1729                 {
1730                         log << TestLog::Message << "ERROR: " << featureName << " = VK_TRUE but " << setName << " formats not supported" << TestLog::EndMessage;
1731                         numErrors += 1;
1732                 }
1733                 else if (allSupported && !featureBitSet)
1734                 {
1735                         log << TestLog::Message << "WARNING: " << setName << " formats supported but " << featureName << " = VK_FALSE" << TestLog::EndMessage;
1736                         numWarnings += 1;
1737                 }
1738
1739                 if (featureBitSet)
1740                 {
1741                         log << TestLog::Message << "All " << setName << " formats are supported" << TestLog::EndMessage;
1742                         numSupportedSets += 1;
1743                 }
1744                 else
1745                         log << TestLog::Message << setName << " formats are not supported" << TestLog::EndMessage;
1746         }
1747
1748         if (numSupportedSets == 0)
1749         {
1750                 log << TestLog::Message << "No compressed format sets supported" << TestLog::EndMessage;
1751                 numErrors += 1;
1752         }
1753
1754         if (numErrors > 0)
1755                 return tcu::TestStatus::fail("Compressed format support not valid");
1756         else if (numWarnings > 0)
1757                 return tcu::TestStatus(QP_TEST_RESULT_QUALITY_WARNING, "Found inconsistencies in compressed format support");
1758         else
1759                 return tcu::TestStatus::pass("Compressed texture format support is valid");
1760 }
1761
1762 void createFormatTests (tcu::TestCaseGroup* testGroup)
1763 {
1764         DE_STATIC_ASSERT(VK_FORMAT_UNDEFINED == 0);
1765
1766         for (deUint32 formatNdx = VK_FORMAT_UNDEFINED+1; formatNdx < VK_CORE_FORMAT_LAST; ++formatNdx)
1767         {
1768                 const VkFormat          format                  = (VkFormat)formatNdx;
1769                 const char* const       enumName                = getFormatName(format);
1770                 const string            caseName                = de::toLower(string(enumName).substr(10));
1771
1772                 addFunctionCase(testGroup, caseName, enumName, formatProperties, format);
1773         }
1774
1775         addFunctionCase(testGroup, "depth_stencil",                     "",     testDepthStencilSupported);
1776         addFunctionCase(testGroup, "compressed_formats",        "",     testCompressedFormatsSupported);
1777 }
1778
1779 VkImageUsageFlags getValidImageUsageFlags (const VkFormatFeatureFlags supportedFeatures, const bool useKhrMaintenance1Semantics)
1780 {
1781         VkImageUsageFlags       flags   = (VkImageUsageFlags)0;
1782
1783         if (useKhrMaintenance1Semantics)
1784         {
1785                 if ((supportedFeatures & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR) != 0)
1786                         flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1787
1788                 if ((supportedFeatures & VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR) != 0)
1789                         flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1790         }
1791         else
1792         {
1793                 // If format is supported at all, it must be valid transfer src+dst
1794                 if (supportedFeatures != 0)
1795                         flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1796         }
1797
1798         if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
1799                 flags |= VK_IMAGE_USAGE_SAMPLED_BIT;
1800
1801         if ((supportedFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) != 0)
1802                 flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
1803
1804         if ((supportedFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)
1805                 flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1806
1807         if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
1808                 flags |= VK_IMAGE_USAGE_STORAGE_BIT;
1809
1810         return flags;
1811 }
1812
1813 bool isValidImageUsageFlagCombination (VkImageUsageFlags usage)
1814 {
1815         if ((usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0)
1816         {
1817                 const VkImageUsageFlags         allowedFlags    = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
1818                                                                                                         | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
1819                                                                                                         | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
1820                                                                                                         | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
1821
1822                 // Only *_ATTACHMENT_BIT flags can be combined with TRANSIENT_ATTACHMENT_BIT
1823                 if ((usage & ~allowedFlags) != 0)
1824                         return false;
1825
1826                 // TRANSIENT_ATTACHMENT_BIT is not valid without COLOR_ or DEPTH_STENCIL_ATTACHMENT_BIT
1827                 if ((usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) == 0)
1828                         return false;
1829         }
1830
1831         return usage != 0;
1832 }
1833
1834 VkImageCreateFlags getValidImageCreateFlags (const VkPhysicalDeviceFeatures& deviceFeatures, VkFormat, VkFormatFeatureFlags, VkImageType type, VkImageUsageFlags usage)
1835 {
1836         VkImageCreateFlags      flags   = (VkImageCreateFlags)0;
1837
1838         if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
1839         {
1840                 flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
1841
1842                 if (type == VK_IMAGE_TYPE_2D)
1843                         flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
1844         }
1845
1846         if ((usage & (VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT)) != 0 &&
1847                 (usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)
1848         {
1849                 if (deviceFeatures.sparseBinding)
1850                         flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT|VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
1851
1852                 if (deviceFeatures.sparseResidencyAliased)
1853                         flags |= VK_IMAGE_CREATE_SPARSE_ALIASED_BIT;
1854         }
1855
1856         return flags;
1857 }
1858
1859 bool isValidImageCreateFlagCombination (VkImageCreateFlags)
1860 {
1861         return true;
1862 }
1863
1864 bool isRequiredImageParameterCombination (const VkPhysicalDeviceFeatures&       deviceFeatures,
1865                                                                                   const VkFormat                                        format,
1866                                                                                   const VkFormatProperties&                     formatProperties,
1867                                                                                   const VkImageType                                     imageType,
1868                                                                                   const VkImageTiling                           imageTiling,
1869                                                                                   const VkImageUsageFlags                       usageFlags,
1870                                                                                   const VkImageCreateFlags                      createFlags)
1871 {
1872         DE_UNREF(deviceFeatures);
1873         DE_UNREF(formatProperties);
1874         DE_UNREF(createFlags);
1875
1876         // Linear images can have arbitrary limitations
1877         if (imageTiling == VK_IMAGE_TILING_LINEAR)
1878                 return false;
1879
1880         // Support for other usages for compressed formats is optional
1881         if (isCompressedFormat(format) &&
1882                 (usageFlags & ~(VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT)) != 0)
1883                 return false;
1884
1885         // Support for 1D, and sliced 3D compressed formats is optional
1886         if (isCompressedFormat(format) && (imageType == VK_IMAGE_TYPE_1D || imageType == VK_IMAGE_TYPE_3D))
1887                 return false;
1888
1889         DE_ASSERT(deviceFeatures.sparseBinding || (createFlags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT|VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)) == 0);
1890         DE_ASSERT(deviceFeatures.sparseResidencyAliased || (createFlags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) == 0);
1891
1892         return true;
1893 }
1894
1895 VkSampleCountFlags getRequiredOptimalTilingSampleCounts (const VkPhysicalDeviceLimits&  deviceLimits,
1896                                                                                                                  const VkFormat                                 format,
1897                                                                                                                  const VkImageUsageFlags                usageFlags)
1898 {
1899         if (!isCompressedFormat(format))
1900         {
1901                 const tcu::TextureFormat                tcuFormat               = mapVkFormat(format);
1902                 const bool                                              hasDepthComp    = (tcuFormat.order == tcu::TextureFormat::D || tcuFormat.order == tcu::TextureFormat::DS);
1903                 const bool                                              hasStencilComp  = (tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS);
1904                 const bool                                              isColorFormat   = !hasDepthComp && !hasStencilComp;
1905                 VkSampleCountFlags                              sampleCounts    = ~(VkSampleCountFlags)0;
1906
1907                 DE_ASSERT((hasDepthComp || hasStencilComp) != isColorFormat);
1908
1909                 if ((usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) != 0)
1910                         sampleCounts &= deviceLimits.storageImageSampleCounts;
1911
1912                 if ((usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
1913                 {
1914                         if (hasDepthComp)
1915                                 sampleCounts &= deviceLimits.sampledImageDepthSampleCounts;
1916
1917                         if (hasStencilComp)
1918                                 sampleCounts &= deviceLimits.sampledImageStencilSampleCounts;
1919
1920                         if (isColorFormat)
1921                         {
1922                                 const tcu::TextureChannelClass  chnClass        = tcu::getTextureChannelClass(tcuFormat.type);
1923
1924                                 if (chnClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ||
1925                                         chnClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
1926                                         sampleCounts &= deviceLimits.sampledImageIntegerSampleCounts;
1927                                 else
1928                                         sampleCounts &= deviceLimits.sampledImageColorSampleCounts;
1929                         }
1930                 }
1931
1932                 if ((usageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0)
1933                         sampleCounts &= deviceLimits.framebufferColorSampleCounts;
1934
1935                 if ((usageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)
1936                 {
1937                         if (hasDepthComp)
1938                                 sampleCounts &= deviceLimits.framebufferDepthSampleCounts;
1939
1940                         if (hasStencilComp)
1941                                 sampleCounts &= deviceLimits.framebufferStencilSampleCounts;
1942                 }
1943
1944                 // If there is no usage flag set that would have corresponding device limit,
1945                 // only VK_SAMPLE_COUNT_1_BIT is required.
1946                 if (sampleCounts == ~(VkSampleCountFlags)0)
1947                         sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
1948
1949                 return sampleCounts;
1950         }
1951         else
1952                 return VK_SAMPLE_COUNT_1_BIT;
1953 }
1954
1955 struct ImageFormatPropertyCase
1956 {
1957         typedef tcu::TestStatus (*Function) (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling);
1958
1959         Function                testFunction;
1960         VkFormat                format;
1961         VkImageType             imageType;
1962         VkImageTiling   tiling;
1963
1964         ImageFormatPropertyCase (Function testFunction_, VkFormat format_, VkImageType imageType_, VkImageTiling tiling_)
1965                 : testFunction  (testFunction_)
1966                 , format                (format_)
1967                 , imageType             (imageType_)
1968                 , tiling                (tiling_)
1969         {}
1970
1971         ImageFormatPropertyCase (void)
1972                 : testFunction  ((Function)DE_NULL)
1973                 , format                (VK_FORMAT_UNDEFINED)
1974                 , imageType             (VK_IMAGE_TYPE_LAST)
1975                 , tiling                (VK_IMAGE_TILING_LAST)
1976         {}
1977 };
1978
1979 tcu::TestStatus execImageFormatTest (Context& context, ImageFormatPropertyCase testCase)
1980 {
1981         return testCase.testFunction(context, testCase.format, testCase.imageType, testCase.tiling);
1982 }
1983
1984 void createImageFormatTypeTilingTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
1985 {
1986         DE_ASSERT(params.format == VK_FORMAT_UNDEFINED);
1987
1988         for (deUint32 formatNdx = VK_FORMAT_UNDEFINED+1; formatNdx < VK_CORE_FORMAT_LAST; ++formatNdx)
1989         {
1990                 const VkFormat          format                  = (VkFormat)formatNdx;
1991                 const char* const       enumName                = getFormatName(format);
1992                 const string            caseName                = de::toLower(string(enumName).substr(10));
1993
1994                 params.format = format;
1995
1996                 addFunctionCase(testGroup, caseName, enumName, execImageFormatTest, params);
1997         }
1998 }
1999
2000 void createImageFormatTypeTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
2001 {
2002         DE_ASSERT(params.tiling == VK_IMAGE_TILING_LAST);
2003
2004         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "optimal",     "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(params.testFunction, VK_FORMAT_UNDEFINED, params.imageType, VK_IMAGE_TILING_OPTIMAL)));
2005         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "linear",      "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(params.testFunction, VK_FORMAT_UNDEFINED, params.imageType, VK_IMAGE_TILING_LINEAR)));
2006 }
2007
2008 void createImageFormatTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase::Function testFunction)
2009 {
2010         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "1d", "", createImageFormatTypeTests, ImageFormatPropertyCase(testFunction, VK_FORMAT_UNDEFINED, VK_IMAGE_TYPE_1D, VK_IMAGE_TILING_LAST)));
2011         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "2d", "", createImageFormatTypeTests, ImageFormatPropertyCase(testFunction, VK_FORMAT_UNDEFINED, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_LAST)));
2012         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "3d", "", createImageFormatTypeTests, ImageFormatPropertyCase(testFunction, VK_FORMAT_UNDEFINED, VK_IMAGE_TYPE_3D, VK_IMAGE_TILING_LAST)));
2013 }
2014
2015 tcu::TestStatus imageFormatProperties (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling)
2016 {
2017         TestLog&                                                log                                     = context.getTestContext().getLog();
2018         const VkPhysicalDeviceFeatures& deviceFeatures          = context.getDeviceFeatures();
2019         const VkPhysicalDeviceLimits&   deviceLimits            = context.getDeviceProperties().limits;
2020         const VkFormatProperties                formatProperties        = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
2021         const bool                                              hasKhrMaintenance1      = isExtensionSupported(context.getDeviceExtensions(), "VK_KHR_maintenance1");
2022
2023         const VkFormatFeatureFlags              supportedFeatures       = tiling == VK_IMAGE_TILING_LINEAR ? formatProperties.linearTilingFeatures : formatProperties.optimalTilingFeatures;
2024         const VkImageUsageFlags                 usageFlagSet            = getValidImageUsageFlags(supportedFeatures, hasKhrMaintenance1);
2025
2026         tcu::ResultCollector                    results                         (log, "ERROR: ");
2027
2028         if (hasKhrMaintenance1 && (supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
2029         {
2030                 results.check((supportedFeatures & (VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR | VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR)) != 0,
2031                                           "A sampled image format must have VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR and VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR format feature flags set");
2032         }
2033
2034         for (VkImageUsageFlags curUsageFlags = 0; curUsageFlags <= usageFlagSet; curUsageFlags++)
2035         {
2036                 if ((curUsageFlags & ~usageFlagSet) != 0 ||
2037                         !isValidImageUsageFlagCombination(curUsageFlags))
2038                         continue;
2039
2040                 const VkImageCreateFlags        createFlagSet           = getValidImageCreateFlags(deviceFeatures, format, supportedFeatures, imageType, curUsageFlags);
2041
2042                 for (VkImageCreateFlags curCreateFlags = 0; curCreateFlags <= createFlagSet; curCreateFlags++)
2043                 {
2044                         if ((curCreateFlags & ~createFlagSet) != 0 ||
2045                                 !isValidImageCreateFlagCombination(curCreateFlags))
2046                                 continue;
2047
2048                         const bool                              isRequiredCombination   = isRequiredImageParameterCombination(deviceFeatures,
2049                                                                                                                                                                                                   format,
2050                                                                                                                                                                                                   formatProperties,
2051                                                                                                                                                                                                   imageType,
2052                                                                                                                                                                                                   tiling,
2053                                                                                                                                                                                                   curUsageFlags,
2054                                                                                                                                                                                                   curCreateFlags);
2055                         VkImageFormatProperties properties;
2056                         VkResult                                queryResult;
2057
2058                         log << TestLog::Message << "Testing " << getImageTypeStr(imageType) << ", "
2059                                                                         << getImageTilingStr(tiling) << ", "
2060                                                                         << getImageUsageFlagsStr(curUsageFlags) << ", "
2061                                                                         << getImageCreateFlagsStr(curCreateFlags)
2062                                 << TestLog::EndMessage;
2063
2064                         // Set return value to known garbage
2065                         deMemset(&properties, 0xcd, sizeof(properties));
2066
2067                         queryResult = context.getInstanceInterface().getPhysicalDeviceImageFormatProperties(context.getPhysicalDevice(),
2068                                                                                                                                                                                                 format,
2069                                                                                                                                                                                                 imageType,
2070                                                                                                                                                                                                 tiling,
2071                                                                                                                                                                                                 curUsageFlags,
2072                                                                                                                                                                                                 curCreateFlags,
2073                                                                                                                                                                                                 &properties);
2074
2075                         if (queryResult == VK_SUCCESS)
2076                         {
2077                                 const deUint32  fullMipPyramidSize      = de::max(de::max(deLog2Ceil32(properties.maxExtent.width),
2078                                                                                                                                           deLog2Ceil32(properties.maxExtent.height)),
2079                                                                                                                           deLog2Ceil32(properties.maxExtent.depth)) + 1;
2080
2081                                 log << TestLog::Message << properties << "\n" << TestLog::EndMessage;
2082
2083                                 results.check(imageType != VK_IMAGE_TYPE_1D || (properties.maxExtent.width >= 1 && properties.maxExtent.height == 1 && properties.maxExtent.depth == 1), "Invalid dimensions for 1D image");
2084                                 results.check(imageType != VK_IMAGE_TYPE_2D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth == 1), "Invalid dimensions for 2D image");
2085                                 results.check(imageType != VK_IMAGE_TYPE_3D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth >= 1), "Invalid dimensions for 3D image");
2086                                 results.check(imageType != VK_IMAGE_TYPE_3D || properties.maxArrayLayers == 1, "Invalid maxArrayLayers for 3D image");
2087
2088                                 if (tiling == VK_IMAGE_TILING_OPTIMAL && imageType == VK_IMAGE_TYPE_2D && !(curCreateFlags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
2089                                          ((supportedFeatures & (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)) ||
2090                                          ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) && deviceFeatures.shaderStorageImageMultisample)))
2091                                 {
2092                                         const VkSampleCountFlags        requiredSampleCounts    = getRequiredOptimalTilingSampleCounts(deviceLimits, format, curUsageFlags);
2093                                         results.check((properties.sampleCounts & requiredSampleCounts) == requiredSampleCounts, "Required sample counts not supported");
2094                                 }
2095                                 else
2096                                         results.check(properties.sampleCounts == VK_SAMPLE_COUNT_1_BIT, "sampleCounts != VK_SAMPLE_COUNT_1_BIT");
2097
2098                                 if (isRequiredCombination)
2099                                 {
2100                                         results.check(imageType != VK_IMAGE_TYPE_1D || (properties.maxExtent.width      >= deviceLimits.maxImageDimension1D),
2101                                                                   "Reported dimensions smaller than device limits");
2102                                         results.check(imageType != VK_IMAGE_TYPE_2D || (properties.maxExtent.width      >= deviceLimits.maxImageDimension2D &&
2103                                                                                                                                         properties.maxExtent.height     >= deviceLimits.maxImageDimension2D),
2104                                                                   "Reported dimensions smaller than device limits");
2105                                         results.check(imageType != VK_IMAGE_TYPE_3D || (properties.maxExtent.width      >= deviceLimits.maxImageDimension3D &&
2106                                                                                                                                         properties.maxExtent.height     >= deviceLimits.maxImageDimension3D &&
2107                                                                                                                                         properties.maxExtent.depth      >= deviceLimits.maxImageDimension3D),
2108                                                                   "Reported dimensions smaller than device limits");
2109                                         results.check(properties.maxMipLevels == fullMipPyramidSize, "maxMipLevels is not full mip pyramid size");
2110                                         results.check(imageType == VK_IMAGE_TYPE_3D || properties.maxArrayLayers >= deviceLimits.maxImageArrayLayers,
2111                                                                   "maxArrayLayers smaller than device limits");
2112                                 }
2113                                 else
2114                                 {
2115                                         results.check(properties.maxMipLevels == 1 || properties.maxMipLevels == fullMipPyramidSize, "Invalid mip pyramid size");
2116                                         results.check(properties.maxArrayLayers >= 1, "Invalid maxArrayLayers");
2117                                 }
2118
2119                                 results.check(properties.maxResourceSize >= (VkDeviceSize)MINIMUM_REQUIRED_IMAGE_RESOURCE_SIZE,
2120                                                           "maxResourceSize smaller than minimum required size");
2121                         }
2122                         else if (queryResult == VK_ERROR_FORMAT_NOT_SUPPORTED)
2123                         {
2124                                 log << TestLog::Message << "Got VK_ERROR_FORMAT_NOT_SUPPORTED" << TestLog::EndMessage;
2125
2126                                 if (isRequiredCombination)
2127                                         results.fail("VK_ERROR_FORMAT_NOT_SUPPORTED returned for required image parameter combination");
2128
2129                                 // Specification requires that all fields are set to 0
2130                                 results.check(properties.maxExtent.width        == 0, "maxExtent.width != 0");
2131                                 results.check(properties.maxExtent.height       == 0, "maxExtent.height != 0");
2132                                 results.check(properties.maxExtent.depth        == 0, "maxExtent.depth != 0");
2133                                 results.check(properties.maxMipLevels           == 0, "maxMipLevels != 0");
2134                                 results.check(properties.maxArrayLayers         == 0, "maxArrayLayers != 0");
2135                                 results.check(properties.sampleCounts           == 0, "sampleCounts != 0");
2136                                 results.check(properties.maxResourceSize        == 0, "maxResourceSize != 0");
2137                         }
2138                         else
2139                         {
2140                                 results.fail("Got unexpected error" + de::toString(queryResult));
2141                         }
2142                 }
2143         }
2144
2145         return tcu::TestStatus(results.getResult(), results.getMessage());
2146 }
2147
2148 // VK_KHR_get_physical_device_properties2
2149
2150 Move<VkInstance> createInstanceWithExtension (const PlatformInterface& vkp, const char* extensionName)
2151 {
2152         const vector<VkExtensionProperties>     instanceExts    = enumerateInstanceExtensionProperties(vkp, DE_NULL);
2153         vector<string>                                          enabledExts;
2154
2155         if (!isExtensionSupported(instanceExts, RequiredExtension(extensionName)))
2156                 TCU_THROW(NotSupportedError, (string(extensionName) + " is not supported").c_str());
2157
2158         enabledExts.push_back(extensionName);
2159
2160         return createDefaultInstance(vkp, vector<string>() /* layers */, enabledExts);
2161 }
2162
2163 tcu::TestStatus deviceFeatures2 (Context& context)
2164 {
2165         const PlatformInterface&                vkp                     = context.getPlatformInterface();
2166         const Unique<VkInstance>                instance        (createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
2167         const InstanceDriver                    vki                     (vkp, *instance);
2168         const vector<VkPhysicalDevice>  devices         = enumeratePhysicalDevices(vki, *instance);
2169
2170         for (size_t deviceNdx = 0; deviceNdx < devices.size(); ++deviceNdx)
2171         {
2172                 VkPhysicalDeviceFeatures                coreFeatures;
2173                 VkPhysicalDeviceFeatures2KHR    extFeatures;
2174
2175                 deMemset(&coreFeatures, 0xcd, sizeof(coreFeatures));
2176                 deMemset(&extFeatures.features, 0xcd, sizeof(extFeatures.features));
2177
2178                 extFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
2179                 extFeatures.pNext = DE_NULL;
2180
2181                 vki.getPhysicalDeviceFeatures(devices[deviceNdx], &coreFeatures);
2182                 vki.getPhysicalDeviceFeatures2KHR(devices[deviceNdx], &extFeatures);
2183
2184                 TCU_CHECK(extFeatures.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR);
2185                 TCU_CHECK(extFeatures.pNext == DE_NULL);
2186
2187                 if (deMemCmp(&coreFeatures, &extFeatures.features, sizeof(VkPhysicalDeviceFeatures)) != 0)
2188                         TCU_FAIL("Mismatch between features reported by vkGetPhysicalDeviceFeatures and vkGetPhysicalDeviceFeatures2KHR");
2189         }
2190
2191         return tcu::TestStatus::pass("Querying device features succeeded");
2192 }
2193
2194 tcu::TestStatus deviceProperties2 (Context& context)
2195 {
2196         const PlatformInterface&                vkp                     = context.getPlatformInterface();
2197         const Unique<VkInstance>                instance        (createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
2198         const InstanceDriver                    vki                     (vkp, *instance);
2199         const vector<VkPhysicalDevice>  devices         = enumeratePhysicalDevices(vki, *instance);
2200
2201         for (size_t deviceNdx = 0; deviceNdx < devices.size(); ++deviceNdx)
2202         {
2203                 VkPhysicalDeviceProperties              coreProperties;
2204                 VkPhysicalDeviceProperties2KHR  extProperties;
2205
2206                 deMemset(&coreProperties, 0xcd, sizeof(VkPhysicalDeviceProperties));
2207                 deMemset(&extProperties, 0xcd, sizeof(VkPhysicalDeviceProperties2KHR));
2208
2209                 extProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
2210                 extProperties.pNext = DE_NULL;
2211
2212                 vki.getPhysicalDeviceProperties(devices[deviceNdx], &coreProperties);
2213                 vki.getPhysicalDeviceProperties2KHR(devices[deviceNdx], &extProperties);
2214
2215                 TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR);
2216                 TCU_CHECK(extProperties.pNext == DE_NULL);
2217
2218                 if (deMemCmp(&coreProperties, &extProperties.properties, sizeof(VkPhysicalDeviceProperties)) != 0)
2219                         TCU_FAIL("Mismatch between properties reported by vkGetPhysicalDeviceProperties and vkGetPhysicalDeviceProperties2KHR");
2220         }
2221
2222         return tcu::TestStatus::pass("Querying device properties succeeded");
2223 }
2224
2225 tcu::TestStatus deviceFormatProperties2 (Context& context)
2226 {
2227         const PlatformInterface&                vkp                     = context.getPlatformInterface();
2228         const Unique<VkInstance>                instance        (createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
2229         const InstanceDriver                    vki                     (vkp, *instance);
2230         const vector<VkPhysicalDevice>  devices         = enumeratePhysicalDevices(vki, *instance);
2231
2232         for (size_t deviceNdx = 0; deviceNdx < devices.size(); ++deviceNdx)
2233         {
2234                 const VkPhysicalDevice  physicalDevice  = devices[deviceNdx];
2235
2236                 for (int formatNdx = 0; formatNdx < VK_CORE_FORMAT_LAST; ++formatNdx)
2237                 {
2238                         const VkFormat                  format                  = (VkFormat)formatNdx;
2239                         VkFormatProperties              coreProperties;
2240                         VkFormatProperties2KHR  extProperties;
2241
2242                         deMemset(&coreProperties, 0xcd, sizeof(VkFormatProperties));
2243                         deMemset(&extProperties, 0xcd, sizeof(VkFormatProperties2KHR));
2244
2245                         extProperties.sType     = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR;
2246                         extProperties.pNext = DE_NULL;
2247
2248                         vki.getPhysicalDeviceFormatProperties(physicalDevice, format, &coreProperties);
2249                         vki.getPhysicalDeviceFormatProperties2KHR(physicalDevice, format, &extProperties);
2250
2251                         TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR);
2252                         TCU_CHECK(extProperties.pNext == DE_NULL);
2253
2254                 if (deMemCmp(&coreProperties, &extProperties.formatProperties, sizeof(VkFormatProperties)) != 0)
2255                         TCU_FAIL("Mismatch between format properties reported by vkGetPhysicalDeviceFormatProperties and vkGetPhysicalDeviceFormatProperties2KHR");
2256                 }
2257         }
2258
2259         return tcu::TestStatus::pass("Querying device format properties succeeded");
2260 }
2261
2262 tcu::TestStatus deviceQueueFamilyProperties2 (Context& context)
2263 {
2264         const PlatformInterface&                vkp                     = context.getPlatformInterface();
2265         const Unique<VkInstance>                instance        (createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
2266         const InstanceDriver                    vki                     (vkp, *instance);
2267         const vector<VkPhysicalDevice>  devices         = enumeratePhysicalDevices(vki, *instance);
2268
2269         for (size_t deviceNdx = 0; deviceNdx < devices.size(); ++deviceNdx)
2270         {
2271                 const VkPhysicalDevice  physicalDevice                  = devices[deviceNdx];
2272                 deUint32                                numCoreQueueFamilies    = ~0u;
2273                 deUint32                                numExtQueueFamilies             = ~0u;
2274
2275                 vki.getPhysicalDeviceQueueFamilyProperties(physicalDevice, &numCoreQueueFamilies, DE_NULL);
2276                 vki.getPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, &numExtQueueFamilies, DE_NULL);
2277
2278                 TCU_CHECK_MSG(numCoreQueueFamilies == numExtQueueFamilies, "Different number of queue family properties reported");
2279                 TCU_CHECK(numCoreQueueFamilies > 0);
2280
2281                 {
2282                         std::vector<VkQueueFamilyProperties>            coreProperties  (numCoreQueueFamilies);
2283                         std::vector<VkQueueFamilyProperties2KHR>        extProperties   (numExtQueueFamilies);
2284
2285                         deMemset(&coreProperties[0], 0xcd, sizeof(VkQueueFamilyProperties)*numCoreQueueFamilies);
2286                         deMemset(&extProperties[0], 0xcd, sizeof(VkQueueFamilyProperties2KHR)*numExtQueueFamilies);
2287
2288                         for (size_t ndx = 0; ndx < extProperties.size(); ++ndx)
2289                         {
2290                                 extProperties[ndx].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR;
2291                                 extProperties[ndx].pNext = DE_NULL;
2292                         }
2293
2294                         vki.getPhysicalDeviceQueueFamilyProperties(physicalDevice, &numCoreQueueFamilies, &coreProperties[0]);
2295                         vki.getPhysicalDeviceQueueFamilyProperties2KHR(physicalDevice, &numExtQueueFamilies, &extProperties[0]);
2296
2297                         TCU_CHECK((size_t)numCoreQueueFamilies == coreProperties.size());
2298                         TCU_CHECK((size_t)numExtQueueFamilies == extProperties.size());
2299                         DE_ASSERT(numCoreQueueFamilies == numExtQueueFamilies);
2300
2301                         for (size_t ndx = 0; ndx < extProperties.size(); ++ndx)
2302                         {
2303                                 TCU_CHECK(extProperties[ndx].sType == VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR);
2304                                 TCU_CHECK(extProperties[ndx].pNext == DE_NULL);
2305
2306                                 if (deMemCmp(&coreProperties[ndx], &extProperties[ndx].queueFamilyProperties, sizeof(VkQueueFamilyProperties)) != 0)
2307                                         TCU_FAIL("Mismatch between format properties reported by vkGetPhysicalDeviceQueueFamilyProperties and vkGetPhysicalDeviceQueueFamilyProperties2KHR");
2308                         }
2309                 }
2310         }
2311
2312         return tcu::TestStatus::pass("Querying device queue family properties succeeded");
2313 }
2314
2315 tcu::TestStatus deviceMemoryProperties2 (Context& context)
2316 {
2317         const PlatformInterface&                vkp                     = context.getPlatformInterface();
2318         const Unique<VkInstance>                instance        (createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
2319         const InstanceDriver                    vki                     (vkp, *instance);
2320         const vector<VkPhysicalDevice>  devices         = enumeratePhysicalDevices(vki, *instance);
2321
2322         for (size_t deviceNdx = 0; deviceNdx < devices.size(); ++deviceNdx)
2323         {
2324                 VkPhysicalDeviceMemoryProperties                coreProperties;
2325                 VkPhysicalDeviceMemoryProperties2KHR    extProperties;
2326
2327                 deMemset(&coreProperties, 0xcd, sizeof(VkPhysicalDeviceMemoryProperties));
2328                 deMemset(&extProperties, 0xcd, sizeof(VkPhysicalDeviceMemoryProperties2KHR));
2329
2330                 extProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR;
2331                 extProperties.pNext = DE_NULL;
2332
2333                 vki.getPhysicalDeviceMemoryProperties(devices[deviceNdx], &coreProperties);
2334                 vki.getPhysicalDeviceMemoryProperties2KHR(devices[deviceNdx], &extProperties);
2335
2336                 TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR);
2337                 TCU_CHECK(extProperties.pNext == DE_NULL);
2338
2339                 if (deMemCmp(&coreProperties, &extProperties.memoryProperties, sizeof(VkPhysicalDeviceMemoryProperties)) != 0)
2340                         TCU_FAIL("Mismatch between properties reported by vkGetPhysicalDeviceMemoryProperties and vkGetPhysicalDeviceMemoryProperties2KHR");
2341         }
2342
2343         return tcu::TestStatus::pass("Querying device memory properties succeeded");
2344 }
2345
2346 tcu::TestStatus imageFormatProperties2 (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling)
2347 {
2348         TestLog&                                                log                             = context.getTestContext().getLog();
2349
2350         const PlatformInterface&                vkp                             = context.getPlatformInterface();
2351         const Unique<VkInstance>                instance                (createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
2352         const InstanceDriver                    vki                             (vkp, *instance);
2353         const vector<VkPhysicalDevice>  devices                 = enumeratePhysicalDevices(vki, *instance);
2354
2355         const VkImageUsageFlags                 allUsageFlags   = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
2356                                                                                                         | VK_IMAGE_USAGE_TRANSFER_DST_BIT
2357                                                                                                         | VK_IMAGE_USAGE_SAMPLED_BIT
2358                                                                                                         | VK_IMAGE_USAGE_STORAGE_BIT
2359                                                                                                         | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
2360                                                                                                         | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
2361                                                                                                         | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
2362                                                                                                         | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
2363         const VkImageCreateFlags                allCreateFlags  = VK_IMAGE_CREATE_SPARSE_BINDING_BIT
2364                                                                                                         | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT
2365                                                                                                         | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT
2366                                                                                                         | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
2367                                                                                                         | VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
2368
2369         for (size_t deviceNdx = 0; deviceNdx < devices.size(); ++deviceNdx)
2370         {
2371                 const VkPhysicalDevice  physicalDevice  = devices[deviceNdx];
2372
2373                 for (VkImageUsageFlags curUsageFlags = 0; curUsageFlags <= allUsageFlags; curUsageFlags++)
2374                 {
2375                         for (VkImageCreateFlags curCreateFlags = 0; curCreateFlags <= allCreateFlags; curCreateFlags++)
2376                         {
2377                                 const VkPhysicalDeviceImageFormatInfo2KHR       imageFormatInfo =
2378                                 {
2379                                         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2_KHR,
2380                                         DE_NULL,
2381                                         format,
2382                                         imageType,
2383                                         tiling,
2384                                         curUsageFlags,
2385                                         curCreateFlags
2386                                 };
2387
2388                                 VkImageFormatProperties                                         coreProperties;
2389                                 VkImageFormatProperties2KHR                                     extProperties;
2390                                 VkResult                                                                        coreResult;
2391                                 VkResult                                                                        extResult;
2392
2393                                 deMemset(&coreProperties, 0xcd, sizeof(VkImageFormatProperties));
2394                                 deMemset(&extProperties, 0xcd, sizeof(VkImageFormatProperties2KHR));
2395
2396                                 extProperties.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2_KHR;
2397                                 extProperties.pNext = DE_NULL;
2398
2399                                 coreResult      = vki.getPhysicalDeviceImageFormatProperties(physicalDevice, imageFormatInfo.format, imageFormatInfo.type, imageFormatInfo.tiling, imageFormatInfo.usage, imageFormatInfo.flags, &coreProperties);
2400                                 extResult       = vki.getPhysicalDeviceImageFormatProperties2KHR(physicalDevice, &imageFormatInfo, &extProperties);
2401
2402                                 TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2_KHR);
2403                                 TCU_CHECK(extProperties.pNext == DE_NULL);
2404
2405                                 if ((coreResult != extResult) ||
2406                                         (deMemCmp(&coreProperties, &extProperties.imageFormatProperties, sizeof(VkImageFormatProperties)) != 0))
2407                                 {
2408                                         log << TestLog::Message << "ERROR: device " << deviceNdx << ": mismatch with query " << imageFormatInfo << TestLog::EndMessage
2409                                                 << TestLog::Message << "vkGetPhysicalDeviceImageFormatProperties() returned " << coreResult << ", " << coreProperties << TestLog::EndMessage
2410                                                 << TestLog::Message << "vkGetPhysicalDeviceImageFormatProperties2KHR() returned " << extResult << ", " << extProperties << TestLog::EndMessage;
2411                                         TCU_FAIL("Mismatch between image format properties reported by vkGetPhysicalDeviceImageFormatProperties and vkGetPhysicalDeviceImageFormatProperties2KHR");
2412                                 }
2413                         }
2414                 }
2415         }
2416
2417         return tcu::TestStatus::pass("Querying image format properties succeeded");
2418 }
2419
2420 tcu::TestStatus sparseImageFormatProperties2 (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling)
2421 {
2422         TestLog&                                                log                             = context.getTestContext().getLog();
2423
2424         const PlatformInterface&                vkp                             = context.getPlatformInterface();
2425         const Unique<VkInstance>                instance                (createInstanceWithExtension(vkp, "VK_KHR_get_physical_device_properties2"));
2426         const InstanceDriver                    vki                             (vkp, *instance);
2427         const vector<VkPhysicalDevice>  devices                 = enumeratePhysicalDevices(vki, *instance);
2428
2429         const VkImageUsageFlags                 allUsageFlags   = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
2430                                                                                                         | VK_IMAGE_USAGE_TRANSFER_DST_BIT
2431                                                                                                         | VK_IMAGE_USAGE_SAMPLED_BIT
2432                                                                                                         | VK_IMAGE_USAGE_STORAGE_BIT
2433                                                                                                         | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
2434                                                                                                         | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
2435                                                                                                         | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
2436                                                                                                         | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
2437
2438         for (size_t deviceNdx = 0; deviceNdx < devices.size(); ++deviceNdx)
2439         {
2440                 const VkPhysicalDevice  physicalDevice  = devices[deviceNdx];
2441
2442                 for (deUint32 sampleCount = 1; sampleCount <= 64; sampleCount++)
2443                 {
2444                         const VkSampleCountFlagBits     sampleCountFlagBit      = (VkSampleCountFlagBits)(1u<<sampleCount);
2445
2446                         for (VkImageUsageFlags curUsageFlags = 0; curUsageFlags <= allUsageFlags; curUsageFlags++)
2447                         {
2448                                 const VkPhysicalDeviceSparseImageFormatInfo2KHR imageFormatInfo =
2449                                 {
2450                                         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2_KHR,
2451                                         DE_NULL,
2452                                         format,
2453                                         imageType,
2454                                         sampleCountFlagBit,
2455                                         curUsageFlags,
2456                                         tiling,
2457                                 };
2458
2459                                 deUint32                                                                                numCoreProperties       = ~0u;
2460                                 deUint32                                                                                numExtProperties        = ~0u;
2461
2462                                 // Query count
2463                                 vki.getPhysicalDeviceSparseImageFormatProperties(physicalDevice, imageFormatInfo.format, imageFormatInfo.type, imageFormatInfo.samples, imageFormatInfo.usage, imageFormatInfo.tiling, &numCoreProperties, DE_NULL);
2464                                 vki.getPhysicalDeviceSparseImageFormatProperties2KHR(physicalDevice, &imageFormatInfo, &numExtProperties, DE_NULL);
2465
2466                                 if (numCoreProperties != numExtProperties)
2467                                 {
2468                                         log << TestLog::Message << "ERROR: device " << deviceNdx << ": different number of properties reported for " << imageFormatInfo << TestLog::EndMessage;
2469                                         TCU_FAIL("Mismatch in reported property count");
2470                                 }
2471
2472                                 if (numCoreProperties > 0)
2473                                 {
2474                                         std::vector<VkSparseImageFormatProperties>              coreProperties  (numCoreProperties);
2475                                         std::vector<VkSparseImageFormatProperties2KHR>  extProperties   (numExtProperties);
2476
2477                                         deMemset(&coreProperties[0], 0xcd, sizeof(VkSparseImageFormatProperties)*numCoreProperties);
2478                                         deMemset(&extProperties[0], 0xcd, sizeof(VkSparseImageFormatProperties2KHR)*numExtProperties);
2479
2480                                         for (deUint32 ndx = 0; ndx < numExtProperties; ++ndx)
2481                                         {
2482                                                 extProperties[ndx].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2_KHR;
2483                                                 extProperties[ndx].pNext = DE_NULL;
2484                                         }
2485
2486                                         vki.getPhysicalDeviceSparseImageFormatProperties(physicalDevice, imageFormatInfo.format, imageFormatInfo.type, imageFormatInfo.samples, imageFormatInfo.usage, imageFormatInfo.tiling, &numCoreProperties, &coreProperties[0]);
2487                                         vki.getPhysicalDeviceSparseImageFormatProperties2KHR(physicalDevice, &imageFormatInfo, &numExtProperties, &extProperties[0]);
2488
2489                                         TCU_CHECK((size_t)numCoreProperties == coreProperties.size());
2490                                         TCU_CHECK((size_t)numExtProperties == extProperties.size());
2491
2492                                         for (deUint32 ndx = 0; ndx < numCoreProperties; ++ndx)
2493                                         {
2494                                                 TCU_CHECK(extProperties[ndx].sType == VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2_KHR);
2495                                                 TCU_CHECK(extProperties[ndx].pNext == DE_NULL);
2496
2497                                                 if ((deMemCmp(&coreProperties[ndx], &extProperties[ndx].properties, sizeof(VkSparseImageFormatProperties)) != 0))
2498                                                 {
2499                                                         log << TestLog::Message << "ERROR: device " << deviceNdx << ": mismatch with query " << imageFormatInfo << " property " << ndx << TestLog::EndMessage
2500                                                                 << TestLog::Message << "vkGetPhysicalDeviceSparseImageFormatProperties() returned " << coreProperties[ndx] << TestLog::EndMessage
2501                                                                 << TestLog::Message << "vkGetPhysicalDeviceSparseImageFormatProperties2KHR() returned " << extProperties[ndx] << TestLog::EndMessage;
2502                                                         TCU_FAIL("Mismatch between image format properties reported by vkGetPhysicalDeviceSparseImageFormatProperties and vkGetPhysicalDeviceSparseImageFormatProperties2KHR");
2503                                                 }
2504                                         }
2505                                 }
2506                         }
2507                 }
2508         }
2509
2510         return tcu::TestStatus::pass("Querying sparse image format properties succeeded");
2511 }
2512
2513 } // anonymous
2514
2515 tcu::TestCaseGroup* createFeatureInfoTests (tcu::TestContext& testCtx)
2516 {
2517         de::MovePtr<tcu::TestCaseGroup> infoTests       (new tcu::TestCaseGroup(testCtx, "info", "Platform Information Tests"));
2518
2519         {
2520                 de::MovePtr<tcu::TestCaseGroup> instanceInfoTests       (new tcu::TestCaseGroup(testCtx, "instance", "Instance Information Tests"));
2521
2522                 addFunctionCase(instanceInfoTests.get(), "physical_devices",            "Physical devices",                     enumeratePhysicalDevices);
2523                 addFunctionCase(instanceInfoTests.get(), "layers",                                      "Layers",                                       enumerateInstanceLayers);
2524                 addFunctionCase(instanceInfoTests.get(), "extensions",                          "Extensions",                           enumerateInstanceExtensions);
2525
2526                 infoTests->addChild(instanceInfoTests.release());
2527         }
2528
2529         {
2530                 de::MovePtr<tcu::TestCaseGroup> deviceInfoTests (new tcu::TestCaseGroup(testCtx, "device", "Device Information Tests"));
2531
2532                 addFunctionCase(deviceInfoTests.get(), "features",                                      "Device Features",                      deviceFeatures);
2533                 addFunctionCase(deviceInfoTests.get(), "properties",                            "Device Properties",            deviceProperties);
2534                 addFunctionCase(deviceInfoTests.get(), "queue_family_properties",       "Queue family properties",      deviceQueueFamilyProperties);
2535                 addFunctionCase(deviceInfoTests.get(), "memory_properties",                     "Memory properties",            deviceMemoryProperties);
2536                 addFunctionCase(deviceInfoTests.get(), "layers",                                        "Layers",                                       enumerateDeviceLayers);
2537                 addFunctionCase(deviceInfoTests.get(), "extensions",                            "Extensions",                           enumerateDeviceExtensions);
2538
2539                 infoTests->addChild(deviceInfoTests.release());
2540         }
2541
2542         infoTests->addChild(createTestGroup(testCtx, "format_properties",               "VkGetPhysicalDeviceFormatProperties() Tests",          createFormatTests));
2543         infoTests->addChild(createTestGroup(testCtx, "image_format_properties", "VkGetPhysicalDeviceImageFormatProperties() Tests",     createImageFormatTests, imageFormatProperties));
2544
2545         {
2546                 de::MovePtr<tcu::TestCaseGroup> extendedPropertiesTests (new tcu::TestCaseGroup(testCtx, "get_physical_device_properties2", "VK_KHR_get_physical_device_properties2"));
2547
2548                 addFunctionCase(extendedPropertiesTests.get(), "features",                                      "Extended Device Features",                                     deviceFeatures2);
2549                 addFunctionCase(extendedPropertiesTests.get(), "properties",                            "Extended Device Properties",                           deviceProperties2);
2550                 addFunctionCase(extendedPropertiesTests.get(), "format_properties",                     "Extended Device Format Properties",            deviceFormatProperties2);
2551                 addFunctionCase(extendedPropertiesTests.get(), "queue_family_properties",       "Extended Device Queue Family Properties",      deviceQueueFamilyProperties2);
2552                 addFunctionCase(extendedPropertiesTests.get(), "memory_properties",                     "Extended Device Memory Properties",            deviceMemoryProperties2);
2553
2554                 infoTests->addChild(extendedPropertiesTests.release());
2555         }
2556
2557         infoTests->addChild(createTestGroup(testCtx, "image_format_properties2",                "VkGetPhysicalDeviceImageFormatProperties2KHR() Tests",                 createImageFormatTests, imageFormatProperties2));
2558         infoTests->addChild(createTestGroup(testCtx, "sparse_image_format_properties2", "VkGetPhysicalDeviceSparseImageFormatProperties2KHR() Tests",   createImageFormatTests, sparseImageFormatProperties2));
2559
2560         return infoTests.release();
2561 }
2562
2563 } // api
2564 } // vkt