Merge vk-gl-cts/vulkan-cts-1.1.2 into vk-gl-cts/master
[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 "vkRefUtil.hpp"
33 #include "vkDeviceUtil.hpp"
34 #include "vkQueryUtil.hpp"
35 #include "vkImageUtil.hpp"
36 #include "vkApiVersion.hpp"
37
38 #include "tcuTestLog.hpp"
39 #include "tcuFormatUtil.hpp"
40 #include "tcuTextureUtil.hpp"
41 #include "tcuResultCollector.hpp"
42 #include "tcuCommandLine.hpp"
43
44 #include "deUniquePtr.hpp"
45 #include "deString.h"
46 #include "deStringUtil.hpp"
47 #include "deSTLUtil.hpp"
48 #include "deMemory.h"
49 #include "deMath.h"
50
51 #include <vector>
52 #include <set>
53 #include <string>
54
55 namespace vkt
56 {
57 namespace api
58 {
59 namespace
60 {
61
62 #include "vkApiExtensionDependencyInfo.inl"
63
64 using namespace vk;
65 using std::vector;
66 using std::set;
67 using std::string;
68 using tcu::TestLog;
69 using tcu::ScopedLogSection;
70
71 enum
72 {
73         GUARD_SIZE                                                              = 0x20,                 //!< Number of bytes to check
74         GUARD_VALUE                                                             = 0xcd,                 //!< Data pattern
75 };
76
77 static const VkDeviceSize MINIMUM_REQUIRED_IMAGE_RESOURCE_SIZE =        (1LLU<<31);     //!< Minimum value for VkImageFormatProperties::maxResourceSize (2GiB)
78
79 enum LimitFormat
80 {
81         LIMIT_FORMAT_SIGNED_INT,
82         LIMIT_FORMAT_UNSIGNED_INT,
83         LIMIT_FORMAT_FLOAT,
84         LIMIT_FORMAT_DEVICE_SIZE,
85         LIMIT_FORMAT_BITMASK,
86
87         LIMIT_FORMAT_LAST
88 };
89
90 enum LimitType
91 {
92         LIMIT_TYPE_MIN,
93         LIMIT_TYPE_MAX,
94         LIMIT_TYPE_NONE,
95
96         LIMIT_TYPE_LAST
97 };
98
99 #define LIMIT(_X_)              DE_OFFSET_OF(VkPhysicalDeviceLimits, _X_), (const char*)(#_X_)
100 #define FEATURE(_X_)    DE_OFFSET_OF(VkPhysicalDeviceFeatures, _X_)
101
102 bool validateFeatureLimits(VkPhysicalDeviceProperties* properties, VkPhysicalDeviceFeatures* features, TestLog& log)
103 {
104         bool                                            limitsOk                                = true;
105         VkPhysicalDeviceLimits*         limits                                  = &properties->limits;
106         deUint32                                        shaderStages                    = 3;
107         deUint32                                        maxPerStageResourcesMin = deMin32(128,  limits->maxPerStageDescriptorUniformBuffers             +
108                                                                                                                                                 limits->maxPerStageDescriptorStorageBuffers             +
109                                                                                                                                                 limits->maxPerStageDescriptorSampledImages              +
110                                                                                                                                                 limits->maxPerStageDescriptorStorageImages              +
111                                                                                                                                                 limits->maxPerStageDescriptorInputAttachments   +
112                                                                                                                                                 limits->maxColorAttachments);
113
114         if (features->tessellationShader)
115         {
116                 shaderStages += 2;
117         }
118
119         if (features->geometryShader)
120         {
121                 shaderStages++;
122         }
123
124         struct FeatureLimitTable
125         {
126                 deUint32                offset;
127                 const char*             name;
128                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
129                 deInt32                 intVal;                         //!< Format is SIGNED_INT
130                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
131                 float                   floatVal;                       //!< Format is FLOAT
132                 LimitFormat             format;
133                 LimitType               type;
134                 deInt32                 unsuppTableNdx;
135         } featureLimitTable[] =   //!< Based on 1.0.28 Vulkan spec
136         {
137                 { LIMIT(maxImageDimension1D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
138                 { LIMIT(maxImageDimension2D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
139                 { LIMIT(maxImageDimension3D),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
140                 { LIMIT(maxImageDimensionCube),                                                         4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
141                 { LIMIT(maxImageArrayLayers),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
142                 { LIMIT(maxTexelBufferElements),                                                        65536, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
143                 { LIMIT(maxUniformBufferRange),                                                         16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
144                 { LIMIT(maxStorageBufferRange),                                                         134217728, 0, 0, 0, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
145                 { LIMIT(maxPushConstantsSize),                                                          128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
146                 { LIMIT(maxMemoryAllocationCount),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
147                 { LIMIT(maxSamplerAllocationCount),                                                     4000, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
148                 { LIMIT(bufferImageGranularity),                                                        0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
149                 { LIMIT(bufferImageGranularity),                                                        0, 0, 131072, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
150                 { LIMIT(sparseAddressSpaceSize),                                                        0, 0, 2UL*1024*1024*1024, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
151                 { LIMIT(maxBoundDescriptorSets),                                                        4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
152                 { LIMIT(maxPerStageDescriptorSamplers),                                         16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
153                 { LIMIT(maxPerStageDescriptorUniformBuffers),                           12, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
154                 { LIMIT(maxPerStageDescriptorStorageBuffers),                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
155                 { LIMIT(maxPerStageDescriptorSampledImages),                            16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
156                 { LIMIT(maxPerStageDescriptorStorageImages),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
157                 { LIMIT(maxPerStageDescriptorInputAttachments),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
158                 { LIMIT(maxPerStageResources),                                                          maxPerStageResourcesMin, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
159                 { LIMIT(maxDescriptorSetSamplers),                                                      shaderStages * 16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
160                 { LIMIT(maxDescriptorSetUniformBuffers),                                        shaderStages * 12, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
161                 { LIMIT(maxDescriptorSetUniformBuffersDynamic),                         8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
162                 { LIMIT(maxDescriptorSetStorageBuffers),                                        shaderStages * 4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
163                 { LIMIT(maxDescriptorSetStorageBuffersDynamic),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
164                 { LIMIT(maxDescriptorSetSampledImages),                                         shaderStages * 16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
165                 { LIMIT(maxDescriptorSetStorageImages),                                         shaderStages * 4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
166                 { LIMIT(maxDescriptorSetInputAttachments),                                      4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
167                 { LIMIT(maxVertexInputAttributes),                                                      16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
168                 { LIMIT(maxVertexInputBindings),                                                        16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
169                 { LIMIT(maxVertexInputAttributeOffset),                                         2047, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
170                 { LIMIT(maxVertexInputBindingStride),                                           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
171                 { LIMIT(maxVertexOutputComponents),                                                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
172                 { LIMIT(maxTessellationGenerationLevel),                                        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
173                 { LIMIT(maxTessellationPatchSize),                                                      32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
174                 { LIMIT(maxTessellationControlPerVertexInputComponents),        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
175                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
176                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        120, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
177                 { LIMIT(maxTessellationControlTotalOutputComponents),           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
178                 { LIMIT(maxTessellationEvaluationInputComponents),                      64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
179                 { LIMIT(maxTessellationEvaluationOutputComponents),                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
180                 { LIMIT(maxGeometryShaderInvocations),                                          32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
181                 { LIMIT(maxGeometryInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
182                 { LIMIT(maxGeometryOutputComponents),                                           64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
183                 { LIMIT(maxGeometryOutputVertices),                                                     256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
184                 { LIMIT(maxGeometryTotalOutputComponents),                                      1024, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
185                 { LIMIT(maxFragmentInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
186                 { LIMIT(maxFragmentOutputAttachments),                                          4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
187                 { LIMIT(maxFragmentDualSrcAttachments),                                         1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
188                 { LIMIT(maxFragmentCombinedOutputResources),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
189                 { LIMIT(maxComputeSharedMemorySize),                                            16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
190                 { LIMIT(maxComputeWorkGroupCount[0]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
191                 { LIMIT(maxComputeWorkGroupCount[1]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
192                 { LIMIT(maxComputeWorkGroupCount[2]),                                           65535,  0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
193                 { LIMIT(maxComputeWorkGroupInvocations),                                        128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
194                 { LIMIT(maxComputeWorkGroupSize[0]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
195                 { LIMIT(maxComputeWorkGroupSize[1]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
196                 { LIMIT(maxComputeWorkGroupSize[2]),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
197                 { LIMIT(subPixelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
198                 { LIMIT(subTexelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
199                 { LIMIT(mipmapPrecisionBits),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
200                 { LIMIT(maxDrawIndexedIndexValue),                                                      (deUint32)~0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
201                 { LIMIT(maxDrawIndirectCount),                                                          65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
202                 { LIMIT(maxSamplerLodBias),                                                                     0, 0, 0, 2.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
203                 { LIMIT(maxSamplerAnisotropy),                                                          0, 0, 0, 16.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
204                 { LIMIT(maxViewports),                                                                          16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
205                 { LIMIT(maxViewportDimensions[0]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
206                 { LIMIT(maxViewportDimensions[1]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
207                 { LIMIT(viewportBoundsRange[0]),                                                        0, 0, 0, -8192.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
208                 { LIMIT(viewportBoundsRange[1]),                                                        0, 0, 0, 8191.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
209                 { LIMIT(viewportSubPixelBits),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
210                 { LIMIT(minMemoryMapAlignment),                                                         64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
211                 { LIMIT(minTexelBufferOffsetAlignment),                                         0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
212                 { LIMIT(minTexelBufferOffsetAlignment),                                         0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
213                 { LIMIT(minUniformBufferOffsetAlignment),                                       0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
214                 { LIMIT(minUniformBufferOffsetAlignment),                                       0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
215                 { LIMIT(minStorageBufferOffsetAlignment),                                       0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
216                 { LIMIT(minStorageBufferOffsetAlignment),                                       0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
217                 { LIMIT(minTexelOffset),                                                                        0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
218                 { LIMIT(maxTexelOffset),                                                                        7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
219                 { LIMIT(minTexelGatherOffset),                                                          0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
220                 { LIMIT(maxTexelGatherOffset),                                                          7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
221                 { LIMIT(minInterpolationOffset),                                                        0, 0, 0, -0.5f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
222                 { LIMIT(maxInterpolationOffset),                                                        0, 0, 0, 0.5f - (1.0f/deFloatPow(2.0f, (float)limits->subPixelInterpolationOffsetBits)), LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
223                 { LIMIT(subPixelInterpolationOffsetBits),                                       4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
224                 { LIMIT(maxFramebufferWidth),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
225                 { LIMIT(maxFramebufferHeight),                                                          4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
226                 { LIMIT(maxFramebufferLayers),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
227                 { LIMIT(framebufferColorSampleCounts),                                          VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
228                 { LIMIT(framebufferDepthSampleCounts),                                          VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
229                 { LIMIT(framebufferStencilSampleCounts),                                        VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
230                 { LIMIT(framebufferNoAttachmentsSampleCounts),                          VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
231                 { LIMIT(maxColorAttachments),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
232                 { LIMIT(sampledImageColorSampleCounts),                                         VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
233                 { LIMIT(sampledImageIntegerSampleCounts),                                       VK_SAMPLE_COUNT_1_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
234                 { LIMIT(sampledImageDepthSampleCounts),                                         VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
235                 { LIMIT(sampledImageStencilSampleCounts),                                       VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
236                 { LIMIT(storageImageSampleCounts),                                                      VK_SAMPLE_COUNT_1_BIT|VK_SAMPLE_COUNT_4_BIT, 0, 0, 0.0f, LIMIT_FORMAT_BITMASK, LIMIT_TYPE_MIN, -1 },
237                 { LIMIT(maxSampleMaskWords),                                                            1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
238                 { LIMIT(timestampComputeAndGraphics),                                           0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
239                 { LIMIT(timestampPeriod),                                                                       0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
240                 { LIMIT(maxClipDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
241                 { LIMIT(maxCullDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
242                 { LIMIT(maxCombinedClipAndCullDistances),                                       8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
243                 { LIMIT(discreteQueuePriorities),                                                       2, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
244                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 0.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
245                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
246                 { LIMIT(pointSizeRange[1]),                                                                     0, 0, 0, 64.0f - limits->pointSizeGranularity , LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
247                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 0.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
248                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
249                 { LIMIT(lineWidthRange[1]),                                                                     0, 0, 0, 8.0f - limits->lineWidthGranularity, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
250                 { LIMIT(pointSizeGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
251                 { LIMIT(lineWidthGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
252                 { LIMIT(strictLines),                                                                           0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
253                 { LIMIT(standardSampleLocations),                                                       0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_NONE, -1 },
254                 { LIMIT(optimalBufferCopyOffsetAlignment),                                      0, 0, 0, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_NONE, -1 },
255                 { LIMIT(optimalBufferCopyRowPitchAlignment),                            0, 0, 0, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_NONE, -1 },
256                 { LIMIT(nonCoherentAtomSize),                                                           0, 0, 1, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
257                 { LIMIT(nonCoherentAtomSize),                                                           0, 0, 256, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
258         };
259
260         const struct UnsupportedFeatureLimitTable
261         {
262                 deUint32                limitOffset;
263                 const char*             name;
264                 deUint32                featureOffset;
265                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
266                 deInt32                 intVal;                         //!< Format is SIGNED_INT
267                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
268                 float                   floatVal;                       //!< Format is FLOAT
269         } unsupportedFeatureTable[] =
270         {
271                 { LIMIT(sparseAddressSpaceSize),                                                        FEATURE(sparseBinding),                                 0, 0, 0, 0.0f },
272                 { LIMIT(maxTessellationGenerationLevel),                                        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
273                 { LIMIT(maxTessellationPatchSize),                                                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
274                 { LIMIT(maxTessellationControlPerVertexInputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
275                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
276                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
277                 { LIMIT(maxTessellationControlTotalOutputComponents),           FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
278                 { LIMIT(maxTessellationEvaluationInputComponents),                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
279                 { LIMIT(maxTessellationEvaluationOutputComponents),                     FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
280                 { LIMIT(maxGeometryShaderInvocations),                                          FEATURE(geometryShader),                                0, 0, 0, 0.0f },
281                 { LIMIT(maxGeometryInputComponents),                                            FEATURE(geometryShader),                                0, 0, 0, 0.0f },
282                 { LIMIT(maxGeometryOutputComponents),                                           FEATURE(geometryShader),                                0, 0, 0, 0.0f },
283                 { LIMIT(maxGeometryOutputVertices),                                                     FEATURE(geometryShader),                                0, 0, 0, 0.0f },
284                 { LIMIT(maxGeometryTotalOutputComponents),                                      FEATURE(geometryShader),                                0, 0, 0, 0.0f },
285                 { LIMIT(maxFragmentDualSrcAttachments),                                         FEATURE(dualSrcBlend),                                  0, 0, 0, 0.0f },
286                 { LIMIT(maxDrawIndexedIndexValue),                                                      FEATURE(fullDrawIndexUint32),                   (1<<24)-1, 0, 0, 0.0f },
287                 { LIMIT(maxDrawIndirectCount),                                                          FEATURE(multiDrawIndirect),                             1, 0, 0, 0.0f },
288                 { LIMIT(maxSamplerAnisotropy),                                                          FEATURE(samplerAnisotropy),                             1, 0, 0, 0.0f },
289                 { LIMIT(maxViewports),                                                                          FEATURE(multiViewport),                                 1, 0, 0, 0.0f },
290                 { LIMIT(minTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
291                 { LIMIT(maxTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
292                 { LIMIT(minInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
293                 { LIMIT(maxInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
294                 { LIMIT(subPixelInterpolationOffsetBits),                                       FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
295                 { LIMIT(storageImageSampleCounts),                                                      FEATURE(shaderStorageImageMultisample), VK_SAMPLE_COUNT_1_BIT, 0, 0, 0.0f },
296                 { LIMIT(maxClipDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
297                 { LIMIT(maxCullDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
298                 { LIMIT(maxCombinedClipAndCullDistances),                                       FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
299                 { LIMIT(pointSizeRange[0]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
300                 { LIMIT(pointSizeRange[1]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
301                 { LIMIT(lineWidthRange[0]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
302                 { LIMIT(lineWidthRange[1]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
303                 { LIMIT(pointSizeGranularity),                                                          FEATURE(largePoints),                                   0, 0, 0, 0.0f },
304                 { LIMIT(lineWidthGranularity),                                                          FEATURE(wideLines),                                             0, 0, 0, 0.0f }
305         };
306
307         log << TestLog::Message << *limits << TestLog::EndMessage;
308
309         //!< First build a map from limit to unsupported table index
310         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
311         {
312                 for (deUint32 unsuppNdx = 0; unsuppNdx < DE_LENGTH_OF_ARRAY(unsupportedFeatureTable); unsuppNdx++)
313                 {
314                         if (unsupportedFeatureTable[unsuppNdx].limitOffset == featureLimitTable[ndx].offset)
315                         {
316                                 featureLimitTable[ndx].unsuppTableNdx = unsuppNdx;
317                                 break;
318                         }
319                 }
320         }
321
322         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
323         {
324                 switch (featureLimitTable[ndx].format)
325                 {
326                         case LIMIT_FORMAT_UNSIGNED_INT:
327                         {
328                                 deUint32 limitToCheck = featureLimitTable[ndx].uintVal;
329                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
330                                 {
331                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
332                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].uintVal;
333                                 }
334
335                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
336                                 {
337
338                                         if (*((deUint32*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
339                                         {
340                                                 log << TestLog::Message << "limit Validation failed " << featureLimitTable[ndx].name
341                                                         << " not valid-limit type MIN - actual is "
342                                                         << *((deUint32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
343                                                 limitsOk = false;
344                                         }
345                                 }
346                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
347                                 {
348                                         if (*((deUint32*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
349                                         {
350                                                 log << TestLog::Message << "limit validation failed,  " << featureLimitTable[ndx].name
351                                                         << " not valid-limit type MAX - actual is "
352                                                         << *((deUint32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
353                                                 limitsOk = false;
354                                         }
355                                 }
356                                 break;
357                         }
358
359                         case LIMIT_FORMAT_FLOAT:
360                         {
361                                 float limitToCheck = featureLimitTable[ndx].floatVal;
362                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
363                                 {
364                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
365                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].floatVal;
366                                 }
367
368                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
369                                 {
370                                         if (*((float*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
371                                         {
372                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
373                                                         << " not valid-limit type MIN - actual is "
374                                                         << *((float*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
375                                                 limitsOk = false;
376                                         }
377                                 }
378                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
379                                 {
380                                         if (*((float*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
381                                         {
382                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
383                                                         << " not valid-limit type MAX actual is "
384                                                         << *((float*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
385                                                 limitsOk = false;
386                                         }
387                                 }
388                                 break;
389                         }
390
391                         case LIMIT_FORMAT_SIGNED_INT:
392                         {
393                                 deInt32 limitToCheck = featureLimitTable[ndx].intVal;
394                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
395                                 {
396                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
397                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].intVal;
398                                 }
399                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
400                                 {
401                                         if (*((deInt32*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
402                                         {
403                                                 log << TestLog::Message <<  "limit validation failed, " << featureLimitTable[ndx].name
404                                                         << " not valid-limit type MIN actual is "
405                                                         << *((deInt32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
406                                                 limitsOk = false;
407                                         }
408                                 }
409                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
410                                 {
411                                         if (*((deInt32*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
412                                         {
413                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
414                                                         << " not valid-limit type MAX actual is "
415                                                         << *((deInt32*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
416                                                 limitsOk = false;
417                                         }
418                                 }
419                                 break;
420                         }
421
422                         case LIMIT_FORMAT_DEVICE_SIZE:
423                         {
424                                 deUint64 limitToCheck = featureLimitTable[ndx].deviceSizeVal;
425                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
426                                 {
427                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
428                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].deviceSizeVal;
429                                 }
430
431                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
432                                 {
433                                         if (*((deUint64*)((deUint8*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
434                                         {
435                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
436                                                         << " not valid-limit type MIN actual is "
437                                                         << *((deUint64*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
438                                                 limitsOk = false;
439                                         }
440                                 }
441                                 else if (featureLimitTable[ndx].type == LIMIT_TYPE_MAX)
442                                 {
443                                         if (*((deUint64*)((deUint8*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
444                                         {
445                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
446                                                         << " not valid-limit type MAX actual is "
447                                                         << *((deUint64*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
448                                                 limitsOk = false;
449                                         }
450                                 }
451                                 break;
452                         }
453
454                         case LIMIT_FORMAT_BITMASK:
455                         {
456                                 deUint32 limitToCheck = featureLimitTable[ndx].uintVal;
457                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
458                                 {
459                                         if (*((VkBool32*)((deUint8*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
460                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].uintVal;
461                                 }
462
463                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
464                                 {
465                                         if ((*((deUint32*)((deUint8*)limits+featureLimitTable[ndx].offset)) & limitToCheck) != limitToCheck)
466                                         {
467                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
468                                                         << " not valid-limit type bitmask actual is "
469                                                         << *((deUint64*)((deUint8*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
470                                                 limitsOk = false;
471                                         }
472                                 }
473                                 break;
474                         }
475
476                         default:
477                                 DE_ASSERT(0);
478                                 limitsOk = false;
479                 }
480         }
481
482         if (limits->maxFramebufferWidth > limits->maxViewportDimensions[0] ||
483                 limits->maxFramebufferHeight > limits->maxViewportDimensions[1])
484         {
485                 log << TestLog::Message << "limit validation failed, maxFramebufferDimension of "
486                         << "[" << limits->maxFramebufferWidth << ", " << limits->maxFramebufferHeight << "] "
487                         << "is larger than maxViewportDimension of "
488                         << "[" << limits->maxViewportDimensions[0] << ", " << limits->maxViewportDimensions[1] << "]" << TestLog::EndMessage;
489                 limitsOk = false;
490         }
491
492         if (limits->viewportBoundsRange[0] > float(-2 * limits->maxViewportDimensions[0]))
493         {
494                 log << TestLog::Message << "limit validation failed, viewPortBoundsRange[0] of " << limits->viewportBoundsRange[0]
495                         << "is larger than -2*maxViewportDimension[0] of " << -2*limits->maxViewportDimensions[0] << TestLog::EndMessage;
496                 limitsOk = false;
497         }
498
499         if (limits->viewportBoundsRange[1] < float(2 * limits->maxViewportDimensions[1] - 1))
500         {
501                 log << TestLog::Message << "limit validation failed, viewportBoundsRange[1] of " << limits->viewportBoundsRange[1]
502                         << "is less than 2*maxViewportDimension[1] of " << 2*limits->maxViewportDimensions[1] << TestLog::EndMessage;
503                 limitsOk = false;
504         }
505
506         return limitsOk;
507 }
508
509 template<typename T>
510 class CheckIncompleteResult
511 {
512 public:
513         virtual                 ~CheckIncompleteResult  (void) {}
514         virtual void    getResult                               (Context& context, T* data) = 0;
515
516         void operator() (Context& context, tcu::ResultCollector& results, const std::size_t expectedCompleteSize)
517         {
518                 if (expectedCompleteSize == 0)
519                         return;
520
521                 vector<T>               outputData      (expectedCompleteSize);
522                 const deUint32  usedSize        = static_cast<deUint32>(expectedCompleteSize / 3);
523
524                 ValidateQueryBits::fillBits(outputData.begin(), outputData.end());      // unused entries should have this pattern intact
525                 m_count         = usedSize;
526                 m_result        = VK_SUCCESS;
527
528                 getResult(context, &outputData[0]);                                                                     // update m_count and m_result
529
530                 if (m_count != usedSize || m_result != VK_INCOMPLETE || !ValidateQueryBits::checkBits(outputData.begin() + m_count, outputData.end()))
531                         results.fail("Query didn't return VK_INCOMPLETE");
532         }
533
534 protected:
535         deUint32        m_count;
536         VkResult        m_result;
537 };
538
539 struct CheckEnumeratePhysicalDevicesIncompleteResult : public CheckIncompleteResult<VkPhysicalDevice>
540 {
541         void getResult (Context& context, VkPhysicalDevice* data)
542         {
543                 m_result = context.getInstanceInterface().enumeratePhysicalDevices(context.getInstance(), &m_count, data);
544         }
545 };
546
547 struct CheckEnumeratePhysicalDeviceGroupsIncompleteResult : public CheckIncompleteResult<VkPhysicalDeviceGroupProperties>
548 {
549         void getResult (Context& context, VkPhysicalDeviceGroupProperties* data)
550         {
551                 m_result = context.getInstanceInterface().enumeratePhysicalDeviceGroups(context.getInstance(), &m_count, data);
552         }
553 };
554
555 struct CheckEnumerateInstanceLayerPropertiesIncompleteResult : public CheckIncompleteResult<VkLayerProperties>
556 {
557         void getResult (Context& context, VkLayerProperties* data)
558         {
559                 m_result = context.getPlatformInterface().enumerateInstanceLayerProperties(&m_count, data);
560         }
561 };
562
563 struct CheckEnumerateDeviceLayerPropertiesIncompleteResult : public CheckIncompleteResult<VkLayerProperties>
564 {
565         void getResult (Context& context, VkLayerProperties* data)
566         {
567                 m_result = context.getInstanceInterface().enumerateDeviceLayerProperties(context.getPhysicalDevice(), &m_count, data);
568         }
569 };
570
571 struct CheckEnumerateInstanceExtensionPropertiesIncompleteResult : public CheckIncompleteResult<VkExtensionProperties>
572 {
573         CheckEnumerateInstanceExtensionPropertiesIncompleteResult (std::string layerName = std::string()) : m_layerName(layerName) {}
574
575         void getResult (Context& context, VkExtensionProperties* data)
576         {
577                 const char* pLayerName = (m_layerName.length() != 0 ? m_layerName.c_str() : DE_NULL);
578                 m_result = context.getPlatformInterface().enumerateInstanceExtensionProperties(pLayerName, &m_count, data);
579         }
580
581 private:
582         const std::string       m_layerName;
583 };
584
585 struct CheckEnumerateDeviceExtensionPropertiesIncompleteResult : public CheckIncompleteResult<VkExtensionProperties>
586 {
587         CheckEnumerateDeviceExtensionPropertiesIncompleteResult (std::string layerName = std::string()) : m_layerName(layerName) {}
588
589         void getResult (Context& context, VkExtensionProperties* data)
590         {
591                 const char* pLayerName = (m_layerName.length() != 0 ? m_layerName.c_str() : DE_NULL);
592                 m_result = context.getInstanceInterface().enumerateDeviceExtensionProperties(context.getPhysicalDevice(), pLayerName, &m_count, data);
593         }
594
595 private:
596         const std::string       m_layerName;
597 };
598
599 tcu::TestStatus enumeratePhysicalDevices (Context& context)
600 {
601         TestLog&                                                log             = context.getTestContext().getLog();
602         tcu::ResultCollector                    results (log);
603         const vector<VkPhysicalDevice>  devices = enumeratePhysicalDevices(context.getInstanceInterface(), context.getInstance());
604
605         log << TestLog::Integer("NumDevices", "Number of devices", "", QP_KEY_TAG_NONE, deInt64(devices.size()));
606
607         for (size_t ndx = 0; ndx < devices.size(); ndx++)
608                 log << TestLog::Message << ndx << ": " << devices[ndx] << TestLog::EndMessage;
609
610         CheckEnumeratePhysicalDevicesIncompleteResult()(context, results, devices.size());
611
612         return tcu::TestStatus(results.getResult(), results.getMessage());
613 }
614
615 tcu::TestStatus enumeratePhysicalDeviceGroups (Context& context)
616 {
617         TestLog&                                                                                        log                             = context.getTestContext().getLog();
618         tcu::ResultCollector                                                            results                 (log);
619         const PlatformInterface&                                                        vkp                             = context.getPlatformInterface();
620         const Unique<VkInstance>                                                        instance                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_device_group_creation"));
621         const InstanceDriver                                                            vki                             (vkp, *instance);
622         const vector<VkPhysicalDeviceGroupProperties>           devicegroups    = enumeratePhysicalDeviceGroups(vki, *instance);
623
624         log << TestLog::Integer("NumDevices", "Number of device groups", "", QP_KEY_TAG_NONE, deInt64(devicegroups.size()));
625
626         for (size_t ndx = 0; ndx < devicegroups.size(); ndx++)
627                 log << TestLog::Message << ndx << ": " << devicegroups[ndx] << TestLog::EndMessage;
628
629         CheckEnumeratePhysicalDeviceGroupsIncompleteResult()(context, results, devicegroups.size());
630
631         return tcu::TestStatus(results.getResult(), results.getMessage());
632 }
633
634 template<typename T>
635 void collectDuplicates (set<T>& duplicates, const vector<T>& values)
636 {
637         set<T> seen;
638
639         for (size_t ndx = 0; ndx < values.size(); ndx++)
640         {
641                 const T& value = values[ndx];
642
643                 if (!seen.insert(value).second)
644                         duplicates.insert(value);
645         }
646 }
647
648 void checkDuplicates (tcu::ResultCollector& results, const char* what, const vector<string>& values)
649 {
650         set<string> duplicates;
651
652         collectDuplicates(duplicates, values);
653
654         for (set<string>::const_iterator iter = duplicates.begin(); iter != duplicates.end(); ++iter)
655         {
656                 std::ostringstream msg;
657                 msg << "Duplicate " << what << ": " << *iter;
658                 results.fail(msg.str());
659         }
660 }
661
662 void checkDuplicateExtensions (tcu::ResultCollector& results, const vector<string>& extensions)
663 {
664         checkDuplicates(results, "extension", extensions);
665 }
666
667 void checkDuplicateLayers (tcu::ResultCollector& results, const vector<string>& layers)
668 {
669         checkDuplicates(results, "layer", layers);
670 }
671
672 void checkKhrExtensions (tcu::ResultCollector&          results,
673                                                  const vector<string>&          extensions,
674                                                  const int                                      numAllowedKhrExtensions,
675                                                  const char* const*                     allowedKhrExtensions)
676 {
677         const set<string>       allowedExtSet           (allowedKhrExtensions, allowedKhrExtensions+numAllowedKhrExtensions);
678
679         for (vector<string>::const_iterator extIter = extensions.begin(); extIter != extensions.end(); ++extIter)
680         {
681                 // Only Khronos-controlled extensions are checked
682                 if (de::beginsWith(*extIter, "VK_KHR_") &&
683                         !de::contains(allowedExtSet, *extIter))
684                 {
685                         results.fail("Unknown  extension " + *extIter);
686                 }
687         }
688 }
689
690 void checkInstanceExtensions (tcu::ResultCollector& results, const vector<string>& extensions)
691 {
692         static const char* s_allowedInstanceKhrExtensions[] =
693         {
694                 "VK_KHR_surface",
695                 "VK_KHR_display",
696                 "VK_KHR_android_surface",
697                 "VK_KHR_mir_surface",
698                 "VK_KHR_wayland_surface",
699                 "VK_KHR_win32_surface",
700                 "VK_KHR_xcb_surface",
701                 "VK_KHR_xlib_surface",
702                 "VK_KHR_get_physical_device_properties2",
703                 "VK_KHR_get_surface_capabilities2",
704                 "VK_KHR_external_memory_capabilities",
705                 "VK_KHR_external_semaphore_capabilities",
706                 "VK_KHR_external_fence_capabilities",
707                 "VK_KHR_device_group_creation",
708                 "VK_KHR_get_display_properties2",
709         };
710
711         checkKhrExtensions(results, extensions, DE_LENGTH_OF_ARRAY(s_allowedInstanceKhrExtensions), s_allowedInstanceKhrExtensions);
712         checkDuplicateExtensions(results, extensions);
713 }
714
715 void checkDeviceExtensions (tcu::ResultCollector& results, const vector<string>& extensions)
716 {
717         static const char* s_allowedDeviceKhrExtensions[] =
718         {
719                 "VK_KHR_swapchain",
720                 "VK_KHR_display_swapchain",
721                 "VK_KHR_sampler_mirror_clamp_to_edge",
722                 "VK_KHR_shader_draw_parameters",
723                 "VK_KHR_shader_float_controls",
724                 "VK_KHR_shader_float16_int8",
725                 "VK_KHR_maintenance1",
726                 "VK_KHR_push_descriptor",
727                 "VK_KHR_descriptor_update_template",
728                 "VK_KHR_incremental_present",
729                 "VK_KHR_shared_presentable_image",
730                 "VK_KHR_storage_buffer_storage_class",
731                 "VK_KHR_8bit_storage",
732                 "VK_KHR_16bit_storage",
733                 "VK_KHR_get_memory_requirements2",
734                 "VK_KHR_external_memory",
735                 "VK_KHR_external_memory_fd",
736                 "VK_KHR_external_memory_win32",
737                 "VK_KHR_external_semaphore",
738                 "VK_KHR_external_semaphore_fd",
739                 "VK_KHR_external_semaphore_win32",
740                 "VK_KHR_external_fence",
741                 "VK_KHR_external_fence_fd",
742                 "VK_KHR_external_fence_win32",
743                 "VK_KHR_win32_keyed_mutex",
744                 "VK_KHR_dedicated_allocation",
745                 "VK_KHR_variable_pointers",
746                 "VK_KHR_relaxed_block_layout",
747                 "VK_KHR_bind_memory2",
748                 "VK_KHR_maintenance2",
749                 "VK_KHR_image_format_list",
750                 "VK_KHR_sampler_ycbcr_conversion",
751                 "VK_KHR_device_group",
752                 "VK_KHR_multiview",
753                 "VK_KHR_maintenance3",
754                 "VK_KHR_draw_indirect_count",
755                 "VK_KHR_create_renderpass2",
756                 "VK_KHR_driver_properties",
757                 "VK_KHR_swapchain_mutable_format",
758                 "VK_KHR_shader_atomic_int64",
759                 "VK_KHR_vulkan_memory_model",
760                 "VK_KHR_swapchain_mutable_format",
761         };
762
763         checkKhrExtensions(results, extensions, DE_LENGTH_OF_ARRAY(s_allowedDeviceKhrExtensions), s_allowedDeviceKhrExtensions);
764         checkDuplicateExtensions(results, extensions);
765 }
766
767 void checkInstanceExtensionDependencies(tcu::ResultCollector& results,
768                                                                                 int dependencyLength,
769                                                                                 const std::pair<const char*, const char*>* dependencies,
770                                                                                 const vector<VkExtensionProperties>& extensionProperties)
771 {
772         for (int ndx = 0; ndx < dependencyLength; ndx++)
773         {
774                 if (isExtensionSupported(extensionProperties, RequiredExtension(dependencies[ndx].first)) &&
775                         !isExtensionSupported(extensionProperties, RequiredExtension(dependencies[ndx].second)))
776                 {
777                         results.fail("Extension " + string(dependencies[ndx].first) + " is missing dependency: " + string(dependencies[ndx].second));
778                 }
779         }
780 }
781
782 void checkDeviceExtensionDependencies(tcu::ResultCollector& results,
783                                                                           int dependencyLength,
784                                                                           const std::pair<const char*, const char*>* dependencies,
785                                                                           const vector<VkExtensionProperties>& instanceExtensionProperties,
786                                                                           const vector<VkExtensionProperties>& deviceExtensionProperties)
787 {
788         for (int ndx = 0; ndx < dependencyLength; ndx++)
789         {
790                 if (isExtensionSupported(deviceExtensionProperties, RequiredExtension(dependencies[ndx].first)) &&
791                         !isExtensionSupported(deviceExtensionProperties, RequiredExtension(dependencies[ndx].second)) &&
792                         !isExtensionSupported(instanceExtensionProperties, RequiredExtension(dependencies[ndx].second)))
793                 {
794                         results.fail("Extension " + string(dependencies[ndx].first) + " is missing dependency: " + string(dependencies[ndx].second));
795                 }
796         }
797 }
798
799 tcu::TestStatus enumerateInstanceLayers (Context& context)
800 {
801         TestLog&                                                log                                     = context.getTestContext().getLog();
802         tcu::ResultCollector                    results                         (log);
803         const vector<VkLayerProperties> properties                      = enumerateInstanceLayerProperties(context.getPlatformInterface());
804         vector<string>                                  layerNames;
805
806         for (size_t ndx = 0; ndx < properties.size(); ndx++)
807         {
808                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
809
810                 layerNames.push_back(properties[ndx].layerName);
811         }
812
813         checkDuplicateLayers(results, layerNames);
814         CheckEnumerateInstanceLayerPropertiesIncompleteResult()(context, results, layerNames.size());
815
816         return tcu::TestStatus(results.getResult(), results.getMessage());
817 }
818
819 tcu::TestStatus enumerateInstanceExtensions (Context& context)
820 {
821         TestLog&                                log             = context.getTestContext().getLog();
822         tcu::ResultCollector    results (log);
823
824         {
825                 const ScopedLogSection                          section         (log, "Global", "Global Extensions");
826                 const vector<VkExtensionProperties>     properties      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), DE_NULL);
827                 vector<string>                                          extensionNames;
828
829                 for (size_t ndx = 0; ndx < properties.size(); ndx++)
830                 {
831                         log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
832
833                         extensionNames.push_back(properties[ndx].extensionName);
834                 }
835
836                 checkInstanceExtensions(results, extensionNames);
837                 CheckEnumerateInstanceExtensionPropertiesIncompleteResult()(context, results, properties.size());
838
839                 if (context.contextSupports(vk::ApiVersion(1, 1, 0)))
840                 {
841                         checkInstanceExtensionDependencies(results,
842                                                                                            DE_LENGTH_OF_ARRAY(instanceExtensionDependencies_1_1),
843                                                                                            instanceExtensionDependencies_1_1, properties);
844                 }
845                 else if (context.contextSupports(vk::ApiVersion(1, 0, 0)))
846                 {
847                         checkInstanceExtensionDependencies(results,
848                                                                                            DE_LENGTH_OF_ARRAY(instanceExtensionDependencies_1_0),
849                                                                                            instanceExtensionDependencies_1_0, properties);
850                 }
851         }
852
853         {
854                 const vector<VkLayerProperties> layers  = enumerateInstanceLayerProperties(context.getPlatformInterface());
855
856                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
857                 {
858                         const ScopedLogSection                          section                         (log, layer->layerName, string("Layer: ") + layer->layerName);
859                         const vector<VkExtensionProperties>     properties                      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), layer->layerName);
860                         vector<string>                                          extensionNames;
861
862                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
863                         {
864                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
865
866                                 extensionNames.push_back(properties[extNdx].extensionName);
867                         }
868
869                         checkInstanceExtensions(results, extensionNames);
870                         CheckEnumerateInstanceExtensionPropertiesIncompleteResult(layer->layerName)(context, results, properties.size());
871                 }
872         }
873
874         return tcu::TestStatus(results.getResult(), results.getMessage());
875 }
876
877 tcu::TestStatus testNoKhxExtensions (Context& context)
878 {
879         VkPhysicalDevice                        physicalDevice  = context.getPhysicalDevice();
880         const PlatformInterface&        vkp                             = context.getPlatformInterface();
881         const InstanceInterface&        vki                             = context.getInstanceInterface();
882
883         tcu::ResultCollector            results(context.getTestContext().getLog());
884         bool                                            testSucceeded = true;
885         deUint32                                        instanceExtensionsCount;
886         deUint32                                        deviceExtensionsCount;
887
888         // grab number of instance and device extensions
889         vkp.enumerateInstanceExtensionProperties(DE_NULL, &instanceExtensionsCount, DE_NULL);
890         vki.enumerateDeviceExtensionProperties(physicalDevice, DE_NULL, &deviceExtensionsCount, DE_NULL);
891         vector<VkExtensionProperties> extensionsProperties(instanceExtensionsCount + deviceExtensionsCount);
892
893         // grab instance and device extensions into single vector
894         if (instanceExtensionsCount)
895                 vkp.enumerateInstanceExtensionProperties(DE_NULL, &instanceExtensionsCount, &extensionsProperties[0]);
896         if (deviceExtensionsCount)
897                 vki.enumerateDeviceExtensionProperties(physicalDevice, DE_NULL, &deviceExtensionsCount, &extensionsProperties[instanceExtensionsCount]);
898
899         // iterate over all extensions and verify their names
900         vector<VkExtensionProperties>::const_iterator extension = extensionsProperties.begin();
901         while (extension != extensionsProperties.end())
902         {
903                 // KHX author ID is no longer used, all KHX extensions have been promoted to KHR status
904                 std::string extensionName(extension->extensionName);
905                 bool caseFailed = de::beginsWith(extensionName, "VK_KHX_");
906                 if (caseFailed)
907                 {
908                         results.fail("Invalid extension name " + extensionName);
909                         testSucceeded = false;
910                 }
911                 ++extension;
912         }
913
914         if (testSucceeded)
915                 return tcu::TestStatus::pass("No extensions begining with \"VK_KHX\"");
916         return tcu::TestStatus::fail("One or more extensions begins with \"VK_KHX\"");
917 }
918
919 tcu::TestStatus enumerateDeviceLayers (Context& context)
920 {
921         TestLog&                                                log                     = context.getTestContext().getLog();
922         tcu::ResultCollector                    results         (log);
923         const vector<VkLayerProperties> properties      = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
924         vector<string>                                  layerNames;
925
926         for (size_t ndx = 0; ndx < properties.size(); ndx++)
927         {
928                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
929
930                 layerNames.push_back(properties[ndx].layerName);
931         }
932
933         checkDuplicateLayers(results, layerNames);
934         CheckEnumerateDeviceLayerPropertiesIncompleteResult()(context, results, layerNames.size());
935
936         return tcu::TestStatus(results.getResult(), results.getMessage());
937 }
938
939 tcu::TestStatus enumerateDeviceExtensions (Context& context)
940 {
941         TestLog&                                log             = context.getTestContext().getLog();
942         tcu::ResultCollector    results (log);
943
944         {
945                 const ScopedLogSection                          section                                         (log, "Global", "Global Extensions");
946                 const vector<VkExtensionProperties>     instanceExtensionProperties     = enumerateInstanceExtensionProperties(context.getPlatformInterface(), DE_NULL);
947                 const vector<VkExtensionProperties>     deviceExtensionProperties       = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), DE_NULL);
948                 vector<string>                                          deviceExtensionNames;
949
950                 for (size_t ndx = 0; ndx < deviceExtensionProperties.size(); ndx++)
951                 {
952                         log << TestLog::Message << ndx << ": " << deviceExtensionProperties[ndx] << TestLog::EndMessage;
953
954                         deviceExtensionNames.push_back(deviceExtensionProperties[ndx].extensionName);
955                 }
956
957                 checkDeviceExtensions(results, deviceExtensionNames);
958                 CheckEnumerateDeviceExtensionPropertiesIncompleteResult()(context, results, deviceExtensionProperties.size());
959
960                 if (context.contextSupports(vk::ApiVersion(1, 1, 0)))
961                 {
962                         checkDeviceExtensionDependencies(results,
963                                                                                          DE_LENGTH_OF_ARRAY(deviceExtensionDependencies_1_1),
964                                                                                          deviceExtensionDependencies_1_1,
965                                                                                          instanceExtensionProperties,
966                                                                                          deviceExtensionProperties);
967                 }
968                 else if (context.contextSupports(vk::ApiVersion(1, 0, 0)))
969                 {
970                         checkDeviceExtensionDependencies(results,
971                                                                                          DE_LENGTH_OF_ARRAY(deviceExtensionDependencies_1_0),
972                                                                                          deviceExtensionDependencies_1_0,
973                                                                                          instanceExtensionProperties,
974                                                                                          deviceExtensionProperties);
975                 }
976         }
977
978         {
979                 const vector<VkLayerProperties> layers  = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
980
981                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
982                 {
983                         const ScopedLogSection                          section         (log, layer->layerName, string("Layer: ") + layer->layerName);
984                         const vector<VkExtensionProperties>     properties      = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), layer->layerName);
985                         vector<string>                                          extensionNames;
986
987                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
988                         {
989                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
990
991
992                                 extensionNames.push_back(properties[extNdx].extensionName);
993                         }
994
995                         checkDeviceExtensions(results, extensionNames);
996                         CheckEnumerateDeviceExtensionPropertiesIncompleteResult(layer->layerName)(context, results, properties.size());
997                 }
998         }
999
1000         return tcu::TestStatus(results.getResult(), results.getMessage());
1001 }
1002
1003 #define VK_SIZE_OF(STRUCT, MEMBER)                                      (sizeof(((STRUCT*)0)->MEMBER))
1004 #define OFFSET_TABLE_ENTRY(STRUCT, MEMBER)                      { (size_t)DE_OFFSET_OF(STRUCT, MEMBER), VK_SIZE_OF(STRUCT, MEMBER) }
1005
1006 tcu::TestStatus deviceFeatures (Context& context)
1007 {
1008         using namespace ValidateQueryBits;
1009
1010         TestLog&                                                log                     = context.getTestContext().getLog();
1011         VkPhysicalDeviceFeatures*               features;
1012         deUint8                                                 buffer[sizeof(VkPhysicalDeviceFeatures) + GUARD_SIZE];
1013
1014         const QueryMemberTableEntry featureOffsetTable[] =
1015         {
1016                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, robustBufferAccess),
1017                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fullDrawIndexUint32),
1018                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, imageCubeArray),
1019                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, independentBlend),
1020                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, geometryShader),
1021                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, tessellationShader),
1022                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sampleRateShading),
1023                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, dualSrcBlend),
1024                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, logicOp),
1025                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, multiDrawIndirect),
1026                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, drawIndirectFirstInstance),
1027                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthClamp),
1028                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthBiasClamp),
1029                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fillModeNonSolid),
1030                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, depthBounds),
1031                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, wideLines),
1032                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, largePoints),
1033                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, alphaToOne),
1034                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, multiViewport),
1035                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, samplerAnisotropy),
1036                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionETC2),
1037                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionASTC_LDR),
1038                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, textureCompressionBC),
1039                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, occlusionQueryPrecise),
1040                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, pipelineStatisticsQuery),
1041                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, vertexPipelineStoresAndAtomics),
1042                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, fragmentStoresAndAtomics),
1043                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderTessellationAndGeometryPointSize),
1044                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderImageGatherExtended),
1045                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageExtendedFormats),
1046                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageMultisample),
1047                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageReadWithoutFormat),
1048                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageWriteWithoutFormat),
1049                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderUniformBufferArrayDynamicIndexing),
1050                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderSampledImageArrayDynamicIndexing),
1051                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageBufferArrayDynamicIndexing),
1052                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderStorageImageArrayDynamicIndexing),
1053                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderClipDistance),
1054                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderCullDistance),
1055                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderFloat64),
1056                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderInt64),
1057                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderInt16),
1058                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderResourceResidency),
1059                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, shaderResourceMinLod),
1060                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseBinding),
1061                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyBuffer),
1062                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyImage2D),
1063                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyImage3D),
1064                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency2Samples),
1065                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency4Samples),
1066                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency8Samples),
1067                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidency16Samples),
1068                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, sparseResidencyAliased),
1069                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, variableMultisampleRate),
1070                 OFFSET_TABLE_ENTRY(VkPhysicalDeviceFeatures, inheritedQueries),
1071                 { 0, 0 }
1072         };
1073
1074         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
1075         features = reinterpret_cast<VkPhysicalDeviceFeatures*>(buffer);
1076
1077         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), features);
1078
1079         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
1080                 << TestLog::Message << *features << TestLog::EndMessage;
1081
1082         // Requirements and dependencies
1083         {
1084                 if (!features->robustBufferAccess)
1085                         return tcu::TestStatus::fail("robustBufferAccess is not supported");
1086
1087                 // multiViewport requires MultiViewport (SPIR-V capability) support, which depends on Geometry
1088                 if (features->multiViewport && !features->geometryShader)
1089                         return tcu::TestStatus::fail("multiViewport is supported but geometryShader is not");
1090         }
1091
1092         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
1093         {
1094                 if (buffer[ndx + sizeof(VkPhysicalDeviceFeatures)] != GUARD_VALUE)
1095                 {
1096                         log << TestLog::Message << "deviceFeatures - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
1097                         return tcu::TestStatus::fail("deviceFeatures buffer overflow");
1098                 }
1099         }
1100
1101         if (!validateInitComplete(context.getPhysicalDevice(), &InstanceInterface::getPhysicalDeviceFeatures, context.getInstanceInterface(), featureOffsetTable))
1102         {
1103                 log << TestLog::Message << "deviceFeatures - VkPhysicalDeviceFeatures not completely initialized" << TestLog::EndMessage;
1104                 return tcu::TestStatus::fail("deviceFeatures incomplete initialization");
1105         }
1106
1107         return tcu::TestStatus::pass("Query succeeded");
1108 }
1109
1110 static const ValidateQueryBits::QueryMemberTableEntry s_physicalDevicePropertiesOffsetTable[] =
1111 {
1112         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, apiVersion),
1113         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, driverVersion),
1114         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, vendorID),
1115         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, deviceID),
1116         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, deviceType),
1117         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, pipelineCacheUUID),
1118         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimension1D),
1119         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimension2D),
1120         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimension3D),
1121         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageDimensionCube),
1122         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxImageArrayLayers),
1123         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTexelBufferElements),
1124         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxUniformBufferRange),
1125         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxStorageBufferRange),
1126         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPushConstantsSize),
1127         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxMemoryAllocationCount),
1128         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSamplerAllocationCount),
1129         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.bufferImageGranularity),
1130         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sparseAddressSpaceSize),
1131         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxBoundDescriptorSets),
1132         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorSamplers),
1133         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorUniformBuffers),
1134         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorStorageBuffers),
1135         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorSampledImages),
1136         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorStorageImages),
1137         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageDescriptorInputAttachments),
1138         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxPerStageResources),
1139         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetSamplers),
1140         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetUniformBuffers),
1141         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetUniformBuffersDynamic),
1142         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetStorageBuffers),
1143         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetStorageBuffersDynamic),
1144         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetSampledImages),
1145         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetStorageImages),
1146         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDescriptorSetInputAttachments),
1147         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputAttributes),
1148         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputBindings),
1149         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputAttributeOffset),
1150         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexInputBindingStride),
1151         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxVertexOutputComponents),
1152         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationGenerationLevel),
1153         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationPatchSize),
1154         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlPerVertexInputComponents),
1155         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlPerVertexOutputComponents),
1156         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlPerPatchOutputComponents),
1157         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationControlTotalOutputComponents),
1158         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationEvaluationInputComponents),
1159         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTessellationEvaluationOutputComponents),
1160         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryShaderInvocations),
1161         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryInputComponents),
1162         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryOutputComponents),
1163         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryOutputVertices),
1164         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxGeometryTotalOutputComponents),
1165         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentInputComponents),
1166         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentOutputAttachments),
1167         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentDualSrcAttachments),
1168         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFragmentCombinedOutputResources),
1169         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeSharedMemorySize),
1170         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeWorkGroupCount[3]),
1171         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeWorkGroupInvocations),
1172         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxComputeWorkGroupSize[3]),
1173         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.subPixelPrecisionBits),
1174         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.subTexelPrecisionBits),
1175         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.mipmapPrecisionBits),
1176         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDrawIndexedIndexValue),
1177         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxDrawIndirectCount),
1178         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSamplerLodBias),
1179         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSamplerAnisotropy),
1180         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxViewports),
1181         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxViewportDimensions[2]),
1182         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.viewportBoundsRange[2]),
1183         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.viewportSubPixelBits),
1184         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minMemoryMapAlignment),
1185         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minTexelBufferOffsetAlignment),
1186         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minUniformBufferOffsetAlignment),
1187         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minStorageBufferOffsetAlignment),
1188         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minTexelOffset),
1189         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTexelOffset),
1190         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minTexelGatherOffset),
1191         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxTexelGatherOffset),
1192         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.minInterpolationOffset),
1193         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxInterpolationOffset),
1194         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.subPixelInterpolationOffsetBits),
1195         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFramebufferWidth),
1196         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFramebufferHeight),
1197         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxFramebufferLayers),
1198         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferColorSampleCounts),
1199         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferDepthSampleCounts),
1200         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferStencilSampleCounts),
1201         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.framebufferNoAttachmentsSampleCounts),
1202         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxColorAttachments),
1203         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageColorSampleCounts),
1204         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageIntegerSampleCounts),
1205         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageDepthSampleCounts),
1206         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.sampledImageStencilSampleCounts),
1207         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.storageImageSampleCounts),
1208         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxSampleMaskWords),
1209         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.timestampComputeAndGraphics),
1210         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.timestampPeriod),
1211         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxClipDistances),
1212         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxCullDistances),
1213         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.maxCombinedClipAndCullDistances),
1214         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.discreteQueuePriorities),
1215         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.pointSizeRange[2]),
1216         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.lineWidthRange[2]),
1217         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.pointSizeGranularity),
1218         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.lineWidthGranularity),
1219         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.strictLines),
1220         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.standardSampleLocations),
1221         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.optimalBufferCopyOffsetAlignment),
1222         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.optimalBufferCopyRowPitchAlignment),
1223         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, limits.nonCoherentAtomSize),
1224         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyStandard2DBlockShape),
1225         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyStandard2DMultisampleBlockShape),
1226         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyStandard3DBlockShape),
1227         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyAlignedMipSize),
1228         OFFSET_TABLE_ENTRY(VkPhysicalDeviceProperties, sparseProperties.residencyNonResidentStrict),
1229         { 0, 0 }
1230 };
1231
1232 tcu::TestStatus deviceProperties (Context& context)
1233 {
1234         using namespace ValidateQueryBits;
1235
1236         TestLog&                                                log                     = context.getTestContext().getLog();
1237         VkPhysicalDeviceProperties*             props;
1238         VkPhysicalDeviceFeatures                features;
1239         deUint8                                                 buffer[sizeof(VkPhysicalDeviceProperties) + GUARD_SIZE];
1240
1241         props = reinterpret_cast<VkPhysicalDeviceProperties*>(buffer);
1242         deMemset(props, GUARD_VALUE, sizeof(buffer));
1243
1244         context.getInstanceInterface().getPhysicalDeviceProperties(context.getPhysicalDevice(), props);
1245         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &features);
1246
1247         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
1248                 << TestLog::Message << *props << TestLog::EndMessage;
1249
1250         if (!validateFeatureLimits(props, &features, log))
1251                 return tcu::TestStatus::fail("deviceProperties - feature limits failed");
1252
1253         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
1254         {
1255                 if (buffer[ndx + sizeof(VkPhysicalDeviceProperties)] != GUARD_VALUE)
1256                 {
1257                         log << TestLog::Message << "deviceProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
1258                         return tcu::TestStatus::fail("deviceProperties buffer overflow");
1259                 }
1260         }
1261
1262         if (!validateInitComplete(context.getPhysicalDevice(), &InstanceInterface::getPhysicalDeviceProperties, context.getInstanceInterface(), s_physicalDevicePropertiesOffsetTable))
1263         {
1264                 log << TestLog::Message << "deviceProperties - VkPhysicalDeviceProperties not completely initialized" << TestLog::EndMessage;
1265                 return tcu::TestStatus::fail("deviceProperties incomplete initialization");
1266         }
1267
1268         // Check if deviceName string is properly terminated.
1269         if (deStrnlen(props->deviceName, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE) == VK_MAX_PHYSICAL_DEVICE_NAME_SIZE)
1270         {
1271                 log << TestLog::Message << "deviceProperties - VkPhysicalDeviceProperties deviceName not properly initialized" << TestLog::EndMessage;
1272                 return tcu::TestStatus::fail("deviceProperties incomplete initialization");
1273         }
1274
1275         {
1276                 const ApiVersion deviceVersion = unpackVersion(props->apiVersion);
1277                 const ApiVersion deqpVersion = unpackVersion(VK_API_VERSION_1_1);
1278
1279                 if (deviceVersion.majorNum != deqpVersion.majorNum)
1280                 {
1281                         log << TestLog::Message << "deviceProperties - API Major Version " << deviceVersion.majorNum << " is not valid" << TestLog::EndMessage;
1282                         return tcu::TestStatus::fail("deviceProperties apiVersion not valid");
1283                 }
1284
1285                 if (deviceVersion.minorNum > deqpVersion.minorNum)
1286                 {
1287                         log << TestLog::Message << "deviceProperties - API Minor Version " << deviceVersion.minorNum << " is not valid for this version of dEQP" << TestLog::EndMessage;
1288                         return tcu::TestStatus::fail("deviceProperties apiVersion not valid");
1289                 }
1290         }
1291
1292         return tcu::TestStatus::pass("DeviceProperites query succeeded");
1293 }
1294
1295 tcu::TestStatus deviceQueueFamilyProperties (Context& context)
1296 {
1297         TestLog&                                                                log                                     = context.getTestContext().getLog();
1298         const vector<VkQueueFamilyProperties>   queueProperties         = getPhysicalDeviceQueueFamilyProperties(context.getInstanceInterface(), context.getPhysicalDevice());
1299
1300         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage;
1301
1302         for (size_t queueNdx = 0; queueNdx < queueProperties.size(); queueNdx++)
1303                 log << TestLog::Message << queueNdx << ": " << queueProperties[queueNdx] << TestLog::EndMessage;
1304
1305         return tcu::TestStatus::pass("Querying queue properties succeeded");
1306 }
1307
1308 tcu::TestStatus deviceMemoryProperties (Context& context)
1309 {
1310         TestLog&                                                        log                     = context.getTestContext().getLog();
1311         VkPhysicalDeviceMemoryProperties*       memProps;
1312         deUint8                                                         buffer[sizeof(VkPhysicalDeviceMemoryProperties) + GUARD_SIZE];
1313
1314         memProps = reinterpret_cast<VkPhysicalDeviceMemoryProperties*>(buffer);
1315         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
1316
1317         context.getInstanceInterface().getPhysicalDeviceMemoryProperties(context.getPhysicalDevice(), memProps);
1318
1319         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
1320                 << TestLog::Message << *memProps << TestLog::EndMessage;
1321
1322         for (deInt32 ndx = 0; ndx < GUARD_SIZE; ndx++)
1323         {
1324                 if (buffer[ndx + sizeof(VkPhysicalDeviceMemoryProperties)] != GUARD_VALUE)
1325                 {
1326                         log << TestLog::Message << "deviceMemoryProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
1327                         return tcu::TestStatus::fail("deviceMemoryProperties buffer overflow");
1328                 }
1329         }
1330
1331         if (memProps->memoryHeapCount >= VK_MAX_MEMORY_HEAPS)
1332         {
1333                 log << TestLog::Message << "deviceMemoryProperties - HeapCount larger than " << (deUint32)VK_MAX_MEMORY_HEAPS << TestLog::EndMessage;
1334                 return tcu::TestStatus::fail("deviceMemoryProperties HeapCount too large");
1335         }
1336
1337         if (memProps->memoryHeapCount == 1)
1338         {
1339                 if ((memProps->memoryHeaps[0].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) == 0)
1340                 {
1341                         log << TestLog::Message << "deviceMemoryProperties - Single heap is not marked DEVICE_LOCAL" << TestLog::EndMessage;
1342                         return tcu::TestStatus::fail("deviceMemoryProperties invalid HeapFlags");
1343                 }
1344         }
1345
1346         const VkMemoryPropertyFlags validPropertyFlags[] =
1347         {
1348                 0,
1349                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
1350                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1351                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
1352                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1353                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1354                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT,
1355                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_CACHED_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT,
1356                 VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT|VK_MEMORY_PROPERTY_LAZILY_ALLOCATED_BIT
1357         };
1358
1359         const VkMemoryPropertyFlags requiredPropertyFlags[] =
1360         {
1361                 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT|VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
1362         };
1363
1364         bool requiredFlagsFound[DE_LENGTH_OF_ARRAY(requiredPropertyFlags)];
1365         std::fill(DE_ARRAY_BEGIN(requiredFlagsFound), DE_ARRAY_END(requiredFlagsFound), false);
1366
1367         for (deUint32 memoryNdx = 0; memoryNdx < memProps->memoryTypeCount; memoryNdx++)
1368         {
1369                 bool validPropTypeFound = false;
1370
1371                 if (memProps->memoryTypes[memoryNdx].heapIndex >= memProps->memoryHeapCount)
1372                 {
1373                         log << TestLog::Message << "deviceMemoryProperties - heapIndex " << memProps->memoryTypes[memoryNdx].heapIndex << " larger than heapCount" << TestLog::EndMessage;
1374                         return tcu::TestStatus::fail("deviceMemoryProperties - invalid heapIndex");
1375                 }
1376
1377                 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;
1378
1379                 for (const VkMemoryPropertyFlags* requiredFlagsIterator = DE_ARRAY_BEGIN(requiredPropertyFlags); requiredFlagsIterator != DE_ARRAY_END(requiredPropertyFlags); requiredFlagsIterator++)
1380                         if ((memProps->memoryTypes[memoryNdx].propertyFlags & *requiredFlagsIterator) == *requiredFlagsIterator)
1381                                 requiredFlagsFound[requiredFlagsIterator - DE_ARRAY_BEGIN(requiredPropertyFlags)] = true;
1382
1383                 if (de::contains(DE_ARRAY_BEGIN(validPropertyFlags), DE_ARRAY_END(validPropertyFlags), memProps->memoryTypes[memoryNdx].propertyFlags & bitsToCheck))
1384                         validPropTypeFound = true;
1385
1386                 if (!validPropTypeFound)
1387                 {
1388                         log << TestLog::Message << "deviceMemoryProperties - propertyFlags "
1389                                 << memProps->memoryTypes[memoryNdx].propertyFlags << " not valid" << TestLog::EndMessage;
1390                         return tcu::TestStatus::fail("deviceMemoryProperties propertyFlags not valid");
1391                 }
1392
1393                 if (memProps->memoryTypes[memoryNdx].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)
1394                 {
1395                         if ((memProps->memoryHeaps[memProps->memoryTypes[memoryNdx].heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) == 0)
1396                         {
1397                                 log << TestLog::Message << "deviceMemoryProperties - DEVICE_LOCAL memory type references heap which is not DEVICE_LOCAL" << TestLog::EndMessage;
1398                                 return tcu::TestStatus::fail("deviceMemoryProperties inconsistent memoryType and HeapFlags");
1399                         }
1400                 }
1401                 else
1402                 {
1403                         if (memProps->memoryHeaps[memProps->memoryTypes[memoryNdx].heapIndex].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
1404                         {
1405                                 log << TestLog::Message << "deviceMemoryProperties - non-DEVICE_LOCAL memory type references heap with is DEVICE_LOCAL" << TestLog::EndMessage;
1406                                 return tcu::TestStatus::fail("deviceMemoryProperties inconsistent memoryType and HeapFlags");
1407                         }
1408                 }
1409         }
1410
1411         bool* requiredFlagsFoundIterator = std::find(DE_ARRAY_BEGIN(requiredFlagsFound), DE_ARRAY_END(requiredFlagsFound), false);
1412         if (requiredFlagsFoundIterator != DE_ARRAY_END(requiredFlagsFound))
1413         {
1414                 DE_ASSERT(requiredFlagsFoundIterator - DE_ARRAY_BEGIN(requiredFlagsFound) <= DE_LENGTH_OF_ARRAY(requiredPropertyFlags));
1415                 log << TestLog::Message << "deviceMemoryProperties - required property flags "
1416                         << getMemoryPropertyFlagsStr(requiredPropertyFlags[requiredFlagsFoundIterator - DE_ARRAY_BEGIN(requiredFlagsFound)]) << " not found" << TestLog::EndMessage;
1417
1418                 return tcu::TestStatus::fail("deviceMemoryProperties propertyFlags not valid");
1419         }
1420
1421         return tcu::TestStatus::pass("Querying memory properties succeeded");
1422 }
1423
1424 tcu::TestStatus deviceGroupPeerMemoryFeatures (Context& context)
1425 {
1426         TestLog&                                                        log                                             = context.getTestContext().getLog();
1427         const PlatformInterface&                        vkp                                             = context.getPlatformInterface();
1428         const Unique<VkInstance>                        instance                                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_device_group_creation"));
1429         const InstanceDriver                            vki                                             (vkp, *instance);
1430         const tcu::CommandLine&                         cmdLine                                 = context.getTestContext().getCommandLine();
1431         const deUint32                                          devGroupIdx                             = cmdLine.getVKDeviceGroupId() - 1;
1432         const deUint32                                          deviceIdx                               = vk::chooseDeviceIndex(context.getInstanceInterface(), *instance, cmdLine);
1433         const float                                                     queuePriority                   = 1.0f;
1434         VkPhysicalDeviceMemoryProperties        memProps;
1435         VkPeerMemoryFeatureFlags*                       peerMemFeatures;
1436         deUint8                                                         buffer                                  [sizeof(VkPeerMemoryFeatureFlags) + GUARD_SIZE];
1437         deUint32                                                        numPhysicalDevices              = 0;
1438         deUint32                                                        queueFamilyIndex                = 0;
1439
1440         const vector<VkPhysicalDeviceGroupProperties>           deviceGroupProps = enumeratePhysicalDeviceGroups(vki, *instance);
1441         std::vector<const char*>                                                        deviceExtensions;
1442         deviceExtensions.push_back("VK_KHR_device_group");
1443
1444         if (!isCoreDeviceExtension(context.getUsedApiVersion(), "VK_KHR_device_group"))
1445                 deviceExtensions.push_back("VK_KHR_device_group");
1446
1447         const std::vector<VkQueueFamilyProperties>      queueProps              = getPhysicalDeviceQueueFamilyProperties(vki, deviceGroupProps[devGroupIdx].physicalDevices[deviceIdx]);
1448         for (size_t queueNdx = 0; queueNdx < queueProps.size(); queueNdx++)
1449         {
1450                 if (queueProps[queueNdx].queueFlags & VK_QUEUE_GRAPHICS_BIT)
1451                         queueFamilyIndex = (deUint32)queueNdx;
1452         }
1453         const VkDeviceQueueCreateInfo           deviceQueueCreateInfo   =
1454         {
1455                 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,                     //type
1456                 DE_NULL,                                                                                        //pNext
1457                 (VkDeviceQueueCreateFlags)0u,                                           //flags
1458                 queueFamilyIndex,                                                                       //queueFamilyIndex;
1459                 1u,                                                                                                     //queueCount;
1460                 &queuePriority,                                                                         //pQueuePriorities;
1461         };
1462
1463         // Need atleast 2 devices for peer memory features
1464         numPhysicalDevices = deviceGroupProps[devGroupIdx].physicalDeviceCount;
1465         if (numPhysicalDevices < 2)
1466                 TCU_THROW(NotSupportedError, "Need a device Group with at least 2 physical devices.");
1467
1468         // Create device groups
1469         const VkDeviceGroupDeviceCreateInfo                                             deviceGroupInfo =
1470         {
1471                 VK_STRUCTURE_TYPE_DEVICE_GROUP_DEVICE_CREATE_INFO,      //stype
1472                 DE_NULL,                                                                                        //pNext
1473                 deviceGroupProps[devGroupIdx].physicalDeviceCount,      //physicalDeviceCount
1474                 deviceGroupProps[devGroupIdx].physicalDevices           //physicalDevices
1475         };
1476         const VkDeviceCreateInfo                                                                deviceCreateInfo =
1477         {
1478                 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,                                                   //sType;
1479                 &deviceGroupInfo,                                                                                               //pNext;
1480                 (VkDeviceCreateFlags)0u,                                                                                //flags
1481                 1,                                                                                                                              //queueRecordCount;
1482                 &deviceQueueCreateInfo,                                                                                 //pRequestedQueues;
1483                 0,                                                                                                                              //layerCount;
1484                 DE_NULL,                                                                                                                //ppEnabledLayerNames;
1485                 deUint32(deviceExtensions.size()),                                                              //extensionCount;
1486                 (deviceExtensions.empty() ? DE_NULL : &deviceExtensions[0]),    //ppEnabledExtensionNames;
1487                 DE_NULL,                                                                                                                //pEnabledFeatures;
1488         };
1489
1490         Move<VkDevice>          deviceGroup = createDevice(vkp, *instance, vki, deviceGroupProps[devGroupIdx].physicalDevices[deviceIdx], &deviceCreateInfo);
1491         const DeviceDriver      vk      (vkp, *instance, *deviceGroup);
1492         context.getInstanceInterface().getPhysicalDeviceMemoryProperties(deviceGroupProps[devGroupIdx].physicalDevices[deviceIdx], &memProps);
1493
1494         peerMemFeatures = reinterpret_cast<VkPeerMemoryFeatureFlags*>(buffer);
1495         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
1496
1497         for (deUint32 heapIndex = 0; heapIndex < memProps.memoryHeapCount; heapIndex++)
1498         {
1499                 for (deUint32 localDeviceIndex = 0; localDeviceIndex < numPhysicalDevices; localDeviceIndex++)
1500                 {
1501                         for (deUint32 remoteDeviceIndex = 0; remoteDeviceIndex < numPhysicalDevices; remoteDeviceIndex++)
1502                         {
1503                                 if (localDeviceIndex != remoteDeviceIndex)
1504                                 {
1505                                         vk.getDeviceGroupPeerMemoryFeatures(deviceGroup.get(), heapIndex, localDeviceIndex, remoteDeviceIndex, peerMemFeatures);
1506
1507                                         // Check guard
1508                                         for (deInt32 ndx = 0; ndx < GUARD_SIZE; ndx++)
1509                                         {
1510                                                 if (buffer[ndx + sizeof(VkPeerMemoryFeatureFlags)] != GUARD_VALUE)
1511                                                 {
1512                                                         log << TestLog::Message << "deviceGroupPeerMemoryFeatures - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
1513                                                         return tcu::TestStatus::fail("deviceGroupPeerMemoryFeatures buffer overflow");
1514                                                 }
1515                                         }
1516
1517                                         VkPeerMemoryFeatureFlags requiredFlag = VK_PEER_MEMORY_FEATURE_COPY_DST_BIT;
1518                                         VkPeerMemoryFeatureFlags maxValidFlag = VK_PEER_MEMORY_FEATURE_COPY_SRC_BIT|VK_PEER_MEMORY_FEATURE_COPY_DST_BIT|
1519                                                                                                                                 VK_PEER_MEMORY_FEATURE_GENERIC_SRC_BIT|VK_PEER_MEMORY_FEATURE_GENERIC_DST_BIT;
1520                                         if ((!(*peerMemFeatures & requiredFlag)) ||
1521                                                 *peerMemFeatures > maxValidFlag)
1522                                                 return tcu::TestStatus::fail("deviceGroupPeerMemoryFeatures invalid flag");
1523
1524                                         log << TestLog::Message << "deviceGroup = " << deviceGroup.get() << TestLog::EndMessage
1525                                                 << TestLog::Message << "heapIndex = " << heapIndex << TestLog::EndMessage
1526                                                 << TestLog::Message << "localDeviceIndex = " << localDeviceIndex << TestLog::EndMessage
1527                                                 << TestLog::Message << "remoteDeviceIndex = " << remoteDeviceIndex << TestLog::EndMessage
1528                                                 << TestLog::Message << "PeerMemoryFeatureFlags = " << *peerMemFeatures << TestLog::EndMessage;
1529                                 }
1530                         } // remote device
1531                 } // local device
1532         } // heap Index
1533
1534         return tcu::TestStatus::pass("Querying deviceGroup peer memory features succeeded");
1535 }
1536
1537 // \todo [2016-01-22 pyry] Optimize by doing format -> flags mapping instead
1538
1539 VkFormatFeatureFlags getRequiredOptimalTilingFeatures (VkFormat format)
1540 {
1541         static const VkFormat s_requiredSampledImageBlitSrcFormats[] =
1542         {
1543                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1544                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1545                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1546                 VK_FORMAT_R8_UNORM,
1547                 VK_FORMAT_R8_SNORM,
1548                 VK_FORMAT_R8_UINT,
1549                 VK_FORMAT_R8_SINT,
1550                 VK_FORMAT_R8G8_UNORM,
1551                 VK_FORMAT_R8G8_SNORM,
1552                 VK_FORMAT_R8G8_UINT,
1553                 VK_FORMAT_R8G8_SINT,
1554                 VK_FORMAT_R8G8B8A8_UNORM,
1555                 VK_FORMAT_R8G8B8A8_SNORM,
1556                 VK_FORMAT_R8G8B8A8_UINT,
1557                 VK_FORMAT_R8G8B8A8_SINT,
1558                 VK_FORMAT_R8G8B8A8_SRGB,
1559                 VK_FORMAT_B8G8R8A8_UNORM,
1560                 VK_FORMAT_B8G8R8A8_SRGB,
1561                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1562                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1563                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1564                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1565                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1566                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1567                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1568                 VK_FORMAT_R16_UINT,
1569                 VK_FORMAT_R16_SINT,
1570                 VK_FORMAT_R16_SFLOAT,
1571                 VK_FORMAT_R16G16_UINT,
1572                 VK_FORMAT_R16G16_SINT,
1573                 VK_FORMAT_R16G16_SFLOAT,
1574                 VK_FORMAT_R16G16B16A16_UINT,
1575                 VK_FORMAT_R16G16B16A16_SINT,
1576                 VK_FORMAT_R16G16B16A16_SFLOAT,
1577                 VK_FORMAT_R32_UINT,
1578                 VK_FORMAT_R32_SINT,
1579                 VK_FORMAT_R32_SFLOAT,
1580                 VK_FORMAT_R32G32_UINT,
1581                 VK_FORMAT_R32G32_SINT,
1582                 VK_FORMAT_R32G32_SFLOAT,
1583                 VK_FORMAT_R32G32B32A32_UINT,
1584                 VK_FORMAT_R32G32B32A32_SINT,
1585                 VK_FORMAT_R32G32B32A32_SFLOAT,
1586                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1587                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1588                 VK_FORMAT_D16_UNORM,
1589                 VK_FORMAT_D32_SFLOAT
1590         };
1591         static const VkFormat s_requiredSampledImageFilterLinearFormats[] =
1592         {
1593                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1594                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1595                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1596                 VK_FORMAT_R8_UNORM,
1597                 VK_FORMAT_R8_SNORM,
1598                 VK_FORMAT_R8G8_UNORM,
1599                 VK_FORMAT_R8G8_SNORM,
1600                 VK_FORMAT_R8G8B8A8_UNORM,
1601                 VK_FORMAT_R8G8B8A8_SNORM,
1602                 VK_FORMAT_R8G8B8A8_SRGB,
1603                 VK_FORMAT_B8G8R8A8_UNORM,
1604                 VK_FORMAT_B8G8R8A8_SRGB,
1605                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1606                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1607                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1608                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1609                 VK_FORMAT_R16_SFLOAT,
1610                 VK_FORMAT_R16G16_SFLOAT,
1611                 VK_FORMAT_R16G16B16A16_SFLOAT,
1612                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1613                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1614         };
1615         static const VkFormat s_requiredStorageImageFormats[] =
1616         {
1617                 VK_FORMAT_R8G8B8A8_UNORM,
1618                 VK_FORMAT_R8G8B8A8_SNORM,
1619                 VK_FORMAT_R8G8B8A8_UINT,
1620                 VK_FORMAT_R8G8B8A8_SINT,
1621                 VK_FORMAT_R16G16B16A16_UINT,
1622                 VK_FORMAT_R16G16B16A16_SINT,
1623                 VK_FORMAT_R16G16B16A16_SFLOAT,
1624                 VK_FORMAT_R32_UINT,
1625                 VK_FORMAT_R32_SINT,
1626                 VK_FORMAT_R32_SFLOAT,
1627                 VK_FORMAT_R32G32_UINT,
1628                 VK_FORMAT_R32G32_SINT,
1629                 VK_FORMAT_R32G32_SFLOAT,
1630                 VK_FORMAT_R32G32B32A32_UINT,
1631                 VK_FORMAT_R32G32B32A32_SINT,
1632                 VK_FORMAT_R32G32B32A32_SFLOAT
1633         };
1634         static const VkFormat s_requiredStorageImageAtomicFormats[] =
1635         {
1636                 VK_FORMAT_R32_UINT,
1637                 VK_FORMAT_R32_SINT
1638         };
1639         static const VkFormat s_requiredColorAttachmentBlitDstFormats[] =
1640         {
1641                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1642                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1643                 VK_FORMAT_R8_UNORM,
1644                 VK_FORMAT_R8_UINT,
1645                 VK_FORMAT_R8_SINT,
1646                 VK_FORMAT_R8G8_UNORM,
1647                 VK_FORMAT_R8G8_UINT,
1648                 VK_FORMAT_R8G8_SINT,
1649                 VK_FORMAT_R8G8B8A8_UNORM,
1650                 VK_FORMAT_R8G8B8A8_UINT,
1651                 VK_FORMAT_R8G8B8A8_SINT,
1652                 VK_FORMAT_R8G8B8A8_SRGB,
1653                 VK_FORMAT_B8G8R8A8_UNORM,
1654                 VK_FORMAT_B8G8R8A8_SRGB,
1655                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1656                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1657                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1658                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1659                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1660                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1661                 VK_FORMAT_R16_UINT,
1662                 VK_FORMAT_R16_SINT,
1663                 VK_FORMAT_R16_SFLOAT,
1664                 VK_FORMAT_R16G16_UINT,
1665                 VK_FORMAT_R16G16_SINT,
1666                 VK_FORMAT_R16G16_SFLOAT,
1667                 VK_FORMAT_R16G16B16A16_UINT,
1668                 VK_FORMAT_R16G16B16A16_SINT,
1669                 VK_FORMAT_R16G16B16A16_SFLOAT,
1670                 VK_FORMAT_R32_UINT,
1671                 VK_FORMAT_R32_SINT,
1672                 VK_FORMAT_R32_SFLOAT,
1673                 VK_FORMAT_R32G32_UINT,
1674                 VK_FORMAT_R32G32_SINT,
1675                 VK_FORMAT_R32G32_SFLOAT,
1676                 VK_FORMAT_R32G32B32A32_UINT,
1677                 VK_FORMAT_R32G32B32A32_SINT,
1678                 VK_FORMAT_R32G32B32A32_SFLOAT
1679         };
1680         static const VkFormat s_requiredColorAttachmentBlendFormats[] =
1681         {
1682                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1683                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1684                 VK_FORMAT_R8_UNORM,
1685                 VK_FORMAT_R8G8_UNORM,
1686                 VK_FORMAT_R8G8B8A8_UNORM,
1687                 VK_FORMAT_R8G8B8A8_SRGB,
1688                 VK_FORMAT_B8G8R8A8_UNORM,
1689                 VK_FORMAT_B8G8R8A8_SRGB,
1690                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1691                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1692                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1693                 VK_FORMAT_R16_SFLOAT,
1694                 VK_FORMAT_R16G16_SFLOAT,
1695                 VK_FORMAT_R16G16B16A16_SFLOAT
1696         };
1697         static const VkFormat s_requiredDepthStencilAttachmentFormats[] =
1698         {
1699                 VK_FORMAT_D16_UNORM
1700         };
1701
1702         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
1703
1704         if (de::contains(DE_ARRAY_BEGIN(s_requiredSampledImageBlitSrcFormats), DE_ARRAY_END(s_requiredSampledImageBlitSrcFormats), format))
1705                 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT|VK_FORMAT_FEATURE_BLIT_SRC_BIT;
1706
1707         if (de::contains(DE_ARRAY_BEGIN(s_requiredSampledImageFilterLinearFormats), DE_ARRAY_END(s_requiredSampledImageFilterLinearFormats), format))
1708                 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
1709
1710         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageFormats), DE_ARRAY_END(s_requiredStorageImageFormats), format))
1711                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
1712
1713         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageAtomicFormats), DE_ARRAY_END(s_requiredStorageImageAtomicFormats), format))
1714                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
1715
1716         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlitDstFormats), DE_ARRAY_END(s_requiredColorAttachmentBlitDstFormats), format))
1717                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT|VK_FORMAT_FEATURE_BLIT_DST_BIT;
1718
1719         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlendFormats), DE_ARRAY_END(s_requiredColorAttachmentBlendFormats), format))
1720                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
1721
1722         if (de::contains(DE_ARRAY_BEGIN(s_requiredDepthStencilAttachmentFormats), DE_ARRAY_END(s_requiredDepthStencilAttachmentFormats), format))
1723                 flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
1724
1725         return flags;
1726 }
1727
1728 VkFormatFeatureFlags getRequiredOptimalExtendedTilingFeatures (Context& context, VkFormat format, VkFormatFeatureFlags queriedFlags)
1729 {
1730         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
1731
1732         // VK_EXT_sampler_filter_minmax:
1733         //      If filterMinmaxSingleComponentFormats is VK_TRUE, the following formats must
1734         //      support the VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT feature with
1735         //      VK_IMAGE_TILING_OPTIMAL, if they support VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT.
1736
1737         static const VkFormat s_requiredSampledImageFilterMinMaxFormats[] =
1738         {
1739                 VK_FORMAT_R8_UNORM,
1740                 VK_FORMAT_R8_SNORM,
1741                 VK_FORMAT_R16_UNORM,
1742                 VK_FORMAT_R16_SNORM,
1743                 VK_FORMAT_R16_SFLOAT,
1744                 VK_FORMAT_R32_SFLOAT,
1745                 VK_FORMAT_D16_UNORM,
1746                 VK_FORMAT_X8_D24_UNORM_PACK32,
1747                 VK_FORMAT_D32_SFLOAT,
1748                 VK_FORMAT_D16_UNORM_S8_UINT,
1749                 VK_FORMAT_D24_UNORM_S8_UINT,
1750                 VK_FORMAT_D32_SFLOAT_S8_UINT,
1751         };
1752
1753         if ((queriedFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
1754         {
1755                 if (de::contains(context.getDeviceExtensions().begin(), context.getDeviceExtensions().end(), "VK_EXT_sampler_filter_minmax"))
1756                 {
1757                         if (de::contains(DE_ARRAY_BEGIN(s_requiredSampledImageFilterMinMaxFormats), DE_ARRAY_END(s_requiredSampledImageFilterMinMaxFormats), format))
1758                         {
1759                                 VkPhysicalDeviceSamplerFilterMinmaxPropertiesEXT        physicalDeviceSamplerMinMaxProperties =
1760                                 {
1761                                         VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_FILTER_MINMAX_PROPERTIES_EXT,
1762                                         DE_NULL,
1763                                         DE_FALSE,
1764                                         DE_FALSE
1765                                 };
1766
1767                                 {
1768                                         VkPhysicalDeviceProperties2             physicalDeviceProperties;
1769                                         physicalDeviceProperties.sType  = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
1770                                         physicalDeviceProperties.pNext  = &physicalDeviceSamplerMinMaxProperties;
1771
1772                                         const InstanceInterface&                vk = context.getInstanceInterface();
1773                                         vk.getPhysicalDeviceProperties2(context.getPhysicalDevice(), &physicalDeviceProperties);
1774                                 }
1775
1776                                 if (physicalDeviceSamplerMinMaxProperties.filterMinmaxSingleComponentFormats)
1777                                 {
1778                                         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT;
1779                                 }
1780                         }
1781                 }
1782         }
1783         return flags;
1784 }
1785
1786 VkFormatFeatureFlags getRequiredBufferFeatures (VkFormat format)
1787 {
1788         static const VkFormat s_requiredVertexBufferFormats[] =
1789         {
1790                 VK_FORMAT_R8_UNORM,
1791                 VK_FORMAT_R8_SNORM,
1792                 VK_FORMAT_R8_UINT,
1793                 VK_FORMAT_R8_SINT,
1794                 VK_FORMAT_R8G8_UNORM,
1795                 VK_FORMAT_R8G8_SNORM,
1796                 VK_FORMAT_R8G8_UINT,
1797                 VK_FORMAT_R8G8_SINT,
1798                 VK_FORMAT_R8G8B8A8_UNORM,
1799                 VK_FORMAT_R8G8B8A8_SNORM,
1800                 VK_FORMAT_R8G8B8A8_UINT,
1801                 VK_FORMAT_R8G8B8A8_SINT,
1802                 VK_FORMAT_B8G8R8A8_UNORM,
1803                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1804                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1805                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1806                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1807                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1808                 VK_FORMAT_R16_UNORM,
1809                 VK_FORMAT_R16_SNORM,
1810                 VK_FORMAT_R16_UINT,
1811                 VK_FORMAT_R16_SINT,
1812                 VK_FORMAT_R16_SFLOAT,
1813                 VK_FORMAT_R16G16_UNORM,
1814                 VK_FORMAT_R16G16_SNORM,
1815                 VK_FORMAT_R16G16_UINT,
1816                 VK_FORMAT_R16G16_SINT,
1817                 VK_FORMAT_R16G16_SFLOAT,
1818                 VK_FORMAT_R16G16B16A16_UNORM,
1819                 VK_FORMAT_R16G16B16A16_SNORM,
1820                 VK_FORMAT_R16G16B16A16_UINT,
1821                 VK_FORMAT_R16G16B16A16_SINT,
1822                 VK_FORMAT_R16G16B16A16_SFLOAT,
1823                 VK_FORMAT_R32_UINT,
1824                 VK_FORMAT_R32_SINT,
1825                 VK_FORMAT_R32_SFLOAT,
1826                 VK_FORMAT_R32G32_UINT,
1827                 VK_FORMAT_R32G32_SINT,
1828                 VK_FORMAT_R32G32_SFLOAT,
1829                 VK_FORMAT_R32G32B32_UINT,
1830                 VK_FORMAT_R32G32B32_SINT,
1831                 VK_FORMAT_R32G32B32_SFLOAT,
1832                 VK_FORMAT_R32G32B32A32_UINT,
1833                 VK_FORMAT_R32G32B32A32_SINT,
1834                 VK_FORMAT_R32G32B32A32_SFLOAT
1835         };
1836         static const VkFormat s_requiredUniformTexelBufferFormats[] =
1837         {
1838                 VK_FORMAT_R8_UNORM,
1839                 VK_FORMAT_R8_SNORM,
1840                 VK_FORMAT_R8_UINT,
1841                 VK_FORMAT_R8_SINT,
1842                 VK_FORMAT_R8G8_UNORM,
1843                 VK_FORMAT_R8G8_SNORM,
1844                 VK_FORMAT_R8G8_UINT,
1845                 VK_FORMAT_R8G8_SINT,
1846                 VK_FORMAT_R8G8B8A8_UNORM,
1847                 VK_FORMAT_R8G8B8A8_SNORM,
1848                 VK_FORMAT_R8G8B8A8_UINT,
1849                 VK_FORMAT_R8G8B8A8_SINT,
1850                 VK_FORMAT_B8G8R8A8_UNORM,
1851                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1852                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1853                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1854                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1855                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1856                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1857                 VK_FORMAT_R16_UINT,
1858                 VK_FORMAT_R16_SINT,
1859                 VK_FORMAT_R16_SFLOAT,
1860                 VK_FORMAT_R16G16_UINT,
1861                 VK_FORMAT_R16G16_SINT,
1862                 VK_FORMAT_R16G16_SFLOAT,
1863                 VK_FORMAT_R16G16B16A16_UINT,
1864                 VK_FORMAT_R16G16B16A16_SINT,
1865                 VK_FORMAT_R16G16B16A16_SFLOAT,
1866                 VK_FORMAT_R32_UINT,
1867                 VK_FORMAT_R32_SINT,
1868                 VK_FORMAT_R32_SFLOAT,
1869                 VK_FORMAT_R32G32_UINT,
1870                 VK_FORMAT_R32G32_SINT,
1871                 VK_FORMAT_R32G32_SFLOAT,
1872                 VK_FORMAT_R32G32B32A32_UINT,
1873                 VK_FORMAT_R32G32B32A32_SINT,
1874                 VK_FORMAT_R32G32B32A32_SFLOAT,
1875                 VK_FORMAT_B10G11R11_UFLOAT_PACK32
1876         };
1877         static const VkFormat s_requiredStorageTexelBufferFormats[] =
1878         {
1879                 VK_FORMAT_R8G8B8A8_UNORM,
1880                 VK_FORMAT_R8G8B8A8_SNORM,
1881                 VK_FORMAT_R8G8B8A8_UINT,
1882                 VK_FORMAT_R8G8B8A8_SINT,
1883                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1884                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1885                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1886                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1887                 VK_FORMAT_R16G16B16A16_UINT,
1888                 VK_FORMAT_R16G16B16A16_SINT,
1889                 VK_FORMAT_R16G16B16A16_SFLOAT,
1890                 VK_FORMAT_R32_UINT,
1891                 VK_FORMAT_R32_SINT,
1892                 VK_FORMAT_R32_SFLOAT,
1893                 VK_FORMAT_R32G32_UINT,
1894                 VK_FORMAT_R32G32_SINT,
1895                 VK_FORMAT_R32G32_SFLOAT,
1896                 VK_FORMAT_R32G32B32A32_UINT,
1897                 VK_FORMAT_R32G32B32A32_SINT,
1898                 VK_FORMAT_R32G32B32A32_SFLOAT
1899         };
1900         static const VkFormat s_requiredStorageTexelBufferAtomicFormats[] =
1901         {
1902                 VK_FORMAT_R32_UINT,
1903                 VK_FORMAT_R32_SINT
1904         };
1905
1906         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
1907
1908         if (de::contains(DE_ARRAY_BEGIN(s_requiredVertexBufferFormats), DE_ARRAY_END(s_requiredVertexBufferFormats), format))
1909                 flags |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
1910
1911         if (de::contains(DE_ARRAY_BEGIN(s_requiredUniformTexelBufferFormats), DE_ARRAY_END(s_requiredUniformTexelBufferFormats), format))
1912                 flags |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
1913
1914         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferFormats), DE_ARRAY_END(s_requiredStorageTexelBufferFormats), format))
1915                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
1916
1917         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferAtomicFormats), DE_ARRAY_END(s_requiredStorageTexelBufferAtomicFormats), format))
1918                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
1919
1920         return flags;
1921 }
1922
1923 tcu::TestStatus formatProperties (Context& context, VkFormat format)
1924 {
1925         TestLog&                                        log                                     = context.getTestContext().getLog();
1926         const VkFormatProperties        properties                      = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
1927         bool                                            allOk                           = true;
1928
1929         // \todo [2017-05-16 pyry] This should be extended to cover for example COLOR_ATTACHMENT for depth formats etc.
1930         // \todo [2017-05-18 pyry] Any other color conversion related features that can't be supported by regular formats?
1931         const VkFormatFeatureFlags      extOptimalFeatures      = getRequiredOptimalExtendedTilingFeatures(context, format, properties.optimalTilingFeatures);
1932
1933         const VkFormatFeatureFlags      notAllowedFeatures      = VK_FORMAT_FEATURE_DISJOINT_BIT;
1934
1935         const struct
1936         {
1937                 VkFormatFeatureFlags VkFormatProperties::*      field;
1938                 const char*                                                                     fieldName;
1939                 VkFormatFeatureFlags                                            requiredFeatures;
1940         } fields[] =
1941         {
1942                 { &VkFormatProperties::linearTilingFeatures,    "linearTilingFeatures",         (VkFormatFeatureFlags)0                                                                                 },
1943                 { &VkFormatProperties::optimalTilingFeatures,   "optimalTilingFeatures",        getRequiredOptimalTilingFeatures(format) | extOptimalFeatures   },
1944                 { &VkFormatProperties::bufferFeatures,                  "bufferFeatures",                       getRequiredBufferFeatures(format)                                                               }
1945         };
1946
1947         log << TestLog::Message << properties << TestLog::EndMessage;
1948
1949         for (int fieldNdx = 0; fieldNdx < DE_LENGTH_OF_ARRAY(fields); fieldNdx++)
1950         {
1951                 const char* const                               fieldName       = fields[fieldNdx].fieldName;
1952                 const VkFormatFeatureFlags              supported       = properties.*fields[fieldNdx].field;
1953                 const VkFormatFeatureFlags              required        = fields[fieldNdx].requiredFeatures;
1954
1955                 if ((supported & required) != required)
1956                 {
1957                         log << TestLog::Message << "ERROR in " << fieldName << ":\n"
1958                                                                         << "  required: " << getFormatFeatureFlagsStr(required) << "\n  "
1959                                                                         << "  missing: " << getFormatFeatureFlagsStr(~supported & required)
1960                                 << TestLog::EndMessage;
1961                         allOk = false;
1962                 }
1963
1964                 if ((supported & notAllowedFeatures) != 0)
1965                 {
1966                         log << TestLog::Message << "ERROR in " << fieldName << ":\n"
1967                                                                         << "  has: " << getFormatFeatureFlagsStr(supported & notAllowedFeatures)
1968                                 << TestLog::EndMessage;
1969                         allOk = false;
1970                 }
1971         }
1972
1973         if (allOk)
1974                 return tcu::TestStatus::pass("Query and validation passed");
1975         else
1976                 return tcu::TestStatus::fail("Required features not supported");
1977 }
1978
1979 VkPhysicalDeviceSamplerYcbcrConversionFeatures getPhysicalDeviceSamplerYcbcrConversionFeatures (const InstanceInterface& vk, VkPhysicalDevice physicalDevice)
1980 {
1981         VkPhysicalDeviceFeatures2                                               coreFeatures;
1982         VkPhysicalDeviceSamplerYcbcrConversionFeatures  ycbcrFeatures;
1983
1984         deMemset(&coreFeatures, 0, sizeof(coreFeatures));
1985         deMemset(&ycbcrFeatures, 0, sizeof(ycbcrFeatures));
1986
1987         coreFeatures.sType              = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
1988         coreFeatures.pNext              = &ycbcrFeatures;
1989         ycbcrFeatures.sType             = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
1990
1991         vk.getPhysicalDeviceFeatures2(physicalDevice, &coreFeatures);
1992
1993         return ycbcrFeatures;
1994 }
1995
1996 void checkYcbcrApiSupport (Context& context)
1997 {
1998         // check if YCbcr API and are supported by implementation
1999
2000         // the support for formats and YCbCr may still be optional - see isYcbcrConversionSupported below
2001
2002         if (!vk::isCoreDeviceExtension(context.getUsedApiVersion(), "VK_KHR_sampler_ycbcr_conversion"))
2003         {
2004                 if (!vk::isDeviceExtensionSupported(context.getUsedApiVersion(), context.getDeviceExtensions(), "VK_KHR_sampler_ycbcr_conversion"))
2005                         TCU_THROW(NotSupportedError, "VK_KHR_sampler_ycbcr_conversion is not supported");
2006
2007                 // Hard dependency for ycbcr
2008                 TCU_CHECK(de::contains(context.getInstanceExtensions().begin(), context.getInstanceExtensions().end(), "VK_KHR_get_physical_device_properties2"));
2009         }
2010 }
2011
2012 bool isYcbcrConversionSupported (Context& context)
2013 {
2014         checkYcbcrApiSupport(context);
2015
2016         const VkPhysicalDeviceSamplerYcbcrConversionFeatures    ycbcrFeatures   = getPhysicalDeviceSamplerYcbcrConversionFeatures(context.getInstanceInterface(), context.getPhysicalDevice());
2017
2018         return (ycbcrFeatures.samplerYcbcrConversion == VK_TRUE);
2019 }
2020
2021 VkFormatFeatureFlags getAllowedYcbcrFormatFeatures (VkFormat format)
2022 {
2023         DE_ASSERT(isYCbCrFormat(format));
2024
2025         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
2026
2027         // all formats *may* support these
2028         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
2029         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
2030         flags |= VK_FORMAT_FEATURE_TRANSFER_SRC_BIT;
2031         flags |= VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
2032         flags |= VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT;
2033         flags |= VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT;
2034         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_LINEAR_FILTER_BIT;
2035         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_SEPARATE_RECONSTRUCTION_FILTER_BIT;
2036         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_BIT;
2037         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_YCBCR_CONVERSION_CHROMA_RECONSTRUCTION_EXPLICIT_FORCEABLE_BIT;
2038         flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_MINMAX_BIT_EXT;
2039
2040         // multi-plane formats *may* support DISJOINT_BIT
2041         if (getPlaneCount(format) >= 2)
2042                 flags |= VK_FORMAT_FEATURE_DISJOINT_BIT;
2043
2044         if (isChromaSubsampled(format))
2045                 flags |= VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT;
2046
2047         return flags;
2048 }
2049
2050 tcu::TestStatus ycbcrFormatProperties (Context& context, VkFormat format)
2051 {
2052         DE_ASSERT(isYCbCrFormat(format));
2053         // check if Ycbcr format enums are valid given the version and extensions
2054         checkYcbcrApiSupport(context);
2055
2056         TestLog&                                        log                                             = context.getTestContext().getLog();
2057         const VkFormatProperties        properties                              = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
2058         bool                                            allOk                                   = true;
2059         const VkFormatFeatureFlags      allowedImageFeatures    = getAllowedYcbcrFormatFeatures(format);
2060
2061         const struct
2062         {
2063                 VkFormatFeatureFlags VkFormatProperties::*      field;
2064                 const char*                                                                     fieldName;
2065                 bool                                                                            requiredFeatures;
2066                 VkFormatFeatureFlags                                            allowedFeatures;
2067         } fields[] =
2068         {
2069                 { &VkFormatProperties::linearTilingFeatures,    "linearTilingFeatures",         false,  allowedImageFeatures    },
2070                 { &VkFormatProperties::optimalTilingFeatures,   "optimalTilingFeatures",        true,   allowedImageFeatures    },
2071                 { &VkFormatProperties::bufferFeatures,                  "bufferFeatures",                       false,  (VkFormatFeatureFlags)0 }
2072         };
2073         static const VkFormat           s_requiredBaseFormats[] =
2074         {
2075                 VK_FORMAT_G8_B8R8_2PLANE_420_UNORM,
2076                 VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM
2077         };
2078         const bool                                      isRequiredBaseFormat    = isYcbcrConversionSupported(context) &&
2079                                                                                                                   de::contains(DE_ARRAY_BEGIN(s_requiredBaseFormats), DE_ARRAY_END(s_requiredBaseFormats), format);
2080
2081         log << TestLog::Message << properties << TestLog::EndMessage;
2082
2083         for (int fieldNdx = 0; fieldNdx < DE_LENGTH_OF_ARRAY(fields); fieldNdx++)
2084         {
2085                 const char* const                               fieldName       = fields[fieldNdx].fieldName;
2086                 const VkFormatFeatureFlags              supported       = properties.*fields[fieldNdx].field;
2087                 const VkFormatFeatureFlags              allowed         = fields[fieldNdx].allowedFeatures;
2088
2089                 if (isRequiredBaseFormat && fields[fieldNdx].requiredFeatures)
2090                 {
2091                         const VkFormatFeatureFlags      required        = VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT
2092                                                                                                         | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT
2093                                                                                                         | VK_FORMAT_FEATURE_TRANSFER_DST_BIT;
2094
2095                         if ((supported & required) != required)
2096                         {
2097                                 log << TestLog::Message << "ERROR in " << fieldName << ":\n"
2098                                                                                 << "  required: " << getFormatFeatureFlagsStr(required) << "\n  "
2099                                                                                 << "  missing: " << getFormatFeatureFlagsStr(~supported & required)
2100                                         << TestLog::EndMessage;
2101                                 allOk = false;
2102                         }
2103
2104                         if ((supported & (VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT | VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT)) == 0)
2105                         {
2106                                 log << TestLog::Message << "ERROR in " << fieldName << ":\n"
2107                                                                                 << "  Either VK_FORMAT_FEATURE_MIDPOINT_CHROMA_SAMPLES_BIT or VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT required"
2108                                         << TestLog::EndMessage;
2109                                 allOk = false;
2110                         }
2111                 }
2112
2113                 if ((supported & ~allowed) != 0)
2114                 {
2115                         log << TestLog::Message << "ERROR in " << fieldName << ":\n"
2116                                                                         << "  has: " << getFormatFeatureFlagsStr(supported & ~allowed)
2117                                 << TestLog::EndMessage;
2118                         allOk = false;
2119                 }
2120         }
2121
2122         if (allOk)
2123                 return tcu::TestStatus::pass("Query and validation passed");
2124         else
2125                 return tcu::TestStatus::fail("Required features not supported");
2126 }
2127
2128 bool optimalTilingFeaturesSupported (Context& context, VkFormat format, VkFormatFeatureFlags features)
2129 {
2130         const VkFormatProperties        properties      = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
2131
2132         return (properties.optimalTilingFeatures & features) == features;
2133 }
2134
2135 bool optimalTilingFeaturesSupportedForAll (Context& context, const VkFormat* begin, const VkFormat* end, VkFormatFeatureFlags features)
2136 {
2137         for (const VkFormat* cur = begin; cur != end; ++cur)
2138         {
2139                 if (!optimalTilingFeaturesSupported(context, *cur, features))
2140                         return false;
2141         }
2142
2143         return true;
2144 }
2145
2146 tcu::TestStatus testDepthStencilSupported (Context& context)
2147 {
2148         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
2149                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
2150                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_X8_D24_UNORM_PACK32 or VK_FORMAT_D32_SFLOAT");
2151
2152         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
2153                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
2154                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT");
2155
2156         return tcu::TestStatus::pass("Required depth/stencil formats supported");
2157 }
2158
2159 tcu::TestStatus testCompressedFormatsSupported (Context& context)
2160 {
2161         static const VkFormat s_allBcFormats[] =
2162         {
2163                 VK_FORMAT_BC1_RGB_UNORM_BLOCK,
2164                 VK_FORMAT_BC1_RGB_SRGB_BLOCK,
2165                 VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
2166                 VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
2167                 VK_FORMAT_BC2_UNORM_BLOCK,
2168                 VK_FORMAT_BC2_SRGB_BLOCK,
2169                 VK_FORMAT_BC3_UNORM_BLOCK,
2170                 VK_FORMAT_BC3_SRGB_BLOCK,
2171                 VK_FORMAT_BC4_UNORM_BLOCK,
2172                 VK_FORMAT_BC4_SNORM_BLOCK,
2173                 VK_FORMAT_BC5_UNORM_BLOCK,
2174                 VK_FORMAT_BC5_SNORM_BLOCK,
2175                 VK_FORMAT_BC6H_UFLOAT_BLOCK,
2176                 VK_FORMAT_BC6H_SFLOAT_BLOCK,
2177                 VK_FORMAT_BC7_UNORM_BLOCK,
2178                 VK_FORMAT_BC7_SRGB_BLOCK,
2179         };
2180         static const VkFormat s_allEtc2Formats[] =
2181         {
2182                 VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
2183                 VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
2184                 VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
2185                 VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
2186                 VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
2187                 VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
2188                 VK_FORMAT_EAC_R11_UNORM_BLOCK,
2189                 VK_FORMAT_EAC_R11_SNORM_BLOCK,
2190                 VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
2191                 VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
2192         };
2193         static const VkFormat s_allAstcLdrFormats[] =
2194         {
2195                 VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
2196                 VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
2197                 VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
2198                 VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
2199                 VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
2200                 VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
2201                 VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
2202                 VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
2203                 VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
2204                 VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
2205                 VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
2206                 VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
2207                 VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
2208                 VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
2209                 VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
2210                 VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
2211                 VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
2212                 VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
2213                 VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
2214                 VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
2215                 VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
2216                 VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
2217                 VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
2218                 VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
2219                 VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
2220                 VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
2221                 VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
2222                 VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
2223         };
2224
2225         static const struct
2226         {
2227                 const char*                                                                     setName;
2228                 const char*                                                                     featureName;
2229                 const VkBool32 VkPhysicalDeviceFeatures::*      feature;
2230                 const VkFormat*                                                         formatsBegin;
2231                 const VkFormat*                                                         formatsEnd;
2232         } s_compressedFormatSets[] =
2233         {
2234                 { "BC",                 "textureCompressionBC",                 &VkPhysicalDeviceFeatures::textureCompressionBC,                DE_ARRAY_BEGIN(s_allBcFormats),                 DE_ARRAY_END(s_allBcFormats)            },
2235                 { "ETC2",               "textureCompressionETC2",               &VkPhysicalDeviceFeatures::textureCompressionETC2,              DE_ARRAY_BEGIN(s_allEtc2Formats),               DE_ARRAY_END(s_allEtc2Formats)          },
2236                 { "ASTC LDR",   "textureCompressionASTC_LDR",   &VkPhysicalDeviceFeatures::textureCompressionASTC_LDR,  DE_ARRAY_BEGIN(s_allAstcLdrFormats),    DE_ARRAY_END(s_allAstcLdrFormats)       },
2237         };
2238
2239         TestLog&                                                log                                     = context.getTestContext().getLog();
2240         const VkPhysicalDeviceFeatures& features                        = context.getDeviceFeatures();
2241         int                                                             numSupportedSets        = 0;
2242         int                                                             numErrors                       = 0;
2243         int                                                             numWarnings                     = 0;
2244
2245         for (int setNdx = 0; setNdx < DE_LENGTH_OF_ARRAY(s_compressedFormatSets); ++setNdx)
2246         {
2247                 const char* const       setName                 = s_compressedFormatSets[setNdx].setName;
2248                 const char* const       featureName             = s_compressedFormatSets[setNdx].featureName;
2249                 const bool                      featureBitSet   = features.*s_compressedFormatSets[setNdx].feature == VK_TRUE;
2250                 const bool                      allSupported    = optimalTilingFeaturesSupportedForAll(context,
2251                                                                                                                                                                    s_compressedFormatSets[setNdx].formatsBegin,
2252                                                                                                                                                                    s_compressedFormatSets[setNdx].formatsEnd,
2253                                                                                                                                                                    VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
2254
2255                 if (featureBitSet && !allSupported)
2256                 {
2257                         log << TestLog::Message << "ERROR: " << featureName << " = VK_TRUE but " << setName << " formats not supported" << TestLog::EndMessage;
2258                         numErrors += 1;
2259                 }
2260                 else if (allSupported && !featureBitSet)
2261                 {
2262                         log << TestLog::Message << "WARNING: " << setName << " formats supported but " << featureName << " = VK_FALSE" << TestLog::EndMessage;
2263                         numWarnings += 1;
2264                 }
2265
2266                 if (featureBitSet)
2267                 {
2268                         log << TestLog::Message << "All " << setName << " formats are supported" << TestLog::EndMessage;
2269                         numSupportedSets += 1;
2270                 }
2271                 else
2272                         log << TestLog::Message << setName << " formats are not supported" << TestLog::EndMessage;
2273         }
2274
2275         if (numSupportedSets == 0)
2276         {
2277                 log << TestLog::Message << "No compressed format sets supported" << TestLog::EndMessage;
2278                 numErrors += 1;
2279         }
2280
2281         if (numErrors > 0)
2282                 return tcu::TestStatus::fail("Compressed format support not valid");
2283         else if (numWarnings > 0)
2284                 return tcu::TestStatus(QP_TEST_RESULT_QUALITY_WARNING, "Found inconsistencies in compressed format support");
2285         else
2286                 return tcu::TestStatus::pass("Compressed texture format support is valid");
2287 }
2288
2289 void createFormatTests (tcu::TestCaseGroup* testGroup)
2290 {
2291         DE_STATIC_ASSERT(VK_FORMAT_UNDEFINED == 0);
2292
2293         static const struct
2294         {
2295                 VkFormat                                                                begin;
2296                 VkFormat                                                                end;
2297                 FunctionInstance1<VkFormat>::Function   testFunction;
2298         } s_formatRanges[] =
2299         {
2300                 // core formats
2301                 { (VkFormat)(VK_FORMAT_UNDEFINED+1),    VK_CORE_FORMAT_LAST,                                                                            formatProperties },
2302
2303                 // YCbCr formats
2304                 { VK_FORMAT_G8B8G8R8_422_UNORM,                 (VkFormat)(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM+1),   ycbcrFormatProperties },
2305         };
2306
2307         for (int rangeNdx = 0; rangeNdx < DE_LENGTH_OF_ARRAY(s_formatRanges); ++rangeNdx)
2308         {
2309                 const VkFormat                                                          rangeBegin              = s_formatRanges[rangeNdx].begin;
2310                 const VkFormat                                                          rangeEnd                = s_formatRanges[rangeNdx].end;
2311                 const FunctionInstance1<VkFormat>::Function     testFunction    = s_formatRanges[rangeNdx].testFunction;
2312
2313                 for (VkFormat format = rangeBegin; format != rangeEnd; format = (VkFormat)(format+1))
2314                 {
2315                         const char* const       enumName        = getFormatName(format);
2316                         const string            caseName        = de::toLower(string(enumName).substr(10));
2317
2318                         addFunctionCase(testGroup, caseName, enumName, testFunction, format);
2319                 }
2320         }
2321
2322         addFunctionCase(testGroup, "depth_stencil",                     "",     testDepthStencilSupported);
2323         addFunctionCase(testGroup, "compressed_formats",        "",     testCompressedFormatsSupported);
2324 }
2325
2326 VkImageUsageFlags getValidImageUsageFlags (const VkFormatFeatureFlags supportedFeatures, const bool useKhrMaintenance1Semantics)
2327 {
2328         VkImageUsageFlags       flags   = (VkImageUsageFlags)0;
2329
2330         if (useKhrMaintenance1Semantics)
2331         {
2332                 if ((supportedFeatures & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT) != 0)
2333                         flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
2334
2335                 if ((supportedFeatures & VK_FORMAT_FEATURE_TRANSFER_DST_BIT) != 0)
2336                         flags |= VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2337         }
2338         else
2339         {
2340                 // If format is supported at all, it must be valid transfer src+dst
2341                 if (supportedFeatures != 0)
2342                         flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2343         }
2344
2345         if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
2346                 flags |= VK_IMAGE_USAGE_SAMPLED_BIT;
2347
2348         if ((supportedFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) != 0)
2349                 flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
2350
2351         if ((supportedFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)
2352                 flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
2353
2354         if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
2355                 flags |= VK_IMAGE_USAGE_STORAGE_BIT;
2356
2357         return flags;
2358 }
2359
2360 bool isValidImageUsageFlagCombination (VkImageUsageFlags usage)
2361 {
2362         if ((usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) != 0)
2363         {
2364                 const VkImageUsageFlags         allowedFlags    = VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
2365                                                                                                         | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
2366                                                                                                         | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
2367                                                                                                         | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
2368
2369                 // Only *_ATTACHMENT_BIT flags can be combined with TRANSIENT_ATTACHMENT_BIT
2370                 if ((usage & ~allowedFlags) != 0)
2371                         return false;
2372
2373                 // TRANSIENT_ATTACHMENT_BIT is not valid without COLOR_ or DEPTH_STENCIL_ATTACHMENT_BIT
2374                 if ((usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)) == 0)
2375                         return false;
2376         }
2377
2378         return usage != 0;
2379 }
2380
2381 VkImageCreateFlags getValidImageCreateFlags (const VkPhysicalDeviceFeatures& deviceFeatures, VkFormat format, VkFormatFeatureFlags formatFeatures, VkImageType type, VkImageUsageFlags usage)
2382 {
2383         VkImageCreateFlags      flags   = (VkImageCreateFlags)0;
2384
2385         if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
2386         {
2387                 flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
2388
2389                 if (type == VK_IMAGE_TYPE_2D)
2390                         flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
2391         }
2392
2393         if (isYCbCrFormat(format) && getPlaneCount(format) > 1)
2394         {
2395                 if (formatFeatures & VK_FORMAT_FEATURE_DISJOINT_BIT_KHR)
2396                         flags |= VK_IMAGE_CREATE_DISJOINT_BIT_KHR;
2397         }
2398
2399         if ((usage & (VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT)) != 0 &&
2400                 (usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)
2401         {
2402                 if (deviceFeatures.sparseBinding)
2403                         flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT|VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
2404
2405                 if (deviceFeatures.sparseResidencyAliased)
2406                         flags |= VK_IMAGE_CREATE_SPARSE_ALIASED_BIT;
2407         }
2408
2409         return flags;
2410 }
2411
2412 bool isValidImageCreateFlagCombination (VkImageCreateFlags)
2413 {
2414         return true;
2415 }
2416
2417 bool isRequiredImageParameterCombination (const VkPhysicalDeviceFeatures&       deviceFeatures,
2418                                                                                   const VkFormat                                        format,
2419                                                                                   const VkFormatProperties&                     formatProperties,
2420                                                                                   const VkImageType                                     imageType,
2421                                                                                   const VkImageTiling                           imageTiling,
2422                                                                                   const VkImageUsageFlags                       usageFlags,
2423                                                                                   const VkImageCreateFlags                      createFlags)
2424 {
2425         DE_UNREF(deviceFeatures);
2426         DE_UNREF(formatProperties);
2427         DE_UNREF(createFlags);
2428
2429         // Linear images can have arbitrary limitations
2430         if (imageTiling == VK_IMAGE_TILING_LINEAR)
2431                 return false;
2432
2433         // Support for other usages for compressed formats is optional
2434         if (isCompressedFormat(format) &&
2435                 (usageFlags & ~(VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT)) != 0)
2436                 return false;
2437
2438         // Support for 1D, and sliced 3D compressed formats is optional
2439         if (isCompressedFormat(format) && (imageType == VK_IMAGE_TYPE_1D || imageType == VK_IMAGE_TYPE_3D))
2440                 return false;
2441
2442         // Support for 1D and 3D depth/stencil textures is optional
2443         if (isDepthStencilFormat(format) && (imageType == VK_IMAGE_TYPE_1D || imageType == VK_IMAGE_TYPE_3D))
2444                 return false;
2445
2446         DE_ASSERT(deviceFeatures.sparseBinding || (createFlags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT|VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)) == 0);
2447         DE_ASSERT(deviceFeatures.sparseResidencyAliased || (createFlags & VK_IMAGE_CREATE_SPARSE_ALIASED_BIT) == 0);
2448
2449         if (isYCbCrFormat(format) && (createFlags & (VK_IMAGE_CREATE_SPARSE_BINDING_BIT | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)))
2450                 return false;
2451
2452         if (createFlags & VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT)
2453         {
2454                 if (isCompressedFormat(format))
2455                         return false;
2456
2457                 if (isDepthStencilFormat(format))
2458                         return false;
2459
2460                 if (!deIsPowerOfTwo32(mapVkFormat(format).getPixelSize()))
2461                         return false;
2462
2463                 switch (imageType)
2464                 {
2465                         case VK_IMAGE_TYPE_2D:
2466                                 return (deviceFeatures.sparseResidencyImage2D == VK_TRUE);
2467                         case VK_IMAGE_TYPE_3D:
2468                                 return (deviceFeatures.sparseResidencyImage3D == VK_TRUE);
2469                         default:
2470                                 return false;
2471                 }
2472         }
2473
2474         return true;
2475 }
2476
2477 VkSampleCountFlags getRequiredOptimalTilingSampleCounts (const VkPhysicalDeviceLimits&  deviceLimits,
2478                                                                                                                  const VkFormat                                 format,
2479                                                                                                                  const VkImageUsageFlags                usageFlags)
2480 {
2481         if (isCompressedFormat(format))
2482                 return VK_SAMPLE_COUNT_1_BIT;
2483
2484         bool            hasDepthComp    = false;
2485         bool            hasStencilComp  = false;
2486         const bool      isYCbCr                 = isYCbCrFormat(format);
2487         if (!isYCbCr)
2488         {
2489                 const tcu::TextureFormat        tcuFormat               = mapVkFormat(format);
2490                 hasDepthComp    = (tcuFormat.order == tcu::TextureFormat::D || tcuFormat.order == tcu::TextureFormat::DS);
2491                 hasStencilComp  = (tcuFormat.order == tcu::TextureFormat::S || tcuFormat.order == tcu::TextureFormat::DS);
2492         }
2493
2494         const bool                                              isColorFormat   = !hasDepthComp && !hasStencilComp;
2495         VkSampleCountFlags                              sampleCounts    = ~(VkSampleCountFlags)0;
2496
2497         DE_ASSERT((hasDepthComp || hasStencilComp) != isColorFormat);
2498
2499         if ((usageFlags & VK_IMAGE_USAGE_STORAGE_BIT) != 0)
2500                 sampleCounts &= deviceLimits.storageImageSampleCounts;
2501
2502         if ((usageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
2503         {
2504                 if (hasDepthComp)
2505                         sampleCounts &= deviceLimits.sampledImageDepthSampleCounts;
2506
2507                 if (hasStencilComp)
2508                         sampleCounts &= deviceLimits.sampledImageStencilSampleCounts;
2509
2510                 if (isColorFormat)
2511                 {
2512                         if (isYCbCr)
2513                                 sampleCounts &= deviceLimits.sampledImageColorSampleCounts;
2514                         else
2515                         {
2516                                 const tcu::TextureFormat                tcuFormat       = mapVkFormat(format);
2517                                 const tcu::TextureChannelClass  chnClass        = tcu::getTextureChannelClass(tcuFormat.type);
2518
2519                                 if (chnClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER ||
2520                                         chnClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER)
2521                                         sampleCounts &= deviceLimits.sampledImageIntegerSampleCounts;
2522                                 else
2523                                         sampleCounts &= deviceLimits.sampledImageColorSampleCounts;
2524                         }
2525                 }
2526         }
2527
2528         if ((usageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0)
2529                 sampleCounts &= deviceLimits.framebufferColorSampleCounts;
2530
2531         if ((usageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)
2532         {
2533                 if (hasDepthComp)
2534                         sampleCounts &= deviceLimits.framebufferDepthSampleCounts;
2535
2536                 if (hasStencilComp)
2537                         sampleCounts &= deviceLimits.framebufferStencilSampleCounts;
2538         }
2539
2540         // If there is no usage flag set that would have corresponding device limit,
2541         // only VK_SAMPLE_COUNT_1_BIT is required.
2542         if (sampleCounts == ~(VkSampleCountFlags)0)
2543                 sampleCounts &= VK_SAMPLE_COUNT_1_BIT;
2544
2545         return sampleCounts;
2546 }
2547
2548 struct ImageFormatPropertyCase
2549 {
2550         typedef tcu::TestStatus (*Function) (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling);
2551
2552         Function                testFunction;
2553         VkFormat                format;
2554         VkImageType             imageType;
2555         VkImageTiling   tiling;
2556
2557         ImageFormatPropertyCase (Function testFunction_, VkFormat format_, VkImageType imageType_, VkImageTiling tiling_)
2558                 : testFunction  (testFunction_)
2559                 , format                (format_)
2560                 , imageType             (imageType_)
2561                 , tiling                (tiling_)
2562         {}
2563
2564         ImageFormatPropertyCase (void)
2565                 : testFunction  ((Function)DE_NULL)
2566                 , format                (VK_FORMAT_UNDEFINED)
2567                 , imageType             (VK_IMAGE_TYPE_LAST)
2568                 , tiling                (VK_IMAGE_TILING_LAST)
2569         {}
2570 };
2571
2572 tcu::TestStatus imageFormatProperties (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling)
2573 {
2574         if (isYCbCrFormat(format))
2575                 // check if Ycbcr format enums are valid given the version and extensions
2576                 checkYcbcrApiSupport(context);
2577
2578         TestLog&                                                log                                     = context.getTestContext().getLog();
2579         const VkPhysicalDeviceFeatures& deviceFeatures          = context.getDeviceFeatures();
2580         const VkPhysicalDeviceLimits&   deviceLimits            = context.getDeviceProperties().limits;
2581         const VkFormatProperties                formatProperties        = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
2582         const bool                                              hasKhrMaintenance1      = isDeviceExtensionSupported(context.getUsedApiVersion(), context.getDeviceExtensions(), "VK_KHR_maintenance1");
2583
2584         const VkFormatFeatureFlags              supportedFeatures       = tiling == VK_IMAGE_TILING_LINEAR ? formatProperties.linearTilingFeatures : formatProperties.optimalTilingFeatures;
2585         const VkImageUsageFlags                 usageFlagSet            = getValidImageUsageFlags(supportedFeatures, hasKhrMaintenance1);
2586
2587         tcu::ResultCollector                    results                         (log, "ERROR: ");
2588
2589         if (hasKhrMaintenance1 && (supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
2590         {
2591                 results.check((supportedFeatures & (VK_FORMAT_FEATURE_TRANSFER_SRC_BIT|VK_FORMAT_FEATURE_TRANSFER_DST_BIT)) != 0,
2592                                           "A sampled image format must have VK_FORMAT_FEATURE_TRANSFER_SRC_BIT and VK_FORMAT_FEATURE_TRANSFER_DST_BIT format feature flags set");
2593         }
2594
2595         if (isYcbcrConversionSupported(context) && (format == VK_FORMAT_G8_B8_R8_3PLANE_420_UNORM_KHR || format == VK_FORMAT_G8_B8R8_2PLANE_420_UNORM_KHR))
2596         {
2597                 VkFormatFeatureFlags requiredFeatures = VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR | VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR;
2598                 if (tiling == VK_IMAGE_TILING_OPTIMAL)
2599                         requiredFeatures |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_COSITED_CHROMA_SAMPLES_BIT_KHR;
2600
2601                 results.check((supportedFeatures & requiredFeatures) == requiredFeatures,
2602                                           getFormatName(format) + string(" must support ") + de::toString(getFormatFeatureFlagsStr(requiredFeatures)));
2603         }
2604
2605         for (VkImageUsageFlags curUsageFlags = 0; curUsageFlags <= usageFlagSet; curUsageFlags++)
2606         {
2607                 if ((curUsageFlags & ~usageFlagSet) != 0 ||
2608                         !isValidImageUsageFlagCombination(curUsageFlags))
2609                         continue;
2610
2611                 const VkImageCreateFlags        createFlagSet           = getValidImageCreateFlags(deviceFeatures, format, supportedFeatures, imageType, curUsageFlags);
2612
2613                 for (VkImageCreateFlags curCreateFlags = 0; curCreateFlags <= createFlagSet; curCreateFlags++)
2614                 {
2615                         if ((curCreateFlags & ~createFlagSet) != 0 ||
2616                                 !isValidImageCreateFlagCombination(curCreateFlags))
2617                                 continue;
2618
2619                         const bool                              isRequiredCombination   = isRequiredImageParameterCombination(deviceFeatures,
2620                                                                                                                                                                                                   format,
2621                                                                                                                                                                                                   formatProperties,
2622                                                                                                                                                                                                   imageType,
2623                                                                                                                                                                                                   tiling,
2624                                                                                                                                                                                                   curUsageFlags,
2625                                                                                                                                                                                                   curCreateFlags);
2626                         VkImageFormatProperties properties;
2627                         VkResult                                queryResult;
2628
2629                         log << TestLog::Message << "Testing " << getImageTypeStr(imageType) << ", "
2630                                                                         << getImageTilingStr(tiling) << ", "
2631                                                                         << getImageUsageFlagsStr(curUsageFlags) << ", "
2632                                                                         << getImageCreateFlagsStr(curCreateFlags)
2633                                 << TestLog::EndMessage;
2634
2635                         // Set return value to known garbage
2636                         deMemset(&properties, 0xcd, sizeof(properties));
2637
2638                         queryResult = context.getInstanceInterface().getPhysicalDeviceImageFormatProperties(context.getPhysicalDevice(),
2639                                                                                                                                                                                                 format,
2640                                                                                                                                                                                                 imageType,
2641                                                                                                                                                                                                 tiling,
2642                                                                                                                                                                                                 curUsageFlags,
2643                                                                                                                                                                                                 curCreateFlags,
2644                                                                                                                                                                                                 &properties);
2645
2646                         if (queryResult == VK_SUCCESS)
2647                         {
2648                                 const deUint32  fullMipPyramidSize      = de::max(de::max(deLog2Ceil32(properties.maxExtent.width),
2649                                                                                                                                           deLog2Ceil32(properties.maxExtent.height)),
2650                                                                                                                           deLog2Ceil32(properties.maxExtent.depth)) + 1;
2651
2652                                 log << TestLog::Message << properties << "\n" << TestLog::EndMessage;
2653
2654                                 results.check(imageType != VK_IMAGE_TYPE_1D || (properties.maxExtent.width >= 1 && properties.maxExtent.height == 1 && properties.maxExtent.depth == 1), "Invalid dimensions for 1D image");
2655                                 results.check(imageType != VK_IMAGE_TYPE_2D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth == 1), "Invalid dimensions for 2D image");
2656                                 results.check(imageType != VK_IMAGE_TYPE_3D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth >= 1), "Invalid dimensions for 3D image");
2657                                 results.check(imageType != VK_IMAGE_TYPE_3D || properties.maxArrayLayers == 1, "Invalid maxArrayLayers for 3D image");
2658
2659                                 if (tiling == VK_IMAGE_TILING_OPTIMAL && imageType == VK_IMAGE_TYPE_2D && !(curCreateFlags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) &&
2660                                          (supportedFeatures & (VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT)))
2661                                 {
2662                                         const VkSampleCountFlags        requiredSampleCounts    = getRequiredOptimalTilingSampleCounts(deviceLimits, format, curUsageFlags);
2663                                         results.check((properties.sampleCounts & requiredSampleCounts) == requiredSampleCounts, "Required sample counts not supported");
2664                                 }
2665                                 else
2666                                         results.check(properties.sampleCounts == VK_SAMPLE_COUNT_1_BIT, "sampleCounts != VK_SAMPLE_COUNT_1_BIT");
2667
2668                                 if (isRequiredCombination)
2669                                 {
2670                                         results.check(imageType != VK_IMAGE_TYPE_1D || (properties.maxExtent.width      >= deviceLimits.maxImageDimension1D),
2671                                                                   "Reported dimensions smaller than device limits");
2672                                         results.check(imageType != VK_IMAGE_TYPE_2D || (properties.maxExtent.width      >= deviceLimits.maxImageDimension2D &&
2673                                                                                                                                         properties.maxExtent.height     >= deviceLimits.maxImageDimension2D),
2674                                                                   "Reported dimensions smaller than device limits");
2675                                         results.check(imageType != VK_IMAGE_TYPE_3D || (properties.maxExtent.width      >= deviceLimits.maxImageDimension3D &&
2676                                                                                                                                         properties.maxExtent.height     >= deviceLimits.maxImageDimension3D &&
2677                                                                                                                                         properties.maxExtent.depth      >= deviceLimits.maxImageDimension3D),
2678                                                                   "Reported dimensions smaller than device limits");
2679                                         results.check(properties.maxMipLevels == fullMipPyramidSize, "maxMipLevels is not full mip pyramid size");
2680                                         results.check(imageType == VK_IMAGE_TYPE_3D || properties.maxArrayLayers >= deviceLimits.maxImageArrayLayers,
2681                                                                   "maxArrayLayers smaller than device limits");
2682                                 }
2683                                 else
2684                                 {
2685                                         results.check(properties.maxMipLevels == 1 || properties.maxMipLevels == fullMipPyramidSize, "Invalid mip pyramid size");
2686                                         results.check(properties.maxArrayLayers >= 1, "Invalid maxArrayLayers");
2687                                 }
2688
2689                                 results.check(properties.maxResourceSize >= (VkDeviceSize)MINIMUM_REQUIRED_IMAGE_RESOURCE_SIZE,
2690                                                           "maxResourceSize smaller than minimum required size");
2691                         }
2692                         else if (queryResult == VK_ERROR_FORMAT_NOT_SUPPORTED)
2693                         {
2694                                 log << TestLog::Message << "Got VK_ERROR_FORMAT_NOT_SUPPORTED" << TestLog::EndMessage;
2695
2696                                 if (isRequiredCombination)
2697                                         results.fail("VK_ERROR_FORMAT_NOT_SUPPORTED returned for required image parameter combination");
2698
2699                                 // Specification requires that all fields are set to 0
2700                                 results.check(properties.maxExtent.width        == 0, "maxExtent.width != 0");
2701                                 results.check(properties.maxExtent.height       == 0, "maxExtent.height != 0");
2702                                 results.check(properties.maxExtent.depth        == 0, "maxExtent.depth != 0");
2703                                 results.check(properties.maxMipLevels           == 0, "maxMipLevels != 0");
2704                                 results.check(properties.maxArrayLayers         == 0, "maxArrayLayers != 0");
2705                                 results.check(properties.sampleCounts           == 0, "sampleCounts != 0");
2706                                 results.check(properties.maxResourceSize        == 0, "maxResourceSize != 0");
2707                         }
2708                         else
2709                         {
2710                                 results.fail("Got unexpected error" + de::toString(queryResult));
2711                         }
2712                 }
2713         }
2714
2715         return tcu::TestStatus(results.getResult(), results.getMessage());
2716 }
2717
2718 // VK_KHR_get_physical_device_properties2
2719
2720 string toString (const VkPhysicalDevice16BitStorageFeatures& value)
2721 {
2722         std::ostringstream      s;
2723         s << "VkPhysicalDevice16BitStorageFeatures = {\n";
2724         s << "\tsType = " << value.sType << '\n';
2725         s << "\tstorageBuffer16BitAccess = " << value.storageBuffer16BitAccess << '\n';
2726         s << "\tuniformAndStorageBuffer16BitAccess = " << value.uniformAndStorageBuffer16BitAccess << '\n';
2727         s << "\tstoragePushConstant16 = " << value.storagePushConstant16 << '\n';
2728         s << "\tstorageInputOutput16 = " << value.storageInputOutput16 << '\n';
2729         s << '}';
2730         return s.str();
2731 }
2732
2733 string toString (const VkPhysicalDeviceFloatControlsPropertiesKHR& value)
2734 {
2735         std::ostringstream      s;
2736         s << "VkPhysicalDeviceFloatControlsPropertiesKHR = {\n";
2737         s << "\tsType = " << value.sType << '\n';
2738         s << "\tseparateDenormSettings = " << value.separateDenormSettings << '\n';
2739         s << "\tseparateRoundingModeSettings = " << value.separateRoundingModeSettings << '\n';
2740         s << "\tshaderSignedZeroInfNanPreserveFloat16 = " << value.shaderSignedZeroInfNanPreserveFloat16 << '\n';
2741         s << "\tshaderSignedZeroInfNanPreserveFloat32 = " << value.shaderSignedZeroInfNanPreserveFloat32 << '\n';
2742         s << "\tshaderSignedZeroInfNanPreserveFloat64 = " << value.shaderSignedZeroInfNanPreserveFloat64 << '\n';
2743         s << "\tshaderDenormPreserveFloat16 = " << value.shaderDenormPreserveFloat16 << '\n';
2744         s << "\tshaderDenormPreserveFloat32 = " << value.shaderDenormPreserveFloat32 << '\n';
2745         s << "\tshaderDenormPreserveFloat64 = " << value.shaderDenormPreserveFloat64 << '\n';
2746         s << "\tshaderDenormFlushToZeroFloat16 = " << value.shaderDenormFlushToZeroFloat16 << '\n';
2747         s << "\tshaderDenormFlushToZeroFloat32 = " << value.shaderDenormFlushToZeroFloat32 << '\n';
2748         s << "\tshaderDenormFlushToZeroFloat64 = " << value.shaderDenormFlushToZeroFloat64 << '\n';
2749         s << "\tshaderRoundingModeRTEFloat16 = " << value.shaderRoundingModeRTEFloat16 << '\n';
2750         s << "\tshaderRoundingModeRTEFloat32 = " << value.shaderRoundingModeRTEFloat32 << '\n';
2751         s << "\tshaderRoundingModeRTEFloat64 = " << value.shaderRoundingModeRTEFloat64 << '\n';
2752         s << "\tshaderRoundingModeRTZFloat16 = " << value.shaderRoundingModeRTZFloat16 << '\n';
2753         s << "\tshaderRoundingModeRTZFloat32 = " << value.shaderRoundingModeRTZFloat32 << '\n';
2754         s << "\tshaderRoundingModeRTZFloat64 = " << value.shaderRoundingModeRTZFloat64 << '\n';
2755         s << '}';
2756         return s.str();
2757 }
2758
2759 string toString (const VkPhysicalDeviceMultiviewFeatures& value)
2760 {
2761         std::ostringstream      s;
2762         s << "VkPhysicalDeviceMultiviewFeatures = {\n";
2763         s << "\tsType = " << value.sType << '\n';
2764         s << "\tmultiview = " << value.multiview << '\n';
2765         s << "\tmultiviewGeometryShader = " << value.multiviewGeometryShader << '\n';
2766         s << "\tmultiviewTessellationShader = " << value.multiviewTessellationShader << '\n';
2767         s << '}';
2768         return s.str();
2769 }
2770
2771 string toString (const VkPhysicalDeviceProtectedMemoryFeatures& value)
2772 {
2773         std::ostringstream      s;
2774         s << "VkPhysicalDeviceProtectedMemoryFeatures = {\n";
2775         s << "\tsType = " << value.sType << '\n';
2776         s << "\tprotectedMemory = " << value.protectedMemory << '\n';
2777         s << '}';
2778         return s.str();
2779 }
2780
2781 string toString (const VkPhysicalDeviceSamplerYcbcrConversionFeatures& value)
2782 {
2783         std::ostringstream      s;
2784         s << "VkPhysicalDeviceSamplerYcbcrConversionFeatures = {\n";
2785         s << "\tsType = " << value.sType << '\n';
2786         s << "\tsamplerYcbcrConversion = " << value.samplerYcbcrConversion << '\n';
2787         s << '}';
2788         return s.str();
2789 }
2790
2791 string toString (const VkPhysicalDeviceVariablePointerFeatures& value)
2792 {
2793         std::ostringstream      s;
2794         s << "VkPhysicalDeviceVariablePointerFeatures = {\n";
2795         s << "\tsType = " << value.sType << '\n';
2796         s << "\tvariablePointersStorageBuffer = " << value.variablePointersStorageBuffer << '\n';
2797         s << "\tvariablePointers = " << value.variablePointers << '\n';
2798         s << '}';
2799         return s.str();
2800 }
2801
2802 string toString(const VkPhysicalDevicePushDescriptorPropertiesKHR& value)
2803 {
2804         std::ostringstream      s;
2805         s << "VkPhysicalDevicePushDescriptorPropertiesKHR = {\n";
2806         s << "\tsType = " << value.sType << '\n';
2807         s << "\tmaxPushDescriptors = " << value.maxPushDescriptors << '\n';
2808         s << '}';
2809         return s.str();
2810 }
2811
2812 string toString(const VkPhysicalDeviceScalarBlockLayoutFeaturesEXT& value)
2813 {
2814         std::ostringstream      s;
2815         s << "VkPhysicalDeviceScalarBlockLayoutFeaturesEXT = {\n";
2816         s << "\tsType = " << value.sType << '\n';
2817         s << "\tscalarBlockLayout = " << value.scalarBlockLayout << '\n';
2818         s << '}';
2819         return s.str();
2820 }
2821
2822 bool checkExtension (vector<VkExtensionProperties>& properties, const char* extension)
2823 {
2824         for (size_t ndx = 0; ndx < properties.size(); ++ndx)
2825         {
2826                 if (strcmp(properties[ndx].extensionName, extension) == 0)
2827                         return true;
2828         }
2829         return false;
2830 }
2831
2832 tcu::TestStatus deviceFeatures2 (Context& context)
2833 {
2834         const PlatformInterface&        vkp                             = context.getPlatformInterface();
2835         const VkPhysicalDevice          physicalDevice  = context.getPhysicalDevice();
2836         const Unique<VkInstance>        instance                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
2837         const InstanceDriver            vki                             (vkp, *instance);
2838         TestLog&                                        log                             = context.getTestContext().getLog();
2839         VkPhysicalDeviceFeatures        coreFeatures;
2840         VkPhysicalDeviceFeatures2       extFeatures;
2841
2842         deMemset(&coreFeatures, 0xcd, sizeof(coreFeatures));
2843         deMemset(&extFeatures.features, 0xcd, sizeof(extFeatures.features));
2844         std::vector<std::string> instExtensions = context.getInstanceExtensions();
2845
2846         extFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
2847         extFeatures.pNext = DE_NULL;
2848
2849         vki.getPhysicalDeviceFeatures(physicalDevice, &coreFeatures);
2850         vki.getPhysicalDeviceFeatures2(physicalDevice, &extFeatures);
2851
2852         TCU_CHECK(extFeatures.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2);
2853         TCU_CHECK(extFeatures.pNext == DE_NULL);
2854
2855         if (deMemCmp(&coreFeatures, &extFeatures.features, sizeof(VkPhysicalDeviceFeatures)) != 0)
2856                 TCU_FAIL("Mismatch between features reported by vkGetPhysicalDeviceFeatures and vkGetPhysicalDeviceFeatures2");
2857
2858         log << TestLog::Message << extFeatures << TestLog::EndMessage;
2859
2860         vector<VkExtensionProperties>   properties = enumerateDeviceExtensionProperties(vki, physicalDevice, DE_NULL);
2861         const bool khr_8bit_storage                             = checkExtension(properties,"VK_KHR_8bit_storage");
2862         const bool ext_conditional_rendering    = checkExtension(properties,"VK_EXT_conditional_rendering");
2863         const bool scalar_block_layout                  = checkExtension(properties,"VK_EXT_scalar_block_layout");
2864         bool khr_16bit_storage                                  = true;
2865         bool khr_multiview                                              = true;
2866         bool deviceProtectedMemory                              = true;
2867         bool sampler_ycbcr_conversion                   = true;
2868         bool variable_pointers                                  = true;
2869         if (getPhysicalDeviceProperties(vki, physicalDevice).apiVersion < VK_API_VERSION_1_1)
2870         {
2871                 khr_16bit_storage = checkExtension(properties,"VK_KHR_16bit_storage");
2872                 khr_multiview = checkExtension(properties,"VK_KHR_multiview");
2873                 deviceProtectedMemory = false;
2874                 sampler_ycbcr_conversion = checkExtension(properties,"VK_KHR_sampler_ycbcr_conversion");
2875                 variable_pointers = checkExtension(properties,"VK_KHR_variable_pointers");
2876         }
2877
2878         const int count = 2u;
2879         VkPhysicalDevice8BitStorageFeaturesKHR                          device8BitStorageFeatures[count];
2880         VkPhysicalDeviceConditionalRenderingFeaturesEXT         deviceConditionalRenderingFeatures[count];
2881         VkPhysicalDevice16BitStorageFeatures                            device16BitStorageFeatures[count];
2882         VkPhysicalDeviceMultiviewFeatures                                       deviceMultiviewFeatures[count];
2883         VkPhysicalDeviceProtectedMemoryFeatures                         protectedMemoryFeatures[count];
2884         VkPhysicalDeviceSamplerYcbcrConversionFeatures          samplerYcbcrConversionFeatures[count];
2885         VkPhysicalDeviceVariablePointerFeatures                         variablePointerFeatures[count];
2886         VkPhysicalDeviceScalarBlockLayoutFeaturesEXT            scalarBlockLayoutFeatures[count];
2887
2888         for (int ndx = 0; ndx < count; ++ndx)
2889         {
2890                 deMemset(&device8BitStorageFeatures[ndx],                       0xFF*ndx, sizeof(VkPhysicalDevice8BitStorageFeaturesKHR));
2891                 deMemset(&deviceConditionalRenderingFeatures[ndx],      0xFF*ndx, sizeof(VkPhysicalDeviceConditionalRenderingFeaturesEXT));
2892                 deMemset(&device16BitStorageFeatures[ndx],                      0xFF*ndx, sizeof(VkPhysicalDevice16BitStorageFeatures));
2893                 deMemset(&deviceMultiviewFeatures[ndx],                         0xFF*ndx, sizeof(VkPhysicalDeviceMultiviewFeatures));
2894                 deMemset(&protectedMemoryFeatures[ndx],                         0xFF*ndx, sizeof(VkPhysicalDeviceProtectedMemoryFeatures));
2895                 deMemset(&samplerYcbcrConversionFeatures[ndx],          0xFF*ndx, sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
2896                 deMemset(&variablePointerFeatures[ndx],                         0xFF*ndx, sizeof(VkPhysicalDeviceVariablePointerFeatures));
2897                 deMemset(&scalarBlockLayoutFeatures[ndx],                       0xFF*ndx, sizeof(VkPhysicalDeviceScalarBlockLayoutFeaturesEXT));
2898
2899                 device8BitStorageFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR;
2900                 device8BitStorageFeatures[ndx].pNext = &deviceConditionalRenderingFeatures[ndx];
2901
2902                 deviceConditionalRenderingFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CONDITIONAL_RENDERING_FEATURES_EXT;
2903                 deviceConditionalRenderingFeatures[ndx].pNext = &device16BitStorageFeatures[ndx];
2904
2905                 device16BitStorageFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES;
2906                 device16BitStorageFeatures[ndx].pNext = &deviceMultiviewFeatures[ndx];
2907
2908                 deviceMultiviewFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES;
2909                 deviceMultiviewFeatures[ndx].pNext = &protectedMemoryFeatures[ndx];
2910
2911                 protectedMemoryFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_FEATURES;
2912                 protectedMemoryFeatures[ndx].pNext = &samplerYcbcrConversionFeatures[ndx];
2913
2914                 samplerYcbcrConversionFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
2915                 samplerYcbcrConversionFeatures[ndx].pNext = &variablePointerFeatures[ndx];
2916
2917                 variablePointerFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES;
2918                 variablePointerFeatures[ndx].pNext = &scalarBlockLayoutFeatures[ndx];
2919
2920                 scalarBlockLayoutFeatures[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT;
2921                 scalarBlockLayoutFeatures[ndx].pNext = DE_NULL;
2922
2923                 deMemset(&extFeatures.features, 0xcd, sizeof(extFeatures.features));
2924                 extFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
2925                 extFeatures.pNext = &device8BitStorageFeatures[ndx];
2926
2927                 vki.getPhysicalDeviceFeatures2(physicalDevice, &extFeatures);
2928         }
2929
2930         if ( khr_8bit_storage &&
2931                 (device8BitStorageFeatures[0].storageBuffer8BitAccess                           != device8BitStorageFeatures[1].storageBuffer8BitAccess ||
2932                 device8BitStorageFeatures[0].uniformAndStorageBuffer8BitAccess          != device8BitStorageFeatures[1].uniformAndStorageBuffer8BitAccess ||
2933                 device8BitStorageFeatures[0].storagePushConstant8                                       != device8BitStorageFeatures[1].storagePushConstant8 )
2934                 )
2935         {
2936                 TCU_FAIL("Mismatch between VkPhysicalDevice8BitStorageFeatures");
2937         }
2938
2939         if ( ext_conditional_rendering &&
2940                 (deviceConditionalRenderingFeatures[0].conditionalRendering                             != deviceConditionalRenderingFeatures[1].conditionalRendering ||
2941                 deviceConditionalRenderingFeatures[0].inheritedConditionalRendering             != deviceConditionalRenderingFeatures[1].inheritedConditionalRendering )
2942                 )
2943         {
2944                 TCU_FAIL("Mismatch between VkPhysicalDeviceConditionalRenderingFeaturesEXT");
2945         }
2946
2947         if ( khr_16bit_storage &&
2948                 (device16BitStorageFeatures[0].storageBuffer16BitAccess                         != device16BitStorageFeatures[1].storageBuffer16BitAccess ||
2949                 device16BitStorageFeatures[0].uniformAndStorageBuffer16BitAccess        != device16BitStorageFeatures[1].uniformAndStorageBuffer16BitAccess ||
2950                 device16BitStorageFeatures[0].storagePushConstant16                                     != device16BitStorageFeatures[1].storagePushConstant16 ||
2951                 device16BitStorageFeatures[0].storageInputOutput16                                      != device16BitStorageFeatures[1].storageInputOutput16)
2952                 )
2953         {
2954                 TCU_FAIL("Mismatch between VkPhysicalDevice16BitStorageFeatures");
2955         }
2956
2957         if (khr_multiview &&
2958                 (deviceMultiviewFeatures[0].multiview                                   != deviceMultiviewFeatures[1].multiview ||
2959                 deviceMultiviewFeatures[0].multiviewGeometryShader              != deviceMultiviewFeatures[1].multiviewGeometryShader ||
2960                 deviceMultiviewFeatures[0].multiviewTessellationShader  != deviceMultiviewFeatures[1].multiviewTessellationShader)
2961                 )
2962         {
2963                 TCU_FAIL("Mismatch between VkPhysicalDeviceMultiviewFeatures");
2964         }
2965
2966         if (deviceProtectedMemory && protectedMemoryFeatures[0].protectedMemory != protectedMemoryFeatures[1].protectedMemory)
2967         {
2968                 TCU_FAIL("Mismatch between VkPhysicalDeviceProtectedMemoryFeatures");
2969         }
2970
2971         if (sampler_ycbcr_conversion && samplerYcbcrConversionFeatures[0].samplerYcbcrConversion != samplerYcbcrConversionFeatures[1].samplerYcbcrConversion)
2972         {
2973                 TCU_FAIL("Mismatch between VkPhysicalDeviceSamplerYcbcrConversionFeatures");
2974         }
2975
2976         if (variable_pointers &&
2977                 (variablePointerFeatures[0].variablePointersStorageBuffer       != variablePointerFeatures[1].variablePointersStorageBuffer ||
2978                 variablePointerFeatures[0].variablePointers                                     != variablePointerFeatures[1].variablePointers)
2979                 )
2980         {
2981                 TCU_FAIL("Mismatch between VkPhysicalDeviceVariablePointerFeatures");
2982         }
2983         if (scalar_block_layout &&
2984                 (scalarBlockLayoutFeatures[0].scalarBlockLayout != scalarBlockLayoutFeatures[1].scalarBlockLayout))
2985         {
2986                 TCU_FAIL("Mismatch between VkPhysicalDeviceScalarBlockLayoutFeaturesEXT");
2987         }
2988         if (khr_8bit_storage)
2989                 log << TestLog::Message << device8BitStorageFeatures[0]         << TestLog::EndMessage;
2990         if (ext_conditional_rendering)
2991                 log << TestLog::Message << deviceConditionalRenderingFeatures[0]                << TestLog::EndMessage;
2992         if (khr_16bit_storage)
2993                 log << TestLog::Message << toString(device16BitStorageFeatures[0])              << TestLog::EndMessage;
2994         if (khr_multiview)
2995                 log << TestLog::Message << toString(deviceMultiviewFeatures[0])                 << TestLog::EndMessage;
2996         if (deviceProtectedMemory)
2997                 log << TestLog::Message << toString(protectedMemoryFeatures[0])                 << TestLog::EndMessage;
2998         if (sampler_ycbcr_conversion)
2999                 log << TestLog::Message << toString(samplerYcbcrConversionFeatures[0])  << TestLog::EndMessage;
3000         if (variable_pointers)
3001                 log << TestLog::Message << toString(variablePointerFeatures[0])                 << TestLog::EndMessage;
3002         if (scalar_block_layout)
3003                 log << TestLog::Message << toString(scalarBlockLayoutFeatures[0])               << TestLog::EndMessage;
3004
3005         return tcu::TestStatus::pass("Querying device features succeeded");
3006 }
3007
3008
3009 string toString (const VkPhysicalDeviceIDProperties& value)
3010 {
3011         std::ostringstream      s;
3012         s << "VkPhysicalDeviceIDProperties = {\n";
3013         s << "\tsType = " << value.sType << '\n';
3014         s << "\tdeviceUUID = " << '\n' << tcu::formatArray(tcu::Format::HexIterator<deUint8>(DE_ARRAY_BEGIN(value.deviceUUID)), tcu::Format::HexIterator<deUint8>(DE_ARRAY_END(value.deviceUUID))) << '\n';
3015         s << "\tdriverUUID = " << '\n' << tcu::formatArray(tcu::Format::HexIterator<deUint8>(DE_ARRAY_BEGIN(value.driverUUID)), tcu::Format::HexIterator<deUint8>(DE_ARRAY_END(value.driverUUID))) << '\n';
3016         s << "\tdeviceLUID = " << '\n' << tcu::formatArray(tcu::Format::HexIterator<deUint8>(DE_ARRAY_BEGIN(value.deviceLUID)), tcu::Format::HexIterator<deUint8>(DE_ARRAY_END(value.deviceLUID))) << '\n';
3017         s << "\tdeviceNodeMask = " << value.deviceNodeMask << '\n';
3018         s << "\tdeviceLUIDValid = " << value.deviceLUIDValid << '\n';
3019         s << '}';
3020         return s.str();
3021 }
3022
3023 string toString (const VkPhysicalDeviceMaintenance3Properties& value)
3024 {
3025         std::ostringstream      s;
3026         s << "VkPhysicalDeviceMaintenance3Properties = {\n";
3027         s << "\tsType = " << value.sType << '\n';
3028         s << "\tmaxPerSetDescriptors = " << value.maxPerSetDescriptors << '\n';
3029         s << "\tmaxMemoryAllocationSize = " << value.maxMemoryAllocationSize << '\n';
3030         s << '}';
3031         return s.str();
3032 }
3033
3034 string toString (const VkPhysicalDeviceMultiviewProperties& value)
3035 {
3036         std::ostringstream      s;
3037         s << "VkPhysicalDeviceMultiviewProperties = {\n";
3038         s << "\tsType = " << value.sType << '\n';
3039         s << "\tmaxMultiviewViewCount = " << value.maxMultiviewViewCount << '\n';
3040         s << "\tmaxMultiviewInstanceIndex = " << value.maxMultiviewInstanceIndex << '\n';
3041         s << '}';
3042         return s.str();
3043 }
3044
3045 string toString (const VkPhysicalDevicePointClippingProperties& value)
3046 {
3047         std::ostringstream      s;
3048         s << "VkPhysicalDevicePointClippingProperties = {\n";
3049         s << "\tsType = " << value.sType << '\n';
3050         s << "\tpointClippingBehavior = " << value.pointClippingBehavior << '\n';
3051         s << '}';
3052         return s.str();
3053 }
3054
3055 string toString (const VkPhysicalDeviceProtectedMemoryProperties& value)
3056 {
3057         std::ostringstream      s;
3058         s << "VkPhysicalDeviceProtectedMemoryProperties = {\n";
3059         s << "\tsType = " << value.sType << '\n';
3060         s << "\tprotectedNoFault = " << value.protectedNoFault << '\n';
3061         s << '}';
3062         return s.str();
3063 }
3064
3065
3066 string toString (const VkPhysicalDeviceSubgroupProperties& value)
3067 {
3068         std::ostringstream      s;
3069         s << "VkPhysicalDeviceSubgroupProperties = {\n";
3070         s << "\tsType = " << value.sType << '\n';
3071         s << "\tsubgroupSize = " << value.subgroupSize << '\n';
3072         s << "\tsupportedStages = " << getShaderStageFlagsStr(value.supportedStages) << '\n';
3073         s << "\tsupportedOperations = " << getSubgroupFeatureFlagsStr(value.supportedOperations) << '\n';
3074         s << "\tquadOperationsInAllStages = " << value.quadOperationsInAllStages << '\n';
3075         s << '}';
3076         return s.str();
3077 }
3078
3079 tcu::TestStatus deviceProperties2 (Context& context)
3080 {
3081         const PlatformInterface&                vkp                             = context.getPlatformInterface();
3082         const VkPhysicalDevice                  physicalDevice  = context.getPhysicalDevice();
3083         const Unique<VkInstance>                instance                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
3084         const InstanceDriver                    vki                             (vkp, *instance);
3085         TestLog&                                                log                             = context.getTestContext().getLog();
3086         VkPhysicalDeviceProperties              coreProperties;
3087         VkPhysicalDeviceProperties2             extProperties;
3088
3089         extProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
3090         extProperties.pNext = DE_NULL;
3091
3092         vki.getPhysicalDeviceProperties(physicalDevice, &coreProperties);
3093         vki.getPhysicalDeviceProperties2(physicalDevice, &extProperties);
3094
3095         TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2);
3096         TCU_CHECK(extProperties.pNext == DE_NULL);
3097
3098         // We can't use memcmp() here because the structs may contain padding bytes that drivers may or may not
3099         // have written while writing the data and memcmp will compare them anyway, so we iterate through the
3100         // valid bytes for each field in the struct and compare only the valid bytes for each one.
3101         for (int propNdx = 0; propNdx < DE_LENGTH_OF_ARRAY(s_physicalDevicePropertiesOffsetTable); propNdx++)
3102         {
3103                 const size_t offset                                     = s_physicalDevicePropertiesOffsetTable[propNdx].offset;
3104                 const size_t size                                       = s_physicalDevicePropertiesOffsetTable[propNdx].size;
3105
3106                 const deUint8* corePropertyBytes        = reinterpret_cast<deUint8*>(&coreProperties) + offset;
3107                 const deUint8* extPropertyBytes         = reinterpret_cast<deUint8*>(&extProperties.properties) + offset;
3108
3109                 if (deMemCmp(corePropertyBytes, extPropertyBytes, size) != 0)
3110                         TCU_FAIL("Mismatch between properties reported by vkGetPhysicalDeviceProperties and vkGetPhysicalDeviceProperties2");
3111         }
3112
3113         log << TestLog::Message << extProperties.properties << TestLog::EndMessage;
3114
3115         const int count = 2u;
3116
3117         bool khr_external_memory_capabilities           = true;
3118         bool khr_multiview                                                      = true;
3119         bool khr_maintenance2                                           = true;
3120         bool khr_maintenance3                                           = true;
3121         bool apiVersionSmallerThen_1_1                          = (getPhysicalDeviceProperties(vki, physicalDevice).apiVersion < VK_API_VERSION_1_1);
3122         if (apiVersionSmallerThen_1_1)
3123         {
3124                 vector<VkExtensionProperties> properties        = enumerateDeviceExtensionProperties(vki, physicalDevice, DE_NULL);
3125                 khr_external_memory_capabilities                        = checkExtension(properties,"VK_KHR_external_memory_capabilities");
3126                 khr_multiview                                                           = checkExtension(properties,"VK_KHR_multiview");
3127                 khr_maintenance2                                                        = checkExtension(properties,"VK_KHR_maintenance2");
3128                 khr_maintenance3                                                        = checkExtension(properties,"VK_KHR_maintenance3");
3129         }
3130
3131         VkPhysicalDeviceIDProperties                            IDProperties[count];
3132         VkPhysicalDeviceMaintenance3Properties          maintenance3Properties[count];
3133         VkPhysicalDeviceMultiviewProperties                     multiviewProperties[count];
3134         VkPhysicalDevicePointClippingProperties         pointClippingProperties[count];
3135         VkPhysicalDeviceProtectedMemoryProperties       protectedMemoryPropertiesKHR[count];
3136         VkPhysicalDeviceSubgroupProperties                      subgroupProperties[count];
3137
3138         for (int ndx = 0; ndx < count; ++ndx)
3139         {
3140                 deMemset(&IDProperties[ndx],                                    0xFF*ndx, sizeof(VkPhysicalDeviceIDProperties                           ));
3141                 deMemset(&maintenance3Properties[ndx],                  0xFF*ndx, sizeof(VkPhysicalDeviceMaintenance3Properties         ));
3142                 deMemset(&multiviewProperties[ndx],                             0xFF*ndx, sizeof(VkPhysicalDeviceMultiviewProperties            ));
3143                 deMemset(&pointClippingProperties[ndx],                 0xFF*ndx, sizeof(VkPhysicalDevicePointClippingProperties        ));
3144                 deMemset(&protectedMemoryPropertiesKHR[ndx],    0xFF*ndx, sizeof(VkPhysicalDeviceProtectedMemoryProperties      ));
3145                 deMemset(&subgroupProperties[ndx],                              0xFF*ndx, sizeof(VkPhysicalDeviceSubgroupProperties                     ));
3146
3147                 IDProperties[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES;
3148                 IDProperties[ndx].pNext = &maintenance3Properties[ndx];
3149
3150                 maintenance3Properties[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES;
3151                 maintenance3Properties[ndx].pNext = &multiviewProperties[ndx];
3152
3153                 multiviewProperties[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES;
3154                 multiviewProperties[ndx].pNext = &pointClippingProperties[ndx];
3155
3156                 pointClippingProperties[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES;
3157                 pointClippingProperties[ndx].pNext = &protectedMemoryPropertiesKHR[ndx];
3158
3159                 protectedMemoryPropertiesKHR[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROTECTED_MEMORY_PROPERTIES;
3160                 protectedMemoryPropertiesKHR[ndx].pNext = &subgroupProperties[ndx];
3161
3162                 subgroupProperties[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
3163                 subgroupProperties[ndx].pNext = DE_NULL;
3164
3165                 extProperties.pNext = &IDProperties[ndx];
3166
3167                 vki.getPhysicalDeviceProperties2(physicalDevice, &extProperties);
3168
3169                 IDProperties[ndx].pNext                                         = DE_NULL;
3170                 maintenance3Properties[ndx].pNext                       = DE_NULL;
3171                 multiviewProperties[ndx].pNext                          = DE_NULL;
3172                 pointClippingProperties[ndx].pNext                      = DE_NULL;
3173                 protectedMemoryPropertiesKHR[ndx].pNext         = DE_NULL;
3174                 subgroupProperties[ndx].pNext                           = DE_NULL;
3175         }
3176
3177         if (khr_external_memory_capabilities)
3178         {
3179                 if ((deMemCmp(IDProperties[0].deviceUUID, IDProperties[1].deviceUUID, VK_UUID_SIZE) != 0) ||
3180                         (deMemCmp(IDProperties[0].driverUUID, IDProperties[1].driverUUID, VK_UUID_SIZE) != 0) ||
3181                         (IDProperties[0].deviceLUIDValid        != IDProperties[1].deviceLUIDValid))
3182                 {
3183                         TCU_FAIL("Mismatch between VkPhysicalDeviceIDProperties");
3184                 }
3185                 else if (IDProperties[0].deviceLUIDValid)
3186                 {
3187                         // If deviceLUIDValid is VK_FALSE, the contents of deviceLUID and deviceNodeMask are undefined
3188                         // so thay can only be compared when deviceLUIDValid is VK_TRUE.
3189                         if ((deMemCmp(IDProperties[0].deviceLUID, IDProperties[1].deviceLUID, VK_UUID_SIZE) != 0) ||
3190                                 (IDProperties[0].deviceNodeMask         != IDProperties[1].deviceNodeMask))
3191                         {
3192                                 TCU_FAIL("Mismatch between VkPhysicalDeviceIDProperties");
3193                         }
3194                 }
3195         }
3196         if (khr_maintenance3 &&
3197                 ((maintenance3Properties[0].maxPerSetDescriptors        != maintenance3Properties[1].maxPerSetDescriptors) ||
3198                 (maintenance3Properties[0].maxMemoryAllocationSize      != maintenance3Properties[1].maxMemoryAllocationSize))
3199                 )
3200         {
3201                 TCU_FAIL("Mismatch between VkPhysicalDeviceMaintenance3Properties");
3202         }
3203         if (khr_multiview &&
3204                 ((multiviewProperties[0].maxMultiviewViewCount          != multiviewProperties[1].maxMultiviewViewCount) ||
3205                 (multiviewProperties[0].maxMultiviewInstanceIndex       != multiviewProperties[1].maxMultiviewInstanceIndex))
3206                 )
3207         {
3208                 TCU_FAIL("Mismatch between VkPhysicalDeviceMultiviewProperties");
3209         }
3210         if (khr_maintenance2 &&
3211                 (pointClippingProperties[0].pointClippingBehavior != pointClippingProperties[1].pointClippingBehavior))
3212         {
3213                 TCU_FAIL("Mismatch between VkPhysicalDevicePointClippingProperties");
3214         }
3215         if (!apiVersionSmallerThen_1_1)
3216         {
3217                 if(protectedMemoryPropertiesKHR[0].protectedNoFault != protectedMemoryPropertiesKHR[1].protectedNoFault)
3218                 {
3219                         TCU_FAIL("Mismatch between VkPhysicalDeviceProtectedMemoryProperties");
3220                 }
3221                 if ((subgroupProperties[0].subgroupSize                                 != subgroupProperties[1].subgroupSize) ||
3222                         (subgroupProperties[0].supportedStages                          != subgroupProperties[1].supportedStages) ||
3223                         (subgroupProperties[0].supportedOperations                      != subgroupProperties[1].supportedOperations) ||
3224                         (subgroupProperties[0].quadOperationsInAllStages        != subgroupProperties[1].quadOperationsInAllStages))
3225                 {
3226                         TCU_FAIL("Mismatch between VkPhysicalDeviceSubgroupProperties");
3227                 }
3228         }
3229
3230         if (khr_external_memory_capabilities)
3231                 log << TestLog::Message << toString(IDProperties[0])                                    << TestLog::EndMessage;
3232         if (khr_maintenance3)
3233                 log << TestLog::Message << toString(maintenance3Properties[0])                  << TestLog::EndMessage;
3234         if (khr_multiview)
3235                 log << TestLog::Message << toString(multiviewProperties[0])                             << TestLog::EndMessage;
3236         if (khr_maintenance2)
3237                 log << TestLog::Message << toString(pointClippingProperties[0])                 << TestLog::EndMessage;
3238         if (!apiVersionSmallerThen_1_1)
3239         {
3240                 log << TestLog::Message << toString(protectedMemoryPropertiesKHR[0])    << TestLog::EndMessage
3241                         << TestLog::Message << toString(subgroupProperties[0])                          << TestLog::EndMessage;
3242         }
3243
3244         const vector<VkExtensionProperties>     extensions = enumerateDeviceExtensionProperties(vki, physicalDevice, DE_NULL);
3245
3246         if (isExtensionSupported(extensions, RequiredExtension("VK_KHR_push_descriptor")))
3247         {
3248                 VkPhysicalDevicePushDescriptorPropertiesKHR             pushDescriptorProperties[count];
3249
3250                 for (int ndx = 0; ndx < count; ++ndx)
3251                 {
3252                         deMemset(&pushDescriptorProperties[ndx], 0, sizeof(VkPhysicalDevicePushDescriptorPropertiesKHR));
3253
3254                         pushDescriptorProperties[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR;
3255                         pushDescriptorProperties[ndx].pNext     = DE_NULL;
3256
3257                         extProperties.pNext = &pushDescriptorProperties[ndx];
3258
3259                         vki.getPhysicalDeviceProperties2(physicalDevice, &extProperties);
3260
3261                         pushDescriptorProperties[ndx].pNext = DE_NULL;
3262                 }
3263
3264                 if (deMemCmp(&pushDescriptorProperties[0], &pushDescriptorProperties[1], sizeof(VkPhysicalDevicePushDescriptorPropertiesKHR)) != 0)
3265                 {
3266                         TCU_FAIL("Mismatch in vkGetPhysicalDeviceProperties2 in VkPhysicalDevicePushDescriptorPropertiesKHR ");
3267                 }
3268
3269                 log << TestLog::Message << toString(pushDescriptorProperties[0]) << TestLog::EndMessage;
3270
3271                 if (pushDescriptorProperties[0].maxPushDescriptors < 32)
3272                 {
3273                         TCU_FAIL("VkPhysicalDevicePushDescriptorPropertiesKHR.maxPushDescriptors must be at least 32");
3274                 }
3275         }
3276         if (isExtensionSupported(extensions, RequiredExtension("VK_KHR_shader_float_controls")))
3277         {
3278                 VkPhysicalDeviceFloatControlsPropertiesKHR floatControlsProperties[count];
3279
3280                 for (int ndx = 0; ndx < count; ++ndx)
3281                 {
3282                         deMemset(&floatControlsProperties[ndx], 0xFF, sizeof(VkPhysicalDeviceFloatControlsPropertiesKHR));
3283                         floatControlsProperties[ndx].sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR;
3284                         floatControlsProperties[ndx].pNext = DE_NULL;
3285
3286                         extProperties.pNext = &floatControlsProperties[ndx];
3287
3288                         vki.getPhysicalDeviceProperties2(physicalDevice, &extProperties);
3289                 }
3290
3291                 if (deMemCmp(&floatControlsProperties[0], &floatControlsProperties[1], sizeof(VkPhysicalDeviceFloatControlsPropertiesKHR)) != 0)
3292                 {
3293                         TCU_FAIL("Mismatch in VkPhysicalDeviceFloatControlsPropertiesKHR");
3294                 }
3295
3296                 log << TestLog::Message << toString(floatControlsProperties[0]) << TestLog::EndMessage;
3297         }
3298
3299         return tcu::TestStatus::pass("Querying device properties succeeded");
3300 }
3301
3302 string toString (const VkFormatProperties2& value)
3303 {
3304         std::ostringstream      s;
3305         s << "VkFormatProperties2 = {\n";
3306         s << "\tsType = " << value.sType << '\n';
3307         s << "\tformatProperties = {\n";
3308         s << "\tlinearTilingFeatures = " << getFormatFeatureFlagsStr(value.formatProperties.linearTilingFeatures) << '\n';
3309         s << "\toptimalTilingFeatures = " << getFormatFeatureFlagsStr(value.formatProperties.optimalTilingFeatures) << '\n';
3310         s << "\tbufferFeatures = " << getFormatFeatureFlagsStr(value.formatProperties.bufferFeatures) << '\n';
3311         s << "\t}";
3312         s << "}";
3313         return s.str();
3314 }
3315
3316 tcu::TestStatus deviceFormatProperties2 (Context& context)
3317 {
3318         const PlatformInterface&                vkp                             = context.getPlatformInterface();
3319         const VkPhysicalDevice                  physicalDevice  = context.getPhysicalDevice();
3320         const Unique<VkInstance>                instance                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
3321         const InstanceDriver                    vki                             (vkp, *instance);
3322         TestLog&                                                log                             = context.getTestContext().getLog();
3323
3324         for (int formatNdx = 0; formatNdx < VK_CORE_FORMAT_LAST; ++formatNdx)
3325         {
3326                 const VkFormat                  format                  = (VkFormat)formatNdx;
3327                 VkFormatProperties              coreProperties;
3328                 VkFormatProperties2             extProperties;
3329
3330                 deMemset(&coreProperties, 0xcd, sizeof(VkFormatProperties));
3331                 deMemset(&extProperties, 0xcd, sizeof(VkFormatProperties2));
3332
3333                 extProperties.sType     = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2;
3334                 extProperties.pNext = DE_NULL;
3335
3336                 vki.getPhysicalDeviceFormatProperties(physicalDevice, format, &coreProperties);
3337                 vki.getPhysicalDeviceFormatProperties2(physicalDevice, format, &extProperties);
3338
3339                 TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2);
3340                 TCU_CHECK(extProperties.pNext == DE_NULL);
3341
3342         if (deMemCmp(&coreProperties, &extProperties.formatProperties, sizeof(VkFormatProperties)) != 0)
3343                 TCU_FAIL("Mismatch between format properties reported by vkGetPhysicalDeviceFormatProperties and vkGetPhysicalDeviceFormatProperties2");
3344
3345         log << TestLog::Message << toString (extProperties) << TestLog::EndMessage;
3346         }
3347
3348         return tcu::TestStatus::pass("Querying device format properties succeeded");
3349 }
3350
3351 string toString (const VkQueueFamilyProperties2& value)
3352 {
3353         std::ostringstream      s;
3354         s << "VkQueueFamilyProperties2 = {\n";
3355         s << "\tsType = " << value.sType << '\n';
3356         s << "\tqueueFamilyProperties = " << value.queueFamilyProperties << '\n';
3357         s << '}';
3358         return s.str();
3359 }
3360
3361 tcu::TestStatus deviceQueueFamilyProperties2 (Context& context)
3362 {
3363         const PlatformInterface&                vkp                                             = context.getPlatformInterface();
3364         const VkPhysicalDevice                  physicalDevice                  = context.getPhysicalDevice();
3365         const Unique<VkInstance>                instance                                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
3366         const InstanceDriver                    vki                                             (vkp, *instance);
3367         TestLog&                                                log                                             = context.getTestContext().getLog();
3368         deUint32                                                numCoreQueueFamilies    = ~0u;
3369         deUint32                                                numExtQueueFamilies             = ~0u;
3370
3371         vki.getPhysicalDeviceQueueFamilyProperties(physicalDevice, &numCoreQueueFamilies, DE_NULL);
3372         vki.getPhysicalDeviceQueueFamilyProperties2(physicalDevice, &numExtQueueFamilies, DE_NULL);
3373
3374         TCU_CHECK_MSG(numCoreQueueFamilies == numExtQueueFamilies, "Different number of queue family properties reported");
3375         TCU_CHECK(numCoreQueueFamilies > 0);
3376
3377         {
3378                 std::vector<VkQueueFamilyProperties>            coreProperties  (numCoreQueueFamilies);
3379                 std::vector<VkQueueFamilyProperties2>           extProperties   (numExtQueueFamilies);
3380
3381                 deMemset(&coreProperties[0], 0xcd, sizeof(VkQueueFamilyProperties)*numCoreQueueFamilies);
3382                 deMemset(&extProperties[0], 0xcd, sizeof(VkQueueFamilyProperties2)*numExtQueueFamilies);
3383
3384                 for (size_t ndx = 0; ndx < extProperties.size(); ++ndx)
3385                 {
3386                         extProperties[ndx].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2;
3387                         extProperties[ndx].pNext = DE_NULL;
3388                 }
3389
3390                 vki.getPhysicalDeviceQueueFamilyProperties(physicalDevice, &numCoreQueueFamilies, &coreProperties[0]);
3391                 vki.getPhysicalDeviceQueueFamilyProperties2(physicalDevice, &numExtQueueFamilies, &extProperties[0]);
3392
3393                 TCU_CHECK((size_t)numCoreQueueFamilies == coreProperties.size());
3394                 TCU_CHECK((size_t)numExtQueueFamilies == extProperties.size());
3395                 DE_ASSERT(numCoreQueueFamilies == numExtQueueFamilies);
3396
3397                 for (size_t ndx = 0; ndx < extProperties.size(); ++ndx)
3398                 {
3399                         TCU_CHECK(extProperties[ndx].sType == VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2);
3400                         TCU_CHECK(extProperties[ndx].pNext == DE_NULL);
3401
3402                         if (deMemCmp(&coreProperties[ndx], &extProperties[ndx].queueFamilyProperties, sizeof(VkQueueFamilyProperties)) != 0)
3403                                 TCU_FAIL("Mismatch between format properties reported by vkGetPhysicalDeviceQueueFamilyProperties and vkGetPhysicalDeviceQueueFamilyProperties2");
3404
3405                         log << TestLog::Message << " queueFamilyNdx = " << ndx <<TestLog::EndMessage
3406                         << TestLog::Message << toString(extProperties[ndx]) << TestLog::EndMessage;
3407                 }
3408         }
3409
3410         return tcu::TestStatus::pass("Querying device queue family properties succeeded");
3411 }
3412
3413 tcu::TestStatus deviceMemoryProperties2 (Context& context)
3414 {
3415         const PlatformInterface&                        vkp                             = context.getPlatformInterface();
3416         const VkPhysicalDevice                          physicalDevice  = context.getPhysicalDevice();
3417         const Unique<VkInstance>                        instance                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
3418         const InstanceDriver                            vki                             (vkp, *instance);
3419         TestLog&                                                        log                             = context.getTestContext().getLog();
3420         VkPhysicalDeviceMemoryProperties        coreProperties;
3421         VkPhysicalDeviceMemoryProperties2       extProperties;
3422
3423         deMemset(&coreProperties, 0xcd, sizeof(VkPhysicalDeviceMemoryProperties));
3424         deMemset(&extProperties, 0xcd, sizeof(VkPhysicalDeviceMemoryProperties2));
3425
3426         extProperties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2;
3427         extProperties.pNext = DE_NULL;
3428
3429         vki.getPhysicalDeviceMemoryProperties(physicalDevice, &coreProperties);
3430         vki.getPhysicalDeviceMemoryProperties2(physicalDevice, &extProperties);
3431
3432         TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2);
3433         TCU_CHECK(extProperties.pNext == DE_NULL);
3434
3435         if (deMemCmp(&coreProperties, &extProperties.memoryProperties, sizeof(VkPhysicalDeviceMemoryProperties)) != 0)
3436                 TCU_FAIL("Mismatch between properties reported by vkGetPhysicalDeviceMemoryProperties and vkGetPhysicalDeviceMemoryProperties2");
3437
3438         log << TestLog::Message << extProperties << TestLog::EndMessage;
3439
3440         return tcu::TestStatus::pass("Querying device memory properties succeeded");
3441 }
3442
3443 tcu::TestStatus imageFormatProperties2 (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling)
3444 {
3445         if (isYCbCrFormat(format))
3446                 // check if Ycbcr format enums are valid given the version and extensions
3447                 checkYcbcrApiSupport(context);
3448
3449         TestLog&                                                log                             = context.getTestContext().getLog();
3450
3451         const PlatformInterface&                vkp                             = context.getPlatformInterface();
3452         const VkPhysicalDevice                  physicalDevice  = context.getPhysicalDevice();
3453         const Unique<VkInstance>                instance                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
3454         const InstanceDriver                    vki                             (vkp, *instance);
3455
3456         const VkImageCreateFlags                ycbcrFlags              = isYCbCrFormat(format) ? (VkImageCreateFlags)VK_IMAGE_CREATE_DISJOINT_BIT_KHR : (VkImageCreateFlags)0u;
3457         const VkImageUsageFlags                 allUsageFlags   = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
3458                                                                                                         | VK_IMAGE_USAGE_TRANSFER_DST_BIT
3459                                                                                                         | VK_IMAGE_USAGE_SAMPLED_BIT
3460                                                                                                         | VK_IMAGE_USAGE_STORAGE_BIT
3461                                                                                                         | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
3462                                                                                                         | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
3463                                                                                                         | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
3464                                                                                                         | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
3465         const VkImageCreateFlags                allCreateFlags  = VK_IMAGE_CREATE_SPARSE_BINDING_BIT
3466                                                                                                         | VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT
3467                                                                                                         | VK_IMAGE_CREATE_SPARSE_ALIASED_BIT
3468                                                                                                         | VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT
3469                                                                                                         | VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT
3470                                                                                                         | ycbcrFlags;
3471
3472         for (VkImageUsageFlags curUsageFlags = (VkImageUsageFlags)1; curUsageFlags <= allUsageFlags; curUsageFlags++)
3473         {
3474                 for (VkImageCreateFlags curCreateFlags = 0; curCreateFlags <= allCreateFlags; curCreateFlags++)
3475                 {
3476                         const VkPhysicalDeviceImageFormatInfo2  imageFormatInfo =
3477                         {
3478                                 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGE_FORMAT_INFO_2,
3479                                 DE_NULL,
3480                                 format,
3481                                 imageType,
3482                                 tiling,
3483                                 curUsageFlags,
3484                                 curCreateFlags
3485                         };
3486
3487                         VkImageFormatProperties                                         coreProperties;
3488                         VkImageFormatProperties2                                        extProperties;
3489                         VkResult                                                                        coreResult;
3490                         VkResult                                                                        extResult;
3491
3492                         deMemset(&coreProperties, 0xcd, sizeof(VkImageFormatProperties));
3493                         deMemset(&extProperties, 0xcd, sizeof(VkImageFormatProperties2));
3494
3495                         extProperties.sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2;
3496                         extProperties.pNext = DE_NULL;
3497
3498                         coreResult      = vki.getPhysicalDeviceImageFormatProperties(physicalDevice, imageFormatInfo.format, imageFormatInfo.type, imageFormatInfo.tiling, imageFormatInfo.usage, imageFormatInfo.flags, &coreProperties);
3499                         extResult       = vki.getPhysicalDeviceImageFormatProperties2(physicalDevice, &imageFormatInfo, &extProperties);
3500
3501                         TCU_CHECK(extProperties.sType == VK_STRUCTURE_TYPE_IMAGE_FORMAT_PROPERTIES_2);
3502                         TCU_CHECK(extProperties.pNext == DE_NULL);
3503
3504                         if ((coreResult != extResult) ||
3505                                 (deMemCmp(&coreProperties, &extProperties.imageFormatProperties, sizeof(VkImageFormatProperties)) != 0))
3506                         {
3507                                 log << TestLog::Message << "ERROR: device mismatch with query " << imageFormatInfo << TestLog::EndMessage
3508                                         << TestLog::Message << "vkGetPhysicalDeviceImageFormatProperties() returned " << coreResult << ", " << coreProperties << TestLog::EndMessage
3509                                         << TestLog::Message << "vkGetPhysicalDeviceImageFormatProperties2() returned " << extResult << ", " << extProperties << TestLog::EndMessage;
3510                                 TCU_FAIL("Mismatch between image format properties reported by vkGetPhysicalDeviceImageFormatProperties and vkGetPhysicalDeviceImageFormatProperties2");
3511                         }
3512                 }
3513         }
3514
3515         return tcu::TestStatus::pass("Querying image format properties succeeded");
3516 }
3517
3518 tcu::TestStatus sparseImageFormatProperties2 (Context& context, const VkFormat format, const VkImageType imageType, const VkImageTiling tiling)
3519 {
3520         TestLog&                                                log                             = context.getTestContext().getLog();
3521
3522         const PlatformInterface&                vkp                             = context.getPlatformInterface();
3523         const VkPhysicalDevice                  physicalDevice  = context.getPhysicalDevice();
3524         const Unique<VkInstance>                instance                (createInstanceWithExtension(vkp, context.getUsedApiVersion(), "VK_KHR_get_physical_device_properties2"));
3525         const InstanceDriver                    vki                             (vkp, *instance);
3526
3527         const VkImageUsageFlags                 allUsageFlags   = VK_IMAGE_USAGE_TRANSFER_SRC_BIT
3528                                                                                                         | VK_IMAGE_USAGE_TRANSFER_DST_BIT
3529                                                                                                         | VK_IMAGE_USAGE_SAMPLED_BIT
3530                                                                                                         | VK_IMAGE_USAGE_STORAGE_BIT
3531                                                                                                         | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
3532                                                                                                         | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
3533                                                                                                         | VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT
3534                                                                                                         | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
3535
3536         for (deUint32 sampleCountBit = VK_SAMPLE_COUNT_1_BIT; sampleCountBit <= VK_SAMPLE_COUNT_64_BIT; sampleCountBit = (sampleCountBit << 1u))
3537         {
3538                 for (VkImageUsageFlags curUsageFlags = (VkImageUsageFlags)1; curUsageFlags <= allUsageFlags; curUsageFlags++)
3539                 {
3540                         const VkPhysicalDeviceSparseImageFormatInfo2    imageFormatInfo =
3541                         {
3542                                 VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SPARSE_IMAGE_FORMAT_INFO_2,
3543                                 DE_NULL,
3544                                 format,
3545                                 imageType,
3546                                 (VkSampleCountFlagBits)sampleCountBit,
3547                                 curUsageFlags,
3548                                 tiling,
3549                         };
3550
3551                         deUint32                                                                                numCoreProperties       = ~0u;
3552                         deUint32                                                                                numExtProperties        = ~0u;
3553
3554                         // Query count
3555                         vki.getPhysicalDeviceSparseImageFormatProperties(physicalDevice, imageFormatInfo.format, imageFormatInfo.type, imageFormatInfo.samples, imageFormatInfo.usage, imageFormatInfo.tiling, &numCoreProperties, DE_NULL);
3556                         vki.getPhysicalDeviceSparseImageFormatProperties2(physicalDevice, &imageFormatInfo, &numExtProperties, DE_NULL);
3557
3558                         if (numCoreProperties != numExtProperties)
3559                         {
3560                                 log << TestLog::Message << "ERROR: different number of properties reported for " << imageFormatInfo << TestLog::EndMessage;
3561                                 TCU_FAIL("Mismatch in reported property count");
3562                         }
3563
3564                         if (numCoreProperties > 0)
3565                         {
3566                                 std::vector<VkSparseImageFormatProperties>              coreProperties  (numCoreProperties);
3567                                 std::vector<VkSparseImageFormatProperties2>             extProperties   (numExtProperties);
3568
3569                                 deMemset(&coreProperties[0], 0xcd, sizeof(VkSparseImageFormatProperties)*numCoreProperties);
3570                                 deMemset(&extProperties[0], 0xcd, sizeof(VkSparseImageFormatProperties2)*numExtProperties);
3571
3572                                 for (deUint32 ndx = 0; ndx < numExtProperties; ++ndx)
3573                                 {
3574                                         extProperties[ndx].sType = VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2;
3575                                         extProperties[ndx].pNext = DE_NULL;
3576                                 }
3577
3578                                 vki.getPhysicalDeviceSparseImageFormatProperties(physicalDevice, imageFormatInfo.format, imageFormatInfo.type, imageFormatInfo.samples, imageFormatInfo.usage, imageFormatInfo.tiling, &numCoreProperties, &coreProperties[0]);
3579                                 vki.getPhysicalDeviceSparseImageFormatProperties2(physicalDevice, &imageFormatInfo, &numExtProperties, &extProperties[0]);
3580
3581                                 TCU_CHECK((size_t)numCoreProperties == coreProperties.size());
3582                                 TCU_CHECK((size_t)numExtProperties == extProperties.size());
3583
3584                                 for (deUint32 ndx = 0; ndx < numCoreProperties; ++ndx)
3585                                 {
3586                                         TCU_CHECK(extProperties[ndx].sType == VK_STRUCTURE_TYPE_SPARSE_IMAGE_FORMAT_PROPERTIES_2);
3587                                         TCU_CHECK(extProperties[ndx].pNext == DE_NULL);
3588
3589                                         if ((deMemCmp(&coreProperties[ndx], &extProperties[ndx].properties, sizeof(VkSparseImageFormatProperties)) != 0))
3590                                         {
3591                                                 log << TestLog::Message << "ERROR: device mismatch with query " << imageFormatInfo << " property " << ndx << TestLog::EndMessage
3592                                                         << TestLog::Message << "vkGetPhysicalDeviceSparseImageFormatProperties() returned " << coreProperties[ndx] << TestLog::EndMessage
3593                                                         << TestLog::Message << "vkGetPhysicalDeviceSparseImageFormatProperties2() returned " << extProperties[ndx] << TestLog::EndMessage;
3594                                                 TCU_FAIL("Mismatch between image format properties reported by vkGetPhysicalDeviceSparseImageFormatProperties and vkGetPhysicalDeviceSparseImageFormatProperties2");
3595                                         }
3596                                 }
3597                         }
3598                 }
3599         }
3600
3601         return tcu::TestStatus::pass("Querying sparse image format properties succeeded");
3602 }
3603
3604 tcu::TestStatus execImageFormatTest (Context& context, ImageFormatPropertyCase testCase)
3605 {
3606         return testCase.testFunction(context, testCase.format, testCase.imageType, testCase.tiling);
3607 }
3608
3609 void createImageFormatTypeTilingTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
3610 {
3611         DE_ASSERT(params.format == VK_FORMAT_UNDEFINED);
3612
3613         static const struct
3614         {
3615                 VkFormat                                                                begin;
3616                 VkFormat                                                                end;
3617                 ImageFormatPropertyCase                                 params;
3618         } s_formatRanges[] =
3619         {
3620                 // core formats
3621                 { (VkFormat)(VK_FORMAT_UNDEFINED + 1),  VK_CORE_FORMAT_LAST,                                                                            params },
3622
3623                 // YCbCr formats
3624                 { VK_FORMAT_G8B8G8R8_422_UNORM_KHR,             (VkFormat)(VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM_KHR + 1),     params }
3625         };
3626
3627         for (int rangeNdx = 0; rangeNdx < DE_LENGTH_OF_ARRAY(s_formatRanges); ++rangeNdx)
3628         {
3629                 const VkFormat                                                          rangeBegin              = s_formatRanges[rangeNdx].begin;
3630                 const VkFormat                                                          rangeEnd                = s_formatRanges[rangeNdx].end;
3631
3632                 for (VkFormat format = rangeBegin; format != rangeEnd; format = (VkFormat)(format+1))
3633                 {
3634                         const bool                      isYCbCr         = isYCbCrFormat(format);
3635                         const bool                      isSparse        = (params.testFunction == sparseImageFormatProperties2);
3636
3637                         if (isYCbCr && isSparse)
3638                                 continue;
3639
3640                         if (isYCbCr && params.imageType != VK_IMAGE_TYPE_2D)
3641                                 continue;
3642
3643                         const char* const       enumName        = getFormatName(format);
3644                         const string            caseName        = de::toLower(string(enumName).substr(10));
3645
3646                         params.format = format;
3647
3648                         addFunctionCase(testGroup, caseName, enumName, execImageFormatTest, params);
3649                 }
3650         }
3651 }
3652
3653 void createImageFormatTypeTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
3654 {
3655         DE_ASSERT(params.tiling == VK_IMAGE_TILING_LAST);
3656
3657         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "optimal",     "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(params.testFunction, VK_FORMAT_UNDEFINED, params.imageType, VK_IMAGE_TILING_OPTIMAL)));
3658         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "linear",      "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(params.testFunction, VK_FORMAT_UNDEFINED, params.imageType, VK_IMAGE_TILING_LINEAR)));
3659 }
3660
3661 void createImageFormatTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase::Function testFunction)
3662 {
3663         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "1d", "", createImageFormatTypeTests, ImageFormatPropertyCase(testFunction, VK_FORMAT_UNDEFINED, VK_IMAGE_TYPE_1D, VK_IMAGE_TILING_LAST)));
3664         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "2d", "", createImageFormatTypeTests, ImageFormatPropertyCase(testFunction, VK_FORMAT_UNDEFINED, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_LAST)));
3665         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "3d", "", createImageFormatTypeTests, ImageFormatPropertyCase(testFunction, VK_FORMAT_UNDEFINED, VK_IMAGE_TYPE_3D, VK_IMAGE_TILING_LAST)));
3666 }
3667
3668
3669 // Android CTS -specific tests
3670
3671 namespace android
3672 {
3673
3674 void checkExtensions (tcu::ResultCollector& results, const set<string>& allowedExtensions, const vector<VkExtensionProperties>& reportedExtensions)
3675 {
3676         for (vector<VkExtensionProperties>::const_iterator extension = reportedExtensions.begin(); extension != reportedExtensions.end(); ++extension)
3677         {
3678                 const string    extensionName   (extension->extensionName);
3679                 const bool              mustBeKnown             = de::beginsWith(extensionName, "VK_GOOGLE_")   ||
3680                                                                                   de::beginsWith(extensionName, "VK_ANDROID_");
3681
3682                 if (mustBeKnown && !de::contains(allowedExtensions, extensionName))
3683                         results.fail("Unknown extension: " + extensionName);
3684         }
3685 }
3686
3687 tcu::TestStatus testNoUnknownExtensions (Context& context)
3688 {
3689         TestLog&                                log                                     = context.getTestContext().getLog();
3690         tcu::ResultCollector    results                         (log);
3691         set<string>                             allowedInstanceExtensions;
3692         set<string>                             allowedDeviceExtensions;
3693
3694         // All known extensions should be added to allowedExtensions:
3695         // allowedExtensions.insert("VK_GOOGLE_extension1");
3696         allowedDeviceExtensions.insert("VK_ANDROID_external_memory_android_hardware_buffer");
3697         allowedDeviceExtensions.insert("VK_GOOGLE_display_timing");
3698
3699         // Instance extensions
3700         checkExtensions(results,
3701                                         allowedInstanceExtensions,
3702                                         enumerateInstanceExtensionProperties(context.getPlatformInterface(), DE_NULL));
3703
3704         // Extensions exposed by instance layers
3705         {
3706                 const vector<VkLayerProperties> layers  = enumerateInstanceLayerProperties(context.getPlatformInterface());
3707
3708                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
3709                 {
3710                         checkExtensions(results,
3711                                                         allowedInstanceExtensions,
3712                                                         enumerateInstanceExtensionProperties(context.getPlatformInterface(), layer->layerName));
3713                 }
3714         }
3715
3716         // Device extensions
3717         checkExtensions(results,
3718                                         allowedDeviceExtensions,
3719                                         enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), DE_NULL));
3720
3721         // Extensions exposed by device layers
3722         {
3723                 const vector<VkLayerProperties> layers  = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
3724
3725                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
3726                 {
3727                         checkExtensions(results,
3728                                                         allowedDeviceExtensions,
3729                                                         enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), layer->layerName));
3730                 }
3731         }
3732
3733         return tcu::TestStatus(results.getResult(), results.getMessage());
3734 }
3735
3736 tcu::TestStatus testNoLayers (Context& context)
3737 {
3738         TestLog&                                log             = context.getTestContext().getLog();
3739         tcu::ResultCollector    results (log);
3740
3741         {
3742                 const vector<VkLayerProperties> layers  = enumerateInstanceLayerProperties(context.getPlatformInterface());
3743
3744                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
3745                         results.fail(string("Instance layer enumerated: ") + layer->layerName);
3746         }
3747
3748         {
3749                 const vector<VkLayerProperties> layers  = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
3750
3751                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
3752                         results.fail(string("Device layer enumerated: ") + layer->layerName);
3753         }
3754
3755         return tcu::TestStatus(results.getResult(), results.getMessage());
3756 }
3757
3758 tcu::TestStatus testMandatoryExtensions (Context& context)
3759 {
3760         TestLog&                                log             = context.getTestContext().getLog();
3761         tcu::ResultCollector    results (log);
3762
3763         // Instance extensions
3764         {
3765                 static const char*                                      mandatoryExtensions[]   =
3766                 {
3767                         "VK_KHR_get_physical_device_properties2",
3768                 };
3769                 const vector<VkExtensionProperties>     extensions                              = enumerateInstanceExtensionProperties(context.getPlatformInterface(), DE_NULL);
3770
3771                 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(mandatoryExtensions); ++ndx)
3772                 {
3773                         if (!isInstanceExtensionSupported(context.getUsedApiVersion(), extensions, RequiredExtension(mandatoryExtensions[ndx])))
3774                                 results.fail(string(mandatoryExtensions[ndx]) + " is not supported");
3775                 }
3776         }
3777
3778         // Device extensions
3779         {
3780                 static const char*                                      mandatoryExtensions[]   =
3781                 {
3782                         "VK_KHR_maintenance1",
3783                 };
3784                 const vector<VkExtensionProperties>     extensions                              = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), DE_NULL);
3785
3786                 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(mandatoryExtensions); ++ndx)
3787                 {
3788                         if (!isDeviceExtensionSupported(context.getUsedApiVersion(), extensions, RequiredExtension(mandatoryExtensions[ndx])))
3789                                 results.fail(string(mandatoryExtensions[ndx]) + " is not supported");
3790                 }
3791         }
3792
3793         return tcu::TestStatus(results.getResult(), results.getMessage());
3794 }
3795
3796 } // android
3797
3798 } // anonymous
3799
3800 tcu::TestCaseGroup* createFeatureInfoTests (tcu::TestContext& testCtx)
3801 {
3802         de::MovePtr<tcu::TestCaseGroup> infoTests       (new tcu::TestCaseGroup(testCtx, "info", "Platform Information Tests"));
3803
3804         {
3805                 de::MovePtr<tcu::TestCaseGroup> instanceInfoTests       (new tcu::TestCaseGroup(testCtx, "instance", "Instance Information Tests"));
3806
3807                 addFunctionCase(instanceInfoTests.get(), "physical_devices",            "Physical devices",                     enumeratePhysicalDevices);
3808                 addFunctionCase(instanceInfoTests.get(), "physical_device_groups",      "Physical devices Groups",      enumeratePhysicalDeviceGroups);
3809                 addFunctionCase(instanceInfoTests.get(), "layers",                                      "Layers",                                       enumerateInstanceLayers);
3810                 addFunctionCase(instanceInfoTests.get(), "extensions",                          "Extensions",                           enumerateInstanceExtensions);
3811
3812                 infoTests->addChild(instanceInfoTests.release());
3813         }
3814
3815         {
3816                 de::MovePtr<tcu::TestCaseGroup> deviceInfoTests (new tcu::TestCaseGroup(testCtx, "device", "Device Information Tests"));
3817
3818                 addFunctionCase(deviceInfoTests.get(), "features",                                      "Device Features",                      deviceFeatures);
3819                 addFunctionCase(deviceInfoTests.get(), "properties",                            "Device Properties",            deviceProperties);
3820                 addFunctionCase(deviceInfoTests.get(), "queue_family_properties",       "Queue family properties",      deviceQueueFamilyProperties);
3821                 addFunctionCase(deviceInfoTests.get(), "memory_properties",                     "Memory properties",            deviceMemoryProperties);
3822                 addFunctionCase(deviceInfoTests.get(), "layers",                                        "Layers",                                       enumerateDeviceLayers);
3823                 addFunctionCase(deviceInfoTests.get(), "extensions",                            "Extensions",                           enumerateDeviceExtensions);
3824                 addFunctionCase(deviceInfoTests.get(), "no_khx_extensions",                     "KHX extensions",                       testNoKhxExtensions);
3825
3826                 infoTests->addChild(deviceInfoTests.release());
3827         }
3828
3829         {
3830                 de::MovePtr<tcu::TestCaseGroup> deviceGroupInfoTests(new tcu::TestCaseGroup(testCtx, "device_group", "Device Group Information Tests"));
3831
3832                 addFunctionCase(deviceGroupInfoTests.get(), "peer_memory_features",     "Device Group peer memory features",                            deviceGroupPeerMemoryFeatures);
3833
3834                 infoTests->addChild(deviceGroupInfoTests.release());
3835         }
3836
3837         infoTests->addChild(createTestGroup(testCtx, "format_properties",               "VkGetPhysicalDeviceFormatProperties() Tests",          createFormatTests));
3838         infoTests->addChild(createTestGroup(testCtx, "image_format_properties", "VkGetPhysicalDeviceImageFormatProperties() Tests",     createImageFormatTests, imageFormatProperties));
3839
3840         {
3841                 de::MovePtr<tcu::TestCaseGroup> extendedPropertiesTests (new tcu::TestCaseGroup(testCtx, "get_physical_device_properties2", "VK_KHR_get_physical_device_properties2"));
3842
3843                 addFunctionCase(extendedPropertiesTests.get(), "features",                                      "Extended Device Features",                                     deviceFeatures2);
3844                 addFunctionCase(extendedPropertiesTests.get(), "properties",                            "Extended Device Properties",                           deviceProperties2);
3845                 addFunctionCase(extendedPropertiesTests.get(), "format_properties",                     "Extended Device Format Properties",            deviceFormatProperties2);
3846                 addFunctionCase(extendedPropertiesTests.get(), "queue_family_properties",       "Extended Device Queue Family Properties",      deviceQueueFamilyProperties2);
3847                 addFunctionCase(extendedPropertiesTests.get(), "memory_properties",                     "Extended Device Memory Properties",            deviceMemoryProperties2);
3848
3849                 infoTests->addChild(extendedPropertiesTests.release());
3850         }
3851
3852         infoTests->addChild(createTestGroup(testCtx, "image_format_properties2",                "VkGetPhysicalDeviceImageFormatProperties2() Tests",            createImageFormatTests, imageFormatProperties2));
3853         infoTests->addChild(createTestGroup(testCtx, "sparse_image_format_properties2", "VkGetPhysicalDeviceSparseImageFormatProperties2() Tests",      createImageFormatTests, sparseImageFormatProperties2));
3854
3855         {
3856                 de::MovePtr<tcu::TestCaseGroup> androidTests    (new tcu::TestCaseGroup(testCtx, "android", "Android CTS Tests"));
3857
3858                 addFunctionCase(androidTests.get(),     "mandatory_extensions",         "Test that all mandatory extensions are supported",     android::testMandatoryExtensions);
3859                 addFunctionCase(androidTests.get(), "no_unknown_extensions",    "Test for unknown device or instance extensions",       android::testNoUnknownExtensions);
3860                 addFunctionCase(androidTests.get(), "no_layers",                                "Test that no layers are enumerated",                           android::testNoLayers);
3861
3862                 infoTests->addChild(androidTests.release());
3863         }
3864
3865         return infoTests.release();
3866 }
3867
3868 } // api
3869 } // vkt