b504f862b995a0710ad130995f9fd470eff8c9a9
[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                 {
518                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   r;
519                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   g;
520                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   b;
521                         VK_COMPONENT_SWIZZLE_IDENTITY,                          // VkComponentSwizzle                   a;
522                 },                                                                                      // VkComponentMapping                   components;
523                 {
524                         aspectMask,                                                                     // VkImageAspectFlags                   aspectMask;
525                         0u,                                                                                     // deUint32                                             baseMipLevel;
526                         1u,                                                                                     // deUint32                                             mipLevels;
527                         0u,                                                                                     // deUint32                                             baseArrayLayer;
528                         1u,                                                                                     // deUint32                                             arraySize;
529                 },                                                                                      // VkImageSubresourceRange              subresourceRange;
530         };
531
532         return vk::createImageView(m_vkd, m_device, &imageViewCreateInfo, DE_NULL);
533 }
534
535 Move<VkRenderPass> ImageClearingTestInstance::createRenderPass (VkFormat format) const
536 {
537         VkImageLayout                                                   imageLayout;
538
539         if (isDepthStencilFormat(format))
540                 imageLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
541         else
542                 imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
543
544         const VkAttachmentDescription                   attachmentDesc                  =
545         {
546                 0u,                                                                                                     // VkAttachmentDescriptionFlags         flags;
547                 format,                                                                                         // VkFormat                                                     format;
548                 VK_SAMPLE_COUNT_1_BIT,                                                          // VkSampleCountFlagBits                        samples;
549                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           loadOp;
550                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          storeOp;
551                 VK_ATTACHMENT_LOAD_OP_CLEAR,                                            // VkAttachmentLoadOp                           stencilLoadOp;
552                 VK_ATTACHMENT_STORE_OP_STORE,                                           // VkAttachmentStoreOp                          stencilStoreOp;
553                 imageLayout,                                                                            // VkImageLayout                                        initialLayout;
554                 imageLayout,                                                                            // VkImageLayout                                        finalLayout;
555         };
556
557         const VkAttachmentDescription                   attachments[1]                  =
558         {
559                 attachmentDesc
560         };
561
562         const VkAttachmentReference                             attachmentRef                   =
563         {
564                 0u,                                                                                                     // deUint32                                                     attachment;
565                 imageLayout,                                                                            // VkImageLayout                                        layout;
566         };
567
568         const VkAttachmentReference*                    pColorAttachments               = DE_NULL;
569         const VkAttachmentReference*                    pDepthStencilAttachment = DE_NULL;
570         deUint32                                                                colorAttachmentCount    = 1;
571
572         if (isDepthStencilFormat(format))
573         {
574                 colorAttachmentCount    = 0;
575                 pDepthStencilAttachment = &attachmentRef;
576         }
577         else
578         {
579                 colorAttachmentCount    = 1;
580                 pColorAttachments               = &attachmentRef;
581         }
582
583         const VkSubpassDescription                              subpassDesc[1]                  =
584         {
585                 {
586                         0u,                                                                                             // VkSubpassDescriptionFlags            flags;
587                         VK_PIPELINE_BIND_POINT_GRAPHICS,                                // VkPipelineBindPoint                          pipelineBindPoint;
588                         0u,                                                                                             // deUint32                                                     inputAttachmentCount;
589                         DE_NULL,                                                                                // const VkAttachmentReference*         pInputAttachments;
590                         colorAttachmentCount,                                                   // deUint32                                                     colorAttachmentCount;
591                         pColorAttachments,                                                              // const VkAttachmentReference*         pColorAttachments;
592                         DE_NULL,                                                                                // const VkAttachmentReference*         pResolveAttachments;
593                         pDepthStencilAttachment,                                                // const VkAttachmentReference*         pDepthStencilAttachment;
594                         0u,                                                                                             // deUint32                                                     preserveAttachmentCount;
595                         DE_NULL,                                                                                // const VkAttachmentReference*         pPreserveAttachments;
596                 }
597         };
598
599         const VkRenderPassCreateInfo                    renderPassCreateInfo    =
600         {
601                 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,                      // VkStructureType                                      sType;
602                 DE_NULL,                                                                                        // const void*                                          pNext;
603                 0u,                                                                                                     // VkRenderPassCreateFlags                      flags;
604                 1u,                                                                                                     // deUint32                                                     attachmentCount;
605                 attachments,                                                                            // const VkAttachmentDescription*       pAttachments;
606                 1u,                                                                                                     // deUint32                                                     subpassCount;
607                 subpassDesc,                                                                            // const VkSubpassDescription*          pSubpasses;
608                 0u,                                                                                                     // deUint32                                                     dependencyCount;
609                 DE_NULL,                                                                                        // const VkSubpassDependency*           pDependencies;
610         };
611
612         return vk::createRenderPass(m_vkd, m_device, &renderPassCreateInfo, DE_NULL);
613 }
614
615 Move<VkFramebuffer> ImageClearingTestInstance::createFrameBuffer (VkImageView imageView, VkRenderPass renderPass, deUint32 imageWidth, deUint32 imageHeight) const
616 {
617         const VkImageView                                               attachmentViews[1]              =
618         {
619                 imageView
620         };
621
622         const VkFramebufferCreateInfo                   framebufferCreateInfo   =
623         {
624                 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,      // VkStructureType                      sType;
625                 DE_NULL,                                                                        // const void*                          pNext;
626                 0u,                                                                                     // VkFramebufferCreateFlags     flags;
627                 renderPass,                                                                     // VkRenderPass                         renderPass;
628                 1,                                                                                      // deUint32                                     attachmentCount;
629                 attachmentViews,                                                        // const VkImageView*           pAttachments;
630                 imageWidth,                                                                     // deUint32                                     width;
631                 imageHeight,                                                            // deUint32                                     height;
632                 1u,                                                                                     // deUint32                                     layers;
633         };
634
635         return createFramebuffer(m_vkd, m_device, &framebufferCreateInfo, DE_NULL);
636 }
637
638 void ImageClearingTestInstance::beginCommandBuffer (VkCommandBufferUsageFlags usageFlags) const
639 {
640         const VkCommandBufferBeginInfo                  commandBufferBeginInfo  =
641         {
642                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                          sType;
643                 DE_NULL,                                                                                                // const void*                              pNext;
644                 usageFlags,                                                                                             // VkCommandBufferUsageFlags                flags;
645                 DE_NULL                                                                                                 // const VkCommandBufferInheritanceInfo*    pInheritanceInfo;
646         };
647
648         VK_CHECK(m_vkd.beginCommandBuffer(*m_commandBuffer, &commandBufferBeginInfo));
649 }
650
651 void ImageClearingTestInstance::endCommandBuffer (void) const
652 {
653         VK_CHECK(m_vkd.endCommandBuffer(*m_commandBuffer));
654 }
655
656 void ImageClearingTestInstance::submitCommandBuffer (void) const
657 {
658         const VkFenceCreateInfo fenceCreateInfo                                                 =
659         {
660                 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,                                    // VkStructureType       sType;
661                 DE_NULL,                                                                                                // const void*           pNext;
662                 0u                                                                                                              // VkFenceCreateFlags    flags;
663         };
664
665         const Unique<VkFence>                                   fence                                   (createFence(m_vkd, m_device, &fenceCreateInfo));
666
667         const VkSubmitInfo                                              submitInfo                              =
668         {
669                 VK_STRUCTURE_TYPE_SUBMIT_INFO,                                                  // VkStructureType                sType;
670                 DE_NULL,                                                                                                // const void*                    pNext;
671                 0u,                                                                                                             // deUint32                       waitSemaphoreCount;
672                 DE_NULL,                                                                                                // const VkSemaphore*             pWaitSemaphores;
673                 DE_NULL,                                                                                                // const VkPipelineStageFlags*    pWaitDstStageMask;
674                 1u,                                                                                                             // deUint32                       commandBufferCount;
675                 &(*m_commandBuffer),                                                                    // const VkCommandBuffer*         pCommandBuffers;
676                 0u,                                                                                                             // deUint32                       signalSemaphoreCount;
677                 DE_NULL                                                                                                 // const VkSemaphore*             pSignalSemaphores;
678         };
679
680         VK_CHECK(m_vkd.queueSubmit(m_queue, 1, &submitInfo, *fence));
681
682         VK_CHECK(m_vkd.waitForFences(m_device, 1, &fence.get(), VK_TRUE, ~0ull));
683 }
684
685
686 void ImageClearingTestInstance::pipelineImageBarrier(VkPipelineStageFlags srcStageMask, VkPipelineStageFlags dstStageMask, VkAccessFlags srcAccessMask, VkAccessFlags dstAccessMask, VkImageLayout oldLayout, VkImageLayout newLayout) const
687 {
688
689         const VkImageSubresourceRange   subResourcerange        =
690         {
691                 m_imageAspectFlags,                             // VkImageAspectFlags   aspectMask;
692                 0,                                                              // deUint32                             baseMipLevel;
693                 1,                                                              // deUint32                             levelCount;
694                 0,                                                              // deUint32                             baseArrayLayer;
695                 1                                                               // deUint32                             layerCount;
696         };
697
698         const VkImageMemoryBarrier              imageBarrier    =
699         {
700                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
701                 DE_NULL,                                                                        // const void*                          pNext;
702                 srcAccessMask,                                                          // VkAccessFlags                        srcAccessMask;
703                 dstAccessMask,                                                          // VkAccessFlags                        dstAccessMask;
704                 oldLayout,                                                                      // VkImageLayout                        oldLayout;
705                 newLayout,                                                                      // VkImageLayout                        newLayout;
706                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
707                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     destQueueFamilyIndex;
708                 *m_image,                                                                       // VkImage                                      image;
709                 subResourcerange                                                        // VkImageSubresourceRange      subresourceRange;
710         };
711
712         m_vkd.cmdPipelineBarrier(*m_commandBuffer, srcStageMask, dstStageMask, 0, 0, DE_NULL, 0, DE_NULL, 1, &imageBarrier);
713 }
714
715
716 de::MovePtr<TextureLevel> ImageClearingTestInstance::readImage (VkImageAspectFlags aspectMask) const
717 {
718         Move<VkBuffer>                                  buffer;
719         de::MovePtr<Allocation>                 bufferAlloc;
720
721         const TextureFormat                             tcuFormat               = aspectMask == VK_IMAGE_ASPECT_COLOR_BIT ? mapVkFormat(m_params.imageFormat) :
722                                                                                                           aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT ? getDepthCopyFormat(m_params.imageFormat) :
723                                                                                                           aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT ? getStencilCopyFormat(m_params.imageFormat) :
724                                                                                                           TextureFormat();
725
726         const VkDeviceSize                              pixelDataSize   = m_params.imageExtent.width * m_params.imageExtent.height * m_params.imageExtent.depth * tcuFormat.getPixelSize();
727         de::MovePtr<TextureLevel>               result                  (new TextureLevel(tcuFormat, m_params.imageExtent.width, m_params.imageExtent.height, m_params.imageExtent.depth));
728
729         // Create destination buffer
730         {
731                 const VkBufferCreateInfo        bufferParams    =
732                 {
733                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
734                         DE_NULL,                                                                        // const void*                  pNext;
735                         0u,                                                                                     // VkBufferCreateFlags  flags;
736                         pixelDataSize,                                                          // VkDeviceSize                 size;
737                         VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // VkBufferUsageFlags   usage;
738                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
739                         0u,                                                                                     // deUint32                             queueFamilyIndexCount;
740                         DE_NULL                                                                         // const deUint32*              pQueueFamilyIndices;
741                 };
742
743                 buffer          = createBuffer(m_vkd, m_device, &bufferParams);
744                 bufferAlloc     = m_allocator.allocate(getBufferMemoryRequirements(m_vkd, m_device, *buffer), MemoryRequirement::HostVisible);
745                 VK_CHECK(m_vkd.bindBufferMemory(m_device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
746         }
747
748         // Barriers for copying image to buffer
749
750         const VkBufferMemoryBarrier             bufferBarrier   =
751         {
752                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
753                 DE_NULL,                                                                        // const void*          pNext;
754                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags        srcAccessMask;
755                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
756                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
757                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     dstQueueFamilyIndex;
758                 *buffer,                                                                        // VkBuffer                     buffer;
759                 0u,                                                                                     // VkDeviceSize         offset;
760                 pixelDataSize                                                           // VkDeviceSize         size;
761         };
762
763         // Copy image to buffer
764
765         const VkBufferImageCopy                 copyRegion              =
766         {
767                 0u,                                                                                             // VkDeviceSize                         bufferOffset;
768                 m_params.imageExtent.width,                                             // deUint32                                     bufferRowLength;
769                 m_params.imageExtent.height,                                    // deUint32                                     bufferImageHeight;
770                 { aspectMask, 0u, 0u, 1u },                                             // VkImageSubresourceLayers     imageSubresource;
771                 { 0, 0, 0 },                                                                    // VkOffset3D                           imageOffset;
772                 m_params.imageExtent                                                    // VkExtent3D                           imageExtent;
773         };
774
775         beginCommandBuffer(0);
776
777         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
778                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,
779                                                  VK_ACCESS_TRANSFER_WRITE_BIT |
780                                                  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
781                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
782                                                  VK_ACCESS_TRANSFER_READ_BIT,
783                                                  VK_IMAGE_LAYOUT_GENERAL,
784                                                  VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
785
786         m_vkd.cmdCopyImageToBuffer(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, 1, &copyRegion);
787         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);
788
789         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,
790                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,
791
792                                                  VK_ACCESS_TRANSFER_READ_BIT |
793                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
794                                                  VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
795
796                                                  VK_ACCESS_TRANSFER_READ_BIT |
797                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT |
798                                                  VK_ACCESS_COLOR_ATTACHMENT_READ_BIT,
799                                                  VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
800                                                  VK_IMAGE_LAYOUT_GENERAL);
801
802         endCommandBuffer();
803
804         submitCommandBuffer();
805
806         invalidateMappedMemoryRange(m_vkd, m_device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), pixelDataSize);
807
808         copy(*result, ConstPixelBufferAccess(result->getFormat(), result->getSize(), bufferAlloc->getHostPtr()));
809
810         return result;
811 }
812
813 void ImageClearingTestInstance::beginRenderPass (VkSubpassContents content, VkClearValue clearValue) const
814 {
815         const VkRenderPassBeginInfo             renderPassBeginInfo             =
816         {
817                 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                               // VkStructureType              sType;
818                 DE_NULL,                                                                                                // const void*                  pNext;
819                 *m_renderPass,                                                                                  // VkRenderPass                 renderPass;
820                 *m_frameBuffer,                                                                                 // VkFramebuffer                framebuffer;
821                 {
822                         { 0, 0 },                                                                                               // VkOffset2D                   offset;
823                         {
824                                 m_params.imageExtent.width,                                                             // deUint32                             width;
825                                 m_params.imageExtent.height                                                             // deUint32                             height;
826                         }                                                                                                               // VkExtent2D                   extent;
827                 },                                                                                                              // VkRect2D                             renderArea;
828                 1u,                                                                                                             // deUint32                             clearValueCount;
829                 &clearValue                                                                                             // const VkClearValue*  pClearValues;
830         };
831
832         m_vkd.cmdBeginRenderPass(*m_commandBuffer, &renderPassBeginInfo, content);
833 }
834
835 class ClearColorImageTestInstance : public ImageClearingTestInstance
836 {
837 public:
838                                                                         ClearColorImageTestInstance             (Context&                       context,
839                                                                                                                                          const TestParams&      testParams)
840                                                                                 : ImageClearingTestInstance(context, testParams)
841                                                                         {}
842
843         virtual TestStatus                              iterate                                                 (void);
844 };
845
846 TestStatus ClearColorImageTestInstance::iterate (void)
847 {
848         const VkImageSubresourceRange   subResourcerange        =
849         {
850                 m_imageAspectFlags,                             // VkImageAspectFlags   aspectMask;
851                 0,                                                              // deUint32                             baseMipLevel;
852                 1,                                                              // deUint32                             levelCount;
853                 0,                                                              // deUint32                             baseArrayLayer;
854                 1                                                               // deUint32                             layerCount;
855         };
856
857         beginCommandBuffer(0);
858
859         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                         // VkPipelineStageFlags         srcStageMask
860                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                    // VkPipelineStageFlags         dstStageMask
861                                                  0,                                                                                             // VkAccessFlags                        srcAccessMask
862                                                  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                  // VkAccessFlags                        dstAccessMask
863                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                             // VkImageLayout                        oldLayout;
864                                                  VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);             // VkImageLayout                        newLayout;
865
866         beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
867         m_vkd.cmdEndRenderPass(*m_commandBuffer);
868
869         pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                        // VkPipelineStageFlags         srcStageMask
870                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                // VkPipelineStageFlags         dstStageMask
871                                                  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                  // VkAccessFlags                        srcAccessMask
872                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                  // VkAccessFlags                        dstAccessMask
873                                                  VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,              // VkImageLayout                        oldLayout;
874                                                  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);                 // VkImageLayout                        newLayout;
875
876         m_vkd.cmdClearColorImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue.color, 1, &subResourcerange);
877
878         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,                            // VkPipelineStageFlags         srcStageMask
879                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                // VkPipelineStageFlags         dstStageMask
880                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                  // VkAccessFlags                        srcAccessMask
881                                                  VK_ACCESS_TRANSFER_READ_BIT,                                   // VkAccessFlags                        dstAccessMask
882                                                  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                  // VkImageLayout                        oldLayout;
883                                                  VK_IMAGE_LAYOUT_GENERAL);                                              // VkImageLayout                        newLayout;
884
885         endCommandBuffer();
886         submitCommandBuffer();
887
888         de::MovePtr<TextureLevel>       result                                          = readImage(VK_IMAGE_ASPECT_COLOR_BIT);
889         std::string                                     compareResult;
890
891         for (deUint32 z = 0; z < m_params.imageExtent.depth; z++)
892         {
893                 for (deUint32 y = 0; y < m_params.imageExtent.height; y++)
894                 {
895                         for (deUint32 x = 0; x < m_params.imageExtent.width; x++)
896                         {
897                                 if (!comparePixelToColorClearValue(result->getAccess(), x, y, z, m_params.clearValue.color, compareResult))
898                                         return TestStatus::fail("Color value mismatch! " + compareResult);
899                         }
900                 }
901         }
902
903         return TestStatus::pass("cmdClearColorImage passed");
904 }
905
906 class ClearDepthStencilImageTestInstance : public ImageClearingTestInstance
907 {
908 public:
909                                                                         ClearDepthStencilImageTestInstance      (Context&                       context,
910                                                                                                                                                  const TestParams&      testParams)
911                                                                                 : ImageClearingTestInstance(context, testParams)
912                                                                         {}
913
914         virtual TestStatus                              iterate                                                         (void);
915 };
916
917 TestStatus ClearDepthStencilImageTestInstance::iterate (void)
918 {
919         const VkImageSubresourceRange   subResourcerange        =
920         {
921                 m_imageAspectFlags,                             // VkImageAspectFlags   aspectMask;
922                 0,                                                              // deUint32                             baseMipLevel;
923                 1,                                                              // deUint32                             levelCount;
924                 0,                                                              // deUint32                             baseArrayLayer;
925                 1                                                               // deUint32                             layerCount;
926         };
927
928         beginCommandBuffer(0);
929
930         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                                 // VkPipelineStageFlags         srcStageMask
931                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                            // VkPipelineStageFlags         dstStageMask
932                                                  0,                                                                                                     // VkAccessFlags                        srcAccessMask
933                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,          // VkAccessFlags                        dstAccessMask
934                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                                     // VkImageLayout                        oldLayout;
935                                                  VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);     // VkImageLayout                        newLayout;
936
937         beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
938         m_vkd.cmdEndRenderPass(*m_commandBuffer);
939
940         pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                                        // VkPipelineStageFlags         srcStageMask
941                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                                // VkPipelineStageFlags         dstStageMask
942                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,                  // VkAccessFlags                        srcAccessMask
943                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                                  // VkAccessFlags                        dstAccessMask
944                                                  VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,              // VkImageLayout                        oldLayout;
945                                                  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);                                 // VkImageLayout                        newLayout;
946
947         m_vkd.cmdClearDepthStencilImage(*m_commandBuffer, *m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &m_params.clearValue.depthStencil, 1, &subResourcerange);
948
949         pipelineImageBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT,                                    // VkPipelineStageFlags         srcStageMask
950                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                        // VkPipelineStageFlags         dstStageMask
951                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                          // VkAccessFlags                        srcAccessMask
952                                                  VK_ACCESS_TRANSFER_READ_BIT,                                           // VkAccessFlags                        dstAccessMask
953                                                  VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                          // VkImageLayout                        oldLayout;
954                                                  VK_IMAGE_LAYOUT_GENERAL);                                                      // VkImageLayout                        newLayout;
955
956         endCommandBuffer();
957         submitCommandBuffer();
958
959         de::MovePtr<TextureLevel>                                               depthResult;
960         de::MovePtr<TextureLevel>                                               stencilResult;
961         bool                                                                                    isDepthFormat           = getIsDepthFormat(m_params.imageFormat);
962         if (isDepthFormat)
963         {
964                 depthResult             = readImage(VK_IMAGE_ASPECT_DEPTH_BIT);
965         }
966         const bool                                                                              isStencilFormat         = getIsStencilFormat(m_params.imageFormat);
967
968         if (isStencilFormat)
969         {
970                 stencilResult   = readImage(VK_IMAGE_ASPECT_STENCIL_BIT);
971         }
972
973         std::string                                                                             compareResult;
974
975         for (deUint32 y = 0; y < m_params.imageExtent.height; ++y)
976         {
977                 for (deUint32 x = 0; x < m_params.imageExtent.width; ++x)
978                 {
979                         if (isDepthFormat && !comparePixelToDepthClearValue(depthResult->getAccess(), x, y, m_params.clearValue.depthStencil.depth, compareResult))
980                                 return TestStatus::fail("Depth value mismatch! " + compareResult);
981
982                         if (isStencilFormat && !comparePixelToStencilClearValue(stencilResult->getAccess(), x, y, m_params.clearValue.depthStencil.stencil, compareResult))
983                                 return TestStatus::fail("Stencil value mismatch! " + compareResult);
984                 }
985         }
986
987         return TestStatus::pass("cmdClearDepthStencilImage passed");
988 }
989
990 class ClearColorAttachmentTestInstance : public ImageClearingTestInstance
991 {
992 public:
993                                                                         ClearColorAttachmentTestInstance        (Context&                                       context,
994                                                                                                                                                  const TestParams&      testParams)
995                                                                                 : ImageClearingTestInstance(context, testParams)
996                                                                         {}
997
998         virtual TestStatus                              iterate                                                         (void);
999 };
1000
1001 TestStatus ClearColorAttachmentTestInstance::iterate (void)
1002 {
1003         const VkClearAttachment                 clearAttachment         =
1004         {
1005                 VK_IMAGE_ASPECT_COLOR_BIT,                                              // kImageAspectFlags    aspectMask;
1006                 0u,                                                                                             // deUint32                             colorAttachment;
1007                 m_params.clearValue                                                             // VkClearValue                 clearValue;
1008         };
1009
1010         const VkClearRect                               clearRect                       =
1011         {
1012                 {
1013                         { 0, 0 },
1014                         { m_params.imageExtent.width, m_params.imageExtent.height }
1015                 },                                                                                                                                      // VkRect2D     rect;
1016                 0u,                                                                                                                                     // deUint32     baseArrayLayer;
1017                 1u                                                                                                                                      // deUint32     layerCount;
1018         };
1019
1020         beginCommandBuffer(0);
1021
1022         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                         // VkPipelineStageFlags         srcStageMask
1023                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                    // VkPipelineStageFlags         dstStageMask
1024                                                  0,                                                                                             // VkAccessFlags                        srcAccessMask
1025                                                  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1026                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                  // VkAccessFlags                        dstAccessMask
1027                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                             // VkImageLayout                        oldLayout;
1028                                                  VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);             // VkImageLayout                        newLayout;
1029
1030         beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1031         m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, 1, &clearRect);
1032         m_vkd.cmdEndRenderPass(*m_commandBuffer);
1033
1034         pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                        // VkPipelineStageFlags         srcStageMask
1035                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                // VkPipelineStageFlags         dstStageMask
1036                                                  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1037                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                  // VkAccessFlags                        srcAccessMask
1038                                                  VK_ACCESS_TRANSFER_READ_BIT,                                   // VkAccessFlags                        dstAccessMask
1039                                                  VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,              // VkImageLayout                        oldLayout;
1040                                                  VK_IMAGE_LAYOUT_GENERAL);                                              // VkImageLayout                        newLayout;
1041
1042         endCommandBuffer();
1043         submitCommandBuffer();
1044
1045         de::MovePtr<TextureLevel>               result                                          = readImage(VK_IMAGE_ASPECT_COLOR_BIT);
1046         std::string                                             compareResult;
1047
1048         for (deUint32 y = 0; y < m_params.imageExtent.height; y++)
1049         {
1050                 for (deUint32 x = 0; x < m_params.imageExtent.width; x++)
1051                 {
1052                                 if (!comparePixelToColorClearValue(result->getAccess(), x, y, 0, m_params.clearValue.color, compareResult))
1053                                         return TestStatus::fail("Color value mismatch" + compareResult);
1054                 }
1055         }
1056
1057         return TestStatus::pass("cmdClearAttachments passed");
1058 }
1059
1060 class ClearDepthStencilAttachmentTestInstance : public ImageClearingTestInstance
1061 {
1062 public:
1063                                                                         ClearDepthStencilAttachmentTestInstance (Context&                               context,
1064                                                                                                                                                          const TestParams&              testParams)
1065                                                                                 : ImageClearingTestInstance(context, testParams)
1066                                                                         {}
1067
1068         virtual TestStatus                              iterate                                                                 (void);
1069 };
1070
1071 TestStatus ClearDepthStencilAttachmentTestInstance::iterate (void)
1072 {
1073         const VkClearAttachment                 clearAttachment         =
1074         {
1075                 VK_IMAGE_ASPECT_DEPTH_BIT |
1076                 VK_IMAGE_ASPECT_STENCIL_BIT,                                    // kImageAspectFlags    aspectMask;
1077                 0u,                                                                                             // deUint32                             colorAttachment;
1078                 m_params.clearValue                                                             // VkClearValue                 clearValue;
1079         };
1080
1081         const VkClearRect                               clearRect                       =
1082         {
1083                 {
1084                         { 0, 0 },
1085                         { m_params.imageExtent.width, m_params.imageExtent.height }
1086                 },                                                                                                                                      // VkRect2D     rect;
1087                 0u,                                                                                                                                     // deUint32     baseArrayLayer;
1088                 1u                                                                                                                                      // deUint32     layerCount;
1089         };
1090
1091         beginCommandBuffer(0);
1092
1093         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                                 // VkPipelineStageFlags         srcStageMask
1094                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                            // VkPipelineStageFlags         dstStageMask
1095                                                  0,                                                                                                     // VkAccessFlags                        srcAccessMask
1096                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1097                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                          // VkAccessFlags                        dstAccessMask
1098                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                                     // VkImageLayout                        oldLayout;
1099                                                  VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);     // VkImageLayout                        newLayout;
1100
1101         beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1102         m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, 1, &clearRect);
1103         m_vkd.cmdEndRenderPass(*m_commandBuffer);
1104
1105         pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                                // VkPipelineStageFlags         srcStageMask
1106                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                        // VkPipelineStageFlags         dstStageMask
1107                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1108                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                          // VkAccessFlags                        srcAccessMask
1109                                                  VK_ACCESS_TRANSFER_READ_BIT,                                           // VkAccessFlags                        dstAccessMask
1110                                                  VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,      // VkImageLayout                        oldLayout;
1111                                                  VK_IMAGE_LAYOUT_GENERAL);                                                      // VkImageLayout                        newLayout;
1112
1113         endCommandBuffer();
1114         submitCommandBuffer();
1115
1116         de::MovePtr<TextureLevel>                                               depthResult;
1117         de::MovePtr<TextureLevel>                                               stencilResult;
1118         bool                                                                                    isDepthFormat           = getIsDepthFormat(m_params.imageFormat);
1119         if (isDepthFormat)
1120         {
1121                 depthResult             = readImage(VK_IMAGE_ASPECT_DEPTH_BIT);
1122         }
1123         const bool                                                                              isStencilFormat         = getIsStencilFormat(m_params.imageFormat);
1124
1125         if (isStencilFormat)
1126         {
1127                 stencilResult   = readImage(VK_IMAGE_ASPECT_STENCIL_BIT);
1128         }
1129
1130
1131         std::string                                                                             compareResult;
1132
1133         for (deUint32 y = 0; y < m_params.imageExtent.height; y++)
1134         {
1135                 for (deUint32 x = 0; x < m_params.imageExtent.width; x++)
1136                 {
1137                         if (isDepthFormat && !comparePixelToDepthClearValue(depthResult->getAccess(), x, y, m_params.clearValue.depthStencil.depth, compareResult))
1138                                 return TestStatus::fail("Depth value mismatch! " + compareResult);
1139
1140                         if (isStencilFormat && !comparePixelToStencilClearValue(stencilResult->getAccess(), x, y, m_params.clearValue.depthStencil.stencil, compareResult))
1141                                 return TestStatus::fail("Stencil value mismatch! " + compareResult);
1142                 }
1143         }
1144
1145         return TestStatus::pass("cmdClearAttachments passed");
1146 }
1147
1148 class PartialClearColorAttachmentTestInstance : public ImageClearingTestInstance
1149 {
1150 public:
1151                                                                         PartialClearColorAttachmentTestInstance (Context&                               context,
1152                                                                                                                                                          const TestParams&              testParams)
1153                                                                                 : ImageClearingTestInstance(context, testParams)
1154                                                                         {}
1155
1156         virtual TestStatus                              iterate                                                                 (void);
1157 };
1158
1159 TestStatus PartialClearColorAttachmentTestInstance::iterate (void)
1160 {
1161         const VkClearAttachment                 clearAttachment         =
1162         {
1163                 VK_IMAGE_ASPECT_COLOR_BIT,                                              // kImageAspectFlags    aspectMask;
1164                 0u,                                                                                             // deUint32                             colorAttachment;
1165                 m_params.clearValue                                                             // VkClearValue                 clearValue;
1166         };
1167
1168         const VkClearRect                               clearRects[2]           =
1169         {
1170                 {
1171                         {
1172                                 { 0, (deInt32)(m_params.imageExtent.height / 4) },
1173                                 { m_params.imageExtent.width, m_params.imageExtent.height / 2}
1174                         },                                                                                                                                      // VkRect2D     rect;
1175                         0u,                                                                                                                                     // deUint32     baseArrayLayer;
1176                         1u                                                                                                                                      // deUint32     layerCount;
1177                 },
1178                 {
1179                         {
1180                                 { (deInt32)(m_params.imageExtent.width / 4), 0 },
1181                                 { m_params.imageExtent.width / 2, m_params.imageExtent.height}
1182                         },                                                                                                                                      // VkRect2D     rect;
1183                         0u,                                                                                                                                     // deUint32     baseArrayLayer;
1184                         1u                                                                                                                                      // deUint32     layerCount;
1185                 }
1186         };
1187
1188         beginCommandBuffer(0);
1189
1190         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                         // VkPipelineStageFlags         srcStageMask
1191                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                    // VkPipelineStageFlags         dstStageMask
1192                                                  0,                                                                                             // VkAccessFlags                        srcAccessMask
1193                                                  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,                  // VkAccessFlags                        dstAccessMask
1194                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                             // VkImageLayout                        oldLayout;
1195                                                  VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);             // VkImageLayout                        newLayout;
1196
1197         beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1198         m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, 2, clearRects);
1199         m_vkd.cmdEndRenderPass(*m_commandBuffer);
1200
1201         pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                        // VkPipelineStageFlags         srcStageMask
1202                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                // VkPipelineStageFlags         dstStageMask
1203                                                  VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT |
1204                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                  // VkAccessFlags                        srcAccessMask
1205                                                  VK_ACCESS_TRANSFER_READ_BIT,                                   // VkAccessFlags                        dstAccessMask
1206                                                  VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,              // VkImageLayout                        oldLayout;
1207                                                  VK_IMAGE_LAYOUT_GENERAL);                                              // VkImageLayout                        newLayout;
1208
1209         endCommandBuffer();
1210
1211         submitCommandBuffer();
1212
1213         de::MovePtr<TextureLevel>               result                                          = readImage(VK_IMAGE_ASPECT_COLOR_BIT);
1214         std::string                                             compareResult;
1215
1216         for (deUint32 y = 0; y < m_params.imageExtent.height; y++)
1217         {
1218                 for (deUint32 x = 0; x < m_params.imageExtent.width; x++)
1219                 {
1220                         if (((x < m_params.imageExtent.width / 4) && (y < m_params.imageExtent.height / 4)) ||
1221                                 ((x < m_params.imageExtent.width / 4) && (y >= (m_params.imageExtent.height * 3) / 4)) ||
1222                                 ((x >= (m_params.imageExtent.width * 3) / 4) && (y < m_params.imageExtent.height / 4)) ||
1223                                 ((x >= (m_params.imageExtent.width * 3) / 4) && (y >= (m_params.imageExtent.height * 3) / 4)))
1224                         {
1225                                 if (!comparePixelToColorClearValue(result->getAccess(), x, y, 0, m_params.initValue.color, compareResult))
1226                                         return TestStatus::fail("Color value mismatch! " + compareResult);
1227                         }
1228                         else if (!comparePixelToColorClearValue(result->getAccess(), x, y, 0, m_params.clearValue.color, compareResult))
1229                                 return TestStatus::fail("Color value mismatch! " + compareResult);
1230                 }
1231         }
1232
1233         return TestStatus::pass("cmdClearAttachments passed");
1234 }
1235
1236 class PartialClearDepthStencilAttachmentTestInstance : public ImageClearingTestInstance
1237 {
1238 public:
1239                                                                         PartialClearDepthStencilAttachmentTestInstance  (Context&                               context,
1240                                                                                                                                                                          const TestParams&              testParams)
1241                                                                                 : ImageClearingTestInstance(context, testParams)
1242                                                                         {}
1243
1244         virtual TestStatus                              iterate                                                                                 (void);
1245 };
1246
1247 TestStatus PartialClearDepthStencilAttachmentTestInstance::iterate (void)
1248 {
1249         const VkClearAttachment                 clearAttachment         =
1250         {
1251                 VK_IMAGE_ASPECT_DEPTH_BIT |
1252                 VK_IMAGE_ASPECT_STENCIL_BIT,                                    // kImageAspectFlags    aspectMask;
1253                 0u,                                                                                             // deUint32                             colorAttachment;
1254                 m_params.clearValue                                                             // VkClearValue                 clearValue;
1255         };
1256
1257         const VkClearRect                               clearRects[2]           =
1258         {
1259                 {
1260                         {
1261                                 { 0, (deInt32)(m_params.imageExtent.height / 4) },
1262                                 { m_params.imageExtent.width, m_params.imageExtent.height / 2}
1263                         },                                                                                                                                      // VkRect2D     rect;
1264                         0u,                                                                                                                                     // deUint32     baseArrayLayer;
1265                         1u                                                                                                                                      // deUint32     layerCount;
1266                 },
1267                 {
1268                         {
1269                                 { (deInt32)(m_params.imageExtent.width / 4), 0 },
1270                                 { m_params.imageExtent.width / 2, m_params.imageExtent.height}
1271                         },                                                                                                                                      // VkRect2D     rect;
1272                         0u,                                                                                                                                     // deUint32     baseArrayLayer;
1273                         1u                                                                                                                                      // deUint32     layerCount;
1274                 }
1275         };
1276
1277         beginCommandBuffer(0);
1278
1279         pipelineImageBarrier(VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,                                 // VkPipelineStageFlags         srcStageMask
1280                                                  VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,                            // VkPipelineStageFlags         dstStageMask
1281                                                  0,                                                                                                     // VkAccessFlags                        srcAccessMask
1282                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,          // VkAccessFlags                        dstAccessMask
1283                                                  VK_IMAGE_LAYOUT_UNDEFINED,                                                     // VkImageLayout                        oldLayout;
1284                                                  VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);     // VkImageLayout                        newLayout;
1285
1286         beginRenderPass(VK_SUBPASS_CONTENTS_INLINE, m_params.initValue);
1287         m_vkd.cmdClearAttachments(*m_commandBuffer, 1, &clearAttachment, 2, clearRects);
1288         m_vkd.cmdEndRenderPass(*m_commandBuffer);
1289
1290         pipelineImageBarrier(VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,                                // VkPipelineStageFlags         srcStageMask
1291                                                  VK_PIPELINE_STAGE_TRANSFER_BIT,                                        // VkPipelineStageFlags         dstStageMask
1292                                                  VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
1293                                                  VK_ACCESS_TRANSFER_WRITE_BIT,                                          // VkAccessFlags                        srcAccessMask
1294                                                  VK_ACCESS_TRANSFER_READ_BIT,                                           // VkAccessFlags                        dstAccessMask
1295                                                  VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,      // VkImageLayout                        oldLayout;
1296                                                  VK_IMAGE_LAYOUT_GENERAL);                                                      // VkImageLayout                        newLayout;
1297
1298         endCommandBuffer();
1299
1300         submitCommandBuffer();
1301
1302         de::MovePtr<TextureLevel>                                               depthResult;
1303         de::MovePtr<TextureLevel>                                               stencilResult;
1304         bool                                                                                    isDepthFormat           = getIsDepthFormat(m_params.imageFormat);
1305         if (isDepthFormat)
1306         {
1307                 depthResult             = readImage(VK_IMAGE_ASPECT_DEPTH_BIT);
1308         }
1309         const bool                                                                              isStencilFormat         = getIsStencilFormat(m_params.imageFormat);
1310
1311         if (isStencilFormat)
1312         {
1313                 stencilResult   = readImage(VK_IMAGE_ASPECT_STENCIL_BIT);
1314         }
1315
1316         std::string                                                                             compareResult;
1317
1318         for (deUint32 y = 0; y < m_params.imageExtent.height; y++)
1319         {
1320                 for (deUint32 x = 0; x < m_params.imageExtent.width; x++)
1321                 {
1322                         if (((x < m_params.imageExtent.width / 4) && (y < m_params.imageExtent.height / 4)) ||
1323                                 ((x < m_params.imageExtent.width / 4) && (y >= (m_params.imageExtent.height * 3) / 4)) ||
1324                                 ((x >= (m_params.imageExtent.width * 3) / 4) && (y < m_params.imageExtent.height / 4)) ||
1325                                 ((x >= (m_params.imageExtent.width * 3) / 4) && (y >= (m_params.imageExtent.height * 3) / 4)))
1326                         {
1327                                 if (isDepthFormat && !comparePixelToDepthClearValue(depthResult->getAccess(), x, y, m_params.initValue.depthStencil.depth, compareResult))
1328                                         return TestStatus::fail("Depth value mismatch! " + compareResult);
1329
1330                                 if (isStencilFormat && !comparePixelToStencilClearValue(stencilResult->getAccess(), x, y, m_params.initValue.depthStencil.stencil, compareResult))
1331                                         return TestStatus::fail("Stencil value mismatch! " + compareResult);
1332                         }
1333                         else
1334                         {
1335                                 if (isDepthFormat && !comparePixelToDepthClearValue(depthResult->getAccess(), x, y, m_params.clearValue.depthStencil.depth, compareResult))
1336                                         return TestStatus::fail("Depth value mismatch! " + compareResult);
1337
1338                                 if (isStencilFormat && !comparePixelToStencilClearValue(stencilResult->getAccess(), x, y, m_params.clearValue.depthStencil.stencil, compareResult))
1339                                         return TestStatus::fail("Stencil value mismatch! " + compareResult);
1340                         }
1341                 }
1342         }
1343
1344         return TestStatus::pass("cmdClearAttachments passed");
1345 }
1346
1347 VkClearValue makeClearColorValue (VkFormat format, float r, float g, float b, float a)
1348 {
1349         const   TextureFormat tcuFormat = mapVkFormat(format);
1350         VkClearValue clearValue;
1351
1352         if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_FLOATING_POINT
1353                 || getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_FIXED_POINT
1354                 || getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT)
1355         {
1356                 clearValue.color.float32[0] = r;
1357                 clearValue.color.float32[1] = g;
1358                 clearValue.color.float32[2] = b;
1359                 clearValue.color.float32[3] = a;
1360         }
1361         else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
1362         {
1363                 UVec4 maxValues = getFormatMaxUintValue(tcuFormat);
1364
1365                 clearValue.color.uint32[0] = (deUint32)((float)maxValues[0] * r);
1366                 clearValue.color.uint32[1] = (deUint32)((float)maxValues[1] * g);
1367                 clearValue.color.uint32[2] = (deUint32)((float)maxValues[2] * b);
1368                 clearValue.color.uint32[3] = (deUint32)((float)maxValues[3] * a);
1369         }
1370         else if (getTextureChannelClass(tcuFormat.type) == TEXTURECHANNELCLASS_SIGNED_INTEGER)
1371         {
1372                 IVec4 maxValues = getFormatMaxIntValue(tcuFormat);
1373
1374                 clearValue.color.int32[0] = (deUint32)((float)maxValues[0] * r);
1375                 clearValue.color.int32[1] = (deUint32)((float)maxValues[1] * g);
1376                 clearValue.color.int32[2] = (deUint32)((float)maxValues[2] * b);
1377                 clearValue.color.int32[3] = (deUint32)((float)maxValues[3] * a);
1378         }
1379         else
1380                 DE_FATAL("Unknown channel class");
1381
1382         return clearValue;
1383 }
1384
1385 std::string getFormatCaseName (VkFormat format)
1386 {
1387         return de::toLower(de::toString(getFormatStr(format)).substr(10));
1388 }
1389
1390 const char* getImageTypeCaseName (VkImageType type)
1391 {
1392         const char* s_names[] =
1393         {
1394                 "1d",
1395                 "2d",
1396                 "3d"
1397         };
1398         return de::getSizedArrayElement<VK_IMAGE_TYPE_LAST>(s_names, type);
1399 }
1400
1401 } // anonymous
1402
1403 TestCaseGroup* createImageClearingTests (TestContext& testCtx)
1404 {
1405         // Main testgroup.
1406         de::MovePtr<TestCaseGroup>      imageClearingTests                                              (new TestCaseGroup(testCtx, "image_clearing", "Image Clearing Tests"));
1407
1408         de::MovePtr<TestCaseGroup>      colorImageClearTests                                    (new TestCaseGroup(testCtx, "clear_color_image", "Color Image Clear Tests"));
1409         de::MovePtr<TestCaseGroup>      depthStencilImageClearTests                             (new TestCaseGroup(testCtx, "clear_depth_stencil_image", "Color Depth/Stencil Image Tests"));
1410         de::MovePtr<TestCaseGroup>      colorAttachmentClearTests                               (new TestCaseGroup(testCtx, "clear_color_attachment", "Color Color Attachment Tests"));
1411         de::MovePtr<TestCaseGroup>      depthStencilAttachmentClearTests                (new TestCaseGroup(testCtx, "clear_depth_stencil_attachment", "Color Depth/Stencil Attachment Tests"));
1412         de::MovePtr<TestCaseGroup>      partialColorAttachmentClearTests                (new TestCaseGroup(testCtx, "partial_clear_color_attachment", "Clear Partial Color Attachment Tests"));
1413         de::MovePtr<TestCaseGroup>      partialDepthStencilAttachmentClearTests (new TestCaseGroup(testCtx, "partial_clear_depth_stencil_attachment", "Clear Partial Depth/Stencil Attachment Tests"));
1414
1415         // Some formats are commented out due to the tcu::TextureFormat does not support them yet.
1416         const VkFormat          colorImageFormatsToTest[]       =
1417         {
1418                 VK_FORMAT_R4G4_UNORM_PACK8,
1419                 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
1420                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
1421                 VK_FORMAT_R5G6B5_UNORM_PACK16,
1422                 VK_FORMAT_B5G6R5_UNORM_PACK16,
1423                 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
1424                 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
1425                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
1426                 VK_FORMAT_R8_UNORM,
1427                 VK_FORMAT_R8_SNORM,
1428                 VK_FORMAT_R8_USCALED,
1429                 VK_FORMAT_R8_SSCALED,
1430                 VK_FORMAT_R8_UINT,
1431                 VK_FORMAT_R8_SINT,
1432                 VK_FORMAT_R8_SRGB,
1433                 VK_FORMAT_R8G8_UNORM,
1434                 VK_FORMAT_R8G8_SNORM,
1435                 VK_FORMAT_R8G8_USCALED,
1436                 VK_FORMAT_R8G8_SSCALED,
1437                 VK_FORMAT_R8G8_UINT,
1438                 VK_FORMAT_R8G8_SINT,
1439                 VK_FORMAT_R8G8_SRGB,
1440                 VK_FORMAT_R8G8B8_UNORM,
1441                 VK_FORMAT_R8G8B8_SNORM,
1442                 VK_FORMAT_R8G8B8_USCALED,
1443                 VK_FORMAT_R8G8B8_SSCALED,
1444                 VK_FORMAT_R8G8B8_UINT,
1445                 VK_FORMAT_R8G8B8_SINT,
1446                 VK_FORMAT_R8G8B8_SRGB,
1447                 VK_FORMAT_B8G8R8_UNORM,
1448                 VK_FORMAT_B8G8R8_SNORM,
1449                 VK_FORMAT_B8G8R8_USCALED,
1450                 VK_FORMAT_B8G8R8_SSCALED,
1451                 VK_FORMAT_B8G8R8_UINT,
1452                 VK_FORMAT_B8G8R8_SINT,
1453                 VK_FORMAT_B8G8R8_SRGB,
1454                 VK_FORMAT_R8G8B8A8_UNORM,
1455                 VK_FORMAT_R8G8B8A8_SNORM,
1456                 VK_FORMAT_R8G8B8A8_USCALED,
1457                 VK_FORMAT_R8G8B8A8_SSCALED,
1458                 VK_FORMAT_R8G8B8A8_UINT,
1459                 VK_FORMAT_R8G8B8A8_SINT,
1460                 VK_FORMAT_R8G8B8A8_SRGB,
1461                 VK_FORMAT_B8G8R8A8_UNORM,
1462                 VK_FORMAT_B8G8R8A8_SNORM,
1463                 VK_FORMAT_B8G8R8A8_USCALED,
1464                 VK_FORMAT_B8G8R8A8_SSCALED,
1465                 VK_FORMAT_B8G8R8A8_UINT,
1466                 VK_FORMAT_B8G8R8A8_SINT,
1467                 VK_FORMAT_B8G8R8A8_SRGB,
1468                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
1469                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
1470                 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
1471                 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
1472                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
1473                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
1474                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
1475                 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
1476                 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
1477                 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
1478                 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
1479                 VK_FORMAT_A2R10G10B10_UINT_PACK32,
1480                 VK_FORMAT_A2R10G10B10_SINT_PACK32,
1481                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
1482                 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
1483                 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
1484                 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
1485                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
1486                 VK_FORMAT_A2B10G10R10_SINT_PACK32,
1487                 VK_FORMAT_R16_UNORM,
1488                 VK_FORMAT_R16_SNORM,
1489                 VK_FORMAT_R16_USCALED,
1490                 VK_FORMAT_R16_SSCALED,
1491                 VK_FORMAT_R16_UINT,
1492                 VK_FORMAT_R16_SINT,
1493                 VK_FORMAT_R16_SFLOAT,
1494                 VK_FORMAT_R16G16_UNORM,
1495                 VK_FORMAT_R16G16_SNORM,
1496                 VK_FORMAT_R16G16_USCALED,
1497                 VK_FORMAT_R16G16_SSCALED,
1498                 VK_FORMAT_R16G16_UINT,
1499                 VK_FORMAT_R16G16_SINT,
1500                 VK_FORMAT_R16G16_SFLOAT,
1501                 VK_FORMAT_R16G16B16_UNORM,
1502                 VK_FORMAT_R16G16B16_SNORM,
1503                 VK_FORMAT_R16G16B16_USCALED,
1504                 VK_FORMAT_R16G16B16_SSCALED,
1505                 VK_FORMAT_R16G16B16_UINT,
1506                 VK_FORMAT_R16G16B16_SINT,
1507                 VK_FORMAT_R16G16B16_SFLOAT,
1508                 VK_FORMAT_R16G16B16A16_UNORM,
1509                 VK_FORMAT_R16G16B16A16_SNORM,
1510                 VK_FORMAT_R16G16B16A16_USCALED,
1511                 VK_FORMAT_R16G16B16A16_SSCALED,
1512                 VK_FORMAT_R16G16B16A16_UINT,
1513                 VK_FORMAT_R16G16B16A16_SINT,
1514                 VK_FORMAT_R16G16B16A16_SFLOAT,
1515                 VK_FORMAT_R32_UINT,
1516                 VK_FORMAT_R32_SINT,
1517                 VK_FORMAT_R32_SFLOAT,
1518                 VK_FORMAT_R32G32_UINT,
1519                 VK_FORMAT_R32G32_SINT,
1520                 VK_FORMAT_R32G32_SFLOAT,
1521                 VK_FORMAT_R32G32B32_UINT,
1522                 VK_FORMAT_R32G32B32_SINT,
1523                 VK_FORMAT_R32G32B32_SFLOAT,
1524                 VK_FORMAT_R32G32B32A32_UINT,
1525                 VK_FORMAT_R32G32B32A32_SINT,
1526                 VK_FORMAT_R32G32B32A32_SFLOAT,
1527 //              VK_FORMAT_R64_UINT,
1528 //              VK_FORMAT_R64_SINT,
1529 //              VK_FORMAT_R64_SFLOAT,
1530 //              VK_FORMAT_R64G64_UINT,
1531 //              VK_FORMAT_R64G64_SINT,
1532 //              VK_FORMAT_R64G64_SFLOAT,
1533 //              VK_FORMAT_R64G64B64_UINT,
1534 //              VK_FORMAT_R64G64B64_SINT,
1535 //              VK_FORMAT_R64G64B64_SFLOAT,
1536 //              VK_FORMAT_R64G64B64A64_UINT,
1537 //              VK_FORMAT_R64G64B64A64_SINT,
1538 //              VK_FORMAT_R64G64B64A64_SFLOAT,
1539                 VK_FORMAT_B10G11R11_UFLOAT_PACK32,
1540                 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
1541 //              VK_FORMAT_BC1_RGB_UNORM_BLOCK,
1542 //              VK_FORMAT_BC1_RGB_SRGB_BLOCK,
1543 //              VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
1544 //              VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
1545 //              VK_FORMAT_BC2_UNORM_BLOCK,
1546 //              VK_FORMAT_BC2_SRGB_BLOCK,
1547 //              VK_FORMAT_BC3_UNORM_BLOCK,
1548 //              VK_FORMAT_BC3_SRGB_BLOCK,
1549 //              VK_FORMAT_BC4_UNORM_BLOCK,
1550 //              VK_FORMAT_BC4_SNORM_BLOCK,
1551 //              VK_FORMAT_BC5_UNORM_BLOCK,
1552 //              VK_FORMAT_BC5_SNORM_BLOCK,
1553 //              VK_FORMAT_BC6H_UFLOAT_BLOCK,
1554 //              VK_FORMAT_BC6H_SFLOAT_BLOCK,
1555 //              VK_FORMAT_BC7_UNORM_BLOCK,
1556 //              VK_FORMAT_BC7_SRGB_BLOCK,
1557 //              VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
1558 //              VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
1559 //              VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
1560 //              VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
1561 //              VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
1562 //              VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
1563 //              VK_FORMAT_EAC_R11_UNORM_BLOCK,
1564 //              VK_FORMAT_EAC_R11_SNORM_BLOCK,
1565 //              VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
1566 //              VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
1567 //              VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
1568 //              VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
1569 //              VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
1570 //              VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
1571 //              VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
1572 //              VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
1573 //              VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
1574 //              VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
1575 //              VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
1576 //              VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
1577 //              VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
1578 //              VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
1579 //              VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
1580 //              VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
1581 //              VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
1582 //              VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
1583 //              VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
1584 //              VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
1585 //              VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
1586 //              VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
1587 //              VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
1588 //              VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
1589 //              VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
1590 //              VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
1591 //              VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
1592 //              VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
1593 //              VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
1594 //              VK_FORMAT_ASTC_12x12_SRGB_BLOCK
1595         };
1596         const size_t    numOfColorImageFormatsToTest                    = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
1597
1598         const VkFormat  depthStencilImageFormatsToTest[]                =
1599         {
1600                 VK_FORMAT_D16_UNORM,
1601                 VK_FORMAT_X8_D24_UNORM_PACK32,
1602                 VK_FORMAT_D32_SFLOAT,
1603                 VK_FORMAT_S8_UINT,
1604                 VK_FORMAT_D16_UNORM_S8_UINT,
1605                 VK_FORMAT_D24_UNORM_S8_UINT,
1606                 VK_FORMAT_D32_SFLOAT_S8_UINT
1607         };
1608         const size_t    numOfDepthStencilImageFormatsToTest             = DE_LENGTH_OF_ARRAY(depthStencilImageFormatsToTest);
1609
1610         {
1611                 const VkImageType                       imageTypesToTest[]              =
1612                 {
1613                         VK_IMAGE_TYPE_1D,
1614                         VK_IMAGE_TYPE_2D,
1615                         VK_IMAGE_TYPE_3D
1616                 };
1617                 const size_t                            numOfImageTypesToTest   = DE_LENGTH_OF_ARRAY(imageTypesToTest);
1618
1619                 const VkExtent3D                        imageDimensionsByType[] =
1620                 {
1621                         { 256, 1, 1},
1622                         { 256, 256, 1},
1623                         { 256, 256, 16}
1624                 };
1625
1626                 TestParams                                      colorImageTestParams;
1627
1628                 for (size_t     imageTypeIndex = 0; imageTypeIndex < numOfImageTypesToTest; ++imageTypeIndex)
1629                 {
1630                         for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
1631                         {
1632                                 colorImageTestParams.imageType          = imageTypesToTest[imageTypeIndex];
1633                                 colorImageTestParams.imageFormat        = colorImageFormatsToTest[imageFormatIndex];
1634                                 colorImageTestParams.imageExtent        = imageDimensionsByType[imageTypeIndex];
1635                                 colorImageTestParams.initValue          = makeClearColorValue(colorImageTestParams.imageFormat, 0.2f, 0.1f, 0.7f, 0.8f);
1636                                 colorImageTestParams.clearValue         = makeClearColorValue(colorImageTestParams.imageFormat, 0.1f, 0.5f, 0.3f, 0.9f);
1637
1638                                 std::ostringstream      testCaseName;
1639                                 testCaseName << getImageTypeCaseName(colorImageTestParams.imageType);
1640                                 testCaseName << "_" << getFormatCaseName(colorImageTestParams.imageFormat);
1641
1642                                 colorImageClearTests->addChild(new InstanceFactory1<ClearColorImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Image", colorImageTestParams));
1643                         }
1644                 }
1645
1646                 imageClearingTests->addChild(colorImageClearTests.release());
1647         }
1648
1649         {
1650                 TestParams                                      depthStencilImageTestParams                     =
1651                 {
1652                         VK_IMAGE_TYPE_2D,                                                               // VkImageType          imageType;
1653                         depthStencilImageFormatsToTest[0],                              // VkFormat                     format;
1654                         { 256, 256, 1 },                                                                // VkExtent3D           extent;
1655                         makeClearValueDepthStencil(0.5f, 0x03),                 // VkClearValue         initValue
1656                         makeClearValueDepthStencil(0.1f, 0x06)                  // VkClearValue         clearValue
1657                 };
1658
1659                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
1660                 {
1661                         depthStencilImageTestParams.imageFormat = depthStencilImageFormatsToTest[imageFormatIndex];
1662
1663                         std::ostringstream      testCaseName;
1664                         testCaseName << getImageTypeCaseName(depthStencilImageTestParams.imageType);
1665                         testCaseName << "_" << getFormatCaseName(depthStencilImageTestParams.imageFormat);
1666
1667                         depthStencilImageClearTests->addChild(new InstanceFactory1<ClearDepthStencilImageTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Image", depthStencilImageTestParams));
1668                 }
1669
1670                 imageClearingTests->addChild(depthStencilImageClearTests.release());
1671         }
1672
1673         {
1674                 TestParams                                      colorAttachmentTestParams                       =
1675                 {
1676                         VK_IMAGE_TYPE_2D,                                                               // VkImageType          imageType;
1677                         colorImageFormatsToTest[0],                                             // VkFormat                     format;
1678                         { 256, 256, 1 },                                                                // VkExtent3D           extent;
1679                         makeClearValueColorU32(0, 0, 0, 0),                             // VkClearValue         initValue
1680                         makeClearValueColorU32(0, 0, 0, 0)                              // VkClearValue         clearValue
1681                 };
1682
1683                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
1684                 {
1685                         colorAttachmentTestParams.imageFormat   = colorImageFormatsToTest[imageFormatIndex];
1686                         colorAttachmentTestParams.initValue             = makeClearColorValue(colorAttachmentTestParams.imageFormat, 0.2f, 0.1f, 0.7f, 0.8f);
1687                         colorAttachmentTestParams.clearValue    = makeClearColorValue(colorAttachmentTestParams.imageFormat, 0.1f, 0.5f, 0.3f, 0.9f);
1688
1689                         std::ostringstream      testCaseName;
1690                         testCaseName << getImageTypeCaseName(colorAttachmentTestParams.imageType);
1691                         testCaseName << "_" << getFormatCaseName(colorAttachmentTestParams.imageFormat);
1692
1693                         colorAttachmentClearTests->addChild(new InstanceFactory1<ClearColorAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Color Attachment", colorAttachmentTestParams));
1694                 }
1695
1696                 imageClearingTests->addChild(colorAttachmentClearTests.release());
1697         }
1698
1699         {
1700                 TestParams                                      depthStencilAttachmentTestParams        =
1701                 {
1702                         VK_IMAGE_TYPE_2D,                                                               // VkImageType          imageType;
1703                         depthStencilImageFormatsToTest[0],                              // VkFormat                     format;
1704                         { 256, 256, 1 },                                                                // VkExtent3D           extent;
1705                         makeClearValueDepthStencil(0.5f, 0x03),                 // VkClearValue         initValue
1706                         makeClearValueDepthStencil(0.1f, 0x06)                  // VkClearValue         clearValue
1707                 };
1708
1709                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
1710                 {
1711                         depthStencilAttachmentTestParams.imageFormat = depthStencilImageFormatsToTest[imageFormatIndex];
1712
1713                         std::ostringstream      testCaseName;
1714                         testCaseName << getImageTypeCaseName(depthStencilAttachmentTestParams.imageType);
1715                         testCaseName << "_" << getFormatCaseName(depthStencilAttachmentTestParams.imageFormat);
1716
1717                         depthStencilAttachmentClearTests->addChild(new InstanceFactory1<ClearDepthStencilAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Clear Depth/Stencil Attachment", depthStencilAttachmentTestParams));
1718                 }
1719
1720                 imageClearingTests->addChild(depthStencilAttachmentClearTests.release());
1721         }
1722
1723         {
1724                 TestParams                                      colorAttachmentTestParams                       =
1725                 {
1726                         VK_IMAGE_TYPE_2D,                                                               // VkImageType          imageType;
1727                         colorImageFormatsToTest[0],                                             // VkFormat                     format;
1728                         { 256, 256, 1 },                                                                // VkExtent3D           extent;
1729                         makeClearValueColorU32(0, 0, 0, 0),                             // VkClearValue         initValue
1730                         makeClearValueColorU32(0, 0, 0, 0)                              // VkClearValue         clearValue
1731                 };
1732
1733                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfColorImageFormatsToTest; ++imageFormatIndex)
1734                 {
1735                         colorAttachmentTestParams.imageFormat   = colorImageFormatsToTest[imageFormatIndex];
1736                         colorAttachmentTestParams.initValue             = makeClearColorValue(colorAttachmentTestParams.imageFormat, 0.2f, 0.1f, 0.7f, 0.8f);
1737                         colorAttachmentTestParams.clearValue    = makeClearColorValue(colorAttachmentTestParams.imageFormat, 0.1f, 0.5f, 0.3f, 0.9f);
1738
1739                         std::ostringstream      testCaseName;
1740                         testCaseName << getImageTypeCaseName(colorAttachmentTestParams.imageType);
1741                         testCaseName << "_" << getFormatCaseName(colorAttachmentTestParams.imageFormat);
1742
1743                         partialColorAttachmentClearTests->addChild(new InstanceFactory1<PartialClearColorAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Partial Clear Color Attachment", colorAttachmentTestParams));
1744                 }
1745
1746                 imageClearingTests->addChild(partialColorAttachmentClearTests.release());
1747         }
1748
1749         {
1750                 TestParams                                      depthStencilAttachmentTestParams        =
1751                 {
1752                         VK_IMAGE_TYPE_2D,                                                               // VkImageType          imageType;
1753                         depthStencilImageFormatsToTest[0],                              // VkFormat                     format;
1754                         { 256, 256, 1 },                                                                // VkExtent3D           extent;
1755                         makeClearValueDepthStencil(0.5f, 0x03),                 // VkClearValue         initValue
1756                         makeClearValueDepthStencil(0.1f, 0x06)                  // VkClearValue         clearValue
1757                 };
1758
1759                 for (size_t imageFormatIndex = 0; imageFormatIndex < numOfDepthStencilImageFormatsToTest; ++imageFormatIndex)
1760                 {
1761                         depthStencilAttachmentTestParams.imageFormat    = depthStencilImageFormatsToTest[imageFormatIndex];
1762
1763                         std::ostringstream      testCaseName;
1764                         testCaseName << getImageTypeCaseName(depthStencilAttachmentTestParams.imageType);
1765                         testCaseName << "_" << getFormatCaseName(depthStencilAttachmentTestParams.imageFormat);
1766
1767                         partialDepthStencilAttachmentClearTests->addChild(new InstanceFactory1<PartialClearDepthStencilAttachmentTestInstance, TestParams>(testCtx, NODETYPE_SELF_VALIDATE, testCaseName.str(), "Parital Clear Depth/Stencil Attachment", depthStencilAttachmentTestParams));
1768                 }
1769
1770                 imageClearingTests->addChild(partialDepthStencilAttachmentClearTests.release());
1771         }
1772
1773         return imageClearingTests.release();
1774 }
1775
1776 } // api
1777 } // vkt