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