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