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