Modify spirv_assembly tests adding dependency on 16bit_storage extension
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / sparse_resources / vktSparseResourcesImageBlockShapes.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2017 The Khronos Group Inc.
6  * Copyright (c) 2017 Google Inc.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file  vktSparseResourcesImageBlockShapes.cpp
22  * \brief Standard block shape tests.
23  *//*--------------------------------------------------------------------*/
24
25 #include "vktSparseResourcesBufferSparseBinding.hpp"
26 #include "vktSparseResourcesTestsUtil.hpp"
27 #include "vktSparseResourcesBase.hpp"
28 #include "vktTestCaseUtil.hpp"
29
30 #include "vkDefs.hpp"
31 #include "vkRef.hpp"
32 #include "vkRefUtil.hpp"
33 #include "vkPlatform.hpp"
34 #include "vkPrograms.hpp"
35 #include "vkMemUtil.hpp"
36 #include "vkBuilderUtil.hpp"
37 #include "vkImageUtil.hpp"
38 #include "vkQueryUtil.hpp"
39 #include "vkTypeUtil.hpp"
40
41 #include "deUniquePtr.hpp"
42 #include "deStringUtil.hpp"
43
44 #include <string>
45 #include <vector>
46
47 using namespace vk;
48
49 namespace vkt
50 {
51 namespace sparse
52 {
53 namespace
54 {
55
56 class ImageBlockShapesCase : public TestCase
57 {
58 public:
59                                         ImageBlockShapesCase    (tcu::TestContext&                      testCtx,
60                                                                                          const std::string&                     name,
61                                                                                          const std::string&                     description,
62                                                                                          const ImageType                        imageType,
63                                                                                          const tcu::UVec3&                      imageSize,
64                                                                                          const tcu::TextureFormat&      format,
65                                                                                          deUint32                                       numSamples);
66
67         void                    initPrograms                            (SourceCollections&                     sourceCollections) const {DE_UNREF(sourceCollections);};
68         TestInstance*   createInstance                          (Context&                                       context) const;
69
70 private:
71         const ImageType                         m_imageType;
72         const tcu::UVec3                        m_imageSize;
73         const tcu::TextureFormat        m_format;
74         const deUint32                          m_numSamples;
75 };
76
77 ImageBlockShapesCase::ImageBlockShapesCase (tcu::TestContext&                   testCtx,
78                                                                                         const std::string&                      name,
79                                                                                         const std::string&                      description,
80                                                                                         const ImageType                         imageType,
81                                                                                         const tcu::UVec3&                       imageSize,
82                                                                                         const tcu::TextureFormat&       format,
83                                                                                         deUint32                                        numSamples)
84         : TestCase                              (testCtx, name, description)
85         , m_imageType                   (imageType)
86         , m_imageSize                   (imageSize)
87         , m_format                              (format)
88         , m_numSamples                  (numSamples)
89 {
90 }
91
92 class ImageBlockShapesInstance : public SparseResourcesBaseInstance
93 {
94 public:
95                                         ImageBlockShapesInstance(Context&                                                       context,
96                                                                                          const ImageType                                        imageType,
97                                                                                          const tcu::UVec3&                                      imageSize,
98                                                                                          const tcu::TextureFormat&                      format,
99                                                                                          deUint32                                                       numSamples);
100
101         tcu::TestStatus iterate                                         (void);
102
103 private:
104         const ImageType                         m_imageType;
105         const tcu::UVec3                        m_imageSize;
106         const tcu::TextureFormat        m_format;
107         const deUint32                          m_numSamples;
108 };
109
110 ImageBlockShapesInstance::ImageBlockShapesInstance (Context&                                    context,
111                                                                                                         const ImageType                         imageType,
112                                                                                                         const tcu::UVec3&                       imageSize,
113                                                                                                         const tcu::TextureFormat&       format,
114                                                                                                         deUint32                                        numSamples)
115         : SparseResourcesBaseInstance   (context)
116         , m_imageType                                   (imageType)
117         , m_imageSize                                   (imageSize)
118         , m_format                                              (format)
119         , m_numSamples                                  (numSamples)
120 {
121 }
122
123 tcu::TestStatus ImageBlockShapesInstance::iterate (void)
124 {
125         const InstanceInterface&                                instance = m_context.getInstanceInterface();
126         const VkPhysicalDevice                                  physicalDevice = m_context.getPhysicalDevice();
127         const VkPhysicalDeviceProperties                physicalDeviceProperties = getPhysicalDeviceProperties(instance, physicalDevice);
128         VkImageCreateInfo                                               imageCreateInfo;
129         VkSparseImageMemoryRequirements                 aspectRequirements;
130         VkExtent3D                                                              imageGranularity;
131         const VkPhysicalDeviceSparseProperties  sparseProperties = physicalDeviceProperties.sparseProperties;
132         const deUint32                                                  pixelSize = tcu::getPixelSize(m_format) * 8;
133         VkExtent3D                                                              expectedGranularity;
134
135         // Check the image size does not exceed device limits
136         if (!isImageSizeSupported(instance, physicalDevice, m_imageType, m_imageSize))
137                 TCU_THROW(NotSupportedError, "Image size not supported for device");
138
139         // Check if device supports sparse operations for image type
140         if (!checkSparseSupportForImageType(instance, physicalDevice, m_imageType))
141                 TCU_THROW(NotSupportedError, "Sparse residency for image type is not supported");
142
143         imageCreateInfo.sType                                   = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
144         imageCreateInfo.pNext                                   = DE_NULL;
145         imageCreateInfo.flags                                   = VK_IMAGE_CREATE_SPARSE_RESIDENCY_BIT | VK_IMAGE_CREATE_SPARSE_BINDING_BIT;
146         imageCreateInfo.imageType                               = mapImageType(m_imageType);
147         imageCreateInfo.format                                  = mapTextureFormat(m_format);
148         imageCreateInfo.extent                                  = makeExtent3D(getLayerSize(m_imageType, m_imageSize));
149         imageCreateInfo.mipLevels                               = 1u;
150         imageCreateInfo.arrayLayers                             = getNumLayers(m_imageType, m_imageSize);
151         imageCreateInfo.samples                                 = static_cast<VkSampleCountFlagBits>(m_numSamples);
152         imageCreateInfo.tiling                                  = VK_IMAGE_TILING_OPTIMAL;
153         imageCreateInfo.initialLayout                   = VK_IMAGE_LAYOUT_UNDEFINED;
154         imageCreateInfo.usage                                   = VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
155                                                                                           VK_IMAGE_USAGE_STORAGE_BIT;
156         imageCreateInfo.sharingMode                             = VK_SHARING_MODE_EXCLUSIVE;
157         imageCreateInfo.queueFamilyIndexCount   = 0u;
158         imageCreateInfo.pQueueFamilyIndices             = DE_NULL;
159
160         if (m_imageType == IMAGE_TYPE_CUBE || m_imageType == IMAGE_TYPE_CUBE_ARRAY)
161         {
162                 imageCreateInfo.flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
163         }
164
165         // Check the format supports given number of samples
166         const VkImageFormatProperties formatProperties = getPhysicalDeviceImageFormatProperties(instance, physicalDevice, imageCreateInfo.format, imageCreateInfo.imageType, imageCreateInfo.tiling, imageCreateInfo.usage, imageCreateInfo.flags);
167
168         if (!(formatProperties.sampleCounts & imageCreateInfo.samples))
169                 TCU_THROW(NotSupportedError, "The image format does not support the number of samples specified");
170
171         // Check if device supports sparse operations for image format
172         if (!checkSparseSupportForImageFormat(instance, physicalDevice, imageCreateInfo))
173                 TCU_THROW(NotSupportedError, "The image format does not support sparse operations");
174
175         {
176                 QueueRequirementsVec queueRequirements;
177                 queueRequirements.push_back(QueueRequirements(VK_QUEUE_SPARSE_BINDING_BIT, 1u));
178
179                 createDeviceSupportingQueues(queueRequirements);
180         }
181
182         {
183                 const DeviceInterface&                                                          deviceInterface                         = getDeviceInterface();
184
185                 // Create sparse image
186                 const Unique<VkImage>                                                           sparseImage                                     (createImage(deviceInterface, getDevice(), &imageCreateInfo));
187
188                 // Get sparse image sparse memory requirements
189                 const std::vector<VkSparseImageMemoryRequirements>      sparseMemoryRequirements        = getImageSparseMemoryRequirements(deviceInterface, getDevice(), *sparseImage);
190
191                 DE_ASSERT(sparseMemoryRequirements.size() != 0);
192
193                 const deUint32                                                                          colorAspectIndex                        = getSparseAspectRequirementsIndex(sparseMemoryRequirements, VK_IMAGE_ASPECT_COLOR_BIT);
194
195                 if (colorAspectIndex == NO_MATCH_FOUND)
196                         TCU_THROW(NotSupportedError, "Not supported image aspect - the test supports currently only VK_IMAGE_ASPECT_COLOR_BIT");
197
198                 aspectRequirements      = sparseMemoryRequirements[colorAspectIndex];
199                 imageGranularity        = aspectRequirements.formatProperties.imageGranularity;
200         }
201
202         if (m_imageType == IMAGE_TYPE_3D)
203         {
204                 if (!sparseProperties.residencyStandard3DBlockShape)
205                         return tcu::TestStatus::pass("Pass (residencyStandard3DBlockShape disabled)");
206
207                 switch (pixelSize)
208                 {
209                         case 8:
210                                 expectedGranularity.width       = 64;
211                                 expectedGranularity.height      = 32;
212                                 expectedGranularity.depth       = 32;
213                                 break;
214                         case 16:
215                                 expectedGranularity.width       = 32;
216                                 expectedGranularity.height      = 32;
217                                 expectedGranularity.depth       = 32;
218                                 break;
219                         case 32:
220                                 expectedGranularity.width       = 32;
221                                 expectedGranularity.height      = 32;
222                                 expectedGranularity.depth       = 16;
223                                 break;
224                         case 64:
225                                 expectedGranularity.width       = 32;
226                                 expectedGranularity.height      = 16;
227                                 expectedGranularity.depth       = 16;
228                                 break;
229                         default:
230                                 DE_ASSERT(pixelSize == 128);
231                                 expectedGranularity.width       = 16;
232                                 expectedGranularity.height      = 16;
233                                 expectedGranularity.depth       = 16;
234                                 break;
235                 };
236         }
237         else if (m_numSamples == 2)
238         {
239                 if (!sparseProperties.residencyStandard2DMultisampleBlockShape)
240                         return tcu::TestStatus::pass("Pass (residencyStandard2DMultisampleBlockShape disabled)");
241
242                 expectedGranularity.depth = 1;
243
244                 switch (pixelSize)
245                 {
246                         case 8:
247                                 expectedGranularity.width       = 128;
248                                 expectedGranularity.height      = 256;
249                                 break;
250                         case 16:
251                                 expectedGranularity.width       = 128;
252                                 expectedGranularity.height      = 128;
253                                 break;
254                         case 32:
255                                 expectedGranularity.width       = 64;
256                                 expectedGranularity.height      = 128;
257                                 break;
258                         case 64:
259                                 expectedGranularity.width       = 64;
260                                 expectedGranularity.height      = 64;
261                                 break;
262                         default:
263                                 DE_ASSERT(pixelSize == 128);
264                                 expectedGranularity.width       = 32;
265                                 expectedGranularity.height      = 64;
266                                 break;
267                 };
268         }
269         else if (m_numSamples == 4)
270         {
271                 if (!sparseProperties.residencyStandard2DMultisampleBlockShape)
272                         return tcu::TestStatus::pass("Pass (residencyStandard2DMultisampleBlockShape disabled)");
273
274                 expectedGranularity.depth = 1;
275
276                 switch (pixelSize)
277                 {
278                         case 8:
279                                 expectedGranularity.width       = 128;
280                                 expectedGranularity.height      = 128;
281                                 break;
282                         case 16:
283                                 expectedGranularity.width       = 128;
284                                 expectedGranularity.height      = 64;
285                                 break;
286                         case 32:
287                                 expectedGranularity.width       = 64;
288                                 expectedGranularity.height      = 64;
289                                 break;
290                         case 64:
291                                 expectedGranularity.width       = 64;
292                                 expectedGranularity.height      = 32;
293                                 break;
294                         default:
295                                 DE_ASSERT(pixelSize == 128);
296                                 expectedGranularity.width       = 32;
297                                 expectedGranularity.height      = 32;
298                                 break;
299                 };
300         }
301         else if (m_numSamples == 8)
302         {
303                 if (!sparseProperties.residencyStandard2DMultisampleBlockShape)
304                         return tcu::TestStatus::pass("Pass (residencyStandard2DMultisampleBlockShape disabled)");
305
306                 expectedGranularity.depth = 1;
307
308                 switch (pixelSize)
309                 {
310                         case 8:
311                                 expectedGranularity.width       = 64;
312                                 expectedGranularity.height      = 128;
313                                 break;
314                         case 16:
315                                 expectedGranularity.width       = 64;
316                                 expectedGranularity.height      = 64;
317                                 break;
318                         case 32:
319                                 expectedGranularity.width       = 32;
320                                 expectedGranularity.height      = 64;
321                                 break;
322                         case 64:
323                                 expectedGranularity.width       = 32;
324                                 expectedGranularity.height      = 32;
325                                 break;
326                         default:
327                                 DE_ASSERT(pixelSize == 128);
328                                 expectedGranularity.width       = 16;
329                                 expectedGranularity.height      = 32;
330                                 break;
331                 };
332         }
333         else if (m_numSamples == 16)
334         {
335                 if (!sparseProperties.residencyStandard2DMultisampleBlockShape)
336                         return tcu::TestStatus::pass("Pass (residencyStandard2DMultisampleBlockShape disabled)");
337
338                 expectedGranularity.depth = 1;
339
340                 switch (pixelSize)
341                 {
342                         case 8:
343                                 expectedGranularity.width       = 64;
344                                 expectedGranularity.height      = 64;
345                                 break;
346                         case 16:
347                                 expectedGranularity.width       = 64;
348                                 expectedGranularity.height      = 32;
349                                 break;
350                         case 32:
351                                 expectedGranularity.width       = 32;
352                                 expectedGranularity.height      = 32;
353                                 break;
354                         case 64:
355                                 expectedGranularity.width       = 32;
356                                 expectedGranularity.height      = 16;
357                                 break;
358                         default:
359                                 DE_ASSERT(pixelSize == 128);
360                                 expectedGranularity.width       = 16;
361                                 expectedGranularity.height      = 16;
362                                 break;
363                 };
364         }
365         else
366         {
367                 DE_ASSERT(m_numSamples == 1);
368
369                 if (!sparseProperties.residencyStandard2DBlockShape)
370                         return tcu::TestStatus::pass("Pass (residencyStandard2DBlockShape disabled)");
371
372                 expectedGranularity.depth = 1;
373
374                 switch (pixelSize)
375                 {
376                         case 8:
377                                 expectedGranularity.width       = 256;
378                                 expectedGranularity.height      = 256;
379                                 break;
380                         case 16:
381                                 expectedGranularity.width       = 256;
382                                 expectedGranularity.height      = 128;
383                                 break;
384                         case 32:
385                                 expectedGranularity.width       = 128;
386                                 expectedGranularity.height      = 128;
387                                 break;
388                         case 64:
389                                 expectedGranularity.width       = 128;
390                                 expectedGranularity.height      = 64;
391                                 break;
392                         default:
393                                 DE_ASSERT(pixelSize == 128);
394                                 expectedGranularity.width       = 64;
395                                 expectedGranularity.height      = 64;
396                                 break;
397                 };
398         }
399
400         if (imageGranularity.width == expectedGranularity.width
401                 && imageGranularity.height == expectedGranularity.height
402                 && imageGranularity.depth == expectedGranularity.depth)
403         {
404                 return tcu::TestStatus::pass("Passed");
405         }
406         else
407         {
408                 return tcu::TestStatus::fail("Non-standard block shape used");
409         }
410 }
411
412 TestInstance* ImageBlockShapesCase::createInstance (Context& context) const
413 {
414         return new ImageBlockShapesInstance(context, m_imageType, m_imageSize, m_format, m_numSamples);
415 }
416
417 } // anonymous ns
418
419 tcu::TestCaseGroup* createImageBlockShapesTests (tcu::TestContext& testCtx)
420 {
421         de::MovePtr<tcu::TestCaseGroup> testGroup(new tcu::TestCaseGroup(testCtx, "image_block_shapes", "Standard block shape"));
422
423         struct ImageParameters
424         {
425                 ImageType       imageType;
426                 tcu::UVec3      imageSize;
427         };
428
429         static const ImageParameters imageParametersArray[] =
430         {
431                 { IMAGE_TYPE_2D,                 tcu::UVec3(512u, 256u, 1u)             },
432                 { IMAGE_TYPE_2D_ARRAY,   tcu::UVec3(512u, 256u, 6u)             },
433                 { IMAGE_TYPE_CUBE,               tcu::UVec3(256u, 256u, 1u)             },
434                 { IMAGE_TYPE_CUBE_ARRAY, tcu::UVec3(256u, 256u, 6u)             },
435                 { IMAGE_TYPE_3D,                 tcu::UVec3(512u, 256u, 16u)    }
436         };
437
438         static const tcu::TextureFormat formats[] =
439         {
440                 tcu::TextureFormat(tcu::TextureFormat::R,        tcu::TextureFormat::SIGNED_INT32),
441                 tcu::TextureFormat(tcu::TextureFormat::R,        tcu::TextureFormat::SIGNED_INT16),
442                 tcu::TextureFormat(tcu::TextureFormat::R,        tcu::TextureFormat::SIGNED_INT8),
443                 tcu::TextureFormat(tcu::TextureFormat::RG,       tcu::TextureFormat::SIGNED_INT32),
444                 tcu::TextureFormat(tcu::TextureFormat::RG,   tcu::TextureFormat::SIGNED_INT16),
445                 tcu::TextureFormat(tcu::TextureFormat::RG,   tcu::TextureFormat::SIGNED_INT8),
446                 tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT32),
447                 tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT16),
448                 tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNSIGNED_INT8)
449         };
450
451         static const deUint32 sampleCounts[] = { 1u, 2u, 4u, 8u, 16u };
452
453         for (deInt32 imageTypeNdx = 0; imageTypeNdx < DE_LENGTH_OF_ARRAY(imageParametersArray); ++imageTypeNdx)
454         {
455                 const ImageType                                 imageType = imageParametersArray[imageTypeNdx].imageType;
456                 de::MovePtr<tcu::TestCaseGroup> imageTypeGroup(new tcu::TestCaseGroup(testCtx, getImageTypeName(imageType).c_str(), ""));
457
458                 for (deInt32 formatNdx = 0; formatNdx < DE_LENGTH_OF_ARRAY(formats); ++formatNdx)
459                 {
460                         const tcu::TextureFormat&               format = formats[formatNdx];
461                         de::MovePtr<tcu::TestCaseGroup> formatGroup(new tcu::TestCaseGroup(testCtx, getShaderImageFormatQualifier(format).c_str(), ""));
462
463                         for (deInt32 sampleCountNdx = 0; sampleCountNdx < DE_LENGTH_OF_ARRAY(sampleCounts); ++sampleCountNdx)
464                         {
465                                 const tcu::UVec3        imageSize       = imageParametersArray[imageTypeNdx].imageSize;
466                                 const deUint32          sampleCount     = sampleCounts[sampleCountNdx];
467                                 const std::string       name            = std::string("samples_") + de::toString(sampleCount);
468
469                                 formatGroup->addChild(new ImageBlockShapesCase(testCtx, name.c_str(), "", imageType, imageSize, format, sampleCount));
470                         }
471                         imageTypeGroup->addChild(formatGroup.release());
472                 }
473                 testGroup->addChild(imageTypeGroup.release());
474         }
475
476         return testGroup.release();
477 }
478
479 } // sparse
480 } // vkt