5fd91a8f4b0e35a9456835c9abbeaec5b56b20f5
[platform/upstream/VK-GL-CTS.git] / external / vulkancts / modules / vulkan / api / vktApiCopiesAndBlittingTests.cpp
1 /*------------------------------------------------------------------------
2  * Vulkan Conformance Tests
3  * ------------------------
4  *
5  * Copyright (c) 2015-2016 The Khronos Group Inc.
6  * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  *//*!
21  * \file
22  * \brief Vulkan Copies And Blitting Tests
23  *//*--------------------------------------------------------------------*/
24
25 #include "vktApiCopiesAndBlittingTests.hpp"
26
27 #include "deStringUtil.hpp"
28 #include "deUniquePtr.hpp"
29
30 #include "tcuImageCompare.hpp"
31 #include "tcuTexture.hpp"
32 #include "tcuTextureUtil.hpp"
33 #include "tcuVectorType.hpp"
34 #include "tcuVectorUtil.hpp"
35
36 #include "vkImageUtil.hpp"
37 #include "vkMemUtil.hpp"
38 #include "vkPrograms.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkRefUtil.hpp"
41 #include "vktTestCase.hpp"
42 #include "vktTestCaseUtil.hpp"
43 #include "vkTypeUtil.hpp"
44
45 namespace vkt
46 {
47
48 namespace api
49 {
50
51 using namespace vk;
52
53 namespace
54 {
55
56 VkImageAspectFlags getAspectFlags (tcu::TextureFormat format)
57 {
58         VkImageAspectFlags      aspectFlag      = 0;
59         aspectFlag |= (tcu::hasDepthComponent(format.order)? VK_IMAGE_ASPECT_DEPTH_BIT : 0);
60         aspectFlag |= (tcu::hasStencilComponent(format.order)? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
61
62         if (!aspectFlag)
63                 aspectFlag = VK_IMAGE_ASPECT_COLOR_BIT;
64
65         return aspectFlag;
66 }
67
68 // This is effectively same as vk::isFloatFormat(mapTextureFormat(format))
69 // except that it supports some formats that are not mappable to VkFormat.
70 // When we are checking combined depth and stencil formats, each aspect is
71 // checked separately, and in some cases we construct PBA with a format that
72 // is not mappable to VkFormat.
73 bool isFloatFormat (tcu::TextureFormat format)
74 {
75         return tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
76 }
77
78 union CopyRegion
79 {
80         VkBufferCopy            bufferCopy;
81         VkImageCopy                     imageCopy;
82         VkBufferImageCopy       bufferImageCopy;
83         VkImageBlit                     imageBlit;
84         VkImageResolve          imageResolve;
85 };
86
87 struct TestParams
88 {
89         union Data
90         {
91                 struct Buffer
92                 {
93                         VkDeviceSize    size;
94                 }       buffer;
95                 struct Image
96                 {
97                         VkFormat                format;
98                         VkExtent3D              extent;
99                 }       image;
100         }       src, dst;
101
102         std::vector<CopyRegion> regions;
103         union
104         {
105                 VkFilter                                filter;
106                 VkSampleCountFlagBits   samples;
107         };
108 };
109
110 const tcu::TextureFormat mapCombinedToDepthTransferFormat (const tcu::TextureFormat& combinedFormat)
111 {
112         tcu::TextureFormat format;
113         switch (combinedFormat.type)
114         {
115                 case tcu::TextureFormat::UNSIGNED_INT_16_8_8:
116                         format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
117                         break;
118                 case tcu::TextureFormat::UNSIGNED_INT_24_8_REV:
119                         format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNSIGNED_INT_24_8_REV);
120                         break;
121                 case tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:
122                         format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT);
123                         break;
124                 default:
125                         DE_ASSERT(false);
126                         break;
127         }
128         return format;
129 }
130
131 class CopiesAndBlittingTestInstance : public vkt::TestInstance
132 {
133 public:
134                                                                                 CopiesAndBlittingTestInstance           (Context&       context,
135                                                                                                                                                          TestParams     testParams);
136         virtual tcu::TestStatus                         iterate                                                         (void) = 0;
137
138         enum FillMode
139         {
140                 FILL_MODE_GRADIENT = 0,
141                 FILL_MODE_WHITE,
142                 FILL_MODE_RED,
143                 FILL_MODE_MULTISAMPLE,
144
145                 FILL_MODE_LAST
146         };
147
148 protected:
149         const TestParams                                        m_params;
150
151         Move<VkCommandPool>                                     m_cmdPool;
152         Move<VkCommandBuffer>                           m_cmdBuffer;
153         Move<VkFence>                                           m_fence;
154         de::MovePtr<tcu::TextureLevel>          m_sourceTextureLevel;
155         de::MovePtr<tcu::TextureLevel>          m_destinationTextureLevel;
156         de::MovePtr<tcu::TextureLevel>          m_expectedTextureLevel;
157
158         VkCommandBufferBeginInfo                        m_cmdBufferBeginInfo;
159
160         void                                                            generateBuffer                                          (tcu::PixelBufferAccess buffer, int width, int height, int depth = 1, FillMode = FILL_MODE_GRADIENT);
161         virtual void                                            generateExpectedResult                          (void);
162         void                                                            uploadBuffer                                            (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc);
163         void                                                            uploadImage                                                     (const tcu::ConstPixelBufferAccess& src, VkImage dst);
164         virtual tcu::TestStatus                         checkTestResult                                         (tcu::ConstPixelBufferAccess result);
165         virtual void                                            copyRegionToTextureLevel                        (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region) = 0;
166         deUint32                                                        calculateSize                                           (tcu::ConstPixelBufferAccess src) const
167                                                                                 {
168                                                                                         return src.getWidth() * src.getHeight() * src.getDepth() * tcu::getPixelSize(src.getFormat());
169                                                                                 }
170
171         de::MovePtr<tcu::TextureLevel>          readImage                                                       (vk::VkImage                                    image,
172                                                                                                                                                          vk::VkFormat                                   format,
173                                                                                                                                                          const VkExtent3D                               imageSize);
174
175 private:
176         void                                                            uploadImageAspect                                       (const tcu::ConstPixelBufferAccess&     src,
177                                                                                                                                                          const VkImage&                                         dst);
178         void                                                            readImageAspect                                         (vk::VkImage                                            src,
179                                                                                                                                                          const tcu::PixelBufferAccess&          dst);
180 };
181
182 CopiesAndBlittingTestInstance::CopiesAndBlittingTestInstance (Context& context, TestParams testParams)
183         : vkt::TestInstance     (context)
184         , m_params                      (testParams)
185 {
186         const DeviceInterface&          vk                                      = context.getDeviceInterface();
187         const VkDevice                          vkDevice                        = context.getDevice();
188         const deUint32                          queueFamilyIndex        = context.getUniversalQueueFamilyIndex();
189
190         // Create command pool
191         {
192                 const VkCommandPoolCreateInfo           cmdPoolParams                   =
193                 {
194                         VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,             // VkStructureType              sType;
195                         DE_NULL,                                                                                // const void*                  pNext;
196                         VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,                   // VkCmdPoolCreateFlags flags;
197                         queueFamilyIndex,                                                               // deUint32                             queueFamilyIndex;
198                 };
199
200                 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
201         }
202
203         // Create command buffer
204         {
205                 const VkCommandBufferAllocateInfo       cmdBufferAllocateInfo   =
206                 {
207                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType                      sType;
208                         DE_NULL,                                                                                // const void*                          pNext;
209                         *m_cmdPool,                                                                             // VkCommandPool                        commandPool;
210                         VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                // VkCommandBufferLevel         level;
211                         1u                                                                                              // deUint32                                     bufferCount;
212                 };
213
214                 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
215         }
216
217         // Create fence
218         {
219                 const VkFenceCreateInfo                         fenceParams                             =
220                 {
221                         VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // VkStructureType              sType;
222                         DE_NULL,                                                                // const void*                  pNext;
223                         0u                                                                              // VkFenceCreateFlags   flags;
224                 };
225
226                 m_fence = createFence(vk, vkDevice, &fenceParams);
227         }
228 }
229
230 void CopiesAndBlittingTestInstance::generateBuffer (tcu::PixelBufferAccess buffer, int width, int height, int depth, FillMode mode)
231 {
232         if (mode == FILL_MODE_GRADIENT)
233         {
234                 tcu::fillWithComponentGradients(buffer, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
235                 return;
236         }
237
238         const tcu::Vec4         redColor        (1.0, 0.0, 0.0, 1.0);
239         const tcu::Vec4         greenColor      (0.0, 1.0, 0.0, 1.0);
240         const tcu::Vec4         blueColor       (0.0, 0.0, 1.0, 1.0);
241         const tcu::Vec4         whiteColor      (1.0, 1.0, 1.0, 1.0);
242
243         for (int z = 0; z < depth; z++)
244         {
245                 for (int y = 0; y < height; y++)
246                 {
247                         for (int x = 0; x < width; x++)
248                         {
249                                 switch (mode)
250                                 {
251                                         case FILL_MODE_WHITE:
252                                                 if (tcu::isCombinedDepthStencilType(buffer.getFormat().type))
253                                                 {
254                                                         buffer.setPixDepth(1.0f, x, y, z);
255                                                         if (tcu::hasStencilComponent(buffer.getFormat().order))
256                                                                 buffer.setPixStencil(255, x, y, z);
257                                                 }
258                                                 else
259                                                         buffer.setPixel(whiteColor, x, y, z);
260                                                 break;
261                                         case FILL_MODE_RED:
262                                                 DE_ASSERT(!tcu::isCombinedDepthStencilType(buffer.getFormat().type)); // combined types cannot be accessed directly
263                                                 buffer.setPixel(redColor, x, y, z);
264                                                 break;
265                                         case FILL_MODE_MULTISAMPLE:
266                                                 buffer.setPixel((x == y) ? tcu::Vec4(0.0, 0.5, 0.5, 1.0) : ((x > y) ? greenColor : blueColor), x, y, z);
267                                                 break;
268                                         default:
269                                                 break;
270                                 }
271                         }
272                 }
273         }
274 }
275
276 void CopiesAndBlittingTestInstance::uploadBuffer (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc)
277 {
278         const DeviceInterface&          vk                      = m_context.getDeviceInterface();
279         const VkDevice                          vkDevice        = m_context.getDevice();
280         const deUint32                          bufferSize      = calculateSize(bufferAccess);
281
282         // Write buffer data
283         deMemcpy(bufferAlloc.getHostPtr(), bufferAccess.getDataPtr(), bufferSize);
284         flushMappedMemoryRange(vk, vkDevice, bufferAlloc.getMemory(), bufferAlloc.getOffset(), bufferSize);
285 }
286
287 void CopiesAndBlittingTestInstance::uploadImageAspect (const tcu::ConstPixelBufferAccess& imageAccess, const VkImage& image)
288 {
289         const DeviceInterface&          vk                                      = m_context.getDeviceInterface();
290         const VkDevice                          vkDevice                        = m_context.getDevice();
291         const VkQueue                           queue                           = m_context.getUniversalQueue();
292         const deUint32                          queueFamilyIndex        = m_context.getUniversalQueueFamilyIndex();
293         Allocator&                                      memAlloc                        = m_context.getDefaultAllocator();
294
295         Move<VkBuffer>                          buffer;
296         const deUint32                          bufferSize                      = calculateSize(imageAccess);
297         de::MovePtr<Allocation>         bufferAlloc;
298         Move<VkCommandBuffer>           cmdBuffer;
299
300         // Create source buffer
301         {
302                 const VkBufferCreateInfo                        bufferParams                    =
303                 {
304                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
305                         DE_NULL,                                                                        // const void*                  pNext;
306                         0u,                                                                                     // VkBufferCreateFlags  flags;
307                         bufferSize,                                                                     // VkDeviceSize                 size;
308                         VK_BUFFER_USAGE_TRANSFER_SRC_BIT,                       // VkBufferUsageFlags   usage;
309                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
310                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
311                         &queueFamilyIndex,                                                      // const deUint32*              pQueueFamilyIndices;
312                 };
313
314                 buffer          = createBuffer(vk, vkDevice, &bufferParams);
315                 bufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *buffer), MemoryRequirement::HostVisible);
316                 VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
317         }
318
319         // Create command buffer
320         {
321                 const VkCommandBufferAllocateInfo       cmdBufferAllocateInfo   =
322                 {
323                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType                      sType;
324                         DE_NULL,                                                                                // const void*                          pNext;
325                         *m_cmdPool,                                                                             // VkCommandPool                        commandPool;
326                         VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                // VkCommandBufferLevel         level;
327                         1u,                                                                                             // deUint32                                     bufferCount;
328                 };
329
330                 cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
331         }
332
333         // Barriers for copying buffer to image
334         const VkBufferMemoryBarrier                             preBufferBarrier                =
335         {
336                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,                // VkStructureType      sType;
337                 DE_NULL,                                                                                // const void*          pNext;
338                 VK_ACCESS_HOST_WRITE_BIT,                                               // VkAccessFlags        srcAccessMask;
339                 VK_ACCESS_TRANSFER_READ_BIT,                                    // VkAccessFlags        dstAccessMask;
340                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                     srcQueueFamilyIndex;
341                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                     dstQueueFamilyIndex;
342                 *buffer,                                                                                // VkBuffer                     buffer;
343                 0u,                                                                                             // VkDeviceSize         offset;
344                 bufferSize                                                                              // VkDeviceSize         size;
345         };
346
347         const VkImageAspectFlags                                aspect                                  = getAspectFlags(imageAccess.getFormat());
348         const VkImageMemoryBarrier                              preImageBarrier                 =
349         {
350                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
351                 DE_NULL,                                                                                // const void*                          pNext;
352                 0u,                                                                                             // VkAccessFlags                        srcAccessMask;
353                 VK_ACCESS_TRANSFER_WRITE_BIT,                                   // VkAccessFlags                        dstAccessMask;
354                 VK_IMAGE_LAYOUT_UNDEFINED,                                              // VkImageLayout                        oldLayout;
355                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                   // VkImageLayout                        newLayout;
356                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
357                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     dstQueueFamilyIndex;
358                 image,                                                                                  // VkImage                                      image;
359                 {                                                                                               // VkImageSubresourceRange      subresourceRange;
360                         aspect,                                                                 // VkImageAspectFlags   aspect;
361                         0u,                                                                             // deUint32                             baseMipLevel;
362                         1u,                                                                             // deUint32                             mipLevels;
363                         0u,                                                                             // deUint32                             baseArraySlice;
364                         1u,                                                                             // deUint32                             arraySize;
365                 }
366         };
367
368         const VkImageMemoryBarrier                              postImageBarrier                =
369         {
370                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,                 // VkStructureType                      sType;
371                 DE_NULL,                                                                                // const void*                          pNext;
372                 VK_ACCESS_TRANSFER_WRITE_BIT,                                   // VkAccessFlags                        srcAccessMask;
373                 VK_ACCESS_TRANSFER_WRITE_BIT,                                   // VkAccessFlags                        dstAccessMask;
374                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                   // VkImageLayout                        oldLayout;
375                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,                   // VkImageLayout                        newLayout;
376                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     srcQueueFamilyIndex;
377                 VK_QUEUE_FAMILY_IGNORED,                                                // deUint32                                     dstQueueFamilyIndex;
378                 image,                                                                                  // VkImage                                      image;
379                 {                                                                                               // VkImageSubresourceRange      subresourceRange;
380                         aspect,                                                                 // VkImageAspectFlags   aspect;
381                         0u,                                                                             // deUint32                             baseMipLevel;
382                         1u,                                                                             // deUint32                             mipLevels;
383                         0u,                                                                             // deUint32                             baseArraySlice;
384                         1u,                                                                             // deUint32                             arraySize;
385                 }
386         };
387
388         const VkExtent3D                        imageExtent             = { (deUint32)imageAccess.getWidth(), (deUint32)imageAccess.getHeight(), 1u };
389         const VkBufferImageCopy         copyRegion              =
390         {
391                 0u,                                                                                             // VkDeviceSize                         bufferOffset;
392                 (deUint32)imageAccess.getWidth(),                               // deUint32                                     bufferRowLength;
393                 (deUint32)imageAccess.getHeight(),                              // deUint32                                     bufferImageHeight;
394                 {
395                         getAspectFlags(imageAccess.getFormat()),                // VkImageAspectFlags   aspect;
396                         0u,                                                                                             // deUint32                             mipLevel;
397                         0u,                                                                                             // deUint32                             baseArrayLayer;
398                         1u,                                                                                             // deUint32                             layerCount;
399                 },                                                                                              // VkImageSubresourceLayers     imageSubresource;
400                 { 0, 0, 0 },                                                                    // VkOffset3D                           imageOffset;
401                 imageExtent                                                                             // VkExtent3D                           imageExtent;
402         };
403
404         // Write buffer data
405         deMemcpy(bufferAlloc->getHostPtr(), imageAccess.getDataPtr(), bufferSize);
406         flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), bufferSize);
407
408         // Copy buffer to image
409         const VkCommandBufferBeginInfo                  cmdBufferBeginInfo              =
410         {
411                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
412                 DE_NULL,                                                                                                // const void*                                          pNext;
413                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
414                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
415         };
416
417         VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
418         vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &preBufferBarrier, 1, &preImageBarrier);
419         vk.cmdCopyBufferToImage(*cmdBuffer, *buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, &copyRegion);
420         vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &postImageBarrier);
421         VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
422
423         const VkSubmitInfo                                              submitInfo                              =
424         {
425                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
426                 DE_NULL,                                                // const void*                          pNext;
427                 0u,                                                             // deUint32                                     waitSemaphoreCount;
428                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
429                 (const VkPipelineStageFlags*)DE_NULL,
430                 1u,                                                             // deUint32                                     commandBufferCount;
431                 &cmdBuffer.get(),                               // const VkCommandBuffer*       pCommandBuffers;
432                 0u,                                                             // deUint32                                     signalSemaphoreCount;
433                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
434         };
435
436         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
437         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
438         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
439 }
440
441 void CopiesAndBlittingTestInstance::uploadImage (const tcu::ConstPixelBufferAccess& src, VkImage dst)
442 {
443         if (tcu::isCombinedDepthStencilType(src.getFormat().type))
444         {
445                 if (tcu::hasDepthComponent(src.getFormat().order))
446                 {
447                         tcu::TextureLevel       depthTexture    (mapCombinedToDepthTransferFormat(src.getFormat()), src.getWidth(), src.getHeight(), src.getDepth());
448                         tcu::copy(depthTexture.getAccess(), tcu::getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_DEPTH));
449                         uploadImageAspect(depthTexture.getAccess(), dst);
450                 }
451
452                 if (tcu::hasStencilComponent(src.getFormat().order))
453                 {
454                         tcu::TextureLevel       stencilTexture  (tcu::getEffectiveDepthStencilTextureFormat(src.getFormat(), tcu::Sampler::MODE_STENCIL), src.getWidth(), src.getHeight(), src.getDepth());
455                         tcu::copy(stencilTexture.getAccess(), tcu::getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_STENCIL));
456                         uploadImageAspect(stencilTexture.getAccess(), dst);
457                 }
458         }
459         else
460                 uploadImageAspect(src, dst);
461 }
462
463 tcu::TestStatus CopiesAndBlittingTestInstance::checkTestResult (tcu::ConstPixelBufferAccess result)
464 {
465         const tcu::ConstPixelBufferAccess       expected        = m_expectedTextureLevel->getAccess();
466
467         if (isFloatFormat(result.getFormat()))
468         {
469                 const tcu::Vec4 threshold (0.0f);
470                 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
471                         return tcu::TestStatus::fail("CopiesAndBlitting test");
472         }
473         else
474         {
475                 const tcu::UVec4 threshold (0u);
476                 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
477                         return tcu::TestStatus::fail("CopiesAndBlitting test");
478         }
479
480         return tcu::TestStatus::pass("CopiesAndBlitting test");
481 }
482
483 void CopiesAndBlittingTestInstance::generateExpectedResult (void)
484 {
485         const tcu::ConstPixelBufferAccess       src     = m_sourceTextureLevel->getAccess();
486         const tcu::ConstPixelBufferAccess       dst     = m_destinationTextureLevel->getAccess();
487
488         m_expectedTextureLevel  = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
489         tcu::copy(m_expectedTextureLevel->getAccess(), dst);
490         for (deUint32 i = 0; i < m_params.regions.size(); i++)
491                 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), m_params.regions[i]);
492 }
493
494 class CopiesAndBlittingTestCase : public vkt::TestCase
495 {
496 public:
497                                                         CopiesAndBlittingTestCase       (tcu::TestContext&                      testCtx,
498                                                                                                                  const std::string&                     name,
499                                                                                                                  const std::string&                     description)
500                                                                 : vkt::TestCase (testCtx, name, description)
501                                                         {}
502
503         virtual TestInstance*   createInstance                          (Context&                                       context) const = 0;
504 };
505
506 void CopiesAndBlittingTestInstance::readImageAspect (vk::VkImage                                        image,
507                                                                                                          const tcu::PixelBufferAccess&  dst)
508 {
509         const DeviceInterface&          vk                                      = m_context.getDeviceInterface();
510         const VkDevice                          device                          = m_context.getDevice();
511         const VkQueue                           queue                           = m_context.getUniversalQueue();
512         Allocator&                                      allocator                       = m_context.getDefaultAllocator();
513
514         Move<VkBuffer>                          buffer;
515         de::MovePtr<Allocation>         bufferAlloc;
516         Move<VkCommandBuffer>           cmdBuffer;
517         const deUint32                          queueFamilyIndex        = m_context.getUniversalQueueFamilyIndex();
518         const VkDeviceSize                      pixelDataSize           = calculateSize(dst);
519
520         // Create destination buffer
521         {
522                 const VkBufferCreateInfo                        bufferParams                    =
523                 {
524                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
525                         DE_NULL,                                                                        // const void*                  pNext;
526                         0u,                                                                                     // VkBufferCreateFlags  flags;
527                         pixelDataSize,                                                          // VkDeviceSize                 size;
528                         VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // VkBufferUsageFlags   usage;
529                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
530                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
531                         &queueFamilyIndex,                                                      // const deUint32*              pQueueFamilyIndices;
532                 };
533
534                 buffer          = createBuffer(vk, device, &bufferParams);
535                 bufferAlloc     = allocator.allocate(getBufferMemoryRequirements(vk, device, *buffer), MemoryRequirement::HostVisible);
536                 VK_CHECK(vk.bindBufferMemory(device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
537         }
538
539         // Create command pool and buffer
540         {
541                 const VkCommandBufferAllocateInfo       cmdBufferAllocateInfo   =
542                 {
543                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType                      sType;
544                         DE_NULL,                                                                                // const void*                          pNext;
545                         *m_cmdPool,                                                                             // VkCommandPool                        commandPool;
546                         VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                // VkCommandBufferLevel         level;
547                         1u                                                                                              // deUint32                                     bufferCount;
548                 };
549
550                 cmdBuffer       = allocateCommandBuffer(vk, device, &cmdBufferAllocateInfo);
551         }
552
553         // Barriers for copying image to buffer
554         const VkImageAspectFlags                                aspect                                  = getAspectFlags(dst.getFormat());
555         const VkImageMemoryBarrier                              imageBarrier                    =
556         {
557                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
558                 DE_NULL,                                                                        // const void*                          pNext;
559                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        srcAccessMask;
560                 VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags                        dstAccessMask;
561                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        oldLayout;
562                 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // VkImageLayout                        newLayout;
563                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
564                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
565                 image,                                                                          // VkImage                                      image;
566                 {                                                                                       // VkImageSubresourceRange      subresourceRange;
567                         aspect,                                         // VkImageAspectFlags   aspectMask;
568                         0u,                                                     // deUint32                             baseMipLevel;
569                         1u,                                                     // deUint32                             mipLevels;
570                         0u,                                                     // deUint32                             baseArraySlice;
571                         1u                                                      // deUint32                             arraySize;
572                 }
573         };
574
575         const VkBufferMemoryBarrier                             bufferBarrier                   =
576         {
577                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
578                 DE_NULL,                                                                        // const void*          pNext;
579                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags        srcAccessMask;
580                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
581                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
582                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     dstQueueFamilyIndex;
583                 *buffer,                                                                        // VkBuffer                     buffer;
584                 0u,                                                                                     // VkDeviceSize         offset;
585                 pixelDataSize                                                           // VkDeviceSize         size;
586         };
587
588         const VkImageMemoryBarrier                              postImageBarrier                =
589         {
590                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
591                 DE_NULL,                                                                        // const void*                          pNext;
592                 VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags                        srcAccessMask;
593                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        dstAccessMask;
594                 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // VkImageLayout                        oldLayout;
595                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        newLayout;
596                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
597                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
598                 image,                                                                          // VkImage                                      image;
599                 {
600                         aspect,                                                                 // VkImageAspectFlags   aspectMask;
601                         0u,                                                                                     // deUint32                             baseMipLevel;
602                         1u,                                                                                     // deUint32                             mipLevels;
603                         0u,                                                                                     // deUint32                             baseArraySlice;
604                         1u,                                                                                     // deUint32                             arraySize;
605                 }                                                                                       // VkImageSubresourceRange      subresourceRange;
606         };
607
608         // Copy image to buffer
609         const VkExtent3D                        imageExtent             = { (deUint32)dst.getWidth(), (deUint32)dst.getHeight(), 1u };
610         const VkBufferImageCopy         copyRegion              =
611         {
612                 0u,                                                                     // VkDeviceSize                         bufferOffset;
613                 (deUint32)dst.getWidth(),                       // deUint32                                     bufferRowLength;
614                 (deUint32)dst.getHeight(),                      // deUint32                                     bufferImageHeight;
615                 {
616                         aspect,                                                         // VkImageAspectFlags           aspect;
617                         0u,                                                                     // deUint32                                     mipLevel;
618                         0u,                                                                     // deUint32                                     baseArrayLayer;
619                         1u,                                                                     // deUint32                                     layerCount;
620                 },                                                                      // VkImageSubresourceLayers     imageSubresource;
621                 { 0, 0, 0 },                                            // VkOffset3D                           imageOffset;
622                 imageExtent                                                     // VkExtent3D                           imageExtent;
623         };
624
625         const VkCommandBufferBeginInfo                  cmdBufferBeginInfo              =
626         {
627                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
628                 DE_NULL,                                                                                                // const void*                                          pNext;
629                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
630                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
631         };
632
633         VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
634         vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
635         vk.cmdCopyImageToBuffer(*cmdBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, 1u, &copyRegion);
636         vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT|VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 1, &postImageBarrier);
637         VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
638
639         const VkSubmitInfo                                              submitInfo                              =
640         {
641                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
642                 DE_NULL,                                                // const void*                          pNext;
643                 0u,                                                             // deUint32                                     waitSemaphoreCount;
644                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
645                 (const VkPipelineStageFlags*)DE_NULL,
646                 1u,                                                             // deUint32                                     commandBufferCount;
647                 &cmdBuffer.get(),                               // const VkCommandBuffer*       pCommandBuffers;
648                 0u,                                                             // deUint32                                     signalSemaphoreCount;
649                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
650         };
651
652         VK_CHECK(vk.resetFences(device, 1, &m_fence.get()));
653         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
654         VK_CHECK(vk.waitForFences(device, 1, &m_fence.get(), 0, ~(0ull) /* infinity */));
655
656         // Read buffer data
657         invalidateMappedMemoryRange(vk, device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), pixelDataSize);
658         tcu::copy(dst, tcu::ConstPixelBufferAccess(dst.getFormat(), dst.getSize(), bufferAlloc->getHostPtr()));
659 }
660
661 de::MovePtr<tcu::TextureLevel> CopiesAndBlittingTestInstance::readImage (vk::VkImage            image,
662                                                                                                                                                  vk::VkFormat           format,
663                                                                                                                                                  const VkExtent3D       imageSize)
664 {
665         const tcu::TextureFormat                imageFormat     = mapVkFormat(format);
666         de::MovePtr<tcu::TextureLevel>  resultLevel     (new tcu::TextureLevel(imageFormat, imageSize.width, imageSize.height, imageSize.depth));
667
668         if (tcu::isCombinedDepthStencilType(imageFormat.type))
669         {
670                 if (tcu::hasDepthComponent(imageFormat.order))
671                 {
672                         tcu::TextureLevel       depthTexture    (mapCombinedToDepthTransferFormat(imageFormat), imageSize.width, imageSize.height, imageSize.depth);
673                         readImageAspect(image, depthTexture.getAccess());
674                         tcu::copy(tcu::getEffectiveDepthStencilAccess(resultLevel->getAccess(), tcu::Sampler::MODE_DEPTH), depthTexture.getAccess());
675                 }
676
677                 if (tcu::hasStencilComponent(imageFormat.order))
678                 {
679                         tcu::TextureLevel       stencilTexture  (tcu::getEffectiveDepthStencilTextureFormat(imageFormat, tcu::Sampler::MODE_STENCIL), imageSize.width, imageSize.height, imageSize.depth);
680                         readImageAspect(image, stencilTexture.getAccess());
681                         tcu::copy(tcu::getEffectiveDepthStencilAccess(resultLevel->getAccess(), tcu::Sampler::MODE_STENCIL), stencilTexture.getAccess());
682                 }
683         }
684         else
685                 readImageAspect(image, resultLevel->getAccess());
686
687         return resultLevel;
688 }
689
690 // Copy from image to image.
691
692 class CopyImageToImage : public CopiesAndBlittingTestInstance
693 {
694 public:
695                                                                                 CopyImageToImage                        (Context&       context,
696                                                                                                                                          TestParams params);
697         virtual tcu::TestStatus                         iterate                                         (void);
698 private:
699         Move<VkImage>                                           m_source;
700         de::MovePtr<Allocation>                         m_sourceImageAlloc;
701         Move<VkImage>                                           m_destination;
702         de::MovePtr<Allocation>                         m_destinationImageAlloc;
703
704         virtual void                                            copyRegionToTextureLevel        (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
705 };
706
707 CopyImageToImage::CopyImageToImage (Context& context, TestParams params)
708         : CopiesAndBlittingTestInstance(context, params)
709 {
710         const DeviceInterface&          vk                                      = context.getDeviceInterface();
711         const VkDevice                          vkDevice                        = context.getDevice();
712         const deUint32                          queueFamilyIndex        = context.getUniversalQueueFamilyIndex();
713         Allocator&                                      memAlloc                        = context.getDefaultAllocator();
714
715         VkImageFormatProperties properties;
716         if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
717                                                                                                                                                                 m_params.src.image.format,
718                                                                                                                                                                 VK_IMAGE_TYPE_2D,
719                                                                                                                                                                 VK_IMAGE_TILING_OPTIMAL,
720                                                                                                                                                                 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
721                                                                                                                                                                 0,
722                                                                                                                                                                 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
723                 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
724                                                                                                                                                                 m_params.dst.image.format,
725                                                                                                                                                                 VK_IMAGE_TYPE_2D,
726                                                                                                                                                                 VK_IMAGE_TILING_OPTIMAL,
727                                                                                                                                                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
728                                                                                                                                                                 0,
729                                                                                                                                                                 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
730         {
731                 TCU_THROW(NotSupportedError, "Format not supported");
732         }
733
734         // Create source image
735         {
736                 const VkImageCreateInfo sourceImageParams               =
737                 {
738                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,    // VkStructureType              sType;
739                         DE_NULL,                                                                // const void*                  pNext;
740                         0u,                                                                             // VkImageCreateFlags   flags;
741                         VK_IMAGE_TYPE_2D,                                               // VkImageType                  imageType;
742                         m_params.src.image.format,                              // VkFormat                             format;
743                         m_params.src.image.extent,                              // VkExtent3D                   extent;
744                         1u,                                                                             // deUint32                             mipLevels;
745                         1u,                                                                             // deUint32                             arraySize;
746                         VK_SAMPLE_COUNT_1_BIT,                                  // deUint32                             samples;
747                         VK_IMAGE_TILING_OPTIMAL,                                // VkImageTiling                tiling;
748                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
749                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,        // VkImageUsageFlags    usage;
750                         VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
751                         1u,                                                                             // deUint32                             queueFamilyCount;
752                         &queueFamilyIndex,                                              // const deUint32*              pQueueFamilyIndices;
753                         VK_IMAGE_LAYOUT_UNDEFINED,                              // VkImageLayout                initialLayout;
754                 };
755
756                 m_source                                = createImage(vk, vkDevice, &sourceImageParams);
757                 m_sourceImageAlloc              = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
758                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
759         }
760
761         // Create destination image
762         {
763                 const VkImageCreateInfo destinationImageParams  =
764                 {
765                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,    // VkStructureType              sType;
766                         DE_NULL,                                                                // const void*                  pNext;
767                         0u,                                                                             // VkImageCreateFlags   flags;
768                         VK_IMAGE_TYPE_2D,                                               // VkImageType                  imageType;
769                         m_params.dst.image.format,                              // VkFormat                             format;
770                         m_params.dst.image.extent,                              // VkExtent3D                   extent;
771                         1u,                                                                             // deUint32                             mipLevels;
772                         1u,                                                                             // deUint32                             arraySize;
773                         VK_SAMPLE_COUNT_1_BIT,                                  // deUint32                             samples;
774                         VK_IMAGE_TILING_OPTIMAL,                                // VkImageTiling                tiling;
775                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
776                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,        // VkImageUsageFlags    usage;
777                         VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
778                         1u,                                                                             // deUint32                             queueFamilyCount;
779                         &queueFamilyIndex,                                              // const deUint32*              pQueueFamilyIndices;
780                         VK_IMAGE_LAYOUT_UNDEFINED,                              // VkImageLayout                initialLayout;
781                 };
782
783                 m_destination                   = createImage(vk, vkDevice, &destinationImageParams);
784                 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
785                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
786         }
787 }
788
789 tcu::TestStatus CopyImageToImage::iterate (void)
790 {
791         const tcu::TextureFormat        srcTcuFormat            = mapVkFormat(m_params.src.image.format);
792         const tcu::TextureFormat        dstTcuFormat            = mapVkFormat(m_params.dst.image.format);
793         m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
794                                                                                                                                                                 m_params.src.image.extent.width,
795                                                                                                                                                                 m_params.src.image.extent.height,
796                                                                                                                                                                 m_params.src.image.extent.depth));
797         generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_WHITE);
798         m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
799                                                                                                                                                                          (int)m_params.dst.image.extent.width,
800                                                                                                                                                                          (int)m_params.dst.image.extent.height,
801                                                                                                                                                                          (int)m_params.dst.image.extent.depth));
802         generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth, FILL_MODE_GRADIENT);
803         generateExpectedResult();
804
805         uploadImage(m_sourceTextureLevel->getAccess(), m_source.get());
806         uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
807
808         const DeviceInterface&          vk                                      = m_context.getDeviceInterface();
809         const VkDevice                          vkDevice                        = m_context.getDevice();
810         const VkQueue                           queue                           = m_context.getUniversalQueue();
811
812         std::vector<VkImageCopy>        imageCopies;
813         for (deUint32 i = 0; i < m_params.regions.size(); i++)
814                 imageCopies.push_back(m_params.regions[i].imageCopy);
815
816         const VkImageMemoryBarrier      imageBarriers[]         =
817         {
818                 // source image
819                 {
820                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
821                         DE_NULL,                                                                        // const void*                          pNext;
822                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        srcAccessMask;
823                         VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags                        dstAccessMask;
824                         VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        oldLayout;
825                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // VkImageLayout                        newLayout;
826                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
827                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
828                         m_source.get(),                                                         // VkImage                                      image;
829                         {                                                                                       // VkImageSubresourceRange      subresourceRange;
830                                 getAspectFlags(srcTcuFormat),   // VkImageAspectFlags   aspectMask;
831                                 0u,                                                             // deUint32                             baseMipLevel;
832                                 1u,                                                             // deUint32                             mipLevels;
833                                 0u,                                                             // deUint32                             baseArraySlice;
834                                 1u                                                              // deUint32                             arraySize;
835                         }
836                 },
837                 // destination image
838                 {
839                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
840                         DE_NULL,                                                                        // const void*                          pNext;
841                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        srcAccessMask;
842                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        dstAccessMask;
843                         VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        oldLayout;
844                         VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        newLayout;
845                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
846                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
847                         m_destination.get(),                                            // VkImage                                      image;
848                         {                                                                                       // VkImageSubresourceRange      subresourceRange;
849                                 getAspectFlags(dstTcuFormat),   // VkImageAspectFlags   aspectMask;
850                                 0u,                                                             // deUint32                             baseMipLevel;
851                                 1u,                                                             // deUint32                             mipLevels;
852                                 0u,                                                             // deUint32                             baseArraySlice;
853                                 1u                                                              // deUint32                             arraySize;
854                         }
855                 },
856         };
857
858         const VkCommandBufferBeginInfo  cmdBufferBeginInfo      =
859         {
860                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
861                 DE_NULL,                                                                                                // const void*                                          pNext;
862                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
863                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
864         };
865
866         VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
867         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, DE_LENGTH_OF_ARRAY(imageBarriers), imageBarriers);
868         vk.cmdCopyImage(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), imageCopies.data());
869         VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
870
871         const VkSubmitInfo                              submitInfo                      =
872         {
873                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
874                 DE_NULL,                                                // const void*                          pNext;
875                 0u,                                                             // deUint32                                     waitSemaphoreCount;
876                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
877                 (const VkPipelineStageFlags*)DE_NULL,
878                 1u,                                                             // deUint32                                     commandBufferCount;
879                 &m_cmdBuffer.get(),                             // const VkCommandBuffer*       pCommandBuffers;
880                 0u,                                                             // deUint32                                     signalSemaphoreCount;
881                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
882         };
883
884         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
885         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
886         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
887
888         de::MovePtr<tcu::TextureLevel>  resultTextureLevel      = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
889
890         return checkTestResult(resultTextureLevel->getAccess());
891 }
892
893 void CopyImageToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
894 {
895         VkOffset3D srcOffset    = region.imageCopy.srcOffset;
896         VkOffset3D dstOffset    = region.imageCopy.dstOffset;
897         VkExtent3D extent               = region.imageCopy.extent;
898
899         if (tcu::isCombinedDepthStencilType(src.getFormat().type))
900         {
901                 DE_ASSERT(src.getFormat() == dst.getFormat());
902                 // Copy depth.
903                 {
904                         const tcu::ConstPixelBufferAccess       srcSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
905                         const tcu::PixelBufferAccess            dstWithSrcFormat(srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
906                         const tcu::PixelBufferAccess            dstSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
907
908                         tcu::copy(dstSubRegion, srcSubRegion);
909                 }
910
911                 // Copy stencil.
912                 if (tcu::hasStencilComponent(src.getFormat().order))
913                 {
914                         const tcu::ConstPixelBufferAccess       srcSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
915                         const tcu::PixelBufferAccess            dstWithSrcFormat(srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
916                         const tcu::PixelBufferAccess            dstSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
917
918                         tcu::copy(dstSubRegion, srcSubRegion);
919                 }
920         }
921         else
922         {
923                 const tcu::ConstPixelBufferAccess       srcSubRegion            = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth);
924                 // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
925                 const tcu::PixelBufferAccess            dstWithSrcFormat        (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
926                 const tcu::PixelBufferAccess            dstSubRegion            = tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth);
927
928                 tcu::copy(dstSubRegion, srcSubRegion);
929         }
930 }
931
932 class CopyImageToImageTestCase : public vkt::TestCase
933 {
934 public:
935                                                         CopyImageToImageTestCase        (tcu::TestContext&                              testCtx,
936                                                                                                                  const std::string&                             name,
937                                                                                                                  const std::string&                             description,
938                                                                                                                  const TestParams                               params)
939                                                                 : vkt::TestCase (testCtx, name, description)
940                                                                 , m_params              (params)
941                                                         {}
942
943         virtual TestInstance*   createInstance                          (Context&                                               context) const
944                                                         {
945                                                                 return new CopyImageToImage(context, m_params);
946                                                         }
947 private:
948         TestParams                              m_params;
949 };
950
951 // Copy from buffer to buffer.
952
953 class CopyBufferToBuffer : public CopiesAndBlittingTestInstance
954 {
955 public:
956                                                                 CopyBufferToBuffer                      (Context& context, TestParams params);
957         virtual tcu::TestStatus         iterate                                         (void);
958 private:
959         virtual void                            copyRegionToTextureLevel        (tcu::ConstPixelBufferAccess, tcu::PixelBufferAccess, CopyRegion);
960         Move<VkBuffer>                          m_source;
961         de::MovePtr<Allocation>         m_sourceBufferAlloc;
962         Move<VkBuffer>                          m_destination;
963         de::MovePtr<Allocation>         m_destinationBufferAlloc;
964 };
965
966 CopyBufferToBuffer::CopyBufferToBuffer (Context& context, TestParams params)
967         : CopiesAndBlittingTestInstance (context, params)
968 {
969         const DeviceInterface&          vk                                      = context.getDeviceInterface();
970         const VkDevice                          vkDevice                        = context.getDevice();
971         const deUint32                          queueFamilyIndex        = context.getUniversalQueueFamilyIndex();
972         Allocator&                                      memAlloc                        = context.getDefaultAllocator();
973
974         // Create source buffer
975         {
976                 const VkBufferCreateInfo        sourceBufferParams              =
977                 {
978                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
979                         DE_NULL,                                                                        // const void*                  pNext;
980                         0u,                                                                                     // VkBufferCreateFlags  flags;
981                         m_params.src.buffer.size,                                       // VkDeviceSize                 size;
982                         VK_BUFFER_USAGE_TRANSFER_SRC_BIT,                       // VkBufferUsageFlags   usage;
983                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
984                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
985                         &queueFamilyIndex,                                                      // const deUint32*              pQueueFamilyIndices;
986                 };
987
988                 m_source                                = createBuffer(vk, vkDevice, &sourceBufferParams);
989                 m_sourceBufferAlloc             = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::HostVisible);
990                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
991         }
992
993         // Create destination buffer
994         {
995                 const VkBufferCreateInfo        destinationBufferParams =
996                 {
997                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
998                         DE_NULL,                                                                        // const void*                  pNext;
999                         0u,                                                                                     // VkBufferCreateFlags  flags;
1000                         m_params.dst.buffer.size,                                       // VkDeviceSize                 size;
1001                         VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // VkBufferUsageFlags   usage;
1002                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
1003                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
1004                         &queueFamilyIndex,                                                      // const deUint32*              pQueueFamilyIndices;
1005                 };
1006
1007                 m_destination                           = createBuffer(vk, vkDevice, &destinationBufferParams);
1008                 m_destinationBufferAlloc        = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::HostVisible);
1009                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
1010         }
1011 }
1012
1013 tcu::TestStatus CopyBufferToBuffer::iterate (void)
1014 {
1015         const int srcLevelWidth         = (int)(m_params.src.buffer.size/4); // Here the format is VK_FORMAT_R32_UINT, we need to divide the buffer size by 4
1016         m_sourceTextureLevel            = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), srcLevelWidth, 1));
1017         generateBuffer(m_sourceTextureLevel->getAccess(), srcLevelWidth, 1, 1, FILL_MODE_RED);
1018
1019         const int dstLevelWidth         = (int)(m_params.dst.buffer.size/4);
1020         m_destinationTextureLevel       = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
1021         generateBuffer(m_destinationTextureLevel->getAccess(), dstLevelWidth, 1, 1, FILL_MODE_WHITE);
1022
1023         generateExpectedResult();
1024
1025         uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
1026         uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
1027
1028         const DeviceInterface&          vk                      = m_context.getDeviceInterface();
1029         const VkDevice                          vkDevice        = m_context.getDevice();
1030         const VkQueue                           queue           = m_context.getUniversalQueue();
1031
1032         const VkBufferMemoryBarrier             srcBufferBarrier        =
1033         {
1034                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
1035                 DE_NULL,                                                                        // const void*          pNext;
1036                 VK_ACCESS_HOST_WRITE_BIT,                                       // VkAccessFlags        srcAccessMask;
1037                 VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags        dstAccessMask;
1038                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
1039                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     dstQueueFamilyIndex;
1040                 *m_source,                                                                      // VkBuffer                     buffer;
1041                 0u,                                                                                     // VkDeviceSize         offset;
1042                 m_params.src.buffer.size                                        // VkDeviceSize         size;
1043         };
1044
1045         const VkBufferMemoryBarrier             dstBufferBarrier        =
1046         {
1047                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
1048                 DE_NULL,                                                                        // const void*          pNext;
1049                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags        srcAccessMask;
1050                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
1051                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
1052                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     dstQueueFamilyIndex;
1053                 *m_destination,                                                         // VkBuffer                     buffer;
1054                 0u,                                                                                     // VkDeviceSize         offset;
1055                 m_params.dst.buffer.size                                        // VkDeviceSize         size;
1056         };
1057
1058         std::vector<VkBufferCopy>               bufferCopies;
1059         for (deUint32 i = 0; i < m_params.regions.size(); i++)
1060                 bufferCopies.push_back(m_params.regions[i].bufferCopy);
1061
1062         const VkCommandBufferBeginInfo  cmdBufferBeginInfo      =
1063         {
1064                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
1065                 DE_NULL,                                                                                                // const void*                                          pNext;
1066                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
1067                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1068         };
1069
1070         VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1071         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &srcBufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1072         vk.cmdCopyBuffer(*m_cmdBuffer, m_source.get(), m_destination.get(), (deUint32)m_params.regions.size(), &bufferCopies[0]);
1073         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &dstBufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1074         VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1075
1076         const VkSubmitInfo                              submitInfo                      =
1077         {
1078                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
1079                 DE_NULL,                                                // const void*                          pNext;
1080                 0u,                                                             // deUint32                                     waitSemaphoreCount;
1081                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
1082                 (const VkPipelineStageFlags*)DE_NULL,
1083                 1u,                                                             // deUint32                                     commandBufferCount;
1084                 &m_cmdBuffer.get(),                             // const VkCommandBuffer*       pCommandBuffers;
1085                 0u,                                                             // deUint32                                     signalSemaphoreCount;
1086                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
1087         };
1088
1089         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1090         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1091         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1092
1093         // Read buffer data
1094         de::MovePtr<tcu::TextureLevel>  resultLevel             (new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
1095         invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_params.dst.buffer.size);
1096         tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1097
1098         return checkTestResult(resultLevel->getAccess());
1099 }
1100
1101 void CopyBufferToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1102 {
1103         deMemcpy((deUint8*) dst.getDataPtr() + region.bufferCopy.dstOffset,
1104                          (deUint8*) src.getDataPtr() + region.bufferCopy.srcOffset,
1105                          (size_t)region.bufferCopy.size);
1106 }
1107
1108 class BufferToBufferTestCase : public vkt::TestCase
1109 {
1110 public:
1111                                                         BufferToBufferTestCase  (tcu::TestContext&      testCtx,
1112                                                                                                          const std::string&     name,
1113                                                                                                          const std::string&     description,
1114                                                                                                          const TestParams       params)
1115                                                                 : vkt::TestCase (testCtx, name, description)
1116                                                                 , m_params              (params)
1117                                                         {}
1118
1119         virtual TestInstance*   createInstance                  (Context& context) const
1120                                                         {
1121                                                                 return new CopyBufferToBuffer(context, m_params);
1122                                                         }
1123 private:
1124         TestParams                              m_params;
1125 };
1126
1127 // Copy from image to buffer.
1128
1129 class CopyImageToBuffer : public CopiesAndBlittingTestInstance
1130 {
1131 public:
1132                                                                 CopyImageToBuffer                       (Context&       context,
1133                                                                                                                          TestParams     testParams);
1134         virtual tcu::TestStatus         iterate                                         (void);
1135 private:
1136         virtual void                            copyRegionToTextureLevel        (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1137
1138         tcu::TextureFormat                      m_textureFormat;
1139         VkDeviceSize                            m_bufferSize;
1140
1141         Move<VkImage>                           m_source;
1142         de::MovePtr<Allocation>         m_sourceImageAlloc;
1143         Move<VkBuffer>                          m_destination;
1144         de::MovePtr<Allocation>         m_destinationBufferAlloc;
1145 };
1146
1147 CopyImageToBuffer::CopyImageToBuffer (Context& context, TestParams testParams)
1148         : CopiesAndBlittingTestInstance(context, testParams)
1149         , m_textureFormat(mapVkFormat(testParams.src.image.format))
1150         , m_bufferSize(m_params.dst.buffer.size * tcu::getPixelSize(m_textureFormat))
1151 {
1152         const DeviceInterface&          vk                                      = context.getDeviceInterface();
1153         const VkDevice                          vkDevice                        = context.getDevice();
1154         const deUint32                          queueFamilyIndex        = context.getUniversalQueueFamilyIndex();
1155         Allocator&                                      memAlloc                        = context.getDefaultAllocator();
1156
1157         // Create source image
1158         {
1159                 const VkImageCreateInfo         sourceImageParams               =
1160                 {
1161                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,    // VkStructureType              sType;
1162                         DE_NULL,                                                                // const void*                  pNext;
1163                         0u,                                                                             // VkImageCreateFlags   flags;
1164                         VK_IMAGE_TYPE_2D,                                               // VkImageType                  imageType;
1165                         m_params.src.image.format,                              // VkFormat                             format;
1166                         m_params.src.image.extent,                              // VkExtent3D                   extent;
1167                         1u,                                                                             // deUint32                             mipLevels;
1168                         1u,                                                                             // deUint32                             arraySize;
1169                         VK_SAMPLE_COUNT_1_BIT,                                  // deUint32                             samples;
1170                         VK_IMAGE_TILING_OPTIMAL,                                // VkImageTiling                tiling;
1171                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1172                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,        // VkImageUsageFlags    usage;
1173                         VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
1174                         1u,                                                                             // deUint32                             queueFamilyCount;
1175                         &queueFamilyIndex,                                              // const deUint32*              pQueueFamilyIndices;
1176                         VK_IMAGE_LAYOUT_UNDEFINED,                              // VkImageLayout                initialLayout;
1177                 };
1178
1179                 m_source                        = createImage(vk, vkDevice, &sourceImageParams);
1180                 m_sourceImageAlloc      = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
1181                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1182         }
1183
1184         // Create destination buffer
1185         {
1186                 const VkBufferCreateInfo        destinationBufferParams =
1187                 {
1188                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
1189                         DE_NULL,                                                                        // const void*                  pNext;
1190                         0u,                                                                                     // VkBufferCreateFlags  flags;
1191                         m_bufferSize,                                                           // VkDeviceSize                 size;
1192                         VK_BUFFER_USAGE_TRANSFER_DST_BIT,                       // VkBufferUsageFlags   usage;
1193                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
1194                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
1195                         &queueFamilyIndex,                                                      // const deUint32*              pQueueFamilyIndices;
1196                 };
1197
1198                 m_destination                           = createBuffer(vk, vkDevice, &destinationBufferParams);
1199                 m_destinationBufferAlloc        = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::HostVisible);
1200                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
1201         }
1202 }
1203
1204 tcu::TestStatus CopyImageToBuffer::iterate (void)
1205 {
1206         m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1207                                                                                                                                                                 m_params.src.image.extent.width,
1208                                                                                                                                                                 m_params.src.image.extent.height,
1209                                                                                                                                                                 m_params.src.image.extent.depth));
1210         generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_RED);
1211         m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1212         generateBuffer(m_destinationTextureLevel->getAccess(), (int)m_params.dst.buffer.size, 1, 1);
1213
1214         generateExpectedResult();
1215
1216         uploadImage(m_sourceTextureLevel->getAccess(), *m_source);
1217         uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
1218
1219         const DeviceInterface&          vk                      = m_context.getDeviceInterface();
1220         const VkDevice                          vkDevice        = m_context.getDevice();
1221         const VkQueue                           queue           = m_context.getUniversalQueue();
1222
1223         // Barriers for copying image to buffer
1224         const VkImageMemoryBarrier              imageBarrier            =
1225         {
1226                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
1227                 DE_NULL,                                                                        // const void*                          pNext;
1228                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        srcAccessMask;
1229                 VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags                        dstAccessMask;
1230                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        oldLayout;
1231                 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // VkImageLayout                        newLayout;
1232                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
1233                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
1234                 *m_source,                                                                      // VkImage                                      image;
1235                 {                                                                                       // VkImageSubresourceRange      subresourceRange;
1236                         getAspectFlags(m_textureFormat),        // VkImageAspectFlags   aspectMask;
1237                         0u,                                                             // deUint32                             baseMipLevel;
1238                         1u,                                                             // deUint32                             mipLevels;
1239                         0u,                                                             // deUint32                             baseArraySlice;
1240                         1u                                                              // deUint32                             arraySize;
1241                 }
1242         };
1243
1244         const VkBufferMemoryBarrier             bufferBarrier           =
1245         {
1246                 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,        // VkStructureType      sType;
1247                 DE_NULL,                                                                        // const void*          pNext;
1248                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags        srcAccessMask;
1249                 VK_ACCESS_HOST_READ_BIT,                                        // VkAccessFlags        dstAccessMask;
1250                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     srcQueueFamilyIndex;
1251                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                     dstQueueFamilyIndex;
1252                 *m_destination,                                                         // VkBuffer                     buffer;
1253                 0u,                                                                                     // VkDeviceSize         offset;
1254                 m_bufferSize                                                            // VkDeviceSize         size;
1255         };
1256
1257         // Copy from image to buffer
1258         std::vector<VkBufferImageCopy>  bufferImageCopies;
1259         for (deUint32 i = 0; i < m_params.regions.size(); i++)
1260                 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1261
1262         const VkCommandBufferBeginInfo  cmdBufferBeginInfo      =
1263         {
1264                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
1265                 DE_NULL,                                                                                                // const void*                                          pNext;
1266                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
1267                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1268         };
1269
1270         VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1271         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
1272         vk.cmdCopyImageToBuffer(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), (deUint32)m_params.regions.size(), &bufferImageCopies[0]);
1273         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1274         VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1275
1276         const VkSubmitInfo                              submitInfo                      =
1277         {
1278                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
1279                 DE_NULL,                                                // const void*                          pNext;
1280                 0u,                                                             // deUint32                                     waitSemaphoreCount;
1281                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
1282                 (const VkPipelineStageFlags*)DE_NULL,
1283                 1u,                                                             // deUint32                                     commandBufferCount;
1284                 &m_cmdBuffer.get(),                             // const VkCommandBuffer*       pCommandBuffers;
1285                 0u,                                                             // deUint32                                     signalSemaphoreCount;
1286                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
1287         };
1288
1289         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1290         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1291         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1292
1293         // Read buffer data
1294         de::MovePtr<tcu::TextureLevel>  resultLevel             (new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1295         invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_bufferSize);
1296         tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1297
1298         return checkTestResult(resultLevel->getAccess());
1299 }
1300
1301 class CopyImageToBufferTestCase : public vkt::TestCase
1302 {
1303 public:
1304                                                         CopyImageToBufferTestCase       (tcu::TestContext&              testCtx,
1305                                                                                                                  const std::string&             name,
1306                                                                                                                  const std::string&             description,
1307                                                                                                                  const TestParams               params)
1308                                                                 : vkt::TestCase (testCtx, name, description)
1309                                                                 , m_params              (params)
1310                                                         {}
1311
1312         virtual TestInstance*   createInstance                          (Context&                               context) const
1313                                                         {
1314                                                                 return new CopyImageToBuffer(context, m_params);
1315                                                         }
1316 private:
1317         TestParams                              m_params;
1318 };
1319
1320 void CopyImageToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1321 {
1322         deUint32                        rowLength       = region.bufferImageCopy.bufferRowLength;
1323         if (!rowLength)
1324                 rowLength = region.bufferImageCopy.imageExtent.width;
1325
1326         deUint32                        imageHeight     = region.bufferImageCopy.bufferImageHeight;
1327         if (!imageHeight)
1328                 imageHeight = region.bufferImageCopy.imageExtent.height;
1329
1330         const int                       texelSize       = src.getFormat().getPixelSize();
1331         const VkExtent3D        extent          = region.bufferImageCopy.imageExtent;
1332         const VkOffset3D        srcOffset       = region.bufferImageCopy.imageOffset;
1333         const int                       texelOffset     = (int) region.bufferImageCopy.bufferOffset / texelSize;
1334
1335         for (deUint32 z = 0; z < extent.depth; z++)
1336         {
1337                 for (deUint32 y = 0; y < extent.height; y++)
1338                 {
1339                         int                                                                     texelIndex              = texelOffset + (z * imageHeight + y) * rowLength;
1340                         const tcu::ConstPixelBufferAccess       srcSubRegion    = tcu::getSubregion(src, srcOffset.x, srcOffset.y + y, srcOffset.z + z,
1341                                                                                                                                                                         region.bufferImageCopy.imageExtent.width, 1, 1);
1342                         const tcu::PixelBufferAccess            dstSubRegion    = tcu::getSubregion(dst, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1343                         tcu::copy(dstSubRegion, srcSubRegion);
1344                 }
1345         }
1346 }
1347
1348 // Copy from buffer to image.
1349
1350 class CopyBufferToImage : public CopiesAndBlittingTestInstance
1351 {
1352 public:
1353                                                                 CopyBufferToImage                       (Context&       context,
1354                                                                                                                          TestParams     testParams);
1355         virtual tcu::TestStatus         iterate                                         (void);
1356 private:
1357         virtual void                            copyRegionToTextureLevel        (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1358
1359         tcu::TextureFormat                      m_textureFormat;
1360         VkDeviceSize                            m_bufferSize;
1361
1362         Move<VkBuffer>                          m_source;
1363         de::MovePtr<Allocation>         m_sourceBufferAlloc;
1364         Move<VkImage>                           m_destination;
1365         de::MovePtr<Allocation>         m_destinationImageAlloc;
1366 };
1367
1368 CopyBufferToImage::CopyBufferToImage (Context& context, TestParams testParams)
1369         : CopiesAndBlittingTestInstance(context, testParams)
1370         , m_textureFormat(mapVkFormat(testParams.dst.image.format))
1371         , m_bufferSize(m_params.src.buffer.size * tcu::getPixelSize(m_textureFormat))
1372 {
1373         const DeviceInterface&          vk                                      = context.getDeviceInterface();
1374         const VkDevice                          vkDevice                        = context.getDevice();
1375         const deUint32                          queueFamilyIndex        = context.getUniversalQueueFamilyIndex();
1376         Allocator&                                      memAlloc                        = context.getDefaultAllocator();
1377
1378         // Create source buffer
1379         {
1380                 const VkBufferCreateInfo        sourceBufferParams              =
1381                 {
1382                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
1383                         DE_NULL,                                                                        // const void*                  pNext;
1384                         0u,                                                                                     // VkBufferCreateFlags  flags;
1385                         m_bufferSize,                                                           // VkDeviceSize                 size;
1386                         VK_BUFFER_USAGE_TRANSFER_SRC_BIT,                       // VkBufferUsageFlags   usage;
1387                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
1388                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
1389                         &queueFamilyIndex,                                                      // const deUint32*              pQueueFamilyIndices;
1390                 };
1391
1392                 m_source                                = createBuffer(vk, vkDevice, &sourceBufferParams);
1393                 m_sourceBufferAlloc             = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::HostVisible);
1394                 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
1395         }
1396
1397         // Create destination image
1398         {
1399                 const VkImageCreateInfo         destinationImageParams  =
1400                 {
1401                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,    // VkStructureType              sType;
1402                         DE_NULL,                                                                // const void*                  pNext;
1403                         0u,                                                                             // VkImageCreateFlags   flags;
1404                         VK_IMAGE_TYPE_2D,                                               // VkImageType                  imageType;
1405                         m_params.dst.image.format,                              // VkFormat                             format;
1406                         m_params.dst.image.extent,                              // VkExtent3D                   extent;
1407                         1u,                                                                             // deUint32                             mipLevels;
1408                         1u,                                                                             // deUint32                             arraySize;
1409                         VK_SAMPLE_COUNT_1_BIT,                                  // deUint32                             samples;
1410                         VK_IMAGE_TILING_OPTIMAL,                                // VkImageTiling                tiling;
1411                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1412                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,        // VkImageUsageFlags    usage;
1413                         VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
1414                         1u,                                                                             // deUint32                             queueFamilyCount;
1415                         &queueFamilyIndex,                                              // const deUint32*              pQueueFamilyIndices;
1416                         VK_IMAGE_LAYOUT_UNDEFINED,                              // VkImageLayout                initialLayout;
1417                 };
1418
1419                 m_destination                   = createImage(vk, vkDevice, &destinationImageParams);
1420                 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
1421                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1422         }
1423 }
1424
1425 tcu::TestStatus CopyBufferToImage::iterate (void)
1426 {
1427         m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.src.buffer.size, 1));
1428         generateBuffer(m_sourceTextureLevel->getAccess(), (int)m_params.src.buffer.size, 1, 1);
1429         m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1430                                                                                                                                                                         m_params.dst.image.extent.width,
1431                                                                                                                                                                         m_params.dst.image.extent.height,
1432                                                                                                                                                                         m_params.dst.image.extent.depth));
1433
1434         generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth, FILL_MODE_WHITE);
1435
1436         generateExpectedResult();
1437
1438         uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
1439         uploadImage(m_destinationTextureLevel->getAccess(), *m_destination);
1440
1441         const DeviceInterface&          vk                      = m_context.getDeviceInterface();
1442         const VkDevice                          vkDevice        = m_context.getDevice();
1443         const VkQueue                           queue           = m_context.getUniversalQueue();
1444
1445         const VkImageMemoryBarrier      imageBarrier    =
1446         {
1447                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
1448                 DE_NULL,                                                                        // const void*                          pNext;
1449                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        srcAccessMask;
1450                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        dstAccessMask;
1451                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        oldLayout;
1452                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        newLayout;
1453                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
1454                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
1455                 *m_destination,                                                         // VkImage                                      image;
1456                 {                                                                                       // VkImageSubresourceRange      subresourceRange;
1457                         getAspectFlags(m_textureFormat),        // VkImageAspectFlags   aspectMask;
1458                         0u,                                                             // deUint32                             baseMipLevel;
1459                         1u,                                                             // deUint32                             mipLevels;
1460                         0u,                                                             // deUint32                             baseArraySlice;
1461                         1u                                                              // deUint32                             arraySize;
1462                 }
1463         };
1464
1465         // Copy from buffer to image
1466         std::vector<VkBufferImageCopy>          bufferImageCopies;
1467         for (deUint32 i = 0; i < m_params.regions.size(); i++)
1468                 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1469
1470         const VkCommandBufferBeginInfo  cmdBufferBeginInfo      =
1471         {
1472                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
1473                 DE_NULL,                                                                                                // const void*                                          pNext;
1474                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
1475                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1476         };
1477
1478         VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1479         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
1480         vk.cmdCopyBufferToImage(*m_cmdBuffer, m_source.get(), m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), bufferImageCopies.data());
1481         VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1482
1483         const VkSubmitInfo                              submitInfo                      =
1484         {
1485                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
1486                 DE_NULL,                                                // const void*                          pNext;
1487                 0u,                                                             // deUint32                                     waitSemaphoreCount;
1488                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
1489                 (const VkPipelineStageFlags*)DE_NULL,
1490                 1u,                                                             // deUint32                                     commandBufferCount;
1491                 &m_cmdBuffer.get(),                             // const VkCommandBuffer*       pCommandBuffers;
1492                 0u,                                                             // deUint32                                     signalSemaphoreCount;
1493                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
1494         };
1495
1496         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1497         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1498         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1499
1500         de::MovePtr<tcu::TextureLevel>  resultLevel     = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
1501
1502         return checkTestResult(resultLevel->getAccess());
1503 }
1504
1505 class CopyBufferToImageTestCase : public vkt::TestCase
1506 {
1507 public:
1508                                                         CopyBufferToImageTestCase       (tcu::TestContext&              testCtx,
1509                                                                                                                  const std::string&             name,
1510                                                                                                                  const std::string&             description,
1511                                                                                                                  const TestParams               params)
1512                                                                 : vkt::TestCase (testCtx, name, description)
1513                                                                 , m_params              (params)
1514                                                         {}
1515
1516         virtual                                 ~CopyBufferToImageTestCase      (void) {}
1517
1518         virtual TestInstance*   createInstance                          (Context&                               context) const
1519                                                         {
1520                                                                 return new CopyBufferToImage(context, m_params);
1521                                                         }
1522 private:
1523         TestParams                              m_params;
1524 };
1525
1526 void CopyBufferToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1527 {
1528         deUint32                        rowLength       = region.bufferImageCopy.bufferRowLength;
1529         if (!rowLength)
1530                 rowLength = region.bufferImageCopy.imageExtent.width;
1531
1532         deUint32                        imageHeight     = region.bufferImageCopy.bufferImageHeight;
1533         if (!imageHeight)
1534                 imageHeight = region.bufferImageCopy.imageExtent.height;
1535
1536         const int                       texelSize       = dst.getFormat().getPixelSize();
1537         const VkExtent3D        extent          = region.bufferImageCopy.imageExtent;
1538         const VkOffset3D        dstOffset       = region.bufferImageCopy.imageOffset;
1539         const int                       texelOffset     = (int) region.bufferImageCopy.bufferOffset / texelSize;
1540
1541         for (deUint32 z = 0; z < extent.depth; z++)
1542         {
1543                 for (deUint32 y = 0; y < extent.height; y++)
1544                 {
1545                         int                                                                     texelIndex              = texelOffset + (z * imageHeight + y) * rowLength;
1546                         const tcu::ConstPixelBufferAccess       srcSubRegion    = tcu::getSubregion(src, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1547                         const tcu::PixelBufferAccess            dstSubRegion    = tcu::getSubregion(dst, dstOffset.x, dstOffset.y + y, dstOffset.z + z,
1548                                                                                                                                                                         region.bufferImageCopy.imageExtent.width, 1, 1);
1549                         tcu::copy(dstSubRegion, srcSubRegion);
1550                 }
1551         }
1552 }
1553
1554 // Copy from image to image with scaling.
1555
1556 class BlittingImages : public CopiesAndBlittingTestInstance
1557 {
1558 public:
1559                                                                                 BlittingImages                                  (Context&       context,
1560                                                                                                                                                  TestParams params);
1561         virtual tcu::TestStatus                         iterate                                                 (void);
1562 protected:
1563         virtual tcu::TestStatus                         checkTestResult                                 (tcu::ConstPixelBufferAccess result);
1564         virtual void                                            copyRegionToTextureLevel                (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1565         virtual void                                            generateExpectedResult                  (void);
1566 private:
1567         bool                                                            checkClampedAndUnclampedResult  (const tcu::ConstPixelBufferAccess&     result,
1568                                                                                                                                                  const tcu::ConstPixelBufferAccess&     clampedReference,
1569                                                                                                                                                  const tcu::ConstPixelBufferAccess&     unclampedReference,
1570                                                                                                                                                  VkImageAspectFlagBits                          aspect);
1571         Move<VkImage>                                           m_source;
1572         de::MovePtr<Allocation>                         m_sourceImageAlloc;
1573         Move<VkImage>                                           m_destination;
1574         de::MovePtr<Allocation>                         m_destinationImageAlloc;
1575
1576         de::MovePtr<tcu::TextureLevel>          m_unclampedExpectedTextureLevel;
1577 };
1578
1579 BlittingImages::BlittingImages (Context& context, TestParams params)
1580         : CopiesAndBlittingTestInstance(context, params)
1581 {
1582         const DeviceInterface&          vk                                      = context.getDeviceInterface();
1583         const VkDevice                          vkDevice                        = context.getDevice();
1584         const deUint32                          queueFamilyIndex        = context.getUniversalQueueFamilyIndex();
1585         Allocator&                                      memAlloc                        = context.getDefaultAllocator();
1586
1587         VkImageFormatProperties properties;
1588         if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1589                                                                                                                                                                 m_params.src.image.format,
1590                                                                                                                                                                 VK_IMAGE_TYPE_2D,
1591                                                                                                                                                                 VK_IMAGE_TILING_OPTIMAL,
1592                                                                                                                                                                 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
1593                                                                                                                                                                 0,
1594                                                                                                                                                                 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
1595                 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1596                                                                                                                                                                 m_params.dst.image.format,
1597                                                                                                                                                                 VK_IMAGE_TYPE_2D,
1598                                                                                                                                                                 VK_IMAGE_TILING_OPTIMAL,
1599                                                                                                                                                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1600                                                                                                                                                                 0,
1601                                                                                                                                                                 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
1602         {
1603                 TCU_THROW(NotSupportedError, "Format not supported");
1604         }
1605
1606         VkFormatProperties srcFormatProperties;
1607         context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.src.image.format, &srcFormatProperties);
1608         if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
1609         {
1610                 TCU_THROW(NotSupportedError, "Format feature blit source not supported");
1611         }
1612
1613         VkFormatProperties dstFormatProperties;
1614         context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.dst.image.format, &dstFormatProperties);
1615         if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
1616         {
1617                 TCU_THROW(NotSupportedError, "Format feature blit destination not supported");
1618         }
1619
1620         if (m_params.filter == VK_FILTER_LINEAR)
1621         {
1622                 if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1623                         TCU_THROW(NotSupportedError, "Source format feature sampled image filter linear not supported");
1624                 if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1625                         TCU_THROW(NotSupportedError, "Destination format feature sampled image filter linear not supported");
1626         }
1627
1628         // Create source image
1629         {
1630                 const VkImageCreateInfo         sourceImageParams               =
1631                 {
1632                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,    // VkStructureType              sType;
1633                         DE_NULL,                                                                // const void*                  pNext;
1634                         0u,                                                                             // VkImageCreateFlags   flags;
1635                         VK_IMAGE_TYPE_2D,                                               // VkImageType                  imageType;
1636                         m_params.src.image.format,                              // VkFormat                             format;
1637                         m_params.src.image.extent,                              // VkExtent3D                   extent;
1638                         1u,                                                                             // deUint32                             mipLevels;
1639                         1u,                                                                             // deUint32                             arraySize;
1640                         VK_SAMPLE_COUNT_1_BIT,                                  // deUint32                             samples;
1641                         VK_IMAGE_TILING_OPTIMAL,                                // VkImageTiling                tiling;
1642                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1643                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,        // VkImageUsageFlags    usage;
1644                         VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
1645                         1u,                                                                             // deUint32                             queueFamilyCount;
1646                         &queueFamilyIndex,                                              // const deUint32*              pQueueFamilyIndices;
1647                         VK_IMAGE_LAYOUT_UNDEFINED,                              // VkImageLayout                initialLayout;
1648                 };
1649
1650                 m_source = createImage(vk, vkDevice, &sourceImageParams);
1651                 m_sourceImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
1652                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1653         }
1654
1655         // Create destination image
1656         {
1657                 const VkImageCreateInfo         destinationImageParams  =
1658                 {
1659                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,    // VkStructureType              sType;
1660                         DE_NULL,                                                                // const void*                  pNext;
1661                         0u,                                                                             // VkImageCreateFlags   flags;
1662                         VK_IMAGE_TYPE_2D,                                               // VkImageType                  imageType;
1663                         m_params.dst.image.format,                              // VkFormat                             format;
1664                         m_params.dst.image.extent,                              // VkExtent3D                   extent;
1665                         1u,                                                                             // deUint32                             mipLevels;
1666                         1u,                                                                             // deUint32                             arraySize;
1667                         VK_SAMPLE_COUNT_1_BIT,                                  // deUint32                             samples;
1668                         VK_IMAGE_TILING_OPTIMAL,                                // VkImageTiling                tiling;
1669                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1670                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,        // VkImageUsageFlags    usage;
1671                         VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
1672                         1u,                                                                             // deUint32                             queueFamilyCount;
1673                         &queueFamilyIndex,                                              // const deUint32*              pQueueFamilyIndices;
1674                         VK_IMAGE_LAYOUT_UNDEFINED,                              // VkImageLayout                initialLayout;
1675                 };
1676
1677                 m_destination = createImage(vk, vkDevice, &destinationImageParams);
1678                 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
1679                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1680         }
1681 }
1682
1683 tcu::TestStatus BlittingImages::iterate (void)
1684 {
1685         const tcu::TextureFormat        srcTcuFormat            = mapVkFormat(m_params.src.image.format);
1686         const tcu::TextureFormat        dstTcuFormat            = mapVkFormat(m_params.dst.image.format);
1687         m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
1688                                                                                                                                                                 m_params.src.image.extent.width,
1689                                                                                                                                                                 m_params.src.image.extent.height,
1690                                                                                                                                                                 m_params.src.image.extent.depth));
1691         generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_GRADIENT);
1692         m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
1693                                                                                                                                                                          (int)m_params.dst.image.extent.width,
1694                                                                                                                                                                          (int)m_params.dst.image.extent.height,
1695                                                                                                                                                                          (int)m_params.dst.image.extent.depth));
1696         generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth, FILL_MODE_WHITE);
1697         generateExpectedResult();
1698
1699         uploadImage(m_sourceTextureLevel->getAccess(), m_source.get());
1700         uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
1701
1702         const DeviceInterface&          vk                                      = m_context.getDeviceInterface();
1703         const VkDevice                          vkDevice                        = m_context.getDevice();
1704         const VkQueue                           queue                           = m_context.getUniversalQueue();
1705
1706         std::vector<VkImageBlit>        regions;
1707         for (deUint32 i = 0; i < m_params.regions.size(); i++)
1708                 regions.push_back(m_params.regions[i].imageBlit);
1709
1710         // Barriers for copying image to buffer
1711         const VkImageMemoryBarrier              srcImageBarrier         =
1712         {
1713                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
1714                 DE_NULL,                                                                        // const void*                          pNext;
1715                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        srcAccessMask;
1716                 VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags                        dstAccessMask;
1717                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        oldLayout;
1718                 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // VkImageLayout                        newLayout;
1719                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
1720                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
1721                 m_source.get(),                                                         // VkImage                                      image;
1722                 {                                                                                       // VkImageSubresourceRange      subresourceRange;
1723                         getAspectFlags(srcTcuFormat),   // VkImageAspectFlags   aspectMask;
1724                         0u,                                                             // deUint32                             baseMipLevel;
1725                         1u,                                                             // deUint32                             mipLevels;
1726                         0u,                                                             // deUint32                             baseArraySlice;
1727                         1u                                                              // deUint32                             arraySize;
1728                 }
1729         };
1730
1731         const VkImageMemoryBarrier              dstImageBarrier         =
1732         {
1733                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
1734                 DE_NULL,                                                                        // const void*                          pNext;
1735                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        srcAccessMask;
1736                 VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        dstAccessMask;
1737                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        oldLayout;
1738                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        newLayout;
1739                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
1740                 VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
1741                 m_destination.get(),                                            // VkImage                                      image;
1742                 {                                                                                       // VkImageSubresourceRange      subresourceRange;
1743                         getAspectFlags(dstTcuFormat),   // VkImageAspectFlags   aspectMask;
1744                         0u,                                                             // deUint32                             baseMipLevel;
1745                         1u,                                                             // deUint32                             mipLevels;
1746                         0u,                                                             // deUint32                             baseArraySlice;
1747                         1u                                                              // deUint32                             arraySize;
1748                 }
1749         };
1750
1751         const VkCommandBufferBeginInfo  cmdBufferBeginInfo      =
1752         {
1753                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
1754                 DE_NULL,                                                                                                // const void*                                          pNext;
1755                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
1756                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1757         };
1758
1759         VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1760         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &srcImageBarrier);
1761         vk.cmdBlitImage(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), &regions[0], m_params.filter);
1762         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &dstImageBarrier);
1763         VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1764
1765         const VkSubmitInfo                              submitInfo                      =
1766         {
1767                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
1768                 DE_NULL,                                                // const void*                          pNext;
1769                 0u,                                                             // deUint32                                     waitSemaphoreCount;
1770                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
1771                 (const VkPipelineStageFlags*)DE_NULL,
1772                 1u,                                                             // deUint32                                     commandBufferCount;
1773                 &m_cmdBuffer.get(),                             // const VkCommandBuffer*       pCommandBuffers;
1774                 0u,                                                             // deUint32                                     signalSemaphoreCount;
1775                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
1776         };
1777
1778         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1779         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1780         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1781
1782         de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
1783
1784         return checkTestResult(resultTextureLevel->getAccess());
1785 }
1786
1787 static float calculateFloatConversionError (int srcBits)
1788 {
1789         if (srcBits > 0)
1790         {
1791                 const int       clampedBits     = de::clamp<int>(srcBits, 0, 32);
1792                 const float     srcMaxValue     = de::max((float)(1ULL<<clampedBits) - 1.0f, 1.0f);
1793                 const float     error           = 1.0f / srcMaxValue;
1794
1795                 return de::clamp<float>(error, 0.0f, 1.0f);
1796         }
1797         else
1798                 return 1.0f;
1799 }
1800
1801 tcu::Vec4 getFormatThreshold (const tcu::TextureFormat& format)
1802 {
1803         tcu::Vec4 threshold(0.01f);
1804
1805         switch (format.type)
1806         {
1807         case tcu::TextureFormat::HALF_FLOAT:
1808                 threshold = tcu::Vec4(0.005f);
1809                 break;
1810
1811         case tcu::TextureFormat::FLOAT:
1812         case tcu::TextureFormat::FLOAT64:
1813                 threshold = tcu::Vec4(0.001f);
1814                 break;
1815
1816         case tcu::TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
1817                 threshold = tcu::Vec4(0.02f, 0.02f, 0.0625f, 1.0f);
1818                 break;
1819
1820         case tcu::TextureFormat::UNSIGNED_INT_999_E5_REV:
1821                 threshold = tcu::Vec4(0.05f, 0.05f, 0.05f, 1.0f);
1822                 break;
1823
1824         default:
1825                 const tcu::IVec4 bits = tcu::getTextureFormatMantissaBitDepth(format);
1826                 threshold = tcu::Vec4(calculateFloatConversionError(bits.x()),
1827                                       calculateFloatConversionError(bits.y()),
1828                                       calculateFloatConversionError(bits.z()),
1829                                       calculateFloatConversionError(bits.w()));
1830         }
1831
1832         // Return value matching the channel order specified by the format
1833         if (format.order == tcu::TextureFormat::BGR || format.order == tcu::TextureFormat::BGRA)
1834                 return threshold.swizzle(2, 1, 0, 3);
1835         else
1836                 return threshold;
1837 }
1838
1839 tcu::TextureFormat getFormatAspect (VkFormat format, VkImageAspectFlagBits aspect)
1840 {
1841         const tcu::TextureFormat        baseFormat      = mapVkFormat(format);
1842
1843         if (isCombinedDepthStencilType(baseFormat.type))
1844         {
1845                 if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT)
1846                         return getEffectiveDepthStencilTextureFormat(baseFormat, tcu::Sampler::MODE_DEPTH);
1847                 else if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT)
1848                         return getEffectiveDepthStencilTextureFormat(baseFormat, tcu::Sampler::MODE_STENCIL);
1849                 else
1850                         DE_FATAL("Invalid aspect");
1851         }
1852
1853         return baseFormat;
1854 }
1855
1856 bool BlittingImages::checkClampedAndUnclampedResult (const tcu::ConstPixelBufferAccess& result,
1857                                                                                                          const tcu::ConstPixelBufferAccess& clampedExpected,
1858                                                                                                          const tcu::ConstPixelBufferAccess& unclampedExpected,
1859                                                                                                          VkImageAspectFlagBits                          aspect)
1860 {
1861         tcu::TestLog&                           log                     (m_context.getTestContext().getLog());
1862         const bool                                      isLinear        = m_params.filter == VK_FILTER_LINEAR;
1863         const tcu::TextureFormat        srcFormat       = getFormatAspect(m_params.src.image.format, aspect);
1864         const tcu::TextureFormat        dstFormat       = result.getFormat();
1865         bool                                            isOk            = false;
1866
1867         DE_ASSERT(dstFormat == getFormatAspect(m_params.dst.image.format, aspect));
1868
1869         if (isLinear)
1870                 log << tcu::TestLog::Section("ClampedSourceImage", "Region with clamped edges on source image.");
1871
1872         if (isFloatFormat(dstFormat))
1873         {
1874                 const bool              srcIsSRGB       = tcu::isSRGB(srcFormat);
1875                 const tcu::Vec4 srcMaxDiff      = getFormatThreshold(srcFormat) * tcu::Vec4(srcIsSRGB ? 2 : 1);
1876                 const tcu::Vec4 dstMaxDiff      = getFormatThreshold(dstFormat);
1877                 const tcu::Vec4 threshold       = tcu::max(srcMaxDiff, dstMaxDiff);
1878
1879                 isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1880
1881                 if (isLinear)
1882                         log << tcu::TestLog::EndSection;
1883
1884                 if (!isOk && isLinear)
1885                 {
1886                         log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
1887                         isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1888                         log << tcu::TestLog::EndSection;
1889                 }
1890         }
1891         else
1892         {
1893                 tcu::UVec4      threshold;
1894                 // Calculate threshold depending on channel width of destination format.
1895                 const tcu::IVec4        bitDepth        = tcu::getTextureFormatBitDepth(dstFormat);
1896                 for (deUint32 i = 0; i < 4; ++i)
1897                         threshold[i] = de::max( (0x1 << bitDepth[i]) / 256, 1);
1898
1899                 isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1900
1901                 if (isLinear)
1902                         log << tcu::TestLog::EndSection;
1903
1904                 if (!isOk && isLinear)
1905                 {
1906                         log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
1907                         isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1908                         log << tcu::TestLog::EndSection;
1909                 }
1910         }
1911         return isOk;
1912 }
1913
1914 tcu::TestStatus BlittingImages::checkTestResult (tcu::ConstPixelBufferAccess result)
1915 {
1916         DE_ASSERT(m_params.filter == VK_FILTER_NEAREST || m_params.filter == VK_FILTER_LINEAR);
1917
1918         if (tcu::isCombinedDepthStencilType(result.getFormat().type))
1919         {
1920                 if (tcu::hasDepthComponent(result.getFormat().order))
1921                 {
1922                         const tcu::Sampler::DepthStencilMode    mode                            = tcu::Sampler::MODE_DEPTH;
1923                         const tcu::ConstPixelBufferAccess               depthResult                     = tcu::getEffectiveDepthStencilAccess(result, mode);
1924                         const tcu::ConstPixelBufferAccess               clampedExpected         = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1925                         const tcu::ConstPixelBufferAccess               unclampedExpected       = m_params.filter == VK_FILTER_LINEAR ? tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode) : tcu::ConstPixelBufferAccess();
1926
1927                         if (!checkClampedAndUnclampedResult(depthResult, clampedExpected, unclampedExpected, VK_IMAGE_ASPECT_DEPTH_BIT))
1928                         {
1929                                 return tcu::TestStatus::fail("CopiesAndBlitting test");
1930                         }
1931                 }
1932
1933                 if (tcu::hasStencilComponent(result.getFormat().order))
1934                 {
1935                         const tcu::Sampler::DepthStencilMode    mode                            = tcu::Sampler::MODE_STENCIL;
1936                         const tcu::ConstPixelBufferAccess               stencilResult           = tcu::getEffectiveDepthStencilAccess(result, mode);
1937                         const tcu::ConstPixelBufferAccess               clampedExpected         = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1938                         const tcu::ConstPixelBufferAccess               unclampedExpected       = m_params.filter == VK_FILTER_LINEAR ? tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode) : tcu::ConstPixelBufferAccess();
1939
1940                         if (!checkClampedAndUnclampedResult(stencilResult, clampedExpected, unclampedExpected, VK_IMAGE_ASPECT_STENCIL_BIT))
1941                         {
1942                                 return tcu::TestStatus::fail("CopiesAndBlitting test");
1943                         }
1944                 }
1945         }
1946         else
1947         {
1948                 if (!checkClampedAndUnclampedResult(result, m_expectedTextureLevel->getAccess(), m_params.filter == VK_FILTER_LINEAR ? m_unclampedExpectedTextureLevel->getAccess() : tcu::ConstPixelBufferAccess(), VK_IMAGE_ASPECT_COLOR_BIT))
1949                 {
1950                         return tcu::TestStatus::fail("CopiesAndBlitting test");
1951                 }
1952         }
1953
1954         return tcu::TestStatus::pass("CopiesAndBlitting test");
1955 }
1956
1957 tcu::Vec4 linearToSRGBIfNeeded (const tcu::TextureFormat& format, const tcu::Vec4& color)
1958 {
1959         return isSRGB(format) ? linearToSRGB(color) : color;
1960 }
1961
1962 void scaleFromWholeSrcBuffer (const tcu::PixelBufferAccess& dst, const tcu::ConstPixelBufferAccess& src, const VkOffset3D regionOffset, const VkOffset3D regionExtent, tcu::Sampler::FilterMode filter)
1963 {
1964         DE_ASSERT(filter == tcu::Sampler::LINEAR);
1965         DE_ASSERT(dst.getDepth() == 1 && src.getDepth() == 1);
1966
1967         tcu::Sampler sampler(tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE,
1968                                         filter, filter, 0.0f, false);
1969
1970         float sX = (float)regionExtent.x / (float)dst.getWidth();
1971         float sY = (float)regionExtent.y / (float)dst.getHeight();
1972
1973         for (int y = 0; y < dst.getHeight(); y++)
1974         for (int x = 0; x < dst.getWidth(); x++)
1975                 dst.setPixel(linearToSRGBIfNeeded(dst.getFormat(), src.sample2D(sampler, filter, (float)regionOffset.x + ((float)x+0.5f)*sX, (float)regionOffset.y + ((float)y+0.5f)*sY, 0)), x, y);
1976 }
1977
1978 void BlittingImages::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1979 {
1980         const VkOffset3D                                        srcOffset               = region.imageBlit.srcOffsets[0];
1981         const VkOffset3D                                        srcExtent               =
1982         {
1983                 region.imageBlit.srcOffsets[1].x - srcOffset.x,
1984                 region.imageBlit.srcOffsets[1].y - srcOffset.y,
1985                 region.imageBlit.srcOffsets[1].z - srcOffset.z
1986         };
1987         const VkOffset3D                                        dstOffset               = region.imageBlit.dstOffsets[0];
1988         const VkOffset3D                                        dstExtent               =
1989         {
1990                 region.imageBlit.dstOffsets[1].x - dstOffset.x,
1991                 region.imageBlit.dstOffsets[1].y - dstOffset.y,
1992                 region.imageBlit.dstOffsets[1].z - dstOffset.z
1993         };
1994         const tcu::Sampler::FilterMode          filter                  = (m_params.filter == VK_FILTER_LINEAR) ? tcu::Sampler::LINEAR : tcu::Sampler::NEAREST;
1995
1996         if (tcu::isCombinedDepthStencilType(src.getFormat().type))
1997         {
1998                 DE_ASSERT(src.getFormat() == dst.getFormat());
1999                 // Scale depth.
2000                 if (tcu::hasDepthComponent(src.getFormat().order))
2001                 {
2002                         const tcu::ConstPixelBufferAccess       srcSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_DEPTH);
2003                         const tcu::PixelBufferAccess            dstSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
2004                         tcu::scale(dstSubRegion, srcSubRegion, filter);
2005
2006                         if (filter == tcu::Sampler::LINEAR)
2007                         {
2008                                 const tcu::ConstPixelBufferAccess       depthSrc                        = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_DEPTH);
2009                                 const tcu::PixelBufferAccess            unclampedSubRegion      = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
2010                                 scaleFromWholeSrcBuffer(unclampedSubRegion, depthSrc, srcOffset, srcExtent, filter);
2011                         }
2012                 }
2013
2014                 // Scale stencil.
2015                 if (tcu::hasStencilComponent(src.getFormat().order))
2016                 {
2017                         const tcu::ConstPixelBufferAccess       srcSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_STENCIL);
2018                         const tcu::PixelBufferAccess            dstSubRegion    = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
2019                         tcu::scale(dstSubRegion, srcSubRegion, filter);
2020
2021                         if (filter == tcu::Sampler::LINEAR)
2022                         {
2023                                 const tcu::ConstPixelBufferAccess       stencilSrc                      = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_STENCIL);
2024                                 const tcu::PixelBufferAccess            unclampedSubRegion      = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
2025                                 scaleFromWholeSrcBuffer(unclampedSubRegion, stencilSrc, srcOffset, srcExtent, filter);
2026                         }
2027                 }
2028         }
2029         else
2030         {
2031                 const tcu::ConstPixelBufferAccess       srcSubRegion    = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y);
2032                 const tcu::PixelBufferAccess            dstSubRegion    = tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
2033                 tcu::scale(dstSubRegion, srcSubRegion, filter);
2034
2035                 if (filter == tcu::Sampler::LINEAR)
2036                 {
2037                         const tcu::PixelBufferAccess    unclampedSubRegion      = tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
2038                         scaleFromWholeSrcBuffer(unclampedSubRegion, src, srcOffset, srcExtent, filter);
2039                 }
2040         }
2041 }
2042
2043 void BlittingImages::generateExpectedResult (void)
2044 {
2045         const tcu::ConstPixelBufferAccess       src     = m_sourceTextureLevel->getAccess();
2046         const tcu::ConstPixelBufferAccess       dst     = m_destinationTextureLevel->getAccess();
2047
2048         m_expectedTextureLevel                  = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
2049         tcu::copy(m_expectedTextureLevel->getAccess(), dst);
2050
2051         if (m_params.filter == VK_FILTER_LINEAR)
2052         {
2053                 m_unclampedExpectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
2054                 tcu::copy(m_unclampedExpectedTextureLevel->getAccess(), dst);
2055         }
2056
2057         for (deUint32 i = 0; i < m_params.regions.size(); i++)
2058                 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), m_params.regions[i]);
2059 }
2060
2061 class BlittingTestCase : public vkt::TestCase
2062 {
2063 public:
2064                                                         BlittingTestCase                (tcu::TestContext&                              testCtx,
2065                                                                                                          const std::string&                             name,
2066                                                                                                          const std::string&                             description,
2067                                                                                                          const TestParams                               params)
2068                                                                 : vkt::TestCase (testCtx, name, description)
2069                                                                 , m_params              (params)
2070                                                         {}
2071
2072         virtual TestInstance*   createInstance                  (Context&                                               context) const
2073                                                         {
2074                                                                 return new BlittingImages(context, m_params);
2075                                                         }
2076 private:
2077         TestParams                              m_params;
2078 };
2079
2080 // Resolve image to image.
2081
2082 class ResolveImageToImage : public CopiesAndBlittingTestInstance
2083 {
2084 public:
2085                                                                                                 ResolveImageToImage                     (Context&       context,
2086                                                                                                                                                          TestParams params);
2087         virtual tcu::TestStatus                                         iterate                                         (void);
2088 protected:
2089         virtual tcu::TestStatus                                         checkTestResult                         (tcu::ConstPixelBufferAccess result);
2090 private:
2091         Move<VkImage>                                                           m_multisampledImage;
2092         de::MovePtr<Allocation>                                         m_multisampledImageAlloc;
2093
2094         Move<VkImage>                                                           m_destination;
2095         de::MovePtr<Allocation>                                         m_destinationImageAlloc;
2096
2097         virtual void                                                            copyRegionToTextureLevel        (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
2098 };
2099
2100 ResolveImageToImage::ResolveImageToImage (Context& context, TestParams params)
2101         : CopiesAndBlittingTestInstance(context, params)
2102 {
2103         const VkSampleCountFlagBits     rasterizationSamples    = m_params.samples;
2104
2105         if (!(context.getDeviceProperties().limits.framebufferColorSampleCounts & rasterizationSamples))
2106                 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
2107
2108         const DeviceInterface&          vk                                              = context.getDeviceInterface();
2109         const VkDevice                          vkDevice                                = context.getDevice();
2110         const deUint32                          queueFamilyIndex                = context.getUniversalQueueFamilyIndex();
2111         Allocator&                                      memAlloc                                = m_context.getDefaultAllocator();
2112
2113         const VkComponentMapping        componentMappingRGBA    = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
2114
2115         Move<VkImageView>                       sourceAttachmentView;
2116
2117         Move<VkRenderPass>                      renderPass;
2118         Move<VkFramebuffer>                     framebuffer;
2119
2120         Move<VkShaderModule>            vertexShaderModule;
2121         Move<VkShaderModule>            fragmentShaderModule;
2122
2123         Move<VkBuffer>                          vertexBuffer;
2124         std::vector<tcu::Vec4>          vertices;
2125         de::MovePtr<Allocation>         vertexBufferAlloc;
2126
2127         Move<VkPipelineLayout>          pipelineLayout;
2128         Move<VkPipeline>                        graphicsPipeline;
2129
2130         Move<VkCommandPool>                     cmdPool;
2131         Move<VkCommandBuffer>           cmdBuffer;
2132
2133         Move<VkFence>                           fence;
2134
2135         VkImageFormatProperties properties;
2136         if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2137                                                                                                                                                                 m_params.src.image.format,
2138                                                                                                                                                                 VK_IMAGE_TYPE_2D,
2139                                                                                                                                                                 VK_IMAGE_TILING_OPTIMAL,
2140                                                                                                                                                                 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
2141                                                                                                                                                                 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
2142                 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2143                                                                                                                                                                 m_params.dst.image.format,
2144                                                                                                                                                                 VK_IMAGE_TYPE_2D,
2145                                                                                                                                                                 VK_IMAGE_TILING_OPTIMAL,
2146                                                                                                                                                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
2147                                                                                                                                                                 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
2148         {
2149                 TCU_THROW(NotSupportedError, "Format not supported");
2150         }
2151
2152         // Create color image.
2153         {
2154                 const VkImageCreateInfo colorImageParams        =
2155                 {
2156                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,                                                                            // VkStructureType                      sType;
2157                         DE_NULL,                                                                                                                                        // const void*                          pNext;
2158                         0u,                                                                                                                                                     // VkImageCreateFlags           flags;
2159                         VK_IMAGE_TYPE_2D,                                                                                                                       // VkImageType                          imageType;
2160                         m_params.src.image.format,                                                                                                      // VkFormat                                     format;
2161                         m_params.src.image.extent,                                                                                                      // VkExtent3D                           extent;
2162                         1u,                                                                                                                                                     // deUint32                                     mipLevels;
2163                         1u,                                                                                                                                                     // deUint32                                     arrayLayers;
2164                         rasterizationSamples,                                                                                                           // VkSampleCountFlagBits        samples;
2165                         VK_IMAGE_TILING_OPTIMAL,                                                                                                        // VkImageTiling                        tiling;
2166                         VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT,          // VkImageUsageFlags            usage;
2167                         VK_SHARING_MODE_EXCLUSIVE,                                                                                                      // VkSharingMode                        sharingMode;
2168                         1u,                                                                                                                                                     // deUint32                                     queueFamilyIndexCount;
2169                         &queueFamilyIndex,                                                                                                                      // const deUint32*                      pQueueFamilyIndices;
2170                         VK_IMAGE_LAYOUT_UNDEFINED,                                                                                                      // VkImageLayout                        initialLayout;
2171                 };
2172
2173                 m_multisampledImage                     = createImage(vk, vkDevice, &colorImageParams);
2174
2175                 // Allocate and bind color image memory.
2176                 m_multisampledImageAlloc                = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_multisampledImage), MemoryRequirement::Any);
2177                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_multisampledImage, m_multisampledImageAlloc->getMemory(), m_multisampledImageAlloc->getOffset()));
2178         }
2179
2180         // Create destination image.
2181         {
2182                 const VkImageCreateInfo destinationImageParams  =
2183                 {
2184                         VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,    // VkStructureType              sType;
2185                         DE_NULL,                                                                // const void*                  pNext;
2186                         0u,                                                                             // VkImageCreateFlags   flags;
2187                         VK_IMAGE_TYPE_2D,                                               // VkImageType                  imageType;
2188                         m_params.dst.image.format,                              // VkFormat                             format;
2189                         m_params.dst.image.extent,                              // VkExtent3D                   extent;
2190                         1u,                                                                             // deUint32                             mipLevels;
2191                         1u,                                                                             // deUint32                             arraySize;
2192                         VK_SAMPLE_COUNT_1_BIT,                                  // deUint32                             samples;
2193                         VK_IMAGE_TILING_OPTIMAL,                                // VkImageTiling                tiling;
2194                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
2195                                 VK_IMAGE_USAGE_TRANSFER_DST_BIT,        // VkImageUsageFlags    usage;
2196                         VK_SHARING_MODE_EXCLUSIVE,                              // VkSharingMode                sharingMode;
2197                         1u,                                                                             // deUint32                             queueFamilyCount;
2198                         &queueFamilyIndex,                                              // const deUint32*              pQueueFamilyIndices;
2199                         VK_IMAGE_LAYOUT_UNDEFINED,                              // VkImageLayout                initialLayout;
2200                 };
2201
2202                 m_destination                   = createImage(vk, vkDevice, &destinationImageParams);
2203                 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
2204                 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
2205         }
2206
2207         // Create color attachment view.
2208         {
2209                 const VkImageViewCreateInfo     colorAttachmentViewParams       =
2210                 {
2211                         VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,               // VkStructureType                      sType;
2212                         DE_NULL,                                                                                // const void*                          pNext;
2213                         0u,                                                                                             // VkImageViewCreateFlags       flags;
2214                         *m_multisampledImage,                                                   // VkImage                                      image;
2215                         VK_IMAGE_VIEW_TYPE_2D,                                                  // VkImageViewType                      viewType;
2216                         m_params.src.image.format,                                              // VkFormat                                     format;
2217                         componentMappingRGBA,                                                   // VkComponentMapping           components;
2218                         { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u }   // VkImageSubresourceRange      subresourceRange;
2219                 };
2220
2221                 sourceAttachmentView    = createImageView(vk, vkDevice, &colorAttachmentViewParams);
2222         }
2223
2224         // Create render pass.
2225         {
2226                 const VkAttachmentDescription   attachmentDescriptions[1]       =
2227                 {
2228                         {
2229                                 0u,                                                                                     // VkAttachmentDescriptionFlags         flags;
2230                                 m_params.src.image.format,                                      // VkFormat                                                     format;
2231                                 rasterizationSamples,                                           // VkSampleCountFlagBits                        samples;
2232                                 VK_ATTACHMENT_LOAD_OP_CLEAR,                            // VkAttachmentLoadOp                           loadOp;
2233                                 VK_ATTACHMENT_STORE_OP_STORE,                           // VkAttachmentStoreOp                          storeOp;
2234                                 VK_ATTACHMENT_LOAD_OP_DONT_CARE,                        // VkAttachmentLoadOp                           stencilLoadOp;
2235                                 VK_ATTACHMENT_STORE_OP_DONT_CARE,                       // VkAttachmentStoreOp                          stencilStoreOp;
2236                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                                        initialLayout;
2237                                 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL        // VkImageLayout                                        finalLayout;
2238                         },
2239                 };
2240
2241                 const VkAttachmentReference             colorAttachmentReference        =
2242                 {
2243                         0u,                                                                                                     // deUint32                     attachment;
2244                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL                        // VkImageLayout        layout;
2245                 };
2246
2247                 const VkSubpassDescription              subpassDescription                      =
2248                 {
2249                         0u,                                                                     // VkSubpassDescriptionFlags    flags;
2250                         VK_PIPELINE_BIND_POINT_GRAPHICS,        // VkPipelineBindPoint                  pipelineBindPoint;
2251                         0u,                                                                     // deUint32                                             inputAttachmentCount;
2252                         DE_NULL,                                                        // const VkAttachmentReference* pInputAttachments;
2253                         1u,                                                                     // deUint32                                             colorAttachmentCount;
2254                         &colorAttachmentReference,                      // const VkAttachmentReference* pColorAttachments;
2255                         DE_NULL,                                                        // const VkAttachmentReference* pResolveAttachments;
2256                         DE_NULL,                                                        // const VkAttachmentReference* pDepthStencilAttachment;
2257                         0u,                                                                     // deUint32                                             preserveAttachmentCount;
2258                         DE_NULL                                                         // const VkAttachmentReference* pPreserveAttachments;
2259                 };
2260
2261                 const VkRenderPassCreateInfo    renderPassParams                        =
2262                 {
2263                         VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,      // VkStructureType                                      sType;
2264                         DE_NULL,                                                                        // const void*                                          pNext;
2265                         0u,                                                                                     // VkRenderPassCreateFlags                      flags;
2266                         1u,                                                                                     // deUint32                                                     attachmentCount;
2267                         attachmentDescriptions,                                         // const VkAttachmentDescription*       pAttachments;
2268                         1u,                                                                                     // deUint32                                                     subpassCount;
2269                         &subpassDescription,                                            // const VkSubpassDescription*          pSubpasses;
2270                         0u,                                                                                     // deUint32                                                     dependencyCount;
2271                         DE_NULL                                                                         // const VkSubpassDependency*           pDependencies;
2272                 };
2273
2274                 renderPass      = createRenderPass(vk, vkDevice, &renderPassParams);
2275         }
2276
2277         // Create framebuffer
2278         {
2279                 const VkImageView                               attachments[1]          =
2280                 {
2281                         *sourceAttachmentView,
2282                 };
2283
2284                 const VkFramebufferCreateInfo   framebufferParams       =
2285                 {
2286                         VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,                      // VkStructureType                              sType;
2287                         DE_NULL,                                                                                        // const void*                                  pNext;
2288                         0u,                                                                                                     // VkFramebufferCreateFlags             flags;
2289                         *renderPass,                                                                            // VkRenderPass                                 renderPass;
2290                         1u,                                                                                                     // deUint32                                             attachmentCount;
2291                         attachments,                                                                            // const VkImageView*                   pAttachments;
2292                         m_params.src.image.extent.width,                                        // deUint32                                             width;
2293                         m_params.src.image.extent.height,                                       // deUint32                                             height;
2294                         1u                                                                                                      // deUint32                                             layers;
2295                 };
2296
2297                 framebuffer     = createFramebuffer(vk, vkDevice, &framebufferParams);
2298         }
2299
2300         // Create pipeline layout
2301         {
2302                 const VkPipelineLayoutCreateInfo        pipelineLayoutParams    =
2303                 {
2304                         VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO,          // VkStructureType                                      sType;
2305                         DE_NULL,                                                                                        // const void*                                          pNext;
2306                         0u,                                                                                                     // VkPipelineLayoutCreateFlags          flags;
2307                         0u,                                                                                                     // deUint32                                                     setLayoutCount;
2308                         DE_NULL,                                                                                        // const VkDescriptorSetLayout*         pSetLayouts;
2309                         0u,                                                                                                     // deUint32                                                     pushConstantRangeCount;
2310                         DE_NULL                                                                                         // const VkPushConstantRange*           pPushConstantRanges;
2311                 };
2312
2313                 pipelineLayout  = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
2314         }
2315
2316         // Create shaders
2317         {
2318                 vertexShaderModule              = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("vert"), 0);
2319                 fragmentShaderModule    = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("frag"), 0);
2320         }
2321
2322         // Create pipeline
2323         {
2324                 const VkPipelineShaderStageCreateInfo                   shaderStageParams[2]                            =
2325                 {
2326                         {
2327                                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                                              sType;
2328                                 DE_NULL,                                                                                                        // const void*                                                  pNext;
2329                                 0u,                                                                                                                     // VkPipelineShaderStageCreateFlags             flags;
2330                                 VK_SHADER_STAGE_VERTEX_BIT,                                                                     // VkShaderStageFlagBits                                stage;
2331                                 *vertexShaderModule,                                                                            // VkShaderModule                                               module;
2332                                 "main",                                                                                                         // const char*                                                  pName;
2333                                 DE_NULL                                                                                                         // const VkSpecializationInfo*                  pSpecializationInfo;
2334                         },
2335                         {
2336                                 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO,            // VkStructureType                                              sType;
2337                                 DE_NULL,                                                                                                        // const void*                                                  pNext;
2338                                 0u,                                                                                                                     // VkPipelineShaderStageCreateFlags             flags;
2339                                 VK_SHADER_STAGE_FRAGMENT_BIT,                                                           // VkShaderStageFlagBits                                stage;
2340                                 *fragmentShaderModule,                                                                          // VkShaderModule                                               module;
2341                                 "main",                                                                                                         // const char*                                                  pName;
2342                                 DE_NULL                                                                                                         // const VkSpecializationInfo*                  pSpecializationInfo;
2343                         }
2344                 };
2345
2346                 const VkVertexInputBindingDescription                   vertexInputBindingDescription           =
2347                 {
2348                         0u,                                                                     // deUint32                             binding;
2349                         sizeof(tcu::Vec4),                                      // deUint32                             stride;
2350                         VK_VERTEX_INPUT_RATE_VERTEX                     // VkVertexInputRate    inputRate;
2351                 };
2352
2353                 const VkVertexInputAttributeDescription                 vertexInputAttributeDescriptions[1]     =
2354                 {
2355                         {
2356                                 0u,                                                                     // deUint32     location;
2357                                 0u,                                                                     // deUint32     binding;
2358                                 VK_FORMAT_R32G32B32A32_SFLOAT,          // VkFormat     format;
2359                                 0u                                                                      // deUint32     offset;
2360                         }
2361                 };
2362
2363                 const VkPipelineVertexInputStateCreateInfo              vertexInputStateParams                          =
2364                 {
2365                         VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO,              // VkStructureType                                                      sType;
2366                         DE_NULL,                                                                                                                // const void*                                                          pNext;
2367                         0u,                                                                                                                             // VkPipelineVertexInputStateCreateFlags        flags;
2368                         1u,                                                                                                                             // deUint32                                                                     vertexBindingDescriptionCount;
2369                         &vertexInputBindingDescription,                                                                 // const VkVertexInputBindingDescription*       pVertexBindingDescriptions;
2370                         1u,                                                                                                                             // deUint32                                                                     vertexAttributeDescriptionCount;
2371                         vertexInputAttributeDescriptions                                                                // const VkVertexInputAttributeDescription*     pVertexAttributeDescriptions;
2372                 };
2373
2374                 const VkPipelineInputAssemblyStateCreateInfo    inputAssemblyStateParams                        =
2375                 {
2376                         VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO,    // VkStructureType                                                      sType;
2377                         DE_NULL,                                                                                                                // const void*                                                          pNext;
2378                         0u,                                                                                                                             // VkPipelineInputAssemblyStateCreateFlags      flags;
2379                         VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,                                                    // VkPrimitiveTopology                                          topology;
2380                         false                                                                                                                   // VkBool32                                                                     primitiveRestartEnable;
2381                 };
2382
2383                 const VkViewport        viewport        =
2384                 {
2385                         0.0f,                                                                           // float        x;
2386                         0.0f,                                                                           // float        y;
2387                         (float)m_params.src.image.extent.width,         // float        width;
2388                         (float)m_params.src.image.extent.height,        // float        height;
2389                         0.0f,                                                                           // float        minDepth;
2390                         1.0f                                                                            // float        maxDepth;
2391                 };
2392
2393                 const VkRect2D          scissor         =
2394                 {
2395                         { 0, 0 },                                                                                                                               // VkOffset2D   offset;
2396                         { m_params.src.image.extent.width, m_params.src.image.extent.height }   // VkExtent2D   extent;
2397                 };
2398
2399                 const VkPipelineViewportStateCreateInfo                 viewportStateParams             =
2400                 {
2401                         VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO,                  // VkStructureType                                              sType;
2402                         DE_NULL,                                                                                                                // const void*                                                  pNext;
2403                         0u,                                                                                                                             // VkPipelineViewportStateCreateFlags   flags;
2404                         1u,                                                                                                                             // deUint32                                                             viewportCount;
2405                         &viewport,                                                                                                              // const VkViewport*                                    pViewports;
2406                         1u,                                                                                                                             // deUint32                                                             scissorCount;
2407                         &scissor                                                                                                                // const VkRect2D*                                              pScissors;
2408                 };
2409
2410                 const VkPipelineRasterizationStateCreateInfo    rasterStateParams               =
2411                 {
2412                         VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO,             // VkStructureType                                                      sType;
2413                         DE_NULL,                                                                                                                // const void*                                                          pNext;
2414                         0u,                                                                                                                             // VkPipelineRasterizationStateCreateFlags      flags;
2415                         false,                                                                                                                  // VkBool32                                                                     depthClampEnable;
2416                         false,                                                                                                                  // VkBool32                                                                     rasterizerDiscardEnable;
2417                         VK_POLYGON_MODE_FILL,                                                                                   // VkPolygonMode                                                        polygonMode;
2418                         VK_CULL_MODE_NONE,                                                                                              // VkCullModeFlags                                                      cullMode;
2419                         VK_FRONT_FACE_COUNTER_CLOCKWISE,                                                                // VkFrontFace                                                          frontFace;
2420                         VK_FALSE,                                                                                                               // VkBool32                                                                     depthBiasEnable;
2421                         0.0f,                                                                                                                   // float                                                                        depthBiasConstantFactor;
2422                         0.0f,                                                                                                                   // float                                                                        depthBiasClamp;
2423                         0.0f,                                                                                                                   // float                                                                        depthBiasSlopeFactor;
2424                         1.0f                                                                                                                    // float                                                                        lineWidth;
2425                 };
2426
2427                 const VkPipelineMultisampleStateCreateInfo      multisampleStateParams          =
2428                 {
2429                         VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO,               // VkStructureType                                                      sType;
2430                         DE_NULL,                                                                                                                // const void*                                                          pNext;
2431                         0u,                                                                                                                             // VkPipelineMultisampleStateCreateFlags        flags;
2432                         rasterizationSamples,                                                                                   // VkSampleCountFlagBits                                        rasterizationSamples;
2433                         VK_FALSE,                                                                                                               // VkBool32                                                                     sampleShadingEnable;
2434                         0.0f,                                                                                                                   // float                                                                        minSampleShading;
2435                         DE_NULL,                                                                                                                // const VkSampleMask*                                          pSampleMask;
2436                         VK_FALSE,                                                                                                               // VkBool32                                                                     alphaToCoverageEnable;
2437                         VK_FALSE                                                                                                                // VkBool32                                                                     alphaToOneEnable;
2438                 };
2439
2440                 const VkPipelineColorBlendAttachmentState       colorBlendAttachmentState       =
2441                 {
2442                         false,                                                                                                          // VkBool32                     blendEnable;
2443                         VK_BLEND_FACTOR_ONE,                                                                            // VkBlend                      srcBlendColor;
2444                         VK_BLEND_FACTOR_ZERO,                                                                           // VkBlend                      destBlendColor;
2445                         VK_BLEND_OP_ADD,                                                                                        // VkBlendOp            blendOpColor;
2446                         VK_BLEND_FACTOR_ONE,                                                                            // VkBlend                      srcBlendAlpha;
2447                         VK_BLEND_FACTOR_ZERO,                                                                           // VkBlend                      destBlendAlpha;
2448                         VK_BLEND_OP_ADD,                                                                                        // VkBlendOp            blendOpAlpha;
2449                         (VK_COLOR_COMPONENT_R_BIT |
2450                          VK_COLOR_COMPONENT_G_BIT |
2451                          VK_COLOR_COMPONENT_B_BIT |
2452                          VK_COLOR_COMPONENT_A_BIT)                                                                      // VkChannelFlags       channelWriteMask;
2453                 };
2454
2455                 const VkPipelineColorBlendStateCreateInfo       colorBlendStateParams   =
2456                 {
2457                         VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO,       // VkStructureType                                                              sType;
2458                         DE_NULL,                                                                                                        // const void*                                                                  pNext;
2459                         0u,                                                                                                                     // VkPipelineColorBlendStateCreateFlags                 flags;
2460                         false,                                                                                                          // VkBool32                                                                             logicOpEnable;
2461                         VK_LOGIC_OP_COPY,                                                                                       // VkLogicOp                                                                    logicOp;
2462                         1u,                                                                                                                     // deUint32                                                                             attachmentCount;
2463                         &colorBlendAttachmentState,                                                                     // const VkPipelineColorBlendAttachmentState*   pAttachments;
2464                         { 0.0f, 0.0f, 0.0f, 0.0f }                                                                      // float                                                                                blendConstants[4];
2465                 };
2466
2467                 const VkGraphicsPipelineCreateInfo                      graphicsPipelineParams  =
2468                 {
2469                         VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,        // VkStructureType                                                                      sType;
2470                         DE_NULL,                                                                                        // const void*                                                                          pNext;
2471                         0u,                                                                                                     // VkPipelineCreateFlags                                                        flags;
2472                         2u,                                                                                                     // deUint32                                                                                     stageCount;
2473                         shaderStageParams,                                                                      // const VkPipelineShaderStageCreateInfo*                       pStages;
2474                         &vertexInputStateParams,                                                        // const VkPipelineVertexInputStateCreateInfo*          pVertexInputState;
2475                         &inputAssemblyStateParams,                                                      // const VkPipelineInputAssemblyStateCreateInfo*        pInputAssemblyState;
2476                         DE_NULL,                                                                                        // const VkPipelineTessellationStateCreateInfo*         pTessellationState;
2477                         &viewportStateParams,                                                           // const VkPipelineViewportStateCreateInfo*                     pViewportState;
2478                         &rasterStateParams,                                                                     // const VkPipelineRasterizationStateCreateInfo*        pRasterizationState;
2479                         &multisampleStateParams,                                                        // const VkPipelineMultisampleStateCreateInfo*          pMultisampleState;
2480                         DE_NULL,                                                                                        // const VkPipelineDepthStencilStateCreateInfo*         pDepthStencilState;
2481                         &colorBlendStateParams,                                                         // const VkPipelineColorBlendStateCreateInfo*           pColorBlendState;
2482                         DE_NULL,                                                                                        // const VkPipelineDynamicStateCreateInfo*                      pDynamicState;
2483                         *pipelineLayout,                                                                        // VkPipelineLayout                                                                     layout;
2484                         *renderPass,                                                                            // VkRenderPass                                                                         renderPass;
2485                         0u,                                                                                                     // deUint32                                                                                     subpass;
2486                         0u,                                                                                                     // VkPipeline                                                                           basePipelineHandle;
2487                         0u                                                                                                      // deInt32                                                                                      basePipelineIndex;
2488                 };
2489
2490                 graphicsPipeline        = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
2491         }
2492
2493         // Create vertex buffer.
2494         {
2495                 // Create upper half triangle.
2496                 {
2497                         const tcu::Vec4 a       (-1.0, -1.0, 0.0, 1.0);
2498                         const tcu::Vec4 b       (1.0, -1.0, 0.0, 1.0);
2499                         const tcu::Vec4 c       (1.0, 1.0, 0.0, 1.0);
2500
2501                         // Add triangle.
2502                         vertices.push_back(a);
2503                         vertices.push_back(c);
2504                         vertices.push_back(b);
2505                 }
2506
2507                 const VkDeviceSize                      vertexDataSize          = vertices.size() * sizeof(tcu::Vec4);
2508                 const VkBufferCreateInfo        vertexBufferParams      =
2509                 {
2510                         VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,           // VkStructureType              sType;
2511                         DE_NULL,                                                                        // const void*                  pNext;
2512                         0u,                                                                                     // VkBufferCreateFlags  flags;
2513                         vertexDataSize,                                                         // VkDeviceSize                 size;
2514                         VK_BUFFER_USAGE_VERTEX_BUFFER_BIT,                      // VkBufferUsageFlags   usage;
2515                         VK_SHARING_MODE_EXCLUSIVE,                                      // VkSharingMode                sharingMode;
2516                         1u,                                                                                     // deUint32                             queueFamilyIndexCount;
2517                         &queueFamilyIndex                                                       // const deUint32*              pQueueFamilyIndices;
2518                 };
2519
2520                 vertexBuffer            = createBuffer(vk, vkDevice, &vertexBufferParams);
2521                 vertexBufferAlloc       = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible);
2522
2523                 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset()));
2524
2525                 // Load vertices into vertex buffer.
2526                 deMemcpy(vertexBufferAlloc->getHostPtr(), vertices.data(), (size_t)vertexDataSize);
2527                 flushMappedMemoryRange(vk, vkDevice, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset(), vertexDataSize);
2528         }
2529
2530         // Create command pool
2531         {
2532                 const VkCommandPoolCreateInfo cmdPoolParams =
2533                 {
2534                         VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,             // VkStructureType                              sType;
2535                         DE_NULL,                                                                                // const void*                                  pNext;
2536                         VK_COMMAND_POOL_CREATE_TRANSIENT_BIT,                   // VkCommandPoolCreateFlags             flags;
2537                         queueFamilyIndex,                                                               // deUint32                                             queueFamilyIndex;
2538                 };
2539
2540                 cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
2541         }
2542
2543         // Create command buffer
2544         {
2545                 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
2546                 {
2547                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType                      sType;
2548                         DE_NULL,                                                                                // const void*                          pNext;
2549                         *cmdPool,                                                                               // VkCommandPool                        commandPool;
2550                         VK_COMMAND_BUFFER_LEVEL_PRIMARY,                                // VkCommandBufferLevel level;
2551                         1u                                                                                              // deUint32                             bufferCount;
2552                 };
2553
2554                 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
2555                 {
2556                         VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,    // VkStructureType                                      sType;
2557                         DE_NULL,                                                                                // const void*                                          pNext;
2558                         0u,                                                                                             // VkCommandBufferUsageFlags            flags;
2559                         (const VkCommandBufferInheritanceInfo*)DE_NULL,
2560                 };
2561
2562                 const VkClearValue clearValue = makeClearValueColorF32(0.0f, 0.0f, 1.0f, 1.0f);
2563
2564                 const VkClearValue clearValues[1] =
2565                 {
2566                         clearValue
2567                 };
2568
2569                 const VkRenderPassBeginInfo renderPassBeginInfo =
2570                 {
2571                         VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,                               // VkStructureType              sType;
2572                         DE_NULL,                                                                                                // const void*                  pNext;
2573                         *renderPass,                                                                                    // VkRenderPass                 renderPass;
2574                         *framebuffer,                                                                                   // VkFramebuffer                framebuffer;
2575                         {
2576                                 { 0, 0 },
2577                                 { m_params.src.image.extent.width, m_params.src.image.extent.height }
2578                         },                                                                                                              // VkRect2D                             renderArea;
2579                         1u,                                                                                                             // deUint32                             clearValueCount;
2580                         clearValues                                                                                             // const VkClearValue*  pClearValues;
2581                 };
2582
2583                 // Barriers for copying image to buffer
2584                 const VkImageMemoryBarrier              srcImageBarrier         =
2585                 {
2586                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
2587                         DE_NULL,                                                                        // const void*                          pNext;
2588                         0u,                                                                                     // VkAccessFlags                        srcAccessMask;
2589                         VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,           // VkAccessFlags                        dstAccessMask;
2590                         VK_IMAGE_LAYOUT_UNDEFINED,                                      // VkImageLayout                        oldLayout;
2591                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                        newLayout;
2592                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
2593                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
2594                         m_multisampledImage.get(),                                      // VkImage                                      image;
2595                         {                                                                                       // VkImageSubresourceRange      subresourceRange;
2596                                 VK_IMAGE_ASPECT_COLOR_BIT,              // VkImageAspectFlags   aspectMask;
2597                                 0u,                                                             // deUint32                             baseMipLevel;
2598                                 1u,                                                             // deUint32                             mipLevels;
2599                                 0u,                                                             // deUint32                             baseArraySlice;
2600                                 1u                                                              // deUint32                             arraySize;
2601                         }
2602                 };
2603
2604                 cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
2605
2606                 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
2607                 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &srcImageBarrier);
2608                 vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
2609
2610                 const VkDeviceSize      vertexBufferOffset      = 0u;
2611
2612                 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *graphicsPipeline);
2613                 vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer.get(), &vertexBufferOffset);
2614                 vk.cmdDraw(*cmdBuffer, (deUint32)vertices.size(), 1, 0, 0);
2615
2616                 vk.cmdEndRenderPass(*cmdBuffer);
2617
2618                 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
2619         }
2620
2621         // Create fence
2622         {
2623                 const VkFenceCreateInfo fenceParams =
2624                 {
2625                         VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,    // VkStructureType              sType;
2626                         DE_NULL,                                                                // const void*                  pNext;
2627                         0u                                                                              // VkFenceCreateFlags   flags;
2628                 };
2629
2630                 fence = createFence(vk, vkDevice, &fenceParams);
2631         }
2632
2633         // Queue submit.
2634         {
2635                 const VkQueue                           queue           = m_context.getUniversalQueue();
2636                 const VkSubmitInfo                      submitInfo      =
2637                 {
2638                         VK_STRUCTURE_TYPE_SUBMIT_INFO,
2639                         DE_NULL,
2640                         0u,
2641                         (const VkSemaphore*)DE_NULL,
2642                         (const VkPipelineStageFlags*)DE_NULL,
2643                         1u,
2644                         &cmdBuffer.get(),
2645                         0u,
2646                         (const VkSemaphore*)DE_NULL,
2647                 };
2648
2649                 VK_CHECK(vk.resetFences(vkDevice, 1, &fence.get()));
2650                 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *fence));
2651                 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), true, ~(0ull) /* infinity */));
2652         }
2653 }
2654
2655 tcu::TestStatus ResolveImageToImage::iterate (void)
2656 {
2657         const tcu::TextureFormat                srcTcuFormat            = mapVkFormat(m_params.src.image.format);
2658         const tcu::TextureFormat                dstTcuFormat            = mapVkFormat(m_params.dst.image.format);
2659
2660         m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
2661                                                                                                                                                                 m_params.src.image.extent.width,
2662                                                                                                                                                                 m_params.src.image.extent.height,
2663                                                                                                                                                                 m_params.src.image.extent.depth));
2664         generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_MULTISAMPLE);
2665         m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
2666                                                                                                                                                                          (int)m_params.dst.image.extent.width,
2667                                                                                                                                                                          (int)m_params.dst.image.extent.height,
2668                                                                                                                                                                          (int)m_params.dst.image.extent.depth));
2669         generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth);
2670         generateExpectedResult();
2671
2672         uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
2673
2674         const DeviceInterface&                  vk                                      = m_context.getDeviceInterface();
2675         const VkDevice                                  vkDevice                        = m_context.getDevice();
2676         const VkQueue                                   queue                           = m_context.getUniversalQueue();
2677
2678         std::vector<VkImageResolve>             imageResolves;
2679         for (deUint32 i = 0; i < m_params.regions.size(); i++)
2680                 imageResolves.push_back(m_params.regions[i].imageResolve);
2681
2682         const VkImageMemoryBarrier      imageBarriers[]         =
2683         {
2684                 // source image
2685                 {
2686                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
2687                         DE_NULL,                                                                        // const void*                          pNext;
2688                         0u,                                                                                     // VkAccessFlags                        srcAccessMask;
2689                         VK_ACCESS_TRANSFER_READ_BIT,                            // VkAccessFlags                        dstAccessMask;
2690                         VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,       // VkImageLayout                        oldLayout;
2691                         VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,           // VkImageLayout                        newLayout;
2692                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
2693                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
2694                         m_multisampledImage.get(),                                      // VkImage                                      image;
2695                         {                                                                                       // VkImageSubresourceRange      subresourceRange;
2696                                 getAspectFlags(srcTcuFormat),   // VkImageAspectFlags   aspectMask;
2697                                 0u,                                                             // deUint32                             baseMipLevel;
2698                                 1u,                                                             // deUint32                             mipLevels;
2699                                 0u,                                                             // deUint32                             baseArraySlice;
2700                                 1u                                                              // deUint32                             arraySize;
2701                         }
2702                 },
2703                 // destination image
2704                 {
2705                         VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,         // VkStructureType                      sType;
2706                         DE_NULL,                                                                        // const void*                          pNext;
2707                         0u,                                                                                     // VkAccessFlags                        srcAccessMask;
2708                         VK_ACCESS_TRANSFER_WRITE_BIT,                           // VkAccessFlags                        dstAccessMask;
2709                         VK_IMAGE_LAYOUT_UNDEFINED,                                      // VkImageLayout                        oldLayout;
2710                         VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,           // VkImageLayout                        newLayout;
2711                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     srcQueueFamilyIndex;
2712                         VK_QUEUE_FAMILY_IGNORED,                                        // deUint32                                     dstQueueFamilyIndex;
2713                         m_destination.get(),                                            // VkImage                                      image;
2714                         {                                                                                       // VkImageSubresourceRange      subresourceRange;
2715                                 getAspectFlags(dstTcuFormat),   // VkImageAspectFlags   aspectMask;
2716                                 0u,                                                             // deUint32                             baseMipLevel;
2717                                 1u,                                                             // deUint32                             mipLevels;
2718                                 0u,                                                             // deUint32                             baseArraySlice;
2719                                 1u                                                              // deUint32                             arraySize;
2720                         }
2721                 },
2722         };
2723
2724         const VkImageMemoryBarrier postImageBarrier =
2725         {
2726                 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType                      sType;
2727                 DE_NULL,                                                                // const void*                          pNext;
2728                 VK_ACCESS_TRANSFER_WRITE_BIT,                   // VkAccessFlags                        srcAccessMask;
2729                 VK_ACCESS_TRANSFER_WRITE_BIT,                   // VkAccessFlags                        dstAccessMask;
2730                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,   // VkImageLayout                        oldLayout;
2731                 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,   // VkImageLayout                        newLayout;
2732                 VK_QUEUE_FAMILY_IGNORED,                                // deUint32                                     srcQueueFamilyIndex;
2733                 VK_QUEUE_FAMILY_IGNORED,                                // deUint32                                     dstQueueFamilyIndex;
2734                 m_destination.get(),                                    // VkImage                                      image;
2735                 {                                                                               // VkImageSubresourceRange      subresourceRange;
2736                         getAspectFlags(dstTcuFormat),           // VkImageAspectFlags           aspectMask;
2737                         0u,                                                                     // deUint32                                     baseMipLevel;
2738                         1u,                                                                     // deUint32                                     mipLevels;
2739                         0u,                                                                     // deUint32                                     baseArraySlice;
2740                         1u                                                                      // deUint32                                     arraySize;
2741                 }
2742         };
2743
2744         const VkCommandBufferBeginInfo  cmdBufferBeginInfo      =
2745         {
2746                 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,                    // VkStructureType                                      sType;
2747                 DE_NULL,                                                                                                // const void*                                          pNext;
2748                 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT,                    // VkCommandBufferUsageFlags            flags;
2749                 (const VkCommandBufferInheritanceInfo*)DE_NULL,
2750         };
2751
2752         VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
2753         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, DE_LENGTH_OF_ARRAY(imageBarriers), imageBarriers);
2754         vk.cmdResolveImage(*m_cmdBuffer, m_multisampledImage.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), imageResolves.data());
2755         vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &postImageBarrier);
2756         VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2757
2758         const VkSubmitInfo                              submitInfo                      =
2759         {
2760                 VK_STRUCTURE_TYPE_SUBMIT_INFO,  // VkStructureType                      sType;
2761                 DE_NULL,                                                // const void*                          pNext;
2762                 0u,                                                             // deUint32                                     waitSemaphoreCount;
2763                 DE_NULL,                                                // const VkSemaphore*           pWaitSemaphores;
2764                 (const VkPipelineStageFlags*)DE_NULL,
2765                 1u,                                                             // deUint32                                     commandBufferCount;
2766                 &m_cmdBuffer.get(),                             // const VkCommandBuffer*       pCommandBuffers;
2767                 0u,                                                             // deUint32                                     signalSemaphoreCount;
2768                 DE_NULL                                                 // const VkSemaphore*           pSignalSemaphores;
2769         };
2770
2771         VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
2772         VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
2773         VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
2774
2775         de::MovePtr<tcu::TextureLevel>  resultTextureLevel      = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
2776
2777         return checkTestResult(resultTextureLevel->getAccess());
2778 }
2779
2780 tcu::TestStatus ResolveImageToImage::checkTestResult (tcu::ConstPixelBufferAccess result)
2781 {
2782         const tcu::ConstPixelBufferAccess       expected                = m_expectedTextureLevel->getAccess();
2783         const float                                                     fuzzyThreshold  = 0.01f;
2784
2785         if (!tcu::fuzzyCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, fuzzyThreshold, tcu::COMPARE_LOG_RESULT))
2786                 return tcu::TestStatus::fail("CopiesAndBlitting test");
2787
2788         return tcu::TestStatus::pass("CopiesAndBlitting test");
2789 }
2790
2791 void ResolveImageToImage::copyRegionToTextureLevel(tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
2792 {
2793         VkOffset3D srcOffset    = region.imageCopy.srcOffset;
2794         VkOffset3D dstOffset    = region.imageCopy.dstOffset;
2795         VkExtent3D extent               = region.imageCopy.extent;
2796
2797         const tcu::ConstPixelBufferAccess       srcSubRegion            = tcu::getSubregion(src, srcOffset.x, srcOffset.y, extent.width, extent.height);
2798         // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
2799         const tcu::PixelBufferAccess            dstWithSrcFormat        (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
2800         const tcu::PixelBufferAccess            dstSubRegion            = tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, extent.width, extent.height);
2801
2802         tcu::copy(dstSubRegion, srcSubRegion);
2803 }
2804
2805 class ResolveImageToImageTestCase : public vkt::TestCase
2806 {
2807 public:
2808                                                         ResolveImageToImageTestCase     (tcu::TestContext&              testCtx,
2809                                                                                                                  const std::string&             name,
2810                                                                                                                  const std::string&             description,
2811                                                                                                                  const TestParams               params)
2812                                                                 : vkt::TestCase (testCtx, name, description)
2813                                                                 , m_params              (params)
2814                                                         {}
2815         virtual void                    initPrograms                            (SourceCollections&             programCollection) const;
2816
2817         virtual TestInstance*   createInstance                          (Context&                               context) const
2818                                                         {
2819                                                                 return new ResolveImageToImage(context, m_params);
2820                                                         }
2821 private:
2822         TestParams                              m_params;
2823 };
2824
2825 void ResolveImageToImageTestCase::initPrograms (SourceCollections& programCollection) const
2826 {
2827         programCollection.glslSources.add("vert") << glu::VertexSource(
2828                 "#version 310 es\n"
2829                 "layout (location = 0) in highp vec4 a_position;\n"
2830                 "void main()\n"
2831                 "{\n"
2832                 "       gl_Position = a_position;\n"
2833                 "}\n");
2834
2835
2836         programCollection.glslSources.add("frag") << glu::FragmentSource(
2837                 "#version 310 es\n"
2838                 "layout (location = 0) out highp vec4 o_color;\n"
2839                 "void main()\n"
2840                 "{\n"
2841                 "       o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
2842                 "}\n");
2843 }
2844
2845 std::string getSampleCountCaseName (VkSampleCountFlagBits sampleFlag)
2846 {
2847         return de::toLower(de::toString(getSampleCountFlagsStr(sampleFlag)).substr(16));
2848 }
2849
2850 std::string getFormatCaseName (VkFormat format)
2851 {
2852         return de::toLower(de::toString(getFormatStr(format)).substr(10));
2853 }
2854
2855 void addCopyImageTestsAllFormats (tcu::TestCaseGroup*   testCaseGroup,
2856                                                                   tcu::TestContext&             testCtx,
2857                                                                   TestParams&                   params)
2858 {
2859         const VkFormat  compatibleFormats8Bit[]                 =
2860         {
2861                 VK_FORMAT_R4G4_UNORM_PACK8,
2862                 VK_FORMAT_R8_UNORM,
2863                 VK_FORMAT_R8_SNORM,
2864                 VK_FORMAT_R8_USCALED,
2865                 VK_FORMAT_R8_SSCALED,
2866                 VK_FORMAT_R8_UINT,
2867                 VK_FORMAT_R8_SINT,
2868                 VK_FORMAT_R8_SRGB,
2869
2870                 VK_FORMAT_LAST
2871         };
2872         const VkFormat  compatibleFormats16Bit[]                =
2873         {
2874                 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
2875                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
2876                 VK_FORMAT_R5G6B5_UNORM_PACK16,
2877                 VK_FORMAT_B5G6R5_UNORM_PACK16,
2878                 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
2879                 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
2880                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
2881                 VK_FORMAT_R8G8_UNORM,
2882                 VK_FORMAT_R8G8_SNORM,
2883                 VK_FORMAT_R8G8_USCALED,
2884                 VK_FORMAT_R8G8_SSCALED,
2885                 VK_FORMAT_R8G8_UINT,
2886                 VK_FORMAT_R8G8_SINT,
2887                 VK_FORMAT_R8G8_SRGB,
2888                 VK_FORMAT_R16_UNORM,
2889                 VK_FORMAT_R16_SNORM,
2890                 VK_FORMAT_R16_USCALED,
2891                 VK_FORMAT_R16_SSCALED,
2892                 VK_FORMAT_R16_UINT,
2893                 VK_FORMAT_R16_SINT,
2894                 VK_FORMAT_R16_SFLOAT,
2895
2896                 VK_FORMAT_LAST
2897          };
2898         const VkFormat  compatibleFormats24Bit[]                =
2899         {
2900                 VK_FORMAT_R8G8B8_UNORM,
2901                 VK_FORMAT_R8G8B8_SNORM,
2902                 VK_FORMAT_R8G8B8_USCALED,
2903                 VK_FORMAT_R8G8B8_SSCALED,
2904                 VK_FORMAT_R8G8B8_UINT,
2905                 VK_FORMAT_R8G8B8_SINT,
2906                 VK_FORMAT_R8G8B8_SRGB,
2907                 VK_FORMAT_B8G8R8_UNORM,
2908                 VK_FORMAT_B8G8R8_SNORM,
2909                 VK_FORMAT_B8G8R8_USCALED,
2910                 VK_FORMAT_B8G8R8_SSCALED,
2911                 VK_FORMAT_B8G8R8_UINT,
2912                 VK_FORMAT_B8G8R8_SINT,
2913                 VK_FORMAT_B8G8R8_SRGB,
2914
2915                 VK_FORMAT_LAST
2916          };
2917         const VkFormat  compatibleFormats32Bit[]                =
2918         {
2919                 VK_FORMAT_R8G8B8A8_UNORM,
2920                 VK_FORMAT_R8G8B8A8_SNORM,
2921                 VK_FORMAT_R8G8B8A8_USCALED,
2922                 VK_FORMAT_R8G8B8A8_SSCALED,
2923                 VK_FORMAT_R8G8B8A8_UINT,
2924                 VK_FORMAT_R8G8B8A8_SINT,
2925                 VK_FORMAT_R8G8B8A8_SRGB,
2926                 VK_FORMAT_B8G8R8A8_UNORM,
2927                 VK_FORMAT_B8G8R8A8_SNORM,
2928                 VK_FORMAT_B8G8R8A8_USCALED,
2929                 VK_FORMAT_B8G8R8A8_SSCALED,
2930                 VK_FORMAT_B8G8R8A8_UINT,
2931                 VK_FORMAT_B8G8R8A8_SINT,
2932                 VK_FORMAT_B8G8R8A8_SRGB,
2933                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
2934                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
2935                 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
2936                 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
2937                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
2938                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
2939                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
2940                 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
2941                 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
2942                 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
2943                 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
2944                 VK_FORMAT_A2R10G10B10_UINT_PACK32,
2945                 VK_FORMAT_A2R10G10B10_SINT_PACK32,
2946                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
2947                 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
2948                 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
2949                 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
2950                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
2951                 VK_FORMAT_A2B10G10R10_SINT_PACK32,
2952                 VK_FORMAT_R16G16_UNORM,
2953                 VK_FORMAT_R16G16_SNORM,
2954                 VK_FORMAT_R16G16_USCALED,
2955                 VK_FORMAT_R16G16_SSCALED,
2956                 VK_FORMAT_R16G16_UINT,
2957                 VK_FORMAT_R16G16_SINT,
2958                 VK_FORMAT_R16G16_SFLOAT,
2959                 VK_FORMAT_R32_UINT,
2960                 VK_FORMAT_R32_SINT,
2961                 VK_FORMAT_R32_SFLOAT,
2962
2963                 VK_FORMAT_LAST
2964          };
2965         const VkFormat  compatibleFormats48Bit[]                =
2966         {
2967                 VK_FORMAT_R16G16B16_UNORM,
2968                 VK_FORMAT_R16G16B16_SNORM,
2969                 VK_FORMAT_R16G16B16_USCALED,
2970                 VK_FORMAT_R16G16B16_SSCALED,
2971                 VK_FORMAT_R16G16B16_UINT,
2972                 VK_FORMAT_R16G16B16_SINT,
2973                 VK_FORMAT_R16G16B16_SFLOAT,
2974
2975                 VK_FORMAT_LAST
2976          };
2977         const VkFormat  compatibleFormats64Bit[]                =
2978         {
2979                 VK_FORMAT_R16G16B16A16_UNORM,
2980                 VK_FORMAT_R16G16B16A16_SNORM,
2981                 VK_FORMAT_R16G16B16A16_USCALED,
2982                 VK_FORMAT_R16G16B16A16_SSCALED,
2983                 VK_FORMAT_R16G16B16A16_UINT,
2984                 VK_FORMAT_R16G16B16A16_SINT,
2985                 VK_FORMAT_R16G16B16A16_SFLOAT,
2986                 VK_FORMAT_R32G32_UINT,
2987                 VK_FORMAT_R32G32_SINT,
2988                 VK_FORMAT_R32G32_SFLOAT,
2989                 VK_FORMAT_R64_UINT,
2990                 VK_FORMAT_R64_SINT,
2991                 VK_FORMAT_R64_SFLOAT,
2992
2993                 VK_FORMAT_LAST
2994          };
2995         const VkFormat  compatibleFormats96Bit[]                =
2996         {
2997                 VK_FORMAT_R32G32B32_UINT,
2998                 VK_FORMAT_R32G32B32_SINT,
2999                 VK_FORMAT_R32G32B32_SFLOAT,
3000
3001                 VK_FORMAT_LAST
3002          };
3003         const VkFormat  compatibleFormats128Bit[]               =
3004         {
3005                 VK_FORMAT_R32G32B32A32_UINT,
3006                 VK_FORMAT_R32G32B32A32_SINT,
3007                 VK_FORMAT_R32G32B32A32_SFLOAT,
3008                 VK_FORMAT_R64G64_UINT,
3009                 VK_FORMAT_R64G64_SINT,
3010                 VK_FORMAT_R64G64_SFLOAT,
3011
3012                 VK_FORMAT_LAST
3013          };
3014         const VkFormat  compatibleFormats192Bit[]               =
3015         {
3016                 VK_FORMAT_R64G64B64_UINT,
3017                 VK_FORMAT_R64G64B64_SINT,
3018                 VK_FORMAT_R64G64B64_SFLOAT,
3019
3020                 VK_FORMAT_LAST
3021          };
3022         const VkFormat  compatibleFormats256Bit[]               =
3023         {
3024                 VK_FORMAT_R64G64B64A64_UINT,
3025                 VK_FORMAT_R64G64B64A64_SINT,
3026                 VK_FORMAT_R64G64B64A64_SFLOAT,
3027
3028                 VK_FORMAT_LAST
3029         };
3030
3031         const VkFormat* colorImageFormatsToTest[]               =
3032         {
3033                 compatibleFormats8Bit,
3034                 compatibleFormats16Bit,
3035                 compatibleFormats24Bit,
3036                 compatibleFormats32Bit,
3037                 compatibleFormats48Bit,
3038                 compatibleFormats64Bit,
3039                 compatibleFormats96Bit,
3040                 compatibleFormats128Bit,
3041                 compatibleFormats192Bit,
3042                 compatibleFormats256Bit,
3043         };
3044         const size_t    numOfColorImageFormatsToTest    = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
3045
3046         for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
3047         {
3048                 const VkFormat* compatibleFormats       = colorImageFormatsToTest[compatibleFormatsIndex];
3049                 for (size_t srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_LAST; ++srcFormatIndex)
3050                 {
3051                         params.src.image.format = compatibleFormats[srcFormatIndex];
3052                         for (size_t dstFormatIndex = 0; compatibleFormats[dstFormatIndex] != VK_FORMAT_LAST; ++dstFormatIndex)
3053                         {
3054                                 params.dst.image.format = compatibleFormats[dstFormatIndex];
3055
3056                                 if (!isSupportedByFramework(params.src.image.format) || !isSupportedByFramework(params.dst.image.format))
3057                                         continue;
3058
3059                                 std::ostringstream      testName;
3060                                 testName << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
3061                                 std::ostringstream      description;
3062                                 description << "Copy from src " << params.src.image.format << " to dst " << params.dst.image.format;
3063
3064                                 testCaseGroup->addChild(new CopyImageToImageTestCase(testCtx, testName.str(), description.str(), params));
3065                         }
3066                 }
3067         }
3068 }
3069
3070 void addBlittingTestsAllFormats (tcu::TestCaseGroup*    testCaseGroup,
3071                                                                  tcu::TestContext&              testCtx,
3072                                                                  TestParams&                    params)
3073 {
3074         // Test Image formats.
3075         const VkFormat  compatibleFormatsUInts[]                        =
3076         {
3077                 VK_FORMAT_R8_UINT,
3078                 VK_FORMAT_R8G8_UINT,
3079                 VK_FORMAT_R8G8B8_UINT,
3080                 VK_FORMAT_B8G8R8_UINT,
3081                 VK_FORMAT_R8G8B8A8_UINT,
3082                 VK_FORMAT_B8G8R8A8_UINT,
3083                 VK_FORMAT_A8B8G8R8_UINT_PACK32,
3084                 VK_FORMAT_A2R10G10B10_UINT_PACK32,
3085                 VK_FORMAT_A2B10G10R10_UINT_PACK32,
3086                 VK_FORMAT_R16_UINT,
3087                 VK_FORMAT_R16G16_UINT,
3088                 VK_FORMAT_R16G16B16_UINT,
3089                 VK_FORMAT_R16G16B16A16_UINT,
3090                 VK_FORMAT_R32_UINT,
3091                 VK_FORMAT_R32G32_UINT,
3092                 VK_FORMAT_R32G32B32_UINT,
3093                 VK_FORMAT_R32G32B32A32_UINT,
3094                 VK_FORMAT_R64_UINT,
3095                 VK_FORMAT_R64G64_UINT,
3096                 VK_FORMAT_R64G64B64_UINT,
3097                 VK_FORMAT_R64G64B64A64_UINT,
3098
3099                 VK_FORMAT_LAST
3100         };
3101         const VkFormat  compatibleFormatsSInts[]                        =
3102         {
3103                 VK_FORMAT_R8_SINT,
3104                 VK_FORMAT_R8G8_SINT,
3105                 VK_FORMAT_R8G8B8_SINT,
3106                 VK_FORMAT_B8G8R8_SINT,
3107                 VK_FORMAT_R8G8B8A8_SINT,
3108                 VK_FORMAT_B8G8R8A8_SINT,
3109                 VK_FORMAT_A8B8G8R8_SINT_PACK32,
3110                 VK_FORMAT_A2R10G10B10_SINT_PACK32,
3111                 VK_FORMAT_A2B10G10R10_SINT_PACK32,
3112                 VK_FORMAT_R16_SINT,
3113                 VK_FORMAT_R16G16_SINT,
3114                 VK_FORMAT_R16G16B16_SINT,
3115                 VK_FORMAT_R16G16B16A16_SINT,
3116                 VK_FORMAT_R32_SINT,
3117                 VK_FORMAT_R32G32_SINT,
3118                 VK_FORMAT_R32G32B32_SINT,
3119                 VK_FORMAT_R32G32B32A32_SINT,
3120                 VK_FORMAT_R64_SINT,
3121                 VK_FORMAT_R64G64_SINT,
3122                 VK_FORMAT_R64G64B64_SINT,
3123                 VK_FORMAT_R64G64B64A64_SINT,
3124
3125                 VK_FORMAT_LAST
3126         };
3127         const VkFormat  compatibleFormatsFloats[]                       =
3128         {
3129                 VK_FORMAT_R4G4_UNORM_PACK8,
3130                 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
3131                 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
3132                 VK_FORMAT_R5G6B5_UNORM_PACK16,
3133                 VK_FORMAT_B5G6R5_UNORM_PACK16,
3134                 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
3135                 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
3136                 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
3137                 VK_FORMAT_R8_UNORM,
3138                 VK_FORMAT_R8_SNORM,
3139                 VK_FORMAT_R8_USCALED,
3140                 VK_FORMAT_R8_SSCALED,
3141                 VK_FORMAT_R8G8_UNORM,
3142                 VK_FORMAT_R8G8_SNORM,
3143                 VK_FORMAT_R8G8_USCALED,
3144                 VK_FORMAT_R8G8_SSCALED,
3145                 VK_FORMAT_R8G8B8_UNORM,
3146                 VK_FORMAT_R8G8B8_SNORM,
3147                 VK_FORMAT_R8G8B8_USCALED,
3148                 VK_FORMAT_R8G8B8_SSCALED,
3149                 VK_FORMAT_B8G8R8_UNORM,
3150                 VK_FORMAT_B8G8R8_SNORM,
3151                 VK_FORMAT_B8G8R8_USCALED,
3152                 VK_FORMAT_B8G8R8_SSCALED,
3153                 VK_FORMAT_R8G8B8A8_UNORM,
3154                 VK_FORMAT_R8G8B8A8_SNORM,
3155                 VK_FORMAT_R8G8B8A8_USCALED,
3156                 VK_FORMAT_R8G8B8A8_SSCALED,
3157                 VK_FORMAT_B8G8R8A8_UNORM,
3158                 VK_FORMAT_B8G8R8A8_SNORM,
3159                 VK_FORMAT_B8G8R8A8_USCALED,
3160                 VK_FORMAT_B8G8R8A8_SSCALED,
3161                 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
3162                 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
3163                 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
3164                 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
3165                 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
3166                 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
3167                 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
3168                 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
3169                 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
3170                 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
3171                 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
3172                 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
3173                 VK_FORMAT_R16_UNORM,
3174                 VK_FORMAT_R16_SNORM,
3175                 VK_FORMAT_R16_USCALED,
3176                 VK_FORMAT_R16_SSCALED,
3177                 VK_FORMAT_R16_SFLOAT,
3178                 VK_FORMAT_R16G16_UNORM,
3179                 VK_FORMAT_R16G16_SNORM,
3180                 VK_FORMAT_R16G16_USCALED,
3181                 VK_FORMAT_R16G16_SSCALED,
3182                 VK_FORMAT_R16G16_SFLOAT,
3183                 VK_FORMAT_R16G16B16_UNORM,
3184                 VK_FORMAT_R16G16B16_SNORM,
3185                 VK_FORMAT_R16G16B16_USCALED,
3186                 VK_FORMAT_R16G16B16_SSCALED,
3187                 VK_FORMAT_R16G16B16_SFLOAT,
3188                 VK_FORMAT_R16G16B16A16_UNORM,
3189                 VK_FORMAT_R16G16B16A16_SNORM,
3190                 VK_FORMAT_R16G16B16A16_USCALED,
3191                 VK_FORMAT_R16G16B16A16_SSCALED,
3192                 VK_FORMAT_R16G16B16A16_SFLOAT,
3193                 VK_FORMAT_R32_SFLOAT,
3194                 VK_FORMAT_R32G32_SFLOAT,
3195                 VK_FORMAT_R32G32B32_SFLOAT,
3196                 VK_FORMAT_R32G32B32A32_SFLOAT,
3197                 VK_FORMAT_R64_SFLOAT,
3198                 VK_FORMAT_R64G64_SFLOAT,
3199                 VK_FORMAT_R64G64B64_SFLOAT,
3200                 VK_FORMAT_R64G64B64A64_SFLOAT,
3201 //              VK_FORMAT_B10G11R11_UFLOAT_PACK32,
3202 //              VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
3203 //              VK_FORMAT_BC1_RGB_UNORM_BLOCK,
3204 //              VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
3205 //              VK_FORMAT_BC2_UNORM_BLOCK,
3206 //              VK_FORMAT_BC3_UNORM_BLOCK,
3207 //              VK_FORMAT_BC4_UNORM_BLOCK,
3208 //              VK_FORMAT_BC4_SNORM_BLOCK,
3209 //              VK_FORMAT_BC5_UNORM_BLOCK,
3210 //              VK_FORMAT_BC5_SNORM_BLOCK,
3211 //              VK_FORMAT_BC6H_UFLOAT_BLOCK,
3212 //              VK_FORMAT_BC6H_SFLOAT_BLOCK,
3213 //              VK_FORMAT_BC7_UNORM_BLOCK,
3214 //              VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
3215 //              VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
3216 //              VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
3217 //              VK_FORMAT_EAC_R11_UNORM_BLOCK,
3218 //              VK_FORMAT_EAC_R11_SNORM_BLOCK,
3219 //              VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
3220 //              VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
3221 //              VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
3222 //              VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
3223 //              VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
3224 //              VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
3225 //              VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
3226 //              VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
3227 //              VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
3228 //              VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
3229 //              VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
3230 //              VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
3231 //              VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
3232 //              VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
3233 //              VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
3234 //              VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
3235
3236                 VK_FORMAT_LAST
3237         };
3238         const VkFormat  compatibleFormatsSrgb[]                         =
3239         {
3240                 VK_FORMAT_R8_SRGB,
3241                 VK_FORMAT_R8G8_SRGB,
3242                 VK_FORMAT_R8G8B8_SRGB,
3243                 VK_FORMAT_B8G8R8_SRGB,
3244                 VK_FORMAT_R8G8B8A8_SRGB,
3245                 VK_FORMAT_B8G8R8A8_SRGB,
3246                 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
3247 //              VK_FORMAT_BC1_RGB_SRGB_BLOCK,
3248 //              VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
3249 //              VK_FORMAT_BC2_SRGB_BLOCK,
3250 //              VK_FORMAT_BC3_SRGB_BLOCK,
3251 //              VK_FORMAT_BC7_SRGB_BLOCK,
3252 //              VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
3253 //              VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
3254 //              VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
3255 //              VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
3256 //              VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
3257 //              VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
3258 //              VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
3259 //              VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
3260 //              VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
3261 //              VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
3262 //              VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
3263 //              VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
3264 //              VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
3265 //              VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
3266 //              VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
3267 //              VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
3268 //              VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
3269
3270                 VK_FORMAT_LAST
3271         };
3272
3273         const struct {
3274                 const VkFormat* compatibleFormats;
3275                 const bool              onlyNearest;
3276         }       colorImageFormatsToTest[]                       =
3277         {
3278                 { compatibleFormatsUInts,       true    },
3279                 { compatibleFormatsSInts,       true    },
3280                 { compatibleFormatsFloats,      false   },
3281                 { compatibleFormatsSrgb,        false   },
3282         };
3283         const size_t    numOfColorImageFormatsToTest            = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
3284
3285         for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
3286         {
3287                 const VkFormat* compatibleFormats       = colorImageFormatsToTest[compatibleFormatsIndex].compatibleFormats;
3288                 const bool              onlyNearest                     = colorImageFormatsToTest[compatibleFormatsIndex].onlyNearest;
3289                 for (size_t srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_LAST; ++srcFormatIndex)
3290                 {
3291                         params.src.image.format = compatibleFormats[srcFormatIndex];
3292                         for (size_t dstFormatIndex = 0; compatibleFormats[dstFormatIndex] != VK_FORMAT_LAST; ++dstFormatIndex)
3293                         {
3294                                 params.dst.image.format = compatibleFormats[dstFormatIndex];
3295
3296                                 if (!isSupportedByFramework(params.src.image.format) || !isSupportedByFramework(params.dst.image.format))
3297                                         continue;
3298
3299                                 std::ostringstream      testName;
3300                                 testName << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
3301                                 std::ostringstream      description;
3302                                 description << "Blit image from src " << params.src.image.format << " to dst " << params.dst.image.format;
3303
3304                                 params.filter                   = VK_FILTER_NEAREST;
3305                                 testCaseGroup->addChild(new BlittingTestCase(testCtx, testName.str() + "_nearest", description.str(), params));
3306
3307                                 if (!onlyNearest)
3308                                 {
3309                                         params.filter           = VK_FILTER_LINEAR;
3310                                         testCaseGroup->addChild(new BlittingTestCase(testCtx, testName.str() + "_linear", description.str(), params));
3311                                 }
3312                         }
3313                 }
3314         }
3315 }
3316
3317 } // anonymous
3318
3319 tcu::TestCaseGroup* createCopiesAndBlittingTests (tcu::TestContext& testCtx)
3320 {
3321         de::MovePtr<tcu::TestCaseGroup> copiesAndBlittingTests  (new tcu::TestCaseGroup(testCtx, "copy_and_blit", "Copies And Blitting Tests"));
3322
3323         de::MovePtr<tcu::TestCaseGroup> imageToImageTests               (new tcu::TestCaseGroup(testCtx, "image_to_image", "Copy from image to image"));
3324         de::MovePtr<tcu::TestCaseGroup> imgToImgSimpleTests             (new tcu::TestCaseGroup(testCtx, "simple_tests", "Copy from image to image simple tests"));
3325         de::MovePtr<tcu::TestCaseGroup> imgToImgAllFormatsTests (new tcu::TestCaseGroup(testCtx, "all_formats", "Copy from image to image with all compatible formats"));
3326
3327         de::MovePtr<tcu::TestCaseGroup> imageToBufferTests              (new tcu::TestCaseGroup(testCtx, "image_to_buffer", "Copy from image to buffer"));
3328         de::MovePtr<tcu::TestCaseGroup> bufferToImageTests              (new tcu::TestCaseGroup(testCtx, "buffer_to_image", "Copy from buffer to image"));
3329         de::MovePtr<tcu::TestCaseGroup> bufferToBufferTests             (new tcu::TestCaseGroup(testCtx, "buffer_to_buffer", "Copy from buffer to buffer"));
3330
3331         de::MovePtr<tcu::TestCaseGroup> blittingImageTests              (new tcu::TestCaseGroup(testCtx, "blit_image", "Blitting image"));
3332         de::MovePtr<tcu::TestCaseGroup> blitImgSimpleTests              (new tcu::TestCaseGroup(testCtx, "simple_tests", "Blitting image simple tests"));
3333         de::MovePtr<tcu::TestCaseGroup> blitImgAllFormatsTests  (new tcu::TestCaseGroup(testCtx, "all_formats", "Blitting image with all compatible formats"));
3334
3335         de::MovePtr<tcu::TestCaseGroup> resolveImageTests               (new tcu::TestCaseGroup(testCtx, "resolve_image", "Resolve image"));
3336
3337         const deInt32                                   defaultSize                             = 64;
3338         const deInt32                                   defaultHalfSize                 = defaultSize / 2;
3339         const deInt32                                   defaultFourthSize               = defaultSize / 4;
3340         const VkExtent3D                                defaultExtent                   = {defaultSize, defaultSize, 1};
3341         const VkExtent3D                                defaultHalfExtent               = {defaultHalfSize, defaultHalfSize, 1};
3342
3343         const VkImageSubresourceLayers  defaultSourceLayer              =
3344         {
3345                 VK_IMAGE_ASPECT_COLOR_BIT,      // VkImageAspectFlags   aspectMask;
3346                 0u,                                                     // uint32_t                             mipLevel;
3347                 0u,                                                     // uint32_t                             baseArrayLayer;
3348                 1u,                                                     // uint32_t                             layerCount;
3349         };
3350
3351         // Copy image to image testcases.
3352         {
3353                 TestParams                      params;
3354                 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3355                 params.src.image.extent = defaultExtent;
3356                 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3357                 params.dst.image.extent = defaultExtent;
3358
3359                 {
3360                         const VkImageCopy                               testCopy        =
3361                         {
3362                                 defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3363                                 {0, 0, 0},                      // VkOffset3D                           srcOffset;
3364                                 defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3365                                 {0, 0, 0},                      // VkOffset3D                           dstOffset;
3366                                 defaultExtent,          // VkExtent3D                           extent;
3367                         };
3368
3369                         CopyRegion      imageCopy;
3370                         imageCopy.imageCopy     = testCopy;
3371
3372                         params.regions.push_back(imageCopy);
3373                 }
3374
3375                 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "whole_image", "Whole image", params));
3376         }
3377
3378         {
3379                 TestParams                      params;
3380                 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3381                 params.src.image.extent = defaultExtent;
3382                 params.dst.image.format = VK_FORMAT_R32_UINT;
3383                 params.dst.image.extent = defaultExtent;
3384
3385                 {
3386                         const VkImageCopy                               testCopy        =
3387                         {
3388                                 defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3389                                 {0, 0, 0},                      // VkOffset3D                           srcOffset;
3390                                 defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3391                                 {0, 0, 0},                      // VkOffset3D                           dstOffset;
3392                                 defaultExtent,          // VkExtent3D                           extent;
3393                         };
3394
3395                         CopyRegion      imageCopy;
3396                         imageCopy.imageCopy     = testCopy;
3397
3398                         params.regions.push_back(imageCopy);
3399                 }
3400
3401                 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "whole_image_diff_fromat", "Whole image with different format", params));
3402         }
3403
3404         {
3405                 TestParams                      params;
3406                 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3407                 params.src.image.extent = defaultExtent;
3408                 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3409                 params.dst.image.extent = defaultExtent;
3410
3411                 {
3412                         const VkImageCopy                               testCopy        =
3413                         {
3414                                 defaultSourceLayer,                                                                     // VkImageSubresourceLayers     srcSubresource;
3415                                 {0, 0, 0},                                                                                      // VkOffset3D                           srcOffset;
3416                                 defaultSourceLayer,                                                                     // VkImageSubresourceLayers     dstSubresource;
3417                                 {defaultFourthSize, defaultFourthSize / 2, 0},          // VkOffset3D                           dstOffset;
3418                                 {defaultFourthSize / 2, defaultFourthSize / 2, 1},      // VkExtent3D                           extent;
3419                         };
3420
3421                         CopyRegion      imageCopy;
3422                         imageCopy.imageCopy     = testCopy;
3423
3424                         params.regions.push_back(imageCopy);
3425                 }
3426
3427                 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "partial_image", "Partial image", params));
3428         }
3429
3430         {
3431                 TestParams                      params;
3432                 params.src.image.format = VK_FORMAT_D32_SFLOAT;
3433                 params.src.image.extent = defaultExtent;
3434                 params.dst.image.format = VK_FORMAT_D32_SFLOAT;
3435                 params.dst.image.extent = defaultExtent;
3436
3437                 {
3438                         const VkImageSubresourceLayers  sourceLayer =
3439                         {
3440                                 VK_IMAGE_ASPECT_DEPTH_BIT,      // VkImageAspectFlags   aspectMask;
3441                                 0u,                                                     // uint32_t                             mipLevel;
3442                                 0u,                                                     // uint32_t                             baseArrayLayer;
3443                                 1u                                                      // uint32_t                             layerCount;
3444                         };
3445                         const VkImageCopy                               testCopy        =
3446                         {
3447                                 sourceLayer,                                                                            // VkImageSubresourceLayers     srcSubresource;
3448                                 {0, 0, 0},                                                                                      // VkOffset3D                           srcOffset;
3449                                 sourceLayer,                                                                            // VkImageSubresourceLayers     dstSubresource;
3450                                 {defaultFourthSize, defaultFourthSize / 2, 0},          // VkOffset3D                           dstOffset;
3451                                 {defaultFourthSize / 2, defaultFourthSize / 2, 1},      // VkExtent3D                           extent;
3452                         };
3453
3454                         CopyRegion      imageCopy;
3455                         imageCopy.imageCopy     = testCopy;
3456
3457                         params.regions.push_back(imageCopy);
3458                 }
3459
3460                 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "depth", "With depth", params));
3461         }
3462
3463         {
3464                 TestParams                      params;
3465                 params.src.image.format = VK_FORMAT_S8_UINT;
3466                 params.src.image.extent = defaultExtent;
3467                 params.dst.image.format = VK_FORMAT_S8_UINT;
3468                 params.dst.image.extent = defaultExtent;
3469
3470                 {
3471                         const VkImageSubresourceLayers  sourceLayer =
3472                         {
3473                                 VK_IMAGE_ASPECT_STENCIL_BIT,    // VkImageAspectFlags   aspectMask;
3474                                 0u,                                                             // uint32_t                             mipLevel;
3475                                 0u,                                                             // uint32_t                             baseArrayLayer;
3476                                 1u                                                              // uint32_t                             layerCount;
3477                         };
3478                         const VkImageCopy                               testCopy        =
3479                         {
3480                                 sourceLayer,                                                                            // VkImageSubresourceLayers     srcSubresource;
3481                                 {0, 0, 0},                                                                                      // VkOffset3D                           srcOffset;
3482                                 sourceLayer,                                                                            // VkImageSubresourceLayers     dstSubresource;
3483                                 {defaultFourthSize, defaultFourthSize / 2, 0},          // VkOffset3D                           dstOffset;
3484                                 {defaultFourthSize / 2, defaultFourthSize / 2, 1},      // VkExtent3D                           extent;
3485                         };
3486
3487                         CopyRegion      imageCopy;
3488                         imageCopy.imageCopy     = testCopy;
3489
3490                         params.regions.push_back(imageCopy);
3491                 }
3492
3493                 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "stencil", "With stencil", params));
3494         }
3495
3496         {
3497                 TestParams                      params;
3498                 params.src.image.extent = defaultExtent;
3499                 params.dst.image.extent = defaultExtent;
3500
3501                 for (deInt32 i = 0; i < defaultSize; i += defaultFourthSize)
3502                 {
3503                         const VkImageCopy                               testCopy        =
3504                         {
3505                                 defaultSourceLayer,                                                             // VkImageSubresourceLayers     srcSubresource;
3506                                 {0, 0, 0},                                                                              // VkOffset3D                           srcOffset;
3507                                 defaultSourceLayer,                                                             // VkImageSubresourceLayers     dstSubresource;
3508                                 {i, defaultSize - i - defaultFourthSize, 0},    // VkOffset3D                           dstOffset;
3509                                 {defaultFourthSize, defaultFourthSize, 1},              // VkExtent3D                           extent;
3510                         };
3511
3512                         CopyRegion      imageCopy;
3513                         imageCopy.imageCopy     = testCopy;
3514
3515                         params.regions.push_back(imageCopy);
3516                 }
3517
3518                 addCopyImageTestsAllFormats(imgToImgAllFormatsTests.get(), testCtx, params);
3519         }
3520         imageToImageTests->addChild(imgToImgSimpleTests.release());
3521         imageToImageTests->addChild(imgToImgAllFormatsTests.release());
3522
3523         // Copy image to buffer testcases.
3524         {
3525                 TestParams                      params;
3526                 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3527                 params.src.image.extent = defaultExtent;
3528                 params.dst.buffer.size  = defaultSize * defaultSize;
3529
3530                 const VkBufferImageCopy                 bufferImageCopy =
3531                 {
3532                         0u,                                                                                     // VkDeviceSize                         bufferOffset;
3533                         0u,                                                                                     // uint32_t                                     bufferRowLength;
3534                         0u,                                                                                     // uint32_t                                     bufferImageHeight;
3535                         defaultSourceLayer,                                                     // VkImageSubresourceLayers     imageSubresource;
3536                         {0, 0, 0},                                                                      // VkOffset3D                           imageOffset;
3537                         {defaultFourthSize, defaultFourthSize, 1}       // VkExtent3D                           imageExtent;
3538                 };
3539                 CopyRegion      copyRegion;
3540                 copyRegion.bufferImageCopy      = bufferImageCopy;
3541
3542                 params.regions.push_back(copyRegion);
3543
3544                 imageToBufferTests->addChild(new CopyImageToBufferTestCase(testCtx, "whole", "Copy from image to buffer", params));
3545         }
3546
3547         // Copy buffer to image testcases.
3548         {
3549                 TestParams                      params;
3550                 params.src.buffer.size  = defaultSize * defaultSize;
3551                 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3552                 params.dst.image.extent = defaultExtent;
3553
3554                 const VkBufferImageCopy                 bufferImageCopy =
3555                 {
3556                         0u,                                                                                     // VkDeviceSize                         bufferOffset;
3557                         0u,                                                                                     // uint32_t                                     bufferRowLength;
3558                         0u,                                                                                     // uint32_t                                     bufferImageHeight;
3559                         defaultSourceLayer,                                                     // VkImageSubresourceLayers     imageSubresource;
3560                         {0, 0, 0},                                                                      // VkOffset3D                           imageOffset;
3561                         {defaultFourthSize, defaultFourthSize, 1}       // VkExtent3D                           imageExtent;
3562                 };
3563                 CopyRegion      copyRegion;
3564                 copyRegion.bufferImageCopy      = bufferImageCopy;
3565
3566                 params.regions.push_back(copyRegion);
3567
3568                 bufferToImageTests->addChild(new CopyBufferToImageTestCase(testCtx, "whole", "Copy from buffer to image", params));
3569         }
3570
3571         // Copy buffer to buffer testcases.
3572         {
3573                 TestParams                      params;
3574                 params.src.buffer.size  = defaultSize;
3575                 params.dst.buffer.size  = defaultSize;
3576
3577                 const VkBufferCopy      bufferCopy      =
3578                 {
3579                         0u,                             // VkDeviceSize srcOffset;
3580                         0u,                             // VkDeviceSize dstOffset;
3581                         defaultSize,    // VkDeviceSize size;
3582                 };
3583
3584                 CopyRegion      copyRegion;
3585                 copyRegion.bufferCopy   = bufferCopy;
3586                 params.regions.push_back(copyRegion);
3587
3588                 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "whole", "Whole buffer", params));
3589         }
3590
3591         {
3592                 TestParams                      params;
3593                 params.src.buffer.size  = defaultFourthSize;
3594                 params.dst.buffer.size  = defaultFourthSize;
3595
3596                 const VkBufferCopy      bufferCopy      =
3597                 {
3598                         12u,    // VkDeviceSize srcOffset;
3599                         4u,             // VkDeviceSize dstOffset;
3600                         1u,             // VkDeviceSize size;
3601                 };
3602
3603                 CopyRegion      copyRegion;
3604                 copyRegion.bufferCopy = bufferCopy;
3605                 params.regions.push_back(copyRegion);
3606
3607                 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "partial", "Partial", params));
3608         }
3609
3610         {
3611                 const deUint32          size            = 16;
3612                 TestParams                      params;
3613                 params.src.buffer.size  = size;
3614                 params.dst.buffer.size  = size * (size + 1);
3615
3616                 // Copy region with size 1..size
3617                 for (unsigned int i = 1; i <= size; i++)
3618                 {
3619                         const VkBufferCopy      bufferCopy      =
3620                         {
3621                                 0,                      // VkDeviceSize srcOffset;
3622                                 i * size,       // VkDeviceSize dstOffset;
3623                                 i,                      // VkDeviceSize size;
3624                         };
3625
3626                         CopyRegion      copyRegion;
3627                         copyRegion.bufferCopy = bufferCopy;
3628                         params.regions.push_back(copyRegion);
3629                 }
3630
3631                 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "regions", "Multiple regions", params));
3632         }
3633
3634         // Blitting testcases.
3635         {
3636                 const std::string       description     ("Blit without scaling (whole)");
3637                 const std::string       testName        ("whole");
3638
3639                 TestParams                      params;
3640                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3641                 params.src.image.extent = defaultExtent;
3642                 params.dst.image.extent = defaultExtent;
3643
3644                 {
3645                         const VkImageBlit                               imageBlit       =
3646                         {
3647                                 defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3648                                 {
3649                                         {0, 0, 0},
3650                                         {defaultSize, defaultSize, 1}
3651                                 },                                      // VkOffset3D                           srcOffsets[2];
3652
3653                                 defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3654                                 {
3655                                         {0, 0, 0},
3656                                         {defaultSize, defaultSize, 1}
3657                                 }                                       // VkOffset3D                           dstOffset[2];
3658                         };
3659
3660                         CopyRegion      region;
3661                         region.imageBlit = imageBlit;
3662                         params.regions.push_back(region);
3663                 }
3664
3665                 // Filter is VK_FILTER_NEAREST.
3666                 {
3667                         params.filter                   = VK_FILTER_NEAREST;
3668
3669                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3670                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3671
3672                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3673                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)");
3674                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3675
3676                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3677                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3678                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3679                 }
3680
3681                 // Filter is VK_FILTER_LINEAR.
3682                 {
3683                         params.filter                   = VK_FILTER_LINEAR;
3684
3685                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3686                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3687
3688                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3689                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3690                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3691
3692                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3693                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3694                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3695                 }
3696         }
3697
3698         {
3699                 const std::string       description     ("Blit with scaling (whole, src extent bigger)");
3700                 const std::string       testName        ("scaling_whole1");
3701
3702                 TestParams                      params;
3703                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3704                 params.src.image.extent = defaultExtent;
3705                 params.dst.image.extent = defaultHalfExtent;
3706
3707                 {
3708                         const VkImageBlit                               imageBlit       =
3709                         {
3710                                 defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3711                                 {
3712                                         {0, 0, 0},
3713                                         {defaultSize, defaultSize, 1}
3714                                 },                                      // VkOffset3D                                   srcOffsets[2];
3715
3716                                 defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3717                                 {
3718                                         {0, 0, 0},
3719                                         {defaultHalfSize, defaultHalfSize, 1}
3720                                 }                                       // VkOffset3D                                   dstOffset[2];
3721                         };
3722
3723                         CopyRegion      region;
3724                         region.imageBlit        = imageBlit;
3725                         params.regions.push_back(region);
3726                 }
3727
3728                 // Filter is VK_FILTER_NEAREST.
3729                 {
3730                         params.filter                   = VK_FILTER_NEAREST;
3731
3732                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3733                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3734
3735                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3736                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)");
3737                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3738
3739                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3740                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3741                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3742                 }
3743
3744                 // Filter is VK_FILTER_LINEAR.
3745                 {
3746                         params.filter                   = VK_FILTER_LINEAR;
3747
3748                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3749                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3750
3751                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3752                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3753                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3754
3755                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3756                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3757                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3758                 }
3759         }
3760
3761         {
3762                 const std::string       description     ("Blit with scaling (whole, dst extent bigger)");
3763                 const std::string       testName        ("scaling_whole2");
3764
3765                 TestParams                      params;
3766                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3767                 params.src.image.extent = defaultHalfExtent;
3768                 params.dst.image.extent = defaultExtent;
3769
3770                 {
3771                         const VkImageBlit                               imageBlit       =
3772                         {
3773                                 defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3774                                 {
3775                                         {0, 0, 0},
3776                                         {defaultHalfSize, defaultHalfSize, 1}
3777                                 },                                      // VkOffset3D                                   srcOffsets[2];
3778
3779                                 defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3780                                 {
3781                                         {0, 0, 0},
3782                                         {defaultSize, defaultSize, 1}
3783                                 }                                       // VkOffset3D                                   dstOffset[2];
3784                         };
3785
3786                         CopyRegion      region;
3787                         region.imageBlit        = imageBlit;
3788                         params.regions.push_back(region);
3789                 }
3790
3791                 // Filter is VK_FILTER_NEAREST.
3792                 {
3793                         params.filter                   = VK_FILTER_NEAREST;
3794
3795                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3796                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3797
3798                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3799                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)");
3800                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3801
3802                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3803                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3804                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3805                 }
3806
3807                 // Filter is VK_FILTER_LINEAR.
3808                 {
3809                         params.filter                   = VK_FILTER_LINEAR;
3810
3811                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3812                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3813
3814                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3815                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3816                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3817
3818                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3819                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3820                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3821                 }
3822         }
3823
3824         {
3825                 const std::string       description     ("Blit with scaling and offset (whole, dst extent bigger)");
3826                 const std::string       testName        ("scaling_and_offset");
3827
3828                 TestParams                      params;
3829                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3830                 params.src.image.extent = defaultExtent;
3831                 params.dst.image.extent = defaultExtent;
3832
3833                 {
3834                         const VkImageBlit                               imageBlit       =
3835                         {
3836                                 defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3837                                 {
3838                                         {defaultFourthSize, defaultFourthSize, 0},
3839                                         {defaultFourthSize*3, defaultFourthSize*3, 1}
3840                                 },                                      // VkOffset3D                                   srcOffsets[2];
3841
3842                                 defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3843                                 {
3844                                         {0, 0, 0},
3845                                         {defaultSize, defaultSize, 1}
3846                                 }                                       // VkOffset3D                                   dstOffset[2];
3847                         };
3848
3849                         CopyRegion      region;
3850                         region.imageBlit        = imageBlit;
3851                         params.regions.push_back(region);
3852                 }
3853
3854                 // Filter is VK_FILTER_NEAREST.
3855                 {
3856                         params.filter                   = VK_FILTER_NEAREST;
3857
3858                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3859                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3860
3861
3862                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3863                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)");
3864                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3865
3866                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3867                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3868                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3869                 }
3870
3871                 // Filter is VK_FILTER_LINEAR.
3872                 {
3873                         params.filter                   = VK_FILTER_LINEAR;
3874
3875                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3876                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3877
3878                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3879                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3880                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3881
3882                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3883                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3884                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3885                 }
3886         }
3887
3888         {
3889                 const std::string       description     ("Blit without scaling (partial)");
3890                 const std::string       testName        ("without_scaling_partial");
3891
3892                 TestParams                      params;
3893                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3894                 params.src.image.extent = defaultExtent;
3895                 params.dst.image.extent = defaultExtent;
3896
3897                 {
3898                         CopyRegion      region;
3899                         for (int i = 0; i < defaultSize; i += defaultFourthSize)
3900                         {
3901                                 const VkImageBlit                       imageBlit       =
3902                                 {
3903                                         defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3904                                         {
3905                                                 {defaultSize - defaultFourthSize - i, defaultSize - defaultFourthSize - i, 0},
3906                                                 {defaultSize - i, defaultSize - i, 1}
3907                                         },                                      // VkOffset3D                                   srcOffsets[2];
3908
3909                                         defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3910                                         {
3911                                                 {i, i, 0},
3912                                                 {i + defaultFourthSize, i + defaultFourthSize, 1}
3913                                         }                                       // VkOffset3D                                   dstOffset[2];
3914                                 };
3915                                 region.imageBlit        = imageBlit;
3916                                 params.regions.push_back(region);
3917                         }
3918                 }
3919
3920                 // Filter is VK_FILTER_NEAREST.
3921                 {
3922                         params.filter                   = VK_FILTER_NEAREST;
3923
3924                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3925                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3926
3927
3928                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3929                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)");
3930                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3931
3932                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3933                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3934                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3935                 }
3936
3937                 // Filter is VK_FILTER_LINEAR.
3938                 {
3939                         params.filter                   = VK_FILTER_LINEAR;
3940
3941                         params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3942                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3943
3944                         params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3945                         const std::string       descriptionOfRGBAToR32  (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3946                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3947
3948                         params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3949                         const std::string       descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3950                         blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3951                 }
3952         }
3953
3954         {
3955                 const std::string       description     ("Blit with scaling (partial)");
3956                 const std::string       testName        ("scaling_partial");
3957
3958                 // Test Color formats.
3959                 {
3960                         TestParams      params;
3961                         params.src.image.extent = defaultExtent;
3962                         params.dst.image.extent = defaultExtent;
3963
3964                         CopyRegion      region;
3965                         for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
3966                         {
3967                                 const VkImageBlit                       imageBlit       =
3968                                 {
3969                                         defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3970                                         {
3971                                                 {0, 0, 0},
3972                                                 {defaultSize, defaultSize, 1}
3973                                         },                                      // VkOffset3D                                   srcOffsets[2];
3974
3975                                         defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3976                                         {
3977                                                 {i, 0, 0},
3978                                                 {i + defaultFourthSize / j, defaultFourthSize / j, 1}
3979                                         }                                       // VkOffset3D                                   dstOffset[2];
3980                                 };
3981                                 region.imageBlit        = imageBlit;
3982                                 params.regions.push_back(region);
3983                         }
3984                         for (int i = 0; i < defaultSize; i += defaultFourthSize)
3985                         {
3986                                 const VkImageBlit                       imageBlit       =
3987                                 {
3988                                         defaultSourceLayer,     // VkImageSubresourceLayers     srcSubresource;
3989                                         {
3990                                                 {i, i, 0},
3991                                                 {i + defaultFourthSize, i + defaultFourthSize, 1}
3992                                         },                                      // VkOffset3D                                   srcOffsets[2];
3993
3994                                         defaultSourceLayer,     // VkImageSubresourceLayers     dstSubresource;
3995                                         {
3996                                                 {i, defaultSize / 2, 0},
3997                                                 {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1}
3998                                         }                                       // VkOffset3D                                   dstOffset[2];
3999                                 };
4000                                 region.imageBlit        = imageBlit;
4001                                 params.regions.push_back(region);
4002                         }
4003
4004                         addBlittingTestsAllFormats(blitImgAllFormatsTests.get(), testCtx, params);
4005                 }
4006
4007                 // Test Depth and Stencil formats.
4008                 {
4009                         const VkFormat  compatibleDepthAndStencilFormats[]      =
4010                         {
4011                                 VK_FORMAT_D16_UNORM,
4012                                 VK_FORMAT_X8_D24_UNORM_PACK32,
4013                                 VK_FORMAT_D32_SFLOAT,
4014                                 VK_FORMAT_S8_UINT,
4015                                 VK_FORMAT_D16_UNORM_S8_UINT,
4016                                 VK_FORMAT_D24_UNORM_S8_UINT,
4017                                 VK_FORMAT_D32_SFLOAT_S8_UINT,
4018                         };
4019
4020                         for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < DE_LENGTH_OF_ARRAY(compatibleDepthAndStencilFormats); ++compatibleFormatsIndex)
4021                         {
4022                                 TestParams params;
4023
4024                                 params.src.image.extent = defaultExtent;
4025                                 params.dst.image.extent = defaultExtent;
4026                                 params.src.image.format = compatibleDepthAndStencilFormats[compatibleFormatsIndex];
4027                                 params.dst.image.format = params.src.image.format;
4028                                 std::ostringstream      oss;
4029                                 oss << testName << "_" << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
4030
4031                                 const VkImageSubresourceLayers  defaultDepthSourceLayer         = { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u };
4032                                 const VkImageSubresourceLayers  defaultStencilSourceLayer       = { VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u };
4033
4034                                 CopyRegion      region;
4035                                 for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
4036                                 {
4037                                         const VkOffset3D        srcOffset0      = {0, 0, 0};
4038                                         const VkOffset3D        srcOffset1      = {defaultSize, defaultSize, 1};
4039                                         const VkOffset3D        dstOffset0      = {i, 0, 0};
4040                                         const VkOffset3D        dstOffset1      = {i + defaultFourthSize / j, defaultFourthSize / j, 1};
4041
4042                                         if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
4043                                         {
4044                                                 const VkImageBlit                       imageBlit       =
4045                                                 {
4046                                                         defaultDepthSourceLayer,                // VkImageSubresourceLayers     srcSubresource;
4047                                                         { srcOffset0 , srcOffset1 },    // VkOffset3D                                   srcOffsets[2];
4048                                                         defaultDepthSourceLayer,                // VkImageSubresourceLayers     dstSubresource;
4049                                                         { dstOffset0 , dstOffset1 },    // VkOffset3D                                   dstOffset[2];
4050                                                 };
4051                                                 region.imageBlit        = imageBlit;
4052                                                 params.regions.push_back(region);
4053                                         }
4054                                         if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
4055                                         {
4056                                                 const VkImageBlit                       imageBlit       =
4057                                                 {
4058                                                         defaultStencilSourceLayer,              // VkImageSubresourceLayers     srcSubresource;
4059                                                         { srcOffset0 , srcOffset1 },    // VkOffset3D                                   srcOffsets[2];
4060                                                         defaultStencilSourceLayer,              // VkImageSubresourceLayers     dstSubresource;
4061                                                         { dstOffset0 , dstOffset1 },    // VkOffset3D                                   dstOffset[2];
4062                                                 };
4063                                                 region.imageBlit        = imageBlit;
4064                                                 params.regions.push_back(region);
4065                                         }
4066                                 }
4067                                 for (int i = 0; i < defaultSize; i += defaultFourthSize)
4068                                 {
4069                                         const VkOffset3D        srcOffset0      = {i, i, 0};
4070                                         const VkOffset3D        srcOffset1      = {i + defaultFourthSize, i + defaultFourthSize, 1};
4071                                         const VkOffset3D        dstOffset0      = {i, defaultSize / 2, 0};
4072                                         const VkOffset3D        dstOffset1      = {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1};
4073
4074                                         if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
4075                                         {
4076                                                 const VkImageBlit                       imageBlit       =
4077                                                 {
4078                                                         defaultDepthSourceLayer,                // VkImageSubresourceLayers     srcSubresource;
4079                                                         { srcOffset0, srcOffset1 },             // VkOffset3D                                   srcOffsets[2];
4080                                                         defaultDepthSourceLayer,                // VkImageSubresourceLayers     dstSubresource;
4081                                                         { dstOffset0, dstOffset1 }              // VkOffset3D                                   dstOffset[2];
4082                                                 };
4083                                                 region.imageBlit        = imageBlit;
4084                                                 params.regions.push_back(region);
4085                                         }
4086                                         if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
4087                                         {
4088                                                 const VkImageBlit                       imageBlit       =
4089                                                 {
4090                                                         defaultStencilSourceLayer,              // VkImageSubresourceLayers     srcSubresource;
4091                                                         { srcOffset0, srcOffset1 },             // VkOffset3D                                   srcOffsets[2];
4092                                                         defaultStencilSourceLayer,              // VkImageSubresourceLayers     dstSubresource;
4093                                                         { dstOffset0, dstOffset1 }              // VkOffset3D                                   dstOffset[2];
4094                                                 };
4095                                                 region.imageBlit        = imageBlit;
4096                                                 params.regions.push_back(region);
4097                                         }
4098                                 }
4099
4100                                 params.filter                   = VK_FILTER_NEAREST;
4101                                 blitImgAllFormatsTests->addChild(new BlittingTestCase(testCtx, oss.str() + "_nearest", description, params));
4102                         }
4103                 }
4104         }
4105         blittingImageTests->addChild(blitImgSimpleTests.release());
4106         blittingImageTests->addChild(blitImgAllFormatsTests.release());
4107
4108
4109         // Resolve image to image testcases.
4110         const VkSampleCountFlagBits     samples[]               =
4111         {
4112                 VK_SAMPLE_COUNT_2_BIT,
4113                 VK_SAMPLE_COUNT_4_BIT,
4114                 VK_SAMPLE_COUNT_8_BIT,
4115                 VK_SAMPLE_COUNT_16_BIT,
4116                 VK_SAMPLE_COUNT_32_BIT,
4117                 VK_SAMPLE_COUNT_64_BIT
4118         };
4119         const VkExtent3D                        resolveExtent   = {256u, 256u, 1};
4120
4121         {
4122                 const std::string       description     ("Resolve from image to image");
4123                 const std::string       testName        ("whole");
4124
4125                 TestParams                      params;
4126                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4127                 params.src.image.extent = resolveExtent;
4128                 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4129                 params.dst.image.extent = resolveExtent;
4130
4131                 {
4132                         const VkImageSubresourceLayers  sourceLayer     =
4133                         {
4134                                 VK_IMAGE_ASPECT_COLOR_BIT,      // VkImageAspectFlags   aspectMask;
4135                                 0u,                                                     // uint32_t                             mipLevel;
4136                                 0u,                                                     // uint32_t                             baseArrayLayer;
4137                                 1u                                                      // uint32_t                             layerCount;
4138                         };
4139                         const VkImageResolve                    testResolve     =
4140                         {
4141                                 sourceLayer,    // VkImageSubresourceLayers     srcSubresource;
4142                                 {0, 0, 0},              // VkOffset3D                           srcOffset;
4143                                 sourceLayer,    // VkImageSubresourceLayers     dstSubresource;
4144                                 {0, 0, 0},              // VkOffset3D                           dstOffset;
4145                                 resolveExtent,  // VkExtent3D                           extent;
4146                         };
4147
4148                         CopyRegion      imageResolve;
4149                         imageResolve.imageResolve       = testResolve;
4150                         params.regions.push_back(imageResolve);
4151                 }
4152
4153                 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4154                 {
4155                         params.samples = samples[samplesIndex];
4156                         std::ostringstream caseName;
4157                         caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4158                         resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4159                 }
4160         }
4161
4162         {
4163                 const std::string       description     ("Resolve from image to image");
4164                 const std::string       testName        ("partial");
4165
4166                 TestParams                      params;
4167                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4168                 params.src.image.extent = resolveExtent;
4169                 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4170                 params.dst.image.extent = resolveExtent;
4171
4172                 {
4173                         const VkImageSubresourceLayers  sourceLayer     =
4174                         {
4175                                 VK_IMAGE_ASPECT_COLOR_BIT,      // VkImageAspectFlags   aspectMask;
4176                                 0u,                                                     // uint32_t                             mipLevel;
4177                                 0u,                                                     // uint32_t                             baseArrayLayer;
4178                                 1u                                                      // uint32_t                             layerCount;
4179                         };
4180                         const VkImageResolve                    testResolve     =
4181                         {
4182                                 sourceLayer,    // VkImageSubresourceLayers     srcSubresource;
4183                                 {0, 0, 0},              // VkOffset3D                           srcOffset;
4184                                 sourceLayer,    // VkImageSubresourceLayers     dstSubresource;
4185                                 {64u, 64u, 0},          // VkOffset3D                           dstOffset;
4186                                 {128u, 128u, 1u},       // VkExtent3D                           extent;
4187                         };
4188
4189                         CopyRegion      imageResolve;
4190                         imageResolve.imageResolve = testResolve;
4191                         params.regions.push_back(imageResolve);
4192                 }
4193
4194                 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4195                 {
4196                         params.samples = samples[samplesIndex];
4197                         std::ostringstream caseName;
4198                         caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4199                         resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4200                 }
4201         }
4202
4203         {
4204                 const std::string       description     ("Resolve from image to image");
4205                 const std::string       testName        ("with_regions");
4206
4207                 TestParams                      params;
4208                 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4209                 params.src.image.extent = resolveExtent;
4210                 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4211                 params.dst.image.extent = resolveExtent;
4212
4213                 {
4214                         const VkImageSubresourceLayers  sourceLayer     =
4215                         {
4216                                 VK_IMAGE_ASPECT_COLOR_BIT,      // VkImageAspectFlags   aspectMask;
4217                                 0u,                                                     // uint32_t                             mipLevel;
4218                                 0u,                                                     // uint32_t                             baseArrayLayer;
4219                                 1u                                                      // uint32_t                             layerCount;
4220                         };
4221
4222                         for (int i = 0; i < 256; i += 64)
4223                         {
4224                                 const VkImageResolve                    testResolve     =
4225                                 {
4226                                         sourceLayer,    // VkImageSubresourceLayers     srcSubresource;
4227                                         {i, i, 0},              // VkOffset3D                           srcOffset;
4228                                         sourceLayer,    // VkImageSubresourceLayers     dstSubresource;
4229                                         {i, 0, 0},              // VkOffset3D                           dstOffset;
4230                                         {64u, 64u, 1u}, // VkExtent3D                           extent;
4231                                 };
4232
4233                                 CopyRegion      imageResolve;
4234                                 imageResolve.imageResolve = testResolve;
4235                                 params.regions.push_back(imageResolve);
4236                         }
4237                 }
4238
4239                 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4240                 {
4241                         params.samples = samples[samplesIndex];
4242                         std::ostringstream caseName;
4243                         caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4244                         resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4245                 }
4246         }
4247
4248         copiesAndBlittingTests->addChild(imageToImageTests.release());
4249         copiesAndBlittingTests->addChild(imageToBufferTests.release());
4250         copiesAndBlittingTests->addChild(bufferToImageTests.release());
4251         copiesAndBlittingTests->addChild(bufferToBufferTests.release());
4252         copiesAndBlittingTests->addChild(blittingImageTests.release());
4253         copiesAndBlittingTests->addChild(resolveImageTests.release());
4254
4255         return copiesAndBlittingTests.release();
4256 }
4257
4258 } // api
4259 } // vkt