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