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