1 /*------------------------------------------------------------------------
2 * Vulkan Conformance Tests
3 * ------------------------
5 * Copyright (c) 2015-2016 The Khronos Group Inc.
6 * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * \brief Vulkan Copies And Blitting Tests
23 *//*--------------------------------------------------------------------*/
25 #include "vktApiCopiesAndBlittingTests.hpp"
27 #include "deStringUtil.hpp"
28 #include "deUniquePtr.hpp"
30 #include "tcuImageCompare.hpp"
31 #include "tcuTexture.hpp"
32 #include "tcuTextureUtil.hpp"
33 #include "tcuVectorType.hpp"
34 #include "tcuVectorUtil.hpp"
35 #include "tcuTestLog.hpp"
36 #include "tcuTexLookupVerifier.hpp"
38 #include "vkImageUtil.hpp"
39 #include "vkMemUtil.hpp"
40 #include "vkPrograms.hpp"
41 #include "vkQueryUtil.hpp"
42 #include "vkRefUtil.hpp"
43 #include "vktTestCase.hpp"
44 #include "vktTestCaseUtil.hpp"
45 #include "vktTestGroupUtil.hpp"
46 #include "vkTypeUtil.hpp"
61 MIRROR_MODE_X = (1<<0),
62 MIRROR_MODE_Y = (1<<1),
63 MIRROR_MODE_XY = MIRROR_MODE_X | MIRROR_MODE_Y,
70 ALLOCATION_KIND_SUBALLOCATED,
71 ALLOCATION_KIND_DEDICATED,
74 template <typename Type>
78 bool operator() (const Type& a, const Type& b) const
80 return deMemCmp(&a, &b, sizeof(Type)) < 0;
84 typedef std::set<vk::VkFormat, BinaryCompare<vk::VkFormat> > FormatSet;
86 FormatSet dedicatedAllocationImageToImageFormatsToTestSet;
87 FormatSet dedicatedAllocationBlittingFormatsToTestSet;
91 VkImageAspectFlags getAspectFlags (tcu::TextureFormat format)
93 VkImageAspectFlags aspectFlag = 0;
94 aspectFlag |= (tcu::hasDepthComponent(format.order)? VK_IMAGE_ASPECT_DEPTH_BIT : 0);
95 aspectFlag |= (tcu::hasStencilComponent(format.order)? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
98 aspectFlag = VK_IMAGE_ASPECT_COLOR_BIT;
103 // This is effectively same as vk::isFloatFormat(mapTextureFormat(format))
104 // except that it supports some formats that are not mappable to VkFormat.
105 // When we are checking combined depth and stencil formats, each aspect is
106 // checked separately, and in some cases we construct PBA with a format that
107 // is not mappable to VkFormat.
108 bool isFloatFormat (tcu::TextureFormat format)
110 return tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
115 VkBufferCopy bufferCopy;
116 VkImageCopy imageCopy;
117 VkBufferImageCopy bufferImageCopy;
118 VkImageBlit imageBlit;
119 VkImageResolve imageResolve;
124 VkImageType imageType;
127 VkImageLayout operationLayout;
142 std::vector<CopyRegion> regions;
147 VkSampleCountFlagBits samples;
150 AllocationKind allocationKind;
153 de::MovePtr<Allocation> allocateBuffer (const InstanceInterface& vki,
154 const DeviceInterface& vkd,
155 const VkPhysicalDevice& physDevice,
156 const VkDevice device,
157 const VkBuffer& buffer,
158 const MemoryRequirement requirement,
159 Allocator& allocator,
160 AllocationKind allocationKind)
162 switch (allocationKind)
164 case ALLOCATION_KIND_SUBALLOCATED:
166 const VkMemoryRequirements memoryRequirements = getBufferMemoryRequirements(vkd, device, buffer);
168 return allocator.allocate(memoryRequirements, requirement);
171 case ALLOCATION_KIND_DEDICATED:
173 return allocateDedicated(vki, vkd, physDevice, device, buffer, requirement);
178 TCU_THROW(InternalError, "Invalid allocation kind");
183 de::MovePtr<Allocation> allocateImage (const InstanceInterface& vki,
184 const DeviceInterface& vkd,
185 const VkPhysicalDevice& physDevice,
186 const VkDevice device,
187 const VkImage& image,
188 const MemoryRequirement requirement,
189 Allocator& allocator,
190 AllocationKind allocationKind)
192 switch (allocationKind)
194 case ALLOCATION_KIND_SUBALLOCATED:
196 const VkMemoryRequirements memoryRequirements = getImageMemoryRequirements(vkd, device, image);
198 return allocator.allocate(memoryRequirements, requirement);
201 case ALLOCATION_KIND_DEDICATED:
203 return allocateDedicated(vki, vkd, physDevice, device, image, requirement);
208 TCU_THROW(InternalError, "Invalid allocation kind");
214 inline deUint32 getArraySize(const ImageParms& parms)
216 return (parms.imageType == VK_IMAGE_TYPE_2D) ? parms.extent.depth : 1u;
219 inline VkExtent3D getExtent3D(const ImageParms& parms)
221 const VkExtent3D extent =
225 (parms.imageType == VK_IMAGE_TYPE_2D) ? 1u : parms.extent.depth
230 const tcu::TextureFormat mapCombinedToDepthTransferFormat (const tcu::TextureFormat& combinedFormat)
232 tcu::TextureFormat format;
233 switch (combinedFormat.type)
235 case tcu::TextureFormat::UNSIGNED_INT_16_8_8:
236 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
238 case tcu::TextureFormat::UNSIGNED_INT_24_8_REV:
239 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNSIGNED_INT_24_8_REV);
241 case tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:
242 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT);
251 class CopiesAndBlittingTestInstance : public vkt::TestInstance
254 CopiesAndBlittingTestInstance (Context& context,
255 TestParams testParams);
256 virtual tcu::TestStatus iterate (void) = 0;
260 FILL_MODE_GRADIENT = 0,
263 FILL_MODE_MULTISAMPLE,
269 const TestParams m_params;
271 Move<VkCommandPool> m_cmdPool;
272 Move<VkCommandBuffer> m_cmdBuffer;
273 Move<VkFence> m_fence;
274 de::MovePtr<tcu::TextureLevel> m_sourceTextureLevel;
275 de::MovePtr<tcu::TextureLevel> m_destinationTextureLevel;
276 de::MovePtr<tcu::TextureLevel> m_expectedTextureLevel;
278 VkCommandBufferBeginInfo m_cmdBufferBeginInfo;
280 void generateBuffer (tcu::PixelBufferAccess buffer, int width, int height, int depth = 1, FillMode = FILL_MODE_GRADIENT);
281 virtual void generateExpectedResult (void);
282 void uploadBuffer (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc);
283 void uploadImage (const tcu::ConstPixelBufferAccess& src, VkImage dst, const ImageParms& parms);
284 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
285 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region) = 0;
286 deUint32 calculateSize (tcu::ConstPixelBufferAccess src) const
288 return src.getWidth() * src.getHeight() * src.getDepth() * tcu::getPixelSize(src.getFormat());
291 de::MovePtr<tcu::TextureLevel> readImage (vk::VkImage image,
292 const ImageParms& imageParms);
293 void submitCommandsAndWait (const DeviceInterface& vk,
294 const VkDevice device,
296 const VkCommandBuffer& cmdBuffer);
299 void uploadImageAspect (const tcu::ConstPixelBufferAccess& src,
301 const ImageParms& parms);
302 void readImageAspect (vk::VkImage src,
303 const tcu::PixelBufferAccess& dst,
304 const ImageParms& parms);
307 CopiesAndBlittingTestInstance::CopiesAndBlittingTestInstance (Context& context, TestParams testParams)
308 : vkt::TestInstance (context)
309 , m_params (testParams)
311 const DeviceInterface& vk = context.getDeviceInterface();
312 const VkDevice vkDevice = context.getDevice();
313 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
315 if (m_params.allocationKind == ALLOCATION_KIND_DEDICATED)
317 const std::string extensionName("VK_KHR_dedicated_allocation");
319 if (!de::contains(context.getDeviceExtensions().begin(), context.getDeviceExtensions().end(), extensionName))
320 TCU_THROW(NotSupportedError, std::string(extensionName + " is not supported").c_str());
323 // Create command pool
324 m_cmdPool = createCommandPool(vk, vkDevice, VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT, queueFamilyIndex);
326 // Create command buffer
327 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, *m_cmdPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY);
330 m_fence = createFence(vk, vkDevice);
333 void CopiesAndBlittingTestInstance::generateBuffer (tcu::PixelBufferAccess buffer, int width, int height, int depth, FillMode mode)
335 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(buffer.getFormat().type);
336 tcu::Vec4 maxValue (1.0f);
338 if (buffer.getFormat().order == tcu::TextureFormat::S)
340 // Stencil-only is stored in the first component. Stencil is always 8 bits.
341 maxValue.x() = 1 << 8;
343 else if (buffer.getFormat().order == tcu::TextureFormat::DS)
345 // In a combined format, fillWithComponentGradients expects stencil in the fourth component.
346 maxValue.w() = 1 << 8;
348 else if (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER || channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
350 // The tcu::Vectors we use as pixels are 32-bit, so clamp to that.
351 const tcu::IVec4 bits = tcu::min(tcu::getTextureFormatBitDepth(buffer.getFormat()), tcu::IVec4(32));
352 const int signBit = (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER ? 1 : 0);
354 for (int i = 0; i < 4; ++i)
357 maxValue[i] = static_cast<float>((1 << (bits[i] - signBit)) - 1);
361 if (mode == FILL_MODE_GRADIENT)
363 tcu::fillWithComponentGradients(buffer, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), maxValue);
367 const tcu::Vec4 redColor (maxValue.x(), 0.0, 0.0, maxValue.w());
368 const tcu::Vec4 greenColor (0.0, maxValue.y(), 0.0, maxValue.w());
369 const tcu::Vec4 blueColor (0.0, 0.0, maxValue.z(), maxValue.w());
370 const tcu::Vec4 whiteColor (maxValue.x(), maxValue.y(), maxValue.z(), maxValue.w());
372 for (int z = 0; z < depth; ++z)
373 for (int y = 0; y < height; ++y)
374 for (int x = 0; x < width; ++x)
378 case FILL_MODE_WHITE:
379 if (tcu::isCombinedDepthStencilType(buffer.getFormat().type))
381 buffer.setPixDepth(1.0f, x, y, z);
382 if (tcu::hasStencilComponent(buffer.getFormat().order))
383 buffer.setPixStencil(255, x, y, z);
386 buffer.setPixel(whiteColor, x, y, z);
390 if (tcu::isCombinedDepthStencilType(buffer.getFormat().type))
392 buffer.setPixDepth(redColor[x % 4], x, y, z);
393 if (tcu::hasStencilComponent(buffer.getFormat().order))
394 buffer.setPixStencil(255 * (int)redColor[y % 4], x, y, z);
397 buffer.setPixel(redColor, x, y, z);
400 case FILL_MODE_MULTISAMPLE:
402 float xScaled = static_cast<float>(x) / static_cast<float>(width);
403 float yScaled = static_cast<float>(y) / static_cast<float>(height);
404 buffer.setPixel((xScaled == yScaled) ? tcu::Vec4(0.0, 0.5, 0.5, 1.0) : ((xScaled > yScaled) ? greenColor : blueColor), x, y, z);
414 void CopiesAndBlittingTestInstance::uploadBuffer (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc)
416 const DeviceInterface& vk = m_context.getDeviceInterface();
417 const VkDevice vkDevice = m_context.getDevice();
418 const deUint32 bufferSize = calculateSize(bufferAccess);
421 deMemcpy(bufferAlloc.getHostPtr(), bufferAccess.getDataPtr(), bufferSize);
422 flushMappedMemoryRange(vk, vkDevice, bufferAlloc.getMemory(), bufferAlloc.getOffset(), bufferSize);
425 void CopiesAndBlittingTestInstance::uploadImageAspect (const tcu::ConstPixelBufferAccess& imageAccess, const VkImage& image, const ImageParms& parms)
427 const InstanceInterface& vki = m_context.getInstanceInterface();
428 const DeviceInterface& vk = m_context.getDeviceInterface();
429 const VkPhysicalDevice vkPhysDevice = m_context.getPhysicalDevice();
430 const VkDevice vkDevice = m_context.getDevice();
431 const VkQueue queue = m_context.getUniversalQueue();
432 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
433 Allocator& memAlloc = m_context.getDefaultAllocator();
434 Move<VkBuffer> buffer;
435 const deUint32 bufferSize = calculateSize(imageAccess);
436 de::MovePtr<Allocation> bufferAlloc;
437 const deUint32 arraySize = getArraySize(parms);
438 const VkExtent3D imageExtent = getExtent3D(parms);
440 // Create source buffer
442 const VkBufferCreateInfo bufferParams =
444 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
445 DE_NULL, // const void* pNext;
446 0u, // VkBufferCreateFlags flags;
447 bufferSize, // VkDeviceSize size;
448 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
449 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
450 1u, // deUint32 queueFamilyIndexCount;
451 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
454 buffer = createBuffer(vk, vkDevice, &bufferParams);
455 bufferAlloc = allocateBuffer(vki, vk, vkPhysDevice, vkDevice, *buffer, MemoryRequirement::HostVisible, memAlloc, m_params.allocationKind);
456 VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
459 // Barriers for copying buffer to image
460 const VkBufferMemoryBarrier preBufferBarrier =
462 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
463 DE_NULL, // const void* pNext;
464 VK_ACCESS_HOST_WRITE_BIT, // VkAccessFlags srcAccessMask;
465 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
466 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
467 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
468 *buffer, // VkBuffer buffer;
469 0u, // VkDeviceSize offset;
470 bufferSize // VkDeviceSize size;
473 const VkImageAspectFlags formatAspect = getAspectFlags(mapVkFormat(parms.format));
474 const bool skipPreImageBarrier = formatAspect == (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT) &&
475 getAspectFlags(imageAccess.getFormat()) == VK_IMAGE_ASPECT_STENCIL_BIT;
476 const VkImageMemoryBarrier preImageBarrier =
478 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
479 DE_NULL, // const void* pNext;
480 0u, // VkAccessFlags srcAccessMask;
481 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
482 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
483 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
484 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
485 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
486 image, // VkImage image;
487 { // VkImageSubresourceRange subresourceRange;
488 formatAspect, // VkImageAspectFlags aspect;
489 0u, // deUint32 baseMipLevel;
490 1u, // deUint32 mipLevels;
491 0u, // deUint32 baseArraySlice;
492 arraySize, // deUint32 arraySize;
496 const VkImageMemoryBarrier postImageBarrier =
498 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
499 DE_NULL, // const void* pNext;
500 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
501 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
502 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
503 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
504 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
505 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
506 image, // VkImage image;
507 { // VkImageSubresourceRange subresourceRange;
508 formatAspect, // VkImageAspectFlags aspect;
509 0u, // deUint32 baseMipLevel;
510 1u, // deUint32 mipLevels;
511 0u, // deUint32 baseArraySlice;
512 arraySize, // deUint32 arraySize;
516 const VkBufferImageCopy copyRegion =
518 0u, // VkDeviceSize bufferOffset;
519 (deUint32)imageAccess.getWidth(), // deUint32 bufferRowLength;
520 (deUint32)imageAccess.getHeight(), // deUint32 bufferImageHeight;
522 getAspectFlags(imageAccess.getFormat()), // VkImageAspectFlags aspect;
523 0u, // deUint32 mipLevel;
524 0u, // deUint32 baseArrayLayer;
525 arraySize, // deUint32 layerCount;
526 }, // VkImageSubresourceLayers imageSubresource;
527 { 0, 0, 0 }, // VkOffset3D imageOffset;
528 imageExtent // VkExtent3D imageExtent;
532 deMemcpy(bufferAlloc->getHostPtr(), imageAccess.getDataPtr(), bufferSize);
533 flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), bufferSize);
535 // Copy buffer to image
536 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
538 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
539 DE_NULL, // const void* pNext;
540 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
541 (const VkCommandBufferInheritanceInfo*)DE_NULL,
544 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
545 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL,
546 1, &preBufferBarrier, (skipPreImageBarrier ? 0 : 1), (skipPreImageBarrier ? DE_NULL : &preImageBarrier));
547 vk.cmdCopyBufferToImage(*m_cmdBuffer, *buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ©Region);
548 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, &postImageBarrier);
549 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
551 submitCommandsAndWait(vk, vkDevice, queue, *m_cmdBuffer);
554 void CopiesAndBlittingTestInstance::uploadImage (const tcu::ConstPixelBufferAccess& src, VkImage dst, const ImageParms& parms)
556 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
558 if (tcu::hasDepthComponent(src.getFormat().order))
560 tcu::TextureLevel depthTexture (mapCombinedToDepthTransferFormat(src.getFormat()), src.getWidth(), src.getHeight(), src.getDepth());
561 tcu::copy(depthTexture.getAccess(), tcu::getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_DEPTH));
562 uploadImageAspect(depthTexture.getAccess(), dst, parms);
565 if (tcu::hasStencilComponent(src.getFormat().order))
567 tcu::TextureLevel stencilTexture (tcu::getEffectiveDepthStencilTextureFormat(src.getFormat(), tcu::Sampler::MODE_STENCIL), src.getWidth(), src.getHeight(), src.getDepth());
568 tcu::copy(stencilTexture.getAccess(), tcu::getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_STENCIL));
569 uploadImageAspect(stencilTexture.getAccess(), dst, parms);
573 uploadImageAspect(src, dst, parms);
576 tcu::TestStatus CopiesAndBlittingTestInstance::checkTestResult (tcu::ConstPixelBufferAccess result)
578 const tcu::ConstPixelBufferAccess expected = m_expectedTextureLevel->getAccess();
580 if (isFloatFormat(result.getFormat()))
582 const tcu::Vec4 threshold (0.0f);
583 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
584 return tcu::TestStatus::fail("CopiesAndBlitting test");
588 const tcu::UVec4 threshold (0u);
589 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
590 return tcu::TestStatus::fail("CopiesAndBlitting test");
593 return tcu::TestStatus::pass("CopiesAndBlitting test");
596 void CopiesAndBlittingTestInstance::generateExpectedResult (void)
598 const tcu::ConstPixelBufferAccess src = m_sourceTextureLevel->getAccess();
599 const tcu::ConstPixelBufferAccess dst = m_destinationTextureLevel->getAccess();
601 m_expectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
602 tcu::copy(m_expectedTextureLevel->getAccess(), dst);
604 for (deUint32 i = 0; i < m_params.regions.size(); i++)
605 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), m_params.regions[i]);
608 class CopiesAndBlittingTestCase : public vkt::TestCase
611 CopiesAndBlittingTestCase (tcu::TestContext& testCtx,
612 const std::string& name,
613 const std::string& description)
614 : vkt::TestCase (testCtx, name, description)
617 virtual TestInstance* createInstance (Context& context) const = 0;
620 void CopiesAndBlittingTestInstance::readImageAspect (vk::VkImage image,
621 const tcu::PixelBufferAccess& dst,
622 const ImageParms& imageParms)
624 const InstanceInterface& vki = m_context.getInstanceInterface();
625 const DeviceInterface& vk = m_context.getDeviceInterface();
626 const VkPhysicalDevice physDevice = m_context.getPhysicalDevice();
627 const VkDevice device = m_context.getDevice();
628 const VkQueue queue = m_context.getUniversalQueue();
629 Allocator& allocator = m_context.getDefaultAllocator();
631 Move<VkBuffer> buffer;
632 de::MovePtr<Allocation> bufferAlloc;
633 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
634 const VkDeviceSize pixelDataSize = calculateSize(dst);
635 const VkExtent3D imageExtent = getExtent3D(imageParms);
637 // Create destination buffer
639 const VkBufferCreateInfo bufferParams =
641 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
642 DE_NULL, // const void* pNext;
643 0u, // VkBufferCreateFlags flags;
644 pixelDataSize, // VkDeviceSize size;
645 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
646 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
647 1u, // deUint32 queueFamilyIndexCount;
648 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
651 buffer = createBuffer(vk, device, &bufferParams);
652 bufferAlloc = allocateBuffer(vki, vk, physDevice, device, *buffer, MemoryRequirement::HostVisible, allocator, m_params.allocationKind);
653 VK_CHECK(vk.bindBufferMemory(device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
655 deMemset(bufferAlloc->getHostPtr(), 0, static_cast<size_t>(pixelDataSize));
656 flushMappedMemoryRange(vk, device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), pixelDataSize);
659 // Barriers for copying image to buffer
660 const VkImageAspectFlags formatAspect = getAspectFlags(mapVkFormat(imageParms.format));
661 const VkImageMemoryBarrier imageBarrier =
663 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
664 DE_NULL, // const void* pNext;
665 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
666 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
667 imageParms.operationLayout, // VkImageLayout oldLayout;
668 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
669 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
670 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
671 image, // VkImage image;
672 { // VkImageSubresourceRange subresourceRange;
673 formatAspect, // VkImageAspectFlags aspectMask;
674 0u, // deUint32 baseMipLevel;
675 1u, // deUint32 mipLevels;
676 0u, // deUint32 baseArraySlice;
677 getArraySize(imageParms)// deUint32 arraySize;
681 const VkBufferMemoryBarrier bufferBarrier =
683 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
684 DE_NULL, // const void* pNext;
685 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
686 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
687 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
688 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
689 *buffer, // VkBuffer buffer;
690 0u, // VkDeviceSize offset;
691 pixelDataSize // VkDeviceSize size;
694 const VkImageMemoryBarrier postImageBarrier =
696 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
697 DE_NULL, // const void* pNext;
698 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags srcAccessMask;
699 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
700 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout oldLayout;
701 imageParms.operationLayout, // VkImageLayout newLayout;
702 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
703 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
704 image, // VkImage image;
706 formatAspect, // VkImageAspectFlags aspectMask;
707 0u, // deUint32 baseMipLevel;
708 1u, // deUint32 mipLevels;
709 0u, // deUint32 baseArraySlice;
710 getArraySize(imageParms) // deUint32 arraySize;
711 } // VkImageSubresourceRange subresourceRange;
714 // Copy image to buffer
715 const VkImageAspectFlags aspect = getAspectFlags(dst.getFormat());
716 const VkBufferImageCopy copyRegion =
718 0u, // VkDeviceSize bufferOffset;
719 (deUint32)dst.getWidth(), // deUint32 bufferRowLength;
720 (deUint32)dst.getHeight(), // deUint32 bufferImageHeight;
722 aspect, // VkImageAspectFlags aspect;
723 0u, // deUint32 mipLevel;
724 0u, // deUint32 baseArrayLayer;
725 getArraySize(imageParms), // deUint32 layerCount;
726 }, // VkImageSubresourceLayers imageSubresource;
727 { 0, 0, 0 }, // VkOffset3D imageOffset;
728 imageExtent // VkExtent3D imageExtent;
731 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
733 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
734 DE_NULL, // const void* pNext;
735 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
736 (const VkCommandBufferInheritanceInfo*)DE_NULL,
739 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
740 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);
741 vk.cmdCopyImageToBuffer(*m_cmdBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, 1u, ©Region);
742 vk.cmdPipelineBarrier(*m_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);
743 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
745 submitCommandsAndWait(vk, device, queue, *m_cmdBuffer);
748 invalidateMappedMemoryRange(vk, device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), pixelDataSize);
749 tcu::copy(dst, tcu::ConstPixelBufferAccess(dst.getFormat(), dst.getSize(), bufferAlloc->getHostPtr()));
752 void CopiesAndBlittingTestInstance::submitCommandsAndWait (const DeviceInterface& vk, const VkDevice device, const VkQueue queue, const VkCommandBuffer& cmdBuffer)
754 const VkSubmitInfo submitInfo =
756 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
757 DE_NULL, // const void* pNext;
758 0u, // deUint32 waitSemaphoreCount;
759 DE_NULL, // const VkSemaphore* pWaitSemaphores;
760 (const VkPipelineStageFlags*)DE_NULL,
761 1u, // deUint32 commandBufferCount;
762 &cmdBuffer, // const VkCommandBuffer* pCommandBuffers;
763 0u, // deUint32 signalSemaphoreCount;
764 DE_NULL // const VkSemaphore* pSignalSemaphores;
767 VK_CHECK(vk.resetFences(device, 1, &m_fence.get()));
768 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
769 VK_CHECK(vk.waitForFences(device, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
772 de::MovePtr<tcu::TextureLevel> CopiesAndBlittingTestInstance::readImage (vk::VkImage image,
773 const ImageParms& parms)
775 const tcu::TextureFormat imageFormat = mapVkFormat(parms.format);
776 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(imageFormat, parms.extent.width, parms.extent.height, parms.extent.depth));
778 if (tcu::isCombinedDepthStencilType(imageFormat.type))
780 if (tcu::hasDepthComponent(imageFormat.order))
782 tcu::TextureLevel depthTexture (mapCombinedToDepthTransferFormat(imageFormat), parms.extent.width, parms.extent.height, parms.extent.depth);
783 readImageAspect(image, depthTexture.getAccess(), parms);
784 tcu::copy(tcu::getEffectiveDepthStencilAccess(resultLevel->getAccess(), tcu::Sampler::MODE_DEPTH), depthTexture.getAccess());
787 if (tcu::hasStencilComponent(imageFormat.order))
789 tcu::TextureLevel stencilTexture (tcu::getEffectiveDepthStencilTextureFormat(imageFormat, tcu::Sampler::MODE_STENCIL), parms.extent.width, parms.extent.height, parms.extent.depth);
790 readImageAspect(image, stencilTexture.getAccess(), parms);
791 tcu::copy(tcu::getEffectiveDepthStencilAccess(resultLevel->getAccess(), tcu::Sampler::MODE_STENCIL), stencilTexture.getAccess());
795 readImageAspect(image, resultLevel->getAccess(), parms);
800 // Copy from image to image.
802 class CopyImageToImage : public CopiesAndBlittingTestInstance
805 CopyImageToImage (Context& context,
807 virtual tcu::TestStatus iterate (void);
810 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
813 Move<VkImage> m_source;
814 de::MovePtr<Allocation> m_sourceImageAlloc;
815 Move<VkImage> m_destination;
816 de::MovePtr<Allocation> m_destinationImageAlloc;
818 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
821 CopyImageToImage::CopyImageToImage (Context& context, TestParams params)
822 : CopiesAndBlittingTestInstance(context, params)
824 const InstanceInterface& vki = context.getInstanceInterface();
825 const DeviceInterface& vk = context.getDeviceInterface();
826 const VkPhysicalDevice vkPhysDevice = context.getPhysicalDevice();
827 const VkDevice vkDevice = context.getDevice();
828 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
829 Allocator& memAlloc = context.getDefaultAllocator();
831 if ((m_params.dst.image.imageType == VK_IMAGE_TYPE_3D && m_params.src.image.imageType == VK_IMAGE_TYPE_2D) ||
832 (m_params.dst.image.imageType == VK_IMAGE_TYPE_2D && m_params.src.image.imageType == VK_IMAGE_TYPE_3D))
834 if (std::find(context.getDeviceExtensions().begin(), context.getDeviceExtensions().end(), "VK_KHR_maintenance1") == context.getDeviceExtensions().end())
835 TCU_THROW(NotSupportedError, "Extension VK_KHR_maintenance1 not supported");
838 VkImageFormatProperties properties;
839 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
840 m_params.src.image.format,
841 m_params.src.image.imageType,
842 VK_IMAGE_TILING_OPTIMAL,
843 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
845 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
846 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
847 m_params.dst.image.format,
848 m_params.dst.image.imageType,
849 VK_IMAGE_TILING_OPTIMAL,
850 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
852 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
854 TCU_THROW(NotSupportedError, "Format not supported");
857 // Create source image
859 const VkImageCreateInfo sourceImageParams =
861 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
862 DE_NULL, // const void* pNext;
863 0u, // VkImageCreateFlags flags;
864 m_params.src.image.imageType, // VkImageType imageType;
865 m_params.src.image.format, // VkFormat format;
866 getExtent3D(m_params.src.image), // VkExtent3D extent;
867 1u, // deUint32 mipLevels;
868 getArraySize(m_params.src.image), // deUint32 arraySize;
869 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
870 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
871 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
872 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
873 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
874 1u, // deUint32 queueFamilyCount;
875 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
876 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
879 m_source = createImage(vk, vkDevice, &sourceImageParams);
880 m_sourceImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_source, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
881 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
884 // Create destination image
886 const VkImageCreateInfo destinationImageParams =
888 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
889 DE_NULL, // const void* pNext;
890 0u, // VkImageCreateFlags flags;
891 m_params.dst.image.imageType, // VkImageType imageType;
892 m_params.dst.image.format, // VkFormat format;
893 getExtent3D(m_params.dst.image), // VkExtent3D extent;
894 1u, // deUint32 mipLevels;
895 getArraySize(m_params.dst.image), // deUint32 arraySize;
896 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
897 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
898 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
899 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
900 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
901 1u, // deUint32 queueFamilyCount;
902 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
903 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
906 m_destination = createImage(vk, vkDevice, &destinationImageParams);
907 m_destinationImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_destination, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
908 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
912 tcu::TestStatus CopyImageToImage::iterate (void)
914 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
915 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
916 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
917 (int)m_params.src.image.extent.width,
918 (int)m_params.src.image.extent.height,
919 (int)m_params.src.image.extent.depth));
920 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);
921 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
922 (int)m_params.dst.image.extent.width,
923 (int)m_params.dst.image.extent.height,
924 (int)m_params.dst.image.extent.depth));
925 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);
926 generateExpectedResult();
928 uploadImage(m_sourceTextureLevel->getAccess(), m_source.get(), m_params.src.image);
929 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get(), m_params.dst.image);
931 const DeviceInterface& vk = m_context.getDeviceInterface();
932 const VkDevice vkDevice = m_context.getDevice();
933 const VkQueue queue = m_context.getUniversalQueue();
935 std::vector<VkImageCopy> imageCopies;
936 for (deUint32 i = 0; i < m_params.regions.size(); i++)
937 imageCopies.push_back(m_params.regions[i].imageCopy);
939 const VkImageMemoryBarrier imageBarriers[] =
943 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
944 DE_NULL, // const void* pNext;
945 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
946 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
947 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
948 m_params.src.image.operationLayout, // VkImageLayout newLayout;
949 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
950 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
951 m_source.get(), // VkImage image;
952 { // VkImageSubresourceRange subresourceRange;
953 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
954 0u, // deUint32 baseMipLevel;
955 1u, // deUint32 mipLevels;
956 0u, // deUint32 baseArraySlice;
957 getArraySize(m_params.src.image)// deUint32 arraySize;
962 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
963 DE_NULL, // const void* pNext;
964 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
965 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
966 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
967 m_params.dst.image.operationLayout, // VkImageLayout newLayout;
968 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
969 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
970 m_destination.get(), // VkImage image;
971 { // VkImageSubresourceRange subresourceRange;
972 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
973 0u, // deUint32 baseMipLevel;
974 1u, // deUint32 mipLevels;
975 0u, // deUint32 baseArraySlice;
976 getArraySize(m_params.dst.image)// deUint32 arraySize;
981 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
983 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
984 DE_NULL, // const void* pNext;
985 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
986 (const VkCommandBufferInheritanceInfo*)DE_NULL,
989 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
990 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);
991 vk.cmdCopyImage(*m_cmdBuffer, m_source.get(), m_params.src.image.operationLayout, m_destination.get(), m_params.dst.image.operationLayout, (deUint32)m_params.regions.size(), imageCopies.data());
992 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
994 submitCommandsAndWait (vk, vkDevice, queue, *m_cmdBuffer);
996 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(*m_destination, m_params.dst.image);
998 return checkTestResult(resultTextureLevel->getAccess());
1001 tcu::TestStatus CopyImageToImage::checkTestResult (tcu::ConstPixelBufferAccess result)
1003 const tcu::Vec4 fThreshold (0.0f);
1004 const tcu::UVec4 uThreshold (0u);
1006 if (tcu::isCombinedDepthStencilType(result.getFormat().type))
1008 if (tcu::hasDepthComponent(result.getFormat().order))
1010 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_DEPTH;
1011 const tcu::ConstPixelBufferAccess depthResult = tcu::getEffectiveDepthStencilAccess(result, mode);
1012 const tcu::ConstPixelBufferAccess expectedResult = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1014 if (isFloatFormat(result.getFormat()))
1016 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", expectedResult, depthResult, fThreshold, tcu::COMPARE_LOG_RESULT))
1017 return tcu::TestStatus::fail("CopiesAndBlitting test");
1021 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", expectedResult, depthResult, uThreshold, tcu::COMPARE_LOG_RESULT))
1022 return tcu::TestStatus::fail("CopiesAndBlitting test");
1026 if (tcu::hasStencilComponent(result.getFormat().order))
1028 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_STENCIL;
1029 const tcu::ConstPixelBufferAccess stencilResult = tcu::getEffectiveDepthStencilAccess(result, mode);
1030 const tcu::ConstPixelBufferAccess expectedResult = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1032 if (isFloatFormat(result.getFormat()))
1034 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", expectedResult, stencilResult, fThreshold, tcu::COMPARE_LOG_RESULT))
1035 return tcu::TestStatus::fail("CopiesAndBlitting test");
1039 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", expectedResult, stencilResult, uThreshold, tcu::COMPARE_LOG_RESULT))
1040 return tcu::TestStatus::fail("CopiesAndBlitting test");
1046 if (isFloatFormat(result.getFormat()))
1048 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", m_expectedTextureLevel->getAccess(), result, fThreshold, tcu::COMPARE_LOG_RESULT))
1049 return tcu::TestStatus::fail("CopiesAndBlitting test");
1051 else if (isSnormFormat(mapTextureFormat(result.getFormat())))
1053 // There may be an ambiguity between two possible binary representations of 1.0.
1054 // Get rid of that by expanding the data to floats and re-normalizing again.
1056 tcu::TextureLevel resultSnorm (result.getFormat(), result.getWidth(), result.getHeight(), result.getDepth());
1058 tcu::TextureLevel resultFloat (tcu::TextureFormat(resultSnorm.getFormat().order, tcu::TextureFormat::FLOAT), resultSnorm.getWidth(), resultSnorm.getHeight(), resultSnorm.getDepth());
1060 tcu::copy(resultFloat.getAccess(), result);
1061 tcu::copy(resultSnorm, resultFloat.getAccess());
1064 tcu::TextureLevel expectedSnorm (m_expectedTextureLevel->getFormat(), m_expectedTextureLevel->getWidth(), m_expectedTextureLevel->getHeight(), m_expectedTextureLevel->getDepth());
1067 tcu::TextureLevel expectedFloat (tcu::TextureFormat(expectedSnorm.getFormat().order, tcu::TextureFormat::FLOAT), expectedSnorm.getWidth(), expectedSnorm.getHeight(), expectedSnorm.getDepth());
1069 tcu::copy(expectedFloat.getAccess(), m_expectedTextureLevel->getAccess());
1070 tcu::copy(expectedSnorm, expectedFloat.getAccess());
1073 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", expectedSnorm.getAccess(), resultSnorm.getAccess(), uThreshold, tcu::COMPARE_LOG_RESULT))
1074 return tcu::TestStatus::fail("CopiesAndBlitting test");
1078 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparison", m_expectedTextureLevel->getAccess(), result, uThreshold, tcu::COMPARE_LOG_RESULT))
1079 return tcu::TestStatus::fail("CopiesAndBlitting test");
1083 return tcu::TestStatus::pass("CopiesAndBlitting test");
1086 void CopyImageToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1088 VkOffset3D srcOffset = region.imageCopy.srcOffset;
1089 VkOffset3D dstOffset = region.imageCopy.dstOffset;
1090 VkExtent3D extent = region.imageCopy.extent;
1092 if (m_params.src.image.imageType == VK_IMAGE_TYPE_3D && m_params.dst.image.imageType == VK_IMAGE_TYPE_2D)
1093 dstOffset.z = srcOffset.z;
1094 if (m_params.src.image.imageType == VK_IMAGE_TYPE_2D && m_params.dst.image.imageType == VK_IMAGE_TYPE_3D)
1096 srcOffset.z = dstOffset.z;
1097 extent.depth = std::max(region.imageCopy.extent.depth, region.imageCopy.srcSubresource.layerCount);
1101 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
1103 DE_ASSERT(src.getFormat() == dst.getFormat());
1106 if (tcu::hasDepthComponent(src.getFormat().order))
1108 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
1109 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
1110 tcu::copy(dstSubRegion, srcSubRegion);
1114 if (tcu::hasStencilComponent(src.getFormat().order))
1116 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
1117 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
1118 tcu::copy(dstSubRegion, srcSubRegion);
1123 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth);
1124 // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
1125 const tcu::PixelBufferAccess dstWithSrcFormat (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
1126 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth);
1128 tcu::copy(dstSubRegion, srcSubRegion);
1132 class CopyImageToImageTestCase : public vkt::TestCase
1135 CopyImageToImageTestCase (tcu::TestContext& testCtx,
1136 const std::string& name,
1137 const std::string& description,
1138 const TestParams params)
1139 : vkt::TestCase (testCtx, name, description)
1143 virtual TestInstance* createInstance (Context& context) const
1145 return new CopyImageToImage(context, m_params);
1148 TestParams m_params;
1151 // Copy from buffer to buffer.
1153 class CopyBufferToBuffer : public CopiesAndBlittingTestInstance
1156 CopyBufferToBuffer (Context& context, TestParams params);
1157 virtual tcu::TestStatus iterate (void);
1159 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess, tcu::PixelBufferAccess, CopyRegion);
1160 Move<VkBuffer> m_source;
1161 de::MovePtr<Allocation> m_sourceBufferAlloc;
1162 Move<VkBuffer> m_destination;
1163 de::MovePtr<Allocation> m_destinationBufferAlloc;
1166 CopyBufferToBuffer::CopyBufferToBuffer (Context& context, TestParams params)
1167 : CopiesAndBlittingTestInstance (context, params)
1169 const InstanceInterface& vki = context.getInstanceInterface();
1170 const DeviceInterface& vk = context.getDeviceInterface();
1171 const VkPhysicalDevice vkPhysDevice = context.getPhysicalDevice();
1172 const VkDevice vkDevice = context.getDevice();
1173 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1174 Allocator& memAlloc = context.getDefaultAllocator();
1176 // Create source buffer
1178 const VkBufferCreateInfo sourceBufferParams =
1180 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1181 DE_NULL, // const void* pNext;
1182 0u, // VkBufferCreateFlags flags;
1183 m_params.src.buffer.size, // VkDeviceSize size;
1184 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
1185 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1186 1u, // deUint32 queueFamilyIndexCount;
1187 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1190 m_source = createBuffer(vk, vkDevice, &sourceBufferParams);
1191 m_sourceBufferAlloc = allocateBuffer(vki, vk, vkPhysDevice, vkDevice, *m_source, MemoryRequirement::HostVisible, memAlloc, m_params.allocationKind);
1192 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
1195 // Create destination buffer
1197 const VkBufferCreateInfo destinationBufferParams =
1199 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1200 DE_NULL, // const void* pNext;
1201 0u, // VkBufferCreateFlags flags;
1202 m_params.dst.buffer.size, // VkDeviceSize size;
1203 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
1204 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1205 1u, // deUint32 queueFamilyIndexCount;
1206 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1209 m_destination = createBuffer(vk, vkDevice, &destinationBufferParams);
1210 m_destinationBufferAlloc = allocateBuffer(vki, vk, vkPhysDevice, vkDevice, *m_destination, MemoryRequirement::HostVisible, memAlloc, m_params.allocationKind);
1211 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
1215 tcu::TestStatus CopyBufferToBuffer::iterate (void)
1217 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
1218 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), srcLevelWidth, 1));
1219 generateBuffer(m_sourceTextureLevel->getAccess(), srcLevelWidth, 1, 1, FILL_MODE_RED);
1221 const int dstLevelWidth = (int)(m_params.dst.buffer.size/4);
1222 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
1223 generateBuffer(m_destinationTextureLevel->getAccess(), dstLevelWidth, 1, 1, FILL_MODE_WHITE);
1225 generateExpectedResult();
1227 uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
1228 uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
1230 const DeviceInterface& vk = m_context.getDeviceInterface();
1231 const VkDevice vkDevice = m_context.getDevice();
1232 const VkQueue queue = m_context.getUniversalQueue();
1234 const VkBufferMemoryBarrier srcBufferBarrier =
1236 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1237 DE_NULL, // const void* pNext;
1238 VK_ACCESS_HOST_WRITE_BIT, // VkAccessFlags srcAccessMask;
1239 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1240 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1241 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1242 *m_source, // VkBuffer buffer;
1243 0u, // VkDeviceSize offset;
1244 m_params.src.buffer.size // VkDeviceSize size;
1247 const VkBufferMemoryBarrier dstBufferBarrier =
1249 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1250 DE_NULL, // const void* pNext;
1251 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1252 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
1253 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1254 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1255 *m_destination, // VkBuffer buffer;
1256 0u, // VkDeviceSize offset;
1257 m_params.dst.buffer.size // VkDeviceSize size;
1260 std::vector<VkBufferCopy> bufferCopies;
1261 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1262 bufferCopies.push_back(m_params.regions[i].bufferCopy);
1264 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1266 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1267 DE_NULL, // const void* pNext;
1268 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1269 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1272 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1273 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);
1274 vk.cmdCopyBuffer(*m_cmdBuffer, m_source.get(), m_destination.get(), (deUint32)m_params.regions.size(), &bufferCopies[0]);
1275 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);
1276 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1277 submitCommandsAndWait(vk, vkDevice, queue, *m_cmdBuffer);
1282 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
1283 invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_params.dst.buffer.size);
1284 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1286 return checkTestResult(resultLevel->getAccess());
1289 void CopyBufferToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1291 deMemcpy((deUint8*) dst.getDataPtr() + region.bufferCopy.dstOffset,
1292 (deUint8*) src.getDataPtr() + region.bufferCopy.srcOffset,
1293 (size_t)region.bufferCopy.size);
1296 class BufferToBufferTestCase : public vkt::TestCase
1299 BufferToBufferTestCase (tcu::TestContext& testCtx,
1300 const std::string& name,
1301 const std::string& description,
1302 const TestParams params)
1303 : vkt::TestCase (testCtx, name, description)
1307 virtual TestInstance* createInstance (Context& context) const
1309 return new CopyBufferToBuffer(context, m_params);
1312 TestParams m_params;
1315 // Copy from image to buffer.
1317 class CopyImageToBuffer : public CopiesAndBlittingTestInstance
1320 CopyImageToBuffer (Context& context,
1321 TestParams testParams);
1322 virtual tcu::TestStatus iterate (void);
1324 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1326 tcu::TextureFormat m_textureFormat;
1327 VkDeviceSize m_bufferSize;
1329 Move<VkImage> m_source;
1330 de::MovePtr<Allocation> m_sourceImageAlloc;
1331 Move<VkBuffer> m_destination;
1332 de::MovePtr<Allocation> m_destinationBufferAlloc;
1335 CopyImageToBuffer::CopyImageToBuffer (Context& context, TestParams testParams)
1336 : CopiesAndBlittingTestInstance(context, testParams)
1337 , m_textureFormat(mapVkFormat(testParams.src.image.format))
1338 , m_bufferSize(m_params.dst.buffer.size * tcu::getPixelSize(m_textureFormat))
1340 const InstanceInterface& vki = context.getInstanceInterface();
1341 const DeviceInterface& vk = context.getDeviceInterface();
1342 const VkPhysicalDevice vkPhysDevice = context.getPhysicalDevice();
1343 const VkDevice vkDevice = context.getDevice();
1344 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1345 Allocator& memAlloc = context.getDefaultAllocator();
1347 // Create source image
1349 const VkImageCreateInfo sourceImageParams =
1351 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1352 DE_NULL, // const void* pNext;
1353 0u, // VkImageCreateFlags flags;
1354 m_params.src.image.imageType, // VkImageType imageType;
1355 m_params.src.image.format, // VkFormat format;
1356 getExtent3D(m_params.src.image), // VkExtent3D extent;
1357 1u, // deUint32 mipLevels;
1358 getArraySize(m_params.src.image), // deUint32 arraySize;
1359 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1360 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1361 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1362 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1363 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1364 1u, // deUint32 queueFamilyCount;
1365 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1366 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1369 m_source = createImage(vk, vkDevice, &sourceImageParams);
1370 m_sourceImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_source, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
1371 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1374 // Create destination buffer
1376 const VkBufferCreateInfo destinationBufferParams =
1378 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1379 DE_NULL, // const void* pNext;
1380 0u, // VkBufferCreateFlags flags;
1381 m_bufferSize, // VkDeviceSize size;
1382 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
1383 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1384 1u, // deUint32 queueFamilyIndexCount;
1385 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1388 m_destination = createBuffer(vk, vkDevice, &destinationBufferParams);
1389 m_destinationBufferAlloc = allocateBuffer(vki, vk, vkPhysDevice, vkDevice, *m_destination, MemoryRequirement::HostVisible, memAlloc, m_params.allocationKind);
1390 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
1394 tcu::TestStatus CopyImageToBuffer::iterate (void)
1396 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1397 m_params.src.image.extent.width,
1398 m_params.src.image.extent.height,
1399 m_params.src.image.extent.depth));
1400 generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth);
1401 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1402 generateBuffer(m_destinationTextureLevel->getAccess(), (int)m_params.dst.buffer.size, 1, 1);
1404 generateExpectedResult();
1406 uploadImage(m_sourceTextureLevel->getAccess(), *m_source, m_params.src.image);
1407 uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
1409 const DeviceInterface& vk = m_context.getDeviceInterface();
1410 const VkDevice vkDevice = m_context.getDevice();
1411 const VkQueue queue = m_context.getUniversalQueue();
1413 // Barriers for copying image to buffer
1414 const VkImageMemoryBarrier imageBarrier =
1416 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1417 DE_NULL, // const void* pNext;
1418 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1419 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1420 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1421 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
1422 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1423 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1424 *m_source, // VkImage image;
1425 { // VkImageSubresourceRange subresourceRange;
1426 getAspectFlags(m_textureFormat), // VkImageAspectFlags aspectMask;
1427 0u, // deUint32 baseMipLevel;
1428 1u, // deUint32 mipLevels;
1429 0u, // deUint32 baseArraySlice;
1430 1u // deUint32 arraySize;
1434 const VkBufferMemoryBarrier bufferBarrier =
1436 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1437 DE_NULL, // const void* pNext;
1438 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1439 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
1440 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1441 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1442 *m_destination, // VkBuffer buffer;
1443 0u, // VkDeviceSize offset;
1444 m_bufferSize // VkDeviceSize size;
1447 // Copy from image to buffer
1448 std::vector<VkBufferImageCopy> bufferImageCopies;
1449 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1450 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1452 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1454 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1455 DE_NULL, // const void* pNext;
1456 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1457 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1460 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1461 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);
1462 vk.cmdCopyImageToBuffer(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), (deUint32)m_params.regions.size(), &bufferImageCopies[0]);
1463 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);
1464 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1466 submitCommandsAndWait (vk, vkDevice, queue, *m_cmdBuffer);
1469 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1470 invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_bufferSize);
1471 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1473 return checkTestResult(resultLevel->getAccess());
1476 class CopyImageToBufferTestCase : public vkt::TestCase
1479 CopyImageToBufferTestCase (tcu::TestContext& testCtx,
1480 const std::string& name,
1481 const std::string& description,
1482 const TestParams params)
1483 : vkt::TestCase (testCtx, name, description)
1487 virtual TestInstance* createInstance (Context& context) const
1489 return new CopyImageToBuffer(context, m_params);
1492 TestParams m_params;
1495 void CopyImageToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1497 deUint32 rowLength = region.bufferImageCopy.bufferRowLength;
1499 rowLength = region.bufferImageCopy.imageExtent.width;
1501 deUint32 imageHeight = region.bufferImageCopy.bufferImageHeight;
1503 imageHeight = region.bufferImageCopy.imageExtent.height;
1505 const int texelSize = src.getFormat().getPixelSize();
1506 const VkExtent3D extent = region.bufferImageCopy.imageExtent;
1507 const VkOffset3D srcOffset = region.bufferImageCopy.imageOffset;
1508 const int texelOffset = (int) region.bufferImageCopy.bufferOffset / texelSize;
1510 for (deUint32 z = 0; z < extent.depth; z++)
1512 for (deUint32 y = 0; y < extent.height; y++)
1514 int texelIndex = texelOffset + (z * imageHeight + y) * rowLength;
1515 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y + y, srcOffset.z + z,
1516 region.bufferImageCopy.imageExtent.width, 1, 1);
1517 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1518 tcu::copy(dstSubRegion, srcSubRegion);
1523 // Copy from buffer to image.
1525 class CopyBufferToImage : public CopiesAndBlittingTestInstance
1528 CopyBufferToImage (Context& context,
1529 TestParams testParams);
1530 virtual tcu::TestStatus iterate (void);
1532 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1534 tcu::TextureFormat m_textureFormat;
1535 VkDeviceSize m_bufferSize;
1537 Move<VkBuffer> m_source;
1538 de::MovePtr<Allocation> m_sourceBufferAlloc;
1539 Move<VkImage> m_destination;
1540 de::MovePtr<Allocation> m_destinationImageAlloc;
1543 CopyBufferToImage::CopyBufferToImage (Context& context, TestParams testParams)
1544 : CopiesAndBlittingTestInstance(context, testParams)
1545 , m_textureFormat(mapVkFormat(testParams.dst.image.format))
1546 , m_bufferSize(m_params.src.buffer.size * tcu::getPixelSize(m_textureFormat))
1548 const InstanceInterface& vki = context.getInstanceInterface();
1549 const DeviceInterface& vk = context.getDeviceInterface();
1550 const VkPhysicalDevice vkPhysDevice = context.getPhysicalDevice();
1551 const VkDevice vkDevice = context.getDevice();
1552 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1553 Allocator& memAlloc = context.getDefaultAllocator();
1555 // Create source buffer
1557 const VkBufferCreateInfo sourceBufferParams =
1559 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1560 DE_NULL, // const void* pNext;
1561 0u, // VkBufferCreateFlags flags;
1562 m_bufferSize, // VkDeviceSize size;
1563 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
1564 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1565 1u, // deUint32 queueFamilyIndexCount;
1566 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1569 m_source = createBuffer(vk, vkDevice, &sourceBufferParams);
1570 m_sourceBufferAlloc = allocateBuffer(vki, vk, vkPhysDevice, vkDevice, *m_source, MemoryRequirement::HostVisible, memAlloc, m_params.allocationKind);
1571 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
1574 // Create destination image
1576 const VkImageCreateInfo destinationImageParams =
1578 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1579 DE_NULL, // const void* pNext;
1580 0u, // VkImageCreateFlags flags;
1581 m_params.dst.image.imageType, // VkImageType imageType;
1582 m_params.dst.image.format, // VkFormat format;
1583 getExtent3D(m_params.dst.image), // VkExtent3D extent;
1584 1u, // deUint32 mipLevels;
1585 getArraySize(m_params.dst.image), // deUint32 arraySize;
1586 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1587 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1588 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1589 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1590 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1591 1u, // deUint32 queueFamilyCount;
1592 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1593 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1596 m_destination = createImage(vk, vkDevice, &destinationImageParams);
1597 m_destinationImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_destination, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
1598 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1602 tcu::TestStatus CopyBufferToImage::iterate (void)
1604 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.src.buffer.size, 1));
1605 generateBuffer(m_sourceTextureLevel->getAccess(), (int)m_params.src.buffer.size, 1, 1);
1606 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1607 m_params.dst.image.extent.width,
1608 m_params.dst.image.extent.height,
1609 m_params.dst.image.extent.depth));
1611 generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth);
1613 generateExpectedResult();
1615 uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
1616 uploadImage(m_destinationTextureLevel->getAccess(), *m_destination, m_params.dst.image);
1618 const DeviceInterface& vk = m_context.getDeviceInterface();
1619 const VkDevice vkDevice = m_context.getDevice();
1620 const VkQueue queue = m_context.getUniversalQueue();
1622 const VkImageMemoryBarrier imageBarrier =
1624 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1625 DE_NULL, // const void* pNext;
1626 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1627 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
1628 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1629 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
1630 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1631 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1632 *m_destination, // VkImage image;
1633 { // VkImageSubresourceRange subresourceRange;
1634 getAspectFlags(m_textureFormat), // VkImageAspectFlags aspectMask;
1635 0u, // deUint32 baseMipLevel;
1636 1u, // deUint32 mipLevels;
1637 0u, // deUint32 baseArraySlice;
1638 1u // deUint32 arraySize;
1642 // Copy from buffer to image
1643 std::vector<VkBufferImageCopy> bufferImageCopies;
1644 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1645 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1647 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1649 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1650 DE_NULL, // const void* pNext;
1651 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1652 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1655 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1656 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);
1657 vk.cmdCopyBufferToImage(*m_cmdBuffer, m_source.get(), m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), bufferImageCopies.data());
1658 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1660 submitCommandsAndWait (vk, vkDevice, queue, *m_cmdBuffer);
1662 de::MovePtr<tcu::TextureLevel> resultLevel = readImage(*m_destination, m_params.dst.image);
1664 return checkTestResult(resultLevel->getAccess());
1667 class CopyBufferToImageTestCase : public vkt::TestCase
1670 CopyBufferToImageTestCase (tcu::TestContext& testCtx,
1671 const std::string& name,
1672 const std::string& description,
1673 const TestParams params)
1674 : vkt::TestCase (testCtx, name, description)
1678 virtual ~CopyBufferToImageTestCase (void) {}
1680 virtual TestInstance* createInstance (Context& context) const
1682 return new CopyBufferToImage(context, m_params);
1685 TestParams m_params;
1688 void CopyBufferToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1690 deUint32 rowLength = region.bufferImageCopy.bufferRowLength;
1692 rowLength = region.bufferImageCopy.imageExtent.width;
1694 deUint32 imageHeight = region.bufferImageCopy.bufferImageHeight;
1696 imageHeight = region.bufferImageCopy.imageExtent.height;
1698 const int texelSize = dst.getFormat().getPixelSize();
1699 const VkExtent3D extent = region.bufferImageCopy.imageExtent;
1700 const VkOffset3D dstOffset = region.bufferImageCopy.imageOffset;
1701 const int texelOffset = (int) region.bufferImageCopy.bufferOffset / texelSize;
1703 for (deUint32 z = 0; z < extent.depth; z++)
1705 for (deUint32 y = 0; y < extent.height; y++)
1707 int texelIndex = texelOffset + (z * imageHeight + y) * rowLength;
1708 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1709 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, dstOffset.x, dstOffset.y + y, dstOffset.z + z,
1710 region.bufferImageCopy.imageExtent.width, 1, 1);
1711 tcu::copy(dstSubRegion, srcSubRegion);
1716 // Copy from image to image with scaling.
1718 class BlittingImages : public CopiesAndBlittingTestInstance
1721 BlittingImages (Context& context,
1723 virtual tcu::TestStatus iterate (void);
1725 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
1726 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1727 virtual void generateExpectedResult (void);
1729 bool checkLinearFilteredResult (const tcu::ConstPixelBufferAccess& result,
1730 const tcu::ConstPixelBufferAccess& clampedReference,
1731 const tcu::ConstPixelBufferAccess& unclampedReference,
1732 const tcu::TextureFormat& sourceFormat);
1733 bool checkNearestFilteredResult (const tcu::ConstPixelBufferAccess& result,
1734 const tcu::ConstPixelBufferAccess& source);
1736 Move<VkImage> m_source;
1737 de::MovePtr<Allocation> m_sourceImageAlloc;
1738 Move<VkImage> m_destination;
1739 de::MovePtr<Allocation> m_destinationImageAlloc;
1741 de::MovePtr<tcu::TextureLevel> m_unclampedExpectedTextureLevel;
1744 BlittingImages::BlittingImages (Context& context, TestParams params)
1745 : CopiesAndBlittingTestInstance(context, params)
1747 const InstanceInterface& vki = context.getInstanceInterface();
1748 const DeviceInterface& vk = context.getDeviceInterface();
1749 const VkPhysicalDevice vkPhysDevice = context.getPhysicalDevice();
1750 const VkDevice vkDevice = context.getDevice();
1751 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1752 Allocator& memAlloc = context.getDefaultAllocator();
1754 VkImageFormatProperties properties;
1755 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1756 m_params.src.image.format,
1758 VK_IMAGE_TILING_OPTIMAL,
1759 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
1761 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
1762 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1763 m_params.dst.image.format,
1765 VK_IMAGE_TILING_OPTIMAL,
1766 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1768 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
1770 TCU_THROW(NotSupportedError, "Format not supported");
1773 VkFormatProperties srcFormatProperties;
1774 context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.src.image.format, &srcFormatProperties);
1775 if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
1777 TCU_THROW(NotSupportedError, "Format feature blit source not supported");
1780 VkFormatProperties dstFormatProperties;
1781 context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.dst.image.format, &dstFormatProperties);
1782 if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
1784 TCU_THROW(NotSupportedError, "Format feature blit destination not supported");
1787 if (m_params.filter == VK_FILTER_LINEAR)
1789 if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1790 TCU_THROW(NotSupportedError, "Source format feature sampled image filter linear not supported");
1791 if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1792 TCU_THROW(NotSupportedError, "Destination format feature sampled image filter linear not supported");
1795 // Create source image
1797 const VkImageCreateInfo sourceImageParams =
1799 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1800 DE_NULL, // const void* pNext;
1801 0u, // VkImageCreateFlags flags;
1802 m_params.src.image.imageType, // VkImageType imageType;
1803 m_params.src.image.format, // VkFormat format;
1804 getExtent3D(m_params.src.image), // VkExtent3D extent;
1805 1u, // deUint32 mipLevels;
1806 getArraySize(m_params.src.image), // deUint32 arraySize;
1807 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1808 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1809 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1810 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1811 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1812 1u, // deUint32 queueFamilyCount;
1813 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1814 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1817 m_source = createImage(vk, vkDevice, &sourceImageParams);
1818 m_sourceImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_source, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
1819 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1822 // Create destination image
1824 const VkImageCreateInfo destinationImageParams =
1826 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1827 DE_NULL, // const void* pNext;
1828 0u, // VkImageCreateFlags flags;
1829 m_params.dst.image.imageType, // VkImageType imageType;
1830 m_params.dst.image.format, // VkFormat format;
1831 getExtent3D(m_params.dst.image), // VkExtent3D extent;
1832 1u, // deUint32 mipLevels;
1833 getArraySize(m_params.dst.image), // deUint32 arraySize;
1834 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1835 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1836 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1837 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1838 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1839 1u, // deUint32 queueFamilyCount;
1840 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1841 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1844 m_destination = createImage(vk, vkDevice, &destinationImageParams);
1845 m_destinationImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_destination, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
1846 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1850 tcu::TestStatus BlittingImages::iterate (void)
1852 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
1853 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
1854 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
1855 m_params.src.image.extent.width,
1856 m_params.src.image.extent.height,
1857 m_params.src.image.extent.depth));
1858 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);
1859 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
1860 (int)m_params.dst.image.extent.width,
1861 (int)m_params.dst.image.extent.height,
1862 (int)m_params.dst.image.extent.depth));
1863 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);
1864 generateExpectedResult();
1866 uploadImage(m_sourceTextureLevel->getAccess(), m_source.get(), m_params.src.image);
1867 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get(), m_params.dst.image);
1869 const DeviceInterface& vk = m_context.getDeviceInterface();
1870 const VkDevice vkDevice = m_context.getDevice();
1871 const VkQueue queue = m_context.getUniversalQueue();
1873 std::vector<VkImageBlit> regions;
1874 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1875 regions.push_back(m_params.regions[i].imageBlit);
1877 // Barriers for copying image to buffer
1878 const VkImageMemoryBarrier srcImageBarrier =
1880 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1881 DE_NULL, // const void* pNext;
1882 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1883 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1884 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1885 m_params.src.image.operationLayout, // VkImageLayout newLayout;
1886 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1887 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1888 m_source.get(), // VkImage image;
1889 { // VkImageSubresourceRange subresourceRange;
1890 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
1891 0u, // deUint32 baseMipLevel;
1892 1u, // deUint32 mipLevels;
1893 0u, // deUint32 baseArraySlice;
1894 1u // deUint32 arraySize;
1898 const VkImageMemoryBarrier dstImageBarrier =
1900 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1901 DE_NULL, // const void* pNext;
1902 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1903 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
1904 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1905 m_params.dst.image.operationLayout, // VkImageLayout newLayout;
1906 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1907 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1908 m_destination.get(), // VkImage image;
1909 { // VkImageSubresourceRange subresourceRange;
1910 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
1911 0u, // deUint32 baseMipLevel;
1912 1u, // deUint32 mipLevels;
1913 0u, // deUint32 baseArraySlice;
1914 1u // deUint32 arraySize;
1918 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1920 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1921 DE_NULL, // const void* pNext;
1922 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1923 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1926 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1927 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);
1928 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, &dstImageBarrier);
1929 vk.cmdBlitImage(*m_cmdBuffer, m_source.get(), m_params.src.image.operationLayout, m_destination.get(), m_params.dst.image.operationLayout, (deUint32)m_params.regions.size(), ®ions[0], m_params.filter);
1930 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1931 submitCommandsAndWait(vk, vkDevice, queue, *m_cmdBuffer);
1933 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(*m_destination, m_params.dst.image);
1935 return checkTestResult(resultTextureLevel->getAccess());
1938 static float calculateFloatConversionError (int srcBits)
1942 const int clampedBits = de::clamp<int>(srcBits, 0, 32);
1943 const float srcMaxValue = de::max((float)(1ULL<<clampedBits) - 1.0f, 1.0f);
1944 const float error = 1.0f / srcMaxValue;
1946 return de::clamp<float>(error, 0.0f, 1.0f);
1952 tcu::Vec4 getFormatThreshold (const tcu::TextureFormat& format)
1954 tcu::Vec4 threshold(0.01f);
1956 switch (format.type)
1958 case tcu::TextureFormat::HALF_FLOAT:
1959 threshold = tcu::Vec4(0.005f);
1962 case tcu::TextureFormat::FLOAT:
1963 case tcu::TextureFormat::FLOAT64:
1964 threshold = tcu::Vec4(0.001f);
1967 case tcu::TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
1968 threshold = tcu::Vec4(0.02f, 0.02f, 0.0625f, 1.0f);
1971 case tcu::TextureFormat::UNSIGNED_INT_999_E5_REV:
1972 threshold = tcu::Vec4(0.05f, 0.05f, 0.05f, 1.0f);
1976 const tcu::IVec4 bits = tcu::getTextureFormatMantissaBitDepth(format);
1977 threshold = tcu::Vec4(calculateFloatConversionError(bits.x()),
1978 calculateFloatConversionError(bits.y()),
1979 calculateFloatConversionError(bits.z()),
1980 calculateFloatConversionError(bits.w()));
1983 // Return value matching the channel order specified by the format
1984 if (format.order == tcu::TextureFormat::BGR || format.order == tcu::TextureFormat::BGRA)
1985 return threshold.swizzle(2, 1, 0, 3);
1990 bool BlittingImages::checkLinearFilteredResult (const tcu::ConstPixelBufferAccess& result,
1991 const tcu::ConstPixelBufferAccess& clampedExpected,
1992 const tcu::ConstPixelBufferAccess& unclampedExpected,
1993 const tcu::TextureFormat& srcFormat)
1995 tcu::TestLog& log (m_context.getTestContext().getLog());
1996 const tcu::TextureFormat dstFormat = result.getFormat();
1999 log << tcu::TestLog::Section("ClampedSourceImage", "Region with clamped edges on source image.");
2001 if (isFloatFormat(dstFormat))
2003 const bool srcIsSRGB = tcu::isSRGB(srcFormat);
2004 const tcu::Vec4 srcMaxDiff = getFormatThreshold(srcFormat) * tcu::Vec4(srcIsSRGB ? 2.0f : 1.0f);
2005 const tcu::Vec4 dstMaxDiff = getFormatThreshold(dstFormat);
2006 const tcu::Vec4 threshold = tcu::max(srcMaxDiff, dstMaxDiff);
2008 isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
2009 log << tcu::TestLog::EndSection;
2013 log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
2014 isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
2015 log << tcu::TestLog::EndSection;
2020 tcu::UVec4 threshold;
2021 // Calculate threshold depending on channel width of destination format.
2022 const tcu::IVec4 bitDepth = tcu::getTextureFormatBitDepth(dstFormat);
2023 for (deUint32 i = 0; i < 4; ++i)
2024 threshold[i] = de::max( (0x1 << bitDepth[i]) / 256, 1);
2026 isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
2027 log << tcu::TestLog::EndSection;
2031 log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
2032 isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
2033 log << tcu::TestLog::EndSection;
2040 //! Utility to encapsulate coordinate computation and loops.
2041 struct CompareEachPixelInEachRegion
2043 virtual ~CompareEachPixelInEachRegion (void) {}
2044 virtual bool compare (const void* pUserData, const int x, const int y, const tcu::Vec2& srcNormCoord) const = 0;
2046 bool forEach (const void* pUserData,
2047 const std::vector<CopyRegion>& regions,
2048 const int sourceWidth,
2049 const int sourceHeight,
2050 const tcu::PixelBufferAccess& errorMask) const
2052 bool compareOk = true;
2054 for (std::vector<CopyRegion>::const_iterator regionIter = regions.begin(); regionIter != regions.end(); ++regionIter)
2056 const VkImageBlit& blit = regionIter->imageBlit;
2058 const int dx = deSign32(blit.dstOffsets[1].x - blit.dstOffsets[0].x);
2059 const int dy = deSign32(blit.dstOffsets[1].y - blit.dstOffsets[0].y);
2060 const float xScale = static_cast<float>(blit.srcOffsets[1].x - blit.srcOffsets[0].x) / static_cast<float>(blit.dstOffsets[1].x - blit.dstOffsets[0].x);
2061 const float yScale = static_cast<float>(blit.srcOffsets[1].y - blit.srcOffsets[0].y) / static_cast<float>(blit.dstOffsets[1].y - blit.dstOffsets[0].y);
2062 const float srcInvW = 1.0f / static_cast<float>(sourceWidth);
2063 const float srcInvH = 1.0f / static_cast<float>(sourceHeight);
2065 for (int y = blit.dstOffsets[0].y; y < blit.dstOffsets[1].y; y += dy)
2066 for (int x = blit.dstOffsets[0].x; x < blit.dstOffsets[1].x; x += dx)
2068 const tcu::Vec2 srcNormCoord
2070 (xScale * (static_cast<float>(x - blit.dstOffsets[0].x) + 0.5f) + static_cast<float>(blit.srcOffsets[0].x)) * srcInvW,
2071 (yScale * (static_cast<float>(y - blit.dstOffsets[0].y) + 0.5f) + static_cast<float>(blit.srcOffsets[0].y)) * srcInvH
2074 if (!compare(pUserData, x, y, srcNormCoord))
2076 errorMask.setPixel(tcu::Vec4(1.0f, 0.0f, 0.0f, 1.0f), x, y);
2085 tcu::Vec4 getFloatOrFixedPointFormatThreshold (const tcu::TextureFormat& format)
2087 const tcu::TextureChannelClass channelClass = tcu::getTextureChannelClass(format.type);
2088 const tcu::IVec4 bitDepth = tcu::getTextureFormatBitDepth(format);
2090 if (channelClass == tcu::TEXTURECHANNELCLASS_FLOATING_POINT)
2092 return getFormatThreshold(format);
2094 else if (channelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_FIXED_POINT ||
2095 channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT)
2097 const bool isSigned = (channelClass == tcu::TEXTURECHANNELCLASS_SIGNED_FIXED_POINT);
2098 const float range = isSigned ? 1.0f - (-1.0f)
2102 for (int i = 0; i < 4; ++i)
2104 if (bitDepth[i] == 0)
2107 v[i] = range / static_cast<float>((1 << bitDepth[i]) - 1);
2118 bool floatNearestBlitCompare (const tcu::ConstPixelBufferAccess& source,
2119 const tcu::ConstPixelBufferAccess& result,
2120 const tcu::PixelBufferAccess& errorMask,
2121 const std::vector<CopyRegion>& regions)
2123 const tcu::Sampler sampler (tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::NEAREST, tcu::Sampler::NEAREST);
2124 tcu::LookupPrecision precision;
2127 const tcu::IVec4 dstBitDepth = tcu::getTextureFormatBitDepth(result.getFormat());
2128 const tcu::Vec4 srcMaxDiff = getFloatOrFixedPointFormatThreshold(source.getFormat());
2129 const tcu::Vec4 dstMaxDiff = getFloatOrFixedPointFormatThreshold(result.getFormat());
2131 precision.colorMask = tcu::notEqual(dstBitDepth, tcu::IVec4(0));
2132 precision.colorThreshold = tcu::max(srcMaxDiff, dstMaxDiff);
2135 const struct Capture
2137 const tcu::ConstPixelBufferAccess& source;
2138 const tcu::ConstPixelBufferAccess& result;
2139 const tcu::Sampler& sampler;
2140 const tcu::LookupPrecision& precision;
2144 source, result, sampler, precision, tcu::isSRGB(result.getFormat())
2147 const struct Loop : CompareEachPixelInEachRegion
2151 bool compare (const void* pUserData, const int x, const int y, const tcu::Vec2& srcNormCoord) const
2153 const Capture& c = *static_cast<const Capture*>(pUserData);
2154 const tcu::TexLookupScaleMode lookupScaleDontCare = tcu::TEX_LOOKUP_SCALE_MINIFY;
2155 tcu::Vec4 dstColor = c.result.getPixel(x, y);
2157 // TexLookupVerifier performs a conversion to linear space, so we have to as well
2159 dstColor = tcu::sRGBToLinear(dstColor);
2161 return tcu::isLevel2DLookupResultValid(c.source, c.sampler, lookupScaleDontCare, c.precision, srcNormCoord, 0, dstColor);
2165 return loop.forEach(&capture, regions, source.getWidth(), source.getHeight(), errorMask);
2168 bool intNearestBlitCompare (const tcu::ConstPixelBufferAccess& source,
2169 const tcu::ConstPixelBufferAccess& result,
2170 const tcu::PixelBufferAccess& errorMask,
2171 const std::vector<CopyRegion>& regions)
2173 const tcu::Sampler sampler (tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::NEAREST, tcu::Sampler::NEAREST);
2174 tcu::IntLookupPrecision precision;
2177 const tcu::IVec4 srcBitDepth = tcu::getTextureFormatBitDepth(source.getFormat());
2178 const tcu::IVec4 dstBitDepth = tcu::getTextureFormatBitDepth(result.getFormat());
2180 for (deUint32 i = 0; i < 4; ++i) {
2181 precision.colorThreshold[i] = de::max(de::max(srcBitDepth[i] / 8, dstBitDepth[i] / 8), 1);
2182 precision.colorMask[i] = dstBitDepth[i] != 0;
2186 // Prepare a source image with a matching (converted) pixel format. Ideally, we would've used a wrapper that
2187 // does the conversion on the fly without wasting memory, but this approach is more straightforward.
2188 tcu::TextureLevel convertedSourceTexture (result.getFormat(), source.getWidth(), source.getHeight());
2189 const tcu::PixelBufferAccess convertedSource = convertedSourceTexture.getAccess();
2191 for (int y = 0; y < source.getHeight(); ++y)
2192 for (int x = 0; x < source.getWidth(); ++x)
2193 convertedSource.setPixel(source.getPixelInt(x, y), x, y); // will be clamped to max. representable value
2195 const struct Capture
2197 const tcu::ConstPixelBufferAccess& source;
2198 const tcu::ConstPixelBufferAccess& result;
2199 const tcu::Sampler& sampler;
2200 const tcu::IntLookupPrecision& precision;
2203 convertedSource, result, sampler, precision
2206 const struct Loop : CompareEachPixelInEachRegion
2210 bool compare (const void* pUserData, const int x, const int y, const tcu::Vec2& srcNormCoord) const
2212 const Capture& c = *static_cast<const Capture*>(pUserData);
2213 const tcu::TexLookupScaleMode lookupScaleDontCare = tcu::TEX_LOOKUP_SCALE_MINIFY;
2214 const tcu::IVec4 dstColor = c.result.getPixelInt(x, y);
2216 return tcu::isLevel2DLookupResultValid(c.source, c.sampler, lookupScaleDontCare, c.precision, srcNormCoord, 0, dstColor);
2220 return loop.forEach(&capture, regions, source.getWidth(), source.getHeight(), errorMask);
2223 bool BlittingImages::checkNearestFilteredResult (const tcu::ConstPixelBufferAccess& result,
2224 const tcu::ConstPixelBufferAccess& source)
2226 tcu::TestLog& log (m_context.getTestContext().getLog());
2227 const tcu::TextureFormat dstFormat = result.getFormat();
2228 const tcu::TextureChannelClass dstChannelClass = tcu::getTextureChannelClass(dstFormat.type);
2230 tcu::TextureLevel errorMaskStorage (tcu::TextureFormat(tcu::TextureFormat::RGB, tcu::TextureFormat::UNORM_INT8), result.getWidth(), result.getHeight());
2231 tcu::PixelBufferAccess errorMask = errorMaskStorage.getAccess();
2232 tcu::Vec4 pixelBias (0.0f, 0.0f, 0.0f, 0.0f);
2233 tcu::Vec4 pixelScale (1.0f, 1.0f, 1.0f, 1.0f);
2236 tcu::clear(errorMask, tcu::Vec4(0.0f, 1.0f, 0.0f, 1.0));
2238 if (dstChannelClass == tcu::TEXTURECHANNELCLASS_SIGNED_INTEGER ||
2239 dstChannelClass == tcu::TEXTURECHANNELCLASS_UNSIGNED_INTEGER)
2241 ok = intNearestBlitCompare(source, result, errorMask, m_params.regions);
2244 ok = floatNearestBlitCompare(source, result, errorMask, m_params.regions);
2246 if (result.getFormat() != tcu::TextureFormat(tcu::TextureFormat::RGBA, tcu::TextureFormat::UNORM_INT8))
2247 tcu::computePixelScaleBias(result, pixelScale, pixelBias);
2251 log << tcu::TestLog::ImageSet("Compare", "Result comparsion")
2252 << tcu::TestLog::Image("Result", "Result", result, pixelScale, pixelBias)
2253 << tcu::TestLog::Image("ErrorMask", "Error mask", errorMask)
2254 << tcu::TestLog::EndImageSet;
2258 log << tcu::TestLog::ImageSet("Compare", "Result comparsion")
2259 << tcu::TestLog::Image("Result", "Result", result, pixelScale, pixelBias)
2260 << tcu::TestLog::EndImageSet;
2266 tcu::TestStatus BlittingImages::checkTestResult (tcu::ConstPixelBufferAccess result)
2268 DE_ASSERT(m_params.filter == VK_FILTER_NEAREST || m_params.filter == VK_FILTER_LINEAR);
2269 const std::string failMessage("Result image is incorrect");
2271 if (m_params.filter == VK_FILTER_LINEAR)
2273 if (tcu::isCombinedDepthStencilType(result.getFormat().type))
2275 if (tcu::hasDepthComponent(result.getFormat().order))
2277 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_DEPTH;
2278 const tcu::ConstPixelBufferAccess depthResult = tcu::getEffectiveDepthStencilAccess(result, mode);
2279 const tcu::ConstPixelBufferAccess clampedExpected = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
2280 const tcu::ConstPixelBufferAccess unclampedExpected = tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode);
2281 const tcu::TextureFormat sourceFormat = tcu::getEffectiveDepthStencilTextureFormat(mapVkFormat(m_params.src.image.format), mode);
2283 if (!checkLinearFilteredResult(depthResult, clampedExpected, unclampedExpected, sourceFormat))
2284 return tcu::TestStatus::fail(failMessage);
2287 if (tcu::hasStencilComponent(result.getFormat().order))
2289 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_STENCIL;
2290 const tcu::ConstPixelBufferAccess stencilResult = tcu::getEffectiveDepthStencilAccess(result, mode);
2291 const tcu::ConstPixelBufferAccess clampedExpected = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
2292 const tcu::ConstPixelBufferAccess unclampedExpected = tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode);
2293 const tcu::TextureFormat sourceFormat = tcu::getEffectiveDepthStencilTextureFormat(mapVkFormat(m_params.src.image.format), mode);
2295 if (!checkLinearFilteredResult(stencilResult, clampedExpected, unclampedExpected, sourceFormat))
2296 return tcu::TestStatus::fail(failMessage);
2301 const tcu::TextureFormat sourceFormat = mapVkFormat(m_params.src.image.format);
2303 if (!checkLinearFilteredResult(result, m_expectedTextureLevel->getAccess(), m_unclampedExpectedTextureLevel->getAccess(), sourceFormat))
2304 return tcu::TestStatus::fail(failMessage);
2307 else // NEAREST filtering
2309 if (tcu::isCombinedDepthStencilType(result.getFormat().type))
2311 if (tcu::hasDepthComponent(result.getFormat().order))
2313 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_DEPTH;
2314 const tcu::ConstPixelBufferAccess depthResult = tcu::getEffectiveDepthStencilAccess(result, mode);
2315 const tcu::ConstPixelBufferAccess depthSource = tcu::getEffectiveDepthStencilAccess(m_sourceTextureLevel->getAccess(), mode);
2317 if (!checkNearestFilteredResult(depthResult, depthSource))
2318 return tcu::TestStatus::fail(failMessage);
2321 if (tcu::hasStencilComponent(result.getFormat().order))
2323 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_STENCIL;
2324 const tcu::ConstPixelBufferAccess stencilResult = tcu::getEffectiveDepthStencilAccess(result, mode);
2325 const tcu::ConstPixelBufferAccess stencilSource = tcu::getEffectiveDepthStencilAccess(m_sourceTextureLevel->getAccess(), mode);
2327 if (!checkNearestFilteredResult(stencilResult, stencilSource))
2328 return tcu::TestStatus::fail(failMessage);
2333 if (!checkNearestFilteredResult(result, m_sourceTextureLevel->getAccess()))
2334 return tcu::TestStatus::fail(failMessage);
2338 return tcu::TestStatus::pass("Pass");
2341 tcu::Vec4 linearToSRGBIfNeeded (const tcu::TextureFormat& format, const tcu::Vec4& color)
2343 return isSRGB(format) ? linearToSRGB(color) : color;
2346 void scaleFromWholeSrcBuffer (const tcu::PixelBufferAccess& dst, const tcu::ConstPixelBufferAccess& src, const VkOffset3D regionOffset, const VkOffset3D regionExtent, tcu::Sampler::FilterMode filter)
2348 DE_ASSERT(filter == tcu::Sampler::LINEAR);
2349 DE_ASSERT(dst.getDepth() == 1 && src.getDepth() == 1);
2351 tcu::Sampler sampler(tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE,
2352 filter, filter, 0.0f, false);
2354 float sX = (float)regionExtent.x / (float)dst.getWidth();
2355 float sY = (float)regionExtent.y / (float)dst.getHeight();
2357 for (int y = 0; y < dst.getHeight(); y++)
2358 for (int x = 0; x < dst.getWidth(); x++)
2359 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);
2362 void blit (const tcu::PixelBufferAccess& dst, const tcu::ConstPixelBufferAccess& src, const tcu::Sampler::FilterMode filter, const MirrorMode mirrorMode)
2364 DE_ASSERT(filter == tcu::Sampler::NEAREST || filter == tcu::Sampler::LINEAR);
2366 tcu::Sampler sampler(tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE,
2367 filter, filter, 0.0f, false);
2369 const float sX = (float)src.getWidth() / (float)dst.getWidth();
2370 const float sY = (float)src.getHeight() / (float)dst.getHeight();
2371 const float sZ = (float)src.getDepth() / (float)dst.getDepth();
2373 tcu::Mat2 rotMatrix;
2374 rotMatrix(0,0) = (mirrorMode & MIRROR_MODE_X) ? -1.0f : 1.0f;
2375 rotMatrix(0,1) = 0.0f;
2376 rotMatrix(1,0) = 0.0f;
2377 rotMatrix(1,1) = (mirrorMode & MIRROR_MODE_Y) ? -1.0f : 1.0f;
2379 const int xOffset = (mirrorMode & MIRROR_MODE_X) ? dst.getWidth() - 1 : 0;
2380 const int yOffset = (mirrorMode & MIRROR_MODE_Y) ? dst.getHeight() - 1 : 0;
2382 if (dst.getDepth() == 1 && src.getDepth() == 1)
2384 for (int y = 0; y < dst.getHeight(); ++y)
2385 for (int x = 0; x < dst.getWidth(); ++x)
2387 const tcu::Vec2 xy = rotMatrix * tcu::Vec2((float)x,(float)y);
2388 dst.setPixel(linearToSRGBIfNeeded(dst.getFormat(), src.sample2D(sampler, filter, ((float)x+0.5f)*sX, ((float)y+0.5f)*sY, 0)), (int)round(xy[0]) + xOffset, (int)round(xy[1]) + yOffset);
2393 for (int z = 0; z < dst.getDepth(); ++z)
2394 for (int y = 0; y < dst.getHeight(); ++y)
2395 for (int x = 0; x < dst.getWidth(); ++x)
2397 const tcu::Vec2 xy = rotMatrix * tcu::Vec2((float)x,(float)y);
2398 dst.setPixel(linearToSRGBIfNeeded(dst.getFormat(), src.sample3D(sampler, filter, ((float)x+0.5f)*sX, ((float)y+0.5f)*sY, ((float)z+0.5f)*sZ)), (int)round(xy[0]) + xOffset, (int)round(xy[1]) + yOffset, z);
2403 void flipCoordinates (CopyRegion& region, const MirrorMode mirrorMode)
2405 const VkOffset3D dstOffset0 = region.imageBlit.dstOffsets[0];
2406 const VkOffset3D dstOffset1 = region.imageBlit.dstOffsets[1];
2407 const VkOffset3D srcOffset0 = region.imageBlit.srcOffsets[0];
2408 const VkOffset3D srcOffset1 = region.imageBlit.srcOffsets[1];
2410 if (mirrorMode > MIRROR_MODE_NONE && mirrorMode < MIRROR_MODE_LAST)
2413 region.imageBlit.srcOffsets[0].x = std::min(srcOffset0.x, srcOffset1.x);
2414 region.imageBlit.srcOffsets[0].y = std::min(srcOffset0.y, srcOffset1.y);
2416 region.imageBlit.srcOffsets[1].x = std::max(srcOffset0.x, srcOffset1.x);
2417 region.imageBlit.srcOffsets[1].y = std::max(srcOffset0.y, srcOffset1.y);
2420 region.imageBlit.dstOffsets[0].x = std::min(dstOffset0.x, dstOffset1.x);
2421 region.imageBlit.dstOffsets[0].y = std::min(dstOffset0.y, dstOffset1.y);
2423 region.imageBlit.dstOffsets[1].x = std::max(dstOffset0.x, dstOffset1.x);
2424 region.imageBlit.dstOffsets[1].y = std::max(dstOffset0.y, dstOffset1.y);
2428 MirrorMode getMirrorMode(const VkOffset3D x1, const VkOffset3D x2)
2430 if (x1.x >= x2.x && x1.y >= x2.y)
2432 return MIRROR_MODE_XY;
2434 else if (x1.x <= x2.x && x1.y <= x2.y)
2436 return MIRROR_MODE_NONE;
2438 else if (x1.x <= x2.x && x1.y >= x2.y)
2440 return MIRROR_MODE_Y;
2442 else if (x1.x >= x2.x && x1.y <= x2.y)
2444 return MIRROR_MODE_X;
2446 return MIRROR_MODE_LAST;
2449 MirrorMode getMirrorMode(const VkOffset3D s1, const VkOffset3D s2, const VkOffset3D d1, const VkOffset3D d2)
2451 const MirrorMode source = getMirrorMode(s1, s2);
2452 const MirrorMode destination = getMirrorMode(d1, d2);
2454 if (source == destination)
2456 return MIRROR_MODE_NONE;
2458 else if ((source == MIRROR_MODE_XY && destination == MIRROR_MODE_X) || (destination == MIRROR_MODE_XY && source == MIRROR_MODE_X) ||
2459 (source == MIRROR_MODE_Y && destination == MIRROR_MODE_NONE) || (destination == MIRROR_MODE_Y && source == MIRROR_MODE_NONE))
2461 return MIRROR_MODE_Y;
2463 else if ((source == MIRROR_MODE_XY && destination == MIRROR_MODE_Y) || (destination == MIRROR_MODE_XY && source == MIRROR_MODE_Y) ||
2464 (source == MIRROR_MODE_X && destination == MIRROR_MODE_NONE) || (destination == MIRROR_MODE_X && source == MIRROR_MODE_NONE))
2466 return MIRROR_MODE_X;
2468 else if ((source == MIRROR_MODE_XY && destination == MIRROR_MODE_NONE) || (destination == MIRROR_MODE_XY && source == MIRROR_MODE_NONE))
2470 return MIRROR_MODE_XY;
2472 return MIRROR_MODE_LAST;
2475 void BlittingImages::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
2477 const MirrorMode mirrorMode = getMirrorMode(region.imageBlit.srcOffsets[0],
2478 region.imageBlit.srcOffsets[1],
2479 region.imageBlit.dstOffsets[0],
2480 region.imageBlit.dstOffsets[1]);
2482 flipCoordinates(region, mirrorMode);
2484 const VkOffset3D srcOffset = region.imageBlit.srcOffsets[0];
2485 const VkOffset3D srcExtent =
2487 region.imageBlit.srcOffsets[1].x - srcOffset.x,
2488 region.imageBlit.srcOffsets[1].y - srcOffset.y,
2489 region.imageBlit.srcOffsets[1].z - srcOffset.z
2491 const VkOffset3D dstOffset = region.imageBlit.dstOffsets[0];
2492 const VkOffset3D dstExtent =
2494 region.imageBlit.dstOffsets[1].x - dstOffset.x,
2495 region.imageBlit.dstOffsets[1].y - dstOffset.y,
2496 region.imageBlit.dstOffsets[1].z - dstOffset.z
2498 const tcu::Sampler::FilterMode filter = (m_params.filter == VK_FILTER_LINEAR) ? tcu::Sampler::LINEAR : tcu::Sampler::NEAREST;
2500 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
2502 DE_ASSERT(src.getFormat() == dst.getFormat());
2504 if (tcu::hasDepthComponent(src.getFormat().order))
2506 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_DEPTH);
2507 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
2508 tcu::scale(dstSubRegion, srcSubRegion, filter);
2510 if (filter == tcu::Sampler::LINEAR)
2512 const tcu::ConstPixelBufferAccess depthSrc = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_DEPTH);
2513 const tcu::PixelBufferAccess unclampedSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
2514 scaleFromWholeSrcBuffer(unclampedSubRegion, depthSrc, srcOffset, srcExtent, filter);
2519 if (tcu::hasStencilComponent(src.getFormat().order))
2521 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_STENCIL);
2522 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
2523 blit(dstSubRegion, srcSubRegion, filter, mirrorMode);
2525 if (filter == tcu::Sampler::LINEAR)
2527 const tcu::ConstPixelBufferAccess stencilSrc = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_STENCIL);
2528 const tcu::PixelBufferAccess unclampedSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
2529 scaleFromWholeSrcBuffer(unclampedSubRegion, stencilSrc, srcOffset, srcExtent, filter);
2535 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y);
2536 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
2537 blit(dstSubRegion, srcSubRegion, filter, mirrorMode);
2539 if (filter == tcu::Sampler::LINEAR)
2541 const tcu::PixelBufferAccess unclampedSubRegion = tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
2542 scaleFromWholeSrcBuffer(unclampedSubRegion, src, srcOffset, srcExtent, filter);
2547 void BlittingImages::generateExpectedResult (void)
2549 const tcu::ConstPixelBufferAccess src = m_sourceTextureLevel->getAccess();
2550 const tcu::ConstPixelBufferAccess dst = m_destinationTextureLevel->getAccess();
2552 m_expectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
2553 tcu::copy(m_expectedTextureLevel->getAccess(), dst);
2555 if (m_params.filter == VK_FILTER_LINEAR)
2557 m_unclampedExpectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
2558 tcu::copy(m_unclampedExpectedTextureLevel->getAccess(), dst);
2561 for (deUint32 i = 0; i < m_params.regions.size(); i++)
2563 CopyRegion region = m_params.regions[i];
2564 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), region);
2568 class BlittingTestCase : public vkt::TestCase
2571 BlittingTestCase (tcu::TestContext& testCtx,
2572 const std::string& name,
2573 const std::string& description,
2574 const TestParams params)
2575 : vkt::TestCase (testCtx, name, description)
2579 virtual TestInstance* createInstance (Context& context) const
2581 return new BlittingImages(context, m_params);
2584 TestParams m_params;
2587 // Resolve image to image.
2589 enum ResolveImageToImageOptions{NO_OPTIONAL_OPERATION, COPY_MS_IMAGE_TO_MS_IMAGE, COPY_MS_IMAGE_TO_ARRAY_MS_IMAGE};
2590 class ResolveImageToImage : public CopiesAndBlittingTestInstance
2593 ResolveImageToImage (Context& context,
2595 const ResolveImageToImageOptions options);
2596 virtual tcu::TestStatus iterate (void);
2598 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
2599 void copyMSImageToMSImage (void);
2601 Move<VkImage> m_multisampledImage;
2602 de::MovePtr<Allocation> m_multisampledImageAlloc;
2604 Move<VkImage> m_destination;
2605 de::MovePtr<Allocation> m_destinationImageAlloc;
2607 Move<VkImage> m_multisampledCopyImage;
2608 de::MovePtr<Allocation> m_multisampledCopyImageAlloc;
2610 const ResolveImageToImageOptions m_options;
2612 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src,
2613 tcu::PixelBufferAccess dst,
2617 ResolveImageToImage::ResolveImageToImage (Context& context, TestParams params, const ResolveImageToImageOptions options)
2618 : CopiesAndBlittingTestInstance (context, params)
2619 , m_options (options)
2621 const VkSampleCountFlagBits rasterizationSamples = m_params.samples;
2623 if (!(context.getDeviceProperties().limits.framebufferColorSampleCounts & rasterizationSamples))
2624 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
2626 const InstanceInterface& vki = context.getInstanceInterface();
2627 const DeviceInterface& vk = context.getDeviceInterface();
2628 const VkPhysicalDevice vkPhysDevice = context.getPhysicalDevice();
2629 const VkDevice vkDevice = context.getDevice();
2630 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2631 Allocator& memAlloc = m_context.getDefaultAllocator();
2633 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
2634 Move<VkRenderPass> renderPass;
2636 Move<VkShaderModule> vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("vert"), 0);
2637 Move<VkShaderModule> fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("frag"), 0);
2638 std::vector<tcu::Vec4> vertices;
2640 Move<VkBuffer> vertexBuffer;
2641 de::MovePtr<Allocation> vertexBufferAlloc;
2643 Move<VkPipelineLayout> pipelineLayout;
2644 Move<VkPipeline> graphicsPipeline;
2646 VkImageFormatProperties properties;
2647 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2648 m_params.src.image.format,
2649 m_params.src.image.imageType,
2650 VK_IMAGE_TILING_OPTIMAL,
2651 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
2652 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
2653 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2654 m_params.dst.image.format,
2655 m_params.dst.image.imageType,
2656 VK_IMAGE_TILING_OPTIMAL,
2657 VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
2658 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
2660 TCU_THROW(NotSupportedError, "Format not supported");
2663 // Create color image.
2665 VkImageCreateInfo colorImageParams =
2667 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
2668 DE_NULL, // const void* pNext;
2669 0u, // VkImageCreateFlags flags;
2670 m_params.src.image.imageType, // VkImageType imageType;
2671 m_params.src.image.format, // VkFormat format;
2672 getExtent3D(m_params.src.image), // VkExtent3D extent;
2673 1u, // deUint32 mipLevels;
2674 getArraySize(m_params.src.image), // deUint32 arrayLayers;
2675 rasterizationSamples, // VkSampleCountFlagBits samples;
2676 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2677 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
2678 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2679 1u, // deUint32 queueFamilyIndexCount;
2680 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
2681 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
2684 m_multisampledImage = createImage(vk, vkDevice, &colorImageParams);
2686 // Allocate and bind color image memory.
2687 m_multisampledImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_multisampledImage, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
2688 VK_CHECK(vk.bindImageMemory(vkDevice, *m_multisampledImage, m_multisampledImageAlloc->getMemory(), m_multisampledImageAlloc->getOffset()));
2692 case COPY_MS_IMAGE_TO_MS_IMAGE:
2694 colorImageParams.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2695 m_multisampledCopyImage = createImage(vk, vkDevice, &colorImageParams);
2696 // Allocate and bind color image memory.
2697 m_multisampledCopyImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_multisampledCopyImage, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
2698 VK_CHECK(vk.bindImageMemory(vkDevice, *m_multisampledCopyImage, m_multisampledCopyImageAlloc->getMemory(), m_multisampledCopyImageAlloc->getOffset()));
2702 case COPY_MS_IMAGE_TO_ARRAY_MS_IMAGE:
2704 colorImageParams.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
2705 colorImageParams.arrayLayers = getArraySize(m_params.dst.image);
2706 m_multisampledCopyImage = createImage(vk, vkDevice, &colorImageParams);
2707 // Allocate and bind color image memory.
2708 m_multisampledCopyImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_multisampledCopyImage, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
2709 VK_CHECK(vk.bindImageMemory(vkDevice, *m_multisampledCopyImage, m_multisampledCopyImageAlloc->getMemory(), m_multisampledCopyImageAlloc->getOffset()));
2718 // Create destination image.
2720 const VkImageCreateInfo destinationImageParams =
2722 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
2723 DE_NULL, // const void* pNext;
2724 0u, // VkImageCreateFlags flags;
2725 m_params.dst.image.imageType, // VkImageType imageType;
2726 m_params.dst.image.format, // VkFormat format;
2727 getExtent3D(m_params.dst.image), // VkExtent3D extent;
2728 1u, // deUint32 mipLevels;
2729 getArraySize(m_params.dst.image), // deUint32 arraySize;
2730 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
2731 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2732 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
2733 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
2734 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2735 1u, // deUint32 queueFamilyCount;
2736 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
2737 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
2740 m_destination = createImage(vk, vkDevice, &destinationImageParams);
2741 m_destinationImageAlloc = allocateImage(vki, vk, vkPhysDevice, vkDevice, *m_destination, MemoryRequirement::Any, memAlloc, m_params.allocationKind);
2742 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
2745 // Barriers for copying image to buffer
2746 VkImageMemoryBarrier srcImageBarrier =
2748 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2749 DE_NULL, // const void* pNext;
2750 0u, // VkAccessFlags srcAccessMask;
2751 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
2752 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2753 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
2754 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2755 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2756 m_multisampledImage.get(), // VkImage image;
2757 { // VkImageSubresourceRange subresourceRange;
2758 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
2759 0u, // deUint32 baseMipLevel;
2760 1u, // deUint32 mipLevels;
2761 0u, // deUint32 baseArraySlice;
2762 getArraySize(m_params.src.image) // deUint32 arraySize;
2766 // Create render pass.
2768 const VkAttachmentDescription attachmentDescriptions[1] =
2771 0u, // VkAttachmentDescriptionFlags flags;
2772 m_params.src.image.format, // VkFormat format;
2773 rasterizationSamples, // VkSampleCountFlagBits samples;
2774 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
2775 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
2776 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
2777 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
2778 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
2779 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
2783 const VkAttachmentReference colorAttachmentReference =
2785 0u, // deUint32 attachment;
2786 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
2789 const VkSubpassDescription subpassDescription =
2791 0u, // VkSubpassDescriptionFlags flags;
2792 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
2793 0u, // deUint32 inputAttachmentCount;
2794 DE_NULL, // const VkAttachmentReference* pInputAttachments;
2795 1u, // deUint32 colorAttachmentCount;
2796 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
2797 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
2798 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
2799 0u, // deUint32 preserveAttachmentCount;
2800 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
2803 const VkRenderPassCreateInfo renderPassParams =
2805 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
2806 DE_NULL, // const void* pNext;
2807 0u, // VkRenderPassCreateFlags flags;
2808 1u, // deUint32 attachmentCount;
2809 attachmentDescriptions, // const VkAttachmentDescription* pAttachments;
2810 1u, // deUint32 subpassCount;
2811 &subpassDescription, // const VkSubpassDescription* pSubpasses;
2812 0u, // deUint32 dependencyCount;
2813 DE_NULL // const VkSubpassDependency* pDependencies;
2816 renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
2819 // Create pipeline layout
2821 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
2823 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
2824 DE_NULL, // const void* pNext;
2825 0u, // VkPipelineLayoutCreateFlags flags;
2826 0u, // deUint32 setLayoutCount;
2827 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
2828 0u, // deUint32 pushConstantRangeCount;
2829 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
2832 pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
2835 // Create upper half triangle.
2837 const tcu::Vec4 a (-1.0, -1.0, 0.0, 1.0);
2838 const tcu::Vec4 b (1.0, -1.0, 0.0, 1.0);
2839 const tcu::Vec4 c (1.0, 1.0, 0.0, 1.0);
2841 vertices.push_back(a);
2842 vertices.push_back(c);
2843 vertices.push_back(b);
2846 // Create vertex buffer.
2848 const VkDeviceSize vertexDataSize = vertices.size() * sizeof(tcu::Vec4);
2849 const VkBufferCreateInfo vertexBufferParams =
2851 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
2852 DE_NULL, // const void* pNext;
2853 0u, // VkBufferCreateFlags flags;
2854 vertexDataSize, // VkDeviceSize size;
2855 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
2856 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2857 1u, // deUint32 queueFamilyIndexCount;
2858 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
2861 vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
2862 vertexBufferAlloc = allocateBuffer(vki, vk, vkPhysDevice, vkDevice, *vertexBuffer, MemoryRequirement::HostVisible, memAlloc, m_params.allocationKind);
2863 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset()));
2865 // Load vertices into vertex buffer.
2866 deMemcpy(vertexBufferAlloc->getHostPtr(), vertices.data(), (size_t)vertexDataSize);
2867 flushMappedMemoryRange(vk, vkDevice, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset(), vertexDataSize);
2871 Move<VkFramebuffer> framebuffer;
2872 Move<VkImageView> sourceAttachmentView;
2874 // Create color attachment view.
2876 const VkImageViewCreateInfo colorAttachmentViewParams =
2878 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
2879 DE_NULL, // const void* pNext;
2880 0u, // VkImageViewCreateFlags flags;
2881 *m_multisampledImage, // VkImage image;
2882 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
2883 m_params.src.image.format, // VkFormat format;
2884 componentMappingRGBA, // VkComponentMapping components;
2885 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
2887 sourceAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
2890 // Create framebuffer
2892 const VkImageView attachments[1] =
2894 *sourceAttachmentView,
2897 const VkFramebufferCreateInfo framebufferParams =
2899 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
2900 DE_NULL, // const void* pNext;
2901 0u, // VkFramebufferCreateFlags flags;
2902 *renderPass, // VkRenderPass renderPass;
2903 1u, // deUint32 attachmentCount;
2904 attachments, // const VkImageView* pAttachments;
2905 m_params.src.image.extent.width, // deUint32 width;
2906 m_params.src.image.extent.height, // deUint32 height;
2907 1u // deUint32 layers;
2910 framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
2915 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
2918 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
2919 DE_NULL, // const void* pNext;
2920 0u, // VkPipelineShaderStageCreateFlags flags;
2921 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
2922 *vertexShaderModule, // VkShaderModule module;
2923 "main", // const char* pName;
2924 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
2927 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
2928 DE_NULL, // const void* pNext;
2929 0u, // VkPipelineShaderStageCreateFlags flags;
2930 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
2931 *fragmentShaderModule, // VkShaderModule module;
2932 "main", // const char* pName;
2933 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
2937 const VkVertexInputBindingDescription vertexInputBindingDescription =
2939 0u, // deUint32 binding;
2940 sizeof(tcu::Vec4), // deUint32 stride;
2941 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputRate inputRate;
2944 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[1] =
2947 0u, // deUint32 location;
2948 0u, // deUint32 binding;
2949 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
2950 0u // deUint32 offset;
2954 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
2956 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
2957 DE_NULL, // const void* pNext;
2958 0u, // VkPipelineVertexInputStateCreateFlags flags;
2959 1u, // deUint32 vertexBindingDescriptionCount;
2960 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
2961 1u, // deUint32 vertexAttributeDescriptionCount;
2962 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
2965 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
2967 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
2968 DE_NULL, // const void* pNext;
2969 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
2970 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
2971 false // VkBool32 primitiveRestartEnable;
2974 const VkViewport viewport =
2978 (float)m_params.src.image.extent.width, // float width;
2979 (float)m_params.src.image.extent.height,// float height;
2980 0.0f, // float minDepth;
2981 1.0f // float maxDepth;
2984 const VkRect2D scissor =
2986 { 0, 0 }, // VkOffset2D offset;
2987 { m_params.src.image.extent.width, m_params.src.image.extent.height } // VkExtent2D extent;
2990 const VkPipelineViewportStateCreateInfo viewportStateParams =
2992 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
2993 DE_NULL, // const void* pNext;
2994 0u, // VkPipelineViewportStateCreateFlags flags;
2995 1u, // deUint32 viewportCount;
2996 &viewport, // const VkViewport* pViewports;
2997 1u, // deUint32 scissorCount;
2998 &scissor // const VkRect2D* pScissors;
3001 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
3003 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
3004 DE_NULL, // const void* pNext;
3005 0u, // VkPipelineRasterizationStateCreateFlags flags;
3006 false, // VkBool32 depthClampEnable;
3007 false, // VkBool32 rasterizerDiscardEnable;
3008 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
3009 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
3010 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
3011 VK_FALSE, // VkBool32 depthBiasEnable;
3012 0.0f, // float depthBiasConstantFactor;
3013 0.0f, // float depthBiasClamp;
3014 0.0f, // float depthBiasSlopeFactor;
3015 1.0f // float lineWidth;
3018 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
3020 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
3021 DE_NULL, // const void* pNext;
3022 0u, // VkPipelineMultisampleStateCreateFlags flags;
3023 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
3024 VK_FALSE, // VkBool32 sampleShadingEnable;
3025 0.0f, // float minSampleShading;
3026 DE_NULL, // const VkSampleMask* pSampleMask;
3027 VK_FALSE, // VkBool32 alphaToCoverageEnable;
3028 VK_FALSE // VkBool32 alphaToOneEnable;
3031 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
3033 false, // VkBool32 blendEnable;
3034 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor;
3035 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor;
3036 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor;
3037 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha;
3038 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha;
3039 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha;
3040 (VK_COLOR_COMPONENT_R_BIT |
3041 VK_COLOR_COMPONENT_G_BIT |
3042 VK_COLOR_COMPONENT_B_BIT |
3043 VK_COLOR_COMPONENT_A_BIT) // VkChannelFlags channelWriteMask;
3046 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
3048 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
3049 DE_NULL, // const void* pNext;
3050 0u, // VkPipelineColorBlendStateCreateFlags flags;
3051 false, // VkBool32 logicOpEnable;
3052 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
3053 1u, // deUint32 attachmentCount;
3054 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
3055 { 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4];
3058 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
3060 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
3061 DE_NULL, // const void* pNext;
3062 0u, // VkPipelineCreateFlags flags;
3063 2u, // deUint32 stageCount;
3064 shaderStageParams, // const VkPipelineShaderStageCreateInfo* pStages;
3065 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
3066 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
3067 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
3068 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
3069 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
3070 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
3071 DE_NULL, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
3072 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
3073 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
3074 *pipelineLayout, // VkPipelineLayout layout;
3075 *renderPass, // VkRenderPass renderPass;
3076 0u, // deUint32 subpass;
3077 0u, // VkPipeline basePipelineHandle;
3078 0u // deInt32 basePipelineIndex;
3081 graphicsPipeline = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
3084 // Create command buffer
3086 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
3088 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
3089 DE_NULL, // const void* pNext;
3090 0u, // VkCommandBufferUsageFlags flags;
3091 (const VkCommandBufferInheritanceInfo*)DE_NULL,
3094 const VkClearValue clearValues[1] =
3096 makeClearValueColorF32(0.0f, 0.0f, 1.0f, 1.0f),
3099 const VkRenderPassBeginInfo renderPassBeginInfo =
3101 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
3102 DE_NULL, // const void* pNext;
3103 *renderPass, // VkRenderPass renderPass;
3104 *framebuffer, // VkFramebuffer framebuffer;
3107 { m_params.src.image.extent.width, m_params.src.image.extent.height }
3108 }, // VkRect2D renderArea;
3109 1u, // deUint32 clearValueCount;
3110 clearValues // const VkClearValue* pClearValues;
3113 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
3114 vk.cmdPipelineBarrier(*m_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);
3115 vk.cmdBeginRenderPass(*m_cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
3117 const VkDeviceSize vertexBufferOffset = 0u;
3119 vk.cmdBindPipeline(*m_cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *graphicsPipeline);
3120 vk.cmdBindVertexBuffers(*m_cmdBuffer, 0, 1, &vertexBuffer.get(), &vertexBufferOffset);
3121 vk.cmdDraw(*m_cmdBuffer, (deUint32)vertices.size(), 1, 0, 0);
3123 vk.cmdEndRenderPass(*m_cmdBuffer);
3124 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3129 const VkQueue queue = m_context.getUniversalQueue();
3130 submitCommandsAndWait (vk, vkDevice, queue, *m_cmdBuffer);
3135 tcu::TestStatus ResolveImageToImage::iterate (void)
3137 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
3138 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
3140 // upload the destination image
3141 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
3142 (int)m_params.dst.image.extent.width,
3143 (int)m_params.dst.image.extent.height,
3144 (int)m_params.dst.image.extent.depth));
3145 generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth);
3146 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get(), m_params.dst.image);
3148 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
3149 (int)m_params.src.image.extent.width,
3150 (int)m_params.src.image.extent.height,
3151 (int)m_params.dst.image.extent.depth));
3153 generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.dst.image.extent.depth, FILL_MODE_MULTISAMPLE);
3154 generateExpectedResult();
3158 case COPY_MS_IMAGE_TO_MS_IMAGE:
3159 case COPY_MS_IMAGE_TO_ARRAY_MS_IMAGE:
3160 copyMSImageToMSImage();
3166 const DeviceInterface& vk = m_context.getDeviceInterface();
3167 const VkDevice vkDevice = m_context.getDevice();
3168 const VkQueue queue = m_context.getUniversalQueue();
3170 std::vector<VkImageResolve> imageResolves;
3171 for (deUint32 i = 0; i < m_params.regions.size(); i++)
3172 imageResolves.push_back(m_params.regions[i].imageResolve);
3174 const VkImageMemoryBarrier imageBarriers[] =
3178 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
3179 DE_NULL, // const void* pNext;
3180 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags srcAccessMask;
3181 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
3182 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
3183 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
3184 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
3185 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
3186 m_multisampledImage.get(), // VkImage image;
3187 { // VkImageSubresourceRange subresourceRange;
3188 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
3189 0u, // deUint32 baseMipLevel;
3190 1u, // deUint32 mipLevels;
3191 0u, // deUint32 baseArraySlice;
3192 getArraySize(m_params.src.image) // deUint32 arraySize;
3195 // destination image
3197 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
3198 DE_NULL, // const void* pNext;
3199 0u, // VkAccessFlags srcAccessMask;
3200 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
3201 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
3202 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
3203 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
3204 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
3205 m_destination.get(), // VkImage image;
3206 { // VkImageSubresourceRange subresourceRange;
3207 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
3208 0u, // deUint32 baseMipLevel;
3209 1u, // deUint32 mipLevels;
3210 0u, // deUint32 baseArraySlice;
3211 getArraySize(m_params.dst.image) // deUint32 arraySize;
3216 const VkImageMemoryBarrier postImageBarrier =
3218 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
3219 DE_NULL, // const void* pNext;
3220 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
3221 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
3222 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
3223 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
3224 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
3225 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
3226 m_destination.get(), // VkImage image;
3227 { // VkImageSubresourceRange subresourceRange;
3228 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
3229 0u, // deUint32 baseMipLevel;
3230 1u, // deUint32 mipLevels;
3231 0u, // deUint32 baseArraySlice;
3232 getArraySize(m_params.dst.image) // deUint32 arraySize;
3236 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
3238 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
3239 DE_NULL, // const void* pNext;
3240 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
3241 (const VkCommandBufferInheritanceInfo*)DE_NULL,
3244 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
3245 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);
3246 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());
3247 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);
3248 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3249 submitCommandsAndWait(vk, vkDevice, queue, *m_cmdBuffer);
3251 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(*m_destination, m_params.dst.image);
3253 return checkTestResult(resultTextureLevel->getAccess());
3256 tcu::TestStatus ResolveImageToImage::checkTestResult (tcu::ConstPixelBufferAccess result)
3258 const tcu::ConstPixelBufferAccess expected = m_expectedTextureLevel->getAccess();
3259 const float fuzzyThreshold = 0.01f;
3261 for (int arrayLayerNdx = 0; arrayLayerNdx < (int)getArraySize(m_params.dst.image); ++arrayLayerNdx)
3263 const tcu::ConstPixelBufferAccess expectedSub = getSubregion (expected, 0, 0, arrayLayerNdx, expected.getWidth(), expected.getHeight(), 1u);
3264 const tcu::ConstPixelBufferAccess resultSub = getSubregion (result, 0, 0, arrayLayerNdx, result.getWidth(), result.getHeight(), 1u);
3265 if (!tcu::fuzzyCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expectedSub, resultSub, fuzzyThreshold, tcu::COMPARE_LOG_RESULT))
3266 return tcu::TestStatus::fail("CopiesAndBlitting test");
3269 return tcu::TestStatus::pass("CopiesAndBlitting test");
3272 void ResolveImageToImage::copyRegionToTextureLevel(tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
3274 VkOffset3D srcOffset = region.imageResolve.srcOffset;
3275 srcOffset.z = region.imageResolve.srcSubresource.baseArrayLayer;
3276 VkOffset3D dstOffset = region.imageResolve.dstOffset;
3277 dstOffset.z = region.imageResolve.dstSubresource.baseArrayLayer;
3278 VkExtent3D extent = region.imageResolve.extent;
3280 const tcu::ConstPixelBufferAccess srcSubRegion = getSubregion (src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth);
3281 // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
3282 const tcu::PixelBufferAccess dstWithSrcFormat (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
3283 const tcu::PixelBufferAccess dstSubRegion = getSubregion (dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth);
3285 tcu::copy(dstSubRegion, srcSubRegion);
3288 void ResolveImageToImage::copyMSImageToMSImage (void)
3290 const DeviceInterface& vk = m_context.getDeviceInterface();
3291 const VkDevice vkDevice = m_context.getDevice();
3292 const VkQueue queue = m_context.getUniversalQueue();
3293 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
3294 std::vector<VkImageCopy> imageCopies;
3296 for (deUint32 layerNdx = 0; layerNdx < getArraySize(m_params.dst.image); ++layerNdx)
3298 const VkImageSubresourceLayers sourceSubresourceLayers =
3300 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
3301 0u, // uint32_t mipLevel;
3302 0u, // uint32_t baseArrayLayer;
3303 1u // uint32_t layerCount;
3306 const VkImageSubresourceLayers destinationSubresourceLayers =
3308 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;//getAspectFlags(dstTcuFormat)
3309 0u, // uint32_t mipLevel;
3310 layerNdx, // uint32_t baseArrayLayer;
3311 1u // uint32_t layerCount;
3314 const VkImageCopy imageCopy =
3316 sourceSubresourceLayers, // VkImageSubresourceLayers srcSubresource;
3317 {0, 0, 0}, // VkOffset3D srcOffset;
3318 destinationSubresourceLayers, // VkImageSubresourceLayers dstSubresource;
3319 {0, 0, 0}, // VkOffset3D dstOffset;
3320 getExtent3D(m_params.src.image), // VkExtent3D extent;
3322 imageCopies.push_back(imageCopy);
3325 const VkImageMemoryBarrier imageBarriers[] =
3329 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
3330 DE_NULL, // const void* pNext;
3331 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags srcAccessMask;
3332 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
3333 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
3334 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
3335 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
3336 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
3337 m_multisampledImage.get(), // VkImage image;
3338 { // VkImageSubresourceRange subresourceRange;
3339 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
3340 0u, // deUint32 baseMipLevel;
3341 1u, // deUint32 mipLevels;
3342 0u, // deUint32 baseArraySlice;
3343 getArraySize(m_params.src.image) // deUint32 arraySize;
3346 // destination image
3348 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
3349 DE_NULL, // const void* pNext;
3350 0, // VkAccessFlags srcAccessMask;
3351 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
3352 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
3353 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
3354 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
3355 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
3356 m_multisampledCopyImage.get(), // VkImage image;
3357 { // VkImageSubresourceRange subresourceRange;
3358 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
3359 0u, // deUint32 baseMipLevel;
3360 1u, // deUint32 mipLevels;
3361 0u, // deUint32 baseArraySlice;
3362 getArraySize(m_params.dst.image) // deUint32 arraySize;
3367 const VkImageMemoryBarrier postImageBarriers =
3370 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
3371 DE_NULL, // const void* pNext;
3372 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
3373 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
3374 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
3375 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
3376 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
3377 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
3378 m_multisampledCopyImage.get(), // VkImage image;
3379 { // VkImageSubresourceRange subresourceRange;
3380 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
3381 0u, // deUint32 baseMipLevel;
3382 1u, // deUint32 mipLevels;
3383 0u, // deUint32 baseArraySlice;
3384 getArraySize(m_params.dst.image) // deUint32 arraySize;
3388 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
3390 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
3391 DE_NULL, // const void* pNext;
3392 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
3393 (const VkCommandBufferInheritanceInfo*)DE_NULL,
3396 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
3397 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);
3398 vk.cmdCopyImage(*m_cmdBuffer, m_multisampledImage.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_multisampledCopyImage.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)imageCopies.size(), imageCopies.data());
3399 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1u, &postImageBarriers);
3400 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
3402 submitCommandsAndWait (vk, vkDevice, queue, *m_cmdBuffer);
3404 m_multisampledImage = m_multisampledCopyImage;
3407 class ResolveImageToImageTestCase : public vkt::TestCase
3410 ResolveImageToImageTestCase (tcu::TestContext& testCtx,
3411 const std::string& name,
3412 const std::string& description,
3413 const TestParams params,
3414 const ResolveImageToImageOptions options = NO_OPTIONAL_OPERATION)
3415 : vkt::TestCase (testCtx, name, description)
3417 , m_options (options)
3419 virtual void initPrograms (SourceCollections& programCollection) const;
3421 virtual TestInstance* createInstance (Context& context) const
3423 return new ResolveImageToImage(context, m_params, m_options);
3426 TestParams m_params;
3427 const ResolveImageToImageOptions m_options;
3430 void ResolveImageToImageTestCase::initPrograms (SourceCollections& programCollection) const
3432 programCollection.glslSources.add("vert") << glu::VertexSource(
3434 "layout (location = 0) in highp vec4 a_position;\n"
3437 " gl_Position = a_position;\n"
3441 programCollection.glslSources.add("frag") << glu::FragmentSource(
3443 "layout (location = 0) out highp vec4 o_color;\n"
3446 " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
3450 std::string getSampleCountCaseName (VkSampleCountFlagBits sampleFlag)
3452 return de::toLower(de::toString(getSampleCountFlagsStr(sampleFlag)).substr(16));
3455 std::string getFormatCaseName (VkFormat format)
3457 return de::toLower(de::toString(getFormatStr(format)).substr(10));
3460 std::string getImageLayoutCaseName (VkImageLayout layout)
3464 case VK_IMAGE_LAYOUT_GENERAL:
3466 case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL:
3467 case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL:
3475 const deInt32 defaultSize = 64;
3476 const deInt32 defaultHalfSize = defaultSize / 2;
3477 const deInt32 defaultFourthSize = defaultSize / 4;
3478 const VkExtent3D defaultExtent = {defaultSize, defaultSize, 1};
3479 const VkExtent3D defaultHalfExtent = {defaultHalfSize, defaultHalfSize, 1};
3481 const VkImageSubresourceLayers defaultSourceLayer =
3483 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
3484 0u, // uint32_t mipLevel;
3485 0u, // uint32_t baseArrayLayer;
3486 1u, // uint32_t layerCount;
3489 void addImageToImageSimpleTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
3491 tcu::TestContext& testCtx = group->getTestContext();
3495 params.src.image.imageType = VK_IMAGE_TYPE_2D;
3496 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3497 params.src.image.extent = defaultExtent;
3498 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3499 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
3500 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3501 params.dst.image.extent = defaultExtent;
3502 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3503 params.allocationKind = allocationKind;
3506 const VkImageCopy testCopy =
3508 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3509 {0, 0, 0}, // VkOffset3D srcOffset;
3510 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3511 {0, 0, 0}, // VkOffset3D dstOffset;
3512 defaultExtent, // VkExtent3D extent;
3515 CopyRegion imageCopy;
3516 imageCopy.imageCopy = testCopy;
3518 params.regions.push_back(imageCopy);
3521 group->addChild(new CopyImageToImageTestCase(testCtx, "whole_image", "Whole image", params));
3526 params.src.image.imageType = VK_IMAGE_TYPE_2D;
3527 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3528 params.src.image.extent = defaultExtent;
3529 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3530 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
3531 params.dst.image.format = VK_FORMAT_R32_UINT;
3532 params.dst.image.extent = defaultExtent;
3533 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3534 params.allocationKind = allocationKind;
3537 const VkImageCopy testCopy =
3539 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3540 {0, 0, 0}, // VkOffset3D srcOffset;
3541 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3542 {0, 0, 0}, // VkOffset3D dstOffset;
3543 defaultExtent, // VkExtent3D extent;
3546 CopyRegion imageCopy;
3547 imageCopy.imageCopy = testCopy;
3549 params.regions.push_back(imageCopy);
3552 group->addChild(new CopyImageToImageTestCase(testCtx, "whole_image_diff_fromat", "Whole image with different format", params));
3557 params.src.image.imageType = VK_IMAGE_TYPE_2D;
3558 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3559 params.src.image.extent = defaultExtent;
3560 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3561 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
3562 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3563 params.dst.image.extent = defaultExtent;
3564 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3565 params.allocationKind = allocationKind;
3568 const VkImageCopy testCopy =
3570 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3571 {0, 0, 0}, // VkOffset3D srcOffset;
3572 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3573 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3574 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3577 CopyRegion imageCopy;
3578 imageCopy.imageCopy = testCopy;
3580 params.regions.push_back(imageCopy);
3583 group->addChild(new CopyImageToImageTestCase(testCtx, "partial_image", "Partial image", params));
3588 params.src.image.imageType = VK_IMAGE_TYPE_2D;
3589 params.src.image.format = VK_FORMAT_D32_SFLOAT;
3590 params.src.image.extent = defaultExtent;
3591 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3592 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
3593 params.dst.image.format = VK_FORMAT_D32_SFLOAT;
3594 params.dst.image.extent = defaultExtent;
3595 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3596 params.allocationKind = allocationKind;
3599 const VkImageSubresourceLayers sourceLayer =
3601 VK_IMAGE_ASPECT_DEPTH_BIT, // VkImageAspectFlags aspectMask;
3602 0u, // uint32_t mipLevel;
3603 0u, // uint32_t baseArrayLayer;
3604 1u // uint32_t layerCount;
3606 const VkImageCopy testCopy =
3608 sourceLayer, // VkImageSubresourceLayers srcSubresource;
3609 {0, 0, 0}, // VkOffset3D srcOffset;
3610 sourceLayer, // VkImageSubresourceLayers dstSubresource;
3611 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3612 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3615 CopyRegion imageCopy;
3616 imageCopy.imageCopy = testCopy;
3618 params.regions.push_back(imageCopy);
3621 group->addChild(new CopyImageToImageTestCase(testCtx, "depth", "With depth", params));
3626 params.src.image.imageType = VK_IMAGE_TYPE_2D;
3627 params.src.image.format = VK_FORMAT_S8_UINT;
3628 params.src.image.extent = defaultExtent;
3629 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
3630 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
3631 params.dst.image.format = VK_FORMAT_S8_UINT;
3632 params.dst.image.extent = defaultExtent;
3633 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
3634 params.allocationKind = allocationKind;
3637 const VkImageSubresourceLayers sourceLayer =
3639 VK_IMAGE_ASPECT_STENCIL_BIT, // VkImageAspectFlags aspectMask;
3640 0u, // uint32_t mipLevel;
3641 0u, // uint32_t baseArrayLayer;
3642 1u // uint32_t layerCount;
3644 const VkImageCopy testCopy =
3646 sourceLayer, // VkImageSubresourceLayers srcSubresource;
3647 {0, 0, 0}, // VkOffset3D srcOffset;
3648 sourceLayer, // VkImageSubresourceLayers dstSubresource;
3649 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3650 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3653 CopyRegion imageCopy;
3654 imageCopy.imageCopy = testCopy;
3656 params.regions.push_back(imageCopy);
3659 group->addChild(new CopyImageToImageTestCase(testCtx, "stencil", "With stencil", params));
3663 struct CopyColorTestParams
3666 const VkFormat* compatibleFormats;
3669 void addImageToImageAllFormatsColorSrcFormatDstFormatTests (tcu::TestCaseGroup* group, TestParams params)
3671 const VkImageLayout copySrcLayouts[] =
3673 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
3674 VK_IMAGE_LAYOUT_GENERAL
3676 const VkImageLayout copyDstLayouts[] =
3678 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
3679 VK_IMAGE_LAYOUT_GENERAL
3682 for (int srcLayoutNdx = 0u; srcLayoutNdx < DE_LENGTH_OF_ARRAY(copySrcLayouts); ++srcLayoutNdx)
3684 params.src.image.operationLayout = copySrcLayouts[srcLayoutNdx];
3686 for (int dstLayoutNdx = 0u; dstLayoutNdx < DE_LENGTH_OF_ARRAY(copyDstLayouts); ++dstLayoutNdx)
3688 params.dst.image.operationLayout = copyDstLayouts[dstLayoutNdx];
3690 const std::string testName = getImageLayoutCaseName(params.src.image.operationLayout) + "_" +
3691 getImageLayoutCaseName(params.dst.image.operationLayout);
3692 const std::string description = "From layout " + getImageLayoutCaseName(params.src.image.operationLayout) +
3693 " to " + getImageLayoutCaseName(params.dst.image.operationLayout);
3694 group->addChild(new CopyImageToImageTestCase(group->getTestContext(), testName, description, params));
3699 bool isAllowedImageToImageAllFormatsColorSrcFormatTests(CopyColorTestParams& testParams)
3703 if (testParams.params.allocationKind == ALLOCATION_KIND_DEDICATED)
3705 DE_ASSERT(!dedicatedAllocationImageToImageFormatsToTestSet.empty());
3708 de::contains(dedicatedAllocationImageToImageFormatsToTestSet, testParams.params.dst.image.format) ||
3709 de::contains(dedicatedAllocationImageToImageFormatsToTestSet, testParams.params.src.image.format);
3715 void addImageToImageAllFormatsColorSrcFormatTests (tcu::TestCaseGroup* group, CopyColorTestParams testParams)
3717 for (int dstFormatIndex = 0; testParams.compatibleFormats[dstFormatIndex] != VK_FORMAT_UNDEFINED; ++dstFormatIndex)
3719 testParams.params.dst.image.format = testParams.compatibleFormats[dstFormatIndex];
3720 if (!isSupportedByFramework(testParams.params.dst.image.format))
3723 if (!isAllowedImageToImageAllFormatsColorSrcFormatTests(testParams))
3726 const std::string description = "Copy to destination format " + getFormatCaseName(testParams.params.dst.image.format);
3727 addTestGroup(group, getFormatCaseName(testParams.params.dst.image.format), description, addImageToImageAllFormatsColorSrcFormatDstFormatTests, testParams.params);
3731 const VkFormat compatibleFormats8Bit[] =
3733 VK_FORMAT_R4G4_UNORM_PACK8,
3736 VK_FORMAT_R8_USCALED,
3737 VK_FORMAT_R8_SSCALED,
3744 const VkFormat compatibleFormats16Bit[] =
3746 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
3747 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
3748 VK_FORMAT_R5G6B5_UNORM_PACK16,
3749 VK_FORMAT_B5G6R5_UNORM_PACK16,
3750 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
3751 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
3752 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
3753 VK_FORMAT_R8G8_UNORM,
3754 VK_FORMAT_R8G8_SNORM,
3755 VK_FORMAT_R8G8_USCALED,
3756 VK_FORMAT_R8G8_SSCALED,
3757 VK_FORMAT_R8G8_UINT,
3758 VK_FORMAT_R8G8_SINT,
3759 VK_FORMAT_R8G8_SRGB,
3760 VK_FORMAT_R16_UNORM,
3761 VK_FORMAT_R16_SNORM,
3762 VK_FORMAT_R16_USCALED,
3763 VK_FORMAT_R16_SSCALED,
3766 VK_FORMAT_R16_SFLOAT,
3770 const VkFormat compatibleFormats24Bit[] =
3772 VK_FORMAT_R8G8B8_UNORM,
3773 VK_FORMAT_R8G8B8_SNORM,
3774 VK_FORMAT_R8G8B8_USCALED,
3775 VK_FORMAT_R8G8B8_SSCALED,
3776 VK_FORMAT_R8G8B8_UINT,
3777 VK_FORMAT_R8G8B8_SINT,
3778 VK_FORMAT_R8G8B8_SRGB,
3779 VK_FORMAT_B8G8R8_UNORM,
3780 VK_FORMAT_B8G8R8_SNORM,
3781 VK_FORMAT_B8G8R8_USCALED,
3782 VK_FORMAT_B8G8R8_SSCALED,
3783 VK_FORMAT_B8G8R8_UINT,
3784 VK_FORMAT_B8G8R8_SINT,
3785 VK_FORMAT_B8G8R8_SRGB,
3789 const VkFormat compatibleFormats32Bit[] =
3791 VK_FORMAT_R8G8B8A8_UNORM,
3792 VK_FORMAT_R8G8B8A8_SNORM,
3793 VK_FORMAT_R8G8B8A8_USCALED,
3794 VK_FORMAT_R8G8B8A8_SSCALED,
3795 VK_FORMAT_R8G8B8A8_UINT,
3796 VK_FORMAT_R8G8B8A8_SINT,
3797 VK_FORMAT_R8G8B8A8_SRGB,
3798 VK_FORMAT_B8G8R8A8_UNORM,
3799 VK_FORMAT_B8G8R8A8_SNORM,
3800 VK_FORMAT_B8G8R8A8_USCALED,
3801 VK_FORMAT_B8G8R8A8_SSCALED,
3802 VK_FORMAT_B8G8R8A8_UINT,
3803 VK_FORMAT_B8G8R8A8_SINT,
3804 VK_FORMAT_B8G8R8A8_SRGB,
3805 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
3806 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
3807 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
3808 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
3809 VK_FORMAT_A8B8G8R8_UINT_PACK32,
3810 VK_FORMAT_A8B8G8R8_SINT_PACK32,
3811 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
3812 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
3813 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
3814 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
3815 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
3816 VK_FORMAT_A2R10G10B10_UINT_PACK32,
3817 VK_FORMAT_A2R10G10B10_SINT_PACK32,
3818 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
3819 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
3820 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
3821 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
3822 VK_FORMAT_A2B10G10R10_UINT_PACK32,
3823 VK_FORMAT_A2B10G10R10_SINT_PACK32,
3824 VK_FORMAT_R16G16_UNORM,
3825 VK_FORMAT_R16G16_SNORM,
3826 VK_FORMAT_R16G16_USCALED,
3827 VK_FORMAT_R16G16_SSCALED,
3828 VK_FORMAT_R16G16_UINT,
3829 VK_FORMAT_R16G16_SINT,
3830 VK_FORMAT_R16G16_SFLOAT,
3833 VK_FORMAT_R32_SFLOAT,
3837 const VkFormat compatibleFormats48Bit[] =
3839 VK_FORMAT_R16G16B16_UNORM,
3840 VK_FORMAT_R16G16B16_SNORM,
3841 VK_FORMAT_R16G16B16_USCALED,
3842 VK_FORMAT_R16G16B16_SSCALED,
3843 VK_FORMAT_R16G16B16_UINT,
3844 VK_FORMAT_R16G16B16_SINT,
3845 VK_FORMAT_R16G16B16_SFLOAT,
3849 const VkFormat compatibleFormats64Bit[] =
3851 VK_FORMAT_R16G16B16A16_UNORM,
3852 VK_FORMAT_R16G16B16A16_SNORM,
3853 VK_FORMAT_R16G16B16A16_USCALED,
3854 VK_FORMAT_R16G16B16A16_SSCALED,
3855 VK_FORMAT_R16G16B16A16_UINT,
3856 VK_FORMAT_R16G16B16A16_SINT,
3857 VK_FORMAT_R16G16B16A16_SFLOAT,
3858 VK_FORMAT_R32G32_UINT,
3859 VK_FORMAT_R32G32_SINT,
3860 VK_FORMAT_R32G32_SFLOAT,
3863 VK_FORMAT_R64_SFLOAT,
3867 const VkFormat compatibleFormats96Bit[] =
3869 VK_FORMAT_R32G32B32_UINT,
3870 VK_FORMAT_R32G32B32_SINT,
3871 VK_FORMAT_R32G32B32_SFLOAT,
3875 const VkFormat compatibleFormats128Bit[] =
3877 VK_FORMAT_R32G32B32A32_UINT,
3878 VK_FORMAT_R32G32B32A32_SINT,
3879 VK_FORMAT_R32G32B32A32_SFLOAT,
3880 VK_FORMAT_R64G64_UINT,
3881 VK_FORMAT_R64G64_SINT,
3882 VK_FORMAT_R64G64_SFLOAT,
3886 const VkFormat compatibleFormats192Bit[] =
3888 VK_FORMAT_R64G64B64_UINT,
3889 VK_FORMAT_R64G64B64_SINT,
3890 VK_FORMAT_R64G64B64_SFLOAT,
3894 const VkFormat compatibleFormats256Bit[] =
3896 VK_FORMAT_R64G64B64A64_UINT,
3897 VK_FORMAT_R64G64B64A64_SINT,
3898 VK_FORMAT_R64G64B64A64_SFLOAT,
3903 const VkFormat* colorImageFormatsToTest[] =
3905 compatibleFormats8Bit,
3906 compatibleFormats16Bit,
3907 compatibleFormats24Bit,
3908 compatibleFormats32Bit,
3909 compatibleFormats48Bit,
3910 compatibleFormats64Bit,
3911 compatibleFormats96Bit,
3912 compatibleFormats128Bit,
3913 compatibleFormats192Bit,
3914 compatibleFormats256Bit,
3917 const VkFormat dedicatedAllocationImageToImageFormatsToTest[] =
3919 // From compatibleFormats8Bit
3920 VK_FORMAT_R4G4_UNORM_PACK8,
3923 // From compatibleFormats16Bit
3924 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
3925 VK_FORMAT_R16_SFLOAT,
3927 // From compatibleFormats24Bit
3928 VK_FORMAT_R8G8B8_UNORM,
3929 VK_FORMAT_B8G8R8_SRGB,
3931 // From compatibleFormats32Bit
3932 VK_FORMAT_R8G8B8A8_UNORM,
3933 VK_FORMAT_R32_SFLOAT,
3935 // From compatibleFormats48Bit
3936 VK_FORMAT_R16G16B16_UNORM,
3937 VK_FORMAT_R16G16B16_SFLOAT,
3939 // From compatibleFormats64Bit
3940 VK_FORMAT_R16G16B16A16_UNORM,
3941 VK_FORMAT_R64_SFLOAT,
3943 // From compatibleFormats96Bit
3944 VK_FORMAT_R32G32B32_UINT,
3945 VK_FORMAT_R32G32B32_SFLOAT,
3947 // From compatibleFormats128Bit
3948 VK_FORMAT_R32G32B32A32_UINT,
3949 VK_FORMAT_R64G64_SFLOAT,
3951 // From compatibleFormats192Bit
3952 VK_FORMAT_R64G64B64_UINT,
3953 VK_FORMAT_R64G64B64_SFLOAT,
3955 // From compatibleFormats256Bit
3956 VK_FORMAT_R64G64B64A64_UINT,
3957 VK_FORMAT_R64G64B64A64_SFLOAT,
3960 void addImageToImageAllFormatsColorTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
3963 params.src.image.imageType = VK_IMAGE_TYPE_2D;
3964 params.src.image.extent = defaultExtent;
3965 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
3966 params.dst.image.extent = defaultExtent;
3967 params.allocationKind = allocationKind;
3969 for (deInt32 i = 0; i < defaultSize; i += defaultFourthSize)
3971 const VkImageCopy testCopy =
3973 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3974 {0, 0, 0}, // VkOffset3D srcOffset;
3975 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3976 {i, defaultSize - i - defaultFourthSize, 0}, // VkOffset3D dstOffset;
3977 {defaultFourthSize, defaultFourthSize, 1}, // VkExtent3D extent;
3980 CopyRegion imageCopy;
3981 imageCopy.imageCopy = testCopy;
3983 params.regions.push_back(imageCopy);
3986 if (allocationKind == ALLOCATION_KIND_DEDICATED)
3988 const int numOfColorImageFormatsToTestFilter = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
3989 for (int compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTestFilter; ++compatibleFormatsIndex)
3990 dedicatedAllocationImageToImageFormatsToTestSet.insert(dedicatedAllocationImageToImageFormatsToTest[compatibleFormatsIndex]);
3993 const int numOfColorImageFormatsToTest = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
3994 for (int compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
3996 const VkFormat* compatibleFormats = colorImageFormatsToTest[compatibleFormatsIndex];
3997 for (int srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_UNDEFINED; ++srcFormatIndex)
3999 params.src.image.format = compatibleFormats[srcFormatIndex];
4000 if (!isSupportedByFramework(params.src.image.format))
4003 CopyColorTestParams testParams;
4004 testParams.params = params;
4005 testParams.compatibleFormats = compatibleFormats;
4007 const std::string description = "Copy from source format " + getFormatCaseName(params.src.image.format);
4008 addTestGroup(group, getFormatCaseName(params.src.image.format), description, addImageToImageAllFormatsColorSrcFormatTests, testParams);
4013 void addImageToImageAllFormatsDepthStencilFormatsTests (tcu::TestCaseGroup* group, TestParams params)
4015 const VkImageLayout copySrcLayouts[] =
4017 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
4018 VK_IMAGE_LAYOUT_GENERAL
4020 const VkImageLayout copyDstLayouts[] =
4022 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
4023 VK_IMAGE_LAYOUT_GENERAL
4026 for (int srcLayoutNdx = 0u; srcLayoutNdx < DE_LENGTH_OF_ARRAY(copySrcLayouts); ++srcLayoutNdx)
4028 params.src.image.operationLayout = copySrcLayouts[srcLayoutNdx];
4029 for (int dstLayoutNdx = 0u; dstLayoutNdx < DE_LENGTH_OF_ARRAY(copyDstLayouts); ++dstLayoutNdx)
4031 params.dst.image.operationLayout = copyDstLayouts[dstLayoutNdx];
4033 const std::string testName = getImageLayoutCaseName(params.src.image.operationLayout) + "_" +
4034 getImageLayoutCaseName(params.dst.image.operationLayout);
4035 const std::string description = "From layout " + getImageLayoutCaseName(params.src.image.operationLayout) +
4036 " to " + getImageLayoutCaseName(params.dst.image.operationLayout);
4037 group->addChild(new CopyImageToImageTestCase(group->getTestContext(), testName, description, params));
4042 void addImageToImageAllFormatsDepthStencilTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4044 const VkFormat depthAndStencilFormats[] =
4046 VK_FORMAT_D16_UNORM,
4047 VK_FORMAT_X8_D24_UNORM_PACK32,
4048 VK_FORMAT_D32_SFLOAT,
4050 VK_FORMAT_D16_UNORM_S8_UINT,
4051 VK_FORMAT_D24_UNORM_S8_UINT,
4052 VK_FORMAT_D32_SFLOAT_S8_UINT,
4055 for (int compatibleFormatsIndex = 0; compatibleFormatsIndex < DE_LENGTH_OF_ARRAY(depthAndStencilFormats); ++compatibleFormatsIndex)
4058 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4059 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4060 params.src.image.extent = defaultExtent;
4061 params.dst.image.extent = defaultExtent;
4062 params.src.image.format = depthAndStencilFormats[compatibleFormatsIndex];
4063 params.dst.image.format = params.src.image.format;
4064 params.allocationKind = allocationKind;
4066 const VkImageSubresourceLayers defaultDepthSourceLayer = { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u };
4067 const VkImageSubresourceLayers defaultStencilSourceLayer = { VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u };
4069 for (deInt32 i = 0; i < defaultSize; i += defaultFourthSize)
4071 CopyRegion copyRegion;
4072 const VkOffset3D srcOffset = {0, 0, 0};
4073 const VkOffset3D dstOffset = {i, defaultSize - i - defaultFourthSize, 0};
4074 const VkExtent3D extent = {defaultFourthSize, defaultFourthSize, 1};
4076 if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
4078 const VkImageCopy testCopy =
4080 defaultDepthSourceLayer, // VkImageSubresourceLayers srcSubresource;
4081 srcOffset, // VkOffset3D srcOffset;
4082 defaultDepthSourceLayer, // VkImageSubresourceLayers dstSubresource;
4083 dstOffset, // VkOffset3D dstOffset;
4084 extent, // VkExtent3D extent;
4087 copyRegion.imageCopy = testCopy;
4088 params.regions.push_back(copyRegion);
4090 if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
4092 const VkImageCopy testCopy =
4094 defaultStencilSourceLayer, // VkImageSubresourceLayers srcSubresource;
4095 srcOffset, // VkOffset3D srcOffset;
4096 defaultStencilSourceLayer, // VkImageSubresourceLayers dstSubresource;
4097 dstOffset, // VkOffset3D dstOffset;
4098 extent, // VkExtent3D extent;
4101 copyRegion.imageCopy = testCopy;
4102 params.regions.push_back(copyRegion);
4106 const std::string testName = getFormatCaseName(params.src.image.format) + "_" + getFormatCaseName(params.dst.image.format);
4107 const std::string description = "Copy from " + getFormatCaseName(params.src.image.format) + " to " + getFormatCaseName(params.dst.image.format);
4108 addTestGroup(group, testName, description, addImageToImageAllFormatsDepthStencilFormatsTests, params);
4112 void addImageToImageAllFormatsTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4114 addTestGroup(group, "color", "Copy image to image with color formats", addImageToImageAllFormatsColorTests, allocationKind);
4115 addTestGroup(group, "depth_stencil", "Copy image to image with depth/stencil formats", addImageToImageAllFormatsDepthStencilTests, allocationKind);
4118 void addImageToImage3dImagesTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4120 tcu::TestContext& testCtx = group->getTestContext();
4123 TestParams params3DTo2D;
4124 const deUint32 slicesLayers = 16u;
4125 params3DTo2D.src.image.imageType = VK_IMAGE_TYPE_3D;
4126 params3DTo2D.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
4127 params3DTo2D.src.image.extent = defaultHalfExtent;
4128 params3DTo2D.src.image.extent.depth = slicesLayers;
4129 params3DTo2D.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4130 params3DTo2D.dst.image.imageType = VK_IMAGE_TYPE_2D;
4131 params3DTo2D.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
4132 params3DTo2D.dst.image.extent = defaultHalfExtent;
4133 params3DTo2D.dst.image.extent.depth = slicesLayers;
4134 params3DTo2D.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4135 params3DTo2D.allocationKind = allocationKind;
4137 for (deUint32 slicesLayersNdx = 0; slicesLayersNdx < slicesLayers; ++slicesLayersNdx)
4139 const VkImageSubresourceLayers sourceLayer =
4141 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4142 0u, // uint32_t mipLevel;
4143 0u, // uint32_t baseArrayLayer;
4144 1u // uint32_t layerCount;
4147 const VkImageSubresourceLayers destinationLayer =
4149 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4150 0u, // uint32_t mipLevel;
4151 slicesLayersNdx, // uint32_t baseArrayLayer;
4152 1u // uint32_t layerCount;
4155 const VkImageCopy testCopy =
4157 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4158 {0, 0, (deInt32)slicesLayersNdx}, // VkOffset3D srcOffset;
4159 destinationLayer, // VkImageSubresourceLayers dstSubresource;
4160 {0, 0, 0}, // VkOffset3D dstOffset;
4161 defaultHalfExtent, // VkExtent3D extent;
4164 CopyRegion imageCopy;
4165 imageCopy.imageCopy = testCopy;
4167 params3DTo2D.regions.push_back(imageCopy);
4169 group->addChild(new CopyImageToImageTestCase(testCtx, "3d_to_2d_by_slices", "copy 2d layers to 3d slices one by one", params3DTo2D));
4173 TestParams params2DTo3D;
4174 const deUint32 slicesLayers = 16u;
4175 params2DTo3D.src.image.imageType = VK_IMAGE_TYPE_2D;
4176 params2DTo3D.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
4177 params2DTo3D.src.image.extent = defaultHalfExtent;
4178 params2DTo3D.src.image.extent.depth = slicesLayers;
4179 params2DTo3D.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4180 params2DTo3D.dst.image.imageType = VK_IMAGE_TYPE_3D;
4181 params2DTo3D.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
4182 params2DTo3D.dst.image.extent = defaultHalfExtent;
4183 params2DTo3D.dst.image.extent.depth = slicesLayers;
4184 params2DTo3D.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4185 params2DTo3D.allocationKind = allocationKind;
4187 for (deUint32 slicesLayersNdx = 0; slicesLayersNdx < slicesLayers; ++slicesLayersNdx)
4189 const VkImageSubresourceLayers sourceLayer =
4191 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4192 0u, // uint32_t mipLevel;
4193 slicesLayersNdx, // uint32_t baseArrayLayer;
4194 1u // uint32_t layerCount;
4197 const VkImageSubresourceLayers destinationLayer =
4199 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4200 0u, // uint32_t mipLevel;
4201 0u, // uint32_t baseArrayLayer;
4202 1u // uint32_t layerCount;
4205 const VkImageCopy testCopy =
4207 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4208 {0, 0, 0}, // VkOffset3D srcOffset;
4209 destinationLayer, // VkImageSubresourceLayers dstSubresource;
4210 {0, 0, (deInt32)slicesLayersNdx}, // VkOffset3D dstOffset;
4211 defaultHalfExtent, // VkExtent3D extent;
4214 CopyRegion imageCopy;
4215 imageCopy.imageCopy = testCopy;
4217 params2DTo3D.regions.push_back(imageCopy);
4220 group->addChild(new CopyImageToImageTestCase(testCtx, "2d_to_3d_by_layers", "copy 3d slices to 2d layers one by one", params2DTo3D));
4224 TestParams params3DTo2D;
4225 const deUint32 slicesLayers = 16u;
4226 params3DTo2D.src.image.imageType = VK_IMAGE_TYPE_3D;
4227 params3DTo2D.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
4228 params3DTo2D.src.image.extent = defaultHalfExtent;
4229 params3DTo2D.src.image.extent.depth = slicesLayers;
4230 params3DTo2D.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4231 params3DTo2D.dst.image.imageType = VK_IMAGE_TYPE_2D;
4232 params3DTo2D.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
4233 params3DTo2D.dst.image.extent = defaultHalfExtent;
4234 params3DTo2D.dst.image.extent.depth = slicesLayers;
4235 params3DTo2D.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4236 params3DTo2D.allocationKind = allocationKind;
4238 for (deUint32 slicesLayersNdx = 0; slicesLayersNdx < slicesLayers; ++slicesLayersNdx)
4240 const VkImageSubresourceLayers sourceLayer =
4242 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4243 0u, // uint32_t mipLevel;
4244 0u, // uint32_t baseArrayLayer;
4245 1u // uint32_t layerCount;
4248 const VkImageSubresourceLayers destinationLayer =
4250 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4251 0u, // uint32_t mipLevel;
4252 0, // uint32_t baseArrayLayer;
4253 slicesLayers // uint32_t layerCount;
4256 const VkImageCopy testCopy =
4258 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4259 {0, 0, 0}, // VkOffset3D srcOffset;
4260 destinationLayer, // VkImageSubresourceLayers dstSubresource;
4261 {0, 0, 0}, // VkOffset3D dstOffset;
4262 params3DTo2D.src.image.extent // VkExtent3D extent;
4265 CopyRegion imageCopy;
4266 imageCopy.imageCopy = testCopy;
4268 params3DTo2D.regions.push_back(imageCopy);
4270 group->addChild(new CopyImageToImageTestCase(testCtx, "3d_to_2d_whole", "copy 3d slices to 2d layers all at once", params3DTo2D));
4274 TestParams params2DTo3D;
4275 const deUint32 slicesLayers = 16u;
4276 params2DTo3D.src.image.imageType = VK_IMAGE_TYPE_2D;
4277 params2DTo3D.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
4278 params2DTo3D.src.image.extent = defaultHalfExtent;
4279 params2DTo3D.src.image.extent.depth = slicesLayers;
4280 params2DTo3D.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4281 params2DTo3D.dst.image.imageType = VK_IMAGE_TYPE_3D;
4282 params2DTo3D.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
4283 params2DTo3D.dst.image.extent = defaultHalfExtent;
4284 params2DTo3D.dst.image.extent.depth = slicesLayers;
4285 params2DTo3D.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4286 params2DTo3D.allocationKind = allocationKind;
4289 const VkImageSubresourceLayers sourceLayer =
4291 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4292 0u, // uint32_t mipLevel;
4293 0u, // uint32_t baseArrayLayer;
4294 slicesLayers // uint32_t layerCount;
4297 const VkImageSubresourceLayers destinationLayer =
4299 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4300 0u, // uint32_t mipLevel;
4301 0u, // uint32_t baseArrayLayer;
4302 1u // uint32_t layerCount;
4305 const VkImageCopy testCopy =
4307 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4308 {0, 0, 0}, // VkOffset3D srcOffset;
4309 destinationLayer, // VkImageSubresourceLayers dstSubresource;
4310 {0, 0, 0}, // VkOffset3D dstOffset;
4311 params2DTo3D.dst.image.extent, // VkExtent3D extent;
4314 CopyRegion imageCopy;
4315 imageCopy.imageCopy = testCopy;
4317 params2DTo3D.regions.push_back(imageCopy);
4320 group->addChild(new CopyImageToImageTestCase(testCtx, "2d_to_3d_whole", "copy 2d layers to 3d slices all at once", params2DTo3D));
4324 TestParams params3DTo2D;
4325 const deUint32 slicesLayers = 16u;
4326 params3DTo2D.src.image.imageType = VK_IMAGE_TYPE_3D;
4327 params3DTo2D.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
4328 params3DTo2D.src.image.extent = defaultHalfExtent;
4329 params3DTo2D.src.image.extent.depth = slicesLayers;
4330 params3DTo2D.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4331 params3DTo2D.dst.image.imageType = VK_IMAGE_TYPE_2D;
4332 params3DTo2D.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
4333 params3DTo2D.dst.image.extent = defaultHalfExtent;
4334 params3DTo2D.dst.image.extent.depth = slicesLayers;
4335 params3DTo2D.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4336 params3DTo2D.allocationKind = allocationKind;
4338 const deUint32 regionWidth = defaultHalfExtent.width / slicesLayers -1;
4339 const deUint32 regionHeight = defaultHalfExtent.height / slicesLayers -1 ;
4341 for (deUint32 slicesLayersNdx = 0; slicesLayersNdx < slicesLayers; ++slicesLayersNdx)
4343 const VkImageSubresourceLayers sourceLayer =
4345 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4346 0u, // uint32_t mipLevel;
4347 0u, // uint32_t baseArrayLayer;
4348 1u // uint32_t layerCount;
4351 const VkImageSubresourceLayers destinationLayer =
4353 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4354 0u, // uint32_t mipLevel;
4355 slicesLayersNdx, // uint32_t baseArrayLayer;
4356 1u // uint32_t layerCount;
4360 const VkImageCopy testCopy =
4362 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4363 {0, (deInt32)(regionHeight*slicesLayersNdx), (deInt32)slicesLayersNdx}, // VkOffset3D srcOffset;
4364 destinationLayer, // VkImageSubresourceLayers dstSubresource;
4365 {(deInt32)(regionWidth*slicesLayersNdx), 0, 0}, // VkOffset3D dstOffset;
4367 (defaultHalfExtent.width - regionWidth*slicesLayersNdx),
4368 (defaultHalfExtent.height - regionHeight*slicesLayersNdx),
4370 } // VkExtent3D extent;
4373 CopyRegion imageCopy;
4374 imageCopy.imageCopy = testCopy;
4375 params3DTo2D.regions.push_back(imageCopy);
4377 group->addChild(new CopyImageToImageTestCase(testCtx, "3d_to_2d_regions", "copy 3d slices regions to 2d layers", params3DTo2D));
4381 TestParams params2DTo3D;
4382 const deUint32 slicesLayers = 16u;
4383 params2DTo3D.src.image.imageType = VK_IMAGE_TYPE_2D;
4384 params2DTo3D.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
4385 params2DTo3D.src.image.extent = defaultHalfExtent;
4386 params2DTo3D.src.image.extent.depth = slicesLayers;
4387 params2DTo3D.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4388 params2DTo3D.dst.image.imageType = VK_IMAGE_TYPE_3D;
4389 params2DTo3D.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
4390 params2DTo3D.dst.image.extent = defaultHalfExtent;
4391 params2DTo3D.dst.image.extent.depth = slicesLayers;
4392 params2DTo3D.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4393 params2DTo3D.allocationKind = allocationKind;
4395 const deUint32 regionWidth = defaultHalfExtent.width / slicesLayers -1;
4396 const deUint32 regionHeight = defaultHalfExtent.height / slicesLayers -1 ;
4398 for (deUint32 slicesLayersNdx = 0; slicesLayersNdx < slicesLayers; ++slicesLayersNdx)
4400 const VkImageSubresourceLayers sourceLayer =
4402 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4403 0u, // uint32_t mipLevel;
4404 slicesLayersNdx, // uint32_t baseArrayLayer;
4405 1u // uint32_t layerCount;
4408 const VkImageSubresourceLayers destinationLayer =
4410 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4411 0u, // uint32_t mipLevel;
4412 0u, // uint32_t baseArrayLayer;
4413 1u // uint32_t layerCount;
4416 const VkImageCopy testCopy =
4418 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4419 {(deInt32)(regionWidth*slicesLayersNdx), 0, 0}, // VkOffset3D srcOffset;
4420 destinationLayer, // VkImageSubresourceLayers dstSubresource;
4421 {0, (deInt32)(regionHeight*slicesLayersNdx), (deInt32)(slicesLayersNdx)}, // VkOffset3D dstOffset;
4423 defaultHalfExtent.width - regionWidth*slicesLayersNdx,
4424 defaultHalfExtent.height - regionHeight*slicesLayersNdx,
4426 } // VkExtent3D extent;
4429 CopyRegion imageCopy;
4430 imageCopy.imageCopy = testCopy;
4432 params2DTo3D.regions.push_back(imageCopy);
4435 group->addChild(new CopyImageToImageTestCase(testCtx, "2d_to_3d_regions", "copy 2d layers regions to 3d slices", params2DTo3D));
4439 void addImageToImageTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4441 addTestGroup(group, "simple_tests", "Copy from image to image simple tests", addImageToImageSimpleTests, allocationKind);
4442 addTestGroup(group, "all_formats", "Copy from image to image with all compatible formats", addImageToImageAllFormatsTests, allocationKind);
4443 addTestGroup(group, "3d_images", "Coping operations on 3d images", addImageToImage3dImagesTests, allocationKind);
4446 void addImageToBufferTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4448 tcu::TestContext& testCtx = group->getTestContext();
4452 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4453 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4454 params.src.image.extent = defaultExtent;
4455 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4456 params.dst.buffer.size = defaultSize * defaultSize;
4457 params.allocationKind = allocationKind;
4459 const VkBufferImageCopy bufferImageCopy =
4461 0u, // VkDeviceSize bufferOffset;
4462 0u, // uint32_t bufferRowLength;
4463 0u, // uint32_t bufferImageHeight;
4464 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
4465 {0, 0, 0}, // VkOffset3D imageOffset;
4466 defaultExtent // VkExtent3D imageExtent;
4468 CopyRegion copyRegion;
4469 copyRegion.bufferImageCopy = bufferImageCopy;
4471 params.regions.push_back(copyRegion);
4473 group->addChild(new CopyImageToBufferTestCase(testCtx, "whole", "Copy from image to buffer", params));
4478 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4479 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4480 params.src.image.extent = defaultExtent;
4481 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4482 params.dst.buffer.size = defaultSize * defaultSize;
4483 params.allocationKind = allocationKind;
4485 const VkBufferImageCopy bufferImageCopy =
4487 defaultSize * defaultHalfSize, // VkDeviceSize bufferOffset;
4488 0u, // uint32_t bufferRowLength;
4489 0u, // uint32_t bufferImageHeight;
4490 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
4491 {defaultFourthSize, defaultFourthSize, 0}, // VkOffset3D imageOffset;
4492 defaultHalfExtent // VkExtent3D imageExtent;
4494 CopyRegion copyRegion;
4495 copyRegion.bufferImageCopy = bufferImageCopy;
4497 params.regions.push_back(copyRegion);
4499 group->addChild(new CopyImageToBufferTestCase(testCtx, "buffer_offset", "Copy from image to buffer with buffer offset", params));
4504 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4505 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4506 params.src.image.extent = defaultExtent;
4507 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4508 params.dst.buffer.size = defaultSize * defaultSize;
4509 params.allocationKind = allocationKind;
4511 const int pixelSize = tcu::getPixelSize(mapVkFormat(params.src.image.format));
4512 const VkDeviceSize bufferSize = pixelSize * params.dst.buffer.size;
4513 const VkDeviceSize offsetSize = pixelSize * defaultFourthSize * defaultFourthSize;
4514 deUint32 divisor = 1;
4515 for (VkDeviceSize offset = 0; offset < bufferSize - offsetSize; offset += offsetSize, ++divisor)
4517 const deUint32 bufferRowLength = defaultFourthSize;
4518 const deUint32 bufferImageHeight = defaultFourthSize;
4519 const VkExtent3D imageExtent = {defaultFourthSize / divisor, defaultFourthSize, 1};
4520 DE_ASSERT(!bufferRowLength || bufferRowLength >= imageExtent.width);
4521 DE_ASSERT(!bufferImageHeight || bufferImageHeight >= imageExtent.height);
4522 DE_ASSERT(imageExtent.width * imageExtent.height *imageExtent.depth <= offsetSize);
4525 const VkBufferImageCopy bufferImageCopy =
4527 offset, // VkDeviceSize bufferOffset;
4528 bufferRowLength, // uint32_t bufferRowLength;
4529 bufferImageHeight, // uint32_t bufferImageHeight;
4530 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
4531 {0, 0, 0}, // VkOffset3D imageOffset;
4532 imageExtent // VkExtent3D imageExtent;
4534 region.bufferImageCopy = bufferImageCopy;
4535 params.regions.push_back(region);
4538 group->addChild(new CopyImageToBufferTestCase(testCtx, "regions", "Copy from image to buffer with multiple regions", params));
4542 void addBufferToImageTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4544 tcu::TestContext& testCtx = group->getTestContext();
4548 params.src.buffer.size = defaultSize * defaultSize;
4549 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4550 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
4551 params.dst.image.extent = defaultExtent;
4552 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4553 params.allocationKind = allocationKind;
4555 const VkBufferImageCopy bufferImageCopy =
4557 0u, // VkDeviceSize bufferOffset;
4558 0u, // uint32_t bufferRowLength;
4559 0u, // uint32_t bufferImageHeight;
4560 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
4561 {0, 0, 0}, // VkOffset3D imageOffset;
4562 defaultExtent // VkExtent3D imageExtent;
4564 CopyRegion copyRegion;
4565 copyRegion.bufferImageCopy = bufferImageCopy;
4567 params.regions.push_back(copyRegion);
4569 group->addChild(new CopyBufferToImageTestCase(testCtx, "whole", "Copy from buffer to image", params));
4574 params.src.buffer.size = defaultSize * defaultSize;
4575 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4576 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4577 params.dst.image.extent = defaultExtent;
4578 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4579 params.allocationKind = allocationKind;
4582 deUint32 divisor = 1;
4583 for (int offset = 0; (offset + defaultFourthSize / divisor < defaultSize) && (defaultFourthSize > divisor); offset += defaultFourthSize / divisor++)
4585 const VkBufferImageCopy bufferImageCopy =
4587 0u, // VkDeviceSize bufferOffset;
4588 0u, // uint32_t bufferRowLength;
4589 0u, // uint32_t bufferImageHeight;
4590 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
4591 {offset, defaultHalfSize, 0}, // VkOffset3D imageOffset;
4592 {defaultFourthSize / divisor, defaultFourthSize / divisor, 1} // VkExtent3D imageExtent;
4594 region.bufferImageCopy = bufferImageCopy;
4595 params.regions.push_back(region);
4598 group->addChild(new CopyBufferToImageTestCase(testCtx, "regions", "Copy from buffer to image with multiple regions", params));
4603 params.src.buffer.size = defaultSize * defaultSize;
4604 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4605 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4606 params.dst.image.extent = defaultExtent;
4607 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4608 params.allocationKind = allocationKind;
4610 const VkBufferImageCopy bufferImageCopy =
4612 defaultFourthSize, // VkDeviceSize bufferOffset;
4613 defaultHalfSize + defaultFourthSize, // uint32_t bufferRowLength;
4614 defaultHalfSize + defaultFourthSize, // uint32_t bufferImageHeight;
4615 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
4616 {defaultFourthSize, defaultFourthSize, 0}, // VkOffset3D imageOffset;
4617 defaultHalfExtent // VkExtent3D imageExtent;
4619 CopyRegion copyRegion;
4620 copyRegion.bufferImageCopy = bufferImageCopy;
4622 params.regions.push_back(copyRegion);
4624 group->addChild(new CopyBufferToImageTestCase(testCtx, "buffer_offset", "Copy from buffer to image with buffer offset", params));
4628 void addBufferToBufferTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4630 tcu::TestContext& testCtx = group->getTestContext();
4634 params.src.buffer.size = defaultSize;
4635 params.dst.buffer.size = defaultSize;
4636 params.allocationKind = allocationKind;
4638 const VkBufferCopy bufferCopy =
4640 0u, // VkDeviceSize srcOffset;
4641 0u, // VkDeviceSize dstOffset;
4642 defaultSize, // VkDeviceSize size;
4645 CopyRegion copyRegion;
4646 copyRegion.bufferCopy = bufferCopy;
4647 params.regions.push_back(copyRegion);
4649 group->addChild(new BufferToBufferTestCase(testCtx, "whole", "Whole buffer", params));
4652 // Filter is VK_FILTER_NEAREST.
4655 params.src.buffer.size = defaultFourthSize;
4656 params.dst.buffer.size = defaultFourthSize;
4657 params.allocationKind = allocationKind;
4659 const VkBufferCopy bufferCopy =
4661 12u, // VkDeviceSize srcOffset;
4662 4u, // VkDeviceSize dstOffset;
4663 1u, // VkDeviceSize size;
4666 CopyRegion copyRegion;
4667 copyRegion.bufferCopy = bufferCopy;
4668 params.regions.push_back(copyRegion);
4670 group->addChild(new BufferToBufferTestCase(testCtx, "partial", "Partial", params));
4674 const deUint32 size = 16;
4676 params.src.buffer.size = size;
4677 params.dst.buffer.size = size * (size + 1);
4678 params.allocationKind = allocationKind;
4680 // Copy region with size 1..size
4681 for (unsigned int i = 1; i <= size; i++)
4683 const VkBufferCopy bufferCopy =
4685 0, // VkDeviceSize srcOffset;
4686 i * size, // VkDeviceSize dstOffset;
4687 i, // VkDeviceSize size;
4690 CopyRegion copyRegion;
4691 copyRegion.bufferCopy = bufferCopy;
4692 params.regions.push_back(copyRegion);
4695 group->addChild(new BufferToBufferTestCase(testCtx, "regions", "Multiple regions", params));
4699 void addBlittingImageSimpleWholeTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4701 tcu::TestContext& testCtx = group->getTestContext();
4703 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4704 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4705 params.src.image.extent = defaultExtent;
4706 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4707 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4708 params.dst.image.extent = defaultExtent;
4709 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4710 params.allocationKind = allocationKind;
4713 const VkImageBlit imageBlit =
4715 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
4718 { defaultSize, defaultSize, 1 }
4719 }, // VkOffset3D srcOffsets[2];
4721 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
4724 { defaultSize, defaultSize, 1 }
4725 } // VkOffset3D dstOffset[2];
4729 region.imageBlit = imageBlit;
4730 params.regions.push_back(region);
4733 // Filter is VK_FILTER_NEAREST.
4735 params.filter = VK_FILTER_NEAREST;
4736 const std::string description = "Nearest filter";
4738 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4739 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
4741 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4742 const std::string descriptionOfRGBAToR32(description + " and different formats (R8G8B8A8 -> R32)");
4743 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
4745 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4746 const std::string descriptionOfRGBAToBGRA(description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4747 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
4750 // Filter is VK_FILTER_LINEAR.
4752 params.filter = VK_FILTER_LINEAR;
4753 const std::string description = "Linear filter";
4755 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4756 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
4758 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4759 const std::string descriptionOfRGBAToR32(description + " and different formats (R8G8B8A8 -> R32)");
4760 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
4762 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4763 const std::string descriptionOfRGBAToBGRA(description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4764 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
4768 void addBlittingImageSimpleMirrorXYTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4770 tcu::TestContext& testCtx = group->getTestContext();
4772 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4773 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4774 params.src.image.extent = defaultExtent;
4775 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4776 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4777 params.dst.image.extent = defaultExtent;
4778 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4779 params.allocationKind = allocationKind;
4782 const VkImageBlit imageBlit =
4784 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
4787 {defaultSize, defaultSize, 1}
4788 }, // VkOffset3D srcOffsets[2];
4790 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
4792 {defaultSize, defaultSize, 0},
4794 } // VkOffset3D dstOffset[2];
4798 region.imageBlit = imageBlit;
4799 params.regions.push_back(region);
4802 // Filter is VK_FILTER_NEAREST.
4804 params.filter = VK_FILTER_NEAREST;
4805 const std::string description = "Nearest filter";
4807 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4808 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
4810 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4811 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
4812 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
4814 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4815 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4816 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
4819 // Filter is VK_FILTER_LINEAR.
4821 params.filter = VK_FILTER_LINEAR;
4822 const std::string description = "Linear filter";
4824 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4825 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
4827 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4828 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
4829 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
4831 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4832 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4833 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
4837 void addBlittingImageSimpleMirrorXTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4839 tcu::TestContext& testCtx = group->getTestContext();
4841 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4842 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4843 params.src.image.extent = defaultExtent;
4844 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4845 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4846 params.dst.image.extent = defaultExtent;
4847 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4848 params.allocationKind = allocationKind;
4851 const VkImageBlit imageBlit =
4853 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
4856 {defaultSize, defaultSize, 1}
4857 }, // VkOffset3D srcOffsets[2];
4859 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
4861 {defaultSize, 0, 0},
4863 } // VkOffset3D dstOffset[2];
4867 region.imageBlit = imageBlit;
4868 params.regions.push_back(region);
4871 // Filter is VK_FILTER_NEAREST.
4873 params.filter = VK_FILTER_NEAREST;
4874 const std::string description = "Nearest filter";
4876 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4877 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
4879 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4880 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
4881 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
4883 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4884 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4885 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
4888 // Filter is VK_FILTER_LINEAR.
4890 params.filter = VK_FILTER_LINEAR;
4891 const std::string description = "Linear filter";
4893 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4894 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
4896 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4897 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
4898 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
4900 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4901 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4902 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
4906 void addBlittingImageSimpleMirrorYTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4908 tcu::TestContext& testCtx = group->getTestContext();
4910 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4911 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4912 params.src.image.extent = defaultExtent;
4913 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4914 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4915 params.dst.image.extent = defaultExtent;
4916 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4917 params.allocationKind = allocationKind;
4920 const VkImageBlit imageBlit =
4922 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
4925 {defaultSize, defaultSize, 1}
4926 }, // VkOffset3D srcOffsets[2];
4928 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
4930 {0, defaultSize, 0},
4932 } // VkOffset3D dstOffset[2];
4936 region.imageBlit = imageBlit;
4937 params.regions.push_back(region);
4940 // Filter is VK_FILTER_NEAREST.
4942 params.filter = VK_FILTER_NEAREST;
4943 const std::string description = "Nearest filter";
4945 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4946 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
4948 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4949 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
4950 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
4952 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4953 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4954 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
4957 // Filter is VK_FILTER_LINEAR.
4959 params.filter = VK_FILTER_LINEAR;
4960 const std::string description = "Linear filter";
4962 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4963 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
4965 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
4966 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
4967 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
4969 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
4970 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
4971 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
4975 void addBlittingImageSimpleMirrorSubregionsTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
4977 tcu::TestContext& testCtx = group->getTestContext();
4979 params.src.image.imageType = VK_IMAGE_TYPE_2D;
4980 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4981 params.src.image.extent = defaultExtent;
4982 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
4983 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
4984 params.dst.image.extent = defaultExtent;
4985 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
4986 params.allocationKind = allocationKind;
4990 const VkImageBlit imageBlit =
4992 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
4995 {defaultHalfSize, defaultHalfSize, 1}
4996 }, // VkOffset3D srcOffsets[2];
4998 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5001 {defaultHalfSize, defaultHalfSize, 1}
5002 } // VkOffset3D dstOffset[2];
5006 region.imageBlit = imageBlit;
5007 params.regions.push_back(region);
5010 // Flipping y coordinates.
5012 const VkImageBlit imageBlit =
5014 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5016 {defaultHalfSize, 0, 0},
5017 {defaultSize, defaultHalfSize, 1}
5018 }, // VkOffset3D srcOffsets[2];
5020 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5022 {defaultHalfSize, defaultHalfSize, 0},
5024 } // VkOffset3D dstOffset[2];
5027 region.imageBlit = imageBlit;
5028 params.regions.push_back(region);
5031 // Flipping x coordinates.
5033 const VkImageBlit imageBlit =
5035 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5037 {0, defaultHalfSize, 0},
5038 {defaultHalfSize, defaultSize, 1}
5039 }, // VkOffset3D srcOffsets[2];
5041 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5043 {defaultHalfSize, defaultHalfSize, 0},
5045 } // VkOffset3D dstOffset[2];
5049 region.imageBlit = imageBlit;
5050 params.regions.push_back(region);
5053 // Flipping x and y coordinates.
5055 const VkImageBlit imageBlit =
5057 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5059 {defaultHalfSize, defaultHalfSize, 0},
5060 {defaultSize, defaultSize, 1}
5061 }, // VkOffset3D srcOffsets[2];
5063 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5065 {defaultSize, defaultSize, 0},
5066 {defaultHalfSize, defaultHalfSize, 1}
5067 } // VkOffset3D dstOffset[2];
5071 region.imageBlit = imageBlit;
5072 params.regions.push_back(region);
5075 // Filter is VK_FILTER_NEAREST.
5077 params.filter = VK_FILTER_NEAREST;
5078 const std::string description = "Nearest filter";
5080 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5081 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
5083 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5084 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5085 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
5087 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5088 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5089 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
5092 // Filter is VK_FILTER_LINEAR.
5094 params.filter = VK_FILTER_LINEAR;
5095 const std::string description = "Linear filter";
5097 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5098 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
5100 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5101 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5102 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
5104 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5105 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5106 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
5110 void addBlittingImageSimpleScalingWhole1Tests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5112 tcu::TestContext& testCtx = group->getTestContext();
5114 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5115 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5116 params.src.image.extent = defaultExtent;
5117 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5118 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5119 params.dst.image.extent = defaultHalfExtent;
5120 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
5121 params.allocationKind = allocationKind;
5124 const VkImageBlit imageBlit =
5126 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5129 {defaultSize, defaultSize, 1}
5130 }, // VkOffset3D srcOffsets[2];
5132 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5135 {defaultHalfSize, defaultHalfSize, 1}
5136 } // VkOffset3D dstOffset[2];
5140 region.imageBlit = imageBlit;
5141 params.regions.push_back(region);
5144 // Filter is VK_FILTER_NEAREST.
5146 params.filter = VK_FILTER_NEAREST;
5147 const std::string description = "Nearest filter";
5149 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5150 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
5152 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5153 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5154 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
5156 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5157 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5158 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
5161 // Filter is VK_FILTER_LINEAR.
5163 params.filter = VK_FILTER_LINEAR;
5164 const std::string description = "Linear filter";
5166 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5167 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
5169 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5170 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" );
5171 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
5173 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5174 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5175 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
5179 void addBlittingImageSimpleScalingWhole2Tests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5181 tcu::TestContext& testCtx = group->getTestContext();
5183 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5184 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5185 params.src.image.extent = defaultHalfExtent;
5186 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5187 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5188 params.dst.image.extent = defaultExtent;
5189 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
5190 params.allocationKind = allocationKind;
5193 const VkImageBlit imageBlit =
5195 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5198 {defaultHalfSize, defaultHalfSize, 1}
5199 }, // VkOffset3D srcOffsets[2];
5201 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5204 {defaultSize, defaultSize, 1}
5205 } // VkOffset3D dstOffset[2];
5209 region.imageBlit = imageBlit;
5210 params.regions.push_back(region);
5213 // Filter is VK_FILTER_NEAREST.
5215 params.filter = VK_FILTER_NEAREST;
5216 const std::string description = "Nearest filter";
5218 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5219 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
5221 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5222 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5223 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
5225 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5226 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5227 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
5230 // Filter is VK_FILTER_LINEAR.
5232 params.filter = VK_FILTER_LINEAR;
5233 const std::string description = "Linear filter";
5235 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5236 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
5238 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5239 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5240 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
5242 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5243 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5244 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
5248 void addBlittingImageSimpleScalingAndOffsetTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5250 tcu::TestContext& testCtx = group->getTestContext();
5252 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5253 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5254 params.src.image.extent = defaultExtent;
5255 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5256 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5257 params.dst.image.extent = defaultExtent;
5258 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
5259 params.allocationKind = allocationKind;
5262 const VkImageBlit imageBlit =
5264 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5266 {defaultFourthSize, defaultFourthSize, 0},
5267 {defaultFourthSize*3, defaultFourthSize*3, 1}
5268 }, // VkOffset3D srcOffsets[2];
5270 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5273 {defaultSize, defaultSize, 1}
5274 } // VkOffset3D dstOffset[2];
5278 region.imageBlit = imageBlit;
5279 params.regions.push_back(region);
5282 // Filter is VK_FILTER_NEAREST.
5284 params.filter = VK_FILTER_NEAREST;
5285 const std::string description = "Nearest filter";
5287 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5288 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
5290 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5291 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5292 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
5294 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5295 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5296 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
5299 // Filter is VK_FILTER_LINEAR.
5301 params.filter = VK_FILTER_LINEAR;
5302 const std::string description = "Linear filter";
5304 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5305 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
5307 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5308 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5309 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
5311 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5312 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5313 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
5317 void addBlittingImageSimpleWithoutScalingPartialTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5319 tcu::TestContext& testCtx = group->getTestContext();
5321 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5322 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5323 params.src.image.extent = defaultExtent;
5324 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5325 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5326 params.dst.image.extent = defaultExtent;
5327 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
5328 params.allocationKind = allocationKind;
5332 for (int i = 0; i < defaultSize; i += defaultFourthSize)
5334 const VkImageBlit imageBlit =
5336 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5338 {defaultSize - defaultFourthSize - i, defaultSize - defaultFourthSize - i, 0},
5339 {defaultSize - i, defaultSize - i, 1}
5340 }, // VkOffset3D srcOffsets[2];
5342 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5345 {i + defaultFourthSize, i + defaultFourthSize, 1}
5346 } // VkOffset3D dstOffset[2];
5348 region.imageBlit = imageBlit;
5349 params.regions.push_back(region);
5353 // Filter is VK_FILTER_NEAREST.
5355 params.filter = VK_FILTER_NEAREST;
5356 const std::string description = "Nearest filter";
5358 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5359 group->addChild(new BlittingTestCase(testCtx, "nearest", description, params));
5362 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5363 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5364 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
5366 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5367 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5368 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
5371 // Filter is VK_FILTER_LINEAR.
5373 params.filter = VK_FILTER_LINEAR;
5374 const std::string description = "Linear filter";
5376 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5377 group->addChild(new BlittingTestCase(testCtx, "linear", description, params));
5379 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
5380 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
5381 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
5383 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
5384 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
5385 group->addChild(new BlittingTestCase(testCtx, getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
5389 void addBlittingImageSimpleTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5391 addTestGroup(group, "whole", "Blit without scaling (whole)", addBlittingImageSimpleWholeTests, allocationKind);
5392 addTestGroup(group, "mirror_xy", "Flipping x and y coordinates (whole)", addBlittingImageSimpleMirrorXYTests, allocationKind);
5393 addTestGroup(group, "mirror_x", "Flipping x coordinates (whole)", addBlittingImageSimpleMirrorXTests, allocationKind);
5394 addTestGroup(group, "mirror_y", "Flipping y coordinates (whole)", addBlittingImageSimpleMirrorYTests, allocationKind);
5395 addTestGroup(group, "mirror_subregions", "Mirroring subregions in image (no flip, y flip, x flip, xy flip)", addBlittingImageSimpleMirrorSubregionsTests, allocationKind);
5396 addTestGroup(group, "scaling_whole1", "Blit with scaling (whole, src extent bigger)", addBlittingImageSimpleScalingWhole1Tests, allocationKind);
5397 addTestGroup(group, "scaling_whole2", "Blit with scaling (whole, dst extent bigger)", addBlittingImageSimpleScalingWhole2Tests, allocationKind);
5398 addTestGroup(group, "scaling_and_offset", "Blit with scaling and offset (whole, dst extent bigger)", addBlittingImageSimpleScalingAndOffsetTests, allocationKind);
5399 addTestGroup(group, "without_scaling_partial", "Blit without scaling (partial)", addBlittingImageSimpleWithoutScalingPartialTests, allocationKind);
5402 struct BlitColorTestParams
5405 const VkFormat* compatibleFormats;
5409 bool isAllowedBlittingAllFormatsColorSrcFormatTests(const BlitColorTestParams& testParams)
5413 if (testParams.params.allocationKind == ALLOCATION_KIND_DEDICATED)
5415 DE_ASSERT(!dedicatedAllocationBlittingFormatsToTestSet.empty());
5418 de::contains(dedicatedAllocationBlittingFormatsToTestSet, testParams.params.dst.image.format) ||
5419 de::contains(dedicatedAllocationBlittingFormatsToTestSet, testParams.params.src.image.format);
5426 void addBlittingImageAllFormatsColorSrcFormatDstFormatTests (tcu::TestCaseGroup* group, BlitColorTestParams testParams)
5428 tcu::TestContext& testCtx = group->getTestContext();
5430 const VkImageLayout blitSrcLayouts[] =
5432 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5433 VK_IMAGE_LAYOUT_GENERAL
5435 const VkImageLayout blitDstLayouts[] =
5437 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
5438 VK_IMAGE_LAYOUT_GENERAL
5441 for (int srcLayoutNdx = 0u; srcLayoutNdx < DE_LENGTH_OF_ARRAY(blitSrcLayouts); ++srcLayoutNdx)
5443 testParams.params.src.image.operationLayout = blitSrcLayouts[srcLayoutNdx];
5444 for (int dstLayoutNdx = 0u; dstLayoutNdx < DE_LENGTH_OF_ARRAY(blitDstLayouts); ++dstLayoutNdx)
5446 testParams.params.dst.image.operationLayout = blitDstLayouts[dstLayoutNdx];
5448 testParams.params.filter = VK_FILTER_NEAREST;
5449 const std::string testName = getImageLayoutCaseName(testParams.params.src.image.operationLayout) + "_" +
5450 getImageLayoutCaseName(testParams.params.dst.image.operationLayout);
5451 const std::string description = "Blit from layout " + getImageLayoutCaseName(testParams.params.src.image.operationLayout) +
5452 " to " + getImageLayoutCaseName(testParams.params.dst.image.operationLayout);
5453 group->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, testParams.params));
5455 if (!testParams.onlyNearest)
5457 testParams.params.filter = VK_FILTER_LINEAR;
5458 group->addChild(new BlittingTestCase(testCtx, testName + "_linear", description, testParams.params));
5464 void addBlittingImageAllFormatsColorSrcFormatTests (tcu::TestCaseGroup* group, BlitColorTestParams testParams)
5466 for (int dstFormatIndex = 0; testParams.compatibleFormats[dstFormatIndex] != VK_FORMAT_UNDEFINED; ++dstFormatIndex)
5468 testParams.params.dst.image.format = testParams.compatibleFormats[dstFormatIndex];
5469 if (!isSupportedByFramework(testParams.params.dst.image.format))
5472 if (!isAllowedBlittingAllFormatsColorSrcFormatTests(testParams))
5475 const std::string description = "Blit destination format " + getFormatCaseName(testParams.params.dst.image.format);
5476 addTestGroup(group, getFormatCaseName(testParams.params.dst.image.format), description, addBlittingImageAllFormatsColorSrcFormatDstFormatTests, testParams);
5480 const VkFormat compatibleFormatsUInts[] =
5483 VK_FORMAT_R8G8_UINT,
5484 VK_FORMAT_R8G8B8_UINT,
5485 VK_FORMAT_B8G8R8_UINT,
5486 VK_FORMAT_R8G8B8A8_UINT,
5487 VK_FORMAT_B8G8R8A8_UINT,
5488 VK_FORMAT_A8B8G8R8_UINT_PACK32,
5489 VK_FORMAT_A2R10G10B10_UINT_PACK32,
5490 VK_FORMAT_A2B10G10R10_UINT_PACK32,
5492 VK_FORMAT_R16G16_UINT,
5493 VK_FORMAT_R16G16B16_UINT,
5494 VK_FORMAT_R16G16B16A16_UINT,
5496 VK_FORMAT_R32G32_UINT,
5497 VK_FORMAT_R32G32B32_UINT,
5498 VK_FORMAT_R32G32B32A32_UINT,
5500 VK_FORMAT_R64G64_UINT,
5501 VK_FORMAT_R64G64B64_UINT,
5502 VK_FORMAT_R64G64B64A64_UINT,
5506 const VkFormat compatibleFormatsSInts[] =
5509 VK_FORMAT_R8G8_SINT,
5510 VK_FORMAT_R8G8B8_SINT,
5511 VK_FORMAT_B8G8R8_SINT,
5512 VK_FORMAT_R8G8B8A8_SINT,
5513 VK_FORMAT_B8G8R8A8_SINT,
5514 VK_FORMAT_A8B8G8R8_SINT_PACK32,
5515 VK_FORMAT_A2R10G10B10_SINT_PACK32,
5516 VK_FORMAT_A2B10G10R10_SINT_PACK32,
5518 VK_FORMAT_R16G16_SINT,
5519 VK_FORMAT_R16G16B16_SINT,
5520 VK_FORMAT_R16G16B16A16_SINT,
5522 VK_FORMAT_R32G32_SINT,
5523 VK_FORMAT_R32G32B32_SINT,
5524 VK_FORMAT_R32G32B32A32_SINT,
5526 VK_FORMAT_R64G64_SINT,
5527 VK_FORMAT_R64G64B64_SINT,
5528 VK_FORMAT_R64G64B64A64_SINT,
5532 const VkFormat compatibleFormatsFloats[] =
5534 VK_FORMAT_R4G4_UNORM_PACK8,
5535 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
5536 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
5537 VK_FORMAT_R5G6B5_UNORM_PACK16,
5538 VK_FORMAT_B5G6R5_UNORM_PACK16,
5539 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
5540 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
5541 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
5544 VK_FORMAT_R8_USCALED,
5545 VK_FORMAT_R8_SSCALED,
5546 VK_FORMAT_R8G8_UNORM,
5547 VK_FORMAT_R8G8_SNORM,
5548 VK_FORMAT_R8G8_USCALED,
5549 VK_FORMAT_R8G8_SSCALED,
5550 VK_FORMAT_R8G8B8_UNORM,
5551 VK_FORMAT_R8G8B8_SNORM,
5552 VK_FORMAT_R8G8B8_USCALED,
5553 VK_FORMAT_R8G8B8_SSCALED,
5554 VK_FORMAT_B8G8R8_UNORM,
5555 VK_FORMAT_B8G8R8_SNORM,
5556 VK_FORMAT_B8G8R8_USCALED,
5557 VK_FORMAT_B8G8R8_SSCALED,
5558 VK_FORMAT_R8G8B8A8_UNORM,
5559 VK_FORMAT_R8G8B8A8_SNORM,
5560 VK_FORMAT_R8G8B8A8_USCALED,
5561 VK_FORMAT_R8G8B8A8_SSCALED,
5562 VK_FORMAT_B8G8R8A8_UNORM,
5563 VK_FORMAT_B8G8R8A8_SNORM,
5564 VK_FORMAT_B8G8R8A8_USCALED,
5565 VK_FORMAT_B8G8R8A8_SSCALED,
5566 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
5567 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
5568 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
5569 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
5570 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
5571 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
5572 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
5573 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
5574 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
5575 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
5576 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
5577 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
5578 VK_FORMAT_R16_UNORM,
5579 VK_FORMAT_R16_SNORM,
5580 VK_FORMAT_R16_USCALED,
5581 VK_FORMAT_R16_SSCALED,
5582 VK_FORMAT_R16_SFLOAT,
5583 VK_FORMAT_R16G16_UNORM,
5584 VK_FORMAT_R16G16_SNORM,
5585 VK_FORMAT_R16G16_USCALED,
5586 VK_FORMAT_R16G16_SSCALED,
5587 VK_FORMAT_R16G16_SFLOAT,
5588 VK_FORMAT_R16G16B16_UNORM,
5589 VK_FORMAT_R16G16B16_SNORM,
5590 VK_FORMAT_R16G16B16_USCALED,
5591 VK_FORMAT_R16G16B16_SSCALED,
5592 VK_FORMAT_R16G16B16_SFLOAT,
5593 VK_FORMAT_R16G16B16A16_UNORM,
5594 VK_FORMAT_R16G16B16A16_SNORM,
5595 VK_FORMAT_R16G16B16A16_USCALED,
5596 VK_FORMAT_R16G16B16A16_SSCALED,
5597 VK_FORMAT_R16G16B16A16_SFLOAT,
5598 VK_FORMAT_R32_SFLOAT,
5599 VK_FORMAT_R32G32_SFLOAT,
5600 VK_FORMAT_R32G32B32_SFLOAT,
5601 VK_FORMAT_R32G32B32A32_SFLOAT,
5602 VK_FORMAT_R64_SFLOAT,
5603 VK_FORMAT_R64G64_SFLOAT,
5604 VK_FORMAT_R64G64B64_SFLOAT,
5605 VK_FORMAT_R64G64B64A64_SFLOAT,
5606 // VK_FORMAT_B10G11R11_UFLOAT_PACK32,
5607 // VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
5608 // VK_FORMAT_BC1_RGB_UNORM_BLOCK,
5609 // VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
5610 // VK_FORMAT_BC2_UNORM_BLOCK,
5611 // VK_FORMAT_BC3_UNORM_BLOCK,
5612 // VK_FORMAT_BC4_UNORM_BLOCK,
5613 // VK_FORMAT_BC4_SNORM_BLOCK,
5614 // VK_FORMAT_BC5_UNORM_BLOCK,
5615 // VK_FORMAT_BC5_SNORM_BLOCK,
5616 // VK_FORMAT_BC6H_UFLOAT_BLOCK,
5617 // VK_FORMAT_BC6H_SFLOAT_BLOCK,
5618 // VK_FORMAT_BC7_UNORM_BLOCK,
5619 // VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
5620 // VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
5621 // VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
5622 // VK_FORMAT_EAC_R11_UNORM_BLOCK,
5623 // VK_FORMAT_EAC_R11_SNORM_BLOCK,
5624 // VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
5625 // VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
5626 // VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
5627 // VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
5628 // VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
5629 // VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
5630 // VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
5631 // VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
5632 // VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
5633 // VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
5634 // VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
5635 // VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
5636 // VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
5637 // VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
5638 // VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
5639 // VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
5643 const VkFormat compatibleFormatsSrgb[] =
5646 VK_FORMAT_R8G8_SRGB,
5647 VK_FORMAT_R8G8B8_SRGB,
5648 VK_FORMAT_B8G8R8_SRGB,
5649 VK_FORMAT_R8G8B8A8_SRGB,
5650 VK_FORMAT_B8G8R8A8_SRGB,
5651 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
5652 // VK_FORMAT_BC1_RGB_SRGB_BLOCK,
5653 // VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
5654 // VK_FORMAT_BC2_SRGB_BLOCK,
5655 // VK_FORMAT_BC3_SRGB_BLOCK,
5656 // VK_FORMAT_BC7_SRGB_BLOCK,
5657 // VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
5658 // VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
5659 // VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
5660 // VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
5661 // VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
5662 // VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
5663 // VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
5664 // VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
5665 // VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
5666 // VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
5667 // VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
5668 // VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
5669 // VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
5670 // VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
5671 // VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
5672 // VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
5673 // VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
5678 const VkFormat dedicatedAllocationBlittingFormatsToTest[] =
5680 // compatibleFormatsUInts
5682 VK_FORMAT_R64G64B64A64_UINT,
5684 // compatibleFormatsSInts
5686 VK_FORMAT_R64G64B64A64_SINT,
5688 // compatibleFormatsFloats
5689 VK_FORMAT_R4G4_UNORM_PACK8,
5690 VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
5692 // compatibleFormatsSrgb
5694 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
5697 void addBlittingImageAllFormatsColorTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5700 const VkFormat* compatibleFormats;
5701 const bool onlyNearest;
5702 } colorImageFormatsToTestBlit[] =
5704 { compatibleFormatsUInts, true },
5705 { compatibleFormatsSInts, true },
5706 { compatibleFormatsFloats, false },
5707 { compatibleFormatsSrgb, false },
5710 const int numOfColorImageFormatsToTest = DE_LENGTH_OF_ARRAY(colorImageFormatsToTestBlit);
5713 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5714 params.src.image.extent = defaultExtent;
5715 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5716 params.dst.image.extent = defaultExtent;
5717 params.allocationKind = allocationKind;
5720 for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
5722 const VkImageBlit imageBlit =
5724 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5727 {defaultSize, defaultSize, 1}
5728 }, // VkOffset3D srcOffsets[2];
5730 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5733 {i + defaultFourthSize / j, defaultFourthSize / j, 1}
5734 } // VkOffset3D dstOffset[2];
5736 region.imageBlit = imageBlit;
5737 params.regions.push_back(region);
5739 for (int i = 0; i < defaultSize; i += defaultFourthSize)
5741 const VkImageBlit imageBlit =
5743 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
5746 {i + defaultFourthSize, i + defaultFourthSize, 1}
5747 }, // VkOffset3D srcOffsets[2];
5749 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
5751 {i, defaultSize / 2, 0},
5752 {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1}
5753 } // VkOffset3D dstOffset[2];
5755 region.imageBlit = imageBlit;
5756 params.regions.push_back(region);
5759 if (allocationKind == ALLOCATION_KIND_DEDICATED)
5761 const int numOfColorImageFormatsToTestFilter = DE_LENGTH_OF_ARRAY(dedicatedAllocationBlittingFormatsToTest);
5762 for (int compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTestFilter; ++compatibleFormatsIndex)
5763 dedicatedAllocationBlittingFormatsToTestSet.insert(dedicatedAllocationBlittingFormatsToTest[compatibleFormatsIndex]);
5766 for (int compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
5768 const VkFormat* compatibleFormats = colorImageFormatsToTestBlit[compatibleFormatsIndex].compatibleFormats;
5769 const bool onlyNearest = colorImageFormatsToTestBlit[compatibleFormatsIndex].onlyNearest;
5770 for (int srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_UNDEFINED; ++srcFormatIndex)
5772 params.src.image.format = compatibleFormats[srcFormatIndex];
5773 if (!isSupportedByFramework(params.src.image.format))
5776 BlitColorTestParams testParams;
5777 testParams.params = params;
5778 testParams.compatibleFormats = compatibleFormats;
5779 testParams.onlyNearest = onlyNearest;
5781 const std::string description = "Blit source format " + getFormatCaseName(params.src.image.format);
5782 addTestGroup(group, getFormatCaseName(params.src.image.format), description, addBlittingImageAllFormatsColorSrcFormatTests, testParams);
5787 void addBlittingImageAllFormatsDepthStencilFormatsTests (tcu::TestCaseGroup* group, TestParams params)
5789 const VkImageLayout blitSrcLayouts[] =
5791 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
5792 VK_IMAGE_LAYOUT_GENERAL
5794 const VkImageLayout blitDstLayouts[] =
5796 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
5797 VK_IMAGE_LAYOUT_GENERAL
5800 for (int srcLayoutNdx = 0u; srcLayoutNdx < DE_LENGTH_OF_ARRAY(blitSrcLayouts); ++srcLayoutNdx)
5802 params.src.image.operationLayout = blitSrcLayouts[srcLayoutNdx];
5804 for (int dstLayoutNdx = 0u; dstLayoutNdx < DE_LENGTH_OF_ARRAY(blitDstLayouts); ++dstLayoutNdx)
5806 params.dst.image.operationLayout = blitDstLayouts[dstLayoutNdx];
5807 params.filter = VK_FILTER_NEAREST;
5809 const std::string testName = getImageLayoutCaseName(params.src.image.operationLayout) + "_" +
5810 getImageLayoutCaseName(params.dst.image.operationLayout);
5811 const std::string description = "Blit from " + getImageLayoutCaseName(params.src.image.operationLayout) +
5812 " to " + getImageLayoutCaseName(params.dst.image.operationLayout);
5814 group->addChild(new BlittingTestCase(group->getTestContext(), testName + "_nearest", description, params));
5819 void addBlittingImageAllFormatsDepthStencilTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5821 const VkFormat depthAndStencilFormats[] =
5823 VK_FORMAT_D16_UNORM,
5824 VK_FORMAT_X8_D24_UNORM_PACK32,
5825 VK_FORMAT_D32_SFLOAT,
5827 VK_FORMAT_D16_UNORM_S8_UINT,
5828 VK_FORMAT_D24_UNORM_S8_UINT,
5829 VK_FORMAT_D32_SFLOAT_S8_UINT,
5832 const VkImageSubresourceLayers defaultDepthSourceLayer = { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u };
5833 const VkImageSubresourceLayers defaultStencilSourceLayer = { VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u };
5835 for (int compatibleFormatsIndex = 0; compatibleFormatsIndex < DE_LENGTH_OF_ARRAY(depthAndStencilFormats); ++compatibleFormatsIndex)
5838 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5839 params.src.image.extent = defaultExtent;
5840 params.src.image.format = depthAndStencilFormats[compatibleFormatsIndex];
5841 params.dst.image.extent = defaultExtent;
5842 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5843 params.dst.image.format = params.src.image.format;
5844 params.allocationKind = allocationKind;
5847 for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
5849 const VkOffset3D srcOffset0 = {0, 0, 0};
5850 const VkOffset3D srcOffset1 = {defaultSize, defaultSize, 1};
5851 const VkOffset3D dstOffset0 = {i, 0, 0};
5852 const VkOffset3D dstOffset1 = {i + defaultFourthSize / j, defaultFourthSize / j, 1};
5854 if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
5856 const VkImageBlit imageBlit =
5858 defaultDepthSourceLayer, // VkImageSubresourceLayers srcSubresource;
5859 { srcOffset0 , srcOffset1 }, // VkOffset3D srcOffsets[2];
5860 defaultDepthSourceLayer, // VkImageSubresourceLayers dstSubresource;
5861 { dstOffset0 , dstOffset1 }, // VkOffset3D dstOffset[2];
5863 region.imageBlit = imageBlit;
5864 params.regions.push_back(region);
5866 if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
5868 const VkImageBlit imageBlit =
5870 defaultStencilSourceLayer, // VkImageSubresourceLayers srcSubresource;
5871 { srcOffset0 , srcOffset1 }, // VkOffset3D srcOffsets[2];
5872 defaultStencilSourceLayer, // VkImageSubresourceLayers dstSubresource;
5873 { dstOffset0 , dstOffset1 }, // VkOffset3D dstOffset[2];
5875 region.imageBlit = imageBlit;
5876 params.regions.push_back(region);
5879 for (int i = 0; i < defaultSize; i += defaultFourthSize)
5881 const VkOffset3D srcOffset0 = {i, i, 0};
5882 const VkOffset3D srcOffset1 = {i + defaultFourthSize, i + defaultFourthSize, 1};
5883 const VkOffset3D dstOffset0 = {i, defaultSize / 2, 0};
5884 const VkOffset3D dstOffset1 = {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1};
5886 if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
5888 const VkImageBlit imageBlit =
5890 defaultDepthSourceLayer, // VkImageSubresourceLayers srcSubresource;
5891 { srcOffset0, srcOffset1 }, // VkOffset3D srcOffsets[2];
5892 defaultDepthSourceLayer, // VkImageSubresourceLayers dstSubresource;
5893 { dstOffset0, dstOffset1 } // VkOffset3D dstOffset[2];
5895 region.imageBlit = imageBlit;
5896 params.regions.push_back(region);
5898 if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
5900 const VkImageBlit imageBlit =
5902 defaultStencilSourceLayer, // VkImageSubresourceLayers srcSubresource;
5903 { srcOffset0, srcOffset1 }, // VkOffset3D srcOffsets[2];
5904 defaultStencilSourceLayer, // VkImageSubresourceLayers dstSubresource;
5905 { dstOffset0, dstOffset1 } // VkOffset3D dstOffset[2];
5907 region.imageBlit = imageBlit;
5908 params.regions.push_back(region);
5912 const std::string testName = getFormatCaseName(params.src.image.format) + "_" +
5913 getFormatCaseName(params.dst.image.format);
5914 const std::string description = "Blit from " + getFormatCaseName(params.src.image.format) +
5915 " to " + getFormatCaseName(params.dst.image.format);
5916 addTestGroup(group, testName, description, addBlittingImageAllFormatsDepthStencilFormatsTests, params);
5920 void addBlittingImageAllFormatsTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5922 addTestGroup(group, "color", "Blitting image with color formats", addBlittingImageAllFormatsColorTests, allocationKind);
5923 addTestGroup(group, "depth_stencil", "Blitting image with depth/stencil formats", addBlittingImageAllFormatsDepthStencilTests, allocationKind);
5926 void addBlittingImageTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5928 addTestGroup(group, "simple_tests", "Blitting image simple tests", addBlittingImageSimpleTests, allocationKind);
5929 addTestGroup(group, "all_formats", "Blitting image with all compatible formats", addBlittingImageAllFormatsTests, allocationKind);
5932 const VkSampleCountFlagBits samples[] =
5934 VK_SAMPLE_COUNT_2_BIT,
5935 VK_SAMPLE_COUNT_4_BIT,
5936 VK_SAMPLE_COUNT_8_BIT,
5937 VK_SAMPLE_COUNT_16_BIT,
5938 VK_SAMPLE_COUNT_32_BIT,
5939 VK_SAMPLE_COUNT_64_BIT
5941 const VkExtent3D resolveExtent = {256u, 256u, 1};
5943 void addResolveImageWholeTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5946 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5947 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5948 params.src.image.extent = resolveExtent;
5949 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5950 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5951 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5952 params.dst.image.extent = resolveExtent;
5953 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
5954 params.allocationKind = allocationKind;
5957 const VkImageSubresourceLayers sourceLayer =
5959 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
5960 0u, // uint32_t mipLevel;
5961 0u, // uint32_t baseArrayLayer;
5962 1u // uint32_t layerCount;
5964 const VkImageResolve testResolve =
5966 sourceLayer, // VkImageSubresourceLayers srcSubresource;
5967 {0, 0, 0}, // VkOffset3D srcOffset;
5968 sourceLayer, // VkImageSubresourceLayers dstSubresource;
5969 {0, 0, 0}, // VkOffset3D dstOffset;
5970 resolveExtent, // VkExtent3D extent;
5973 CopyRegion imageResolve;
5974 imageResolve.imageResolve = testResolve;
5975 params.regions.push_back(imageResolve);
5978 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
5980 params.samples = samples[samplesIndex];
5981 const std::string description = "With " + getSampleCountCaseName(samples[samplesIndex]);
5982 group->addChild(new ResolveImageToImageTestCase(group->getTestContext(), getSampleCountCaseName(samples[samplesIndex]), description, params));
5986 void addResolveImagePartialTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
5989 params.src.image.imageType = VK_IMAGE_TYPE_2D;
5990 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5991 params.src.image.extent = resolveExtent;
5992 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
5993 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
5994 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
5995 params.dst.image.extent = resolveExtent;
5996 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
5997 params.allocationKind = allocationKind;
6000 const VkImageSubresourceLayers sourceLayer =
6002 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
6003 0u, // uint32_t mipLevel;
6004 0u, // uint32_t baseArrayLayer;
6005 1u // uint32_t layerCount;
6007 const VkImageResolve testResolve =
6009 sourceLayer, // VkImageSubresourceLayers srcSubresource;
6010 {0, 0, 0}, // VkOffset3D srcOffset;
6011 sourceLayer, // VkImageSubresourceLayers dstSubresource;
6012 {64u, 64u, 0}, // VkOffset3D dstOffset;
6013 {128u, 128u, 1u}, // VkExtent3D extent;
6016 CopyRegion imageResolve;
6017 imageResolve.imageResolve = testResolve;
6018 params.regions.push_back(imageResolve);
6021 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
6023 params.samples = samples[samplesIndex];
6024 const std::string description = "With " + getSampleCountCaseName(samples[samplesIndex]);
6025 group->addChild(new ResolveImageToImageTestCase(group->getTestContext(), getSampleCountCaseName(samples[samplesIndex]), description, params));
6029 void addResolveImageWithRegionsTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
6032 params.src.image.imageType = VK_IMAGE_TYPE_2D;
6033 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6034 params.src.image.extent = resolveExtent;
6035 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6036 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
6037 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6038 params.dst.image.extent = resolveExtent;
6039 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
6040 params.allocationKind = allocationKind;
6043 const VkImageSubresourceLayers sourceLayer =
6045 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
6046 0u, // uint32_t mipLevel;
6047 0u, // uint32_t baseArrayLayer;
6048 1u // uint32_t layerCount;
6051 for (int i = 0; i < 256; i += 64)
6053 const VkImageResolve testResolve =
6055 sourceLayer, // VkImageSubresourceLayers srcSubresource;
6056 {i, i, 0}, // VkOffset3D srcOffset;
6057 sourceLayer, // VkImageSubresourceLayers dstSubresource;
6058 {i, 0, 0}, // VkOffset3D dstOffset;
6059 {64u, 64u, 1u}, // VkExtent3D extent;
6062 CopyRegion imageResolve;
6063 imageResolve.imageResolve = testResolve;
6064 params.regions.push_back(imageResolve);
6068 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
6070 params.samples = samples[samplesIndex];
6071 const std::string description = "With " + getSampleCountCaseName(samples[samplesIndex]);
6072 group->addChild(new ResolveImageToImageTestCase(group->getTestContext(), getSampleCountCaseName(samples[samplesIndex]), description, params));
6076 void addResolveImageWholeCopyBeforeResolvingTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
6079 params.src.image.imageType = VK_IMAGE_TYPE_2D;
6080 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6081 params.src.image.extent = defaultExtent;
6082 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6083 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
6084 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6085 params.dst.image.extent = defaultExtent;
6086 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
6087 params.allocationKind = allocationKind;
6090 const VkImageSubresourceLayers sourceLayer =
6092 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
6093 0u, // uint32_t mipLevel;
6094 0u, // uint32_t baseArrayLayer;
6095 1u // uint32_t layerCount;
6098 const VkImageResolve testResolve =
6100 sourceLayer, // VkImageSubresourceLayers srcSubresource;
6101 {0, 0, 0}, // VkOffset3D srcOffset;
6102 sourceLayer, // VkImageSubresourceLayers dstSubresource;
6103 {0, 0, 0}, // VkOffset3D dstOffset;
6104 defaultExtent, // VkExtent3D extent;
6107 CopyRegion imageResolve;
6108 imageResolve.imageResolve = testResolve;
6109 params.regions.push_back(imageResolve);
6112 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
6114 params.samples = samples[samplesIndex];
6115 const std::string description = "With " + getSampleCountCaseName(samples[samplesIndex]);
6116 group->addChild(new ResolveImageToImageTestCase(group->getTestContext(), getSampleCountCaseName(samples[samplesIndex]), description, params, COPY_MS_IMAGE_TO_MS_IMAGE));
6120 void addResolveImageWholeArrayImageTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
6123 params.src.image.imageType = VK_IMAGE_TYPE_2D;
6124 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6125 params.src.image.extent = defaultExtent;
6126 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6127 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
6128 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6129 params.dst.image.extent = defaultExtent;
6130 params.dst.image.extent.depth = 5u;
6131 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
6132 params.allocationKind = allocationKind;
6134 for (deUint32 layerNdx=0; layerNdx < params.dst.image.extent.depth; ++layerNdx)
6136 const VkImageSubresourceLayers sourceLayer =
6138 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
6139 0u, // uint32_t mipLevel;
6140 layerNdx, // uint32_t baseArrayLayer;
6141 1u // uint32_t layerCount;
6144 const VkImageResolve testResolve =
6146 sourceLayer, // VkImageSubresourceLayers srcSubresource;
6147 {0, 0, 0}, // VkOffset3D srcOffset;
6148 sourceLayer, // VkImageSubresourceLayers dstSubresource;
6149 {0, 0, 0}, // VkOffset3D dstOffset;
6150 defaultExtent, // VkExtent3D extent;
6153 CopyRegion imageResolve;
6154 imageResolve.imageResolve = testResolve;
6155 params.regions.push_back(imageResolve);
6158 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
6160 params.samples = samples[samplesIndex];
6161 const std::string description = "With " + getSampleCountCaseName(samples[samplesIndex]);
6162 group->addChild(new ResolveImageToImageTestCase(group->getTestContext(), getSampleCountCaseName(samples[samplesIndex]), description, params, COPY_MS_IMAGE_TO_ARRAY_MS_IMAGE));
6166 void addResolveImageDiffImageSizeTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
6168 tcu::TestContext& testCtx = group->getTestContext();
6170 params.src.image.imageType = VK_IMAGE_TYPE_2D;
6171 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6172 params.src.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
6173 params.dst.image.imageType = VK_IMAGE_TYPE_2D;
6174 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
6175 params.dst.image.operationLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
6176 params.allocationKind = allocationKind;
6179 const VkImageSubresourceLayers sourceLayer =
6181 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
6182 0u, // uint32_t mipLevel;
6183 0u, // uint32_t baseArrayLayer;
6184 1u // uint32_t layerCount;
6186 const VkImageResolve testResolve =
6188 sourceLayer, // VkImageSubresourceLayers srcSubresource;
6189 {0, 0, 0}, // VkOffset3D srcOffset;
6190 sourceLayer, // VkImageSubresourceLayers dstSubresource;
6191 {0, 0, 0}, // VkOffset3D dstOffset;
6192 resolveExtent, // VkExtent3D extent;
6194 CopyRegion imageResolve;
6195 imageResolve.imageResolve = testResolve;
6196 params.regions.push_back(imageResolve);
6199 const VkExtent3D imageExtents[] =
6201 { resolveExtent.width + 10, resolveExtent.height, resolveExtent.depth },
6202 { resolveExtent.width, resolveExtent.height * 2, resolveExtent.depth },
6203 { resolveExtent.width, resolveExtent.height, resolveExtent.depth + 10 }
6206 for (int srcImageExtentIndex = 0; srcImageExtentIndex < DE_LENGTH_OF_ARRAY(imageExtents); ++srcImageExtentIndex)
6208 const VkExtent3D& srcImageSize = imageExtents[srcImageExtentIndex];
6209 params.src.image.extent = srcImageSize;
6210 params.dst.image.extent = resolveExtent;
6211 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
6213 params.samples = samples[samplesIndex];
6214 std::ostringstream testName;
6215 testName << "src_" << srcImageSize.width << "_" << srcImageSize.height << "_" << srcImageSize.depth << "_" << getSampleCountCaseName(samples[samplesIndex]);
6216 std::ostringstream description;
6217 description << "With " << getSampleCountCaseName(samples[samplesIndex]) << " and source image size ("
6218 << srcImageSize.width << ", " << srcImageSize.height << ", " << srcImageSize.depth << ")";
6219 group->addChild(new ResolveImageToImageTestCase(testCtx, testName.str(), description.str(), params));
6222 for (int dstImageExtentIndex = 0; dstImageExtentIndex < DE_LENGTH_OF_ARRAY(imageExtents); ++dstImageExtentIndex)
6224 const VkExtent3D& dstImageSize = imageExtents[dstImageExtentIndex];
6225 params.src.image.extent = resolveExtent;
6226 params.dst.image.extent = dstImageSize;
6227 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
6229 params.samples = samples[samplesIndex];
6230 std::ostringstream testName;
6231 testName << "dst_" << dstImageSize.width << "_" << dstImageSize.height << "_" << dstImageSize.depth << "_" << getSampleCountCaseName(samples[samplesIndex]);
6232 std::ostringstream description;
6233 description << "With " << getSampleCountCaseName(samples[samplesIndex]) << " and destination image size ("
6234 << dstImageSize.width << ", " << dstImageSize.height << ", " << dstImageSize.depth << ")";
6235 group->addChild(new ResolveImageToImageTestCase(testCtx, testName.str(), description.str(), params));
6240 void addResolveImageTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
6242 addTestGroup(group, "whole", "Resolve from image to image (whole)", addResolveImageWholeTests, allocationKind);
6243 addTestGroup(group, "partial", "Resolve from image to image (partial)", addResolveImagePartialTests, allocationKind);
6244 addTestGroup(group, "with_regions", "Resolve from image to image (with regions)", addResolveImageWithRegionsTests, allocationKind);
6245 addTestGroup(group, "whole_copy_before_resolving", "Resolve from image to image (whole copy before resolving)", addResolveImageWholeCopyBeforeResolvingTests, allocationKind);
6246 addTestGroup(group, "whole_array_image", "Resolve from image to image (whole array image)", addResolveImageWholeArrayImageTests, allocationKind);
6247 addTestGroup(group, "diff_image_size", "Resolve from image to image of different size", addResolveImageDiffImageSizeTests, allocationKind);
6250 void addCopiesAndBlittingTests (tcu::TestCaseGroup* group, AllocationKind allocationKind)
6252 addTestGroup(group, "image_to_image", "Copy from image to image", addImageToImageTests, allocationKind);
6253 addTestGroup(group, "image_to_buffer", "Copy from image to buffer", addImageToBufferTests, allocationKind);
6254 addTestGroup(group, "buffer_to_image", "Copy from buffer to image", addBufferToImageTests, allocationKind);
6255 addTestGroup(group, "buffer_to_buffer", "Copy from buffer to buffer", addBufferToBufferTests, allocationKind);
6256 addTestGroup(group, "blit_image", "Blitting image", addBlittingImageTests, allocationKind);
6257 addTestGroup(group, "resolve_image", "Resolve image", addResolveImageTests, allocationKind);
6260 void addCoreCopiesAndBlittingTests (tcu::TestCaseGroup* group)
6262 addCopiesAndBlittingTests(group, ALLOCATION_KIND_SUBALLOCATED);
6265 void addDedicatedAllocationCopiesAndBlittingTests (tcu::TestCaseGroup* group)
6267 addCopiesAndBlittingTests(group, ALLOCATION_KIND_DEDICATED);
6272 tcu::TestCaseGroup* createCopiesAndBlittingTests (tcu::TestContext& testCtx)
6274 de::MovePtr<tcu::TestCaseGroup> copiesAndBlittingTests(new tcu::TestCaseGroup(testCtx, "copy_and_blit", "Copies And Blitting Tests"));
6276 copiesAndBlittingTests->addChild(createTestGroup(testCtx, "core", "Core Copies And Blitting Tests", addCoreCopiesAndBlittingTests));
6277 copiesAndBlittingTests->addChild(createTestGroup(testCtx, "dedicated_allocation", "Copies And Blitting Tests For Dedicated Memory Allocation", addDedicatedAllocationCopiesAndBlittingTests));
6279 return copiesAndBlittingTests.release();