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"
36 #include "vkImageUtil.hpp"
37 #include "vkMemUtil.hpp"
38 #include "vkPrograms.hpp"
39 #include "vkQueryUtil.hpp"
40 #include "vkRefUtil.hpp"
41 #include "vktTestCase.hpp"
42 #include "vktTestCaseUtil.hpp"
43 #include "vkTypeUtil.hpp"
56 VkImageAspectFlags getAspectFlags (tcu::TextureFormat format)
58 VkImageAspectFlags aspectFlag = 0;
59 aspectFlag |= (tcu::hasDepthComponent(format.order)? VK_IMAGE_ASPECT_DEPTH_BIT : 0);
60 aspectFlag |= (tcu::hasStencilComponent(format.order)? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
63 aspectFlag = VK_IMAGE_ASPECT_COLOR_BIT;
68 // This is effectively same as vk::isFloatFormat(mapTextureFormat(format))
69 // except that it supports some formats that are not mappable to VkFormat.
70 // When we are checking combined depth and stencil formats, each aspect is
71 // checked separately, and in some cases we construct PBA with a format that
72 // is not mappable to VkFormat.
73 bool isFloatFormat (tcu::TextureFormat format)
75 return tcu::getTextureChannelClass(format.type) == tcu::TEXTURECHANNELCLASS_FLOATING_POINT;
80 VkBufferCopy bufferCopy;
81 VkImageCopy imageCopy;
82 VkBufferImageCopy bufferImageCopy;
83 VkImageBlit imageBlit;
84 VkImageResolve imageResolve;
102 std::vector<CopyRegion> regions;
106 VkSampleCountFlagBits samples;
110 const tcu::TextureFormat mapCombinedToDepthTransferFormat (const tcu::TextureFormat& combinedFormat)
112 tcu::TextureFormat format;
113 switch (combinedFormat.type)
115 case tcu::TextureFormat::UNSIGNED_INT_16_8_8:
116 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNORM_INT16);
118 case tcu::TextureFormat::UNSIGNED_INT_24_8_REV:
119 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::UNSIGNED_INT_24_8_REV);
121 case tcu::TextureFormat::FLOAT_UNSIGNED_INT_24_8_REV:
122 format = tcu::TextureFormat(tcu::TextureFormat::D, tcu::TextureFormat::FLOAT);
131 class CopiesAndBlittingTestInstance : public vkt::TestInstance
134 CopiesAndBlittingTestInstance (Context& context,
135 TestParams testParams);
136 virtual tcu::TestStatus iterate (void) = 0;
140 FILL_MODE_GRADIENT = 0,
143 FILL_MODE_MULTISAMPLE,
149 const TestParams m_params;
151 Move<VkCommandPool> m_cmdPool;
152 Move<VkCommandBuffer> m_cmdBuffer;
153 Move<VkFence> m_fence;
154 de::MovePtr<tcu::TextureLevel> m_sourceTextureLevel;
155 de::MovePtr<tcu::TextureLevel> m_destinationTextureLevel;
156 de::MovePtr<tcu::TextureLevel> m_expectedTextureLevel;
158 VkCommandBufferBeginInfo m_cmdBufferBeginInfo;
160 void generateBuffer (tcu::PixelBufferAccess buffer, int width, int height, int depth = 1, FillMode = FILL_MODE_GRADIENT);
161 virtual void generateExpectedResult (void);
162 void uploadBuffer (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc);
163 void uploadImage (const tcu::ConstPixelBufferAccess& src, VkImage dst);
164 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
165 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region) = 0;
166 deUint32 calculateSize (tcu::ConstPixelBufferAccess src) const
168 return src.getWidth() * src.getHeight() * src.getDepth() * tcu::getPixelSize(src.getFormat());
171 de::MovePtr<tcu::TextureLevel> readImage (vk::VkImage image,
173 const VkExtent3D imageSize);
176 void uploadImageAspect (const tcu::ConstPixelBufferAccess& src,
178 void readImageAspect (vk::VkImage src,
179 const tcu::PixelBufferAccess& dst);
182 CopiesAndBlittingTestInstance::CopiesAndBlittingTestInstance (Context& context, TestParams testParams)
183 : vkt::TestInstance (context)
184 , m_params (testParams)
186 const DeviceInterface& vk = context.getDeviceInterface();
187 const VkDevice vkDevice = context.getDevice();
188 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
190 // Create command pool
192 const VkCommandPoolCreateInfo cmdPoolParams =
194 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
195 DE_NULL, // const void* pNext;
196 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
197 queueFamilyIndex, // deUint32 queueFamilyIndex;
200 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
203 // Create command buffer
205 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
207 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
208 DE_NULL, // const void* pNext;
209 *m_cmdPool, // VkCommandPool commandPool;
210 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
211 1u // deUint32 bufferCount;
214 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
219 const VkFenceCreateInfo fenceParams =
221 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
222 DE_NULL, // const void* pNext;
223 0u // VkFenceCreateFlags flags;
226 m_fence = createFence(vk, vkDevice, &fenceParams);
230 void CopiesAndBlittingTestInstance::generateBuffer (tcu::PixelBufferAccess buffer, int width, int height, int depth, FillMode mode)
232 if (mode == FILL_MODE_GRADIENT)
234 tcu::fillWithComponentGradients(buffer, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
238 const tcu::Vec4 redColor (1.0, 0.0, 0.0, 1.0);
239 const tcu::Vec4 greenColor (0.0, 1.0, 0.0, 1.0);
240 const tcu::Vec4 blueColor (0.0, 0.0, 1.0, 1.0);
241 const tcu::Vec4 whiteColor (1.0, 1.0, 1.0, 1.0);
243 for (int z = 0; z < depth; z++)
245 for (int y = 0; y < height; y++)
247 for (int x = 0; x < width; x++)
251 case FILL_MODE_WHITE:
252 if (tcu::isCombinedDepthStencilType(buffer.getFormat().type))
254 buffer.setPixDepth(1.0f, x, y, z);
255 if (tcu::hasStencilComponent(buffer.getFormat().order))
256 buffer.setPixStencil(255, x, y, z);
259 buffer.setPixel(whiteColor, x, y, z);
262 DE_ASSERT(!tcu::isCombinedDepthStencilType(buffer.getFormat().type)); // combined types cannot be accessed directly
263 buffer.setPixel(redColor, x, y, z);
265 case FILL_MODE_MULTISAMPLE:
266 buffer.setPixel((x == y) ? tcu::Vec4(0.0, 0.5, 0.5, 1.0) : ((x > y) ? greenColor : blueColor), x, y, z);
276 void CopiesAndBlittingTestInstance::uploadBuffer (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc)
278 const DeviceInterface& vk = m_context.getDeviceInterface();
279 const VkDevice vkDevice = m_context.getDevice();
280 const deUint32 bufferSize = calculateSize(bufferAccess);
283 deMemcpy(bufferAlloc.getHostPtr(), bufferAccess.getDataPtr(), bufferSize);
284 flushMappedMemoryRange(vk, vkDevice, bufferAlloc.getMemory(), bufferAlloc.getOffset(), bufferSize);
287 void CopiesAndBlittingTestInstance::uploadImageAspect (const tcu::ConstPixelBufferAccess& imageAccess, const VkImage& image)
289 const DeviceInterface& vk = m_context.getDeviceInterface();
290 const VkDevice vkDevice = m_context.getDevice();
291 const VkQueue queue = m_context.getUniversalQueue();
292 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
293 Allocator& memAlloc = m_context.getDefaultAllocator();
295 Move<VkBuffer> buffer;
296 const deUint32 bufferSize = calculateSize(imageAccess);
297 de::MovePtr<Allocation> bufferAlloc;
298 Move<VkCommandBuffer> cmdBuffer;
300 // Create source buffer
302 const VkBufferCreateInfo bufferParams =
304 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
305 DE_NULL, // const void* pNext;
306 0u, // VkBufferCreateFlags flags;
307 bufferSize, // VkDeviceSize size;
308 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
309 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
310 1u, // deUint32 queueFamilyIndexCount;
311 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
314 buffer = createBuffer(vk, vkDevice, &bufferParams);
315 bufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *buffer), MemoryRequirement::HostVisible);
316 VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
319 // Create command buffer
321 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
323 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
324 DE_NULL, // const void* pNext;
325 *m_cmdPool, // VkCommandPool commandPool;
326 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
327 1u, // deUint32 bufferCount;
330 cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
333 // Barriers for copying buffer to image
334 const VkBufferMemoryBarrier preBufferBarrier =
336 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
337 DE_NULL, // const void* pNext;
338 VK_ACCESS_HOST_WRITE_BIT, // VkAccessFlags srcAccessMask;
339 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
340 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
341 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
342 *buffer, // VkBuffer buffer;
343 0u, // VkDeviceSize offset;
344 bufferSize // VkDeviceSize size;
347 const VkImageAspectFlags aspect = getAspectFlags(imageAccess.getFormat());
348 const VkImageMemoryBarrier preImageBarrier =
350 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
351 DE_NULL, // const void* pNext;
352 0u, // VkAccessFlags srcAccessMask;
353 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
354 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
355 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
356 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
357 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
358 image, // VkImage image;
359 { // VkImageSubresourceRange subresourceRange;
360 aspect, // VkImageAspectFlags aspect;
361 0u, // deUint32 baseMipLevel;
362 1u, // deUint32 mipLevels;
363 0u, // deUint32 baseArraySlice;
364 1u, // deUint32 arraySize;
368 const VkImageMemoryBarrier postImageBarrier =
370 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
371 DE_NULL, // const void* pNext;
372 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
373 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
374 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
375 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
376 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
377 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
378 image, // VkImage image;
379 { // VkImageSubresourceRange subresourceRange;
380 aspect, // VkImageAspectFlags aspect;
381 0u, // deUint32 baseMipLevel;
382 1u, // deUint32 mipLevels;
383 0u, // deUint32 baseArraySlice;
384 1u, // deUint32 arraySize;
388 const VkExtent3D imageExtent = { (deUint32)imageAccess.getWidth(), (deUint32)imageAccess.getHeight(), 1u };
389 const VkBufferImageCopy copyRegion =
391 0u, // VkDeviceSize bufferOffset;
392 (deUint32)imageAccess.getWidth(), // deUint32 bufferRowLength;
393 (deUint32)imageAccess.getHeight(), // deUint32 bufferImageHeight;
395 getAspectFlags(imageAccess.getFormat()), // VkImageAspectFlags aspect;
396 0u, // deUint32 mipLevel;
397 0u, // deUint32 baseArrayLayer;
398 1u, // deUint32 layerCount;
399 }, // VkImageSubresourceLayers imageSubresource;
400 { 0, 0, 0 }, // VkOffset3D imageOffset;
401 imageExtent // VkExtent3D imageExtent;
405 deMemcpy(bufferAlloc->getHostPtr(), imageAccess.getDataPtr(), bufferSize);
406 flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), bufferSize);
408 // Copy buffer to image
409 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
411 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
412 DE_NULL, // const void* pNext;
413 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
414 (const VkCommandBufferInheritanceInfo*)DE_NULL,
417 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
418 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &preBufferBarrier, 1, &preImageBarrier);
419 vk.cmdCopyBufferToImage(*cmdBuffer, *buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1u, ©Region);
420 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &postImageBarrier);
421 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
423 const VkSubmitInfo submitInfo =
425 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
426 DE_NULL, // const void* pNext;
427 0u, // deUint32 waitSemaphoreCount;
428 DE_NULL, // const VkSemaphore* pWaitSemaphores;
429 (const VkPipelineStageFlags*)DE_NULL,
430 1u, // deUint32 commandBufferCount;
431 &cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
432 0u, // deUint32 signalSemaphoreCount;
433 DE_NULL // const VkSemaphore* pSignalSemaphores;
436 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
437 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
438 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
441 void CopiesAndBlittingTestInstance::uploadImage (const tcu::ConstPixelBufferAccess& src, VkImage dst)
443 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
445 if (tcu::hasDepthComponent(src.getFormat().order))
447 tcu::TextureLevel depthTexture (mapCombinedToDepthTransferFormat(src.getFormat()), src.getWidth(), src.getHeight(), src.getDepth());
448 tcu::copy(depthTexture.getAccess(), tcu::getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_DEPTH));
449 uploadImageAspect(depthTexture.getAccess(), dst);
452 if (tcu::hasStencilComponent(src.getFormat().order))
454 tcu::TextureLevel stencilTexture (tcu::getEffectiveDepthStencilTextureFormat(src.getFormat(), tcu::Sampler::MODE_STENCIL), src.getWidth(), src.getHeight(), src.getDepth());
455 tcu::copy(stencilTexture.getAccess(), tcu::getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_STENCIL));
456 uploadImageAspect(stencilTexture.getAccess(), dst);
460 uploadImageAspect(src, dst);
463 tcu::TestStatus CopiesAndBlittingTestInstance::checkTestResult (tcu::ConstPixelBufferAccess result)
465 const tcu::ConstPixelBufferAccess expected = m_expectedTextureLevel->getAccess();
467 if (isFloatFormat(result.getFormat()))
469 const tcu::Vec4 threshold (0.0f);
470 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
471 return tcu::TestStatus::fail("CopiesAndBlitting test");
475 const tcu::UVec4 threshold (0u);
476 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
477 return tcu::TestStatus::fail("CopiesAndBlitting test");
480 return tcu::TestStatus::pass("CopiesAndBlitting test");
483 void CopiesAndBlittingTestInstance::generateExpectedResult (void)
485 const tcu::ConstPixelBufferAccess src = m_sourceTextureLevel->getAccess();
486 const tcu::ConstPixelBufferAccess dst = m_destinationTextureLevel->getAccess();
488 m_expectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
489 tcu::copy(m_expectedTextureLevel->getAccess(), dst);
490 for (deUint32 i = 0; i < m_params.regions.size(); i++)
491 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), m_params.regions[i]);
494 class CopiesAndBlittingTestCase : public vkt::TestCase
497 CopiesAndBlittingTestCase (tcu::TestContext& testCtx,
498 const std::string& name,
499 const std::string& description)
500 : vkt::TestCase (testCtx, name, description)
503 virtual TestInstance* createInstance (Context& context) const = 0;
506 void CopiesAndBlittingTestInstance::readImageAspect (vk::VkImage image,
507 const tcu::PixelBufferAccess& dst)
509 const DeviceInterface& vk = m_context.getDeviceInterface();
510 const VkDevice device = m_context.getDevice();
511 const VkQueue queue = m_context.getUniversalQueue();
512 Allocator& allocator = m_context.getDefaultAllocator();
514 Move<VkBuffer> buffer;
515 de::MovePtr<Allocation> bufferAlloc;
516 Move<VkCommandBuffer> cmdBuffer;
517 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
518 const VkDeviceSize pixelDataSize = calculateSize(dst);
520 // Create destination buffer
522 const VkBufferCreateInfo bufferParams =
524 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
525 DE_NULL, // const void* pNext;
526 0u, // VkBufferCreateFlags flags;
527 pixelDataSize, // VkDeviceSize size;
528 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
529 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
530 1u, // deUint32 queueFamilyIndexCount;
531 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
534 buffer = createBuffer(vk, device, &bufferParams);
535 bufferAlloc = allocator.allocate(getBufferMemoryRequirements(vk, device, *buffer), MemoryRequirement::HostVisible);
536 VK_CHECK(vk.bindBufferMemory(device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
539 // Create command pool and buffer
541 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
543 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
544 DE_NULL, // const void* pNext;
545 *m_cmdPool, // VkCommandPool commandPool;
546 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
547 1u // deUint32 bufferCount;
550 cmdBuffer = allocateCommandBuffer(vk, device, &cmdBufferAllocateInfo);
553 // Barriers for copying image to buffer
554 const VkImageAspectFlags aspect = getAspectFlags(dst.getFormat());
555 const VkImageMemoryBarrier imageBarrier =
557 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
558 DE_NULL, // const void* pNext;
559 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
560 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
561 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
562 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
563 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
564 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
565 image, // VkImage image;
566 { // VkImageSubresourceRange subresourceRange;
567 aspect, // VkImageAspectFlags aspectMask;
568 0u, // deUint32 baseMipLevel;
569 1u, // deUint32 mipLevels;
570 0u, // deUint32 baseArraySlice;
571 1u // deUint32 arraySize;
575 const VkBufferMemoryBarrier bufferBarrier =
577 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
578 DE_NULL, // const void* pNext;
579 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
580 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
581 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
582 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
583 *buffer, // VkBuffer buffer;
584 0u, // VkDeviceSize offset;
585 pixelDataSize // VkDeviceSize size;
588 const VkImageMemoryBarrier postImageBarrier =
590 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
591 DE_NULL, // const void* pNext;
592 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags srcAccessMask;
593 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
594 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout oldLayout;
595 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
596 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
597 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
598 image, // VkImage image;
600 aspect, // VkImageAspectFlags aspectMask;
601 0u, // deUint32 baseMipLevel;
602 1u, // deUint32 mipLevels;
603 0u, // deUint32 baseArraySlice;
604 1u, // deUint32 arraySize;
605 } // VkImageSubresourceRange subresourceRange;
608 // Copy image to buffer
609 const VkExtent3D imageExtent = { (deUint32)dst.getWidth(), (deUint32)dst.getHeight(), 1u };
610 const VkBufferImageCopy copyRegion =
612 0u, // VkDeviceSize bufferOffset;
613 (deUint32)dst.getWidth(), // deUint32 bufferRowLength;
614 (deUint32)dst.getHeight(), // deUint32 bufferImageHeight;
616 aspect, // VkImageAspectFlags aspect;
617 0u, // deUint32 mipLevel;
618 0u, // deUint32 baseArrayLayer;
619 1u, // deUint32 layerCount;
620 }, // VkImageSubresourceLayers imageSubresource;
621 { 0, 0, 0 }, // VkOffset3D imageOffset;
622 imageExtent // VkExtent3D imageExtent;
625 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
627 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
628 DE_NULL, // const void* pNext;
629 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
630 (const VkCommandBufferInheritanceInfo*)DE_NULL,
633 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
634 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
635 vk.cmdCopyImageToBuffer(*cmdBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, 1u, ©Region);
636 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT|VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 1, &postImageBarrier);
637 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
639 const VkSubmitInfo submitInfo =
641 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
642 DE_NULL, // const void* pNext;
643 0u, // deUint32 waitSemaphoreCount;
644 DE_NULL, // const VkSemaphore* pWaitSemaphores;
645 (const VkPipelineStageFlags*)DE_NULL,
646 1u, // deUint32 commandBufferCount;
647 &cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
648 0u, // deUint32 signalSemaphoreCount;
649 DE_NULL // const VkSemaphore* pSignalSemaphores;
652 VK_CHECK(vk.resetFences(device, 1, &m_fence.get()));
653 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
654 VK_CHECK(vk.waitForFences(device, 1, &m_fence.get(), 0, ~(0ull) /* infinity */));
657 invalidateMappedMemoryRange(vk, device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), pixelDataSize);
658 tcu::copy(dst, tcu::ConstPixelBufferAccess(dst.getFormat(), dst.getSize(), bufferAlloc->getHostPtr()));
661 de::MovePtr<tcu::TextureLevel> CopiesAndBlittingTestInstance::readImage (vk::VkImage image,
663 const VkExtent3D imageSize)
665 const tcu::TextureFormat imageFormat = mapVkFormat(format);
666 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(imageFormat, imageSize.width, imageSize.height, imageSize.depth));
668 if (tcu::isCombinedDepthStencilType(imageFormat.type))
670 if (tcu::hasDepthComponent(imageFormat.order))
672 tcu::TextureLevel depthTexture (mapCombinedToDepthTransferFormat(imageFormat), imageSize.width, imageSize.height, imageSize.depth);
673 readImageAspect(image, depthTexture.getAccess());
674 tcu::copy(tcu::getEffectiveDepthStencilAccess(resultLevel->getAccess(), tcu::Sampler::MODE_DEPTH), depthTexture.getAccess());
677 if (tcu::hasStencilComponent(imageFormat.order))
679 tcu::TextureLevel stencilTexture (tcu::getEffectiveDepthStencilTextureFormat(imageFormat, tcu::Sampler::MODE_STENCIL), imageSize.width, imageSize.height, imageSize.depth);
680 readImageAspect(image, stencilTexture.getAccess());
681 tcu::copy(tcu::getEffectiveDepthStencilAccess(resultLevel->getAccess(), tcu::Sampler::MODE_STENCIL), stencilTexture.getAccess());
685 readImageAspect(image, resultLevel->getAccess());
690 // Copy from image to image.
692 class CopyImageToImage : public CopiesAndBlittingTestInstance
695 CopyImageToImage (Context& context,
697 virtual tcu::TestStatus iterate (void);
699 Move<VkImage> m_source;
700 de::MovePtr<Allocation> m_sourceImageAlloc;
701 Move<VkImage> m_destination;
702 de::MovePtr<Allocation> m_destinationImageAlloc;
704 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
707 CopyImageToImage::CopyImageToImage (Context& context, TestParams params)
708 : CopiesAndBlittingTestInstance(context, params)
710 const DeviceInterface& vk = context.getDeviceInterface();
711 const VkDevice vkDevice = context.getDevice();
712 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
713 Allocator& memAlloc = context.getDefaultAllocator();
715 VkImageFormatProperties properties;
716 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
717 m_params.src.image.format,
719 VK_IMAGE_TILING_OPTIMAL,
720 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
722 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
723 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
724 m_params.dst.image.format,
726 VK_IMAGE_TILING_OPTIMAL,
727 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
729 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
731 TCU_THROW(NotSupportedError, "Format not supported");
734 // Create source image
736 const VkImageCreateInfo sourceImageParams =
738 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
739 DE_NULL, // const void* pNext;
740 0u, // VkImageCreateFlags flags;
741 VK_IMAGE_TYPE_2D, // VkImageType imageType;
742 m_params.src.image.format, // VkFormat format;
743 m_params.src.image.extent, // VkExtent3D extent;
744 1u, // deUint32 mipLevels;
745 1u, // deUint32 arraySize;
746 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
747 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
748 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
749 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
750 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
751 1u, // deUint32 queueFamilyCount;
752 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
753 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
756 m_source = createImage(vk, vkDevice, &sourceImageParams);
757 m_sourceImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
758 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
761 // Create destination image
763 const VkImageCreateInfo destinationImageParams =
765 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
766 DE_NULL, // const void* pNext;
767 0u, // VkImageCreateFlags flags;
768 VK_IMAGE_TYPE_2D, // VkImageType imageType;
769 m_params.dst.image.format, // VkFormat format;
770 m_params.dst.image.extent, // VkExtent3D extent;
771 1u, // deUint32 mipLevels;
772 1u, // deUint32 arraySize;
773 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
774 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
775 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
776 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
777 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
778 1u, // deUint32 queueFamilyCount;
779 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
780 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
783 m_destination = createImage(vk, vkDevice, &destinationImageParams);
784 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
785 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
789 tcu::TestStatus CopyImageToImage::iterate (void)
791 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
792 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
793 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
794 m_params.src.image.extent.width,
795 m_params.src.image.extent.height,
796 m_params.src.image.extent.depth));
797 generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_WHITE);
798 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
799 (int)m_params.dst.image.extent.width,
800 (int)m_params.dst.image.extent.height,
801 (int)m_params.dst.image.extent.depth));
802 generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth, FILL_MODE_GRADIENT);
803 generateExpectedResult();
805 uploadImage(m_sourceTextureLevel->getAccess(), m_source.get());
806 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
808 const DeviceInterface& vk = m_context.getDeviceInterface();
809 const VkDevice vkDevice = m_context.getDevice();
810 const VkQueue queue = m_context.getUniversalQueue();
812 std::vector<VkImageCopy> imageCopies;
813 for (deUint32 i = 0; i < m_params.regions.size(); i++)
814 imageCopies.push_back(m_params.regions[i].imageCopy);
816 const VkImageMemoryBarrier imageBarriers[] =
820 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
821 DE_NULL, // const void* pNext;
822 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
823 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
824 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
825 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
826 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
827 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
828 m_source.get(), // VkImage image;
829 { // VkImageSubresourceRange subresourceRange;
830 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
831 0u, // deUint32 baseMipLevel;
832 1u, // deUint32 mipLevels;
833 0u, // deUint32 baseArraySlice;
834 1u // deUint32 arraySize;
839 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
840 DE_NULL, // const void* pNext;
841 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
842 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
843 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
844 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
845 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
846 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
847 m_destination.get(), // VkImage image;
848 { // VkImageSubresourceRange subresourceRange;
849 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
850 0u, // deUint32 baseMipLevel;
851 1u, // deUint32 mipLevels;
852 0u, // deUint32 baseArraySlice;
853 1u // deUint32 arraySize;
858 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
860 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
861 DE_NULL, // const void* pNext;
862 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
863 (const VkCommandBufferInheritanceInfo*)DE_NULL,
866 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
867 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, DE_LENGTH_OF_ARRAY(imageBarriers), imageBarriers);
868 vk.cmdCopyImage(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), imageCopies.data());
869 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
871 const VkSubmitInfo submitInfo =
873 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
874 DE_NULL, // const void* pNext;
875 0u, // deUint32 waitSemaphoreCount;
876 DE_NULL, // const VkSemaphore* pWaitSemaphores;
877 (const VkPipelineStageFlags*)DE_NULL,
878 1u, // deUint32 commandBufferCount;
879 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
880 0u, // deUint32 signalSemaphoreCount;
881 DE_NULL // const VkSemaphore* pSignalSemaphores;
884 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
885 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
886 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
888 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
890 return checkTestResult(resultTextureLevel->getAccess());
893 void CopyImageToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
895 VkOffset3D srcOffset = region.imageCopy.srcOffset;
896 VkOffset3D dstOffset = region.imageCopy.dstOffset;
897 VkExtent3D extent = region.imageCopy.extent;
899 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
901 DE_ASSERT(src.getFormat() == dst.getFormat());
904 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
905 const tcu::PixelBufferAccess dstWithSrcFormat(srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
906 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
908 tcu::copy(dstSubRegion, srcSubRegion);
912 if (tcu::hasStencilComponent(src.getFormat().order))
914 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
915 const tcu::PixelBufferAccess dstWithSrcFormat(srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
916 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
918 tcu::copy(dstSubRegion, srcSubRegion);
923 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth);
924 // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
925 const tcu::PixelBufferAccess dstWithSrcFormat (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
926 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth);
928 tcu::copy(dstSubRegion, srcSubRegion);
932 class CopyImageToImageTestCase : public vkt::TestCase
935 CopyImageToImageTestCase (tcu::TestContext& testCtx,
936 const std::string& name,
937 const std::string& description,
938 const TestParams params)
939 : vkt::TestCase (testCtx, name, description)
943 virtual TestInstance* createInstance (Context& context) const
945 return new CopyImageToImage(context, m_params);
951 // Copy from buffer to buffer.
953 class CopyBufferToBuffer : public CopiesAndBlittingTestInstance
956 CopyBufferToBuffer (Context& context, TestParams params);
957 virtual tcu::TestStatus iterate (void);
959 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess, tcu::PixelBufferAccess, CopyRegion);
960 Move<VkBuffer> m_source;
961 de::MovePtr<Allocation> m_sourceBufferAlloc;
962 Move<VkBuffer> m_destination;
963 de::MovePtr<Allocation> m_destinationBufferAlloc;
966 CopyBufferToBuffer::CopyBufferToBuffer (Context& context, TestParams params)
967 : CopiesAndBlittingTestInstance (context, params)
969 const DeviceInterface& vk = context.getDeviceInterface();
970 const VkDevice vkDevice = context.getDevice();
971 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
972 Allocator& memAlloc = context.getDefaultAllocator();
974 // Create source buffer
976 const VkBufferCreateInfo sourceBufferParams =
978 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
979 DE_NULL, // const void* pNext;
980 0u, // VkBufferCreateFlags flags;
981 m_params.src.buffer.size, // VkDeviceSize size;
982 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
983 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
984 1u, // deUint32 queueFamilyIndexCount;
985 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
988 m_source = createBuffer(vk, vkDevice, &sourceBufferParams);
989 m_sourceBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::HostVisible);
990 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
993 // Create destination buffer
995 const VkBufferCreateInfo destinationBufferParams =
997 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
998 DE_NULL, // const void* pNext;
999 0u, // VkBufferCreateFlags flags;
1000 m_params.dst.buffer.size, // VkDeviceSize size;
1001 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
1002 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1003 1u, // deUint32 queueFamilyIndexCount;
1004 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1007 m_destination = createBuffer(vk, vkDevice, &destinationBufferParams);
1008 m_destinationBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::HostVisible);
1009 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
1013 tcu::TestStatus CopyBufferToBuffer::iterate (void)
1015 const int srcLevelWidth = (int)(m_params.src.buffer.size/4); // Here the format is VK_FORMAT_R32_UINT, we need to divide the buffer size by 4
1016 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), srcLevelWidth, 1));
1017 generateBuffer(m_sourceTextureLevel->getAccess(), srcLevelWidth, 1, 1, FILL_MODE_RED);
1019 const int dstLevelWidth = (int)(m_params.dst.buffer.size/4);
1020 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
1021 generateBuffer(m_destinationTextureLevel->getAccess(), dstLevelWidth, 1, 1, FILL_MODE_WHITE);
1023 generateExpectedResult();
1025 uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
1026 uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
1028 const DeviceInterface& vk = m_context.getDeviceInterface();
1029 const VkDevice vkDevice = m_context.getDevice();
1030 const VkQueue queue = m_context.getUniversalQueue();
1032 const VkBufferMemoryBarrier srcBufferBarrier =
1034 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1035 DE_NULL, // const void* pNext;
1036 VK_ACCESS_HOST_WRITE_BIT, // VkAccessFlags srcAccessMask;
1037 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1038 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1039 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1040 *m_source, // VkBuffer buffer;
1041 0u, // VkDeviceSize offset;
1042 m_params.src.buffer.size // VkDeviceSize size;
1045 const VkBufferMemoryBarrier dstBufferBarrier =
1047 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1048 DE_NULL, // const void* pNext;
1049 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1050 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
1051 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1052 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1053 *m_destination, // VkBuffer buffer;
1054 0u, // VkDeviceSize offset;
1055 m_params.dst.buffer.size // VkDeviceSize size;
1058 std::vector<VkBufferCopy> bufferCopies;
1059 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1060 bufferCopies.push_back(m_params.regions[i].bufferCopy);
1062 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1064 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1065 DE_NULL, // const void* pNext;
1066 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1067 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1070 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1071 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &srcBufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1072 vk.cmdCopyBuffer(*m_cmdBuffer, m_source.get(), m_destination.get(), (deUint32)m_params.regions.size(), &bufferCopies[0]);
1073 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &dstBufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1074 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1076 const VkSubmitInfo submitInfo =
1078 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1079 DE_NULL, // const void* pNext;
1080 0u, // deUint32 waitSemaphoreCount;
1081 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1082 (const VkPipelineStageFlags*)DE_NULL,
1083 1u, // deUint32 commandBufferCount;
1084 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1085 0u, // deUint32 signalSemaphoreCount;
1086 DE_NULL // const VkSemaphore* pSignalSemaphores;
1089 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1090 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1091 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1094 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
1095 invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_params.dst.buffer.size);
1096 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1098 return checkTestResult(resultLevel->getAccess());
1101 void CopyBufferToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1103 deMemcpy((deUint8*) dst.getDataPtr() + region.bufferCopy.dstOffset,
1104 (deUint8*) src.getDataPtr() + region.bufferCopy.srcOffset,
1105 (size_t)region.bufferCopy.size);
1108 class BufferToBufferTestCase : public vkt::TestCase
1111 BufferToBufferTestCase (tcu::TestContext& testCtx,
1112 const std::string& name,
1113 const std::string& description,
1114 const TestParams params)
1115 : vkt::TestCase (testCtx, name, description)
1119 virtual TestInstance* createInstance (Context& context) const
1121 return new CopyBufferToBuffer(context, m_params);
1124 TestParams m_params;
1127 // Copy from image to buffer.
1129 class CopyImageToBuffer : public CopiesAndBlittingTestInstance
1132 CopyImageToBuffer (Context& context,
1133 TestParams testParams);
1134 virtual tcu::TestStatus iterate (void);
1136 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1138 tcu::TextureFormat m_textureFormat;
1139 VkDeviceSize m_bufferSize;
1141 Move<VkImage> m_source;
1142 de::MovePtr<Allocation> m_sourceImageAlloc;
1143 Move<VkBuffer> m_destination;
1144 de::MovePtr<Allocation> m_destinationBufferAlloc;
1147 CopyImageToBuffer::CopyImageToBuffer (Context& context, TestParams testParams)
1148 : CopiesAndBlittingTestInstance(context, testParams)
1149 , m_textureFormat(mapVkFormat(testParams.src.image.format))
1150 , m_bufferSize(m_params.dst.buffer.size * tcu::getPixelSize(m_textureFormat))
1152 const DeviceInterface& vk = context.getDeviceInterface();
1153 const VkDevice vkDevice = context.getDevice();
1154 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1155 Allocator& memAlloc = context.getDefaultAllocator();
1157 // Create source image
1159 const VkImageCreateInfo sourceImageParams =
1161 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1162 DE_NULL, // const void* pNext;
1163 0u, // VkImageCreateFlags flags;
1164 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1165 m_params.src.image.format, // VkFormat format;
1166 m_params.src.image.extent, // VkExtent3D extent;
1167 1u, // deUint32 mipLevels;
1168 1u, // deUint32 arraySize;
1169 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1170 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1171 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1172 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1173 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1174 1u, // deUint32 queueFamilyCount;
1175 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1176 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1179 m_source = createImage(vk, vkDevice, &sourceImageParams);
1180 m_sourceImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
1181 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1184 // Create destination buffer
1186 const VkBufferCreateInfo destinationBufferParams =
1188 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1189 DE_NULL, // const void* pNext;
1190 0u, // VkBufferCreateFlags flags;
1191 m_bufferSize, // VkDeviceSize size;
1192 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
1193 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1194 1u, // deUint32 queueFamilyIndexCount;
1195 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1198 m_destination = createBuffer(vk, vkDevice, &destinationBufferParams);
1199 m_destinationBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::HostVisible);
1200 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
1204 tcu::TestStatus CopyImageToBuffer::iterate (void)
1206 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1207 m_params.src.image.extent.width,
1208 m_params.src.image.extent.height,
1209 m_params.src.image.extent.depth));
1210 generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_RED);
1211 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1212 generateBuffer(m_destinationTextureLevel->getAccess(), (int)m_params.dst.buffer.size, 1, 1);
1214 generateExpectedResult();
1216 uploadImage(m_sourceTextureLevel->getAccess(), *m_source);
1217 uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
1219 const DeviceInterface& vk = m_context.getDeviceInterface();
1220 const VkDevice vkDevice = m_context.getDevice();
1221 const VkQueue queue = m_context.getUniversalQueue();
1223 // Barriers for copying image to buffer
1224 const VkImageMemoryBarrier imageBarrier =
1226 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1227 DE_NULL, // const void* pNext;
1228 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1229 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1230 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1231 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
1232 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1233 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1234 *m_source, // VkImage image;
1235 { // VkImageSubresourceRange subresourceRange;
1236 getAspectFlags(m_textureFormat), // VkImageAspectFlags aspectMask;
1237 0u, // deUint32 baseMipLevel;
1238 1u, // deUint32 mipLevels;
1239 0u, // deUint32 baseArraySlice;
1240 1u // deUint32 arraySize;
1244 const VkBufferMemoryBarrier bufferBarrier =
1246 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1247 DE_NULL, // const void* pNext;
1248 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1249 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
1250 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1251 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1252 *m_destination, // VkBuffer buffer;
1253 0u, // VkDeviceSize offset;
1254 m_bufferSize // VkDeviceSize size;
1257 // Copy from image to buffer
1258 std::vector<VkBufferImageCopy> bufferImageCopies;
1259 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1260 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1262 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1264 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1265 DE_NULL, // const void* pNext;
1266 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1267 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1270 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1271 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
1272 vk.cmdCopyImageToBuffer(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), (deUint32)m_params.regions.size(), &bufferImageCopies[0]);
1273 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &bufferBarrier, 0, (const VkImageMemoryBarrier*)DE_NULL);
1274 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1276 const VkSubmitInfo submitInfo =
1278 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1279 DE_NULL, // const void* pNext;
1280 0u, // deUint32 waitSemaphoreCount;
1281 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1282 (const VkPipelineStageFlags*)DE_NULL,
1283 1u, // deUint32 commandBufferCount;
1284 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1285 0u, // deUint32 signalSemaphoreCount;
1286 DE_NULL // const VkSemaphore* pSignalSemaphores;
1289 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1290 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1291 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1294 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1295 invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_bufferSize);
1296 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1298 return checkTestResult(resultLevel->getAccess());
1301 class CopyImageToBufferTestCase : public vkt::TestCase
1304 CopyImageToBufferTestCase (tcu::TestContext& testCtx,
1305 const std::string& name,
1306 const std::string& description,
1307 const TestParams params)
1308 : vkt::TestCase (testCtx, name, description)
1312 virtual TestInstance* createInstance (Context& context) const
1314 return new CopyImageToBuffer(context, m_params);
1317 TestParams m_params;
1320 void CopyImageToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1322 deUint32 rowLength = region.bufferImageCopy.bufferRowLength;
1324 rowLength = region.bufferImageCopy.imageExtent.width;
1326 deUint32 imageHeight = region.bufferImageCopy.bufferImageHeight;
1328 imageHeight = region.bufferImageCopy.imageExtent.height;
1330 const int texelSize = src.getFormat().getPixelSize();
1331 const VkExtent3D extent = region.bufferImageCopy.imageExtent;
1332 const VkOffset3D srcOffset = region.bufferImageCopy.imageOffset;
1333 const int texelOffset = (int) region.bufferImageCopy.bufferOffset / texelSize;
1335 for (deUint32 z = 0; z < extent.depth; z++)
1337 for (deUint32 y = 0; y < extent.height; y++)
1339 int texelIndex = texelOffset + (z * imageHeight + y) * rowLength;
1340 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y + y, srcOffset.z + z,
1341 region.bufferImageCopy.imageExtent.width, 1, 1);
1342 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1343 tcu::copy(dstSubRegion, srcSubRegion);
1348 // Copy from buffer to image.
1350 class CopyBufferToImage : public CopiesAndBlittingTestInstance
1353 CopyBufferToImage (Context& context,
1354 TestParams testParams);
1355 virtual tcu::TestStatus iterate (void);
1357 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1359 tcu::TextureFormat m_textureFormat;
1360 VkDeviceSize m_bufferSize;
1362 Move<VkBuffer> m_source;
1363 de::MovePtr<Allocation> m_sourceBufferAlloc;
1364 Move<VkImage> m_destination;
1365 de::MovePtr<Allocation> m_destinationImageAlloc;
1368 CopyBufferToImage::CopyBufferToImage (Context& context, TestParams testParams)
1369 : CopiesAndBlittingTestInstance(context, testParams)
1370 , m_textureFormat(mapVkFormat(testParams.dst.image.format))
1371 , m_bufferSize(m_params.src.buffer.size * tcu::getPixelSize(m_textureFormat))
1373 const DeviceInterface& vk = context.getDeviceInterface();
1374 const VkDevice vkDevice = context.getDevice();
1375 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1376 Allocator& memAlloc = context.getDefaultAllocator();
1378 // Create source buffer
1380 const VkBufferCreateInfo sourceBufferParams =
1382 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1383 DE_NULL, // const void* pNext;
1384 0u, // VkBufferCreateFlags flags;
1385 m_bufferSize, // VkDeviceSize size;
1386 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
1387 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1388 1u, // deUint32 queueFamilyIndexCount;
1389 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1392 m_source = createBuffer(vk, vkDevice, &sourceBufferParams);
1393 m_sourceBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::HostVisible);
1394 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
1397 // Create destination image
1399 const VkImageCreateInfo destinationImageParams =
1401 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1402 DE_NULL, // const void* pNext;
1403 0u, // VkImageCreateFlags flags;
1404 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1405 m_params.dst.image.format, // VkFormat format;
1406 m_params.dst.image.extent, // VkExtent3D extent;
1407 1u, // deUint32 mipLevels;
1408 1u, // deUint32 arraySize;
1409 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1410 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1411 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1412 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1413 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1414 1u, // deUint32 queueFamilyCount;
1415 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1416 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1419 m_destination = createImage(vk, vkDevice, &destinationImageParams);
1420 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
1421 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1425 tcu::TestStatus CopyBufferToImage::iterate (void)
1427 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.src.buffer.size, 1));
1428 generateBuffer(m_sourceTextureLevel->getAccess(), (int)m_params.src.buffer.size, 1, 1);
1429 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1430 m_params.dst.image.extent.width,
1431 m_params.dst.image.extent.height,
1432 m_params.dst.image.extent.depth));
1434 generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth, FILL_MODE_WHITE);
1436 generateExpectedResult();
1438 uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
1439 uploadImage(m_destinationTextureLevel->getAccess(), *m_destination);
1441 const DeviceInterface& vk = m_context.getDeviceInterface();
1442 const VkDevice vkDevice = m_context.getDevice();
1443 const VkQueue queue = m_context.getUniversalQueue();
1445 const VkImageMemoryBarrier imageBarrier =
1447 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1448 DE_NULL, // const void* pNext;
1449 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1450 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
1451 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1452 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
1453 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1454 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1455 *m_destination, // VkImage image;
1456 { // VkImageSubresourceRange subresourceRange;
1457 getAspectFlags(m_textureFormat), // VkImageAspectFlags aspectMask;
1458 0u, // deUint32 baseMipLevel;
1459 1u, // deUint32 mipLevels;
1460 0u, // deUint32 baseArraySlice;
1461 1u // deUint32 arraySize;
1465 // Copy from buffer to image
1466 std::vector<VkBufferImageCopy> bufferImageCopies;
1467 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1468 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1470 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1472 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1473 DE_NULL, // const void* pNext;
1474 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1475 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1478 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1479 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &imageBarrier);
1480 vk.cmdCopyBufferToImage(*m_cmdBuffer, m_source.get(), m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), bufferImageCopies.data());
1481 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1483 const VkSubmitInfo submitInfo =
1485 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1486 DE_NULL, // const void* pNext;
1487 0u, // deUint32 waitSemaphoreCount;
1488 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1489 (const VkPipelineStageFlags*)DE_NULL,
1490 1u, // deUint32 commandBufferCount;
1491 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1492 0u, // deUint32 signalSemaphoreCount;
1493 DE_NULL // const VkSemaphore* pSignalSemaphores;
1496 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1497 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1498 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1500 de::MovePtr<tcu::TextureLevel> resultLevel = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
1502 return checkTestResult(resultLevel->getAccess());
1505 class CopyBufferToImageTestCase : public vkt::TestCase
1508 CopyBufferToImageTestCase (tcu::TestContext& testCtx,
1509 const std::string& name,
1510 const std::string& description,
1511 const TestParams params)
1512 : vkt::TestCase (testCtx, name, description)
1516 virtual ~CopyBufferToImageTestCase (void) {}
1518 virtual TestInstance* createInstance (Context& context) const
1520 return new CopyBufferToImage(context, m_params);
1523 TestParams m_params;
1526 void CopyBufferToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1528 deUint32 rowLength = region.bufferImageCopy.bufferRowLength;
1530 rowLength = region.bufferImageCopy.imageExtent.width;
1532 deUint32 imageHeight = region.bufferImageCopy.bufferImageHeight;
1534 imageHeight = region.bufferImageCopy.imageExtent.height;
1536 const int texelSize = dst.getFormat().getPixelSize();
1537 const VkExtent3D extent = region.bufferImageCopy.imageExtent;
1538 const VkOffset3D dstOffset = region.bufferImageCopy.imageOffset;
1539 const int texelOffset = (int) region.bufferImageCopy.bufferOffset / texelSize;
1541 for (deUint32 z = 0; z < extent.depth; z++)
1543 for (deUint32 y = 0; y < extent.height; y++)
1545 int texelIndex = texelOffset + (z * imageHeight + y) * rowLength;
1546 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1547 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, dstOffset.x, dstOffset.y + y, dstOffset.z + z,
1548 region.bufferImageCopy.imageExtent.width, 1, 1);
1549 tcu::copy(dstSubRegion, srcSubRegion);
1554 // Copy from image to image with scaling.
1556 class BlittingImages : public CopiesAndBlittingTestInstance
1559 BlittingImages (Context& context,
1561 virtual tcu::TestStatus iterate (void);
1563 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
1564 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1565 virtual void generateExpectedResult (void);
1567 bool checkClampedAndUnclampedResult (const tcu::ConstPixelBufferAccess& result,
1568 const tcu::ConstPixelBufferAccess& clampedReference,
1569 const tcu::ConstPixelBufferAccess& unclampedReference,
1570 VkImageAspectFlagBits aspect);
1571 Move<VkImage> m_source;
1572 de::MovePtr<Allocation> m_sourceImageAlloc;
1573 Move<VkImage> m_destination;
1574 de::MovePtr<Allocation> m_destinationImageAlloc;
1576 de::MovePtr<tcu::TextureLevel> m_unclampedExpectedTextureLevel;
1579 BlittingImages::BlittingImages (Context& context, TestParams params)
1580 : CopiesAndBlittingTestInstance(context, params)
1582 const DeviceInterface& vk = context.getDeviceInterface();
1583 const VkDevice vkDevice = context.getDevice();
1584 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1585 Allocator& memAlloc = context.getDefaultAllocator();
1587 VkImageFormatProperties properties;
1588 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1589 m_params.src.image.format,
1591 VK_IMAGE_TILING_OPTIMAL,
1592 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
1594 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
1595 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1596 m_params.dst.image.format,
1598 VK_IMAGE_TILING_OPTIMAL,
1599 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1601 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
1603 TCU_THROW(NotSupportedError, "Format not supported");
1606 VkFormatProperties srcFormatProperties;
1607 context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.src.image.format, &srcFormatProperties);
1608 if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
1610 TCU_THROW(NotSupportedError, "Format feature blit source not supported");
1613 VkFormatProperties dstFormatProperties;
1614 context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.dst.image.format, &dstFormatProperties);
1615 if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
1617 TCU_THROW(NotSupportedError, "Format feature blit destination not supported");
1620 if (m_params.filter == VK_FILTER_LINEAR)
1622 if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1623 TCU_THROW(NotSupportedError, "Source format feature sampled image filter linear not supported");
1624 if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1625 TCU_THROW(NotSupportedError, "Destination format feature sampled image filter linear not supported");
1628 // Create source image
1630 const VkImageCreateInfo sourceImageParams =
1632 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1633 DE_NULL, // const void* pNext;
1634 0u, // VkImageCreateFlags flags;
1635 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1636 m_params.src.image.format, // VkFormat format;
1637 m_params.src.image.extent, // VkExtent3D extent;
1638 1u, // deUint32 mipLevels;
1639 1u, // deUint32 arraySize;
1640 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1641 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1642 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1643 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1644 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1645 1u, // deUint32 queueFamilyCount;
1646 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1647 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1650 m_source = createImage(vk, vkDevice, &sourceImageParams);
1651 m_sourceImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
1652 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1655 // Create destination image
1657 const VkImageCreateInfo destinationImageParams =
1659 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1660 DE_NULL, // const void* pNext;
1661 0u, // VkImageCreateFlags flags;
1662 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1663 m_params.dst.image.format, // VkFormat format;
1664 m_params.dst.image.extent, // VkExtent3D extent;
1665 1u, // deUint32 mipLevels;
1666 1u, // deUint32 arraySize;
1667 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1668 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1669 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1670 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1671 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1672 1u, // deUint32 queueFamilyCount;
1673 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1674 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1677 m_destination = createImage(vk, vkDevice, &destinationImageParams);
1678 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
1679 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1683 tcu::TestStatus BlittingImages::iterate (void)
1685 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
1686 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
1687 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
1688 m_params.src.image.extent.width,
1689 m_params.src.image.extent.height,
1690 m_params.src.image.extent.depth));
1691 generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_GRADIENT);
1692 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
1693 (int)m_params.dst.image.extent.width,
1694 (int)m_params.dst.image.extent.height,
1695 (int)m_params.dst.image.extent.depth));
1696 generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth, FILL_MODE_WHITE);
1697 generateExpectedResult();
1699 uploadImage(m_sourceTextureLevel->getAccess(), m_source.get());
1700 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
1702 const DeviceInterface& vk = m_context.getDeviceInterface();
1703 const VkDevice vkDevice = m_context.getDevice();
1704 const VkQueue queue = m_context.getUniversalQueue();
1706 std::vector<VkImageBlit> regions;
1707 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1708 regions.push_back(m_params.regions[i].imageBlit);
1710 // Barriers for copying image to buffer
1711 const VkImageMemoryBarrier srcImageBarrier =
1713 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1714 DE_NULL, // const void* pNext;
1715 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1716 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1717 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1718 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
1719 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1720 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1721 m_source.get(), // VkImage image;
1722 { // VkImageSubresourceRange subresourceRange;
1723 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
1724 0u, // deUint32 baseMipLevel;
1725 1u, // deUint32 mipLevels;
1726 0u, // deUint32 baseArraySlice;
1727 1u // deUint32 arraySize;
1731 const VkImageMemoryBarrier dstImageBarrier =
1733 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1734 DE_NULL, // const void* pNext;
1735 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1736 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
1737 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1738 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
1739 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1740 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1741 m_destination.get(), // VkImage image;
1742 { // VkImageSubresourceRange subresourceRange;
1743 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
1744 0u, // deUint32 baseMipLevel;
1745 1u, // deUint32 mipLevels;
1746 0u, // deUint32 baseArraySlice;
1747 1u // deUint32 arraySize;
1751 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1753 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1754 DE_NULL, // const void* pNext;
1755 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1756 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1759 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1760 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &srcImageBarrier);
1761 vk.cmdBlitImage(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), ®ions[0], m_params.filter);
1762 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &dstImageBarrier);
1763 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1765 const VkSubmitInfo submitInfo =
1767 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1768 DE_NULL, // const void* pNext;
1769 0u, // deUint32 waitSemaphoreCount;
1770 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1771 (const VkPipelineStageFlags*)DE_NULL,
1772 1u, // deUint32 commandBufferCount;
1773 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1774 0u, // deUint32 signalSemaphoreCount;
1775 DE_NULL // const VkSemaphore* pSignalSemaphores;
1778 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1779 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1780 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1782 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
1784 return checkTestResult(resultTextureLevel->getAccess());
1787 static float calculateFloatConversionError (int srcBits)
1791 const int clampedBits = de::clamp<int>(srcBits, 0, 32);
1792 const float srcMaxValue = de::max((float)(1ULL<<clampedBits) - 1.0f, 1.0f);
1793 const float error = 1.0f / srcMaxValue;
1795 return de::clamp<float>(error, 0.0f, 1.0f);
1801 tcu::Vec4 getFormatThreshold (const tcu::TextureFormat& format)
1803 tcu::Vec4 threshold(0.01f);
1805 switch (format.type)
1807 case tcu::TextureFormat::HALF_FLOAT:
1808 threshold = tcu::Vec4(0.005f);
1811 case tcu::TextureFormat::FLOAT:
1812 case tcu::TextureFormat::FLOAT64:
1813 threshold = tcu::Vec4(0.001f);
1816 case tcu::TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
1817 threshold = tcu::Vec4(0.02f, 0.02f, 0.0625f, 1.0f);
1820 case tcu::TextureFormat::UNSIGNED_INT_999_E5_REV:
1821 threshold = tcu::Vec4(0.05f, 0.05f, 0.05f, 1.0f);
1825 const tcu::IVec4 bits = tcu::getTextureFormatMantissaBitDepth(format);
1826 threshold = tcu::Vec4(calculateFloatConversionError(bits.x()),
1827 calculateFloatConversionError(bits.y()),
1828 calculateFloatConversionError(bits.z()),
1829 calculateFloatConversionError(bits.w()));
1832 // Return value matching the channel order specified by the format
1833 if (format.order == tcu::TextureFormat::BGR || format.order == tcu::TextureFormat::BGRA)
1834 return threshold.swizzle(2, 1, 0, 3);
1839 tcu::TextureFormat getFormatAspect (VkFormat format, VkImageAspectFlagBits aspect)
1841 const tcu::TextureFormat baseFormat = mapVkFormat(format);
1843 if (isCombinedDepthStencilType(baseFormat.type))
1845 if (aspect == VK_IMAGE_ASPECT_DEPTH_BIT)
1846 return getEffectiveDepthStencilTextureFormat(baseFormat, tcu::Sampler::MODE_DEPTH);
1847 else if (aspect == VK_IMAGE_ASPECT_STENCIL_BIT)
1848 return getEffectiveDepthStencilTextureFormat(baseFormat, tcu::Sampler::MODE_STENCIL);
1850 DE_FATAL("Invalid aspect");
1856 bool BlittingImages::checkClampedAndUnclampedResult (const tcu::ConstPixelBufferAccess& result,
1857 const tcu::ConstPixelBufferAccess& clampedExpected,
1858 const tcu::ConstPixelBufferAccess& unclampedExpected,
1859 VkImageAspectFlagBits aspect)
1861 tcu::TestLog& log (m_context.getTestContext().getLog());
1862 const bool isLinear = m_params.filter == VK_FILTER_LINEAR;
1863 const tcu::TextureFormat srcFormat = getFormatAspect(m_params.src.image.format, aspect);
1864 const tcu::TextureFormat dstFormat = result.getFormat();
1867 DE_ASSERT(dstFormat == getFormatAspect(m_params.dst.image.format, aspect));
1870 log << tcu::TestLog::Section("ClampedSourceImage", "Region with clamped edges on source image.");
1872 if (isFloatFormat(dstFormat))
1874 const bool srcIsSRGB = tcu::isSRGB(srcFormat);
1875 const tcu::Vec4 srcMaxDiff = getFormatThreshold(srcFormat) * tcu::Vec4(srcIsSRGB ? 2 : 1);
1876 const tcu::Vec4 dstMaxDiff = getFormatThreshold(dstFormat);
1877 const tcu::Vec4 threshold = tcu::max(srcMaxDiff, dstMaxDiff);
1879 isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1882 log << tcu::TestLog::EndSection;
1884 if (!isOk && isLinear)
1886 log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
1887 isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1888 log << tcu::TestLog::EndSection;
1893 tcu::UVec4 threshold;
1894 // Calculate threshold depending on channel width of destination format.
1895 const tcu::IVec4 bitDepth = tcu::getTextureFormatBitDepth(dstFormat);
1896 for (deUint32 i = 0; i < 4; ++i)
1897 threshold[i] = de::max( (0x1 << bitDepth[i]) / 256, 1);
1899 isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1902 log << tcu::TestLog::EndSection;
1904 if (!isOk && isLinear)
1906 log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
1907 isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1908 log << tcu::TestLog::EndSection;
1914 tcu::TestStatus BlittingImages::checkTestResult (tcu::ConstPixelBufferAccess result)
1916 DE_ASSERT(m_params.filter == VK_FILTER_NEAREST || m_params.filter == VK_FILTER_LINEAR);
1918 if (tcu::isCombinedDepthStencilType(result.getFormat().type))
1920 if (tcu::hasDepthComponent(result.getFormat().order))
1922 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_DEPTH;
1923 const tcu::ConstPixelBufferAccess depthResult = tcu::getEffectiveDepthStencilAccess(result, mode);
1924 const tcu::ConstPixelBufferAccess clampedExpected = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1925 const tcu::ConstPixelBufferAccess unclampedExpected = m_params.filter == VK_FILTER_LINEAR ? tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode) : tcu::ConstPixelBufferAccess();
1927 if (!checkClampedAndUnclampedResult(depthResult, clampedExpected, unclampedExpected, VK_IMAGE_ASPECT_DEPTH_BIT))
1929 return tcu::TestStatus::fail("CopiesAndBlitting test");
1933 if (tcu::hasStencilComponent(result.getFormat().order))
1935 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_STENCIL;
1936 const tcu::ConstPixelBufferAccess stencilResult = tcu::getEffectiveDepthStencilAccess(result, mode);
1937 const tcu::ConstPixelBufferAccess clampedExpected = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1938 const tcu::ConstPixelBufferAccess unclampedExpected = m_params.filter == VK_FILTER_LINEAR ? tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode) : tcu::ConstPixelBufferAccess();
1940 if (!checkClampedAndUnclampedResult(stencilResult, clampedExpected, unclampedExpected, VK_IMAGE_ASPECT_STENCIL_BIT))
1942 return tcu::TestStatus::fail("CopiesAndBlitting test");
1948 if (!checkClampedAndUnclampedResult(result, m_expectedTextureLevel->getAccess(), m_params.filter == VK_FILTER_LINEAR ? m_unclampedExpectedTextureLevel->getAccess() : tcu::ConstPixelBufferAccess(), VK_IMAGE_ASPECT_COLOR_BIT))
1950 return tcu::TestStatus::fail("CopiesAndBlitting test");
1954 return tcu::TestStatus::pass("CopiesAndBlitting test");
1957 tcu::Vec4 linearToSRGBIfNeeded (const tcu::TextureFormat& format, const tcu::Vec4& color)
1959 return isSRGB(format) ? linearToSRGB(color) : color;
1962 void scaleFromWholeSrcBuffer (const tcu::PixelBufferAccess& dst, const tcu::ConstPixelBufferAccess& src, const VkOffset3D regionOffset, const VkOffset3D regionExtent, tcu::Sampler::FilterMode filter)
1964 DE_ASSERT(filter == tcu::Sampler::LINEAR);
1965 DE_ASSERT(dst.getDepth() == 1 && src.getDepth() == 1);
1967 tcu::Sampler sampler(tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE,
1968 filter, filter, 0.0f, false);
1970 float sX = (float)regionExtent.x / (float)dst.getWidth();
1971 float sY = (float)regionExtent.y / (float)dst.getHeight();
1973 for (int y = 0; y < dst.getHeight(); y++)
1974 for (int x = 0; x < dst.getWidth(); x++)
1975 dst.setPixel(linearToSRGBIfNeeded(dst.getFormat(), src.sample2D(sampler, filter, (float)regionOffset.x + ((float)x+0.5f)*sX, (float)regionOffset.y + ((float)y+0.5f)*sY, 0)), x, y);
1978 void BlittingImages::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1980 const VkOffset3D srcOffset = region.imageBlit.srcOffsets[0];
1981 const VkOffset3D srcExtent =
1983 region.imageBlit.srcOffsets[1].x - srcOffset.x,
1984 region.imageBlit.srcOffsets[1].y - srcOffset.y,
1985 region.imageBlit.srcOffsets[1].z - srcOffset.z
1987 const VkOffset3D dstOffset = region.imageBlit.dstOffsets[0];
1988 const VkOffset3D dstExtent =
1990 region.imageBlit.dstOffsets[1].x - dstOffset.x,
1991 region.imageBlit.dstOffsets[1].y - dstOffset.y,
1992 region.imageBlit.dstOffsets[1].z - dstOffset.z
1994 const tcu::Sampler::FilterMode filter = (m_params.filter == VK_FILTER_LINEAR) ? tcu::Sampler::LINEAR : tcu::Sampler::NEAREST;
1996 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
1998 DE_ASSERT(src.getFormat() == dst.getFormat());
2000 if (tcu::hasDepthComponent(src.getFormat().order))
2002 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_DEPTH);
2003 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
2004 tcu::scale(dstSubRegion, srcSubRegion, filter);
2006 if (filter == tcu::Sampler::LINEAR)
2008 const tcu::ConstPixelBufferAccess depthSrc = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_DEPTH);
2009 const tcu::PixelBufferAccess unclampedSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
2010 scaleFromWholeSrcBuffer(unclampedSubRegion, depthSrc, srcOffset, srcExtent, filter);
2015 if (tcu::hasStencilComponent(src.getFormat().order))
2017 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_STENCIL);
2018 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
2019 tcu::scale(dstSubRegion, srcSubRegion, filter);
2021 if (filter == tcu::Sampler::LINEAR)
2023 const tcu::ConstPixelBufferAccess stencilSrc = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_STENCIL);
2024 const tcu::PixelBufferAccess unclampedSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
2025 scaleFromWholeSrcBuffer(unclampedSubRegion, stencilSrc, srcOffset, srcExtent, filter);
2031 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y);
2032 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
2033 tcu::scale(dstSubRegion, srcSubRegion, filter);
2035 if (filter == tcu::Sampler::LINEAR)
2037 const tcu::PixelBufferAccess unclampedSubRegion = tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
2038 scaleFromWholeSrcBuffer(unclampedSubRegion, src, srcOffset, srcExtent, filter);
2043 void BlittingImages::generateExpectedResult (void)
2045 const tcu::ConstPixelBufferAccess src = m_sourceTextureLevel->getAccess();
2046 const tcu::ConstPixelBufferAccess dst = m_destinationTextureLevel->getAccess();
2048 m_expectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
2049 tcu::copy(m_expectedTextureLevel->getAccess(), dst);
2051 if (m_params.filter == VK_FILTER_LINEAR)
2053 m_unclampedExpectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
2054 tcu::copy(m_unclampedExpectedTextureLevel->getAccess(), dst);
2057 for (deUint32 i = 0; i < m_params.regions.size(); i++)
2058 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), m_params.regions[i]);
2061 class BlittingTestCase : public vkt::TestCase
2064 BlittingTestCase (tcu::TestContext& testCtx,
2065 const std::string& name,
2066 const std::string& description,
2067 const TestParams params)
2068 : vkt::TestCase (testCtx, name, description)
2072 virtual TestInstance* createInstance (Context& context) const
2074 return new BlittingImages(context, m_params);
2077 TestParams m_params;
2080 // Resolve image to image.
2082 class ResolveImageToImage : public CopiesAndBlittingTestInstance
2085 ResolveImageToImage (Context& context,
2087 virtual tcu::TestStatus iterate (void);
2089 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
2091 Move<VkImage> m_multisampledImage;
2092 de::MovePtr<Allocation> m_multisampledImageAlloc;
2094 Move<VkImage> m_destination;
2095 de::MovePtr<Allocation> m_destinationImageAlloc;
2097 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
2100 ResolveImageToImage::ResolveImageToImage (Context& context, TestParams params)
2101 : CopiesAndBlittingTestInstance(context, params)
2103 const VkSampleCountFlagBits rasterizationSamples = m_params.samples;
2105 if (!(context.getDeviceProperties().limits.framebufferColorSampleCounts & rasterizationSamples))
2106 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
2108 const DeviceInterface& vk = context.getDeviceInterface();
2109 const VkDevice vkDevice = context.getDevice();
2110 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2111 Allocator& memAlloc = m_context.getDefaultAllocator();
2113 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
2115 Move<VkImageView> sourceAttachmentView;
2117 Move<VkRenderPass> renderPass;
2118 Move<VkFramebuffer> framebuffer;
2120 Move<VkShaderModule> vertexShaderModule;
2121 Move<VkShaderModule> fragmentShaderModule;
2123 Move<VkBuffer> vertexBuffer;
2124 std::vector<tcu::Vec4> vertices;
2125 de::MovePtr<Allocation> vertexBufferAlloc;
2127 Move<VkPipelineLayout> pipelineLayout;
2128 Move<VkPipeline> graphicsPipeline;
2130 Move<VkCommandPool> cmdPool;
2131 Move<VkCommandBuffer> cmdBuffer;
2133 Move<VkFence> fence;
2135 VkImageFormatProperties properties;
2136 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2137 m_params.src.image.format,
2139 VK_IMAGE_TILING_OPTIMAL,
2140 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
2141 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
2142 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2143 m_params.dst.image.format,
2145 VK_IMAGE_TILING_OPTIMAL,
2146 VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
2147 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
2149 TCU_THROW(NotSupportedError, "Format not supported");
2152 // Create color image.
2154 const VkImageCreateInfo colorImageParams =
2156 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
2157 DE_NULL, // const void* pNext;
2158 0u, // VkImageCreateFlags flags;
2159 VK_IMAGE_TYPE_2D, // VkImageType imageType;
2160 m_params.src.image.format, // VkFormat format;
2161 m_params.src.image.extent, // VkExtent3D extent;
2162 1u, // deUint32 mipLevels;
2163 1u, // deUint32 arrayLayers;
2164 rasterizationSamples, // VkSampleCountFlagBits samples;
2165 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2166 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
2167 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2168 1u, // deUint32 queueFamilyIndexCount;
2169 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
2170 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
2173 m_multisampledImage = createImage(vk, vkDevice, &colorImageParams);
2175 // Allocate and bind color image memory.
2176 m_multisampledImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_multisampledImage), MemoryRequirement::Any);
2177 VK_CHECK(vk.bindImageMemory(vkDevice, *m_multisampledImage, m_multisampledImageAlloc->getMemory(), m_multisampledImageAlloc->getOffset()));
2180 // Create destination image.
2182 const VkImageCreateInfo destinationImageParams =
2184 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
2185 DE_NULL, // const void* pNext;
2186 0u, // VkImageCreateFlags flags;
2187 VK_IMAGE_TYPE_2D, // VkImageType imageType;
2188 m_params.dst.image.format, // VkFormat format;
2189 m_params.dst.image.extent, // VkExtent3D extent;
2190 1u, // deUint32 mipLevels;
2191 1u, // deUint32 arraySize;
2192 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
2193 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2194 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
2195 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
2196 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2197 1u, // deUint32 queueFamilyCount;
2198 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
2199 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
2202 m_destination = createImage(vk, vkDevice, &destinationImageParams);
2203 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
2204 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
2207 // Create color attachment view.
2209 const VkImageViewCreateInfo colorAttachmentViewParams =
2211 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
2212 DE_NULL, // const void* pNext;
2213 0u, // VkImageViewCreateFlags flags;
2214 *m_multisampledImage, // VkImage image;
2215 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
2216 m_params.src.image.format, // VkFormat format;
2217 componentMappingRGBA, // VkComponentMapping components;
2218 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
2221 sourceAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
2224 // Create render pass.
2226 const VkAttachmentDescription attachmentDescriptions[1] =
2229 0u, // VkAttachmentDescriptionFlags flags;
2230 m_params.src.image.format, // VkFormat format;
2231 rasterizationSamples, // VkSampleCountFlagBits samples;
2232 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
2233 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
2234 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
2235 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
2236 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
2237 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
2241 const VkAttachmentReference colorAttachmentReference =
2243 0u, // deUint32 attachment;
2244 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
2247 const VkSubpassDescription subpassDescription =
2249 0u, // VkSubpassDescriptionFlags flags;
2250 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
2251 0u, // deUint32 inputAttachmentCount;
2252 DE_NULL, // const VkAttachmentReference* pInputAttachments;
2253 1u, // deUint32 colorAttachmentCount;
2254 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
2255 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
2256 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
2257 0u, // deUint32 preserveAttachmentCount;
2258 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
2261 const VkRenderPassCreateInfo renderPassParams =
2263 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
2264 DE_NULL, // const void* pNext;
2265 0u, // VkRenderPassCreateFlags flags;
2266 1u, // deUint32 attachmentCount;
2267 attachmentDescriptions, // const VkAttachmentDescription* pAttachments;
2268 1u, // deUint32 subpassCount;
2269 &subpassDescription, // const VkSubpassDescription* pSubpasses;
2270 0u, // deUint32 dependencyCount;
2271 DE_NULL // const VkSubpassDependency* pDependencies;
2274 renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
2277 // Create framebuffer
2279 const VkImageView attachments[1] =
2281 *sourceAttachmentView,
2284 const VkFramebufferCreateInfo framebufferParams =
2286 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
2287 DE_NULL, // const void* pNext;
2288 0u, // VkFramebufferCreateFlags flags;
2289 *renderPass, // VkRenderPass renderPass;
2290 1u, // deUint32 attachmentCount;
2291 attachments, // const VkImageView* pAttachments;
2292 m_params.src.image.extent.width, // deUint32 width;
2293 m_params.src.image.extent.height, // deUint32 height;
2294 1u // deUint32 layers;
2297 framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
2300 // Create pipeline layout
2302 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
2304 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
2305 DE_NULL, // const void* pNext;
2306 0u, // VkPipelineLayoutCreateFlags flags;
2307 0u, // deUint32 setLayoutCount;
2308 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
2309 0u, // deUint32 pushConstantRangeCount;
2310 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
2313 pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
2318 vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("vert"), 0);
2319 fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("frag"), 0);
2324 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
2327 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
2328 DE_NULL, // const void* pNext;
2329 0u, // VkPipelineShaderStageCreateFlags flags;
2330 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
2331 *vertexShaderModule, // VkShaderModule module;
2332 "main", // const char* pName;
2333 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
2336 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
2337 DE_NULL, // const void* pNext;
2338 0u, // VkPipelineShaderStageCreateFlags flags;
2339 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
2340 *fragmentShaderModule, // VkShaderModule module;
2341 "main", // const char* pName;
2342 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
2346 const VkVertexInputBindingDescription vertexInputBindingDescription =
2348 0u, // deUint32 binding;
2349 sizeof(tcu::Vec4), // deUint32 stride;
2350 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputRate inputRate;
2353 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[1] =
2356 0u, // deUint32 location;
2357 0u, // deUint32 binding;
2358 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
2359 0u // deUint32 offset;
2363 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
2365 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
2366 DE_NULL, // const void* pNext;
2367 0u, // VkPipelineVertexInputStateCreateFlags flags;
2368 1u, // deUint32 vertexBindingDescriptionCount;
2369 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
2370 1u, // deUint32 vertexAttributeDescriptionCount;
2371 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
2374 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
2376 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
2377 DE_NULL, // const void* pNext;
2378 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
2379 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
2380 false // VkBool32 primitiveRestartEnable;
2383 const VkViewport viewport =
2387 (float)m_params.src.image.extent.width, // float width;
2388 (float)m_params.src.image.extent.height, // float height;
2389 0.0f, // float minDepth;
2390 1.0f // float maxDepth;
2393 const VkRect2D scissor =
2395 { 0, 0 }, // VkOffset2D offset;
2396 { m_params.src.image.extent.width, m_params.src.image.extent.height } // VkExtent2D extent;
2399 const VkPipelineViewportStateCreateInfo viewportStateParams =
2401 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
2402 DE_NULL, // const void* pNext;
2403 0u, // VkPipelineViewportStateCreateFlags flags;
2404 1u, // deUint32 viewportCount;
2405 &viewport, // const VkViewport* pViewports;
2406 1u, // deUint32 scissorCount;
2407 &scissor // const VkRect2D* pScissors;
2410 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
2412 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
2413 DE_NULL, // const void* pNext;
2414 0u, // VkPipelineRasterizationStateCreateFlags flags;
2415 false, // VkBool32 depthClampEnable;
2416 false, // VkBool32 rasterizerDiscardEnable;
2417 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
2418 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
2419 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
2420 VK_FALSE, // VkBool32 depthBiasEnable;
2421 0.0f, // float depthBiasConstantFactor;
2422 0.0f, // float depthBiasClamp;
2423 0.0f, // float depthBiasSlopeFactor;
2424 1.0f // float lineWidth;
2427 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
2429 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
2430 DE_NULL, // const void* pNext;
2431 0u, // VkPipelineMultisampleStateCreateFlags flags;
2432 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
2433 VK_FALSE, // VkBool32 sampleShadingEnable;
2434 0.0f, // float minSampleShading;
2435 DE_NULL, // const VkSampleMask* pSampleMask;
2436 VK_FALSE, // VkBool32 alphaToCoverageEnable;
2437 VK_FALSE // VkBool32 alphaToOneEnable;
2440 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
2442 false, // VkBool32 blendEnable;
2443 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor;
2444 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor;
2445 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor;
2446 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha;
2447 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha;
2448 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha;
2449 (VK_COLOR_COMPONENT_R_BIT |
2450 VK_COLOR_COMPONENT_G_BIT |
2451 VK_COLOR_COMPONENT_B_BIT |
2452 VK_COLOR_COMPONENT_A_BIT) // VkChannelFlags channelWriteMask;
2455 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
2457 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
2458 DE_NULL, // const void* pNext;
2459 0u, // VkPipelineColorBlendStateCreateFlags flags;
2460 false, // VkBool32 logicOpEnable;
2461 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
2462 1u, // deUint32 attachmentCount;
2463 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
2464 { 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4];
2467 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
2469 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
2470 DE_NULL, // const void* pNext;
2471 0u, // VkPipelineCreateFlags flags;
2472 2u, // deUint32 stageCount;
2473 shaderStageParams, // const VkPipelineShaderStageCreateInfo* pStages;
2474 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
2475 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
2476 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
2477 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
2478 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
2479 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
2480 DE_NULL, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
2481 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
2482 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
2483 *pipelineLayout, // VkPipelineLayout layout;
2484 *renderPass, // VkRenderPass renderPass;
2485 0u, // deUint32 subpass;
2486 0u, // VkPipeline basePipelineHandle;
2487 0u // deInt32 basePipelineIndex;
2490 graphicsPipeline = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
2493 // Create vertex buffer.
2495 // Create upper half triangle.
2497 const tcu::Vec4 a (-1.0, -1.0, 0.0, 1.0);
2498 const tcu::Vec4 b (1.0, -1.0, 0.0, 1.0);
2499 const tcu::Vec4 c (1.0, 1.0, 0.0, 1.0);
2502 vertices.push_back(a);
2503 vertices.push_back(c);
2504 vertices.push_back(b);
2507 const VkDeviceSize vertexDataSize = vertices.size() * sizeof(tcu::Vec4);
2508 const VkBufferCreateInfo vertexBufferParams =
2510 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
2511 DE_NULL, // const void* pNext;
2512 0u, // VkBufferCreateFlags flags;
2513 vertexDataSize, // VkDeviceSize size;
2514 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
2515 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2516 1u, // deUint32 queueFamilyIndexCount;
2517 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
2520 vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
2521 vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible);
2523 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset()));
2525 // Load vertices into vertex buffer.
2526 deMemcpy(vertexBufferAlloc->getHostPtr(), vertices.data(), (size_t)vertexDataSize);
2527 flushMappedMemoryRange(vk, vkDevice, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset(), vertexDataSize);
2530 // Create command pool
2532 const VkCommandPoolCreateInfo cmdPoolParams =
2534 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
2535 DE_NULL, // const void* pNext;
2536 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCommandPoolCreateFlags flags;
2537 queueFamilyIndex, // deUint32 queueFamilyIndex;
2540 cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
2543 // Create command buffer
2545 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
2547 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
2548 DE_NULL, // const void* pNext;
2549 *cmdPool, // VkCommandPool commandPool;
2550 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
2551 1u // deUint32 bufferCount;
2554 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
2556 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
2557 DE_NULL, // const void* pNext;
2558 0u, // VkCommandBufferUsageFlags flags;
2559 (const VkCommandBufferInheritanceInfo*)DE_NULL,
2562 const VkClearValue clearValue = makeClearValueColorF32(0.0f, 0.0f, 1.0f, 1.0f);
2564 const VkClearValue clearValues[1] =
2569 const VkRenderPassBeginInfo renderPassBeginInfo =
2571 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
2572 DE_NULL, // const void* pNext;
2573 *renderPass, // VkRenderPass renderPass;
2574 *framebuffer, // VkFramebuffer framebuffer;
2577 { m_params.src.image.extent.width, m_params.src.image.extent.height }
2578 }, // VkRect2D renderArea;
2579 1u, // deUint32 clearValueCount;
2580 clearValues // const VkClearValue* pClearValues;
2583 // Barriers for copying image to buffer
2584 const VkImageMemoryBarrier srcImageBarrier =
2586 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2587 DE_NULL, // const void* pNext;
2588 0u, // VkAccessFlags srcAccessMask;
2589 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
2590 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2591 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
2592 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2593 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2594 m_multisampledImage.get(), // VkImage image;
2595 { // VkImageSubresourceRange subresourceRange;
2596 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
2597 0u, // deUint32 baseMipLevel;
2598 1u, // deUint32 mipLevels;
2599 0u, // deUint32 baseArraySlice;
2600 1u // deUint32 arraySize;
2604 cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
2606 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
2607 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &srcImageBarrier);
2608 vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
2610 const VkDeviceSize vertexBufferOffset = 0u;
2612 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *graphicsPipeline);
2613 vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer.get(), &vertexBufferOffset);
2614 vk.cmdDraw(*cmdBuffer, (deUint32)vertices.size(), 1, 0, 0);
2616 vk.cmdEndRenderPass(*cmdBuffer);
2618 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
2623 const VkFenceCreateInfo fenceParams =
2625 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
2626 DE_NULL, // const void* pNext;
2627 0u // VkFenceCreateFlags flags;
2630 fence = createFence(vk, vkDevice, &fenceParams);
2635 const VkQueue queue = m_context.getUniversalQueue();
2636 const VkSubmitInfo submitInfo =
2638 VK_STRUCTURE_TYPE_SUBMIT_INFO,
2641 (const VkSemaphore*)DE_NULL,
2642 (const VkPipelineStageFlags*)DE_NULL,
2646 (const VkSemaphore*)DE_NULL,
2649 VK_CHECK(vk.resetFences(vkDevice, 1, &fence.get()));
2650 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *fence));
2651 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), true, ~(0ull) /* infinity */));
2655 tcu::TestStatus ResolveImageToImage::iterate (void)
2657 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
2658 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
2660 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
2661 m_params.src.image.extent.width,
2662 m_params.src.image.extent.height,
2663 m_params.src.image.extent.depth));
2664 generateBuffer(m_sourceTextureLevel->getAccess(), m_params.src.image.extent.width, m_params.src.image.extent.height, m_params.src.image.extent.depth, FILL_MODE_MULTISAMPLE);
2665 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
2666 (int)m_params.dst.image.extent.width,
2667 (int)m_params.dst.image.extent.height,
2668 (int)m_params.dst.image.extent.depth));
2669 generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth);
2670 generateExpectedResult();
2672 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
2674 const DeviceInterface& vk = m_context.getDeviceInterface();
2675 const VkDevice vkDevice = m_context.getDevice();
2676 const VkQueue queue = m_context.getUniversalQueue();
2678 std::vector<VkImageResolve> imageResolves;
2679 for (deUint32 i = 0; i < m_params.regions.size(); i++)
2680 imageResolves.push_back(m_params.regions[i].imageResolve);
2682 const VkImageMemoryBarrier imageBarriers[] =
2686 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2687 DE_NULL, // const void* pNext;
2688 0u, // VkAccessFlags srcAccessMask;
2689 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
2690 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
2691 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
2692 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2693 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2694 m_multisampledImage.get(), // VkImage image;
2695 { // VkImageSubresourceRange subresourceRange;
2696 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
2697 0u, // deUint32 baseMipLevel;
2698 1u, // deUint32 mipLevels;
2699 0u, // deUint32 baseArraySlice;
2700 1u // deUint32 arraySize;
2703 // destination image
2705 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2706 DE_NULL, // const void* pNext;
2707 0u, // VkAccessFlags srcAccessMask;
2708 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
2709 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2710 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
2711 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2712 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2713 m_destination.get(), // VkImage image;
2714 { // VkImageSubresourceRange subresourceRange;
2715 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
2716 0u, // deUint32 baseMipLevel;
2717 1u, // deUint32 mipLevels;
2718 0u, // deUint32 baseArraySlice;
2719 1u // deUint32 arraySize;
2724 const VkImageMemoryBarrier postImageBarrier =
2726 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2727 DE_NULL, // const void* pNext;
2728 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
2729 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
2730 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
2731 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
2732 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2733 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2734 m_destination.get(), // VkImage image;
2735 { // VkImageSubresourceRange subresourceRange;
2736 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
2737 0u, // deUint32 baseMipLevel;
2738 1u, // deUint32 mipLevels;
2739 0u, // deUint32 baseArraySlice;
2740 1u // deUint32 arraySize;
2744 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
2746 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
2747 DE_NULL, // const void* pNext;
2748 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
2749 (const VkCommandBufferInheritanceInfo*)DE_NULL,
2752 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
2753 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, DE_LENGTH_OF_ARRAY(imageBarriers), imageBarriers);
2754 vk.cmdResolveImage(*m_cmdBuffer, m_multisampledImage.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), imageResolves.data());
2755 vk.cmdPipelineBarrier(*m_cmdBuffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 0, (const VkBufferMemoryBarrier*)DE_NULL, 1, &postImageBarrier);
2756 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2758 const VkSubmitInfo submitInfo =
2760 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
2761 DE_NULL, // const void* pNext;
2762 0u, // deUint32 waitSemaphoreCount;
2763 DE_NULL, // const VkSemaphore* pWaitSemaphores;
2764 (const VkPipelineStageFlags*)DE_NULL,
2765 1u, // deUint32 commandBufferCount;
2766 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
2767 0u, // deUint32 signalSemaphoreCount;
2768 DE_NULL // const VkSemaphore* pSignalSemaphores;
2771 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
2772 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
2773 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
2775 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(*m_destination, m_params.dst.image.format, m_params.dst.image.extent);
2777 return checkTestResult(resultTextureLevel->getAccess());
2780 tcu::TestStatus ResolveImageToImage::checkTestResult (tcu::ConstPixelBufferAccess result)
2782 const tcu::ConstPixelBufferAccess expected = m_expectedTextureLevel->getAccess();
2783 const float fuzzyThreshold = 0.01f;
2785 if (!tcu::fuzzyCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, fuzzyThreshold, tcu::COMPARE_LOG_RESULT))
2786 return tcu::TestStatus::fail("CopiesAndBlitting test");
2788 return tcu::TestStatus::pass("CopiesAndBlitting test");
2791 void ResolveImageToImage::copyRegionToTextureLevel(tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
2793 VkOffset3D srcOffset = region.imageCopy.srcOffset;
2794 VkOffset3D dstOffset = region.imageCopy.dstOffset;
2795 VkExtent3D extent = region.imageCopy.extent;
2797 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, extent.width, extent.height);
2798 // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
2799 const tcu::PixelBufferAccess dstWithSrcFormat (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
2800 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, extent.width, extent.height);
2802 tcu::copy(dstSubRegion, srcSubRegion);
2805 class ResolveImageToImageTestCase : public vkt::TestCase
2808 ResolveImageToImageTestCase (tcu::TestContext& testCtx,
2809 const std::string& name,
2810 const std::string& description,
2811 const TestParams params)
2812 : vkt::TestCase (testCtx, name, description)
2815 virtual void initPrograms (SourceCollections& programCollection) const;
2817 virtual TestInstance* createInstance (Context& context) const
2819 return new ResolveImageToImage(context, m_params);
2822 TestParams m_params;
2825 void ResolveImageToImageTestCase::initPrograms (SourceCollections& programCollection) const
2827 programCollection.glslSources.add("vert") << glu::VertexSource(
2829 "layout (location = 0) in highp vec4 a_position;\n"
2832 " gl_Position = a_position;\n"
2836 programCollection.glslSources.add("frag") << glu::FragmentSource(
2838 "layout (location = 0) out highp vec4 o_color;\n"
2841 " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
2845 std::string getSampleCountCaseName (VkSampleCountFlagBits sampleFlag)
2847 return de::toLower(de::toString(getSampleCountFlagsStr(sampleFlag)).substr(16));
2850 std::string getFormatCaseName (VkFormat format)
2852 return de::toLower(de::toString(getFormatStr(format)).substr(10));
2855 void addCopyImageTestsAllFormats (tcu::TestCaseGroup* testCaseGroup,
2856 tcu::TestContext& testCtx,
2859 const VkFormat compatibleFormats8Bit[] =
2861 VK_FORMAT_R4G4_UNORM_PACK8,
2864 VK_FORMAT_R8_USCALED,
2865 VK_FORMAT_R8_SSCALED,
2872 const VkFormat compatibleFormats16Bit[] =
2874 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
2875 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
2876 VK_FORMAT_R5G6B5_UNORM_PACK16,
2877 VK_FORMAT_B5G6R5_UNORM_PACK16,
2878 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
2879 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
2880 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
2881 VK_FORMAT_R8G8_UNORM,
2882 VK_FORMAT_R8G8_SNORM,
2883 VK_FORMAT_R8G8_USCALED,
2884 VK_FORMAT_R8G8_SSCALED,
2885 VK_FORMAT_R8G8_UINT,
2886 VK_FORMAT_R8G8_SINT,
2887 VK_FORMAT_R8G8_SRGB,
2888 VK_FORMAT_R16_UNORM,
2889 VK_FORMAT_R16_SNORM,
2890 VK_FORMAT_R16_USCALED,
2891 VK_FORMAT_R16_SSCALED,
2894 VK_FORMAT_R16_SFLOAT,
2898 const VkFormat compatibleFormats24Bit[] =
2900 VK_FORMAT_R8G8B8_UNORM,
2901 VK_FORMAT_R8G8B8_SNORM,
2902 VK_FORMAT_R8G8B8_USCALED,
2903 VK_FORMAT_R8G8B8_SSCALED,
2904 VK_FORMAT_R8G8B8_UINT,
2905 VK_FORMAT_R8G8B8_SINT,
2906 VK_FORMAT_R8G8B8_SRGB,
2907 VK_FORMAT_B8G8R8_UNORM,
2908 VK_FORMAT_B8G8R8_SNORM,
2909 VK_FORMAT_B8G8R8_USCALED,
2910 VK_FORMAT_B8G8R8_SSCALED,
2911 VK_FORMAT_B8G8R8_UINT,
2912 VK_FORMAT_B8G8R8_SINT,
2913 VK_FORMAT_B8G8R8_SRGB,
2917 const VkFormat compatibleFormats32Bit[] =
2919 VK_FORMAT_R8G8B8A8_UNORM,
2920 VK_FORMAT_R8G8B8A8_SNORM,
2921 VK_FORMAT_R8G8B8A8_USCALED,
2922 VK_FORMAT_R8G8B8A8_SSCALED,
2923 VK_FORMAT_R8G8B8A8_UINT,
2924 VK_FORMAT_R8G8B8A8_SINT,
2925 VK_FORMAT_R8G8B8A8_SRGB,
2926 VK_FORMAT_B8G8R8A8_UNORM,
2927 VK_FORMAT_B8G8R8A8_SNORM,
2928 VK_FORMAT_B8G8R8A8_USCALED,
2929 VK_FORMAT_B8G8R8A8_SSCALED,
2930 VK_FORMAT_B8G8R8A8_UINT,
2931 VK_FORMAT_B8G8R8A8_SINT,
2932 VK_FORMAT_B8G8R8A8_SRGB,
2933 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
2934 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
2935 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
2936 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
2937 VK_FORMAT_A8B8G8R8_UINT_PACK32,
2938 VK_FORMAT_A8B8G8R8_SINT_PACK32,
2939 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
2940 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
2941 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
2942 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
2943 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
2944 VK_FORMAT_A2R10G10B10_UINT_PACK32,
2945 VK_FORMAT_A2R10G10B10_SINT_PACK32,
2946 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
2947 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
2948 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
2949 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
2950 VK_FORMAT_A2B10G10R10_UINT_PACK32,
2951 VK_FORMAT_A2B10G10R10_SINT_PACK32,
2952 VK_FORMAT_R16G16_UNORM,
2953 VK_FORMAT_R16G16_SNORM,
2954 VK_FORMAT_R16G16_USCALED,
2955 VK_FORMAT_R16G16_SSCALED,
2956 VK_FORMAT_R16G16_UINT,
2957 VK_FORMAT_R16G16_SINT,
2958 VK_FORMAT_R16G16_SFLOAT,
2961 VK_FORMAT_R32_SFLOAT,
2965 const VkFormat compatibleFormats48Bit[] =
2967 VK_FORMAT_R16G16B16_UNORM,
2968 VK_FORMAT_R16G16B16_SNORM,
2969 VK_FORMAT_R16G16B16_USCALED,
2970 VK_FORMAT_R16G16B16_SSCALED,
2971 VK_FORMAT_R16G16B16_UINT,
2972 VK_FORMAT_R16G16B16_SINT,
2973 VK_FORMAT_R16G16B16_SFLOAT,
2977 const VkFormat compatibleFormats64Bit[] =
2979 VK_FORMAT_R16G16B16A16_UNORM,
2980 VK_FORMAT_R16G16B16A16_SNORM,
2981 VK_FORMAT_R16G16B16A16_USCALED,
2982 VK_FORMAT_R16G16B16A16_SSCALED,
2983 VK_FORMAT_R16G16B16A16_UINT,
2984 VK_FORMAT_R16G16B16A16_SINT,
2985 VK_FORMAT_R16G16B16A16_SFLOAT,
2986 VK_FORMAT_R32G32_UINT,
2987 VK_FORMAT_R32G32_SINT,
2988 VK_FORMAT_R32G32_SFLOAT,
2991 VK_FORMAT_R64_SFLOAT,
2995 const VkFormat compatibleFormats96Bit[] =
2997 VK_FORMAT_R32G32B32_UINT,
2998 VK_FORMAT_R32G32B32_SINT,
2999 VK_FORMAT_R32G32B32_SFLOAT,
3003 const VkFormat compatibleFormats128Bit[] =
3005 VK_FORMAT_R32G32B32A32_UINT,
3006 VK_FORMAT_R32G32B32A32_SINT,
3007 VK_FORMAT_R32G32B32A32_SFLOAT,
3008 VK_FORMAT_R64G64_UINT,
3009 VK_FORMAT_R64G64_SINT,
3010 VK_FORMAT_R64G64_SFLOAT,
3014 const VkFormat compatibleFormats192Bit[] =
3016 VK_FORMAT_R64G64B64_UINT,
3017 VK_FORMAT_R64G64B64_SINT,
3018 VK_FORMAT_R64G64B64_SFLOAT,
3022 const VkFormat compatibleFormats256Bit[] =
3024 VK_FORMAT_R64G64B64A64_UINT,
3025 VK_FORMAT_R64G64B64A64_SINT,
3026 VK_FORMAT_R64G64B64A64_SFLOAT,
3031 const VkFormat* colorImageFormatsToTest[] =
3033 compatibleFormats8Bit,
3034 compatibleFormats16Bit,
3035 compatibleFormats24Bit,
3036 compatibleFormats32Bit,
3037 compatibleFormats48Bit,
3038 compatibleFormats64Bit,
3039 compatibleFormats96Bit,
3040 compatibleFormats128Bit,
3041 compatibleFormats192Bit,
3042 compatibleFormats256Bit,
3044 const size_t numOfColorImageFormatsToTest = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
3046 for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
3048 const VkFormat* compatibleFormats = colorImageFormatsToTest[compatibleFormatsIndex];
3049 for (size_t srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_LAST; ++srcFormatIndex)
3051 params.src.image.format = compatibleFormats[srcFormatIndex];
3052 for (size_t dstFormatIndex = 0; compatibleFormats[dstFormatIndex] != VK_FORMAT_LAST; ++dstFormatIndex)
3054 params.dst.image.format = compatibleFormats[dstFormatIndex];
3056 if (!isSupportedByFramework(params.src.image.format) || !isSupportedByFramework(params.dst.image.format))
3059 std::ostringstream testName;
3060 testName << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
3061 std::ostringstream description;
3062 description << "Copy from src " << params.src.image.format << " to dst " << params.dst.image.format;
3064 testCaseGroup->addChild(new CopyImageToImageTestCase(testCtx, testName.str(), description.str(), params));
3070 void addBlittingTestsAllFormats (tcu::TestCaseGroup* testCaseGroup,
3071 tcu::TestContext& testCtx,
3074 // Test Image formats.
3075 const VkFormat compatibleFormatsUInts[] =
3078 VK_FORMAT_R8G8_UINT,
3079 VK_FORMAT_R8G8B8_UINT,
3080 VK_FORMAT_B8G8R8_UINT,
3081 VK_FORMAT_R8G8B8A8_UINT,
3082 VK_FORMAT_B8G8R8A8_UINT,
3083 VK_FORMAT_A8B8G8R8_UINT_PACK32,
3084 VK_FORMAT_A2R10G10B10_UINT_PACK32,
3085 VK_FORMAT_A2B10G10R10_UINT_PACK32,
3087 VK_FORMAT_R16G16_UINT,
3088 VK_FORMAT_R16G16B16_UINT,
3089 VK_FORMAT_R16G16B16A16_UINT,
3091 VK_FORMAT_R32G32_UINT,
3092 VK_FORMAT_R32G32B32_UINT,
3093 VK_FORMAT_R32G32B32A32_UINT,
3095 VK_FORMAT_R64G64_UINT,
3096 VK_FORMAT_R64G64B64_UINT,
3097 VK_FORMAT_R64G64B64A64_UINT,
3101 const VkFormat compatibleFormatsSInts[] =
3104 VK_FORMAT_R8G8_SINT,
3105 VK_FORMAT_R8G8B8_SINT,
3106 VK_FORMAT_B8G8R8_SINT,
3107 VK_FORMAT_R8G8B8A8_SINT,
3108 VK_FORMAT_B8G8R8A8_SINT,
3109 VK_FORMAT_A8B8G8R8_SINT_PACK32,
3110 VK_FORMAT_A2R10G10B10_SINT_PACK32,
3111 VK_FORMAT_A2B10G10R10_SINT_PACK32,
3113 VK_FORMAT_R16G16_SINT,
3114 VK_FORMAT_R16G16B16_SINT,
3115 VK_FORMAT_R16G16B16A16_SINT,
3117 VK_FORMAT_R32G32_SINT,
3118 VK_FORMAT_R32G32B32_SINT,
3119 VK_FORMAT_R32G32B32A32_SINT,
3121 VK_FORMAT_R64G64_SINT,
3122 VK_FORMAT_R64G64B64_SINT,
3123 VK_FORMAT_R64G64B64A64_SINT,
3127 const VkFormat compatibleFormatsFloats[] =
3129 VK_FORMAT_R4G4_UNORM_PACK8,
3130 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
3131 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
3132 VK_FORMAT_R5G6B5_UNORM_PACK16,
3133 VK_FORMAT_B5G6R5_UNORM_PACK16,
3134 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
3135 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
3136 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
3139 VK_FORMAT_R8_USCALED,
3140 VK_FORMAT_R8_SSCALED,
3141 VK_FORMAT_R8G8_UNORM,
3142 VK_FORMAT_R8G8_SNORM,
3143 VK_FORMAT_R8G8_USCALED,
3144 VK_FORMAT_R8G8_SSCALED,
3145 VK_FORMAT_R8G8B8_UNORM,
3146 VK_FORMAT_R8G8B8_SNORM,
3147 VK_FORMAT_R8G8B8_USCALED,
3148 VK_FORMAT_R8G8B8_SSCALED,
3149 VK_FORMAT_B8G8R8_UNORM,
3150 VK_FORMAT_B8G8R8_SNORM,
3151 VK_FORMAT_B8G8R8_USCALED,
3152 VK_FORMAT_B8G8R8_SSCALED,
3153 VK_FORMAT_R8G8B8A8_UNORM,
3154 VK_FORMAT_R8G8B8A8_SNORM,
3155 VK_FORMAT_R8G8B8A8_USCALED,
3156 VK_FORMAT_R8G8B8A8_SSCALED,
3157 VK_FORMAT_B8G8R8A8_UNORM,
3158 VK_FORMAT_B8G8R8A8_SNORM,
3159 VK_FORMAT_B8G8R8A8_USCALED,
3160 VK_FORMAT_B8G8R8A8_SSCALED,
3161 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
3162 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
3163 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
3164 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
3165 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
3166 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
3167 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
3168 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
3169 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
3170 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
3171 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
3172 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
3173 VK_FORMAT_R16_UNORM,
3174 VK_FORMAT_R16_SNORM,
3175 VK_FORMAT_R16_USCALED,
3176 VK_FORMAT_R16_SSCALED,
3177 VK_FORMAT_R16_SFLOAT,
3178 VK_FORMAT_R16G16_UNORM,
3179 VK_FORMAT_R16G16_SNORM,
3180 VK_FORMAT_R16G16_USCALED,
3181 VK_FORMAT_R16G16_SSCALED,
3182 VK_FORMAT_R16G16_SFLOAT,
3183 VK_FORMAT_R16G16B16_UNORM,
3184 VK_FORMAT_R16G16B16_SNORM,
3185 VK_FORMAT_R16G16B16_USCALED,
3186 VK_FORMAT_R16G16B16_SSCALED,
3187 VK_FORMAT_R16G16B16_SFLOAT,
3188 VK_FORMAT_R16G16B16A16_UNORM,
3189 VK_FORMAT_R16G16B16A16_SNORM,
3190 VK_FORMAT_R16G16B16A16_USCALED,
3191 VK_FORMAT_R16G16B16A16_SSCALED,
3192 VK_FORMAT_R16G16B16A16_SFLOAT,
3193 VK_FORMAT_R32_SFLOAT,
3194 VK_FORMAT_R32G32_SFLOAT,
3195 VK_FORMAT_R32G32B32_SFLOAT,
3196 VK_FORMAT_R32G32B32A32_SFLOAT,
3197 VK_FORMAT_R64_SFLOAT,
3198 VK_FORMAT_R64G64_SFLOAT,
3199 VK_FORMAT_R64G64B64_SFLOAT,
3200 VK_FORMAT_R64G64B64A64_SFLOAT,
3201 // VK_FORMAT_B10G11R11_UFLOAT_PACK32,
3202 // VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
3203 // VK_FORMAT_BC1_RGB_UNORM_BLOCK,
3204 // VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
3205 // VK_FORMAT_BC2_UNORM_BLOCK,
3206 // VK_FORMAT_BC3_UNORM_BLOCK,
3207 // VK_FORMAT_BC4_UNORM_BLOCK,
3208 // VK_FORMAT_BC4_SNORM_BLOCK,
3209 // VK_FORMAT_BC5_UNORM_BLOCK,
3210 // VK_FORMAT_BC5_SNORM_BLOCK,
3211 // VK_FORMAT_BC6H_UFLOAT_BLOCK,
3212 // VK_FORMAT_BC6H_SFLOAT_BLOCK,
3213 // VK_FORMAT_BC7_UNORM_BLOCK,
3214 // VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
3215 // VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
3216 // VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
3217 // VK_FORMAT_EAC_R11_UNORM_BLOCK,
3218 // VK_FORMAT_EAC_R11_SNORM_BLOCK,
3219 // VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
3220 // VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
3221 // VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
3222 // VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
3223 // VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
3224 // VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
3225 // VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
3226 // VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
3227 // VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
3228 // VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
3229 // VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
3230 // VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
3231 // VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
3232 // VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
3233 // VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
3234 // VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
3238 const VkFormat compatibleFormatsSrgb[] =
3241 VK_FORMAT_R8G8_SRGB,
3242 VK_FORMAT_R8G8B8_SRGB,
3243 VK_FORMAT_B8G8R8_SRGB,
3244 VK_FORMAT_R8G8B8A8_SRGB,
3245 VK_FORMAT_B8G8R8A8_SRGB,
3246 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
3247 // VK_FORMAT_BC1_RGB_SRGB_BLOCK,
3248 // VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
3249 // VK_FORMAT_BC2_SRGB_BLOCK,
3250 // VK_FORMAT_BC3_SRGB_BLOCK,
3251 // VK_FORMAT_BC7_SRGB_BLOCK,
3252 // VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
3253 // VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
3254 // VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
3255 // VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
3256 // VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
3257 // VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
3258 // VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
3259 // VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
3260 // VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
3261 // VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
3262 // VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
3263 // VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
3264 // VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
3265 // VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
3266 // VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
3267 // VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
3268 // VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
3274 const VkFormat* compatibleFormats;
3275 const bool onlyNearest;
3276 } colorImageFormatsToTest[] =
3278 { compatibleFormatsUInts, true },
3279 { compatibleFormatsSInts, true },
3280 { compatibleFormatsFloats, false },
3281 { compatibleFormatsSrgb, false },
3283 const size_t numOfColorImageFormatsToTest = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
3285 for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
3287 const VkFormat* compatibleFormats = colorImageFormatsToTest[compatibleFormatsIndex].compatibleFormats;
3288 const bool onlyNearest = colorImageFormatsToTest[compatibleFormatsIndex].onlyNearest;
3289 for (size_t srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_LAST; ++srcFormatIndex)
3291 params.src.image.format = compatibleFormats[srcFormatIndex];
3292 for (size_t dstFormatIndex = 0; compatibleFormats[dstFormatIndex] != VK_FORMAT_LAST; ++dstFormatIndex)
3294 params.dst.image.format = compatibleFormats[dstFormatIndex];
3296 if (!isSupportedByFramework(params.src.image.format) || !isSupportedByFramework(params.dst.image.format))
3299 std::ostringstream testName;
3300 testName << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
3301 std::ostringstream description;
3302 description << "Blit image from src " << params.src.image.format << " to dst " << params.dst.image.format;
3304 params.filter = VK_FILTER_NEAREST;
3305 testCaseGroup->addChild(new BlittingTestCase(testCtx, testName.str() + "_nearest", description.str(), params));
3309 params.filter = VK_FILTER_LINEAR;
3310 testCaseGroup->addChild(new BlittingTestCase(testCtx, testName.str() + "_linear", description.str(), params));
3319 tcu::TestCaseGroup* createCopiesAndBlittingTests (tcu::TestContext& testCtx)
3321 de::MovePtr<tcu::TestCaseGroup> copiesAndBlittingTests (new tcu::TestCaseGroup(testCtx, "copy_and_blit", "Copies And Blitting Tests"));
3323 de::MovePtr<tcu::TestCaseGroup> imageToImageTests (new tcu::TestCaseGroup(testCtx, "image_to_image", "Copy from image to image"));
3324 de::MovePtr<tcu::TestCaseGroup> imgToImgSimpleTests (new tcu::TestCaseGroup(testCtx, "simple_tests", "Copy from image to image simple tests"));
3325 de::MovePtr<tcu::TestCaseGroup> imgToImgAllFormatsTests (new tcu::TestCaseGroup(testCtx, "all_formats", "Copy from image to image with all compatible formats"));
3327 de::MovePtr<tcu::TestCaseGroup> imageToBufferTests (new tcu::TestCaseGroup(testCtx, "image_to_buffer", "Copy from image to buffer"));
3328 de::MovePtr<tcu::TestCaseGroup> bufferToImageTests (new tcu::TestCaseGroup(testCtx, "buffer_to_image", "Copy from buffer to image"));
3329 de::MovePtr<tcu::TestCaseGroup> bufferToBufferTests (new tcu::TestCaseGroup(testCtx, "buffer_to_buffer", "Copy from buffer to buffer"));
3331 de::MovePtr<tcu::TestCaseGroup> blittingImageTests (new tcu::TestCaseGroup(testCtx, "blit_image", "Blitting image"));
3332 de::MovePtr<tcu::TestCaseGroup> blitImgSimpleTests (new tcu::TestCaseGroup(testCtx, "simple_tests", "Blitting image simple tests"));
3333 de::MovePtr<tcu::TestCaseGroup> blitImgAllFormatsTests (new tcu::TestCaseGroup(testCtx, "all_formats", "Blitting image with all compatible formats"));
3335 de::MovePtr<tcu::TestCaseGroup> resolveImageTests (new tcu::TestCaseGroup(testCtx, "resolve_image", "Resolve image"));
3337 const deInt32 defaultSize = 64;
3338 const deInt32 defaultHalfSize = defaultSize / 2;
3339 const deInt32 defaultFourthSize = defaultSize / 4;
3340 const VkExtent3D defaultExtent = {defaultSize, defaultSize, 1};
3341 const VkExtent3D defaultHalfExtent = {defaultHalfSize, defaultHalfSize, 1};
3343 const VkImageSubresourceLayers defaultSourceLayer =
3345 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
3346 0u, // uint32_t mipLevel;
3347 0u, // uint32_t baseArrayLayer;
3348 1u, // uint32_t layerCount;
3351 // Copy image to image testcases.
3354 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3355 params.src.image.extent = defaultExtent;
3356 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3357 params.dst.image.extent = defaultExtent;
3360 const VkImageCopy testCopy =
3362 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3363 {0, 0, 0}, // VkOffset3D srcOffset;
3364 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3365 {0, 0, 0}, // VkOffset3D dstOffset;
3366 defaultExtent, // VkExtent3D extent;
3369 CopyRegion imageCopy;
3370 imageCopy.imageCopy = testCopy;
3372 params.regions.push_back(imageCopy);
3375 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "whole_image", "Whole image", params));
3380 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3381 params.src.image.extent = defaultExtent;
3382 params.dst.image.format = VK_FORMAT_R32_UINT;
3383 params.dst.image.extent = defaultExtent;
3386 const VkImageCopy testCopy =
3388 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3389 {0, 0, 0}, // VkOffset3D srcOffset;
3390 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3391 {0, 0, 0}, // VkOffset3D dstOffset;
3392 defaultExtent, // VkExtent3D extent;
3395 CopyRegion imageCopy;
3396 imageCopy.imageCopy = testCopy;
3398 params.regions.push_back(imageCopy);
3401 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "whole_image_diff_fromat", "Whole image with different format", params));
3406 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3407 params.src.image.extent = defaultExtent;
3408 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3409 params.dst.image.extent = defaultExtent;
3412 const VkImageCopy testCopy =
3414 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3415 {0, 0, 0}, // VkOffset3D srcOffset;
3416 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3417 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3418 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3421 CopyRegion imageCopy;
3422 imageCopy.imageCopy = testCopy;
3424 params.regions.push_back(imageCopy);
3427 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "partial_image", "Partial image", params));
3432 params.src.image.format = VK_FORMAT_D32_SFLOAT;
3433 params.src.image.extent = defaultExtent;
3434 params.dst.image.format = VK_FORMAT_D32_SFLOAT;
3435 params.dst.image.extent = defaultExtent;
3438 const VkImageSubresourceLayers sourceLayer =
3440 VK_IMAGE_ASPECT_DEPTH_BIT, // VkImageAspectFlags aspectMask;
3441 0u, // uint32_t mipLevel;
3442 0u, // uint32_t baseArrayLayer;
3443 1u // uint32_t layerCount;
3445 const VkImageCopy testCopy =
3447 sourceLayer, // VkImageSubresourceLayers srcSubresource;
3448 {0, 0, 0}, // VkOffset3D srcOffset;
3449 sourceLayer, // VkImageSubresourceLayers dstSubresource;
3450 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3451 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3454 CopyRegion imageCopy;
3455 imageCopy.imageCopy = testCopy;
3457 params.regions.push_back(imageCopy);
3460 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "depth", "With depth", params));
3465 params.src.image.format = VK_FORMAT_S8_UINT;
3466 params.src.image.extent = defaultExtent;
3467 params.dst.image.format = VK_FORMAT_S8_UINT;
3468 params.dst.image.extent = defaultExtent;
3471 const VkImageSubresourceLayers sourceLayer =
3473 VK_IMAGE_ASPECT_STENCIL_BIT, // VkImageAspectFlags aspectMask;
3474 0u, // uint32_t mipLevel;
3475 0u, // uint32_t baseArrayLayer;
3476 1u // uint32_t layerCount;
3478 const VkImageCopy testCopy =
3480 sourceLayer, // VkImageSubresourceLayers srcSubresource;
3481 {0, 0, 0}, // VkOffset3D srcOffset;
3482 sourceLayer, // VkImageSubresourceLayers dstSubresource;
3483 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3484 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3487 CopyRegion imageCopy;
3488 imageCopy.imageCopy = testCopy;
3490 params.regions.push_back(imageCopy);
3493 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "stencil", "With stencil", params));
3498 params.src.image.extent = defaultExtent;
3499 params.dst.image.extent = defaultExtent;
3501 for (deInt32 i = 0; i < defaultSize; i += defaultFourthSize)
3503 const VkImageCopy testCopy =
3505 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3506 {0, 0, 0}, // VkOffset3D srcOffset;
3507 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3508 {i, defaultSize - i - defaultFourthSize, 0}, // VkOffset3D dstOffset;
3509 {defaultFourthSize, defaultFourthSize, 1}, // VkExtent3D extent;
3512 CopyRegion imageCopy;
3513 imageCopy.imageCopy = testCopy;
3515 params.regions.push_back(imageCopy);
3518 addCopyImageTestsAllFormats(imgToImgAllFormatsTests.get(), testCtx, params);
3520 imageToImageTests->addChild(imgToImgSimpleTests.release());
3521 imageToImageTests->addChild(imgToImgAllFormatsTests.release());
3523 // Copy image to buffer testcases.
3526 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3527 params.src.image.extent = defaultExtent;
3528 params.dst.buffer.size = defaultSize * defaultSize;
3530 const VkBufferImageCopy bufferImageCopy =
3532 0u, // VkDeviceSize bufferOffset;
3533 0u, // uint32_t bufferRowLength;
3534 0u, // uint32_t bufferImageHeight;
3535 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
3536 {0, 0, 0}, // VkOffset3D imageOffset;
3537 {defaultFourthSize, defaultFourthSize, 1} // VkExtent3D imageExtent;
3539 CopyRegion copyRegion;
3540 copyRegion.bufferImageCopy = bufferImageCopy;
3542 params.regions.push_back(copyRegion);
3544 imageToBufferTests->addChild(new CopyImageToBufferTestCase(testCtx, "whole", "Copy from image to buffer", params));
3547 // Copy buffer to image testcases.
3550 params.src.buffer.size = defaultSize * defaultSize;
3551 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3552 params.dst.image.extent = defaultExtent;
3554 const VkBufferImageCopy bufferImageCopy =
3556 0u, // VkDeviceSize bufferOffset;
3557 0u, // uint32_t bufferRowLength;
3558 0u, // uint32_t bufferImageHeight;
3559 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
3560 {0, 0, 0}, // VkOffset3D imageOffset;
3561 {defaultFourthSize, defaultFourthSize, 1} // VkExtent3D imageExtent;
3563 CopyRegion copyRegion;
3564 copyRegion.bufferImageCopy = bufferImageCopy;
3566 params.regions.push_back(copyRegion);
3568 bufferToImageTests->addChild(new CopyBufferToImageTestCase(testCtx, "whole", "Copy from buffer to image", params));
3571 // Copy buffer to buffer testcases.
3574 params.src.buffer.size = defaultSize;
3575 params.dst.buffer.size = defaultSize;
3577 const VkBufferCopy bufferCopy =
3579 0u, // VkDeviceSize srcOffset;
3580 0u, // VkDeviceSize dstOffset;
3581 defaultSize, // VkDeviceSize size;
3584 CopyRegion copyRegion;
3585 copyRegion.bufferCopy = bufferCopy;
3586 params.regions.push_back(copyRegion);
3588 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "whole", "Whole buffer", params));
3593 params.src.buffer.size = defaultFourthSize;
3594 params.dst.buffer.size = defaultFourthSize;
3596 const VkBufferCopy bufferCopy =
3598 12u, // VkDeviceSize srcOffset;
3599 4u, // VkDeviceSize dstOffset;
3600 1u, // VkDeviceSize size;
3603 CopyRegion copyRegion;
3604 copyRegion.bufferCopy = bufferCopy;
3605 params.regions.push_back(copyRegion);
3607 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "partial", "Partial", params));
3611 const deUint32 size = 16;
3613 params.src.buffer.size = size;
3614 params.dst.buffer.size = size * (size + 1);
3616 // Copy region with size 1..size
3617 for (unsigned int i = 1; i <= size; i++)
3619 const VkBufferCopy bufferCopy =
3621 0, // VkDeviceSize srcOffset;
3622 i * size, // VkDeviceSize dstOffset;
3623 i, // VkDeviceSize size;
3626 CopyRegion copyRegion;
3627 copyRegion.bufferCopy = bufferCopy;
3628 params.regions.push_back(copyRegion);
3631 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "regions", "Multiple regions", params));
3634 // Blitting testcases.
3636 const std::string description ("Blit without scaling (whole)");
3637 const std::string testName ("whole");
3640 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3641 params.src.image.extent = defaultExtent;
3642 params.dst.image.extent = defaultExtent;
3645 const VkImageBlit imageBlit =
3647 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3650 {defaultSize, defaultSize, 1}
3651 }, // VkOffset3D srcOffsets[2];
3653 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3656 {defaultSize, defaultSize, 1}
3657 } // VkOffset3D dstOffset[2];
3661 region.imageBlit = imageBlit;
3662 params.regions.push_back(region);
3665 // Filter is VK_FILTER_NEAREST.
3667 params.filter = VK_FILTER_NEAREST;
3669 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3670 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3672 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3673 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3674 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3676 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3677 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3678 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3681 // Filter is VK_FILTER_LINEAR.
3683 params.filter = VK_FILTER_LINEAR;
3685 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3686 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3688 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3689 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3690 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3692 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3693 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3694 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3699 const std::string description ("Blit with scaling (whole, src extent bigger)");
3700 const std::string testName ("scaling_whole1");
3703 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3704 params.src.image.extent = defaultExtent;
3705 params.dst.image.extent = defaultHalfExtent;
3708 const VkImageBlit imageBlit =
3710 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3713 {defaultSize, defaultSize, 1}
3714 }, // VkOffset3D srcOffsets[2];
3716 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3719 {defaultHalfSize, defaultHalfSize, 1}
3720 } // VkOffset3D dstOffset[2];
3724 region.imageBlit = imageBlit;
3725 params.regions.push_back(region);
3728 // Filter is VK_FILTER_NEAREST.
3730 params.filter = VK_FILTER_NEAREST;
3732 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3733 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3735 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3736 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3737 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3739 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3740 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3741 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3744 // Filter is VK_FILTER_LINEAR.
3746 params.filter = VK_FILTER_LINEAR;
3748 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3749 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3751 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3752 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3753 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3755 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3756 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3757 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3762 const std::string description ("Blit with scaling (whole, dst extent bigger)");
3763 const std::string testName ("scaling_whole2");
3766 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3767 params.src.image.extent = defaultHalfExtent;
3768 params.dst.image.extent = defaultExtent;
3771 const VkImageBlit imageBlit =
3773 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3776 {defaultHalfSize, defaultHalfSize, 1}
3777 }, // VkOffset3D srcOffsets[2];
3779 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3782 {defaultSize, defaultSize, 1}
3783 } // VkOffset3D dstOffset[2];
3787 region.imageBlit = imageBlit;
3788 params.regions.push_back(region);
3791 // Filter is VK_FILTER_NEAREST.
3793 params.filter = VK_FILTER_NEAREST;
3795 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3796 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3798 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3799 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3800 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3802 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3803 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3804 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3807 // Filter is VK_FILTER_LINEAR.
3809 params.filter = VK_FILTER_LINEAR;
3811 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3812 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3814 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3815 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3816 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3818 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3819 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3820 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3825 const std::string description ("Blit with scaling and offset (whole, dst extent bigger)");
3826 const std::string testName ("scaling_and_offset");
3829 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3830 params.src.image.extent = defaultExtent;
3831 params.dst.image.extent = defaultExtent;
3834 const VkImageBlit imageBlit =
3836 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3838 {defaultFourthSize, defaultFourthSize, 0},
3839 {defaultFourthSize*3, defaultFourthSize*3, 1}
3840 }, // VkOffset3D srcOffsets[2];
3842 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3845 {defaultSize, defaultSize, 1}
3846 } // VkOffset3D dstOffset[2];
3850 region.imageBlit = imageBlit;
3851 params.regions.push_back(region);
3854 // Filter is VK_FILTER_NEAREST.
3856 params.filter = VK_FILTER_NEAREST;
3858 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3859 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3862 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3863 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3864 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3866 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3867 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3868 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3871 // Filter is VK_FILTER_LINEAR.
3873 params.filter = VK_FILTER_LINEAR;
3875 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3876 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3878 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3879 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3880 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3882 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3883 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3884 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3889 const std::string description ("Blit without scaling (partial)");
3890 const std::string testName ("without_scaling_partial");
3893 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3894 params.src.image.extent = defaultExtent;
3895 params.dst.image.extent = defaultExtent;
3899 for (int i = 0; i < defaultSize; i += defaultFourthSize)
3901 const VkImageBlit imageBlit =
3903 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3905 {defaultSize - defaultFourthSize - i, defaultSize - defaultFourthSize - i, 0},
3906 {defaultSize - i, defaultSize - i, 1}
3907 }, // VkOffset3D srcOffsets[2];
3909 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3912 {i + defaultFourthSize, i + defaultFourthSize, 1}
3913 } // VkOffset3D dstOffset[2];
3915 region.imageBlit = imageBlit;
3916 params.regions.push_back(region);
3920 // Filter is VK_FILTER_NEAREST.
3922 params.filter = VK_FILTER_NEAREST;
3924 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3925 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3928 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3929 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3930 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3932 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3933 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3934 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3937 // Filter is VK_FILTER_LINEAR.
3939 params.filter = VK_FILTER_LINEAR;
3941 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3942 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3944 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3945 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3946 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3948 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3949 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3950 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3955 const std::string description ("Blit with scaling (partial)");
3956 const std::string testName ("scaling_partial");
3958 // Test Color formats.
3961 params.src.image.extent = defaultExtent;
3962 params.dst.image.extent = defaultExtent;
3965 for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
3967 const VkImageBlit imageBlit =
3969 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3972 {defaultSize, defaultSize, 1}
3973 }, // VkOffset3D srcOffsets[2];
3975 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3978 {i + defaultFourthSize / j, defaultFourthSize / j, 1}
3979 } // VkOffset3D dstOffset[2];
3981 region.imageBlit = imageBlit;
3982 params.regions.push_back(region);
3984 for (int i = 0; i < defaultSize; i += defaultFourthSize)
3986 const VkImageBlit imageBlit =
3988 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3991 {i + defaultFourthSize, i + defaultFourthSize, 1}
3992 }, // VkOffset3D srcOffsets[2];
3994 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3996 {i, defaultSize / 2, 0},
3997 {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1}
3998 } // VkOffset3D dstOffset[2];
4000 region.imageBlit = imageBlit;
4001 params.regions.push_back(region);
4004 addBlittingTestsAllFormats(blitImgAllFormatsTests.get(), testCtx, params);
4007 // Test Depth and Stencil formats.
4009 const VkFormat compatibleDepthAndStencilFormats[] =
4011 VK_FORMAT_D16_UNORM,
4012 VK_FORMAT_X8_D24_UNORM_PACK32,
4013 VK_FORMAT_D32_SFLOAT,
4015 VK_FORMAT_D16_UNORM_S8_UINT,
4016 VK_FORMAT_D24_UNORM_S8_UINT,
4017 VK_FORMAT_D32_SFLOAT_S8_UINT,
4020 for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < DE_LENGTH_OF_ARRAY(compatibleDepthAndStencilFormats); ++compatibleFormatsIndex)
4024 params.src.image.extent = defaultExtent;
4025 params.dst.image.extent = defaultExtent;
4026 params.src.image.format = compatibleDepthAndStencilFormats[compatibleFormatsIndex];
4027 params.dst.image.format = params.src.image.format;
4028 std::ostringstream oss;
4029 oss << testName << "_" << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
4031 const VkImageSubresourceLayers defaultDepthSourceLayer = { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u };
4032 const VkImageSubresourceLayers defaultStencilSourceLayer = { VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u };
4035 for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
4037 const VkOffset3D srcOffset0 = {0, 0, 0};
4038 const VkOffset3D srcOffset1 = {defaultSize, defaultSize, 1};
4039 const VkOffset3D dstOffset0 = {i, 0, 0};
4040 const VkOffset3D dstOffset1 = {i + defaultFourthSize / j, defaultFourthSize / j, 1};
4042 if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
4044 const VkImageBlit imageBlit =
4046 defaultDepthSourceLayer, // VkImageSubresourceLayers srcSubresource;
4047 { srcOffset0 , srcOffset1 }, // VkOffset3D srcOffsets[2];
4048 defaultDepthSourceLayer, // VkImageSubresourceLayers dstSubresource;
4049 { dstOffset0 , dstOffset1 }, // VkOffset3D dstOffset[2];
4051 region.imageBlit = imageBlit;
4052 params.regions.push_back(region);
4054 if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
4056 const VkImageBlit imageBlit =
4058 defaultStencilSourceLayer, // VkImageSubresourceLayers srcSubresource;
4059 { srcOffset0 , srcOffset1 }, // VkOffset3D srcOffsets[2];
4060 defaultStencilSourceLayer, // VkImageSubresourceLayers dstSubresource;
4061 { dstOffset0 , dstOffset1 }, // VkOffset3D dstOffset[2];
4063 region.imageBlit = imageBlit;
4064 params.regions.push_back(region);
4067 for (int i = 0; i < defaultSize; i += defaultFourthSize)
4069 const VkOffset3D srcOffset0 = {i, i, 0};
4070 const VkOffset3D srcOffset1 = {i + defaultFourthSize, i + defaultFourthSize, 1};
4071 const VkOffset3D dstOffset0 = {i, defaultSize / 2, 0};
4072 const VkOffset3D dstOffset1 = {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1};
4074 if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
4076 const VkImageBlit imageBlit =
4078 defaultDepthSourceLayer, // VkImageSubresourceLayers srcSubresource;
4079 { srcOffset0, srcOffset1 }, // VkOffset3D srcOffsets[2];
4080 defaultDepthSourceLayer, // VkImageSubresourceLayers dstSubresource;
4081 { dstOffset0, dstOffset1 } // VkOffset3D dstOffset[2];
4083 region.imageBlit = imageBlit;
4084 params.regions.push_back(region);
4086 if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
4088 const VkImageBlit imageBlit =
4090 defaultStencilSourceLayer, // VkImageSubresourceLayers srcSubresource;
4091 { srcOffset0, srcOffset1 }, // VkOffset3D srcOffsets[2];
4092 defaultStencilSourceLayer, // VkImageSubresourceLayers dstSubresource;
4093 { dstOffset0, dstOffset1 } // VkOffset3D dstOffset[2];
4095 region.imageBlit = imageBlit;
4096 params.regions.push_back(region);
4100 params.filter = VK_FILTER_NEAREST;
4101 blitImgAllFormatsTests->addChild(new BlittingTestCase(testCtx, oss.str() + "_nearest", description, params));
4105 blittingImageTests->addChild(blitImgSimpleTests.release());
4106 blittingImageTests->addChild(blitImgAllFormatsTests.release());
4109 // Resolve image to image testcases.
4110 const VkSampleCountFlagBits samples[] =
4112 VK_SAMPLE_COUNT_2_BIT,
4113 VK_SAMPLE_COUNT_4_BIT,
4114 VK_SAMPLE_COUNT_8_BIT,
4115 VK_SAMPLE_COUNT_16_BIT,
4116 VK_SAMPLE_COUNT_32_BIT,
4117 VK_SAMPLE_COUNT_64_BIT
4119 const VkExtent3D resolveExtent = {256u, 256u, 1};
4122 const std::string description ("Resolve from image to image");
4123 const std::string testName ("whole");
4126 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4127 params.src.image.extent = resolveExtent;
4128 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4129 params.dst.image.extent = resolveExtent;
4132 const VkImageSubresourceLayers sourceLayer =
4134 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4135 0u, // uint32_t mipLevel;
4136 0u, // uint32_t baseArrayLayer;
4137 1u // uint32_t layerCount;
4139 const VkImageResolve testResolve =
4141 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4142 {0, 0, 0}, // VkOffset3D srcOffset;
4143 sourceLayer, // VkImageSubresourceLayers dstSubresource;
4144 {0, 0, 0}, // VkOffset3D dstOffset;
4145 resolveExtent, // VkExtent3D extent;
4148 CopyRegion imageResolve;
4149 imageResolve.imageResolve = testResolve;
4150 params.regions.push_back(imageResolve);
4153 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4155 params.samples = samples[samplesIndex];
4156 std::ostringstream caseName;
4157 caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4158 resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4163 const std::string description ("Resolve from image to image");
4164 const std::string testName ("partial");
4167 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4168 params.src.image.extent = resolveExtent;
4169 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4170 params.dst.image.extent = resolveExtent;
4173 const VkImageSubresourceLayers sourceLayer =
4175 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4176 0u, // uint32_t mipLevel;
4177 0u, // uint32_t baseArrayLayer;
4178 1u // uint32_t layerCount;
4180 const VkImageResolve testResolve =
4182 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4183 {0, 0, 0}, // VkOffset3D srcOffset;
4184 sourceLayer, // VkImageSubresourceLayers dstSubresource;
4185 {64u, 64u, 0}, // VkOffset3D dstOffset;
4186 {128u, 128u, 1u}, // VkExtent3D extent;
4189 CopyRegion imageResolve;
4190 imageResolve.imageResolve = testResolve;
4191 params.regions.push_back(imageResolve);
4194 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4196 params.samples = samples[samplesIndex];
4197 std::ostringstream caseName;
4198 caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4199 resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4204 const std::string description ("Resolve from image to image");
4205 const std::string testName ("with_regions");
4208 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4209 params.src.image.extent = resolveExtent;
4210 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4211 params.dst.image.extent = resolveExtent;
4214 const VkImageSubresourceLayers sourceLayer =
4216 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4217 0u, // uint32_t mipLevel;
4218 0u, // uint32_t baseArrayLayer;
4219 1u // uint32_t layerCount;
4222 for (int i = 0; i < 256; i += 64)
4224 const VkImageResolve testResolve =
4226 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4227 {i, i, 0}, // VkOffset3D srcOffset;
4228 sourceLayer, // VkImageSubresourceLayers dstSubresource;
4229 {i, 0, 0}, // VkOffset3D dstOffset;
4230 {64u, 64u, 1u}, // VkExtent3D extent;
4233 CopyRegion imageResolve;
4234 imageResolve.imageResolve = testResolve;
4235 params.regions.push_back(imageResolve);
4239 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4241 params.samples = samples[samplesIndex];
4242 std::ostringstream caseName;
4243 caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4244 resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4248 copiesAndBlittingTests->addChild(imageToImageTests.release());
4249 copiesAndBlittingTests->addChild(imageToBufferTests.release());
4250 copiesAndBlittingTests->addChild(bufferToImageTests.release());
4251 copiesAndBlittingTests->addChild(bufferToBufferTests.release());
4252 copiesAndBlittingTests->addChild(blittingImageTests.release());
4253 copiesAndBlittingTests->addChild(resolveImageTests.release());
4255 return copiesAndBlittingTests.release();