Merge vk-gl-cts/vulkan-cts-1.0.1 into vk-gl-cts/vulkan-cts-1.0.2
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiImageClearingTests.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2016 The Khronos Group Inc.
6  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
22  * \brief Vulkan Image Clearing Tests
23  *//*--------------------------------------------------------------------*/
24
25 #include "vktApiImageClearingTests.hpp"
26
27 #include "deRandom.hpp"
28 #include "deMath.h"
29 #include "deStringUtil.hpp"
30 #include "deUniquePtr.hpp"
31 #include "deArrayUtil.hpp"
32 #include "deInt32.h"
33 #include "vkImageUtil.hpp"
34 #include "vkMemUtil.hpp"
35 #include "vktTestCase.hpp"
36 #include "vktTestCaseUtil.hpp"
37 #include "vkQueryUtil.hpp"
38 #include "vkRefUtil.hpp"
39 #include "vkTypeUtil.hpp"
40 #include "tcuImageCompare.hpp"
41 #include "tcuTexture.hpp"
42 #include "tcuTextureUtil.hpp"
43 #include "tcuVectorType.hpp"
44 #include "tcuTexture.hpp"
45 #include "tcuFloat.hpp"
46 #include "tcuTestLog.hpp"
47 #include "tcuVectorUtil.hpp"
48 #include <sstream>
49 #include <numeric>
50
51 namespace vkt
52 {
53
54 namespace api
55 {
56
57 using namespace vk;
58 using namespace tcu;
59
60 namespace
61 {
62
63 VkExtent3D getMipLevelExtent (VkExtent3D baseExtent, const deUint32 mipLevel)
64 {
65         baseExtent.width        = std::max(baseExtent.width  >> mipLevel, 1u);
66         baseExtent.height       = std::max(baseExtent.height >> mipLevel, 1u);
67         baseExtent.depth        = std::max(baseExtent.depth  >> mipLevel, 1u);
68         return baseExtent;
69 }
70
71 deUint32 getNumMipLevels (const VkExtent3D& baseExtent, const deUint32 maxMipLevels)
72 {
73         const deUint32 widestEdge = std::max(std::max(baseExtent.width, baseExtent.height), baseExtent.depth);
74         return std::min(static_cast<deUint32>(deFloatLog2(static_cast<float>(widestEdge))) + 1u, maxMipLevels);
75 }
76
77 deUint32 greatestCommonDivisor (const deUint32 a, const deUint32 b)
78 {
79         /* Find GCD */
80         deUint32 temp;
81         deUint32 x=a;
82         deUint32 y=b;
83
84         while (x%b != 0)
85         {
86                 temp = y;
87                 y = x%y;
88                 x = temp;
89         }
90         return y;
91 }
92
93 deUint32 lowestCommonMultiple (const deUint32 a, const deUint32 b)
94 {
95         return (a*b)/greatestCommonDivisor(a,b);
96 }
97
98 std::vector<deUint32> getImageMipLevelSizes (const deUint32 pixelSize, const VkExtent3D& baseExtent, const deUint32 numMipLevels, const deUint32 perLevelAlignment = 1u)
99 {
100         std::vector<deUint32> results(numMipLevels);
101
102         for (deUint32 mipLevel = 0; mipLevel < numMipLevels; ++mipLevel)
103         {
104                 const VkExtent3D extent = getMipLevelExtent(baseExtent, mipLevel);
105                 results[mipLevel] = static_cast<deUint32>(extent.width * extent.height * extent.depth * pixelSize);
106                 results[mipLevel] = ((results[mipLevel] + perLevelAlignment-1) / perLevelAlignment) * perLevelAlignment;
107         }
108
109         return results;
110 }
111
112 //! Check if a point lies in a cross-like area.
113 inline bool isInClearRange (const UVec4& clearCoords, const deUint32 x, const deUint32 y)
114 {
115         return !((x <  clearCoords[0] && y <  clearCoords[1]) ||
116                          (x <  clearCoords[0] && y >= clearCoords[3]) ||
117                          (x >= clearCoords[2] && y <  clearCoords[1]) ||
118                          (x >= clearCoords[2] && y >= clearCoords[3]));
119 }
120
121 // This method is copied from the vktRenderPassTests.cpp. It should be moved to a common place.
122 int calcFloatDiff (float a, float b)
123 {
124         const int                       asign   = Float32(a).sign();
125         const int                       bsign   = Float32(a).sign();
126
127         const deUint32          avalue  = (Float32(a).bits() & ((0x1u << 31u) - 1u));
128         const deUint32          bvalue  = (Float32(b).bits() & ((0x1u << 31u) - 1u));
129
130         if (asign != bsign)
131                 return avalue + bvalue + 1u;
132         else if (avalue < bvalue)
133                 return bvalue - avalue;
134         else
135                 return avalue - bvalue;
136 }
137
138 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
139 bool comparePixelToDepthClearValue (const ConstPixelBufferAccess&       access,
140                                                                         int                                                             x,
141                                                                         int                                                             y,
142                                                                         float                                                   ref,
143                                                                         std::string&                                    stringResult)
144 {
145         const TextureFormat                     format                  = getEffectiveDepthStencilTextureFormat(access.getFormat(), Sampler::MODE_DEPTH);
146         const TextureChannelClass       channelClass    = getTextureChannelClass(format.type);
147
148         switch (channelClass)
149         {
150                 case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
151                 case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
152                 {
153                         const int       bitDepth        = getTextureFormatBitDepth(format).x();
154                         const float     depth           = access.getPixDepth(x, y);
155                         const float     threshold       = 2.0f / (float)((1 << bitDepth) - 1);
156                         const bool      result          = deFloatAbs(depth - ref) <= threshold;
157
158                         if (!result)
159                         {
160                                 std::stringstream s;
161                                 s << "Ref:" << ref << " Threshold:" << threshold << " Depth:" << depth;
162                                 stringResult    = s.str();
163                         }
164
165                         return result;
166                 }
167
168                 case TEXTURECHANNELCLASS_FLOATING_POINT:
169                 {
170                         const float     depth                   = access.getPixDepth(x, y);
171                         const int       mantissaBits    = getTextureFormatMantissaBitDepth(format).x();
172                         const int       threshold               = 10 * 1 << (23 - mantissaBits);
173
174                         DE_ASSERT(mantissaBits <= 23);
175
176                         const bool      result                  = calcFloatDiff(depth, ref) <= threshold;
177
178                         if (!result)
179                         {
180                                 float                           floatThreshold  = Float32((deUint32)threshold).asFloat();
181                                 std::stringstream       s;
182
183                                 s << "Ref:" << ref << " Threshold:" << floatThreshold << " Depth:" << depth;
184                                 stringResult    = s.str();
185                         }
186
187                         return result;
188                 }
189
190                 default:
191                         DE_FATAL("Invalid channel class");
192                         return false;
193         }
194 }
195
196 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
197 bool comparePixelToStencilClearValue (const ConstPixelBufferAccess&     access,
198                                                                           int                                                   x,
199                                                                           int                                                   y,
200                                                                           deUint32                                              ref,
201                                                                           std::string&                                  stringResult)
202 {
203         const deUint32  stencil = access.getPixStencil(x, y);
204         const bool              result  = stencil == ref;
205
206         if (!result)
207         {
208                 std::stringstream s;
209                 s << "Ref:" << ref << " Threshold:0" << " Stencil:" << stencil;
210                 stringResult    = s.str();
211         }
212
213         return result;
214 }
215
216 // This method is copied from the vktRenderPassTests.cpp and extended with the stringResult parameter.
217 bool comparePixelToColorClearValue (const ConstPixelBufferAccess&       access,
218                                                                         int                                                             x,
219                                                                         int                                                             y,
220                                                                         int                                                             z,
221                                                                         const VkClearColorValue&                ref,
222                                                                         std::string&                                    stringResult)
223 {
224         const TextureFormat                             format                  = access.getFormat();
225         const TextureChannelClass               channelClass    = getTextureChannelClass(format.type);
226         const BVec4                                             channelMask             = getTextureFormatChannelMask(format);
227
228         switch (channelClass)
229         {
230                 case TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT:
231                 case TEXTURECHANNELCLASS_SIGNED_FIXED_POINT:
232                 {
233                         const IVec4     bitDepth        (getTextureFormatBitDepth(format));
234                         const Vec4      resColor        (access.getPixel(x, y, z));
235                         Vec4            refColor        (ref.float32[0],
236                                                                          ref.float32[1],
237                                                                          ref.float32[2],
238                                                                          ref.float32[3]);
239                         const int       modifier        = (channelClass == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT) ? 0 : 1;
240                         const Vec4      threshold       (bitDepth[0] > 0 ? 1.0f / ((float)(1 << (bitDepth[0] - modifier)) - 1.0f) : 1.0f,
241                                                                          bitDepth[1] > 0 ? 1.0f / ((float)(1 << (bitDepth[1] - modifier)) - 1.0f) : 1.0f,
242                                                                          bitDepth[2] > 0 ? 1.0f / ((float)(1 << (bitDepth[2] - modifier)) - 1.0f) : 1.0f,
243                                                                          bitDepth[3] > 0 ? 1.0f / ((float)(1 << (bitDepth[3] - modifier)) - 1.0f) : 1.0f);
244
245                         if (isSRGB(access.getFormat()))
246                                 refColor        = linearToSRGB(refColor);
247
248                         const bool      result          = !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
249
250                         if (!result)
251                         {
252                                 std::stringstream s;
253                                 s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
254                                 stringResult    = s.str();
255                         }
256
257                         return result;
258                 }
259
260                 case TEXTURECHANNELCLASS_UNSIGNED_INTEGER:
261                 {
262                         const UVec4     resColor        (access.getPixelUint(x, y, z));
263                         const UVec4     refColor        (ref.uint32[0],
264                                                                          ref.uint32[1],
265                                                                          ref.uint32[2],
266                                                                          ref.uint32[3]);
267                         const UVec4     threshold       (1);
268
269                         const bool      result          = !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
270
271                         if (!result)
272                         {
273                                 std::stringstream s;
274                                 s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
275                                 stringResult    = s.str();
276                         }
277
278                         return result;
279                 }
280
281                 case TEXTURECHANNELCLASS_SIGNED_INTEGER:
282                 {
283                         const IVec4     resColor        (access.getPixelInt(x, y, z));
284                         const IVec4     refColor        (ref.int32[0],
285                                                                          ref.int32[1],
286                                                                          ref.int32[2],
287                                                                          ref.int32[3]);
288                         const IVec4     threshold       (1);
289
290                         const bool      result          = !(anyNotEqual(logicalAnd(lessThanEqual(absDiff(resColor, refColor), threshold), channelMask), channelMask));
291
292                         if (!result)
293                         {
294                                 std::stringstream s;
295                                 s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << threshold << " Color:" << resColor;
296                                 stringResult    = s.str();
297                         }
298
299                         return result;
300                 }
301
302                 case TEXTURECHANNELCLASS_FLOATING_POINT:
303                 {
304                         const Vec4      resColor                (access.getPixel(x, y, z));
305                         const Vec4      refColor                (ref.float32[0],
306                                                                                  ref.float32[1],
307                                                                                  ref.float32[2],
308                                                                                  ref.float32[3]);
309                         const IVec4     mantissaBits    (getTextureFormatMantissaBitDepth(format));
310                         const IVec4     threshold               (10 * IVec4(1) << (23 - mantissaBits));
311
312                         DE_ASSERT(allEqual(greaterThanEqual(threshold, IVec4(0)), BVec4(true)));
313
314                         for (int ndx = 0; ndx < 4; ndx++)
315                         {
316                                 const bool result       = !(calcFloatDiff(resColor[ndx], refColor[ndx]) > threshold[ndx] && channelMask[ndx]);
317
318                                 if (!result)
319                                 {
320                                         float                           floatThreshold  = Float32((deUint32)(threshold)[0]).asFloat();
321                                         Vec4                            thresholdVec4   (floatThreshold,
322                                                                                                                  floatThreshold,
323                                                                                                                  floatThreshold,
324                                                                                                                  floatThreshold);
325                                         std::stringstream       s;
326                                         s << "Ref:" << refColor << " Mask:" << channelMask << " Threshold:" << thresholdVec4 << " Color:" << resColor;
327                                         stringResult    = s.str();
328
329                                         return false;
330                                 }
331                         }
332
333                         return true;
334                 }
335
336                 default:
337                         DE_FATAL("Invalid channel class");
338                         return false;
339         }
340 }
341
342 struct TestParams
343 {
344         bool                    useSingleMipLevel;      //!< only mip level 0, otherwise up to maxMipLevels
345         VkImageType             imageType;
346         VkFormat                imageFormat;
347         VkExtent3D              imageExtent;
348         VkClearValue    initValue;
349         VkClearValue    clearValue[2];          //!< the second value is used with more than one mip map
350 };
351
352 class ImageClearingTestInstance : public vkt::TestInstance
353 {
354 public:
355                                                                                 ImageClearingTestInstance               (Context&                       context,
356                                                                                                                                                  const TestParams&      testParams);
357
358         Move<VkCommandPool>                                     createCommandPool                               (VkCommandPoolCreateFlags commandPoolCreateFlags) const;
359         Move<VkCommandBuffer>                           allocatePrimaryCommandBuffer    (VkCommandPool commandPool) const;
360         Move<VkImage>                                           createImage                                             (VkImageType imageType, VkFormat format, VkExtent3D extent, VkImageUsageFlags usage) const;
361         Move<VkImageView>                                       createImageView                                 (VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask) const;
362         Move<VkRenderPass>                                      createRenderPass                                (VkFormat format) const;
363         Move<VkFramebuffer>                                     createFrameBuffer                               (VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight) const;
364
365         void                                                            beginCommandBuffer                              (VkCommandBufferUsageFlags usageFlags) const;
366         void                                                            endCommandBuffer                                (void) const;
367         void                                                            submitCommandBuffer                             (void) const;
368         void                                                            beginRenderPass                                 (VkSubpassContents content, VkClearValue clearValue) const;
369
370         void                                                            pipelineImageBarrier                    (VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout) const;
371         de::MovePtr<TextureLevelPyramid>        readImage                                               (VkImageAspectFlags aspectMask) const;
372         tcu::TestStatus                                         verifyResultImage                               (const std::string& successMessage, const UVec4& clearCoords = UVec4()) const;
373
374 protected:
375         VkImageViewType                                         getCorrespondingImageViewType   (VkImageType imageType) const;
376         VkImageUsageFlags                                       getImageUsageFlags                              (VkFormat format) const;
377         VkImageAspectFlags                                      getImageAspectFlags                             (VkFormat format) const;
378         bool                                                            getIsAttachmentFormat                   (VkFormat format) const;
379         bool                                                            getIsStencilFormat                              (VkFormat format) const;
380         bool                                                            getIsDepthFormat                                (VkFormat format) const;
381         VkImageFormatProperties                         getImageFormatProperties                (void) const;
382         de::MovePtr<Allocation>                         allocateAndBindImageMemory              (VkImage image) const;
383
384         const TestParams&                                       m_params;
385         const VkDevice                                          m_device;
386         const InstanceInterface&                        m_vki;
387         const DeviceInterface&                          m_vkd;
388         const VkQueue                                           m_queue;
389         const deUint32                                          m_queueFamilyIndex;
390         Allocator&                                                      m_allocator;
391
392         const bool                                                      m_isAttachmentFormat;
393         const VkImageUsageFlags                         m_imageUsageFlags;
394         const VkImageAspectFlags                        m_imageAspectFlags;
395         const VkImageFormatProperties           m_imageFormatProperties;
396         const deUint32                                          m_imageMipLevels;
397         const deUint32                                          m_thresholdMipLevel;
398
399         Unique<VkCommandPool>                           m_commandPool;
400         Unique<VkCommandBuffer>                         m_commandBuffer;
401
402         Unique<VkImage>                                         m_image;
403         de::MovePtr<Allocation>                         m_imageMemory;
404         Unique<VkImageView>                                     m_imageView;
405         Unique<VkRenderPass>                            m_renderPass;
406         Unique<VkFramebuffer>                           m_frameBuffer;
407 };
408
409 ImageClearingTestInstance::ImageClearingTestInstance (Context& context, const TestParams& params)
410         : TestInstance                          (context)
411         , m_params                                      (params)
412         , m_device                                      (context.getDevice())
413         , m_vki                                         (context.getInstanceInterface())
414         , m_vkd                                         (context.getDeviceInterface())
415         , m_queue                                       (context.getUniversalQueue())
416         , m_queueFamilyIndex            (context.getUniversalQueueFamilyIndex())
417         , m_allocator                           (context.getDefaultAllocator())
418         , m_isAttachmentFormat          (getIsAttachmentFormat(params.imageFormat))
419         , m_imageUsageFlags                     (getImageUsageFlags(params.imageFormat))
420         , m_imageAspectFlags            (getImageAspectFlags(params.imageFormat))
421         , m_imageFormatProperties       (getImageFormatProperties())
422         , m_imageMipLevels                      (params.useSingleMipLevel ? 1u : getNumMipLevels(params.imageExtent, m_imageFormatProperties.maxMipLevels))
423         , m_thresholdMipLevel           (std::max(m_imageMipLevels / 2u, 1u))
424         , m_commandPool                         (createCommandPool(VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT))
425         , m_commandBuffer                       (allocatePrimaryCommandBuffer(*m_commandPool))
426
427         , m_image                                       (createImage(params.imageType,
428                                                                                          params.imageFormat,
429                                                                                          params.imageExtent,
430                                                                                          m_imageUsageFlags))
431
432         , m_imageMemory                         (allocateAndBindImageMemory(*m_image))
433         , m_imageView                           (m_isAttachmentFormat ? createImageView(*m_image,
434                                                                                                  getCorrespondingImageViewType(params.imageType),
435                                                                                                  params.imageFormat,
436                                                                                                  m_imageAspectFlags) : vk::Move<VkImageView>())
437
438         , m_renderPass                          (m_isAttachmentFormat ? createRenderPass(params.imageFormat) : vk::Move<vk::VkRenderPass>())
439         , m_frameBuffer                         (m_isAttachmentFormat ? createFrameBuffer(*m_imageView, *m_renderPass, params.imageExtent.width, params.imageExtent.height) : vk::Move<vk::VkFramebuffer>())
440 {
441 }
442
443 VkImageViewType ImageClearingTestInstance::getCorrespondingImageViewType (VkImageType imageType) const
444 {
445         switch (imageType)
446         {
447                 case VK_IMAGE_TYPE_1D:
448                         return VK_IMAGE_VIEW_TYPE_1D;
449                 case VK_IMAGE_TYPE_2D:
450                         return VK_IMAGE_VIEW_TYPE_2D;
451                 case VK_IMAGE_TYPE_3D:
452                         return VK_IMAGE_VIEW_TYPE_3D;
453                 default:
454                         DE_FATAL("Unknown image type!");
455         }
456
457         return VK_IMAGE_VIEW_TYPE_2D;
458 }
459
460 VkImageUsageFlags ImageClearingTestInstance::getImageUsageFlags (VkFormat format) const
461 {
462         VkImageUsageFlags       commonFlags     = VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
463
464         if (m_isAttachmentFormat)
465         {
466                 if (isDepthStencilFormat(format))
467                         return commonFlags | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
468
469                 return commonFlags | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
470         }
471         return commonFlags;
472 }
473
474 VkImageAspectFlags ImageClearingTestInstance::getImageAspectFlags (VkFormat format) const
475 {
476         VkImageAspectFlags      imageAspectFlags        = 0;
477
478         if (getIsDepthFormat(format))
479                 imageAspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT;
480
481         if (getIsStencilFormat(format))
482                 imageAspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
483
484         if (imageAspectFlags == 0)
485                 imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
486
487         return imageAspectFlags;
488 }
489
490 bool ImageClearingTestInstance::getIsAttachmentFormat (VkFormat format) const
491 {
492         const VkFormatProperties props  = vk::getPhysicalDeviceFormatProperties(m_vki, m_context.getPhysicalDevice(), format);
493
494         return (props.optimalTilingFeatures & (vk::VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | vk::VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)) != 0;
495 }
496
497 bool ImageClearingTestInstance::getIsStencilFormat (VkFormat format) const
498 {
499         const TextureFormat tcuFormat   = mapVkFormat(format);
500
501         if (tcuFormat.order == TextureFormat::S || tcuFormat.order == TextureFormat::DS)
502                 return true;
503
504         return false;
505 }
506
507 bool ImageClearingTestInstance::getIsDepthFormat (VkFormat format) const
508 {
509         const TextureFormat     tcuFormat       = mapVkFormat(format);
510
511         if (tcuFormat.order == TextureFormat::D || tcuFormat.order == TextureFormat::DS)
512                 return true;
513
514         return false;
515 }
516
517 VkImageFormatProperties ImageClearingTestInstance::getImageFormatProperties (void) const
518 {
519         VkImageFormatProperties properties;
520         const VkResult result = m_vki.getPhysicalDeviceImageFormatProperties(m_context.getPhysicalDevice(), m_params.imageFormat, m_params.imageType,
521                                                                                                                                                  VK_IMAGE_TILING_OPTIMAL, m_imageUsageFlags, (VkImageCreateFlags)0, &properties);
522
523         if (result == VK_ERROR_FORMAT_NOT_SUPPORTED)
524                 TCU_THROW(NotSupportedError, "Format not supported");
525         else
526                 return properties;
527 }
528
529 de::MovePtr<Allocation> ImageClearingTestInstance::allocateAndBindImageMemory (VkImage image) const
530 {
531         de::MovePtr<Allocation> imageMemory     (m_allocator.allocate(getImageMemoryRequirements(m_vkd, m_device, image), MemoryRequirement::Any));
532         VK_CHECK(m_vkd.bindImageMemory(m_device, image, imageMemory->getMemory(), imageMemory->getOffset()));
533         return imageMemory;
534 }
535
536 Move<VkCommandPool> ImageClearingTestInstance::createCommandPool (VkCommandPoolCreateFlags commandPoolCreateFlags) const
537 {
538         const VkCommandPoolCreateInfo                   cmdPoolCreateInfo               =
539         {
540                 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,                                     // VkStructureType             sType;
541                 DE_NULL,                                                                                                        // const void*                 pNext;
542                 commandPoolCreateFlags,                                                                         // VkCommandPoolCreateFlags    flags;
543                 m_queueFamilyIndex                                                                                      // deUint32                    queueFamilyIndex;
544         };
545
546         return vk::createCommandPool(m_vkd, m_device, &cmdPoolCreateInfo, DE_NULL);
547 }
548
549 Move<VkCommandBuffer> ImageClearingTestInstance::allocatePrimaryCommandBuffer (VkCommandPool commandPool) const
550 {
551         const VkCommandBufferAllocateInfo               cmdBufferAllocateInfo   =
552         {
553                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,                         // VkStructureType             sType;
554                 DE_NULL,                                                                                                        // const void*                 pNext;
555                 commandPool,                                                                                            // VkCommandPool               commandPool;
556                 VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                                        // VkCommandBufferLevel        level;
557                 1                                                                                                                       // deUint32                    commandBufferCount;
558         };
559
560         return vk::allocateCommandBuffer(m_vkd, m_device, &cmdBufferAllocateInfo);
561 }
562
563 Move<VkImage> ImageClearingTestInstance::createImage (VkImageType imageType, VkFormat format, VkExtent3D extent, VkImageUsageFlags usage) const
564 {
565         const VkImageCreateInfo                                 imageCreateInfo                 =
566         {
567                 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,            // VkStructureType                      sType;
568                 DE_NULL,                                                                        // const void*                          pNext;
569                 0u,                                                                                     // VkImageCreateFlags           flags;
570                 imageType,                                                                      // VkImageType                          imageType;
571                 format,                                                                         // VkFormat                                     format;
572                 extent,                                                                         // VkExtent3D                           extent;
573                 m_imageMipLevels,                                                       // deUint32                                     mipLevels;
574                 1u,                                                                                     // deUint32                                     arrayLayers;
575                 VK_SAMPLE_COUNT_1_BIT,                                          // VkSampleCountFlagBits        samples;
576                 VK_IMAGE_TILING_OPTIMAL,                                        // VkImageTiling                        tiling;
577                 usage,                                                                          // VkImageUsageFlags            usage;
578                 VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                        sharingMode;
579                 1u,                                                                                     // deUint32                                     queueFamilyIndexCount;
580                 &m_queueFamilyIndex,                                            // const deUint32*                      pQueueFamilyIndices;
581                 VK_IMAGE_LAYOUT_UNDEFINED                                       // VkImageLayout                        initialLayout;
582         };
583
584         return vk::createImage(m_vkd, m_device, &imageCreateInfo, DE_NULL);
585 }
586
587 Move<VkImageView> ImageClearingTestInstance::createImageView (VkImage image, VkImageViewType viewType, VkFormat format, VkImageAspectFlags aspectMask) const
588 {
589         const VkImageViewCreateInfo                             imageViewCreateInfo             =
590         {
591                 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,       // VkStructureType                              sType;
592                 DE_NULL,                                                                        // const void*                                  pNext;
593                 0u,                                                                                     // VkImageViewCreateFlags               flags;
594                 image,                                                                          // VkImage                                              image;
595                 viewType,                                                                       // VkImageViewType                              viewType;
596                 format,                                                                         // VkFormat                                             format;
597                 {
598                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   r;
599                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   g;
600                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   b;
601                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   a;
602                 },                                                                                      // VkComponentMapping                   components;
603                 {
604                         aspectMask,                                                                     // VkImageAspectFlags                   aspectMask;
605                         0u,                                                                                     // deUint32                                             baseMipLevel;
606                         1u,                                                                                     // deUint32                                             mipLevels;
607                         0u,                                                                                     // deUint32                                             baseArrayLayer;
608                         1u,                                                                                     // deUint32                                             arraySize;
609                 },                                                                                      // VkImageSubresourceRange              subresourceRange;
610         };
611
612         return vk::createImageView(m_vkd, m_device, &imageViewCreateInfo, DE_NULL);
613 }
614
615 Move<VkRenderPass> ImageClearingTestInstance::createRenderPass (VkFormat format) const
616 {
617         VkImageLayout                                                   imageLayout;
618
619         if (isDepthStencilFormat(format))
620                 imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
621         else
622                 imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
623
624         const VkAttachmentDescription                   attachmentDesc                  =
625         {
626                 0u,                                                                                                     // VkAttachmentDescriptionFlags         flags;
627                 format,                                                                                         // VkFormat                                                     format;
628                 VK_SAMPLE_COUNT_1_BIT,                                                          // VkSampleCountFlagBits                        samples;
629                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           loadOp;
630                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          storeOp;
631                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           stencilLoadOp;
632                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          stencilStoreOp;
633                 imageLayout,                                                                            // VkImageLayout                                        initialLayout;
634                 imageLayout,                                                                            // VkImageLayout                                        finalLayout;
635         };
636
637         const VkAttachmentDescription                   attachments[1]                  =
638         {
639                 attachmentDesc
640         };
641
642         const VkAttachmentReference                             attachmentRef                   =
643         {
644                 0u,                                                                                                     // deUint32                                                     attachment;
645                 imageLayout,                                                                            // VkImageLayout                                        layout;
646         };
647
648         const VkAttachmentReference*                    pColorAttachments               = DE_NULL;
649         const VkAttachmentReference*                    pDepthStencilAttachment = DE_NULL;
650         deUint32                                                                colorAttachmentCount    = 1;
651
652         if (isDepthStencilFormat(format))
653         {
654                 colorAttachmentCount    = 0;
655                 pDepthStencilAttachment = &attachmentRef;
656         }
657         else
658         {
659                 colorAttachmentCount    = 1;
660                 pColorAttachments               = &attachmentRef;
661         }
662
663         const VkSubpassDescription                              subpassDesc[1]                  =
664         {
665                 {
666                         0u,                                                                                             // VkSubpassDescriptionFlags            flags;
667                         VK_PIPELINE_BIND_POINT_GRAPHICS,                                // VkPipelineBindPoint                          pipelineBindPoint;
668                         0u,                                                                                             // deUint32                                                     inputAttachmentCount;
669                         DE_NULL,                                                                                // const VkAttachmentReference*         pInputAttachments;
670                         colorAttachmentCount,                                                   // deUint32                                                     colorAttachmentCount;
671                         pColorAttachments,                                                              // const VkAttachmentReference*         pColorAttachments;
672                         DE_NULL,                                                                                // const VkAttachmentReference*         pResolveAttachments;
673                         pDepthStencilAttachment,                                                // const VkAttachmentReference*         pDepthStencilAttachment;
674                         0u,                                                                                             // deUint32                                                     preserveAttachmentCount;
675                         DE_NULL,                                                                                // const VkAttachmentReference*         pPreserveAttachments;
676                 }
677         };
678
679         const VkRenderPassCreateInfo                    renderPassCreateInfo    =
680         {
681                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,                      // VkStructureType                                      sType;
682                 DE_NULL,                                                                                        // const void*                                          pNext;
683                 0u,                                                                                                     // VkRenderPassCreateFlags                      flags;
684                 1u,                                                                                                     // deUint32                                                     attachmentCount;
685                 attachments,                                                                            // const VkAttachmentDescription*       pAttachments;
686                 1u,                                                                                                     // deUint32                                                     subpassCount;
687                 subpassDesc,                                                                            // const VkSubpassDescription*          pSubpasses;
688                 0u,                                                                                                     // deUint32                                                     dependencyCount;
689                 DE_NULL,                                                                                        // const VkSubpassDependency*           pDependencies;
690         };
691
692         return vk::createRenderPass(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
693 }
694
695 Move<VkFramebuffer> ImageClearingTestInstance::createFrameBuffer (VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight) const
696 {
697         const VkImageView                                               attachmentViews[1]              =
698         {
699                 imageView
700         };
701
702         const VkFramebufferCreateInfo                   framebufferCreateInfo   =
703         {
704                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,      // VkStructureType                      sType;
705                 DE_NULL,                                                                        // const void*                          pNext;
706                 0u,                                                                                     // VkFramebufferCreateFlags     flags;
707                 renderPass,                                                                     // VkRenderPass                         renderPass;
708                 1,                                                                                      // deUint32                                     attachmentCount;
709                 attachmentViews,                                                        // const VkImageView*           pAttachments;
710                 imageWidth,                                                                     // deUint32                                     width;
711                 imageHeight,                                                            // deUint32                                     height;
712                 1u,                                                                                     // deUint32                                     layers;
713         };
714
715         return createFramebuffer(m_vkd, m_device, &framebufferCreateInfo, DE_NULL);
716 }
717
718 void ImageClearingTestInstance::beginCommandBuffer (VkCommandBufferUsageFlags usageFlags) const
719 {
720         const VkCommandBufferBeginInfo                  commandBufferBeginInfo  =
721         {
722                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                          sType;
723                 DE_NULL,                                                                                                // const void*                              pNext;
724                 usageFlags,                                                                                             // VkCommandBufferUsageFlags                flags;
725                 DE_NULL                                                                                                 // const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
726         };
727
728         VK_CHECK(m_vkd.beginCommandBuffer(*m_commandBuffer, &commandBufferBeginInfo));
729 }
730
731 void ImageClearingTestInstance::endCommandBuffer (void) const
732 {
733         VK_CHECK(m_vkd.endCommandBuffer(*m_commandBuffer));
734 }
735
736 void ImageClearingTestInstance::submitCommandBuffer (void) const
737 {
738         const VkFenceCreateInfo fenceCreateInfo                                                 =
739         {
740                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,                                    // VkStructureType       sType;
741                 DE_NULL,                                                                                                // const void*           pNext;
742                 0u                                                                                                              // VkFenceCreateFlags    flags;
743         };
744
745         const Unique<VkFence>                                   fence                                   (createFence(m_vkd, m_device, &fenceCreateInfo));
746
747         const VkSubmitInfo                                              submitInfo                              =
748         {
749                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                  // VkStructureType                sType;
750                 DE_NULL,                                                                                                // const void*                    pNext;
751                 0u,                                                                                                             // deUint32                       waitSemaphoreCount;
752                 DE_NULL,                                                                                                // const VkSemaphore*             pWaitSemaphores;
753                 DE_NULL,                                                                                                // const VkPipelineStageFlags*    pWaitDstStageMask;
754                 1u,                                                                                                             // deUint32                       commandBufferCount;
755                 &(*m_commandBuffer),                                                                    // const VkCommandBuffer*         pCommandBuffers;
756                 0u,                                                                                                             // deUint32                       signalSemaphoreCount;
757                 DE_NULL                                                                                                 // const VkSemaphore*             pSignalSemaphores;
758         };
759
760         VK_CHECK(m_vkd.queueSubmit(m_queue, 1, &submitInfo, *fence));
761
762         VK_CHECK(m_vkd.waitForFences(m_device, 1, &fence.get(), VK_TRUE, ~0ull));
763 }
764
765 void ImageClearingTestInstance::pipelineImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout) const
766 {
767         const VkImageMemoryBarrier              imageBarrier    =
768         {
769                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
770                 DE_NULL,                                                                        // const void*                          pNext;
771                 srcAccessMask,                                                          // VkAccessFlags                        srcAccessMask;
772                 dstAccessMask,                                                          // VkAccessFlags                        dstAccessMask;
773                 oldLayout,                                                                      // VkImageLayout                        oldLayout;
774                 newLayout,                                                                      // VkImageLayout                        newLayout;
775                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
776                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     destQueueFamilyIndex;
777                 *m_image,                                                                       // VkImage                                      image;
778                 {
779                         m_imageAspectFlags,                                                     // VkImageAspectFlags   aspectMask;
780                         0u,                                                                                     // deUint32                             baseMipLevel;
781                         VK_REMAINING_MIP_LEVELS,                                        // deUint32                             levelCount;
782                         0u,                                                                                     // deUint32                             baseArrayLayer;
783                         1u,                                                                                     // deUint32                             layerCount;
784                 },                                                                                      // VkImageSubresourceRange      subresourceRange;
785         };
786
787         m_vkd.cmdPipelineBarrier(*m_commandBuffer, srcStageMask, dstStageMask, 0, 0, DE_NULL, 0, DE_NULL, 1, &imageBarrier);
788 }
789
790 de::MovePtr<TextureLevelPyramid> ImageClearingTestInstance::readImage (VkImageAspectFlags aspectMask) const
791 {
792         const TextureFormat                                     tcuFormat               = aspectMask == VK_IMAGE_ASPECT_COLOR_BIT ? mapVkFormat(m_params.imageFormat) :
793                                                                                                                   aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT ? getDepthCopyFormat(m_params.imageFormat) :
794                                                                                                                   aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT ? getStencilCopyFormat(m_params.imageFormat) :
795                                                                                                                   TextureFormat();
796         const deUint32                                          pixelSize               = getPixelSize(tcuFormat);
797         deUint32                                                        alignment               = 4;    // subsequent mip levels aligned to 4 bytes
798
799         if (!getIsDepthFormat(m_params.imageFormat) && !getIsStencilFormat(m_params.imageFormat))
800                 alignment = lowestCommonMultiple(pixelSize, alignment); // alignment must be multiple of pixel size, if not D/S.
801
802         const std::vector<deUint32>                     mipLevelSizes   = getImageMipLevelSizes(pixelSize, m_params.imageExtent, m_imageMipLevels, alignment);
803         const VkDeviceSize                                      imageTotalSize  = std::accumulate(mipLevelSizes.begin(), mipLevelSizes.end(), 0u);
804
805         de::MovePtr<TextureLevelPyramid>        result                  (new TextureLevelPyramid(tcuFormat, m_imageMipLevels));
806         Move<VkBuffer>                                          buffer;
807         de::MovePtr<Allocation>                         bufferAlloc;
808
809         // Create destination buffer
810         {
811                 const VkBufferCreateInfo        bufferParams    =
812                 {
813                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
814                         DE_NULL,                                                                        // const void*                  pNext;
815                         0u,                                                                                     // VkBufferCreateFlags  flags;
816                         imageTotalSize,                                                         // VkDeviceSize                 size;
817                         VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // VkBufferUsageFlags   usage;
818                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
819                         0u,                                                                                     // deUint32                             queueFamilyIndexCount;
820                         DE_NULL                                                                         // const deUint32*              pQueueFamilyIndices;
821                 };
822
823                 buffer          = createBuffer(m_vkd, m_device, &bufferParams);
824                 bufferAlloc     = m_allocator.allocate(getBufferMemoryRequirements(m_vkd, m_device, *buffer), MemoryRequirement::HostVisible);
825                 VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
826         }
827
828         // Barriers for copying image to buffer
829
830         const VkBufferMemoryBarrier             bufferBarrier   =
831         {
832                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
833                 DE_NULL,                                                                        // const void*          pNext;
834                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags        srcAccessMask;
835                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
836                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
837                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     dstQueueFamilyIndex;
838                 *buffer,                                                                        // VkBuffer                     buffer;
839                 0u,                                                                                     // VkDeviceSize         offset;
840                 imageTotalSize,                                                         // VkDeviceSize         size;
841         };
842
843         // Copy image to buffer
844         std::vector<VkBufferImageCopy> copyRegions;
845         {
846                 deUint32 offset = 0u;
847                 for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
848                 {
849                         const VkExtent3D                extent  = getMipLevelExtent(m_params.imageExtent, mipLevel);
850                         const VkBufferImageCopy region  =
851                         {
852                                 offset,                                                                 // VkDeviceSize                         bufferOffset;
853                                 0u,                                                                             // deUint32                                     bufferRowLength;
854                                 0u,                                                                             // deUint32                                     bufferImageHeight;
855                                 { aspectMask, mipLevel, 0u, 1u },               // VkImageSubresourceLayers     imageSubresource;
856                                 { 0, 0, 0 },                                                    // VkOffset3D                           imageOffset;
857                                 extent                                                                  // VkExtent3D                           imageExtent;
858                         };
859                         copyRegions.push_back(region);
860                         offset += mipLevelSizes[mipLevel];
861                 }
862         }
863
864         beginCommandBuffer(0);
865
866         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
867                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,
868                                                  VK_ACCESS_TRANSFER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
869                                                  VK_ACCESS_TRANSFER_READ_BIT,
870                                                  VK_IMAGE_LAYOUT_GENERAL,
871                                                  VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
872
873         m_vkd.cmdCopyImageToBuffer(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, static_cast<deUint32>(copyRegions.size()), &copyRegions[0]);
874         m_vkd.cmdPipelineBarrier(*m_commandBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
875
876         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
877                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,
878                                                  VK_ACCESS_TRANSFER_READ_BIT,
879                                                  VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
880                                                  VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
881                                                  VK_IMAGE_LAYOUT_GENERAL);
882
883         endCommandBuffer();
884         submitCommandBuffer();
885
886         invalidateMappedMemoryRange(m_vkd, m_device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), imageTotalSize);
887
888         {
889                 deUint32 offset = 0u;
890                 for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
891                 {
892                         const VkExtent3D        extent          = getMipLevelExtent(m_params.imageExtent, mipLevel);
893                         const void*                     pLevelData      = static_cast<const void*>(reinterpret_cast<deUint8*>(bufferAlloc->getHostPtr()) + offset);
894
895                         result->allocLevel(mipLevel, extent.width, extent.height, extent.depth);
896                         copy(result->getLevel(mipLevel), ConstPixelBufferAccess(result->getFormat(), result->getLevel(mipLevel).getSize(), pLevelData));
897
898                         offset += mipLevelSizes[mipLevel];
899                 }
900         }
901
902         return result;
903 }
904
905 tcu::TestStatus ImageClearingTestInstance::verifyResultImage (const std::string& successMessage, const UVec4& clearCoords) const
906 {
907         const bool useClearRange = clearCoords != UVec4();
908         DE_ASSERT(!useClearRange || m_params.imageExtent.depth == 1u);
909
910         if (getIsDepthFormat(m_params.imageFormat))
911         {
912                 DE_ASSERT(m_imageMipLevels == 1u);
913
914                 de::MovePtr<TextureLevelPyramid>        image                   = readImage(VK_IMAGE_ASPECT_DEPTH_BIT);
915                 std::string                                                     message;
916                 float                                                           depthValue;
917
918                 for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
919                 for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
920                 {
921                         if (!useClearRange || isInClearRange(clearCoords, x, y))
922                                 depthValue = m_params.clearValue[0].depthStencil.depth;
923                         else
924                                 depthValue = m_params.initValue.depthStencil.depth;
925
926                         if (!comparePixelToDepthClearValue(image->getLevel(0), x, y, depthValue, message))
927                                 return TestStatus::fail("Depth value mismatch! " + message);
928                 }
929         }
930
931         if (getIsStencilFormat(m_params.imageFormat))
932         {
933                 DE_ASSERT(m_imageMipLevels == 1u);
934
935                 de::MovePtr<TextureLevelPyramid>        image                   = readImage(VK_IMAGE_ASPECT_STENCIL_BIT);
936                 std::string                                                     message;
937                 deUint32                                                        stencilValue;
938
939                 for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
940                 for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
941                 {
942                         if (!useClearRange || isInClearRange(clearCoords, x, y))
943                                 stencilValue = m_params.clearValue[0].depthStencil.stencil;
944                         else
945                                 stencilValue = m_params.initValue.depthStencil.stencil;
946
947                         if (!comparePixelToStencilClearValue(image->getLevel(0), x, y, stencilValue, message))
948                                 return TestStatus::fail("Stencil value mismatch! " + message);
949                 }
950         }
951
952         if (!isDepthStencilFormat(m_params.imageFormat))
953         {
954                 de::MovePtr<TextureLevelPyramid>        image                   = readImage(VK_IMAGE_ASPECT_COLOR_BIT);
955                 std::string                                                     message;
956                 const VkClearColorValue*                        pColorValue;
957
958                 for (deUint32 mipLevel = 0; mipLevel < m_imageMipLevels; ++mipLevel)
959                 {
960                         const int                       clearColorNdx   = (mipLevel < m_thresholdMipLevel ? 0 : 1);
961                         const VkExtent3D        extent                  = getMipLevelExtent(m_params.imageExtent, mipLevel);
962
963                         for (deUint32 z = 0; z < extent.depth;  ++z)
964                         for (deUint32 y = 0; y < extent.height; ++y)
965                         for (deUint32 x = 0; x < extent.width;  ++x)
966                         {
967                                 if (!useClearRange || isInClearRange(clearCoords, x, y))
968                                         pColorValue = &m_params.clearValue[clearColorNdx].color;
969                                 else
970                                         pColorValue = &m_params.initValue.color;
971
972                                 if (!comparePixelToColorClearValue(image->getLevel(mipLevel), x, y, z, *pColorValue, message))
973                                         return TestStatus::fail("Color value mismatch! " + message);
974                         }
975                 }
976         }
977
978         return TestStatus::pass(successMessage);
979 }
980
981 void ImageClearingTestInstance::beginRenderPass (VkSubpassContents content, VkClearValue clearValue) const
982 {
983         const VkRenderPassBeginInfo renderPassBeginInfo =
984         {
985                 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                               // VkStructureType              sType;
986                 DE_NULL,                                                                                                // const void*                  pNext;
987                 *m_renderPass,                                                                                  // VkRenderPass                 renderPass;
988                 *m_frameBuffer,                                                                                 // VkFramebuffer                framebuffer;
989                 {
990                         { 0, 0 },                                                                                               // VkOffset2D                   offset;
991                         {
992                                 m_params.imageExtent.width,                                                             // deUint32                             width;
993                                 m_params.imageExtent.height                                                             // deUint32                             height;
994                         }                                                                                                               // VkExtent2D                   extent;
995                 },                                                                                                              // VkRect2D                             renderArea;
996                 1u,                                                                                                             // deUint32                             clearValueCount;
997                 &clearValue                                                                                             // const VkClearValue*  pClearValues;
998         };
999
1000         m_vkd.cmdBeginRenderPass(*m_commandBuffer, &renderPassBeginInfo, content);
1001 }
1002
1003 class ClearColorImageTestInstance : public ImageClearingTestInstance
1004 {
1005 public:
1006                                 ClearColorImageTestInstance     (Context& context, const TestParams& testParams) : ImageClearingTestInstance (context, testParams) {}
1007         TestStatus      iterate                                         (void);
1008 };
1009
1010 TestStatus ClearColorImageTestInstance::iterate (void)
1011 {
1012         std::vector<VkImageSubresourceRange> subresourceRanges;
1013
1014         if (m_imageMipLevels == 1)
1015                 subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags, 0u, 1u, 0u, 1u));
1016         else
1017         {
1018                 subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags,       0u,                                             m_thresholdMipLevel,            0u, 1u));
1019                 subresourceRanges.push_back(makeImageSubresourceRange(m_imageAspectFlags,       m_thresholdMipLevel,    VK_REMAINING_MIP_LEVELS,        0u, 1u));
1020         }
1021
1022         beginCommandBuffer(0);
1023
1024         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                         // VkPipelineStageFlags         srcStageMask
1025                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                    // VkPipelineStageFlags         dstStageMask
1026                                                  0,                                                                                             // VkAccessFlags                        srcAccessMask
1027                                                  (m_isAttachmentFormat
1028                                                         ? VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT
1029                                                         : VK_ACCESS_TRANSFER_WRITE_BIT),                        // VkAccessFlags                        dstAccessMask
1030                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                             // VkImageLayout                        oldLayout;
1031                                                  (m_isAttachmentFormat
1032                                                         ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
1033                                                         : VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL));       // VkImageLayout                        newLayout;
1034
1035         if (m_isAttachmentFormat)
1036         {
1037                 beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1038                 m_vkd.cmdEndRenderPass(*m_commandBuffer);
1039
1040                 pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                // VkPipelineStageFlags         srcStageMask
1041                         VK_PIPELINE_STAGE_TRANSFER_BIT,                                                         // VkPipelineStageFlags         dstStageMask
1042                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                                           // VkAccessFlags                        srcAccessMask
1043                         VK_ACCESS_TRANSFER_WRITE_BIT,                                                           // VkAccessFlags                        dstAccessMask
1044                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,                                       // VkImageLayout                        oldLayout;
1045                         VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);                                          // VkImageLayout                        newLayout;
1046         }
1047
1048         // Different clear color per range
1049         for (std::size_t i = 0u; i < subresourceRanges.size(); ++i)
1050                 m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[i].color, 1, &subresourceRanges[i]);
1051
1052         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,                            // VkPipelineStageFlags         srcStageMask
1053                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                // VkPipelineStageFlags         dstStageMask
1054                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                  // VkAccessFlags                        srcAccessMask
1055                                                  VK_ACCESS_TRANSFER_READ_BIT,                                   // VkAccessFlags                        dstAccessMask
1056                                                  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                  // VkImageLayout                        oldLayout;
1057                                                  VK_IMAGE_LAYOUT_GENERAL);                                              // VkImageLayout                        newLayout;
1058
1059         endCommandBuffer();
1060         submitCommandBuffer();
1061
1062         return verifyResultImage("cmdClearColorImage passed");
1063 }
1064
1065 class ClearDepthStencilImageTestInstance : public ImageClearingTestInstance
1066 {
1067 public:
1068                                 ClearDepthStencilImageTestInstance      (Context& context, const TestParams& testParams) : ImageClearingTestInstance (context, testParams) {}
1069         TestStatus      iterate                                                         (void);
1070 };
1071
1072 TestStatus ClearDepthStencilImageTestInstance::iterate (void)
1073 {
1074         const VkImageSubresourceRange subresourceRange = makeImageSubresourceRange(m_imageAspectFlags, 0u, 1u, 0u, 1u);
1075
1076         beginCommandBuffer(0);
1077
1078         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                                 // VkPipelineStageFlags         srcStageMask
1079                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                            // VkPipelineStageFlags         dstStageMask
1080                                                  0,                                                                                                     // VkAccessFlags                        srcAccessMask
1081                                                  (m_isAttachmentFormat
1082                                                         ?       VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT
1083                                                         :       VK_ACCESS_TRANSFER_WRITE_BIT),                          // VkAccessFlags                        dstAccessMask
1084                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                                     // VkImageLayout                        oldLayout;
1085                                                  (m_isAttachmentFormat
1086                                                         ?       VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL
1087                                                         :       VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL));         // VkImageLayout                        newLayout;
1088
1089         if (m_isAttachmentFormat)
1090         {
1091                 beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1092                 m_vkd.cmdEndRenderPass(*m_commandBuffer);
1093
1094                 pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                                        // VkPipelineStageFlags         srcStageMask
1095                                                          VK_PIPELINE_STAGE_TRANSFER_BIT,                                                // VkPipelineStageFlags         dstStageMask
1096                                                          VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,                  // VkAccessFlags                        srcAccessMask
1097                                                          VK_ACCESS_TRANSFER_WRITE_BIT,                                                  // VkAccessFlags                        dstAccessMask
1098                                                          VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,              // VkImageLayout                        oldLayout;
1099                                                          VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);                                 // VkImageLayout                        newLayout;
1100         }
1101
1102         m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue[0].depthStencil, 1, &subresourceRange);
1103
1104         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,                                    // VkPipelineStageFlags         srcStageMask
1105                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                        // VkPipelineStageFlags         dstStageMask
1106                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                          // VkAccessFlags                        srcAccessMask
1107                                                  VK_ACCESS_TRANSFER_READ_BIT,                                           // VkAccessFlags                        dstAccessMask
1108                                                  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                          // VkImageLayout                        oldLayout;
1109                                                  VK_IMAGE_LAYOUT_GENERAL);                                                      // VkImageLayout                        newLayout;
1110
1111         endCommandBuffer();
1112         submitCommandBuffer();
1113
1114         return verifyResultImage("cmdClearDepthStencilImage passed");
1115 }
1116
1117 class ClearAttachmentTestInstance : public ImageClearingTestInstance
1118 {
1119 public:
1120         enum ClearType
1121         {
1122                 FULL_CLEAR,
1123                 PARTIAL_CLEAR,
1124         };
1125
1126         ClearAttachmentTestInstance (Context& context, const TestParams& testParams, const ClearType clearType = FULL_CLEAR)
1127                 : ImageClearingTestInstance     (context, testParams)
1128                 , m_clearType                           (clearType)
1129         {
1130                 if (!m_isAttachmentFormat)
1131                         TCU_THROW(NotSupportedError, "Format not renderable");
1132         }
1133
1134         TestStatus iterate (void)
1135         {
1136                 const VkClearAttachment clearAttachment =
1137                 {
1138                         m_imageAspectFlags,                                     // VkImageAspectFlags   aspectMask;
1139                         0u,                                                                     // deUint32                             colorAttachment;
1140                         m_params.clearValue[0]                          // VkClearValue                 clearValue;
1141                 };
1142
1143                 UVec4                                           clearCoords;
1144                 std::vector<VkClearRect>        clearRects;
1145
1146                 if (m_clearType == FULL_CLEAR)
1147                 {
1148                         const VkClearRect rect =
1149                         {
1150                                 {
1151                                         { 0, 0 },                                                                                                                                       // VkOffset2D    offset;
1152                                         { m_params.imageExtent.width, m_params.imageExtent.height }                                     // VkExtent2D    extent;
1153                                 },                                                                                                                                                      // VkRect2D     rect;
1154                                 0u,                                                                                                                                                     // deUint32     baseArrayLayer;
1155                                 1u                                                                                                                                                      // deUint32     layerCount;
1156                         };
1157
1158                         clearRects.push_back(rect);
1159                 }
1160                 else
1161                 {
1162                         const deUint32  clearX          = m_params.imageExtent.width  / 4u;
1163                         const deUint32  clearY          = m_params.imageExtent.height / 4u;
1164                         const deUint32  clearWidth      = m_params.imageExtent.width  / 2u;
1165                         const deUint32  clearHeight     = m_params.imageExtent.height / 2u;
1166
1167                         clearCoords     = UVec4(clearX,                                 clearY,
1168                                                                 clearX + clearWidth,    clearY + clearHeight);
1169
1170                         const VkClearRect rects[2] =
1171                         {
1172                                 {
1173                                         {
1174                                                 { 0,                                                    static_cast<deInt32>(clearY)    },              // VkOffset2D    offset;
1175                                                 { m_params.imageExtent.width,   clearHeight                                             }               // VkExtent2D    extent;
1176                                         },                                                                                                                                              // VkRect2D     rect;
1177                                         0u,                                                                                                                                             // deUint32     baseArrayLayer;
1178                                         1u                                                                                                                                              // deUint32     layerCount;
1179                                 },
1180                                 {
1181                                         {
1182                                                 { static_cast<deInt32>(clearX), 0                                                       },                      // VkOffset2D    offset;
1183                                                 { clearWidth,                                   m_params.imageExtent.height     }                       // VkExtent2D    extent;
1184                                         },                                                                                                                                              // VkRect2D     rect;
1185                                         0u,                                                                                                                                             // deUint32     baseArrayLayer;
1186                                         1u                                                                                                                                              // deUint32     layerCount;
1187                                 }
1188                         };
1189
1190                         clearRects.push_back(rects[0]);
1191                         clearRects.push_back(rects[1]);
1192                 }
1193
1194                 const bool                      isDepthStencil          = isDepthStencilFormat(m_params.imageFormat);
1195                 const VkAccessFlags     accessMask                      = (isDepthStencil ? VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT     : VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT);
1196                 const VkImageLayout     attachmentLayout        = (isDepthStencil ? VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL : VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
1197
1198                 beginCommandBuffer(0);
1199
1200                 pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                         // VkPipelineStageFlags         srcStageMask
1201                                                          VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                    // VkPipelineStageFlags         dstStageMask
1202                                                          0,                                                                                             // VkAccessFlags                        srcAccessMask
1203                                                          accessMask,                                                                    // VkAccessFlags                        dstAccessMask
1204                                                          VK_IMAGE_LAYOUT_UNDEFINED,                                             // VkImageLayout                        oldLayout;
1205                                                          attachmentLayout);                                                             // VkImageLayout                        newLayout;
1206
1207                 beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1208                 m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, static_cast<deUint32>(clearRects.size()), &clearRects[0]);
1209                 m_vkd.cmdEndRenderPass(*m_commandBuffer);
1210
1211                 pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                        // VkPipelineStageFlags         srcStageMask
1212                                                          VK_PIPELINE_STAGE_TRANSFER_BIT,                                // VkPipelineStageFlags         dstStageMask
1213                                                          accessMask,                                                                    // VkAccessFlags                        srcAccessMask
1214                                                          VK_ACCESS_TRANSFER_READ_BIT,                                   // VkAccessFlags                        dstAccessMask
1215                                                          attachmentLayout,                                                              // VkImageLayout                        oldLayout;
1216                                                          VK_IMAGE_LAYOUT_GENERAL);                                              // VkImageLayout                        newLayout;
1217
1218                 endCommandBuffer();
1219                 submitCommandBuffer();
1220
1221                 return verifyResultImage("cmdClearAttachments passed", clearCoords);
1222         }
1223
1224 private:
1225         const ClearType m_clearType;
1226 };
1227
1228 class PartialClearAttachmentTestInstance : public ClearAttachmentTestInstance
1229 {
1230 public:
1231         PartialClearAttachmentTestInstance (Context& context, const TestParams& testParams) : ClearAttachmentTestInstance (context, testParams, PARTIAL_CLEAR) {}
1232 };
1233
1234 VkClearValue makeClearColorValue (VkFormat format, float r, float g, float b, float a)
1235 {
1236         const   TextureFormat tcuFormat = mapVkFormat(format);
1237         VkClearValue clearValue;
1238
1239         if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_FLOATING_POINT
1240                 || getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_FIXED_POINT
1241                 || getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT)
1242         {
1243                 clearValue.color.float32[0] = r;
1244                 clearValue.color.float32[1] = g;
1245                 clearValue.color.float32[2] = b;
1246                 clearValue.color.float32[3] = a;
1247         }
1248         else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
1249         {
1250                 UVec4 maxValues = getFormatMaxUintValue(tcuFormat);
1251
1252                 clearValue.color.uint32[0] = (deUint32)((float)maxValues[0] * r);
1253                 clearValue.color.uint32[1] = (deUint32)((float)maxValues[1] * g);
1254                 clearValue.color.uint32[2] = (deUint32)((float)maxValues[2] * b);
1255                 clearValue.color.uint32[3] = (deUint32)((float)maxValues[3] * a);
1256         }
1257         else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_INTEGER)
1258         {
1259                 IVec4 maxValues = getFormatMaxIntValue(tcuFormat);
1260
1261                 clearValue.color.int32[0] = (deUint32)((float)maxValues[0] * r);
1262                 clearValue.color.int32[1] = (deUint32)((float)maxValues[1] * g);
1263                 clearValue.color.int32[2] = (deUint32)((float)maxValues[2] * b);
1264                 clearValue.color.int32[3] = (deUint32)((float)maxValues[3] * a);
1265         }
1266         else
1267                 DE_FATAL("Unknown channel class");
1268
1269         return clearValue;
1270 }
1271
1272 std::string getFormatCaseName (VkFormat format)
1273 {
1274         return de::toLower(de::toString(getFormatStr(format)).substr(10));
1275 }
1276
1277 const char* getImageTypeCaseName (VkImageType type)
1278 {
1279         const char* s_names[] =
1280         {
1281                 "1d",
1282                 "2d",
1283                 "3d"
1284         };
1285         return de::getSizedArrayElement<VK_IMAGE_TYPE_LAST>(s_names, type);
1286 }
1287
1288 } // anonymous
1289
1290 TestCaseGroup* createImageClearingTests (TestContext& testCtx)
1291 {
1292         // Main testgroup.
1293         de::MovePtr<TestCaseGroup>      imageClearingTests                                              (new TestCaseGroup(testCtx, "image_clearing", "Image Clearing Tests"));
1294
1295         de::MovePtr<TestCaseGroup>      colorImageClearTests                                    (new TestCaseGroup(testCtx, "clear_color_image", "Color Image Clear Tests"));
1296         de::MovePtr<TestCaseGroup>      depthStencilImageClearTests                             (new TestCaseGroup(testCtx, "clear_depth_stencil_image", "Color Depth/Stencil Image Tests"));
1297         de::MovePtr<TestCaseGroup>      colorAttachmentClearTests                               (new TestCaseGroup(testCtx, "clear_color_attachment", "Color Color Attachment Tests"));
1298         de::MovePtr<TestCaseGroup>      depthStencilAttachmentClearTests                (new TestCaseGroup(testCtx, "clear_depth_stencil_attachment", "Color Depth/Stencil Attachment Tests"));
1299         de::MovePtr<TestCaseGroup>      partialColorAttachmentClearTests                (new TestCaseGroup(testCtx, "partial_clear_color_attachment", "Clear Partial Color Attachment Tests"));
1300         de::MovePtr<TestCaseGroup>      partialDepthStencilAttachmentClearTests (new TestCaseGroup(testCtx, "partial_clear_depth_stencil_attachment", "Clear Partial Depth/Stencil Attachment Tests"));
1301
1302         // Some formats are commented out due to the tcu::TextureFormat does not support them yet.
1303         const VkFormat          colorImageFormatsToTest[]       =
1304         {
1305                 VK_FORMAT_R4G4_UNORM_PACK8,
1306                 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
1307                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1308                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1309                 VK_FORMAT_B5G6R5_UNORM_PACK16,
1310                 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
1311                 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
1312                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1313                 VK_FORMAT_R8_UNORM,
1314                 VK_FORMAT_R8_SNORM,
1315                 VK_FORMAT_R8_USCALED,
1316                 VK_FORMAT_R8_SSCALED,
1317                 VK_FORMAT_R8_UINT,
1318                 VK_FORMAT_R8_SINT,
1319                 VK_FORMAT_R8_SRGB,
1320                 VK_FORMAT_R8G8_UNORM,
1321                 VK_FORMAT_R8G8_SNORM,
1322                 VK_FORMAT_R8G8_USCALED,
1323                 VK_FORMAT_R8G8_SSCALED,
1324                 VK_FORMAT_R8G8_UINT,
1325                 VK_FORMAT_R8G8_SINT,
1326                 VK_FORMAT_R8G8_SRGB,
1327                 VK_FORMAT_R8G8B8_UNORM,
1328                 VK_FORMAT_R8G8B8_SNORM,
1329                 VK_FORMAT_R8G8B8_USCALED,
1330                 VK_FORMAT_R8G8B8_SSCALED,
1331                 VK_FORMAT_R8G8B8_UINT,
1332                 VK_FORMAT_R8G8B8_SINT,
1333                 VK_FORMAT_R8G8B8_SRGB,
1334                 VK_FORMAT_B8G8R8_UNORM,
1335                 VK_FORMAT_B8G8R8_SNORM,
1336                 VK_FORMAT_B8G8R8_USCALED,
1337                 VK_FORMAT_B8G8R8_SSCALED,
1338                 VK_FORMAT_B8G8R8_UINT,
1339                 VK_FORMAT_B8G8R8_SINT,
1340                 VK_FORMAT_B8G8R8_SRGB,
1341                 VK_FORMAT_R8G8B8A8_UNORM,
1342                 VK_FORMAT_R8G8B8A8_SNORM,
1343                 VK_FORMAT_R8G8B8A8_USCALED,
1344                 VK_FORMAT_R8G8B8A8_SSCALED,
1345                 VK_FORMAT_R8G8B8A8_UINT,
1346                 VK_FORMAT_R8G8B8A8_SINT,
1347                 VK_FORMAT_R8G8B8A8_SRGB,
1348                 VK_FORMAT_B8G8R8A8_UNORM,
1349                 VK_FORMAT_B8G8R8A8_SNORM,
1350                 VK_FORMAT_B8G8R8A8_USCALED,
1351                 VK_FORMAT_B8G8R8A8_SSCALED,
1352                 VK_FORMAT_B8G8R8A8_UINT,
1353                 VK_FORMAT_B8G8R8A8_SINT,
1354                 VK_FORMAT_B8G8R8A8_SRGB,
1355                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1356                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1357                 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
1358                 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
1359                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1360                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1361                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1362                 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
1363                 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
1364                 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
1365                 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
1366                 VK_FORMAT_A2R10G10B10_UINT_PACK32,
1367                 VK_FORMAT_A2R10G10B10_SINT_PACK32,
1368                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1369                 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
1370                 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
1371                 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
1372                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1373                 VK_FORMAT_A2B10G10R10_SINT_PACK32,
1374                 VK_FORMAT_R16_UNORM,
1375                 VK_FORMAT_R16_SNORM,
1376                 VK_FORMAT_R16_USCALED,
1377                 VK_FORMAT_R16_SSCALED,
1378                 VK_FORMAT_R16_UINT,
1379                 VK_FORMAT_R16_SINT,
1380                 VK_FORMAT_R16_SFLOAT,
1381                 VK_FORMAT_R16G16_UNORM,
1382                 VK_FORMAT_R16G16_SNORM,
1383                 VK_FORMAT_R16G16_USCALED,
1384                 VK_FORMAT_R16G16_SSCALED,
1385                 VK_FORMAT_R16G16_UINT,
1386                 VK_FORMAT_R16G16_SINT,
1387                 VK_FORMAT_R16G16_SFLOAT,
1388                 VK_FORMAT_R16G16B16_UNORM,
1389                 VK_FORMAT_R16G16B16_SNORM,
1390                 VK_FORMAT_R16G16B16_USCALED,
1391                 VK_FORMAT_R16G16B16_SSCALED,
1392                 VK_FORMAT_R16G16B16_UINT,
1393                 VK_FORMAT_R16G16B16_SINT,
1394                 VK_FORMAT_R16G16B16_SFLOAT,
1395                 VK_FORMAT_R16G16B16A16_UNORM,
1396                 VK_FORMAT_R16G16B16A16_SNORM,
1397                 VK_FORMAT_R16G16B16A16_USCALED,
1398                 VK_FORMAT_R16G16B16A16_SSCALED,
1399                 VK_FORMAT_R16G16B16A16_UINT,
1400                 VK_FORMAT_R16G16B16A16_SINT,
1401                 VK_FORMAT_R16G16B16A16_SFLOAT,
1402                 VK_FORMAT_R32_UINT,
1403                 VK_FORMAT_R32_SINT,
1404                 VK_FORMAT_R32_SFLOAT,
1405                 VK_FORMAT_R32G32_UINT,
1406                 VK_FORMAT_R32G32_SINT,
1407                 VK_FORMAT_R32G32_SFLOAT,
1408                 VK_FORMAT_R32G32B32_UINT,
1409                 VK_FORMAT_R32G32B32_SINT,
1410                 VK_FORMAT_R32G32B32_SFLOAT,
1411                 VK_FORMAT_R32G32B32A32_UINT,
1412                 VK_FORMAT_R32G32B32A32_SINT,
1413                 VK_FORMAT_R32G32B32A32_SFLOAT,
1414 //              VK_FORMAT_R64_UINT,
1415 //              VK_FORMAT_R64_SINT,
1416 //              VK_FORMAT_R64_SFLOAT,
1417 //              VK_FORMAT_R64G64_UINT,
1418 //              VK_FORMAT_R64G64_SINT,
1419 //              VK_FORMAT_R64G64_SFLOAT,
1420 //              VK_FORMAT_R64G64B64_UINT,
1421 //              VK_FORMAT_R64G64B64_SINT,
1422 //              VK_FORMAT_R64G64B64_SFLOAT,
1423 //              VK_FORMAT_R64G64B64A64_UINT,
1424 //              VK_FORMAT_R64G64B64A64_SINT,
1425 //              VK_FORMAT_R64G64B64A64_SFLOAT,
1426                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1427                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1428 //              VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1429 //              VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1430 //              VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1431 //              VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1432 //              VK_FORMAT_BC2_UNORM_BLOCK,
1433 //              VK_FORMAT_BC2_SRGB_BLOCK,
1434 //              VK_FORMAT_BC3_UNORM_BLOCK,
1435 //              VK_FORMAT_BC3_SRGB_BLOCK,
1436 //              VK_FORMAT_BC4_UNORM_BLOCK,
1437 //              VK_FORMAT_BC4_SNORM_BLOCK,
1438 //              VK_FORMAT_BC5_UNORM_BLOCK,
1439 //              VK_FORMAT_BC5_SNORM_BLOCK,
1440 //              VK_FORMAT_BC6H_UFLOAT_BLOCK,
1441 //              VK_FORMAT_BC6H_SFLOAT_BLOCK,
1442 //              VK_FORMAT_BC7_UNORM_BLOCK,
1443 //              VK_FORMAT_BC7_SRGB_BLOCK,
1444 //              VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
1445 //              VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
1446 //              VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
1447 //              VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
1448 //              VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
1449 //              VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
1450 //              VK_FORMAT_EAC_R11_UNORM_BLOCK,
1451 //              VK_FORMAT_EAC_R11_SNORM_BLOCK,
1452 //              VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
1453 //              VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
1454 //              VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
1455 //              VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
1456 //              VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
1457 //              VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
1458 //              VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
1459 //              VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
1460 //              VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
1461 //              VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
1462 //              VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
1463 //              VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
1464 //              VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
1465 //              VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
1466 //              VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
1467 //              VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
1468 //              VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
1469 //              VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
1470 //              VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
1471 //              VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
1472 //              VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
1473 //              VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
1474 //              VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
1475 //              VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
1476 //              VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
1477 //              VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
1478 //              VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
1479 //              VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
1480 //              VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
1481 //              VK_FORMAT_ASTC_12x12_SRGB_BLOCK
1482         };
1483         const size_t    numOfColorImageFormatsToTest                    = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
1484
1485         const VkFormat  depthStencilImageFormatsToTest[]                =
1486         {
1487                 VK_FORMAT_D16_UNORM,
1488                 VK_FORMAT_X8_D24_UNORM_PACK32,
1489                 VK_FORMAT_D32_SFLOAT,
1490                 VK_FORMAT_S8_UINT,
1491                 VK_FORMAT_D16_UNORM_S8_UINT,
1492                 VK_FORMAT_D24_UNORM_S8_UINT,
1493                 VK_FORMAT_D32_SFLOAT_S8_UINT
1494         };
1495         const size_t    numOfDepthStencilImageFormatsToTest             = DE_LENGTH_OF_ARRAY(depthStencilImageFormatsToTest);
1496
1497         // Clear color image
1498         {
1499                 const VkImageType                       imageTypesToTest[]              =
1500                 {
1501                         VK_IMAGE_TYPE_1D,
1502                         VK_IMAGE_TYPE_2D,
1503                         VK_IMAGE_TYPE_3D
1504                 };
1505                 const size_t                            numOfImageTypesToTest   = DE_LENGTH_OF_ARRAY(imageTypesToTest);
1506
1507                 const VkExtent3D                        imageDimensionsByType[] =
1508                 {
1509                         { 256, 1, 1},
1510                         { 256, 256, 1},
1511                         { 256, 256, 16}
1512                 };
1513
1514                 for (size_t     imageTypeIndex = 0; imageTypeIndex < numOfImageTypesToTest; ++imageTypeIndex)
1515                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
1516                 {
1517                         const VkFormat          format          = colorImageFormatsToTest[imageFormatIndex];
1518                         const TestParams        testParams      =
1519                         {
1520                                 false,                                                                                                          // bool                         useSingleMipLevel;
1521                                 imageTypesToTest[imageTypeIndex],                                                       // VkImageType          imageType;
1522                                 format,                                                                                                         // VkFormat                     imageFormat;
1523                                 imageDimensionsByType[imageTypeIndex],                                          // VkExtent3D           imageExtent;
1524                                 makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),            // VkClearValue         initValue;
1525                                 {
1526                                         makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),    // VkClearValue         clearValue[0];
1527                                         makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),    // VkClearValue         clearValue[1];
1528                                 }
1529                         };
1530
1531                         std::ostringstream      testCaseName;
1532                         testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(format);
1533
1534                         colorImageClearTests->addChild(new InstanceFactory1<ClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Image", testParams));
1535                 }
1536
1537                 imageClearingTests->addChild(colorImageClearTests.release());
1538         }
1539
1540         // Clear depth/stencil image
1541         {
1542                 TestParams testParams =
1543                 {
1544                         true,                                                                                   // bool                         useSingleMipLevel;
1545                         VK_IMAGE_TYPE_2D,                                                               // VkImageType          imageType;
1546                         VK_FORMAT_UNDEFINED,                                                    // VkFormat                     format;
1547                         { 256, 256, 1 },                                                                // VkExtent3D           extent;
1548                         makeClearValueDepthStencil(0.5f, 0x03),                 // VkClearValue         initValue
1549                         {
1550                                 makeClearValueDepthStencil(0.1f, 0x06),         // VkClearValue         clearValue[0];
1551                                 makeClearValueDepthStencil(0.3f, 0x04),         // VkClearValue         clearValue[1];
1552                         }
1553                 };
1554
1555                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
1556                 {
1557                         testParams.imageFormat = depthStencilImageFormatsToTest[imageFormatIndex];
1558
1559                         std::ostringstream      testCaseName;
1560                         testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(testParams.imageFormat);
1561
1562                         depthStencilImageClearTests->addChild(new InstanceFactory1<ClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Image", testParams));
1563                 }
1564
1565                 imageClearingTests->addChild(depthStencilImageClearTests.release());
1566         }
1567
1568         // Clear color attachment
1569         {
1570                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
1571                 {
1572                         const VkFormat          format          = colorImageFormatsToTest[imageFormatIndex];
1573                         const TestParams        testParams      =
1574                         {
1575                                 true,                                                                                                           // bool                         useSingleMipLevel;
1576                                 VK_IMAGE_TYPE_2D,                                                                                       // VkImageType          imageType;
1577                                 format,                                                                                                         // VkFormat                     format;
1578                                 { 256, 256, 1 },                                                                                        // VkExtent3D           extent;
1579                                 makeClearColorValue(format, 0.2f, 0.1f, 0.7f, 0.8f),            // VkClearValue         initValue
1580                                 {
1581                                         makeClearColorValue(format, 0.1f, 0.5f, 0.3f, 0.9f),    // VkClearValue         clearValue[0];
1582                                         makeClearColorValue(format, 0.3f, 0.6f, 0.2f, 0.7f),    // VkClearValue         clearValue[1];
1583                                 }
1584                         };
1585
1586                         std::ostringstream      testCaseName;
1587                         testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(format);
1588
1589                         colorAttachmentClearTests->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Attachment", testParams));
1590                         partialColorAttachmentClearTests->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Partial Clear Color Attachment", testParams));
1591                 }
1592
1593                 imageClearingTests->addChild(colorAttachmentClearTests.release());
1594                 imageClearingTests->addChild(partialColorAttachmentClearTests.release());
1595         }
1596
1597         // Clear depth/stencil attachment
1598         {
1599                 TestParams testParams =
1600                 {
1601                         true,                                                                                   // bool                         useSingleMipLevel;
1602                         VK_IMAGE_TYPE_2D,                                                               // VkImageType          imageType;
1603                         VK_FORMAT_UNDEFINED,                                                    // VkFormat                     format;
1604                         { 256, 256, 1 },                                                                // VkExtent3D           extent;
1605                         makeClearValueDepthStencil(0.5f, 0x03),                 // VkClearValue         initValue
1606                         {
1607                                 makeClearValueDepthStencil(0.1f, 0x06),         // VkClearValue         clearValue[0];
1608                                 makeClearValueDepthStencil(0.3f, 0x04),         // VkClearValue         clearValue[1];
1609                         }
1610                 };
1611
1612                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
1613                 {
1614                         testParams.imageFormat = depthStencilImageFormatsToTest[imageFormatIndex];
1615
1616                         std::ostringstream      testCaseName;
1617                         testCaseName << getImageTypeCaseName(testParams.imageType) << "_" << getFormatCaseName(testParams.imageFormat);
1618
1619                         depthStencilAttachmentClearTests->addChild(new InstanceFactory1<ClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Attachment", testParams));
1620                         partialDepthStencilAttachmentClearTests->addChild(new InstanceFactory1<PartialClearAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Parital Clear Depth/Stencil Attachment", testParams));
1621                 }
1622
1623                 imageClearingTests->addChild(depthStencilAttachmentClearTests.release());
1624                 imageClearingTests->addChild(partialDepthStencilAttachmentClearTests.release());
1625         }
1626
1627         return imageClearingTests.release();
1628 }
1629
1630 } // api
1631 } // vkt