Merge branch '289-renderpass-formats' into 'vulkan-cts-1.0'
[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  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and/or associated documentation files (the
9  * "Materials"), to deal in the Materials without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sublicense, and/or sell copies of the Materials, and to
12  * permit persons to whom the Materials are furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice(s) and this permission notice shall be
16  * included in all copies or substantial portions of the Materials.
17  *
18  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
22  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
25  *
26  *//*!
27  * \file
28  * \brief Api Feature Query tests
29  *//*--------------------------------------------------------------------*/
30
31 #include "vktApiFeatureInfo.hpp"
32
33 #include "vktTestCaseUtil.hpp"
34 #include "vktTestGroupUtil.hpp"
35
36 #include "vkPlatform.hpp"
37 #include "vkStrUtil.hpp"
38 #include "vkRef.hpp"
39 #include "vkDeviceUtil.hpp"
40 #include "vkQueryUtil.hpp"
41
42 #include "tcuTestLog.hpp"
43 #include "tcuFormatUtil.hpp"
44
45 #include "deUniquePtr.hpp"
46 #include "deStringUtil.hpp"
47 #include "deSTLUtil.hpp"
48 #include "deMemory.h"
49 #include "deMath.h"
50
51 namespace vkt
52 {
53 namespace api
54 {
55 namespace
56 {
57
58 using namespace vk;
59 using std::vector;
60 using std::string;
61 using tcu::TestLog;
62 using tcu::ScopedLogSection;
63
64 enum
65 {
66         GUARD_SIZE      = 0x20,                 //!< Number of bytes to check
67         GUARD_VALUE     = 0xcd,                 //!< Data pattern
68 };
69
70 enum LimitFormat
71 {
72         LIMIT_FORMAT_SIGNED_INT,
73         LIMIT_FORMAT_UNSIGNED_INT,
74         LIMIT_FORMAT_FLOAT,
75         LIMIT_FORMAT_DEVICE_SIZE,
76
77         LIMIT_FORMAT_LAST
78 };
79
80 enum LimitType
81 {
82         LIMIT_TYPE_MIN,
83         LIMIT_TYPE_MAX,
84
85         LIMIT_TYPE_LAST
86 };
87
88 #define LIMIT(_X_)              DE_OFFSET_OF(VkPhysicalDeviceLimits, _X_),(char*)(#_X_)
89 #define FEATURE(_X_)    DE_OFFSET_OF(VkPhysicalDeviceFeatures, _X_)
90
91 bool validateFeatureLimits(VkPhysicalDeviceProperties* properties, VkPhysicalDeviceFeatures* features, TestLog& log)
92 {
93         bool                                    limitsOk        = true;
94         VkPhysicalDeviceLimits* limits          = &properties->limits;
95         struct FeatureLimitTable
96         {
97                 deUint32                offset;
98                 char*                   name;
99                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
100                 deInt32                 intVal;                         //!< Format is SIGNED_INT
101                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
102                 float                   floatVal;                       //!< Format is FLOAT
103                 LimitFormat             format;
104                 LimitType               type;
105                 deInt32                 unsuppTableNdx;
106         } featureLimitTable[] =   //!< From gitlab.khronos.org/vulkan/vulkan.git:doc/specs/vulkan/chapters/features.txt@63b23f3bb3ecd211cd6e448e2001ce1088dacd35
107         {
108                 { LIMIT(maxImageDimension1D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
109                 { LIMIT(maxImageDimension2D),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
110                 { LIMIT(maxImageDimension3D),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
111                 { LIMIT(maxImageDimensionCube),                                                         4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
112                 { LIMIT(maxImageArrayLayers),                                                           256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
113                 { LIMIT(maxTexelBufferElements),                                                        65536, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
114                 { LIMIT(maxUniformBufferRange),                                                         16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
115                 { LIMIT(maxPushConstantsSize),                                                          128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
116                 { LIMIT(maxMemoryAllocationCount),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
117                 { LIMIT(bufferImageGranularity),                                                        0, 0, 131072, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
118                 { LIMIT(sparseAddressSpaceSize),                                                        0, 0, 2UL*1024*1024*1024, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MIN, -1 },
119                 { LIMIT(maxBoundDescriptorSets),                                                        4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
120                 { LIMIT(maxPerStageDescriptorSamplers),                                         16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
121                 { LIMIT(maxPerStageDescriptorUniformBuffers),                           12, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
122                 { LIMIT(maxPerStageDescriptorStorageBuffers),                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
123                 { LIMIT(maxPerStageDescriptorSampledImages),                            16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
124                 { LIMIT(maxPerStageDescriptorStorageImages),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
125                 { LIMIT(maxPerStageDescriptorInputAttachments),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
126                 { LIMIT(maxDescriptorSetSamplers),                                                      96, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
127                 { LIMIT(maxDescriptorSetUniformBuffers),                                        72, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
128                 { LIMIT(maxDescriptorSetUniformBuffersDynamic),                         8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
129                 { LIMIT(maxDescriptorSetStorageBuffers),                                        24, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
130                 { LIMIT(maxDescriptorSetStorageBuffersDynamic),                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
131                 { LIMIT(maxDescriptorSetSampledImages),                                         96, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
132                 { LIMIT(maxDescriptorSetStorageImages),                                         24, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
133                 { LIMIT(maxVertexInputAttributes),                                                      16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
134                 { LIMIT(maxVertexInputBindings),                                                        16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
135                 { LIMIT(maxVertexInputAttributeOffset),                                         2047, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
136                 { LIMIT(maxVertexInputBindingStride),                                           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
137                 { LIMIT(maxVertexOutputComponents),                                                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
138                 { LIMIT(maxTessellationGenerationLevel),                                        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
139                 { LIMIT(maxTessellationPatchSize),                                                      32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
140                 { LIMIT(maxTessellationControlPerVertexInputComponents),        64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
141                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
142                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        120, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
143                 { LIMIT(maxTessellationControlTotalOutputComponents),           2048, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
144                 { LIMIT(maxTessellationEvaluationInputComponents),                      64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
145                 { LIMIT(maxTessellationEvaluationOutputComponents),                     64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
146                 { LIMIT(maxGeometryShaderInvocations),                                          32, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
147                 { LIMIT(maxGeometryInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
148                 { LIMIT(maxGeometryOutputComponents),                                           64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
149                 { LIMIT(maxGeometryOutputVertices),                                                     256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
150                 { LIMIT(maxGeometryTotalOutputComponents),                                      1024, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
151                 { LIMIT(maxFragmentInputComponents),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
152                 { LIMIT(maxFragmentOutputAttachments),                                          4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
153                 { LIMIT(maxFragmentDualSrcAttachments),                                         1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
154                 { LIMIT(maxFragmentCombinedOutputResources),                            4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN  , -1 },
155                 { LIMIT(maxComputeSharedMemorySize),                                            16384, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
156                 { LIMIT(maxComputeWorkGroupCount[0]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
157                 { LIMIT(maxComputeWorkGroupCount[1]),                                           65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
158                 { LIMIT(maxComputeWorkGroupCount[2]),                                           65535,  0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN   , -1 },
159                 { LIMIT(maxComputeWorkGroupInvocations),                                        128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
160                 { LIMIT(maxComputeWorkGroupSize[0]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
161                 { LIMIT(maxComputeWorkGroupSize[1]),                                            128, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
162                 { LIMIT(maxComputeWorkGroupSize[2]),                                            64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
163                 { LIMIT(subPixelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
164                 { LIMIT(subTexelPrecisionBits),                                                         4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
165                 { LIMIT(mipmapPrecisionBits),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
166                 { LIMIT(maxDrawIndexedIndexValue),                                                      (deUint32)~0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
167                 { LIMIT(maxDrawIndirectCount),                                                          65535, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN    , -1 },
168                 { LIMIT(maxSamplerLodBias),                                                                     0, 0, 0, 2.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
169                 { LIMIT(maxSamplerAnisotropy),                                                          0, 0, 0, 16.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
170                 { LIMIT(maxViewports),                                                                          16, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
171                 { LIMIT(maxViewportDimensions[0]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
172                 { LIMIT(maxViewportDimensions[1]),                                                      4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN , -1 },
173                 { LIMIT(viewportBoundsRange[0]),                                                        0, 0, 0, -8192.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
174                 { LIMIT(viewportBoundsRange[1]),                                                        0, 0, 0, 8191.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
175                 { LIMIT(viewportSubPixelBits),                                                          0, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
176                 { LIMIT(minMemoryMapAlignment),                                                         64, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
177                 { LIMIT(minTexelBufferOffsetAlignment),                                         256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MAX, -1 },
178                 { LIMIT(minUniformBufferOffsetAlignment),                                       256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MAX, -1 },
179                 { LIMIT(minStorageBufferOffsetAlignment),                                       256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MAX, -1 },
180                 { LIMIT(minTexelOffset),                                                                        0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
181                 { LIMIT(maxTexelOffset),                                                                        7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
182                 { LIMIT(minTexelGatherOffset),                                                          0, -8, 0, 0.0f, LIMIT_FORMAT_SIGNED_INT, LIMIT_TYPE_MAX, -1 },
183                 { LIMIT(maxTexelGatherOffset),                                                          7, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
184                 { LIMIT(minInterpolationOffset),                                                        0, 0, 0, -0.5f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
185                 { LIMIT(maxInterpolationOffset),                                                        0, 0, 0, 0.5f - (1.0f/deFloatPow(2.0f, (float)limits->subPixelInterpolationOffsetBits)), LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
186                 { LIMIT(subPixelInterpolationOffsetBits),                                       4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
187                 { LIMIT(maxFramebufferWidth),                                                           4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
188                 { LIMIT(maxFramebufferHeight),                                                          4096, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
189                 { LIMIT(maxFramebufferLayers),                                                          256, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
190                 { LIMIT(maxColorAttachments),                                                           4, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
191                 { LIMIT(maxSampleMaskWords),                                                            1, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
192                 { LIMIT(maxClipDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
193                 { LIMIT(maxCullDistances),                                                                      8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
194                 { LIMIT(maxCombinedClipAndCullDistances),                                       8, 0, 0, 0.0f, LIMIT_FORMAT_UNSIGNED_INT, LIMIT_TYPE_MIN, -1 },
195                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
196                 { LIMIT(pointSizeRange[1]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
197                 { LIMIT(pointSizeRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
198                 { LIMIT(pointSizeRange[1]),                                                                     0, 0, 0, 64.0f - limits->pointSizeGranularity , LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
199                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
200                 { LIMIT(lineWidthRange[1]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
201                 { LIMIT(lineWidthRange[0]),                                                                     0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
202                 { LIMIT(lineWidthRange[1]),                                                                     0, 0, 0, 8.0f - limits->lineWidthGranularity, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MIN, -1 },
203                 { LIMIT(pointSizeGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
204                 { LIMIT(lineWidthGranularity),                                                          0, 0, 0, 1.0f, LIMIT_FORMAT_FLOAT, LIMIT_TYPE_MAX, -1 },
205                 { LIMIT(nonCoherentAtomSize),                                                           0, 0, 128, 0.0f, LIMIT_FORMAT_DEVICE_SIZE, LIMIT_TYPE_MAX, -1 },
206         };
207
208         struct UnsupportedFeatureLimitTable
209         {
210                 deUint32                limitOffset;
211                 char*                   name;
212                 deUint32                featureOffset;
213                 deUint32                uintVal;                        //!< Format is UNSIGNED_INT
214                 deInt32                 intVal;                         //!< Format is SIGNED_INT
215                 deUint64                deviceSizeVal;          //!< Format is DEVICE_SIZE
216                 float                   floatVal;                       //!< Format is FLOAT
217         } unsupportedFeatureTable[] =
218         {
219                 { LIMIT(sparseAddressSpaceSize),                                                        FEATURE(sparseBinding),                                 0, 0, 0, 0.0f },
220                 { LIMIT(maxTessellationGenerationLevel),                                        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
221                 { LIMIT(maxTessellationPatchSize),                                                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
222                 { LIMIT(maxTessellationControlPerVertexInputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
223                 { LIMIT(maxTessellationControlPerVertexOutputComponents),       FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
224                 { LIMIT(maxTessellationControlPerPatchOutputComponents),        FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
225                 { LIMIT(maxTessellationControlTotalOutputComponents),           FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
226                 { LIMIT(maxTessellationEvaluationInputComponents),                      FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
227                 { LIMIT(maxTessellationEvaluationOutputComponents),                     FEATURE(tessellationShader),                    0, 0, 0, 0.0f },
228                 { LIMIT(maxGeometryShaderInvocations),                                          FEATURE(geometryShader),                                0, 0, 0, 0.0f },
229                 { LIMIT(maxGeometryInputComponents),                                            FEATURE(geometryShader),                                0, 0, 0, 0.0f },
230                 { LIMIT(maxGeometryOutputComponents),                                           FEATURE(geometryShader),                                0, 0, 0, 0.0f },
231                 { LIMIT(maxGeometryOutputVertices),                                                     FEATURE(geometryShader),                                0, 0, 0, 0.0f },
232                 { LIMIT(maxGeometryTotalOutputComponents),                                      FEATURE(geometryShader),                                0, 0, 0, 0.0f },
233                 { LIMIT(maxFragmentDualSrcAttachments),                                         FEATURE(dualSrcBlend),                                  0, 0, 0, 0.0f },
234                 { LIMIT(maxDrawIndexedIndexValue),                                                      FEATURE(fullDrawIndexUint32),                   (1<<24)-1, 0, 0, 0.0f },
235                 { LIMIT(maxDrawIndirectCount),                                                          FEATURE(multiDrawIndirect),                             1, 0, 0, 0.0f },
236                 { LIMIT(maxSamplerAnisotropy),                                                          FEATURE(samplerAnisotropy),                             1, 0, 0, 0.0f },
237                 { LIMIT(maxViewports),                                                                          FEATURE(multiViewport),                                 1, 0, 0, 0.0f },
238                 { LIMIT(minTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
239                 { LIMIT(maxTexelGatherOffset),                                                          FEATURE(shaderImageGatherExtended),             0, 0, 0, 0.0f },
240                 { LIMIT(minInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
241                 { LIMIT(maxInterpolationOffset),                                                        FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
242                 { LIMIT(subPixelInterpolationOffsetBits),                                       FEATURE(sampleRateShading),                             0, 0, 0, 0.0f },
243                 { LIMIT(storageImageSampleCounts),                                                      FEATURE(shaderStorageImageMultisample), 0, 0, 0, 0.0f },
244                 { LIMIT(maxClipDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
245                 { LIMIT(maxCullDistances),                                                                      FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
246                 { LIMIT(maxCombinedClipAndCullDistances),                                       FEATURE(shaderClipDistance),                    0, 0, 0, 0.0f },
247                 { LIMIT(pointSizeRange[0]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
248                 { LIMIT(pointSizeRange[1]),                                                                     FEATURE(largePoints),                                   0, 0, 0, 1.0f },
249                 { LIMIT(lineWidthRange[0]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
250                 { LIMIT(lineWidthRange[1]),                                                                     FEATURE(wideLines),                                             0, 0, 0, 1.0f },
251                 { LIMIT(pointSizeGranularity),                                                          FEATURE(largePoints),                                   0, 0, 0, 0.0f },
252                 { LIMIT(lineWidthGranularity),                                                          FEATURE(wideLines),                                             0, 0, 0, 0.0f }
253         };
254
255         log << TestLog::Message << *limits << TestLog::EndMessage;
256
257         //!< First build a map from limit to unsupported table index
258         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
259         {
260                 for (deUint32 unsuppNdx = 0; unsuppNdx < DE_LENGTH_OF_ARRAY(unsupportedFeatureTable); unsuppNdx++)
261                 {
262                         if (unsupportedFeatureTable[unsuppNdx].limitOffset == featureLimitTable[ndx].offset)
263                         {
264                                 featureLimitTable[ndx].unsuppTableNdx = unsuppNdx;
265                                 break;
266                         }
267                 }
268         }
269
270         for (deUint32 ndx = 0; ndx < DE_LENGTH_OF_ARRAY(featureLimitTable); ndx++)
271         {
272                 switch (featureLimitTable[ndx].format)
273                 {
274                         case LIMIT_FORMAT_UNSIGNED_INT:
275                         {
276                                 deUint32 limitToCheck = featureLimitTable[ndx].uintVal;
277                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
278                                 {
279                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
280                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].uintVal;
281                                 }
282
283                                 if ( featureLimitTable[ndx].type == LIMIT_TYPE_MIN )
284                                 {
285
286                                         if (*((deUint32*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
287                                         {
288                                                 log << TestLog::Message << "limit Validation failed " << featureLimitTable[ndx].name
289                                                         << " not valid-limit type MIN - actual is "
290                                                         << *((deUint32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
291                                                 limitsOk = false;
292                                         }
293                                 }
294                                 else
295                                 {
296                                         if (*((deUint32*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
297                                         {
298                                                 log << TestLog::Message << "limit validation failed,  " << featureLimitTable[ndx].name
299                                                         << " not valid-limit type MAX - actual is "
300                                                         << *((deUint32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
301                                                 limitsOk = false;
302                                         }
303                                 }
304                                 break;
305                         }
306
307                         case LIMIT_FORMAT_FLOAT:
308                         {
309                                 float limitToCheck = featureLimitTable[ndx].floatVal;
310                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
311                                 {
312                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
313                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].floatVal;
314                                 }
315
316                                 if ( featureLimitTable[ndx].type == LIMIT_TYPE_MIN )
317                                 {
318                                         if (*((float*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
319                                         {
320                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
321                                                         << " not valid-limit type MIN - actual is "
322                                                         << *((float*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
323                                                 limitsOk = false;
324                                         }
325                                 }
326                                 else
327                                 {
328                                         if (*((float*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
329                                         {
330                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
331                                                         << " not valid-limit type MAX actual is "
332                                                         << *((float*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
333                                                 limitsOk = false;
334                                         }
335                                 }
336                                 break;
337                         }
338
339                         case LIMIT_FORMAT_SIGNED_INT:
340                         {
341                                 deInt32 limitToCheck = featureLimitTable[ndx].intVal;
342                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
343                                 {
344                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
345                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].intVal;
346                                 }
347                                 if (featureLimitTable[ndx].type == LIMIT_TYPE_MIN)
348                                 {
349                                         if (*((deInt32*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
350                                         {
351                                                 log << TestLog::Message <<  "limit validation failed, " << featureLimitTable[ndx].name
352                                                         << " not valid-limit type MIN actual is "
353                                                         << *((deInt32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
354                                                 limitsOk = false;
355                                         }
356                                 }
357                                 else
358                                 {
359                                         if (*((deInt32*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
360                                         {
361                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
362                                                         << " not valid-limit type MAX actual is "
363                                                         << *((deInt32*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
364                                                 limitsOk = false;
365                                         }
366                                 }
367                                 break;
368                         }
369
370                         case LIMIT_FORMAT_DEVICE_SIZE:
371                         {
372                                 deUint64 limitToCheck = featureLimitTable[ndx].deviceSizeVal;
373                                 if (featureLimitTable[ndx].unsuppTableNdx != -1)
374                                 {
375                                         if (*((VkBool32*)((char*)features+unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].featureOffset)) == VK_FALSE)
376                                                 limitToCheck = unsupportedFeatureTable[featureLimitTable[ndx].unsuppTableNdx].deviceSizeVal;
377                                 }
378
379                                 if ( featureLimitTable[ndx].type == LIMIT_TYPE_MIN )
380                                 {
381                                         if (*((deUint64*)((char*)limits+featureLimitTable[ndx].offset)) < limitToCheck)
382                                         {
383                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
384                                                         << " not valid-limit type MIN actual is "
385                                                         << *((deUint64*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
386                                                 limitsOk = false;
387                                         }
388                                 }
389                                 else
390                                 {
391                                         if (*((deUint64*)((char*)limits+featureLimitTable[ndx].offset)) > limitToCheck)
392                                         {
393                                                 log << TestLog::Message << "limit validation failed, " << featureLimitTable[ndx].name
394                                                         << " not valid-limit type MAX actual is "
395                                                         << *((deUint64*)((char*)limits + featureLimitTable[ndx].offset)) << TestLog::EndMessage;
396                                                 limitsOk = false;
397                                         }
398                                 }
399                                 break;
400                         }
401
402                         default:
403                                 DE_ASSERT(0);
404                                 limitsOk = false;
405                 }
406         }
407
408         return limitsOk;
409 }
410
411 tcu::TestStatus enumeratePhysicalDevices (Context& context)
412 {
413         TestLog&                                                log             = context.getTestContext().getLog();
414         const vector<VkPhysicalDevice>  devices = enumeratePhysicalDevices(context.getInstanceInterface(), context.getInstance());
415
416         log << TestLog::Integer("NumDevices", "Number of devices", "", QP_KEY_TAG_NONE, deInt64(devices.size()));
417
418         for (size_t ndx = 0; ndx < devices.size(); ndx++)
419                 log << TestLog::Message << ndx << ": " << devices[ndx] << TestLog::EndMessage;
420
421         return tcu::TestStatus::pass("Enumerating devices succeeded");
422 }
423
424 tcu::TestStatus enumerateInstanceLayers (Context& context)
425 {
426         TestLog&                                                log                     = context.getTestContext().getLog();
427         const vector<VkLayerProperties> properties      = enumerateInstanceLayerProperties(context.getPlatformInterface());
428
429         for (size_t ndx = 0; ndx < properties.size(); ndx++)
430                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
431
432         return tcu::TestStatus::pass("Enumerating layers succeeded");
433 }
434
435 tcu::TestStatus enumerateInstanceExtensions (Context& context)
436 {
437         TestLog&        log             = context.getTestContext().getLog();
438
439         {
440                 const ScopedLogSection                          section         (log, "Global", "Global Extensions");
441                 const vector<VkExtensionProperties>     properties      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), DE_NULL);
442
443                 for (size_t ndx = 0; ndx < properties.size(); ndx++)
444                         log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
445         }
446
447         {
448                 const vector<VkLayerProperties> layers  = enumerateInstanceLayerProperties(context.getPlatformInterface());
449
450                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
451                 {
452                         const ScopedLogSection                          section         (log, layer->layerName, string("Layer: ") + layer->layerName);
453                         const vector<VkExtensionProperties>     properties      = enumerateInstanceExtensionProperties(context.getPlatformInterface(), layer->layerName);
454
455                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
456                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
457                 }
458         }
459
460         return tcu::TestStatus::pass("Enumerating extensions succeeded");
461 }
462
463 tcu::TestStatus enumerateDeviceLayers (Context& context)
464 {
465         TestLog&                                                log                     = context.getTestContext().getLog();
466         const vector<VkLayerProperties> properties      = vk::enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
467
468         for (size_t ndx = 0; ndx < properties.size(); ndx++)
469                 log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
470
471         return tcu::TestStatus::pass("Enumerating layers succeeded");
472 }
473
474 tcu::TestStatus enumerateDeviceExtensions (Context& context)
475 {
476         TestLog&        log             = context.getTestContext().getLog();
477
478         {
479                 const ScopedLogSection                          section         (log, "Global", "Global Extensions");
480                 const vector<VkExtensionProperties>     properties      = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), DE_NULL);
481
482                 for (size_t ndx = 0; ndx < properties.size(); ndx++)
483                         log << TestLog::Message << ndx << ": " << properties[ndx] << TestLog::EndMessage;
484         }
485
486         {
487                 const vector<VkLayerProperties> layers  = enumerateDeviceLayerProperties(context.getInstanceInterface(), context.getPhysicalDevice());
488
489                 for (vector<VkLayerProperties>::const_iterator layer = layers.begin(); layer != layers.end(); ++layer)
490                 {
491                         const ScopedLogSection                          section         (log, layer->layerName, string("Layer: ") + layer->layerName);
492                         const vector<VkExtensionProperties>     properties      = enumerateDeviceExtensionProperties(context.getInstanceInterface(), context.getPhysicalDevice(), layer->layerName);
493
494                         for (size_t extNdx = 0; extNdx < properties.size(); extNdx++)
495                                 log << TestLog::Message << extNdx << ": " << properties[extNdx] << TestLog::EndMessage;
496                 }
497         }
498
499         return tcu::TestStatus::pass("Enumerating extensions succeeded");
500 }
501
502 tcu::TestStatus deviceFeatures (Context& context)
503 {
504         TestLog&                                                log                     = context.getTestContext().getLog();
505         VkPhysicalDeviceFeatures*               features;
506         deUint8                                                 buffer[sizeof(VkPhysicalDeviceFeatures) + GUARD_SIZE];
507
508         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
509         features = reinterpret_cast<VkPhysicalDeviceFeatures*>(buffer);
510
511         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), features);
512
513         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
514                 << TestLog::Message << *features << TestLog::EndMessage;
515
516         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
517         {
518                 if (buffer[ndx + sizeof(VkPhysicalDeviceFeatures)] != GUARD_VALUE)
519                 {
520                         log << TestLog::Message << "deviceFeatures - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
521                         return tcu::TestStatus::fail("deviceFeatures buffer overflow");
522                 }
523         }
524
525         return tcu::TestStatus::pass("Query succeeded");
526 }
527
528 tcu::TestStatus deviceProperties (Context& context)
529 {
530         TestLog&                                                log                     = context.getTestContext().getLog();
531         VkPhysicalDeviceProperties*             props;
532         VkPhysicalDeviceFeatures                features;
533         deUint8                                                 buffer[sizeof(VkPhysicalDeviceProperties) + GUARD_SIZE];
534
535         props = reinterpret_cast<VkPhysicalDeviceProperties*>(buffer);
536         deMemset(props, GUARD_VALUE, sizeof(buffer));
537
538         context.getInstanceInterface().getPhysicalDeviceProperties(context.getPhysicalDevice(), props);
539         context.getInstanceInterface().getPhysicalDeviceFeatures(context.getPhysicalDevice(), &features);
540
541         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
542                 << TestLog::Message << *props << TestLog::EndMessage;
543
544         if (!validateFeatureLimits(props, &features, log))
545                 return tcu::TestStatus::fail("deviceProperties - feature limits failed");
546
547         for (int ndx = 0; ndx < GUARD_SIZE; ndx++)
548         {
549                 if (buffer[ndx + sizeof(VkPhysicalDeviceProperties)] != GUARD_VALUE)
550                 {
551                         log << TestLog::Message << "deviceProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
552                         return tcu::TestStatus::fail("deviceProperties buffer overflow");
553                 }
554         }
555
556         return tcu::TestStatus::pass("DeviceProperites query succeeded");
557 }
558
559 tcu::TestStatus deviceQueueFamilyProperties (Context& context)
560 {
561         TestLog&                                                                log                                     = context.getTestContext().getLog();
562         const vector<VkQueueFamilyProperties>   queueProperties         = getPhysicalDeviceQueueFamilyProperties(context.getInstanceInterface(), context.getPhysicalDevice());
563
564         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage;
565
566         for (size_t queueNdx = 0; queueNdx < queueProperties.size(); queueNdx++)
567                 log << TestLog::Message << queueNdx << ": " << queueProperties[queueNdx] << TestLog::EndMessage;
568
569         return tcu::TestStatus::pass("Querying queue properties succeeded");
570 }
571
572 tcu::TestStatus deviceMemoryProperties (Context& context)
573 {
574         TestLog&                                                        log                     = context.getTestContext().getLog();
575         VkPhysicalDeviceMemoryProperties*       memProps;
576         deUint8                                                         buffer[sizeof(VkPhysicalDeviceMemoryProperties) + GUARD_SIZE];
577
578         memProps = reinterpret_cast<VkPhysicalDeviceMemoryProperties*>(buffer);
579         deMemset(buffer, GUARD_VALUE, sizeof(buffer));
580
581         context.getInstanceInterface().getPhysicalDeviceMemoryProperties(context.getPhysicalDevice(), memProps);
582
583         log << TestLog::Message << "device = " << context.getPhysicalDevice() << TestLog::EndMessage
584                 << TestLog::Message << *memProps << TestLog::EndMessage;
585
586         for (deInt32 ndx = 0; ndx < GUARD_SIZE; ndx++)
587         {
588                 if (buffer[ndx + sizeof(VkPhysicalDeviceMemoryProperties)] != GUARD_VALUE)
589                 {
590                         log << TestLog::Message << "deviceMemoryProperties - Guard offset " << ndx << " not valid" << TestLog::EndMessage;
591                         return tcu::TestStatus::fail("deviceMemoryProperties buffer overflow");
592                 }
593         }
594
595         return tcu::TestStatus::pass("Querying memory properties succeeded");
596 }
597
598 // \todo [2016-01-22 pyry] Optimize by doing format -> flags mapping instead
599
600 VkFormatFeatureFlags getRequiredOptimalTilingFeatures (VkFormat format)
601 {
602         static const VkFormat s_requiredSampledImageBlitSrcFormats[] =
603         {
604                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
605                 VK_FORMAT_R5G6B5_UNORM_PACK16,
606                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
607                 VK_FORMAT_R8_UNORM,
608                 VK_FORMAT_R8_SNORM,
609                 VK_FORMAT_R8_UINT,
610                 VK_FORMAT_R8_SINT,
611                 VK_FORMAT_R8G8_UNORM,
612                 VK_FORMAT_R8G8_SNORM,
613                 VK_FORMAT_R8G8_UINT,
614                 VK_FORMAT_R8G8_SINT,
615                 VK_FORMAT_R8G8B8A8_UNORM,
616                 VK_FORMAT_R8G8B8A8_SNORM,
617                 VK_FORMAT_R8G8B8A8_UINT,
618                 VK_FORMAT_R8G8B8A8_SINT,
619                 VK_FORMAT_R8G8B8A8_SRGB,
620                 VK_FORMAT_B8G8R8A8_UNORM,
621                 VK_FORMAT_B8G8R8A8_SRGB,
622                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
623                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
624                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
625                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
626                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
627                 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
628                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
629                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
630                 VK_FORMAT_R16_UNORM,
631                 VK_FORMAT_R16_SNORM,
632                 VK_FORMAT_R16_UINT,
633                 VK_FORMAT_R16_SINT,
634                 VK_FORMAT_R16_SFLOAT,
635                 VK_FORMAT_R16G16_UNORM,
636                 VK_FORMAT_R16G16_SNORM,
637                 VK_FORMAT_R16G16_UINT,
638                 VK_FORMAT_R16G16_SINT,
639                 VK_FORMAT_R16G16_SFLOAT,
640                 VK_FORMAT_R16G16B16A16_UNORM,
641                 VK_FORMAT_R16G16B16A16_SNORM,
642                 VK_FORMAT_R16G16B16A16_UINT,
643                 VK_FORMAT_R16G16B16A16_SINT,
644                 VK_FORMAT_R16G16B16A16_SFLOAT,
645                 VK_FORMAT_R32_UINT,
646                 VK_FORMAT_R32_SINT,
647                 VK_FORMAT_R32_SFLOAT,
648                 VK_FORMAT_R32G32_UINT,
649                 VK_FORMAT_R32G32_SINT,
650                 VK_FORMAT_R32G32_SFLOAT,
651                 VK_FORMAT_R32G32B32A32_UINT,
652                 VK_FORMAT_R32G32B32A32_SINT,
653                 VK_FORMAT_R32G32B32A32_SFLOAT,
654                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
655                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
656                 VK_FORMAT_D16_UNORM,
657                 VK_FORMAT_D32_SFLOAT
658         };
659         static const VkFormat s_requiredStorageImageFormats[] =
660         {
661                 VK_FORMAT_R8G8B8A8_UNORM,
662                 VK_FORMAT_R8G8B8A8_SNORM,
663                 VK_FORMAT_R8G8B8A8_UINT,
664                 VK_FORMAT_R8G8B8A8_SINT,
665                 VK_FORMAT_R16G16B16A16_UINT,
666                 VK_FORMAT_R16G16B16A16_SINT,
667                 VK_FORMAT_R16G16B16A16_SFLOAT,
668                 VK_FORMAT_R32_UINT,
669                 VK_FORMAT_R32_SINT,
670                 VK_FORMAT_R32_SFLOAT,
671                 VK_FORMAT_R32G32_UINT,
672                 VK_FORMAT_R32G32_SINT,
673                 VK_FORMAT_R32G32_SFLOAT,
674                 VK_FORMAT_R32G32B32A32_UINT,
675                 VK_FORMAT_R32G32B32A32_SINT,
676                 VK_FORMAT_R32G32B32A32_SFLOAT
677         };
678         static const VkFormat s_requiredStorageImageAtomicFormats[] =
679         {
680                 VK_FORMAT_R32_UINT,
681                 VK_FORMAT_R32_SINT
682         };
683         static const VkFormat s_requiredColorAttachmentBlitDstFormats[] =
684         {
685                 VK_FORMAT_R5G6B5_UNORM_PACK16,
686                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
687                 VK_FORMAT_R8_UNORM,
688                 VK_FORMAT_R8_SNORM,
689                 VK_FORMAT_R8_UINT,
690                 VK_FORMAT_R8_SINT,
691                 VK_FORMAT_R8G8_UNORM,
692                 VK_FORMAT_R8G8_SNORM,
693                 VK_FORMAT_R8G8_UINT,
694                 VK_FORMAT_R8G8_SINT,
695                 VK_FORMAT_R8G8B8A8_UNORM,
696                 VK_FORMAT_R8G8B8A8_SNORM,
697                 VK_FORMAT_R8G8B8A8_UINT,
698                 VK_FORMAT_R8G8B8A8_SINT,
699                 VK_FORMAT_R8G8B8A8_SRGB,
700                 VK_FORMAT_B8G8R8A8_UNORM,
701                 VK_FORMAT_B8G8R8A8_SRGB,
702                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
703                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
704                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
705                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
706                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
707                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
708                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
709                 VK_FORMAT_R16_UNORM,
710                 VK_FORMAT_R16_SNORM,
711                 VK_FORMAT_R16_UINT,
712                 VK_FORMAT_R16_SINT,
713                 VK_FORMAT_R16_SFLOAT,
714                 VK_FORMAT_R16G16_UNORM,
715                 VK_FORMAT_R16G16_SNORM,
716                 VK_FORMAT_R16G16_UINT,
717                 VK_FORMAT_R16G16_SINT,
718                 VK_FORMAT_R16G16_SFLOAT,
719                 VK_FORMAT_R16G16B16A16_UNORM,
720                 VK_FORMAT_R16G16B16A16_SNORM,
721                 VK_FORMAT_R16G16B16A16_UINT,
722                 VK_FORMAT_R16G16B16A16_SINT,
723                 VK_FORMAT_R16G16B16A16_SFLOAT,
724                 VK_FORMAT_R32_UINT,
725                 VK_FORMAT_R32_SINT,
726                 VK_FORMAT_R32_SFLOAT,
727                 VK_FORMAT_R32G32_UINT,
728                 VK_FORMAT_R32G32_SINT,
729                 VK_FORMAT_R32G32_SFLOAT,
730                 VK_FORMAT_R32G32B32A32_UINT,
731                 VK_FORMAT_R32G32B32A32_SINT,
732                 VK_FORMAT_R32G32B32A32_SFLOAT
733         };
734         static const VkFormat s_requiredColorAttachmentBlendFormats[] =
735         {
736                 VK_FORMAT_R5G6B5_UNORM_PACK16,
737                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
738                 VK_FORMAT_R8_UNORM,
739                 VK_FORMAT_R8_SNORM,
740                 VK_FORMAT_R8G8_UNORM,
741                 VK_FORMAT_R8G8_SNORM,
742                 VK_FORMAT_R8G8B8A8_UNORM,
743                 VK_FORMAT_R8G8B8A8_SNORM,
744                 VK_FORMAT_R8G8B8A8_SRGB,
745                 VK_FORMAT_B8G8R8A8_UNORM,
746                 VK_FORMAT_B8G8R8A8_SRGB,
747                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
748                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
749                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
750                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
751                 VK_FORMAT_R16_UNORM,
752                 VK_FORMAT_R16_SNORM,
753                 VK_FORMAT_R16_SFLOAT,
754                 VK_FORMAT_R16G16_UNORM,
755                 VK_FORMAT_R16G16_SNORM,
756                 VK_FORMAT_R16G16_SFLOAT,
757                 VK_FORMAT_R16G16B16A16_UNORM,
758                 VK_FORMAT_R16G16B16A16_SNORM,
759                 VK_FORMAT_R16G16B16A16_SFLOAT
760         };
761         static const VkFormat s_requiredDepthStencilAttachmentFormats[] =
762         {
763                 VK_FORMAT_D16_UNORM
764         };
765
766         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
767
768         if (de::contains(DE_ARRAY_BEGIN(s_requiredSampledImageBlitSrcFormats), DE_ARRAY_END(s_requiredSampledImageBlitSrcFormats), format))
769                 flags |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT|VK_FORMAT_FEATURE_BLIT_SRC_BIT;
770
771         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageFormats), DE_ARRAY_END(s_requiredStorageImageFormats), format))
772                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT;
773
774         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageImageAtomicFormats), DE_ARRAY_END(s_requiredStorageImageAtomicFormats), format))
775                 flags |= VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT;
776
777         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlitDstFormats), DE_ARRAY_END(s_requiredColorAttachmentBlitDstFormats), format))
778                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT|VK_FORMAT_FEATURE_BLIT_DST_BIT;
779
780         if (de::contains(DE_ARRAY_BEGIN(s_requiredColorAttachmentBlendFormats), DE_ARRAY_END(s_requiredColorAttachmentBlendFormats), format))
781                 flags |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
782
783         if (de::contains(DE_ARRAY_BEGIN(s_requiredDepthStencilAttachmentFormats), DE_ARRAY_END(s_requiredDepthStencilAttachmentFormats), format))
784                 flags |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
785
786         return flags;
787 }
788
789 VkFormatFeatureFlags getRequiredBufferFeatures (VkFormat format)
790 {
791         static const VkFormat s_requiredVertexBufferFormats[] =
792         {
793                 VK_FORMAT_R8_UNORM,
794                 VK_FORMAT_R8_SNORM,
795                 VK_FORMAT_R8_UINT,
796                 VK_FORMAT_R8_SINT,
797                 VK_FORMAT_R8G8_UNORM,
798                 VK_FORMAT_R8G8_SNORM,
799                 VK_FORMAT_R8G8_UINT,
800                 VK_FORMAT_R8G8_SINT,
801                 VK_FORMAT_R8G8B8A8_UNORM,
802                 VK_FORMAT_R8G8B8A8_SNORM,
803                 VK_FORMAT_R8G8B8A8_UINT,
804                 VK_FORMAT_R8G8B8A8_SINT,
805                 VK_FORMAT_B8G8R8A8_UNORM,
806                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
807                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
808                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
809                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
810                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
811                 VK_FORMAT_R16_UNORM,
812                 VK_FORMAT_R16_SNORM,
813                 VK_FORMAT_R16_UINT,
814                 VK_FORMAT_R16_SINT,
815                 VK_FORMAT_R16_SFLOAT,
816                 VK_FORMAT_R16G16_UNORM,
817                 VK_FORMAT_R16G16_SNORM,
818                 VK_FORMAT_R16G16_UINT,
819                 VK_FORMAT_R16G16_SINT,
820                 VK_FORMAT_R16G16_SFLOAT,
821                 VK_FORMAT_R16G16B16A16_UNORM,
822                 VK_FORMAT_R16G16B16A16_SNORM,
823                 VK_FORMAT_R16G16B16A16_UINT,
824                 VK_FORMAT_R16G16B16A16_SINT,
825                 VK_FORMAT_R16G16B16A16_SFLOAT,
826                 VK_FORMAT_R32_UINT,
827                 VK_FORMAT_R32_SINT,
828                 VK_FORMAT_R32_SFLOAT,
829                 VK_FORMAT_R32G32_UINT,
830                 VK_FORMAT_R32G32_SINT,
831                 VK_FORMAT_R32G32_SFLOAT,
832                 VK_FORMAT_R32G32B32_UINT,
833                 VK_FORMAT_R32G32B32_SINT,
834                 VK_FORMAT_R32G32B32_SFLOAT,
835                 VK_FORMAT_R32G32B32A32_UINT,
836                 VK_FORMAT_R32G32B32A32_SINT,
837                 VK_FORMAT_R32G32B32A32_SFLOAT
838         };
839         static const VkFormat s_requiredUniformTexelBufferFormats[] =
840         {
841                 VK_FORMAT_R8_UNORM,
842                 VK_FORMAT_R8_SNORM,
843                 VK_FORMAT_R8_UINT,
844                 VK_FORMAT_R8_SINT,
845                 VK_FORMAT_R8G8_UNORM,
846                 VK_FORMAT_R8G8_SNORM,
847                 VK_FORMAT_R8G8_UINT,
848                 VK_FORMAT_R8G8_SINT,
849                 VK_FORMAT_R8G8B8A8_UNORM,
850                 VK_FORMAT_R8G8B8A8_SNORM,
851                 VK_FORMAT_R8G8B8A8_UINT,
852                 VK_FORMAT_R8G8B8A8_SINT,
853                 VK_FORMAT_B8G8R8A8_UNORM,
854                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
855                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
856                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
857                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
858                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
859                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
860                 VK_FORMAT_R16_UNORM,
861                 VK_FORMAT_R16_SNORM,
862                 VK_FORMAT_R16_UINT,
863                 VK_FORMAT_R16_SINT,
864                 VK_FORMAT_R16_SFLOAT,
865                 VK_FORMAT_R16G16_UNORM,
866                 VK_FORMAT_R16G16_SNORM,
867                 VK_FORMAT_R16G16_UINT,
868                 VK_FORMAT_R16G16_SINT,
869                 VK_FORMAT_R16G16_SFLOAT,
870                 VK_FORMAT_R16G16B16A16_UNORM,
871                 VK_FORMAT_R16G16B16A16_SNORM,
872                 VK_FORMAT_R16G16B16A16_UINT,
873                 VK_FORMAT_R16G16B16A16_SINT,
874                 VK_FORMAT_R16G16B16A16_SFLOAT,
875                 VK_FORMAT_R32_UINT,
876                 VK_FORMAT_R32_SINT,
877                 VK_FORMAT_R32_SFLOAT,
878                 VK_FORMAT_R32G32_UINT,
879                 VK_FORMAT_R32G32_SINT,
880                 VK_FORMAT_R32G32_SFLOAT,
881                 VK_FORMAT_R32G32B32A32_UINT,
882                 VK_FORMAT_R32G32B32A32_SINT,
883                 VK_FORMAT_R32G32B32A32_SFLOAT,
884                 VK_FORMAT_B10G11R11_UFLOAT_PACK32
885         };
886         static const VkFormat s_requiredStorageTexelBufferFormats[] =
887         {
888                 VK_FORMAT_R8G8B8A8_UNORM,
889                 VK_FORMAT_R8G8B8A8_SNORM,
890                 VK_FORMAT_R8G8B8A8_UINT,
891                 VK_FORMAT_R8G8B8A8_SINT,
892                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
893                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
894                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
895                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
896                 VK_FORMAT_R16G16B16A16_UINT,
897                 VK_FORMAT_R16G16B16A16_SINT,
898                 VK_FORMAT_R16G16B16A16_SFLOAT,
899                 VK_FORMAT_R32_UINT,
900                 VK_FORMAT_R32_SINT,
901                 VK_FORMAT_R32_SFLOAT,
902                 VK_FORMAT_R32G32_UINT,
903                 VK_FORMAT_R32G32_SINT,
904                 VK_FORMAT_R32G32_SFLOAT,
905                 VK_FORMAT_R32G32B32A32_UINT,
906                 VK_FORMAT_R32G32B32A32_SINT,
907                 VK_FORMAT_R32G32B32A32_SFLOAT
908         };
909         static const VkFormat s_requiredStorageTexelBufferAtomicFormats[] =
910         {
911                 VK_FORMAT_R32_UINT,
912                 VK_FORMAT_R32_SINT
913         };
914
915         VkFormatFeatureFlags    flags   = (VkFormatFeatureFlags)0;
916
917         if (de::contains(DE_ARRAY_BEGIN(s_requiredVertexBufferFormats), DE_ARRAY_END(s_requiredVertexBufferFormats), format))
918                 flags |= VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT;
919
920         if (de::contains(DE_ARRAY_BEGIN(s_requiredUniformTexelBufferFormats), DE_ARRAY_END(s_requiredUniformTexelBufferFormats), format))
921                 flags |= VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT;
922
923         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferFormats), DE_ARRAY_END(s_requiredStorageTexelBufferFormats), format))
924                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT;
925
926         if (de::contains(DE_ARRAY_BEGIN(s_requiredStorageTexelBufferAtomicFormats), DE_ARRAY_END(s_requiredStorageTexelBufferAtomicFormats), format))
927                 flags |= VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT;
928
929         return flags;
930 }
931
932 tcu::TestStatus formatProperties (Context& context, VkFormat format)
933 {
934         TestLog&                                        log                             = context.getTestContext().getLog();
935         const VkFormatProperties        properties              = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
936         bool                                            allOk                   = true;
937
938         const struct
939         {
940                 VkFormatFeatureFlags VkFormatProperties::*      field;
941                 const char*                                                                     fieldName;
942                 VkFormatFeatureFlags                                            requiredFeatures;
943         } fields[] =
944         {
945                 { &VkFormatProperties::linearTilingFeatures,    "linearTilingFeatures",         (VkFormatFeatureFlags)0                                         },
946                 { &VkFormatProperties::optimalTilingFeatures,   "optimalTilingFeatures",        getRequiredOptimalTilingFeatures(format)        },
947                 { &VkFormatProperties::bufferFeatures,                  "buffeFeatures",                        getRequiredBufferFeatures(format)                       }
948         };
949
950         log << TestLog::Message << properties << TestLog::EndMessage;
951
952         for (int fieldNdx = 0; fieldNdx < DE_LENGTH_OF_ARRAY(fields); fieldNdx++)
953         {
954                 const char* const                               fieldName       = fields[fieldNdx].fieldName;
955                 const VkFormatFeatureFlags              supported       = properties.*fields[fieldNdx].field;
956                 const VkFormatFeatureFlags              required        = fields[fieldNdx].requiredFeatures;
957
958                 if ((supported & required) != required)
959                 {
960                         log << TestLog::Message << "ERROR in " << fieldName << ":\n"
961                                                                     << "  required: " << getFormatFeatureFlagsStr(required) << "\n  "
962                                                                         << "  missing: " << getFormatFeatureFlagsStr(~supported & required)
963                                 << TestLog::EndMessage;
964                         allOk = false;
965                 }
966         }
967
968         if (allOk)
969                 return tcu::TestStatus::pass("Query and validation passed");
970         else
971                 return tcu::TestStatus::fail("Required features not supported");
972 }
973
974 bool optimalTilingFeaturesSupported (Context& context, VkFormat format, VkFormatFeatureFlags features)
975 {
976         const VkFormatProperties        properties      = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
977
978         return (properties.optimalTilingFeatures & features) == features;
979 }
980
981 bool optimalTilingFeaturesSupportedForAll (Context& context, const VkFormat* begin, const VkFormat* end, VkFormatFeatureFlags features)
982 {
983         for (const VkFormat* cur = begin; cur != end; ++cur)
984         {
985                 if (!optimalTilingFeaturesSupported(context, *cur, features))
986                         return false;
987         }
988
989         return true;
990 }
991
992 tcu::TestStatus testDepthStencilSupported (Context& context)
993 {
994         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
995                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
996                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_X8_D24_UNORM_PACK32 or VK_FORMAT_D32_SFLOAT");
997
998         if (!optimalTilingFeaturesSupported(context, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) &&
999                 !optimalTilingFeaturesSupported(context, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))
1000                 return tcu::TestStatus::fail("Doesn't support one of VK_FORMAT_D24_UNORM_S8_UINT or VK_FORMAT_D32_SFLOAT_S8_UINT");
1001
1002         return tcu::TestStatus::pass("Required depth/stencil formats supported");
1003 }
1004
1005 tcu::TestStatus testCompressedFormatsSupported (Context& context)
1006 {
1007         static const VkFormat s_allBcFormats[] =
1008         {
1009                 VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1010                 VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1011                 VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1012                 VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1013                 VK_FORMAT_BC2_UNORM_BLOCK,
1014                 VK_FORMAT_BC2_SRGB_BLOCK,
1015                 VK_FORMAT_BC3_UNORM_BLOCK,
1016                 VK_FORMAT_BC3_SRGB_BLOCK,
1017                 VK_FORMAT_BC4_UNORM_BLOCK,
1018                 VK_FORMAT_BC4_SNORM_BLOCK,
1019                 VK_FORMAT_BC5_UNORM_BLOCK,
1020                 VK_FORMAT_BC5_SNORM_BLOCK,
1021                 VK_FORMAT_BC6H_UFLOAT_BLOCK,
1022                 VK_FORMAT_BC6H_SFLOAT_BLOCK,
1023                 VK_FORMAT_BC7_UNORM_BLOCK,
1024                 VK_FORMAT_BC7_SRGB_BLOCK,
1025         };
1026         static const VkFormat s_allEtcEacFormats[] =
1027         {
1028                 VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
1029                 VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
1030                 VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
1031                 VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
1032                 VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
1033                 VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
1034                 VK_FORMAT_EAC_R11_UNORM_BLOCK,
1035                 VK_FORMAT_EAC_R11_SNORM_BLOCK,
1036                 VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
1037                 VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
1038         };
1039         static const VkFormat s_allAstcFormats[] =
1040         {
1041                 VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
1042                 VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
1043                 VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
1044                 VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
1045                 VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
1046                 VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
1047                 VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
1048                 VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
1049                 VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
1050                 VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
1051                 VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
1052                 VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
1053                 VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
1054                 VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
1055                 VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
1056                 VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
1057                 VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
1058                 VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
1059                 VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
1060                 VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
1061                 VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
1062                 VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
1063                 VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
1064                 VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
1065                 VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
1066                 VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
1067                 VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
1068                 VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
1069         };
1070
1071         const bool      bcFormatsSupported              = optimalTilingFeaturesSupportedForAll(context,
1072                                                                                                                                                            DE_ARRAY_BEGIN(s_allBcFormats),
1073                                                                                                                                                            DE_ARRAY_END(s_allBcFormats),
1074                                                                                                                                                            VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
1075         const bool      etcEacFormatsSupported  = optimalTilingFeaturesSupportedForAll(context,
1076                                                                                                                                                            DE_ARRAY_BEGIN(s_allEtcEacFormats),
1077                                                                                                                                                            DE_ARRAY_END(s_allEtcEacFormats),
1078                                                                                                                                                            VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
1079         const bool      astcFormatsSupported    = optimalTilingFeaturesSupportedForAll(context,
1080                                                                                                                                                            DE_ARRAY_BEGIN(s_allAstcFormats),
1081                                                                                                                                                            DE_ARRAY_END(s_allAstcFormats),
1082                                                                                                                                                            VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT);
1083         TestLog&        log                                             = context.getTestContext().getLog();
1084
1085         log << TestLog::Message << "All BC* formats supported: " << (bcFormatsSupported ? "true" : "false") << TestLog::EndMessage;
1086         log << TestLog::Message << "All ETC2/EAC formats supported: " << (etcEacFormatsSupported ? "true" : "false") << TestLog::EndMessage;
1087         log << TestLog::Message << "All ASTC formats supported: " << (astcFormatsSupported ? "true" : "false") << TestLog::EndMessage;
1088
1089         if (bcFormatsSupported || etcEacFormatsSupported || astcFormatsSupported)
1090                 return tcu::TestStatus::pass("At least one set of compressed formats supported");
1091         else
1092                 return tcu::TestStatus::fail("Compressed formats not supported");
1093 }
1094
1095 void createFormatTests (tcu::TestCaseGroup* testGroup)
1096 {
1097         DE_STATIC_ASSERT(VK_FORMAT_UNDEFINED == 0);
1098
1099         for (deUint32 formatNdx = VK_FORMAT_UNDEFINED+1; formatNdx < VK_FORMAT_LAST; ++formatNdx)
1100         {
1101                 const VkFormat          format                  = (VkFormat)formatNdx;
1102                 const char* const       enumName                = getFormatName(format);
1103                 const string            caseName                = de::toLower(string(enumName).substr(10));
1104
1105                 addFunctionCase(testGroup, caseName, enumName, formatProperties, format);
1106         }
1107
1108         addFunctionCase(testGroup, "depth_stencil",                     "",     testDepthStencilSupported);
1109         addFunctionCase(testGroup, "compressed_formats",        "",     testCompressedFormatsSupported);
1110 }
1111
1112 VkImageUsageFlags getValidImageUsageFlags (VkFormat, VkFormatFeatureFlags supportedFeatures)
1113 {
1114         VkImageUsageFlags       flags   = (VkImageUsageFlags)0;
1115
1116         // If format is supported at all, it must be valid transfer src+dst
1117         if (supportedFeatures != 0)
1118                 flags |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT|VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1119
1120         if ((supportedFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) != 0)
1121                 flags |= VK_IMAGE_USAGE_SAMPLED_BIT;
1122
1123         if ((supportedFeatures & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) != 0)
1124                 flags |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT|VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT|VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT;
1125
1126         if ((supportedFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) != 0)
1127                 flags |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
1128
1129         if ((supportedFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) != 0)
1130                 flags |= VK_IMAGE_USAGE_STORAGE_BIT;
1131
1132         return flags;
1133 }
1134
1135 bool isValidImageUsageFlagCombination (VkImageUsageFlags usage)
1136 {
1137         return usage != 0;
1138 }
1139
1140 VkImageCreateFlags getValidImageCreateFlags (const VkPhysicalDeviceFeatures& deviceFeatures, VkFormat, VkFormatFeatureFlags, VkImageType type, VkImageUsageFlags usage)
1141 {
1142         VkImageCreateFlags      flags   = (VkImageCreateFlags)0;
1143
1144         if ((usage & VK_IMAGE_USAGE_SAMPLED_BIT) != 0)
1145         {
1146                 flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
1147
1148                 if (type == VK_IMAGE_TYPE_2D)
1149                         flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
1150         }
1151
1152         if ((usage & (VK_IMAGE_USAGE_SAMPLED_BIT|VK_IMAGE_USAGE_STORAGE_BIT)) != 0 &&
1153                 (usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) == 0)
1154         {
1155                 if (deviceFeatures.sparseBinding)
1156                         flags |= VK_IMAGE_CREATE_SPARSE_BINDING_BIT|VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT;
1157
1158                 if (deviceFeatures.sparseResidencyAliased)
1159                         flags |= VK_IMAGE_CREATE_SPARSE_ALIASED_BIT;
1160         }
1161
1162         return flags;
1163 }
1164
1165 bool isValidImageCreateFlagCombination (VkImageCreateFlags)
1166 {
1167         return true;
1168 }
1169
1170 struct ImageFormatPropertyCase
1171 {
1172         VkFormat                format;
1173         VkImageType             imageType;
1174         VkImageTiling   tiling;
1175
1176         ImageFormatPropertyCase (VkFormat format_, VkImageType imageType_, VkImageTiling tiling_)
1177                 : format        (format_)
1178                 , imageType     (imageType_)
1179                 , tiling        (tiling_)
1180         {}
1181
1182         ImageFormatPropertyCase (void)
1183                 : format        (VK_FORMAT_LAST)
1184                 , imageType     (VK_IMAGE_TYPE_LAST)
1185                 , tiling        (VK_IMAGE_TILING_LAST)
1186         {}
1187 };
1188
1189 tcu::TestStatus imageFormatProperties (Context& context, ImageFormatPropertyCase params)
1190 {
1191         TestLog&                                                log                                     = context.getTestContext().getLog();
1192         const VkFormat                                  format                          = params.format;
1193         const VkImageType                               imageType                       = params.imageType;
1194         const VkImageTiling                             tiling                          = params.tiling;
1195         const VkPhysicalDeviceFeatures& deviceFeatures          = context.getDeviceFeatures();
1196         const VkFormatProperties                formatProperties        = getPhysicalDeviceFormatProperties(context.getInstanceInterface(), context.getPhysicalDevice(), format);
1197
1198         const VkFormatFeatureFlags              supportedFeatures       = tiling == VK_IMAGE_TILING_LINEAR ? formatProperties.linearTilingFeatures : formatProperties.optimalTilingFeatures;
1199         const VkImageUsageFlags                 usageFlagSet            = getValidImageUsageFlags(format, supportedFeatures);
1200
1201         for (VkImageUsageFlags curUsageFlags = 0; curUsageFlags <= usageFlagSet; curUsageFlags++)
1202         {
1203                 if ((curUsageFlags & ~usageFlagSet) != 0 ||
1204                         !isValidImageUsageFlagCombination(curUsageFlags))
1205                         continue;
1206
1207                 const VkImageCreateFlags        createFlagSet           = getValidImageCreateFlags(deviceFeatures, format, supportedFeatures, imageType, curUsageFlags);
1208
1209                 for (VkImageCreateFlags curCreateFlags = 0; curCreateFlags <= createFlagSet; curCreateFlags++)
1210                 {
1211                         if ((curCreateFlags & ~createFlagSet) != 0 ||
1212                                 !isValidImageCreateFlagCombination(curCreateFlags))
1213                                 continue;
1214
1215                         log << TestLog::Message << "Testing " << getImageTypeStr(imageType) << ", "
1216                                                                         << getImageTilingStr(tiling) << ", "
1217                                                                         << getImageUsageFlagsStr(curUsageFlags) << ", "
1218                                                                         << getImageCreateFlagsStr(curCreateFlags)
1219                                 << TestLog::EndMessage;
1220
1221                         try
1222                         {
1223                                 const VkImageFormatProperties   properties      = getPhysicalDeviceImageFormatProperties(context.getInstanceInterface(),
1224                                                                                                                                                                                                                 context.getPhysicalDevice(),
1225                                                                                                                                                                                                                 format,
1226                                                                                                                                                                                                                 imageType,
1227                                                                                                                                                                                                                 tiling,
1228                                                                                                                                                                                                                 curUsageFlags,
1229                                                                                                                                                                                                                 curCreateFlags);
1230                                 log << TestLog::Message << properties << "\n" << TestLog::EndMessage;
1231
1232                                 // \todo [2016-01-24 pyry] Expand validation
1233                                 TCU_CHECK((properties.sampleCounts & VK_SAMPLE_COUNT_1_BIT) != 0);
1234                                 TCU_CHECK(imageType != VK_IMAGE_TYPE_1D || (properties.maxExtent.width >= 1 && properties.maxExtent.height == 1 && properties.maxExtent.depth == 1));
1235                                 TCU_CHECK(imageType != VK_IMAGE_TYPE_2D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth == 1));
1236                                 TCU_CHECK(imageType != VK_IMAGE_TYPE_3D || (properties.maxExtent.width >= 1 && properties.maxExtent.height >= 1 && properties.maxExtent.depth >= 1));
1237                         }
1238                         catch (const Error& error)
1239                         {
1240                                 // \todo [2016-01-22 pyry] Check if this is indeed optional image type / flag combination
1241                                 if (error.getError() == VK_ERROR_FORMAT_NOT_SUPPORTED)
1242                                         log << TestLog::Message << "Got VK_ERROR_FORMAT_NOT_SUPPORTED" << TestLog::EndMessage;
1243                                 else
1244                                         throw;
1245                         }
1246                 }
1247         }
1248
1249         return tcu::TestStatus::pass("All queries succeeded");
1250 }
1251
1252 void createImageFormatTypeTilingTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
1253 {
1254         DE_ASSERT(params.format == VK_FORMAT_LAST);
1255
1256         for (deUint32 formatNdx = VK_FORMAT_UNDEFINED+1; formatNdx < VK_FORMAT_LAST; ++formatNdx)
1257         {
1258                 const VkFormat          format                  = (VkFormat)formatNdx;
1259                 const char* const       enumName                = getFormatName(format);
1260                 const string            caseName                = de::toLower(string(enumName).substr(10));
1261
1262                 params.format = format;
1263
1264                 addFunctionCase(testGroup, caseName, enumName, imageFormatProperties, params);
1265         }
1266 }
1267
1268 void createImageFormatTypeTests (tcu::TestCaseGroup* testGroup, ImageFormatPropertyCase params)
1269 {
1270         DE_ASSERT(params.tiling == VK_IMAGE_TILING_LAST);
1271
1272         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "optimal",     "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(VK_FORMAT_LAST, params.imageType, VK_IMAGE_TILING_OPTIMAL)));
1273         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "linear",      "",     createImageFormatTypeTilingTests, ImageFormatPropertyCase(VK_FORMAT_LAST, params.imageType, VK_IMAGE_TILING_LINEAR)));
1274 }
1275
1276 void createImageFormatTests (tcu::TestCaseGroup* testGroup)
1277 {
1278         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "1d", "", createImageFormatTypeTests, ImageFormatPropertyCase(VK_FORMAT_LAST, VK_IMAGE_TYPE_1D, VK_IMAGE_TILING_LAST)));
1279         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "2d", "", createImageFormatTypeTests, ImageFormatPropertyCase(VK_FORMAT_LAST, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_LAST)));
1280         testGroup->addChild(createTestGroup(testGroup->getTestContext(), "3d", "", createImageFormatTypeTests, ImageFormatPropertyCase(VK_FORMAT_LAST, VK_IMAGE_TYPE_3D, VK_IMAGE_TILING_LAST)));
1281 }
1282
1283 } // anonymous
1284
1285 tcu::TestCaseGroup* createFeatureInfoTests (tcu::TestContext& testCtx)
1286 {
1287         de::MovePtr<tcu::TestCaseGroup> infoTests       (new tcu::TestCaseGroup(testCtx, "info", "Platform Information Tests"));
1288
1289         {
1290                 de::MovePtr<tcu::TestCaseGroup> instanceInfoTests       (new tcu::TestCaseGroup(testCtx, "instance", "Instance Information Tests"));
1291
1292                 addFunctionCase(instanceInfoTests.get(), "physical_devices",            "Physical devices",                     enumeratePhysicalDevices);
1293                 addFunctionCase(instanceInfoTests.get(), "layers",                                      "Layers",                                       enumerateInstanceLayers);
1294                 addFunctionCase(instanceInfoTests.get(), "extensions",                          "Extensions",                           enumerateInstanceExtensions);
1295
1296                 infoTests->addChild(instanceInfoTests.release());
1297         }
1298
1299         {
1300                 de::MovePtr<tcu::TestCaseGroup> deviceInfoTests (new tcu::TestCaseGroup(testCtx, "device", "Device Information Tests"));
1301
1302                 addFunctionCase(deviceInfoTests.get(), "features",                                      "Device Features",                      deviceFeatures);
1303                 addFunctionCase(deviceInfoTests.get(), "properties",                            "Device Properties",            deviceProperties);
1304                 addFunctionCase(deviceInfoTests.get(), "queue_family_properties",       "Queue family properties",      deviceQueueFamilyProperties);
1305                 addFunctionCase(deviceInfoTests.get(), "memory_properties",                     "Memory properties",            deviceMemoryProperties);
1306                 addFunctionCase(deviceInfoTests.get(), "layers",                                        "Layers",                                       enumerateDeviceLayers);
1307                 addFunctionCase(deviceInfoTests.get(), "extensions",                            "Extensions",                           enumerateDeviceExtensions);
1308
1309                 infoTests->addChild(deviceInfoTests.release());
1310         }
1311
1312         infoTests->addChild(createTestGroup(testCtx, "format_properties",               "VkGetPhysicalDeviceFormatProperties() Tests",          createFormatTests));
1313         infoTests->addChild(createTestGroup(testCtx, "image_format_properties", "VkGetPhysicalDeviceImageFormatProperties() Tests",     createImageFormatTests));
1314
1315         return infoTests.release();
1316 }
1317
1318 } // api
1319 } // vkt