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