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"
53 static VkImageAspectFlags getAspectFlags (tcu::TextureFormat format)
55 VkImageAspectFlags aspectFlag = 0;
56 aspectFlag |= (tcu::hasDepthComponent(format.order)? VK_IMAGE_ASPECT_DEPTH_BIT : 0);
57 aspectFlag |= (tcu::hasStencilComponent(format.order)? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
60 aspectFlag = VK_IMAGE_ASPECT_COLOR_BIT;
70 VkBufferCopy bufferCopy;
71 VkImageCopy imageCopy;
72 VkBufferImageCopy bufferImageCopy;
73 VkImageBlit imageBlit;
74 VkImageResolve imageResolve;
92 std::vector<CopyRegion> regions;
96 VkSampleCountFlagBits samples;
100 class CopiesAndBlittingTestInstance : public vkt::TestInstance
103 CopiesAndBlittingTestInstance (Context& context,
104 TestParams testParams);
105 virtual tcu::TestStatus iterate (void) = 0;
109 FILL_MODE_GRADIENT = 0,
112 FILL_MODE_MULTISAMPLE,
117 const TestParams m_params;
119 Move<VkCommandPool> m_cmdPool;
120 Move<VkCommandBuffer> m_cmdBuffer;
121 Move<VkFence> m_fence;
122 de::MovePtr<tcu::TextureLevel> m_sourceTextureLevel;
123 de::MovePtr<tcu::TextureLevel> m_destinationTextureLevel;
124 de::MovePtr<tcu::TextureLevel> m_expectedTextureLevel;
126 VkCommandBufferBeginInfo m_cmdBufferBeginInfo;
128 void generateBuffer (tcu::PixelBufferAccess buffer, int width, int height, int depth = 1, FillMode = FILL_MODE_GRADIENT);
129 virtual void generateExpectedResult (void);
130 void uploadBuffer (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc);
131 void uploadImage (tcu::ConstPixelBufferAccess imageAccess, const VkImage& image);
132 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
133 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region) = 0;
134 deUint32 calculateSize (tcu::ConstPixelBufferAccess src) const
136 return src.getWidth() * src.getHeight() * src.getDepth() * tcu::getPixelSize(src.getFormat());
139 de::MovePtr<tcu::TextureLevel> readImage (const vk::DeviceInterface& vk,
142 vk::Allocator& allocator,
145 const VkExtent3D imageSize);
148 CopiesAndBlittingTestInstance::CopiesAndBlittingTestInstance (Context& context, TestParams testParams)
149 : vkt::TestInstance (context)
150 , m_params (testParams)
152 const DeviceInterface& vk = context.getDeviceInterface();
153 const VkDevice vkDevice = context.getDevice();
154 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
156 // Create command pool
158 const VkCommandPoolCreateInfo cmdPoolParams =
160 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
161 DE_NULL, // const void* pNext;
162 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCmdPoolCreateFlags flags;
163 queueFamilyIndex, // deUint32 queueFamilyIndex;
166 m_cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
169 // Create command buffer
171 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
173 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
174 DE_NULL, // const void* pNext;
175 *m_cmdPool, // VkCommandPool commandPool;
176 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
177 1u // deUint32 bufferCount;
180 m_cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
185 const VkFenceCreateInfo fenceParams =
187 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
188 DE_NULL, // const void* pNext;
189 0u // VkFenceCreateFlags flags;
192 m_fence = createFence(vk, vkDevice, &fenceParams);
196 void CopiesAndBlittingTestInstance::generateBuffer (tcu::PixelBufferAccess buffer, int width, int height, int depth, FillMode mode)
198 if (mode == FILL_MODE_GRADIENT)
200 tcu::fillWithComponentGradients(buffer, tcu::Vec4(0.0f, 0.0f, 0.0f, 0.0f), tcu::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
204 const tcu::Vec4 redColor (1.0, 0.0, 0.0, 1.0);
205 const tcu::Vec4 greenColor (0.0, 1.0, 0.0, 1.0);
206 const tcu::Vec4 blueColor (0.0, 0.0, 1.0, 1.0);
207 const tcu::Vec4 whiteColor (1.0, 1.0, 1.0, 1.0);
209 for (int z = 0; z < depth; z++)
211 for (int y = 0; y < height; y++)
213 for (int x = 0; x < width; x++)
217 case FILL_MODE_WHITE:
218 if (tcu::isCombinedDepthStencilType(buffer.getFormat().type))
220 buffer.setPixDepth(1.0f, x, y, z);
221 if (tcu::hasStencilComponent(buffer.getFormat().order))
222 buffer.setPixStencil(255, x, y, z);
225 buffer.setPixel(whiteColor, x, y, z);
228 DE_ASSERT(!tcu::isCombinedDepthStencilType(buffer.getFormat().type)); // combined types cannot be accessed directly
229 buffer.setPixel(redColor, x, y, z);
231 case FILL_MODE_MULTISAMPLE:
232 buffer.setPixel((x == y) ? tcu::Vec4(0.0, 0.5, 0.5, 1.0) : ((x > y) ? greenColor : blueColor), x, y, z);
242 void CopiesAndBlittingTestInstance::uploadBuffer (tcu::ConstPixelBufferAccess bufferAccess, const Allocation& bufferAlloc)
244 const DeviceInterface& vk = m_context.getDeviceInterface();
245 const VkDevice vkDevice = m_context.getDevice();
246 const deUint32 bufferSize = calculateSize(bufferAccess);
249 deMemcpy(bufferAlloc.getHostPtr(), bufferAccess.getDataPtr(), bufferSize);
250 flushMappedMemoryRange(vk, vkDevice, bufferAlloc.getMemory(), bufferAlloc.getOffset(), bufferSize);
253 void CopiesAndBlittingTestInstance::uploadImage (tcu::ConstPixelBufferAccess imageAccess, const VkImage& image)
255 const DeviceInterface& vk = m_context.getDeviceInterface();
256 const VkDevice vkDevice = m_context.getDevice();
257 const VkQueue queue = m_context.getUniversalQueue();
258 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
259 Allocator& memAlloc = m_context.getDefaultAllocator();
261 Move<VkBuffer> buffer;
262 const deUint32 bufferSize = calculateSize(imageAccess);
263 de::MovePtr<Allocation> bufferAlloc;
264 Move<VkCommandBuffer> cmdBuffer;
266 // Create source buffer
268 const VkBufferCreateInfo bufferParams =
270 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
271 DE_NULL, // const void* pNext;
272 0u, // VkBufferCreateFlags flags;
273 bufferSize, // VkDeviceSize size;
274 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
275 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
276 1u, // deUint32 queueFamilyIndexCount;
277 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
280 buffer = createBuffer(vk, vkDevice, &bufferParams);
281 bufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *buffer), MemoryRequirement::HostVisible);
282 VK_CHECK(vk.bindBufferMemory(vkDevice, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
285 // Create command buffer
287 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
289 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
290 DE_NULL, // const void* pNext;
291 *m_cmdPool, // VkCommandPool commandPool;
292 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
293 1u, // deUint32 bufferCount;
296 cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
299 // Barriers for copying buffer to image
300 const VkBufferMemoryBarrier preBufferBarrier =
302 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
303 DE_NULL, // const void* pNext;
304 VK_ACCESS_HOST_WRITE_BIT, // VkAccessFlags srcAccessMask;
305 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
306 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
307 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
308 *buffer, // VkBuffer buffer;
309 0u, // VkDeviceSize offset;
310 bufferSize // VkDeviceSize size;
313 const VkImageAspectFlags aspect = getAspectFlags(imageAccess.getFormat());
314 const VkImageMemoryBarrier preImageBarrier =
316 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
317 DE_NULL, // const void* pNext;
318 0u, // VkAccessFlags srcAccessMask;
319 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
320 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
321 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
322 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
323 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
324 image, // VkImage image;
325 { // VkImageSubresourceRange subresourceRange;
326 aspect, // VkImageAspectFlags aspect;
327 0u, // deUint32 baseMipLevel;
328 1u, // deUint32 mipLevels;
329 0u, // deUint32 baseArraySlice;
330 1u, // deUint32 arraySize;
334 const VkImageMemoryBarrier postImageBarrier =
336 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
337 DE_NULL, // const void* pNext;
338 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
339 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
340 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
341 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
342 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
343 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
344 image, // VkImage image;
345 { // VkImageSubresourceRange subresourceRange;
346 aspect, // VkImageAspectFlags aspect;
347 0u, // deUint32 baseMipLevel;
348 1u, // deUint32 mipLevels;
349 0u, // deUint32 baseArraySlice;
350 1u, // deUint32 arraySize;
354 const VkExtent3D imageExtent = { (deUint32)imageAccess.getWidth(), (deUint32)imageAccess.getHeight(), 1u };
355 const deUint32 regionCount = tcu::isCombinedDepthStencilType(imageAccess.getFormat().type) ? 2u : 1u;
356 const VkImageAspectFlags firstRegionAspect = aspect & VK_IMAGE_ASPECT_DEPTH_BIT ? VkImageAspectFlags(VK_IMAGE_ASPECT_DEPTH_BIT) : aspect;
357 const VkBufferImageCopy copyRegion[] =
360 0u, // VkDeviceSize bufferOffset;
361 (deUint32)imageAccess.getWidth(), // deUint32 bufferRowLength;
362 (deUint32)imageAccess.getHeight(), // deUint32 bufferImageHeight;
363 { // VkImageSubresourceLayers imageSubresource;
364 firstRegionAspect, // VkImageAspectFlags aspect;
365 0u, // deUint32 mipLevel;
366 0u, // deUint32 baseArrayLayer;
367 1u, // deUint32 layerCount;
369 { 0, 0, 0 }, // VkOffset3D imageOffset;
370 imageExtent // VkExtent3D imageExtent;
373 0u, // VkDeviceSize bufferOffset;
374 (deUint32)imageAccess.getWidth(), // deUint32 bufferRowLength;
375 (deUint32)imageAccess.getHeight(), // deUint32 bufferImageHeight;
376 { // VkImageSubresourceLayers imageSubresource;
377 VK_IMAGE_ASPECT_STENCIL_BIT, // VkImageAspectFlags aspect;
378 0u, // deUint32 mipLevel;
379 0u, // deUint32 baseArrayLayer;
380 1u, // deUint32 layerCount;
382 { 0, 0, 0 }, // VkOffset3D imageOffset;
383 imageExtent // VkExtent3D imageExtent;
388 deMemcpy(bufferAlloc->getHostPtr(), imageAccess.getDataPtr(), bufferSize);
389 flushMappedMemoryRange(vk, vkDevice, bufferAlloc->getMemory(), bufferAlloc->getOffset(), bufferSize);
391 // Copy buffer to image
392 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
394 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
395 DE_NULL, // const void* pNext;
396 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
397 (const VkCommandBufferInheritanceInfo*)DE_NULL,
400 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
401 vk.cmdPipelineBarrier(*cmdBuffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, (VkDependencyFlags)0, 0, (const VkMemoryBarrier*)DE_NULL, 1, &preBufferBarrier, 1, &preImageBarrier);
402 vk.cmdCopyBufferToImage(*cmdBuffer, *buffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, regionCount, copyRegion);
403 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);
404 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
406 const VkSubmitInfo submitInfo =
408 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
409 DE_NULL, // const void* pNext;
410 0u, // deUint32 waitSemaphoreCount;
411 DE_NULL, // const VkSemaphore* pWaitSemaphores;
412 (const VkPipelineStageFlags*)DE_NULL,
413 1u, // deUint32 commandBufferCount;
414 &cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
415 0u, // deUint32 signalSemaphoreCount;
416 DE_NULL // const VkSemaphore* pSignalSemaphores;
419 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
420 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
421 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
424 tcu::TestStatus CopiesAndBlittingTestInstance::checkTestResult (tcu::ConstPixelBufferAccess result)
426 const tcu::ConstPixelBufferAccess expected = m_expectedTextureLevel->getAccess();
428 if (isFloatFormat(mapTextureFormat(result.getFormat())))
430 const tcu::Vec4 threshold (0.0f);
431 if (!tcu::floatThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
432 return tcu::TestStatus::fail("CopiesAndBlitting test");
436 const tcu::UVec4 threshold (0u);
437 if (!tcu::intThresholdCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, threshold, tcu::COMPARE_LOG_RESULT))
438 return tcu::TestStatus::fail("CopiesAndBlitting test");
441 return tcu::TestStatus::pass("CopiesAndBlitting test");
444 void CopiesAndBlittingTestInstance::generateExpectedResult (void)
446 const tcu::ConstPixelBufferAccess src = m_sourceTextureLevel->getAccess();
447 const tcu::ConstPixelBufferAccess dst = m_destinationTextureLevel->getAccess();
449 m_expectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
450 tcu::copy(m_expectedTextureLevel->getAccess(), dst);
451 for (deUint32 i = 0; i < m_params.regions.size(); i++)
452 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), m_params.regions[i]);
455 class CopiesAndBlittingTestCase : public vkt::TestCase
458 CopiesAndBlittingTestCase (tcu::TestContext& testCtx,
459 const std::string& name,
460 const std::string& description)
461 : vkt::TestCase (testCtx, name, description)
464 virtual TestInstance* createInstance (Context& context) const = 0;
467 de::MovePtr<tcu::TextureLevel> CopiesAndBlittingTestInstance::readImage (const vk::DeviceInterface& vk,
470 vk::Allocator& allocator,
473 const VkExtent3D imageSize)
475 Move<VkBuffer> buffer;
476 de::MovePtr<Allocation> bufferAlloc;
477 Move<VkCommandBuffer> cmdBuffer;
478 const deUint32 queueFamilyIndex = m_context.getUniversalQueueFamilyIndex();
479 const tcu::TextureFormat tcuFormat = mapVkFormat(format);
480 const VkDeviceSize pixelDataSize = imageSize.width * imageSize.height * imageSize.depth * tcu::getPixelSize(tcuFormat);
481 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(tcuFormat, imageSize.width, imageSize.height, imageSize.depth));
483 // Create destination buffer
485 const VkBufferCreateInfo bufferParams =
487 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
488 DE_NULL, // const void* pNext;
489 0u, // VkBufferCreateFlags flags;
490 pixelDataSize, // VkDeviceSize size;
491 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
492 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
493 1u, // deUint32 queueFamilyIndexCount;
494 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
497 buffer = createBuffer(vk, device, &bufferParams);
498 bufferAlloc = allocator.allocate(getBufferMemoryRequirements(vk, device, *buffer), MemoryRequirement::HostVisible);
499 VK_CHECK(vk.bindBufferMemory(device, *buffer, bufferAlloc->getMemory(), bufferAlloc->getOffset()));
502 // Create command pool and buffer
504 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
506 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
507 DE_NULL, // const void* pNext;
508 *m_cmdPool, // VkCommandPool commandPool;
509 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
510 1u // deUint32 bufferCount;
513 cmdBuffer = allocateCommandBuffer(vk, device, &cmdBufferAllocateInfo);
516 // Barriers for copying image to buffer
517 const VkImageAspectFlags aspect = getAspectFlags(tcuFormat);
518 const VkImageMemoryBarrier imageBarrier =
520 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
521 DE_NULL, // const void* pNext;
522 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
523 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
524 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
525 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
526 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
527 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
528 image, // VkImage image;
529 { // VkImageSubresourceRange subresourceRange;
530 aspect, // VkImageAspectFlags aspectMask;
531 0u, // deUint32 baseMipLevel;
532 1u, // deUint32 mipLevels;
533 0u, // deUint32 baseArraySlice;
534 1u // deUint32 arraySize;
538 const VkBufferMemoryBarrier bufferBarrier =
540 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
541 DE_NULL, // const void* pNext;
542 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
543 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
544 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
545 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
546 *buffer, // VkBuffer buffer;
547 0u, // VkDeviceSize offset;
548 pixelDataSize // VkDeviceSize size;
551 // Copy image to buffer
552 const deUint32 regionCount = tcu::isCombinedDepthStencilType(tcuFormat.type) ? 2u : 1u;
553 const VkImageAspectFlags firstRegionAspect = aspect & VK_IMAGE_ASPECT_DEPTH_BIT ? VkImageAspectFlags(VK_IMAGE_ASPECT_DEPTH_BIT) : aspect;
554 const VkBufferImageCopy copyRegion[] =
557 0u, // VkDeviceSize bufferOffset;
558 (deUint32)imageSize.width, // deUint32 bufferRowLength;
559 (deUint32)imageSize.height, // deUint32 bufferImageHeight;
560 { // VkImageSubresourceLayers imageSubresource;
561 firstRegionAspect, // VkImageAspectFlags aspect;
562 0u, // deUint32 mipLevel;
563 0u, // deUint32 baseArrayLayer;
564 1u, // deUint32 layerCount;
566 { 0, 0, 0 }, // VkOffset3D imageOffset;
567 imageSize // VkExtent3D imageExtent;
570 0u, // VkDeviceSize bufferOffset;
571 (deUint32)imageSize.width, // deUint32 bufferRowLength;
572 (deUint32)imageSize.height, // deUint32 bufferImageHeight;
573 { // VkImageSubresourceLayers imageSubresource;
574 VK_IMAGE_ASPECT_STENCIL_BIT, // VkImageAspectFlags aspect;
575 0u, // deUint32 mipLevel;
576 0u, // deUint32 baseArrayLayer;
577 1u, // deUint32 layerCount;
579 { 0, 0, 0 }, // VkOffset3D imageOffset;
580 imageSize // VkExtent3D imageExtent;
584 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
586 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
587 DE_NULL, // const void* pNext;
588 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
589 (const VkCommandBufferInheritanceInfo*)DE_NULL,
592 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
593 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);
594 vk.cmdCopyImageToBuffer(*cmdBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, *buffer, regionCount, copyRegion);
595 vk.cmdPipelineBarrier(*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);
596 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
598 const VkSubmitInfo submitInfo =
600 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
601 DE_NULL, // const void* pNext;
602 0u, // deUint32 waitSemaphoreCount;
603 DE_NULL, // const VkSemaphore* pWaitSemaphores;
604 (const VkPipelineStageFlags*)DE_NULL,
605 1u, // deUint32 commandBufferCount;
606 &cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
607 0u, // deUint32 signalSemaphoreCount;
608 DE_NULL // const VkSemaphore* pSignalSemaphores;
611 VK_CHECK(vk.resetFences(device, 1, &m_fence.get()));
612 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
613 VK_CHECK(vk.waitForFences(device, 1, &m_fence.get(), 0, ~(0ull) /* infinity */));
616 invalidateMappedMemoryRange(vk, device, bufferAlloc->getMemory(), bufferAlloc->getOffset(), pixelDataSize);
617 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), bufferAlloc->getHostPtr()));
622 // Copy from image to image.
624 class CopyImageToImage : public CopiesAndBlittingTestInstance
627 CopyImageToImage (Context& context,
629 virtual tcu::TestStatus iterate (void);
631 Move<VkImage> m_source;
632 de::MovePtr<Allocation> m_sourceImageAlloc;
633 Move<VkImage> m_destination;
634 de::MovePtr<Allocation> m_destinationImageAlloc;
636 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
639 CopyImageToImage::CopyImageToImage (Context& context, TestParams params)
640 : CopiesAndBlittingTestInstance(context, params)
642 const DeviceInterface& vk = context.getDeviceInterface();
643 const VkDevice vkDevice = context.getDevice();
644 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
645 Allocator& memAlloc = context.getDefaultAllocator();
647 VkImageFormatProperties properties;
648 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
649 m_params.src.image.format,
651 VK_IMAGE_TILING_OPTIMAL,
652 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
654 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
655 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
656 m_params.dst.image.format,
658 VK_IMAGE_TILING_OPTIMAL,
659 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
661 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
663 TCU_THROW(NotSupportedError, "Format not supported");
666 // Create source image
668 const VkImageCreateInfo sourceImageParams =
670 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
671 DE_NULL, // const void* pNext;
672 0u, // VkImageCreateFlags flags;
673 VK_IMAGE_TYPE_2D, // VkImageType imageType;
674 m_params.src.image.format, // VkFormat format;
675 m_params.src.image.extent, // VkExtent3D extent;
676 1u, // deUint32 mipLevels;
677 1u, // deUint32 arraySize;
678 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
679 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
680 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
681 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
682 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
683 1u, // deUint32 queueFamilyCount;
684 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
685 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
688 m_source = createImage(vk, vkDevice, &sourceImageParams);
689 m_sourceImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
690 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
693 // Create destination image
695 const VkImageCreateInfo destinationImageParams =
697 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
698 DE_NULL, // const void* pNext;
699 0u, // VkImageCreateFlags flags;
700 VK_IMAGE_TYPE_2D, // VkImageType imageType;
701 m_params.dst.image.format, // VkFormat format;
702 m_params.dst.image.extent, // VkExtent3D extent;
703 1u, // deUint32 mipLevels;
704 1u, // deUint32 arraySize;
705 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
706 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
707 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
708 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
709 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
710 1u, // deUint32 queueFamilyCount;
711 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
712 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
715 m_destination = createImage(vk, vkDevice, &destinationImageParams);
716 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
717 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
721 tcu::TestStatus CopyImageToImage::iterate (void)
723 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
724 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
725 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
726 m_params.src.image.extent.width,
727 m_params.src.image.extent.height,
728 m_params.src.image.extent.depth));
729 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);
730 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
731 (int)m_params.dst.image.extent.width,
732 (int)m_params.dst.image.extent.height,
733 (int)m_params.dst.image.extent.depth));
734 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);
735 generateExpectedResult();
737 uploadImage(m_sourceTextureLevel->getAccess(), m_source.get());
738 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
740 const DeviceInterface& vk = m_context.getDeviceInterface();
741 const VkDevice vkDevice = m_context.getDevice();
742 const VkQueue queue = m_context.getUniversalQueue();
743 Allocator& memAlloc = m_context.getDefaultAllocator();
745 std::vector<VkImageCopy> imageCopies;
746 for (deUint32 i = 0; i < m_params.regions.size(); i++)
747 imageCopies.push_back(m_params.regions[i].imageCopy);
749 const VkImageMemoryBarrier imageBarriers[] =
753 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
754 DE_NULL, // const void* pNext;
755 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
756 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
757 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
758 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
759 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
760 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
761 m_source.get(), // VkImage image;
762 { // VkImageSubresourceRange subresourceRange;
763 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
764 0u, // deUint32 baseMipLevel;
765 1u, // deUint32 mipLevels;
766 0u, // deUint32 baseArraySlice;
767 1u // deUint32 arraySize;
772 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
773 DE_NULL, // const void* pNext;
774 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
775 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
776 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
777 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
778 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
779 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
780 m_destination.get(), // VkImage image;
781 { // VkImageSubresourceRange subresourceRange;
782 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
783 0u, // deUint32 baseMipLevel;
784 1u, // deUint32 mipLevels;
785 0u, // deUint32 baseArraySlice;
786 1u // deUint32 arraySize;
791 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
793 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
794 DE_NULL, // const void* pNext;
795 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
796 (const VkCommandBufferInheritanceInfo*)DE_NULL,
799 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
800 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);
801 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());
802 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
804 const VkSubmitInfo submitInfo =
806 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
807 DE_NULL, // const void* pNext;
808 0u, // deUint32 waitSemaphoreCount;
809 DE_NULL, // const VkSemaphore* pWaitSemaphores;
810 (const VkPipelineStageFlags*)DE_NULL,
811 1u, // deUint32 commandBufferCount;
812 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
813 0u, // deUint32 signalSemaphoreCount;
814 DE_NULL // const VkSemaphore* pSignalSemaphores;
817 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
818 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
819 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
821 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(vk, vkDevice, queue, memAlloc, *m_destination, m_params.dst.image.format, m_params.dst.image.extent);
823 return checkTestResult(resultTextureLevel->getAccess());
826 void CopyImageToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
828 VkOffset3D srcOffset = region.imageCopy.srcOffset;
829 VkOffset3D dstOffset = region.imageCopy.dstOffset;
830 VkExtent3D extent = region.imageCopy.extent;
832 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
834 DE_ASSERT(src.getFormat() == dst.getFormat());
837 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
838 const tcu::PixelBufferAccess dstWithSrcFormat(srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
839 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_DEPTH);
841 tcu::copy(dstSubRegion, srcSubRegion);
845 if (tcu::hasStencilComponent(src.getFormat().order))
847 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
848 const tcu::PixelBufferAccess dstWithSrcFormat(srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
849 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth), tcu::Sampler::MODE_STENCIL);
851 tcu::copy(dstSubRegion, srcSubRegion);
856 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcOffset.z, extent.width, extent.height, extent.depth);
857 // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
858 const tcu::PixelBufferAccess dstWithSrcFormat (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
859 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, dstOffset.z, extent.width, extent.height, extent.depth);
861 tcu::copy(dstSubRegion, srcSubRegion);
865 class CopyImageToImageTestCase : public vkt::TestCase
868 CopyImageToImageTestCase (tcu::TestContext& testCtx,
869 const std::string& name,
870 const std::string& description,
871 const TestParams params)
872 : vkt::TestCase (testCtx, name, description)
876 virtual TestInstance* createInstance (Context& context) const
878 return new CopyImageToImage(context, m_params);
884 // Copy from buffer to buffer.
886 class CopyBufferToBuffer : public CopiesAndBlittingTestInstance
889 CopyBufferToBuffer (Context& context, TestParams params);
890 virtual tcu::TestStatus iterate (void);
892 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess, tcu::PixelBufferAccess, CopyRegion);
893 Move<VkBuffer> m_source;
894 de::MovePtr<Allocation> m_sourceBufferAlloc;
895 Move<VkBuffer> m_destination;
896 de::MovePtr<Allocation> m_destinationBufferAlloc;
899 CopyBufferToBuffer::CopyBufferToBuffer (Context& context, TestParams params)
900 : CopiesAndBlittingTestInstance (context, params)
902 const DeviceInterface& vk = context.getDeviceInterface();
903 const VkDevice vkDevice = context.getDevice();
904 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
905 Allocator& memAlloc = context.getDefaultAllocator();
907 // Create source buffer
909 const VkBufferCreateInfo sourceBufferParams =
911 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
912 DE_NULL, // const void* pNext;
913 0u, // VkBufferCreateFlags flags;
914 m_params.src.buffer.size, // VkDeviceSize size;
915 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
916 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
917 1u, // deUint32 queueFamilyIndexCount;
918 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
921 m_source = createBuffer(vk, vkDevice, &sourceBufferParams);
922 m_sourceBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::HostVisible);
923 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
926 // Create destination buffer
928 const VkBufferCreateInfo destinationBufferParams =
930 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
931 DE_NULL, // const void* pNext;
932 0u, // VkBufferCreateFlags flags;
933 m_params.dst.buffer.size, // VkDeviceSize size;
934 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
935 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
936 1u, // deUint32 queueFamilyIndexCount;
937 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
940 m_destination = createBuffer(vk, vkDevice, &destinationBufferParams);
941 m_destinationBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::HostVisible);
942 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
946 tcu::TestStatus CopyBufferToBuffer::iterate (void)
948 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
949 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), srcLevelWidth, 1));
950 generateBuffer(m_sourceTextureLevel->getAccess(), srcLevelWidth, 1, 1, FILL_MODE_RED);
952 const int dstLevelWidth = (int)(m_params.dst.buffer.size/4);
953 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
954 generateBuffer(m_destinationTextureLevel->getAccess(), dstLevelWidth, 1, 1, FILL_MODE_WHITE);
956 generateExpectedResult();
958 uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
959 uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
961 const DeviceInterface& vk = m_context.getDeviceInterface();
962 const VkDevice vkDevice = m_context.getDevice();
963 const VkQueue queue = m_context.getUniversalQueue();
965 const VkBufferMemoryBarrier srcBufferBarrier =
967 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
968 DE_NULL, // const void* pNext;
969 VK_ACCESS_HOST_WRITE_BIT, // VkAccessFlags srcAccessMask;
970 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
971 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
972 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
973 *m_source, // VkBuffer buffer;
974 0u, // VkDeviceSize offset;
975 m_params.src.buffer.size // VkDeviceSize size;
978 const VkBufferMemoryBarrier dstBufferBarrier =
980 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
981 DE_NULL, // const void* pNext;
982 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
983 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
984 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
985 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
986 *m_destination, // VkBuffer buffer;
987 0u, // VkDeviceSize offset;
988 m_params.dst.buffer.size // VkDeviceSize size;
991 std::vector<VkBufferCopy> bufferCopies;
992 for (deUint32 i = 0; i < m_params.regions.size(); i++)
993 bufferCopies.push_back(m_params.regions[i].bufferCopy);
995 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
997 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
998 DE_NULL, // const void* pNext;
999 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1000 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1003 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1004 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);
1005 vk.cmdCopyBuffer(*m_cmdBuffer, m_source.get(), m_destination.get(), (deUint32)m_params.regions.size(), &bufferCopies[0]);
1006 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);
1007 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1009 const VkSubmitInfo submitInfo =
1011 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1012 DE_NULL, // const void* pNext;
1013 0u, // deUint32 waitSemaphoreCount;
1014 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1015 (const VkPipelineStageFlags*)DE_NULL,
1016 1u, // deUint32 commandBufferCount;
1017 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1018 0u, // deUint32 signalSemaphoreCount;
1019 DE_NULL // const VkSemaphore* pSignalSemaphores;
1022 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1023 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1024 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1027 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(mapVkFormat(VK_FORMAT_R32_UINT), dstLevelWidth, 1));
1028 invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_params.dst.buffer.size);
1029 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1031 return checkTestResult(resultLevel->getAccess());
1034 void CopyBufferToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1036 deMemcpy((deUint8*) dst.getDataPtr() + region.bufferCopy.dstOffset,
1037 (deUint8*) src.getDataPtr() + region.bufferCopy.srcOffset,
1038 (size_t)region.bufferCopy.size);
1041 class BufferToBufferTestCase : public vkt::TestCase
1044 BufferToBufferTestCase (tcu::TestContext& testCtx,
1045 const std::string& name,
1046 const std::string& description,
1047 const TestParams params)
1048 : vkt::TestCase (testCtx, name, description)
1052 virtual TestInstance* createInstance (Context& context) const
1054 return new CopyBufferToBuffer(context, m_params);
1057 TestParams m_params;
1060 // Copy from image to buffer.
1062 class CopyImageToBuffer : public CopiesAndBlittingTestInstance
1065 CopyImageToBuffer (Context& context,
1066 TestParams testParams);
1067 virtual tcu::TestStatus iterate (void);
1069 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1071 tcu::TextureFormat m_textureFormat;
1072 VkDeviceSize m_bufferSize;
1074 Move<VkImage> m_source;
1075 de::MovePtr<Allocation> m_sourceImageAlloc;
1076 Move<VkBuffer> m_destination;
1077 de::MovePtr<Allocation> m_destinationBufferAlloc;
1080 CopyImageToBuffer::CopyImageToBuffer (Context& context, TestParams testParams)
1081 : CopiesAndBlittingTestInstance(context, testParams)
1082 , m_textureFormat(mapVkFormat(testParams.src.image.format))
1083 , m_bufferSize(m_params.dst.buffer.size * tcu::getPixelSize(m_textureFormat))
1085 const DeviceInterface& vk = context.getDeviceInterface();
1086 const VkDevice vkDevice = context.getDevice();
1087 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1088 Allocator& memAlloc = context.getDefaultAllocator();
1090 // Create source image
1092 const VkImageCreateInfo sourceImageParams =
1094 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1095 DE_NULL, // const void* pNext;
1096 0u, // VkImageCreateFlags flags;
1097 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1098 m_params.src.image.format, // VkFormat format;
1099 m_params.src.image.extent, // VkExtent3D extent;
1100 1u, // deUint32 mipLevels;
1101 1u, // deUint32 arraySize;
1102 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1103 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1104 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1105 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1106 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1107 1u, // deUint32 queueFamilyCount;
1108 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1109 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1112 m_source = createImage(vk, vkDevice, &sourceImageParams);
1113 m_sourceImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
1114 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1117 // Create destination buffer
1119 const VkBufferCreateInfo destinationBufferParams =
1121 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1122 DE_NULL, // const void* pNext;
1123 0u, // VkBufferCreateFlags flags;
1124 m_bufferSize, // VkDeviceSize size;
1125 VK_BUFFER_USAGE_TRANSFER_DST_BIT, // VkBufferUsageFlags usage;
1126 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1127 1u, // deUint32 queueFamilyIndexCount;
1128 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1131 m_destination = createBuffer(vk, vkDevice, &destinationBufferParams);
1132 m_destinationBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::HostVisible);
1133 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_destination, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset()));
1137 tcu::TestStatus CopyImageToBuffer::iterate (void)
1139 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1140 m_params.src.image.extent.width,
1141 m_params.src.image.extent.height,
1142 m_params.src.image.extent.depth));
1143 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);
1144 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1145 generateBuffer(m_destinationTextureLevel->getAccess(), (int)m_params.dst.buffer.size, 1, 1);
1147 generateExpectedResult();
1149 uploadImage(m_sourceTextureLevel->getAccess(), *m_source);
1150 uploadBuffer(m_destinationTextureLevel->getAccess(), *m_destinationBufferAlloc);
1152 const DeviceInterface& vk = m_context.getDeviceInterface();
1153 const VkDevice vkDevice = m_context.getDevice();
1154 const VkQueue queue = m_context.getUniversalQueue();
1156 // Barriers for copying image to buffer
1157 const VkImageMemoryBarrier imageBarrier =
1159 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1160 DE_NULL, // const void* pNext;
1161 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1162 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1163 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1164 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
1165 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1166 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1167 *m_source, // VkImage image;
1168 { // VkImageSubresourceRange subresourceRange;
1169 getAspectFlags(m_textureFormat), // VkImageAspectFlags aspectMask;
1170 0u, // deUint32 baseMipLevel;
1171 1u, // deUint32 mipLevels;
1172 0u, // deUint32 baseArraySlice;
1173 1u // deUint32 arraySize;
1177 const VkBufferMemoryBarrier bufferBarrier =
1179 VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER, // VkStructureType sType;
1180 DE_NULL, // const void* pNext;
1181 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1182 VK_ACCESS_HOST_READ_BIT, // VkAccessFlags dstAccessMask;
1183 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1184 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1185 *m_destination, // VkBuffer buffer;
1186 0u, // VkDeviceSize offset;
1187 m_bufferSize // VkDeviceSize size;
1190 // Copy from image to buffer
1191 std::vector<VkBufferImageCopy> bufferImageCopies;
1192 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1193 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1195 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1197 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1198 DE_NULL, // const void* pNext;
1199 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1200 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1203 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1204 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);
1205 vk.cmdCopyImageToBuffer(*m_cmdBuffer, m_source.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, m_destination.get(), (deUint32)m_params.regions.size(), &bufferImageCopies[0]);
1206 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);
1207 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1209 const VkSubmitInfo submitInfo =
1211 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1212 DE_NULL, // const void* pNext;
1213 0u, // deUint32 waitSemaphoreCount;
1214 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1215 (const VkPipelineStageFlags*)DE_NULL,
1216 1u, // deUint32 commandBufferCount;
1217 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1218 0u, // deUint32 signalSemaphoreCount;
1219 DE_NULL // const VkSemaphore* pSignalSemaphores;
1222 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1223 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1224 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1227 de::MovePtr<tcu::TextureLevel> resultLevel (new tcu::TextureLevel(m_textureFormat, (int)m_params.dst.buffer.size, 1));
1228 invalidateMappedMemoryRange(vk, vkDevice, m_destinationBufferAlloc->getMemory(), m_destinationBufferAlloc->getOffset(), m_bufferSize);
1229 tcu::copy(*resultLevel, tcu::ConstPixelBufferAccess(resultLevel->getFormat(), resultLevel->getSize(), m_destinationBufferAlloc->getHostPtr()));
1231 return checkTestResult(resultLevel->getAccess());
1234 class CopyImageToBufferTestCase : public vkt::TestCase
1237 CopyImageToBufferTestCase (tcu::TestContext& testCtx,
1238 const std::string& name,
1239 const std::string& description,
1240 const TestParams params)
1241 : vkt::TestCase (testCtx, name, description)
1245 virtual TestInstance* createInstance (Context& context) const
1247 return new CopyImageToBuffer(context, m_params);
1250 TestParams m_params;
1253 void CopyImageToBuffer::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1255 deUint32 rowLength = region.bufferImageCopy.bufferRowLength;
1257 rowLength = region.bufferImageCopy.imageExtent.width;
1259 deUint32 imageHeight = region.bufferImageCopy.bufferImageHeight;
1261 imageHeight = region.bufferImageCopy.imageExtent.height;
1263 const int texelSize = src.getFormat().getPixelSize();
1264 const VkExtent3D extent = region.bufferImageCopy.imageExtent;
1265 const VkOffset3D srcOffset = region.bufferImageCopy.imageOffset;
1266 const int texelOffset = (int) region.bufferImageCopy.bufferOffset / texelSize;
1268 for (deUint32 z = 0; z < extent.depth; z++)
1270 for (deUint32 y = 0; y < extent.height; y++)
1272 int texelIndex = texelOffset + (z * imageHeight + y) * rowLength;
1273 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y + y, srcOffset.z + z,
1274 region.bufferImageCopy.imageExtent.width, 1, 1);
1275 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1276 tcu::copy(dstSubRegion, srcSubRegion);
1281 // Copy from buffer to image.
1283 class CopyBufferToImage : public CopiesAndBlittingTestInstance
1286 CopyBufferToImage (Context& context,
1287 TestParams testParams);
1288 virtual tcu::TestStatus iterate (void);
1290 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1292 tcu::TextureFormat m_textureFormat;
1293 VkDeviceSize m_bufferSize;
1295 Move<VkBuffer> m_source;
1296 de::MovePtr<Allocation> m_sourceBufferAlloc;
1297 Move<VkImage> m_destination;
1298 de::MovePtr<Allocation> m_destinationImageAlloc;
1301 CopyBufferToImage::CopyBufferToImage (Context& context, TestParams testParams)
1302 : CopiesAndBlittingTestInstance(context, testParams)
1303 , m_textureFormat(mapVkFormat(testParams.dst.image.format))
1304 , m_bufferSize(m_params.src.buffer.size * tcu::getPixelSize(m_textureFormat))
1306 const DeviceInterface& vk = context.getDeviceInterface();
1307 const VkDevice vkDevice = context.getDevice();
1308 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1309 Allocator& memAlloc = context.getDefaultAllocator();
1311 // Create source buffer
1313 const VkBufferCreateInfo sourceBufferParams =
1315 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
1316 DE_NULL, // const void* pNext;
1317 0u, // VkBufferCreateFlags flags;
1318 m_bufferSize, // VkDeviceSize size;
1319 VK_BUFFER_USAGE_TRANSFER_SRC_BIT, // VkBufferUsageFlags usage;
1320 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1321 1u, // deUint32 queueFamilyIndexCount;
1322 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1325 m_source = createBuffer(vk, vkDevice, &sourceBufferParams);
1326 m_sourceBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::HostVisible);
1327 VK_CHECK(vk.bindBufferMemory(vkDevice, *m_source, m_sourceBufferAlloc->getMemory(), m_sourceBufferAlloc->getOffset()));
1330 // Create destination image
1332 const VkImageCreateInfo destinationImageParams =
1334 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1335 DE_NULL, // const void* pNext;
1336 0u, // VkImageCreateFlags flags;
1337 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1338 m_params.dst.image.format, // VkFormat format;
1339 m_params.dst.image.extent, // VkExtent3D extent;
1340 1u, // deUint32 mipLevels;
1341 1u, // deUint32 arraySize;
1342 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1343 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1344 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1345 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1346 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1347 1u, // deUint32 queueFamilyCount;
1348 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1349 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1352 m_destination = createImage(vk, vkDevice, &destinationImageParams);
1353 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
1354 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1358 tcu::TestStatus CopyBufferToImage::iterate (void)
1360 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat, (int)m_params.src.buffer.size, 1));
1361 generateBuffer(m_sourceTextureLevel->getAccess(), (int)m_params.src.buffer.size, 1, 1);
1362 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(m_textureFormat,
1363 m_params.dst.image.extent.width,
1364 m_params.dst.image.extent.height,
1365 m_params.dst.image.extent.depth));
1367 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);
1369 generateExpectedResult();
1371 uploadBuffer(m_sourceTextureLevel->getAccess(), *m_sourceBufferAlloc);
1372 uploadImage(m_destinationTextureLevel->getAccess(), *m_destination);
1374 const DeviceInterface& vk = m_context.getDeviceInterface();
1375 const VkDevice vkDevice = m_context.getDevice();
1376 const VkQueue queue = m_context.getUniversalQueue();
1377 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
1379 const VkImageMemoryBarrier imageBarrier =
1381 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1382 DE_NULL, // const void* pNext;
1383 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1384 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
1385 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1386 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
1387 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1388 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1389 *m_destination, // VkImage image;
1390 { // VkImageSubresourceRange subresourceRange;
1391 getAspectFlags(m_textureFormat), // VkImageAspectFlags aspectMask;
1392 0u, // deUint32 baseMipLevel;
1393 1u, // deUint32 mipLevels;
1394 0u, // deUint32 baseArraySlice;
1395 1u // deUint32 arraySize;
1399 // Copy from buffer to image
1400 std::vector<VkBufferImageCopy> bufferImageCopies;
1401 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1402 bufferImageCopies.push_back(m_params.regions[i].bufferImageCopy);
1404 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1406 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1407 DE_NULL, // const void* pNext;
1408 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1409 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1412 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1413 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);
1414 vk.cmdCopyBufferToImage(*m_cmdBuffer, m_source.get(), m_destination.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (deUint32)m_params.regions.size(), bufferImageCopies.data());
1415 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1417 const VkSubmitInfo submitInfo =
1419 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1420 DE_NULL, // const void* pNext;
1421 0u, // deUint32 waitSemaphoreCount;
1422 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1423 (const VkPipelineStageFlags*)DE_NULL,
1424 1u, // deUint32 commandBufferCount;
1425 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1426 0u, // deUint32 signalSemaphoreCount;
1427 DE_NULL // const VkSemaphore* pSignalSemaphores;
1430 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1431 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1432 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1434 de::MovePtr<tcu::TextureLevel> resultLevel = readImage(vk, vkDevice, queue, memAlloc, *m_destination, m_params.dst.image.format, m_params.dst.image.extent);
1436 return checkTestResult(resultLevel->getAccess());
1439 class CopyBufferToImageTestCase : public vkt::TestCase
1442 CopyBufferToImageTestCase (tcu::TestContext& testCtx,
1443 const std::string& name,
1444 const std::string& description,
1445 const TestParams params)
1446 : vkt::TestCase (testCtx, name, description)
1450 virtual ~CopyBufferToImageTestCase (void) {}
1452 virtual TestInstance* createInstance (Context& context) const
1454 return new CopyBufferToImage(context, m_params);
1457 TestParams m_params;
1460 void CopyBufferToImage::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1462 deUint32 rowLength = region.bufferImageCopy.bufferRowLength;
1464 rowLength = region.bufferImageCopy.imageExtent.width;
1466 deUint32 imageHeight = region.bufferImageCopy.bufferImageHeight;
1468 imageHeight = region.bufferImageCopy.imageExtent.height;
1470 const int texelSize = dst.getFormat().getPixelSize();
1471 const VkExtent3D extent = region.bufferImageCopy.imageExtent;
1472 const VkOffset3D dstOffset = region.bufferImageCopy.imageOffset;
1473 const int texelOffset = (int) region.bufferImageCopy.bufferOffset / texelSize;
1475 for (deUint32 z = 0; z < extent.depth; z++)
1477 for (deUint32 y = 0; y < extent.height; y++)
1479 int texelIndex = texelOffset + (z * imageHeight + y) * rowLength;
1480 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, texelIndex, 0, region.bufferImageCopy.imageExtent.width, 1);
1481 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, dstOffset.x, dstOffset.y + y, dstOffset.z + z,
1482 region.bufferImageCopy.imageExtent.width, 1, 1);
1483 tcu::copy(dstSubRegion, srcSubRegion);
1488 // Copy from image to image with scaling.
1490 class BlittingImages : public CopiesAndBlittingTestInstance
1493 BlittingImages (Context& context,
1495 virtual tcu::TestStatus iterate (void);
1497 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
1498 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
1499 virtual void generateExpectedResult (void);
1501 bool checkClampedAndUnclampedResult (const tcu::ConstPixelBufferAccess&, const tcu::ConstPixelBufferAccess&, const tcu::ConstPixelBufferAccess&);
1502 Move<VkImage> m_source;
1503 de::MovePtr<Allocation> m_sourceImageAlloc;
1504 Move<VkImage> m_destination;
1505 de::MovePtr<Allocation> m_destinationImageAlloc;
1507 de::MovePtr<tcu::TextureLevel> m_unclampedExpectedTextureLevel;
1510 BlittingImages::BlittingImages (Context& context, TestParams params)
1511 : CopiesAndBlittingTestInstance(context, params)
1513 const DeviceInterface& vk = context.getDeviceInterface();
1514 const VkDevice vkDevice = context.getDevice();
1515 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
1516 Allocator& memAlloc = context.getDefaultAllocator();
1518 VkImageFormatProperties properties;
1519 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1520 m_params.src.image.format,
1522 VK_IMAGE_TILING_OPTIMAL,
1523 VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
1525 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
1526 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
1527 m_params.dst.image.format,
1529 VK_IMAGE_TILING_OPTIMAL,
1530 VK_IMAGE_USAGE_TRANSFER_DST_BIT,
1532 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
1534 TCU_THROW(NotSupportedError, "Format not supported");
1537 VkFormatProperties srcFormatProperties;
1538 context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.src.image.format, &srcFormatProperties);
1539 if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT))
1541 TCU_THROW(NotSupportedError, "Format feature blit source not supported");
1544 VkFormatProperties dstFormatProperties;
1545 context.getInstanceInterface().getPhysicalDeviceFormatProperties(context.getPhysicalDevice(), m_params.dst.image.format, &dstFormatProperties);
1546 if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_DST_BIT))
1548 TCU_THROW(NotSupportedError, "Format feature blit destination not supported");
1551 if (m_params.filter == VK_FILTER_LINEAR)
1553 if (!(srcFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1554 TCU_THROW(NotSupportedError, "Source format feature sampled image filter linear not supported");
1555 if (!(dstFormatProperties.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
1556 TCU_THROW(NotSupportedError, "Destination format feature sampled image filter linear not supported");
1559 // Create source image
1561 const VkImageCreateInfo sourceImageParams =
1563 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1564 DE_NULL, // const void* pNext;
1565 0u, // VkImageCreateFlags flags;
1566 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1567 m_params.src.image.format, // VkFormat format;
1568 m_params.src.image.extent, // VkExtent3D extent;
1569 1u, // deUint32 mipLevels;
1570 1u, // deUint32 arraySize;
1571 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1572 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1573 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1574 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1575 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1576 1u, // deUint32 queueFamilyCount;
1577 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1578 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1581 m_source = createImage(vk, vkDevice, &sourceImageParams);
1582 m_sourceImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_source), MemoryRequirement::Any);
1583 VK_CHECK(vk.bindImageMemory(vkDevice, *m_source, m_sourceImageAlloc->getMemory(), m_sourceImageAlloc->getOffset()));
1586 // Create destination image
1588 const VkImageCreateInfo destinationImageParams =
1590 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
1591 DE_NULL, // const void* pNext;
1592 0u, // VkImageCreateFlags flags;
1593 VK_IMAGE_TYPE_2D, // VkImageType imageType;
1594 m_params.dst.image.format, // VkFormat format;
1595 m_params.dst.image.extent, // VkExtent3D extent;
1596 1u, // deUint32 mipLevels;
1597 1u, // deUint32 arraySize;
1598 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
1599 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
1600 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
1601 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
1602 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
1603 1u, // deUint32 queueFamilyCount;
1604 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
1605 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
1608 m_destination = createImage(vk, vkDevice, &destinationImageParams);
1609 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
1610 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
1614 tcu::TestStatus BlittingImages::iterate (void)
1616 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
1617 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
1618 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
1619 m_params.src.image.extent.width,
1620 m_params.src.image.extent.height,
1621 m_params.src.image.extent.depth));
1622 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);
1623 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
1624 (int)m_params.dst.image.extent.width,
1625 (int)m_params.dst.image.extent.height,
1626 (int)m_params.dst.image.extent.depth));
1627 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);
1628 generateExpectedResult();
1630 uploadImage(m_sourceTextureLevel->getAccess(), m_source.get());
1631 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
1633 const DeviceInterface& vk = m_context.getDeviceInterface();
1634 const VkDevice vkDevice = m_context.getDevice();
1635 const VkQueue queue = m_context.getUniversalQueue();
1636 Allocator& memAlloc = m_context.getDefaultAllocator();
1638 std::vector<VkImageBlit> regions;
1639 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1640 regions.push_back(m_params.regions[i].imageBlit);
1642 // Barriers for copying image to buffer
1643 const VkImageMemoryBarrier srcImageBarrier =
1645 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1646 DE_NULL, // const void* pNext;
1647 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1648 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
1649 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1650 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
1651 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1652 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1653 m_source.get(), // VkImage image;
1654 { // VkImageSubresourceRange subresourceRange;
1655 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
1656 0u, // deUint32 baseMipLevel;
1657 1u, // deUint32 mipLevels;
1658 0u, // deUint32 baseArraySlice;
1659 1u // deUint32 arraySize;
1663 const VkImageMemoryBarrier dstImageBarrier =
1665 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
1666 DE_NULL, // const void* pNext;
1667 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
1668 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
1669 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
1670 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
1671 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
1672 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
1673 m_destination.get(), // VkImage image;
1674 { // VkImageSubresourceRange subresourceRange;
1675 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
1676 0u, // deUint32 baseMipLevel;
1677 1u, // deUint32 mipLevels;
1678 0u, // deUint32 baseArraySlice;
1679 1u // deUint32 arraySize;
1683 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
1685 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
1686 DE_NULL, // const void* pNext;
1687 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
1688 (const VkCommandBufferInheritanceInfo*)DE_NULL,
1691 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
1692 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);
1693 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);
1694 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);
1695 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
1697 const VkSubmitInfo submitInfo =
1699 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
1700 DE_NULL, // const void* pNext;
1701 0u, // deUint32 waitSemaphoreCount;
1702 DE_NULL, // const VkSemaphore* pWaitSemaphores;
1703 (const VkPipelineStageFlags*)DE_NULL,
1704 1u, // deUint32 commandBufferCount;
1705 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
1706 0u, // deUint32 signalSemaphoreCount;
1707 DE_NULL // const VkSemaphore* pSignalSemaphores;
1710 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
1711 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
1712 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
1714 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(vk, vkDevice, queue, memAlloc, *m_destination, m_params.dst.image.format, m_params.dst.image.extent);
1716 return checkTestResult(resultTextureLevel->getAccess());
1719 static float calculateFloatConversionError (int srcBits)
1723 const int clampedBits = de::clamp<int>(srcBits, 0, 32);
1724 const float srcMaxValue = de::max((float)(1ULL<<clampedBits) - 1.0f, 1.0f);
1725 const float error = 1.0f / srcMaxValue;
1727 return de::clamp<float>(error, 0.0f, 1.0f);
1733 tcu::Vec4 getFormatThreshold (const tcu::TextureFormat& format)
1735 tcu::Vec4 threshold(0.01f);
1737 switch (format.type)
1739 case tcu::TextureFormat::HALF_FLOAT:
1740 threshold = tcu::Vec4(0.005f);
1743 case tcu::TextureFormat::FLOAT:
1744 case tcu::TextureFormat::FLOAT64:
1745 threshold = tcu::Vec4(0.001f);
1748 case tcu::TextureFormat::UNSIGNED_INT_11F_11F_10F_REV:
1749 threshold = tcu::Vec4(0.02f, 0.02f, 0.0625f, 1.0f);
1752 case tcu::TextureFormat::UNSIGNED_INT_999_E5_REV:
1753 threshold = tcu::Vec4(0.05f, 0.05f, 0.05f, 1.0f);
1757 const tcu::IVec4 bits = tcu::getTextureFormatMantissaBitDepth(format);
1758 threshold = tcu::Vec4(calculateFloatConversionError(bits.x()),
1759 calculateFloatConversionError(bits.y()),
1760 calculateFloatConversionError(bits.z()),
1761 calculateFloatConversionError(bits.w()));
1764 // Return value matching the channel order specified by the format
1765 if (format.order == tcu::TextureFormat::BGR || format.order == tcu::TextureFormat::BGRA)
1766 return threshold.swizzle(2, 1, 0, 3);
1771 bool BlittingImages::checkClampedAndUnclampedResult(const tcu::ConstPixelBufferAccess& result,
1772 const tcu::ConstPixelBufferAccess& clampedExpected,
1773 const tcu::ConstPixelBufferAccess& unclampedExpected)
1775 tcu::TestLog& log (m_context.getTestContext().getLog());
1776 const bool isLinear = m_params.filter == VK_FILTER_LINEAR;
1777 const tcu::TextureFormat srcFormat = m_sourceTextureLevel->getFormat();
1778 const tcu::TextureFormat dstFormat = result.getFormat();
1782 log << tcu::TestLog::Section("ClampedSourceImage", "Region with clamped edges on source image.");
1784 if (isFloatFormat(mapTextureFormat(dstFormat)))
1786 const bool srcIsSRGB = tcu::isSRGB(srcFormat);
1787 const tcu::Vec4 srcMaxDiff = getFormatThreshold(srcFormat) * tcu::Vec4(srcIsSRGB ? 2 : 1);
1788 const tcu::Vec4 dstMaxDiff = getFormatThreshold(dstFormat);
1789 const tcu::Vec4 threshold = tcu::max(srcMaxDiff, dstMaxDiff);
1791 isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1794 log << tcu::TestLog::EndSection;
1796 if (!isOk && isLinear)
1798 log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
1799 isOk = tcu::floatThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1800 log << tcu::TestLog::EndSection;
1805 tcu::UVec4 threshold;
1806 // Calculate threshold depending on channel width of destination format.
1807 const tcu::IVec4 bitDepth = tcu::getTextureFormatBitDepth(dstFormat);
1808 for (deUint32 i = 0; i < 4; ++i)
1809 threshold[i] = de::max( (0x1 << bitDepth[i]) / 256, 1);
1811 isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", clampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1814 log << tcu::TestLog::EndSection;
1816 if (!isOk && isLinear)
1818 log << tcu::TestLog::Section("NonClampedSourceImage", "Region with non-clamped edges on source image.");
1819 isOk = tcu::intThresholdCompare(log, "Compare", "Result comparsion", unclampedExpected, result, threshold, tcu::COMPARE_LOG_RESULT);
1820 log << tcu::TestLog::EndSection;
1826 tcu::TestStatus BlittingImages::checkTestResult (tcu::ConstPixelBufferAccess result)
1828 DE_ASSERT(m_params.filter == VK_FILTER_NEAREST || m_params.filter == VK_FILTER_LINEAR);
1830 if (tcu::isCombinedDepthStencilType(result.getFormat().type))
1832 if (tcu::hasDepthComponent(result.getFormat().order))
1834 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_DEPTH;
1835 const tcu::ConstPixelBufferAccess depthResult = tcu::getEffectiveDepthStencilAccess(result, mode);
1836 const tcu::ConstPixelBufferAccess clampedExpected = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1837 const tcu::ConstPixelBufferAccess unclampedExpected = m_params.filter == VK_FILTER_LINEAR ? tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode) : tcu::ConstPixelBufferAccess();
1839 if (!checkClampedAndUnclampedResult(depthResult, clampedExpected, unclampedExpected))
1841 return tcu::TestStatus::fail("CopiesAndBlitting test");
1845 if (tcu::hasStencilComponent(result.getFormat().order))
1847 const tcu::Sampler::DepthStencilMode mode = tcu::Sampler::MODE_STENCIL;
1848 const tcu::ConstPixelBufferAccess stencilResult = tcu::getEffectiveDepthStencilAccess(result, mode);
1849 const tcu::ConstPixelBufferAccess clampedExpected = tcu::getEffectiveDepthStencilAccess(m_expectedTextureLevel->getAccess(), mode);
1850 const tcu::ConstPixelBufferAccess unclampedExpected = m_params.filter == VK_FILTER_LINEAR ? tcu::getEffectiveDepthStencilAccess(m_unclampedExpectedTextureLevel->getAccess(), mode) : tcu::ConstPixelBufferAccess();
1852 if (!checkClampedAndUnclampedResult(stencilResult, clampedExpected, unclampedExpected))
1854 return tcu::TestStatus::fail("CopiesAndBlitting test");
1860 if (!checkClampedAndUnclampedResult(result, m_expectedTextureLevel->getAccess(), m_params.filter == VK_FILTER_LINEAR ? m_unclampedExpectedTextureLevel->getAccess() : tcu::ConstPixelBufferAccess()))
1862 return tcu::TestStatus::fail("CopiesAndBlitting test");
1866 return tcu::TestStatus::pass("CopiesAndBlitting test");
1869 tcu::Vec4 linearToSRGBIfNeeded (const tcu::TextureFormat& format, const tcu::Vec4& color)
1871 return isSRGB(format) ? linearToSRGB(color) : color;
1874 void scaleFromWholeSrcBuffer (const tcu::PixelBufferAccess& dst, const tcu::ConstPixelBufferAccess& src, const VkOffset3D regionOffset, const VkOffset3D regionExtent, tcu::Sampler::FilterMode filter)
1876 DE_ASSERT(filter == tcu::Sampler::LINEAR);
1877 DE_ASSERT(dst.getDepth() == 1 && src.getDepth() == 1);
1879 tcu::Sampler sampler(tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE, tcu::Sampler::CLAMP_TO_EDGE,
1880 filter, filter, 0.0f, false);
1882 float sX = (float)regionExtent.x / (float)dst.getWidth();
1883 float sY = (float)regionExtent.y / (float)dst.getHeight();
1885 for (int y = 0; y < dst.getHeight(); y++)
1886 for (int x = 0; x < dst.getWidth(); x++)
1887 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);
1890 void BlittingImages::copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
1892 const VkOffset3D srcOffset = region.imageBlit.srcOffsets[0];
1893 const VkOffset3D srcExtent =
1895 region.imageBlit.srcOffsets[1].x - srcOffset.x,
1896 region.imageBlit.srcOffsets[1].y - srcOffset.y,
1897 region.imageBlit.srcOffsets[1].z - srcOffset.z
1899 const VkOffset3D dstOffset = region.imageBlit.dstOffsets[0];
1900 const VkOffset3D dstExtent =
1902 region.imageBlit.dstOffsets[1].x - dstOffset.x,
1903 region.imageBlit.dstOffsets[1].y - dstOffset.y,
1904 region.imageBlit.dstOffsets[1].z - dstOffset.z
1906 const tcu::Sampler::FilterMode filter = (m_params.filter == VK_FILTER_LINEAR) ? tcu::Sampler::LINEAR : tcu::Sampler::NEAREST;
1908 if (tcu::isCombinedDepthStencilType(src.getFormat().type))
1910 DE_ASSERT(src.getFormat() == dst.getFormat());
1912 if (tcu::hasDepthComponent(src.getFormat().order))
1914 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_DEPTH);
1915 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
1916 tcu::scale(dstSubRegion, srcSubRegion, filter);
1918 if (filter == tcu::Sampler::LINEAR)
1920 const tcu::ConstPixelBufferAccess depthSrc = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_DEPTH);
1921 const tcu::PixelBufferAccess unclampedSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_DEPTH);
1922 scaleFromWholeSrcBuffer(unclampedSubRegion, depthSrc, srcOffset, srcExtent, filter);
1927 if (tcu::hasStencilComponent(src.getFormat().order))
1929 const tcu::ConstPixelBufferAccess srcSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y), tcu::Sampler::MODE_STENCIL);
1930 const tcu::PixelBufferAccess dstSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
1931 tcu::scale(dstSubRegion, srcSubRegion, filter);
1933 if (filter == tcu::Sampler::LINEAR)
1935 const tcu::ConstPixelBufferAccess stencilSrc = getEffectiveDepthStencilAccess(src, tcu::Sampler::MODE_STENCIL);
1936 const tcu::PixelBufferAccess unclampedSubRegion = getEffectiveDepthStencilAccess(tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y), tcu::Sampler::MODE_STENCIL);
1937 scaleFromWholeSrcBuffer(unclampedSubRegion, stencilSrc, srcOffset, srcExtent, filter);
1943 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, srcExtent.x, srcExtent.y);
1944 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dst, dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
1945 tcu::scale(dstSubRegion, srcSubRegion, filter);
1947 if (filter == tcu::Sampler::LINEAR)
1949 const tcu::PixelBufferAccess unclampedSubRegion = tcu::getSubregion(m_unclampedExpectedTextureLevel->getAccess(), dstOffset.x, dstOffset.y, dstExtent.x, dstExtent.y);
1950 scaleFromWholeSrcBuffer(unclampedSubRegion, src, srcOffset, srcExtent, filter);
1955 void BlittingImages::generateExpectedResult (void)
1957 const tcu::ConstPixelBufferAccess src = m_sourceTextureLevel->getAccess();
1958 const tcu::ConstPixelBufferAccess dst = m_destinationTextureLevel->getAccess();
1960 m_expectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
1961 tcu::copy(m_expectedTextureLevel->getAccess(), dst);
1963 if (m_params.filter == VK_FILTER_LINEAR)
1965 m_unclampedExpectedTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dst.getFormat(), dst.getWidth(), dst.getHeight(), dst.getDepth()));
1966 tcu::copy(m_unclampedExpectedTextureLevel->getAccess(), dst);
1969 for (deUint32 i = 0; i < m_params.regions.size(); i++)
1970 copyRegionToTextureLevel(src, m_expectedTextureLevel->getAccess(), m_params.regions[i]);
1973 class BlittingTestCase : public vkt::TestCase
1976 BlittingTestCase (tcu::TestContext& testCtx,
1977 const std::string& name,
1978 const std::string& description,
1979 const TestParams params)
1980 : vkt::TestCase (testCtx, name, description)
1984 virtual TestInstance* createInstance (Context& context) const
1986 return new BlittingImages(context, m_params);
1989 TestParams m_params;
1992 // Resolve image to image.
1994 class ResolveImageToImage : public CopiesAndBlittingTestInstance
1997 ResolveImageToImage (Context& context,
1999 virtual tcu::TestStatus iterate (void);
2001 virtual tcu::TestStatus checkTestResult (tcu::ConstPixelBufferAccess result);
2003 Move<VkImage> m_multisampledImage;
2004 de::MovePtr<Allocation> m_multisampledImageAlloc;
2006 Move<VkImage> m_destination;
2007 de::MovePtr<Allocation> m_destinationImageAlloc;
2009 virtual void copyRegionToTextureLevel (tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region);
2012 ResolveImageToImage::ResolveImageToImage (Context& context, TestParams params)
2013 : CopiesAndBlittingTestInstance(context, params)
2015 const VkSampleCountFlagBits rasterizationSamples = m_params.samples;
2017 if (!(context.getDeviceProperties().limits.framebufferColorSampleCounts & rasterizationSamples))
2018 throw tcu::NotSupportedError("Unsupported number of rasterization samples");
2020 const DeviceInterface& vk = context.getDeviceInterface();
2021 const VkDevice vkDevice = context.getDevice();
2022 const deUint32 queueFamilyIndex = context.getUniversalQueueFamilyIndex();
2023 Allocator& memAlloc = m_context.getDefaultAllocator();
2025 const VkComponentMapping componentMappingRGBA = { VK_COMPONENT_SWIZZLE_R, VK_COMPONENT_SWIZZLE_G, VK_COMPONENT_SWIZZLE_B, VK_COMPONENT_SWIZZLE_A };
2027 Move<VkImageView> sourceAttachmentView;
2029 Move<VkRenderPass> renderPass;
2030 Move<VkFramebuffer> framebuffer;
2032 Move<VkShaderModule> vertexShaderModule;
2033 Move<VkShaderModule> fragmentShaderModule;
2035 Move<VkBuffer> vertexBuffer;
2036 std::vector<tcu::Vec4> vertices;
2037 de::MovePtr<Allocation> vertexBufferAlloc;
2039 Move<VkPipelineLayout> pipelineLayout;
2040 Move<VkPipeline> graphicsPipeline;
2042 Move<VkCommandPool> cmdPool;
2043 Move<VkCommandBuffer> cmdBuffer;
2045 Move<VkFence> fence;
2047 VkImageFormatProperties properties;
2048 if ((context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2049 m_params.src.image.format,
2051 VK_IMAGE_TILING_OPTIMAL,
2052 VK_IMAGE_USAGE_TRANSFER_SRC_BIT, 0,
2053 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED) ||
2054 (context.getInstanceInterface().getPhysicalDeviceImageFormatProperties (context.getPhysicalDevice(),
2055 m_params.dst.image.format,
2057 VK_IMAGE_TILING_OPTIMAL,
2058 VK_IMAGE_USAGE_TRANSFER_DST_BIT, 0,
2059 &properties) == VK_ERROR_FORMAT_NOT_SUPPORTED))
2061 TCU_THROW(NotSupportedError, "Format not supported");
2064 // Create color image.
2066 const VkImageCreateInfo colorImageParams =
2068 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
2069 DE_NULL, // const void* pNext;
2070 0u, // VkImageCreateFlags flags;
2071 VK_IMAGE_TYPE_2D, // VkImageType imageType;
2072 m_params.src.image.format, // VkFormat format;
2073 m_params.src.image.extent, // VkExtent3D extent;
2074 1u, // deUint32 mipLevels;
2075 1u, // deUint32 arrayLayers;
2076 rasterizationSamples, // VkSampleCountFlagBits samples;
2077 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2078 VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT, // VkImageUsageFlags usage;
2079 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2080 1u, // deUint32 queueFamilyIndexCount;
2081 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
2082 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
2085 m_multisampledImage = createImage(vk, vkDevice, &colorImageParams);
2087 // Allocate and bind color image memory.
2088 m_multisampledImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_multisampledImage), MemoryRequirement::Any);
2089 VK_CHECK(vk.bindImageMemory(vkDevice, *m_multisampledImage, m_multisampledImageAlloc->getMemory(), m_multisampledImageAlloc->getOffset()));
2092 // Create destination image.
2094 const VkImageCreateInfo destinationImageParams =
2096 VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, // VkStructureType sType;
2097 DE_NULL, // const void* pNext;
2098 0u, // VkImageCreateFlags flags;
2099 VK_IMAGE_TYPE_2D, // VkImageType imageType;
2100 m_params.dst.image.format, // VkFormat format;
2101 m_params.dst.image.extent, // VkExtent3D extent;
2102 1u, // deUint32 mipLevels;
2103 1u, // deUint32 arraySize;
2104 VK_SAMPLE_COUNT_1_BIT, // deUint32 samples;
2105 VK_IMAGE_TILING_OPTIMAL, // VkImageTiling tiling;
2106 VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
2107 VK_IMAGE_USAGE_TRANSFER_DST_BIT, // VkImageUsageFlags usage;
2108 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2109 1u, // deUint32 queueFamilyCount;
2110 &queueFamilyIndex, // const deUint32* pQueueFamilyIndices;
2111 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout initialLayout;
2114 m_destination = createImage(vk, vkDevice, &destinationImageParams);
2115 m_destinationImageAlloc = memAlloc.allocate(getImageMemoryRequirements(vk, vkDevice, *m_destination), MemoryRequirement::Any);
2116 VK_CHECK(vk.bindImageMemory(vkDevice, *m_destination, m_destinationImageAlloc->getMemory(), m_destinationImageAlloc->getOffset()));
2119 // Create color attachment view.
2121 const VkImageViewCreateInfo colorAttachmentViewParams =
2123 VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType;
2124 DE_NULL, // const void* pNext;
2125 0u, // VkImageViewCreateFlags flags;
2126 *m_multisampledImage, // VkImage image;
2127 VK_IMAGE_VIEW_TYPE_2D, // VkImageViewType viewType;
2128 m_params.src.image.format, // VkFormat format;
2129 componentMappingRGBA, // VkComponentMapping components;
2130 { VK_IMAGE_ASPECT_COLOR_BIT, 0u, 1u, 0u, 1u } // VkImageSubresourceRange subresourceRange;
2133 sourceAttachmentView = createImageView(vk, vkDevice, &colorAttachmentViewParams);
2136 // Create render pass.
2138 const VkAttachmentDescription attachmentDescriptions[1] =
2141 0u, // VkAttachmentDescriptionFlags flags;
2142 m_params.src.image.format, // VkFormat format;
2143 rasterizationSamples, // VkSampleCountFlagBits samples;
2144 VK_ATTACHMENT_LOAD_OP_CLEAR, // VkAttachmentLoadOp loadOp;
2145 VK_ATTACHMENT_STORE_OP_STORE, // VkAttachmentStoreOp storeOp;
2146 VK_ATTACHMENT_LOAD_OP_DONT_CARE, // VkAttachmentLoadOp stencilLoadOp;
2147 VK_ATTACHMENT_STORE_OP_DONT_CARE, // VkAttachmentStoreOp stencilStoreOp;
2148 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout initialLayout;
2149 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout finalLayout;
2153 const VkAttachmentReference colorAttachmentReference =
2155 0u, // deUint32 attachment;
2156 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL // VkImageLayout layout;
2159 const VkSubpassDescription subpassDescription =
2161 0u, // VkSubpassDescriptionFlags flags;
2162 VK_PIPELINE_BIND_POINT_GRAPHICS, // VkPipelineBindPoint pipelineBindPoint;
2163 0u, // deUint32 inputAttachmentCount;
2164 DE_NULL, // const VkAttachmentReference* pInputAttachments;
2165 1u, // deUint32 colorAttachmentCount;
2166 &colorAttachmentReference, // const VkAttachmentReference* pColorAttachments;
2167 DE_NULL, // const VkAttachmentReference* pResolveAttachments;
2168 DE_NULL, // const VkAttachmentReference* pDepthStencilAttachment;
2169 0u, // deUint32 preserveAttachmentCount;
2170 DE_NULL // const VkAttachmentReference* pPreserveAttachments;
2173 const VkRenderPassCreateInfo renderPassParams =
2175 VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO, // VkStructureType sType;
2176 DE_NULL, // const void* pNext;
2177 0u, // VkRenderPassCreateFlags flags;
2178 1u, // deUint32 attachmentCount;
2179 attachmentDescriptions, // const VkAttachmentDescription* pAttachments;
2180 1u, // deUint32 subpassCount;
2181 &subpassDescription, // const VkSubpassDescription* pSubpasses;
2182 0u, // deUint32 dependencyCount;
2183 DE_NULL // const VkSubpassDependency* pDependencies;
2186 renderPass = createRenderPass(vk, vkDevice, &renderPassParams);
2189 // Create framebuffer
2191 const VkImageView attachments[1] =
2193 *sourceAttachmentView,
2196 const VkFramebufferCreateInfo framebufferParams =
2198 VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO, // VkStructureType sType;
2199 DE_NULL, // const void* pNext;
2200 0u, // VkFramebufferCreateFlags flags;
2201 *renderPass, // VkRenderPass renderPass;
2202 1u, // deUint32 attachmentCount;
2203 attachments, // const VkImageView* pAttachments;
2204 m_params.src.image.extent.width, // deUint32 width;
2205 m_params.src.image.extent.height, // deUint32 height;
2206 1u // deUint32 layers;
2209 framebuffer = createFramebuffer(vk, vkDevice, &framebufferParams);
2212 // Create pipeline layout
2214 const VkPipelineLayoutCreateInfo pipelineLayoutParams =
2216 VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, // VkStructureType sType;
2217 DE_NULL, // const void* pNext;
2218 0u, // VkPipelineLayoutCreateFlags flags;
2219 0u, // deUint32 setLayoutCount;
2220 DE_NULL, // const VkDescriptorSetLayout* pSetLayouts;
2221 0u, // deUint32 pushConstantRangeCount;
2222 DE_NULL // const VkPushConstantRange* pPushConstantRanges;
2225 pipelineLayout = createPipelineLayout(vk, vkDevice, &pipelineLayoutParams);
2230 vertexShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("vert"), 0);
2231 fragmentShaderModule = createShaderModule(vk, vkDevice, m_context.getBinaryCollection().get("frag"), 0);
2236 const VkPipelineShaderStageCreateInfo shaderStageParams[2] =
2239 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
2240 DE_NULL, // const void* pNext;
2241 0u, // VkPipelineShaderStageCreateFlags flags;
2242 VK_SHADER_STAGE_VERTEX_BIT, // VkShaderStageFlagBits stage;
2243 *vertexShaderModule, // VkShaderModule module;
2244 "main", // const char* pName;
2245 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
2248 VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, // VkStructureType sType;
2249 DE_NULL, // const void* pNext;
2250 0u, // VkPipelineShaderStageCreateFlags flags;
2251 VK_SHADER_STAGE_FRAGMENT_BIT, // VkShaderStageFlagBits stage;
2252 *fragmentShaderModule, // VkShaderModule module;
2253 "main", // const char* pName;
2254 DE_NULL // const VkSpecializationInfo* pSpecializationInfo;
2258 const VkVertexInputBindingDescription vertexInputBindingDescription =
2260 0u, // deUint32 binding;
2261 sizeof(tcu::Vec4), // deUint32 stride;
2262 VK_VERTEX_INPUT_RATE_VERTEX // VkVertexInputRate inputRate;
2265 const VkVertexInputAttributeDescription vertexInputAttributeDescriptions[1] =
2268 0u, // deUint32 location;
2269 0u, // deUint32 binding;
2270 VK_FORMAT_R32G32B32A32_SFLOAT, // VkFormat format;
2271 0u // deUint32 offset;
2275 const VkPipelineVertexInputStateCreateInfo vertexInputStateParams =
2277 VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, // VkStructureType sType;
2278 DE_NULL, // const void* pNext;
2279 0u, // VkPipelineVertexInputStateCreateFlags flags;
2280 1u, // deUint32 vertexBindingDescriptionCount;
2281 &vertexInputBindingDescription, // const VkVertexInputBindingDescription* pVertexBindingDescriptions;
2282 1u, // deUint32 vertexAttributeDescriptionCount;
2283 vertexInputAttributeDescriptions // const VkVertexInputAttributeDescription* pVertexAttributeDescriptions;
2286 const VkPipelineInputAssemblyStateCreateInfo inputAssemblyStateParams =
2288 VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, // VkStructureType sType;
2289 DE_NULL, // const void* pNext;
2290 0u, // VkPipelineInputAssemblyStateCreateFlags flags;
2291 VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, // VkPrimitiveTopology topology;
2292 false // VkBool32 primitiveRestartEnable;
2295 const VkViewport viewport =
2299 (float)m_params.src.image.extent.width, // float width;
2300 (float)m_params.src.image.extent.height, // float height;
2301 0.0f, // float minDepth;
2302 1.0f // float maxDepth;
2305 const VkRect2D scissor =
2307 { 0, 0 }, // VkOffset2D offset;
2308 { m_params.src.image.extent.width, m_params.src.image.extent.height } // VkExtent2D extent;
2311 const VkPipelineViewportStateCreateInfo viewportStateParams =
2313 VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, // VkStructureType sType;
2314 DE_NULL, // const void* pNext;
2315 0u, // VkPipelineViewportStateCreateFlags flags;
2316 1u, // deUint32 viewportCount;
2317 &viewport, // const VkViewport* pViewports;
2318 1u, // deUint32 scissorCount;
2319 &scissor // const VkRect2D* pScissors;
2322 const VkPipelineRasterizationStateCreateInfo rasterStateParams =
2324 VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, // VkStructureType sType;
2325 DE_NULL, // const void* pNext;
2326 0u, // VkPipelineRasterizationStateCreateFlags flags;
2327 false, // VkBool32 depthClampEnable;
2328 false, // VkBool32 rasterizerDiscardEnable;
2329 VK_POLYGON_MODE_FILL, // VkPolygonMode polygonMode;
2330 VK_CULL_MODE_NONE, // VkCullModeFlags cullMode;
2331 VK_FRONT_FACE_COUNTER_CLOCKWISE, // VkFrontFace frontFace;
2332 VK_FALSE, // VkBool32 depthBiasEnable;
2333 0.0f, // float depthBiasConstantFactor;
2334 0.0f, // float depthBiasClamp;
2335 0.0f, // float depthBiasSlopeFactor;
2336 1.0f // float lineWidth;
2339 const VkPipelineMultisampleStateCreateInfo multisampleStateParams =
2341 VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, // VkStructureType sType;
2342 DE_NULL, // const void* pNext;
2343 0u, // VkPipelineMultisampleStateCreateFlags flags;
2344 rasterizationSamples, // VkSampleCountFlagBits rasterizationSamples;
2345 VK_FALSE, // VkBool32 sampleShadingEnable;
2346 0.0f, // float minSampleShading;
2347 DE_NULL, // const VkSampleMask* pSampleMask;
2348 VK_FALSE, // VkBool32 alphaToCoverageEnable;
2349 VK_FALSE // VkBool32 alphaToOneEnable;
2352 const VkPipelineColorBlendAttachmentState colorBlendAttachmentState =
2354 false, // VkBool32 blendEnable;
2355 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendColor;
2356 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendColor;
2357 VK_BLEND_OP_ADD, // VkBlendOp blendOpColor;
2358 VK_BLEND_FACTOR_ONE, // VkBlend srcBlendAlpha;
2359 VK_BLEND_FACTOR_ZERO, // VkBlend destBlendAlpha;
2360 VK_BLEND_OP_ADD, // VkBlendOp blendOpAlpha;
2361 (VK_COLOR_COMPONENT_R_BIT |
2362 VK_COLOR_COMPONENT_G_BIT |
2363 VK_COLOR_COMPONENT_B_BIT |
2364 VK_COLOR_COMPONENT_A_BIT) // VkChannelFlags channelWriteMask;
2367 const VkPipelineColorBlendStateCreateInfo colorBlendStateParams =
2369 VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, // VkStructureType sType;
2370 DE_NULL, // const void* pNext;
2371 0u, // VkPipelineColorBlendStateCreateFlags flags;
2372 false, // VkBool32 logicOpEnable;
2373 VK_LOGIC_OP_COPY, // VkLogicOp logicOp;
2374 1u, // deUint32 attachmentCount;
2375 &colorBlendAttachmentState, // const VkPipelineColorBlendAttachmentState* pAttachments;
2376 { 0.0f, 0.0f, 0.0f, 0.0f } // float blendConstants[4];
2379 const VkGraphicsPipelineCreateInfo graphicsPipelineParams =
2381 VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, // VkStructureType sType;
2382 DE_NULL, // const void* pNext;
2383 0u, // VkPipelineCreateFlags flags;
2384 2u, // deUint32 stageCount;
2385 shaderStageParams, // const VkPipelineShaderStageCreateInfo* pStages;
2386 &vertexInputStateParams, // const VkPipelineVertexInputStateCreateInfo* pVertexInputState;
2387 &inputAssemblyStateParams, // const VkPipelineInputAssemblyStateCreateInfo* pInputAssemblyState;
2388 DE_NULL, // const VkPipelineTessellationStateCreateInfo* pTessellationState;
2389 &viewportStateParams, // const VkPipelineViewportStateCreateInfo* pViewportState;
2390 &rasterStateParams, // const VkPipelineRasterizationStateCreateInfo* pRasterizationState;
2391 &multisampleStateParams, // const VkPipelineMultisampleStateCreateInfo* pMultisampleState;
2392 DE_NULL, // const VkPipelineDepthStencilStateCreateInfo* pDepthStencilState;
2393 &colorBlendStateParams, // const VkPipelineColorBlendStateCreateInfo* pColorBlendState;
2394 DE_NULL, // const VkPipelineDynamicStateCreateInfo* pDynamicState;
2395 *pipelineLayout, // VkPipelineLayout layout;
2396 *renderPass, // VkRenderPass renderPass;
2397 0u, // deUint32 subpass;
2398 0u, // VkPipeline basePipelineHandle;
2399 0u // deInt32 basePipelineIndex;
2402 graphicsPipeline = createGraphicsPipeline(vk, vkDevice, DE_NULL, &graphicsPipelineParams);
2405 // Create vertex buffer.
2407 // Create upper half triangle.
2409 const tcu::Vec4 a (-1.0, -1.0, 0.0, 1.0);
2410 const tcu::Vec4 b (1.0, -1.0, 0.0, 1.0);
2411 const tcu::Vec4 c (1.0, 1.0, 0.0, 1.0);
2414 vertices.push_back(a);
2415 vertices.push_back(c);
2416 vertices.push_back(b);
2419 const VkDeviceSize vertexDataSize = vertices.size() * sizeof(tcu::Vec4);
2420 const VkBufferCreateInfo vertexBufferParams =
2422 VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, // VkStructureType sType;
2423 DE_NULL, // const void* pNext;
2424 0u, // VkBufferCreateFlags flags;
2425 vertexDataSize, // VkDeviceSize size;
2426 VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, // VkBufferUsageFlags usage;
2427 VK_SHARING_MODE_EXCLUSIVE, // VkSharingMode sharingMode;
2428 1u, // deUint32 queueFamilyIndexCount;
2429 &queueFamilyIndex // const deUint32* pQueueFamilyIndices;
2432 vertexBuffer = createBuffer(vk, vkDevice, &vertexBufferParams);
2433 vertexBufferAlloc = memAlloc.allocate(getBufferMemoryRequirements(vk, vkDevice, *vertexBuffer), MemoryRequirement::HostVisible);
2435 VK_CHECK(vk.bindBufferMemory(vkDevice, *vertexBuffer, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset()));
2437 // Load vertices into vertex buffer.
2438 deMemcpy(vertexBufferAlloc->getHostPtr(), vertices.data(), (size_t)vertexDataSize);
2439 flushMappedMemoryRange(vk, vkDevice, vertexBufferAlloc->getMemory(), vertexBufferAlloc->getOffset(), vertexDataSize);
2442 // Create command pool
2444 const VkCommandPoolCreateInfo cmdPoolParams =
2446 VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, // VkStructureType sType;
2447 DE_NULL, // const void* pNext;
2448 VK_COMMAND_POOL_CREATE_TRANSIENT_BIT, // VkCommandPoolCreateFlags flags;
2449 queueFamilyIndex, // deUint32 queueFamilyIndex;
2452 cmdPool = createCommandPool(vk, vkDevice, &cmdPoolParams);
2455 // Create command buffer
2457 const VkCommandBufferAllocateInfo cmdBufferAllocateInfo =
2459 VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, // VkStructureType sType;
2460 DE_NULL, // const void* pNext;
2461 *cmdPool, // VkCommandPool commandPool;
2462 VK_COMMAND_BUFFER_LEVEL_PRIMARY, // VkCommandBufferLevel level;
2463 1u // deUint32 bufferCount;
2466 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
2468 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
2469 DE_NULL, // const void* pNext;
2470 0u, // VkCommandBufferUsageFlags flags;
2471 (const VkCommandBufferInheritanceInfo*)DE_NULL,
2474 const VkClearValue clearValue = makeClearValueColorF32(0.0f, 0.0f, 1.0f, 1.0f);
2476 const VkClearValue clearValues[1] =
2481 const VkRenderPassBeginInfo renderPassBeginInfo =
2483 VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO, // VkStructureType sType;
2484 DE_NULL, // const void* pNext;
2485 *renderPass, // VkRenderPass renderPass;
2486 *framebuffer, // VkFramebuffer framebuffer;
2489 { m_params.src.image.extent.width, m_params.src.image.extent.height }
2490 }, // VkRect2D renderArea;
2491 1u, // deUint32 clearValueCount;
2492 clearValues // const VkClearValue* pClearValues;
2495 // Barriers for copying image to buffer
2496 const VkImageMemoryBarrier srcImageBarrier =
2498 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2499 DE_NULL, // const void* pNext;
2500 0u, // VkAccessFlags srcAccessMask;
2501 VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, // VkAccessFlags dstAccessMask;
2502 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2503 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout newLayout;
2504 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2505 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2506 m_multisampledImage.get(), // VkImage image;
2507 { // VkImageSubresourceRange subresourceRange;
2508 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
2509 0u, // deUint32 baseMipLevel;
2510 1u, // deUint32 mipLevels;
2511 0u, // deUint32 baseArraySlice;
2512 1u // deUint32 arraySize;
2516 cmdBuffer = allocateCommandBuffer(vk, vkDevice, &cmdBufferAllocateInfo);
2518 VK_CHECK(vk.beginCommandBuffer(*cmdBuffer, &cmdBufferBeginInfo));
2519 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);
2520 vk.cmdBeginRenderPass(*cmdBuffer, &renderPassBeginInfo, VK_SUBPASS_CONTENTS_INLINE);
2522 const VkDeviceSize vertexBufferOffset = 0u;
2524 vk.cmdBindPipeline(*cmdBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, *graphicsPipeline);
2525 vk.cmdBindVertexBuffers(*cmdBuffer, 0, 1, &vertexBuffer.get(), &vertexBufferOffset);
2526 vk.cmdDraw(*cmdBuffer, (deUint32)vertices.size(), 1, 0, 0);
2528 vk.cmdEndRenderPass(*cmdBuffer);
2530 VK_CHECK(vk.endCommandBuffer(*cmdBuffer));
2535 const VkFenceCreateInfo fenceParams =
2537 VK_STRUCTURE_TYPE_FENCE_CREATE_INFO, // VkStructureType sType;
2538 DE_NULL, // const void* pNext;
2539 0u // VkFenceCreateFlags flags;
2542 fence = createFence(vk, vkDevice, &fenceParams);
2547 const VkQueue queue = m_context.getUniversalQueue();
2548 const VkSubmitInfo submitInfo =
2550 VK_STRUCTURE_TYPE_SUBMIT_INFO,
2553 (const VkSemaphore*)DE_NULL,
2554 (const VkPipelineStageFlags*)DE_NULL,
2558 (const VkSemaphore*)DE_NULL,
2561 VK_CHECK(vk.resetFences(vkDevice, 1, &fence.get()));
2562 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *fence));
2563 VK_CHECK(vk.waitForFences(vkDevice, 1, &fence.get(), true, ~(0ull) /* infinity */));
2567 tcu::TestStatus ResolveImageToImage::iterate (void)
2569 const tcu::TextureFormat srcTcuFormat = mapVkFormat(m_params.src.image.format);
2570 const tcu::TextureFormat dstTcuFormat = mapVkFormat(m_params.dst.image.format);
2572 m_sourceTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(srcTcuFormat,
2573 m_params.src.image.extent.width,
2574 m_params.src.image.extent.height,
2575 m_params.src.image.extent.depth));
2576 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);
2577 m_destinationTextureLevel = de::MovePtr<tcu::TextureLevel>(new tcu::TextureLevel(dstTcuFormat,
2578 (int)m_params.dst.image.extent.width,
2579 (int)m_params.dst.image.extent.height,
2580 (int)m_params.dst.image.extent.depth));
2581 generateBuffer(m_destinationTextureLevel->getAccess(), m_params.dst.image.extent.width, m_params.dst.image.extent.height, m_params.dst.image.extent.depth);
2582 generateExpectedResult();
2584 uploadImage(m_destinationTextureLevel->getAccess(), m_destination.get());
2586 const DeviceInterface& vk = m_context.getDeviceInterface();
2587 const VkDevice vkDevice = m_context.getDevice();
2588 const VkQueue queue = m_context.getUniversalQueue();
2589 SimpleAllocator memAlloc (vk, vkDevice, getPhysicalDeviceMemoryProperties(m_context.getInstanceInterface(), m_context.getPhysicalDevice()));
2591 std::vector<VkImageResolve> imageResolves;
2592 for (deUint32 i = 0; i < m_params.regions.size(); i++)
2593 imageResolves.push_back(m_params.regions[i].imageResolve);
2595 const VkImageMemoryBarrier imageBarriers[] =
2599 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2600 DE_NULL, // const void* pNext;
2601 0u, // VkAccessFlags srcAccessMask;
2602 VK_ACCESS_TRANSFER_READ_BIT, // VkAccessFlags dstAccessMask;
2603 VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, // VkImageLayout oldLayout;
2604 VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // VkImageLayout newLayout;
2605 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2606 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2607 m_multisampledImage.get(), // VkImage image;
2608 { // VkImageSubresourceRange subresourceRange;
2609 getAspectFlags(srcTcuFormat), // VkImageAspectFlags aspectMask;
2610 0u, // deUint32 baseMipLevel;
2611 1u, // deUint32 mipLevels;
2612 0u, // deUint32 baseArraySlice;
2613 1u // deUint32 arraySize;
2616 // destination image
2618 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2619 DE_NULL, // const void* pNext;
2620 0u, // VkAccessFlags srcAccessMask;
2621 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
2622 VK_IMAGE_LAYOUT_UNDEFINED, // VkImageLayout oldLayout;
2623 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
2624 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2625 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2626 m_destination.get(), // VkImage image;
2627 { // VkImageSubresourceRange subresourceRange;
2628 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
2629 0u, // deUint32 baseMipLevel;
2630 1u, // deUint32 mipLevels;
2631 0u, // deUint32 baseArraySlice;
2632 1u // deUint32 arraySize;
2637 const VkImageMemoryBarrier postImageBarrier =
2639 VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, // VkStructureType sType;
2640 DE_NULL, // const void* pNext;
2641 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags srcAccessMask;
2642 VK_ACCESS_TRANSFER_WRITE_BIT, // VkAccessFlags dstAccessMask;
2643 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout oldLayout;
2644 VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, // VkImageLayout newLayout;
2645 VK_QUEUE_FAMILY_IGNORED, // deUint32 srcQueueFamilyIndex;
2646 VK_QUEUE_FAMILY_IGNORED, // deUint32 dstQueueFamilyIndex;
2647 m_destination.get(), // VkImage image;
2648 { // VkImageSubresourceRange subresourceRange;
2649 getAspectFlags(dstTcuFormat), // VkImageAspectFlags aspectMask;
2650 0u, // deUint32 baseMipLevel;
2651 1u, // deUint32 mipLevels;
2652 0u, // deUint32 baseArraySlice;
2653 1u // deUint32 arraySize;
2657 const VkCommandBufferBeginInfo cmdBufferBeginInfo =
2659 VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, // VkStructureType sType;
2660 DE_NULL, // const void* pNext;
2661 VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, // VkCommandBufferUsageFlags flags;
2662 (const VkCommandBufferInheritanceInfo*)DE_NULL,
2665 VK_CHECK(vk.beginCommandBuffer(*m_cmdBuffer, &cmdBufferBeginInfo));
2666 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);
2667 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());
2668 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);
2669 VK_CHECK(vk.endCommandBuffer(*m_cmdBuffer));
2671 const VkSubmitInfo submitInfo =
2673 VK_STRUCTURE_TYPE_SUBMIT_INFO, // VkStructureType sType;
2674 DE_NULL, // const void* pNext;
2675 0u, // deUint32 waitSemaphoreCount;
2676 DE_NULL, // const VkSemaphore* pWaitSemaphores;
2677 (const VkPipelineStageFlags*)DE_NULL,
2678 1u, // deUint32 commandBufferCount;
2679 &m_cmdBuffer.get(), // const VkCommandBuffer* pCommandBuffers;
2680 0u, // deUint32 signalSemaphoreCount;
2681 DE_NULL // const VkSemaphore* pSignalSemaphores;
2684 VK_CHECK(vk.resetFences(vkDevice, 1, &m_fence.get()));
2685 VK_CHECK(vk.queueSubmit(queue, 1, &submitInfo, *m_fence));
2686 VK_CHECK(vk.waitForFences(vkDevice, 1, &m_fence.get(), true, ~(0ull) /* infinity */));
2688 de::MovePtr<tcu::TextureLevel> resultTextureLevel = readImage(vk, vkDevice, queue, memAlloc, *m_destination, m_params.dst.image.format, m_params.dst.image.extent);
2690 return checkTestResult(resultTextureLevel->getAccess());
2693 tcu::TestStatus ResolveImageToImage::checkTestResult (tcu::ConstPixelBufferAccess result)
2695 const tcu::ConstPixelBufferAccess expected = m_expectedTextureLevel->getAccess();
2696 const float fuzzyThreshold = 0.01f;
2698 if (!tcu::fuzzyCompare(m_context.getTestContext().getLog(), "Compare", "Result comparsion", expected, result, fuzzyThreshold, tcu::COMPARE_LOG_RESULT))
2699 return tcu::TestStatus::fail("CopiesAndBlitting test");
2701 return tcu::TestStatus::pass("CopiesAndBlitting test");
2704 void ResolveImageToImage::copyRegionToTextureLevel(tcu::ConstPixelBufferAccess src, tcu::PixelBufferAccess dst, CopyRegion region)
2706 VkOffset3D srcOffset = region.imageCopy.srcOffset;
2707 VkOffset3D dstOffset = region.imageCopy.dstOffset;
2708 VkExtent3D extent = region.imageCopy.extent;
2710 const tcu::ConstPixelBufferAccess srcSubRegion = tcu::getSubregion(src, srcOffset.x, srcOffset.y, extent.width, extent.height);
2711 // CopyImage acts like a memcpy. Replace the destination format with the srcformat to use a memcpy.
2712 const tcu::PixelBufferAccess dstWithSrcFormat (srcSubRegion.getFormat(), dst.getSize(), dst.getDataPtr());
2713 const tcu::PixelBufferAccess dstSubRegion = tcu::getSubregion(dstWithSrcFormat, dstOffset.x, dstOffset.y, extent.width, extent.height);
2715 tcu::copy(dstSubRegion, srcSubRegion);
2718 class ResolveImageToImageTestCase : public vkt::TestCase
2721 ResolveImageToImageTestCase (tcu::TestContext& testCtx,
2722 const std::string& name,
2723 const std::string& description,
2724 const TestParams params)
2725 : vkt::TestCase (testCtx, name, description)
2728 virtual void initPrograms (SourceCollections& programCollection) const;
2730 virtual TestInstance* createInstance (Context& context) const
2732 return new ResolveImageToImage(context, m_params);
2735 TestParams m_params;
2738 void ResolveImageToImageTestCase::initPrograms (SourceCollections& programCollection) const
2740 programCollection.glslSources.add("vert") << glu::VertexSource(
2742 "layout (location = 0) in highp vec4 a_position;\n"
2745 " gl_Position = a_position;\n"
2749 programCollection.glslSources.add("frag") << glu::FragmentSource(
2751 "layout (location = 0) out highp vec4 o_color;\n"
2754 " o_color = vec4(0.0, 1.0, 0.0, 1.0);\n"
2758 std::string getSampleCountCaseName (VkSampleCountFlagBits sampleFlag)
2760 return de::toLower(de::toString(getSampleCountFlagsStr(sampleFlag)).substr(16));
2763 std::string getFormatCaseName (VkFormat format)
2765 return de::toLower(de::toString(getFormatStr(format)).substr(10));
2768 void addCopyImageTestsAllFormats (tcu::TestCaseGroup* testCaseGroup,
2769 tcu::TestContext& testCtx,
2772 const VkFormat compatibleFormats8Bit[] =
2774 VK_FORMAT_R4G4_UNORM_PACK8,
2777 VK_FORMAT_R8_USCALED,
2778 VK_FORMAT_R8_SSCALED,
2785 const VkFormat compatibleFormats16Bit[] =
2787 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
2788 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
2789 VK_FORMAT_R5G6B5_UNORM_PACK16,
2790 VK_FORMAT_B5G6R5_UNORM_PACK16,
2791 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
2792 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
2793 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
2794 VK_FORMAT_R8G8_UNORM,
2795 VK_FORMAT_R8G8_SNORM,
2796 VK_FORMAT_R8G8_USCALED,
2797 VK_FORMAT_R8G8_SSCALED,
2798 VK_FORMAT_R8G8_UINT,
2799 VK_FORMAT_R8G8_SINT,
2800 VK_FORMAT_R8G8_SRGB,
2801 VK_FORMAT_R16_UNORM,
2802 VK_FORMAT_R16_SNORM,
2803 VK_FORMAT_R16_USCALED,
2804 VK_FORMAT_R16_SSCALED,
2807 VK_FORMAT_R16_SFLOAT,
2811 const VkFormat compatibleFormats24Bit[] =
2813 VK_FORMAT_R8G8B8_UNORM,
2814 VK_FORMAT_R8G8B8_SNORM,
2815 VK_FORMAT_R8G8B8_USCALED,
2816 VK_FORMAT_R8G8B8_SSCALED,
2817 VK_FORMAT_R8G8B8_UINT,
2818 VK_FORMAT_R8G8B8_SINT,
2819 VK_FORMAT_R8G8B8_SRGB,
2820 VK_FORMAT_B8G8R8_UNORM,
2821 VK_FORMAT_B8G8R8_SNORM,
2822 VK_FORMAT_B8G8R8_USCALED,
2823 VK_FORMAT_B8G8R8_SSCALED,
2824 VK_FORMAT_B8G8R8_UINT,
2825 VK_FORMAT_B8G8R8_SINT,
2826 VK_FORMAT_B8G8R8_SRGB,
2830 const VkFormat compatibleFormats32Bit[] =
2832 VK_FORMAT_R8G8B8A8_UNORM,
2833 VK_FORMAT_R8G8B8A8_SNORM,
2834 VK_FORMAT_R8G8B8A8_USCALED,
2835 VK_FORMAT_R8G8B8A8_SSCALED,
2836 VK_FORMAT_R8G8B8A8_UINT,
2837 VK_FORMAT_R8G8B8A8_SINT,
2838 VK_FORMAT_R8G8B8A8_SRGB,
2839 VK_FORMAT_B8G8R8A8_UNORM,
2840 VK_FORMAT_B8G8R8A8_SNORM,
2841 VK_FORMAT_B8G8R8A8_USCALED,
2842 VK_FORMAT_B8G8R8A8_SSCALED,
2843 VK_FORMAT_B8G8R8A8_UINT,
2844 VK_FORMAT_B8G8R8A8_SINT,
2845 VK_FORMAT_B8G8R8A8_SRGB,
2846 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
2847 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
2848 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
2849 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
2850 VK_FORMAT_A8B8G8R8_UINT_PACK32,
2851 VK_FORMAT_A8B8G8R8_SINT_PACK32,
2852 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
2853 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
2854 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
2855 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
2856 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
2857 VK_FORMAT_A2R10G10B10_UINT_PACK32,
2858 VK_FORMAT_A2R10G10B10_SINT_PACK32,
2859 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
2860 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
2861 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
2862 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
2863 VK_FORMAT_A2B10G10R10_UINT_PACK32,
2864 VK_FORMAT_A2B10G10R10_SINT_PACK32,
2865 VK_FORMAT_R16G16_UNORM,
2866 VK_FORMAT_R16G16_SNORM,
2867 VK_FORMAT_R16G16_USCALED,
2868 VK_FORMAT_R16G16_SSCALED,
2869 VK_FORMAT_R16G16_UINT,
2870 VK_FORMAT_R16G16_SINT,
2871 VK_FORMAT_R16G16_SFLOAT,
2874 VK_FORMAT_R32_SFLOAT,
2878 const VkFormat compatibleFormats48Bit[] =
2880 VK_FORMAT_R16G16B16_UNORM,
2881 VK_FORMAT_R16G16B16_SNORM,
2882 VK_FORMAT_R16G16B16_USCALED,
2883 VK_FORMAT_R16G16B16_SSCALED,
2884 VK_FORMAT_R16G16B16_UINT,
2885 VK_FORMAT_R16G16B16_SINT,
2886 VK_FORMAT_R16G16B16_SFLOAT,
2890 const VkFormat compatibleFormats64Bit[] =
2892 VK_FORMAT_R16G16B16A16_UNORM,
2893 VK_FORMAT_R16G16B16A16_SNORM,
2894 VK_FORMAT_R16G16B16A16_USCALED,
2895 VK_FORMAT_R16G16B16A16_SSCALED,
2896 VK_FORMAT_R16G16B16A16_UINT,
2897 VK_FORMAT_R16G16B16A16_SINT,
2898 VK_FORMAT_R16G16B16A16_SFLOAT,
2899 VK_FORMAT_R32G32_UINT,
2900 VK_FORMAT_R32G32_SINT,
2901 VK_FORMAT_R32G32_SFLOAT,
2904 VK_FORMAT_R64_SFLOAT,
2908 const VkFormat compatibleFormats96Bit[] =
2910 VK_FORMAT_R32G32B32_UINT,
2911 VK_FORMAT_R32G32B32_SINT,
2912 VK_FORMAT_R32G32B32_SFLOAT,
2916 const VkFormat compatibleFormats128Bit[] =
2918 VK_FORMAT_R32G32B32A32_UINT,
2919 VK_FORMAT_R32G32B32A32_SINT,
2920 VK_FORMAT_R32G32B32A32_SFLOAT,
2921 VK_FORMAT_R64G64_UINT,
2922 VK_FORMAT_R64G64_SINT,
2923 VK_FORMAT_R64G64_SFLOAT,
2927 const VkFormat compatibleFormats192Bit[] =
2929 VK_FORMAT_R64G64B64_UINT,
2930 VK_FORMAT_R64G64B64_SINT,
2931 VK_FORMAT_R64G64B64_SFLOAT,
2935 const VkFormat compatibleFormats256Bit[] =
2937 VK_FORMAT_R64G64B64A64_UINT,
2938 VK_FORMAT_R64G64B64A64_SINT,
2939 VK_FORMAT_R64G64B64A64_SFLOAT,
2944 const VkFormat* colorImageFormatsToTest[] =
2946 compatibleFormats8Bit,
2947 compatibleFormats16Bit,
2948 compatibleFormats24Bit,
2949 compatibleFormats32Bit,
2950 compatibleFormats48Bit,
2951 compatibleFormats64Bit,
2952 compatibleFormats96Bit,
2953 compatibleFormats128Bit,
2954 compatibleFormats192Bit,
2955 compatibleFormats256Bit,
2957 const size_t numOfColorImageFormatsToTest = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
2959 for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
2961 const VkFormat* compatibleFormats = colorImageFormatsToTest[compatibleFormatsIndex];
2962 for (size_t srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_LAST; ++srcFormatIndex)
2964 params.src.image.format = compatibleFormats[srcFormatIndex];
2965 for (size_t dstFormatIndex = 0; compatibleFormats[dstFormatIndex] != VK_FORMAT_LAST; ++dstFormatIndex)
2967 params.dst.image.format = compatibleFormats[dstFormatIndex];
2968 std::ostringstream testName;
2969 testName << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
2970 std::ostringstream description;
2971 description << "Copy from src " << params.src.image.format << " to dst " << params.dst.image.format;
2973 testCaseGroup->addChild(new CopyImageToImageTestCase(testCtx, testName.str(), description.str(), params));
2979 void addBlittingTestsAllFormats (tcu::TestCaseGroup* testCaseGroup,
2980 tcu::TestContext& testCtx,
2983 // Test Image formats.
2984 const VkFormat compatibleFormatsUInts[] =
2987 VK_FORMAT_R8G8_UINT,
2988 VK_FORMAT_R8G8B8_UINT,
2989 VK_FORMAT_B8G8R8_UINT,
2990 VK_FORMAT_R8G8B8A8_UINT,
2991 VK_FORMAT_B8G8R8A8_UINT,
2992 VK_FORMAT_A8B8G8R8_UINT_PACK32,
2993 VK_FORMAT_A2R10G10B10_UINT_PACK32,
2994 VK_FORMAT_A2B10G10R10_UINT_PACK32,
2996 VK_FORMAT_R16G16_UINT,
2997 VK_FORMAT_R16G16B16_UINT,
2998 VK_FORMAT_R16G16B16A16_UINT,
3000 VK_FORMAT_R32G32_UINT,
3001 VK_FORMAT_R32G32B32_UINT,
3002 VK_FORMAT_R32G32B32A32_UINT,
3004 VK_FORMAT_R64G64_UINT,
3005 VK_FORMAT_R64G64B64_UINT,
3006 VK_FORMAT_R64G64B64A64_UINT,
3010 const VkFormat compatibleFormatsSInts[] =
3013 VK_FORMAT_R8G8_SINT,
3014 VK_FORMAT_R8G8B8_SINT,
3015 VK_FORMAT_B8G8R8_SINT,
3016 VK_FORMAT_R8G8B8A8_SINT,
3017 VK_FORMAT_B8G8R8A8_SINT,
3018 VK_FORMAT_A8B8G8R8_SINT_PACK32,
3019 VK_FORMAT_A2R10G10B10_SINT_PACK32,
3020 VK_FORMAT_A2B10G10R10_SINT_PACK32,
3022 VK_FORMAT_R16G16_SINT,
3023 VK_FORMAT_R16G16B16_SINT,
3024 VK_FORMAT_R16G16B16A16_SINT,
3026 VK_FORMAT_R32G32_SINT,
3027 VK_FORMAT_R32G32B32_SINT,
3028 VK_FORMAT_R32G32B32A32_SINT,
3030 VK_FORMAT_R64G64_SINT,
3031 VK_FORMAT_R64G64B64_SINT,
3032 VK_FORMAT_R64G64B64A64_SINT,
3036 const VkFormat compatibleFormatsFloats[] =
3038 VK_FORMAT_R4G4_UNORM_PACK8,
3039 VK_FORMAT_R4G4B4A4_UNORM_PACK16,
3040 VK_FORMAT_B4G4R4A4_UNORM_PACK16,
3041 VK_FORMAT_R5G6B5_UNORM_PACK16,
3042 VK_FORMAT_B5G6R5_UNORM_PACK16,
3043 VK_FORMAT_R5G5B5A1_UNORM_PACK16,
3044 VK_FORMAT_B5G5R5A1_UNORM_PACK16,
3045 VK_FORMAT_A1R5G5B5_UNORM_PACK16,
3048 VK_FORMAT_R8_USCALED,
3049 VK_FORMAT_R8_SSCALED,
3050 VK_FORMAT_R8G8_UNORM,
3051 VK_FORMAT_R8G8_SNORM,
3052 VK_FORMAT_R8G8_USCALED,
3053 VK_FORMAT_R8G8_SSCALED,
3054 VK_FORMAT_R8G8B8_UNORM,
3055 VK_FORMAT_R8G8B8_SNORM,
3056 VK_FORMAT_R8G8B8_USCALED,
3057 VK_FORMAT_R8G8B8_SSCALED,
3058 VK_FORMAT_B8G8R8_UNORM,
3059 VK_FORMAT_B8G8R8_SNORM,
3060 VK_FORMAT_B8G8R8_USCALED,
3061 VK_FORMAT_B8G8R8_SSCALED,
3062 VK_FORMAT_R8G8B8A8_UNORM,
3063 VK_FORMAT_R8G8B8A8_SNORM,
3064 VK_FORMAT_R8G8B8A8_USCALED,
3065 VK_FORMAT_R8G8B8A8_SSCALED,
3066 VK_FORMAT_B8G8R8A8_UNORM,
3067 VK_FORMAT_B8G8R8A8_SNORM,
3068 VK_FORMAT_B8G8R8A8_USCALED,
3069 VK_FORMAT_B8G8R8A8_SSCALED,
3070 VK_FORMAT_A8B8G8R8_UNORM_PACK32,
3071 VK_FORMAT_A8B8G8R8_SNORM_PACK32,
3072 VK_FORMAT_A8B8G8R8_USCALED_PACK32,
3073 VK_FORMAT_A8B8G8R8_SSCALED_PACK32,
3074 VK_FORMAT_A2R10G10B10_UNORM_PACK32,
3075 VK_FORMAT_A2R10G10B10_SNORM_PACK32,
3076 VK_FORMAT_A2R10G10B10_USCALED_PACK32,
3077 VK_FORMAT_A2R10G10B10_SSCALED_PACK32,
3078 VK_FORMAT_A2B10G10R10_UNORM_PACK32,
3079 VK_FORMAT_A2B10G10R10_SNORM_PACK32,
3080 VK_FORMAT_A2B10G10R10_USCALED_PACK32,
3081 VK_FORMAT_A2B10G10R10_SSCALED_PACK32,
3082 VK_FORMAT_R16_UNORM,
3083 VK_FORMAT_R16_SNORM,
3084 VK_FORMAT_R16_USCALED,
3085 VK_FORMAT_R16_SSCALED,
3086 VK_FORMAT_R16_SFLOAT,
3087 VK_FORMAT_R16G16_UNORM,
3088 VK_FORMAT_R16G16_SNORM,
3089 VK_FORMAT_R16G16_USCALED,
3090 VK_FORMAT_R16G16_SSCALED,
3091 VK_FORMAT_R16G16_SFLOAT,
3092 VK_FORMAT_R16G16B16_UNORM,
3093 VK_FORMAT_R16G16B16_SNORM,
3094 VK_FORMAT_R16G16B16_USCALED,
3095 VK_FORMAT_R16G16B16_SSCALED,
3096 VK_FORMAT_R16G16B16_SFLOAT,
3097 VK_FORMAT_R16G16B16A16_UNORM,
3098 VK_FORMAT_R16G16B16A16_SNORM,
3099 VK_FORMAT_R16G16B16A16_USCALED,
3100 VK_FORMAT_R16G16B16A16_SSCALED,
3101 VK_FORMAT_R16G16B16A16_SFLOAT,
3102 VK_FORMAT_R32_SFLOAT,
3103 VK_FORMAT_R32G32_SFLOAT,
3104 VK_FORMAT_R32G32B32_SFLOAT,
3105 VK_FORMAT_R32G32B32A32_SFLOAT,
3106 VK_FORMAT_R64_SFLOAT,
3107 VK_FORMAT_R64G64_SFLOAT,
3108 VK_FORMAT_R64G64B64_SFLOAT,
3109 VK_FORMAT_R64G64B64A64_SFLOAT,
3110 // VK_FORMAT_B10G11R11_UFLOAT_PACK32,
3111 // VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
3112 // VK_FORMAT_BC1_RGB_UNORM_BLOCK,
3113 // VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
3114 // VK_FORMAT_BC2_UNORM_BLOCK,
3115 // VK_FORMAT_BC3_UNORM_BLOCK,
3116 // VK_FORMAT_BC4_UNORM_BLOCK,
3117 // VK_FORMAT_BC4_SNORM_BLOCK,
3118 // VK_FORMAT_BC5_UNORM_BLOCK,
3119 // VK_FORMAT_BC5_SNORM_BLOCK,
3120 // VK_FORMAT_BC6H_UFLOAT_BLOCK,
3121 // VK_FORMAT_BC6H_SFLOAT_BLOCK,
3122 // VK_FORMAT_BC7_UNORM_BLOCK,
3123 // VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK,
3124 // VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK,
3125 // VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK,
3126 // VK_FORMAT_EAC_R11_UNORM_BLOCK,
3127 // VK_FORMAT_EAC_R11_SNORM_BLOCK,
3128 // VK_FORMAT_EAC_R11G11_UNORM_BLOCK,
3129 // VK_FORMAT_EAC_R11G11_SNORM_BLOCK,
3130 // VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
3131 // VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
3132 // VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
3133 // VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
3134 // VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
3135 // VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
3136 // VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
3137 // VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
3138 // VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
3139 // VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
3140 // VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
3141 // VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
3142 // VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
3143 // VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
3147 const VkFormat compatibleFormatsSrgb[] =
3150 VK_FORMAT_R8G8_SRGB,
3151 VK_FORMAT_R8G8B8_SRGB,
3152 VK_FORMAT_B8G8R8_SRGB,
3153 VK_FORMAT_R8G8B8A8_SRGB,
3154 VK_FORMAT_B8G8R8A8_SRGB,
3155 VK_FORMAT_A8B8G8R8_SRGB_PACK32,
3156 // VK_FORMAT_BC1_RGB_SRGB_BLOCK,
3157 // VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
3158 // VK_FORMAT_BC2_SRGB_BLOCK,
3159 // VK_FORMAT_BC3_SRGB_BLOCK,
3160 // VK_FORMAT_BC7_SRGB_BLOCK,
3161 // VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK,
3162 // VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK,
3163 // VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK,
3164 // VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
3165 // VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
3166 // VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
3167 // VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
3168 // VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
3169 // VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
3170 // VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
3171 // VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
3172 // VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
3173 // VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
3174 // VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
3175 // VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
3176 // VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
3177 // VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
3183 const VkFormat* compatibleFormats;
3184 const bool onlyNearest;
3185 } colorImageFormatsToTest[] =
3187 { compatibleFormatsUInts, true },
3188 { compatibleFormatsSInts, true },
3189 { compatibleFormatsFloats, false },
3190 { compatibleFormatsSrgb, false },
3192 const size_t numOfColorImageFormatsToTest = DE_LENGTH_OF_ARRAY(colorImageFormatsToTest);
3194 for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < numOfColorImageFormatsToTest; ++compatibleFormatsIndex)
3196 const VkFormat* compatibleFormats = colorImageFormatsToTest[compatibleFormatsIndex].compatibleFormats;
3197 const bool onlyNearest = colorImageFormatsToTest[compatibleFormatsIndex].onlyNearest;
3198 for (size_t srcFormatIndex = 0; compatibleFormats[srcFormatIndex] != VK_FORMAT_LAST; ++srcFormatIndex)
3200 params.src.image.format = compatibleFormats[srcFormatIndex];
3201 for (size_t dstFormatIndex = 0; compatibleFormats[dstFormatIndex] != VK_FORMAT_LAST; ++dstFormatIndex)
3203 params.dst.image.format = compatibleFormats[dstFormatIndex];
3204 std::ostringstream testName;
3205 testName << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
3206 std::ostringstream description;
3207 description << "Blit image from src " << params.src.image.format << " to dst " << params.dst.image.format;
3209 params.filter = VK_FILTER_NEAREST;
3210 testCaseGroup->addChild(new BlittingTestCase(testCtx, testName.str() + "_nearest", description.str(), params));
3214 params.filter = VK_FILTER_LINEAR;
3215 testCaseGroup->addChild(new BlittingTestCase(testCtx, testName.str() + "_linear", description.str(), params));
3224 tcu::TestCaseGroup* createCopiesAndBlittingTests (tcu::TestContext& testCtx)
3226 de::MovePtr<tcu::TestCaseGroup> copiesAndBlittingTests (new tcu::TestCaseGroup(testCtx, "copy_and_blit", "Copies And Blitting Tests"));
3228 de::MovePtr<tcu::TestCaseGroup> imageToImageTests (new tcu::TestCaseGroup(testCtx, "image_to_image", "Copy from image to image"));
3229 de::MovePtr<tcu::TestCaseGroup> imgToImgSimpleTests (new tcu::TestCaseGroup(testCtx, "simple_tests", "Copy from image to image simple tests"));
3230 de::MovePtr<tcu::TestCaseGroup> imgToImgAllFormatsTests (new tcu::TestCaseGroup(testCtx, "all_formats", "Copy from image to image with all compatible formats"));
3232 de::MovePtr<tcu::TestCaseGroup> imageToBufferTests (new tcu::TestCaseGroup(testCtx, "image_to_buffer", "Copy from image to buffer"));
3233 de::MovePtr<tcu::TestCaseGroup> bufferToImageTests (new tcu::TestCaseGroup(testCtx, "buffer_to_image", "Copy from buffer to image"));
3234 de::MovePtr<tcu::TestCaseGroup> bufferToBufferTests (new tcu::TestCaseGroup(testCtx, "buffer_to_buffer", "Copy from buffer to buffer"));
3236 de::MovePtr<tcu::TestCaseGroup> blittingImageTests (new tcu::TestCaseGroup(testCtx, "blit_image", "Blitting image"));
3237 de::MovePtr<tcu::TestCaseGroup> blitImgSimpleTests (new tcu::TestCaseGroup(testCtx, "simple_tests", "Blitting image simple tests"));
3238 de::MovePtr<tcu::TestCaseGroup> blitImgAllFormatsTests (new tcu::TestCaseGroup(testCtx, "all_formats", "Blitting image with all compatible formats"));
3240 de::MovePtr<tcu::TestCaseGroup> resolveImageTests (new tcu::TestCaseGroup(testCtx, "resolve_image", "Resolve image"));
3242 const deInt32 defaultSize = 64;
3243 const deInt32 defaultHalfSize = defaultSize / 2;
3244 const deInt32 defaultFourthSize = defaultSize / 4;
3245 const VkExtent3D defaultExtent = {defaultSize, defaultSize, 1};
3246 const VkExtent3D defaultHalfExtent = {defaultHalfSize, defaultHalfSize, 1};
3248 const VkImageSubresourceLayers defaultSourceLayer =
3250 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
3251 0u, // uint32_t mipLevel;
3252 0u, // uint32_t baseArrayLayer;
3253 1u, // uint32_t layerCount;
3256 // Copy image to image testcases.
3259 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3260 params.src.image.extent = defaultExtent;
3261 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3262 params.dst.image.extent = defaultExtent;
3265 const VkImageCopy testCopy =
3267 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3268 {0, 0, 0}, // VkOffset3D srcOffset;
3269 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3270 {0, 0, 0}, // VkOffset3D dstOffset;
3271 defaultExtent, // VkExtent3D extent;
3274 CopyRegion imageCopy;
3275 imageCopy.imageCopy = testCopy;
3277 params.regions.push_back(imageCopy);
3280 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "whole_image", "Whole image", params));
3285 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3286 params.src.image.extent = defaultExtent;
3287 params.dst.image.format = VK_FORMAT_R32_UINT;
3288 params.dst.image.extent = defaultExtent;
3291 const VkImageCopy testCopy =
3293 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3294 {0, 0, 0}, // VkOffset3D srcOffset;
3295 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3296 {0, 0, 0}, // VkOffset3D dstOffset;
3297 defaultExtent, // VkExtent3D extent;
3300 CopyRegion imageCopy;
3301 imageCopy.imageCopy = testCopy;
3303 params.regions.push_back(imageCopy);
3306 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "whole_image_diff_fromat", "Whole image with different format", params));
3311 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3312 params.src.image.extent = defaultExtent;
3313 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3314 params.dst.image.extent = defaultExtent;
3317 const VkImageCopy testCopy =
3319 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3320 {0, 0, 0}, // VkOffset3D srcOffset;
3321 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3322 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3323 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3326 CopyRegion imageCopy;
3327 imageCopy.imageCopy = testCopy;
3329 params.regions.push_back(imageCopy);
3332 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "partial_image", "Partial image", params));
3337 params.src.image.format = VK_FORMAT_D32_SFLOAT;
3338 params.src.image.extent = defaultExtent;
3339 params.dst.image.format = VK_FORMAT_D32_SFLOAT;
3340 params.dst.image.extent = defaultExtent;
3343 const VkImageSubresourceLayers sourceLayer =
3345 VK_IMAGE_ASPECT_DEPTH_BIT, // VkImageAspectFlags aspectMask;
3346 0u, // uint32_t mipLevel;
3347 0u, // uint32_t baseArrayLayer;
3348 1u // uint32_t layerCount;
3350 const VkImageCopy testCopy =
3352 sourceLayer, // VkImageSubresourceLayers srcSubresource;
3353 {0, 0, 0}, // VkOffset3D srcOffset;
3354 sourceLayer, // VkImageSubresourceLayers dstSubresource;
3355 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3356 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3359 CopyRegion imageCopy;
3360 imageCopy.imageCopy = testCopy;
3362 params.regions.push_back(imageCopy);
3365 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "depth", "With depth", params));
3370 params.src.image.format = VK_FORMAT_S8_UINT;
3371 params.src.image.extent = defaultExtent;
3372 params.dst.image.format = VK_FORMAT_S8_UINT;
3373 params.dst.image.extent = defaultExtent;
3376 const VkImageSubresourceLayers sourceLayer =
3378 VK_IMAGE_ASPECT_STENCIL_BIT, // VkImageAspectFlags aspectMask;
3379 0u, // uint32_t mipLevel;
3380 0u, // uint32_t baseArrayLayer;
3381 1u // uint32_t layerCount;
3383 const VkImageCopy testCopy =
3385 sourceLayer, // VkImageSubresourceLayers srcSubresource;
3386 {0, 0, 0}, // VkOffset3D srcOffset;
3387 sourceLayer, // VkImageSubresourceLayers dstSubresource;
3388 {defaultFourthSize, defaultFourthSize / 2, 0}, // VkOffset3D dstOffset;
3389 {defaultFourthSize / 2, defaultFourthSize / 2, 1}, // VkExtent3D extent;
3392 CopyRegion imageCopy;
3393 imageCopy.imageCopy = testCopy;
3395 params.regions.push_back(imageCopy);
3398 imgToImgSimpleTests->addChild(new CopyImageToImageTestCase(testCtx, "stencil", "With stencil", params));
3403 params.src.image.extent = defaultExtent;
3404 params.dst.image.extent = defaultExtent;
3406 for (deInt32 i = 0; i < defaultSize; i += defaultFourthSize)
3408 const VkImageCopy testCopy =
3410 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3411 {0, 0, 0}, // VkOffset3D srcOffset;
3412 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3413 {i, defaultSize - i - defaultFourthSize, 0}, // VkOffset3D dstOffset;
3414 {defaultFourthSize, defaultFourthSize, 1}, // VkExtent3D extent;
3417 CopyRegion imageCopy;
3418 imageCopy.imageCopy = testCopy;
3420 params.regions.push_back(imageCopy);
3423 addCopyImageTestsAllFormats(imgToImgAllFormatsTests.get(), testCtx, params);
3425 imageToImageTests->addChild(imgToImgSimpleTests.release());
3426 imageToImageTests->addChild(imgToImgAllFormatsTests.release());
3428 // Copy image to buffer testcases.
3431 params.src.image.format = VK_FORMAT_R8G8B8A8_UINT;
3432 params.src.image.extent = defaultExtent;
3433 params.dst.buffer.size = defaultSize * defaultSize;
3435 const VkBufferImageCopy bufferImageCopy =
3437 0u, // VkDeviceSize bufferOffset;
3438 0u, // uint32_t bufferRowLength;
3439 0u, // uint32_t bufferImageHeight;
3440 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
3441 {0, 0, 0}, // VkOffset3D imageOffset;
3442 {defaultFourthSize, defaultFourthSize, 1} // VkExtent3D imageExtent;
3444 CopyRegion copyRegion;
3445 copyRegion.bufferImageCopy = bufferImageCopy;
3447 params.regions.push_back(copyRegion);
3449 imageToBufferTests->addChild(new CopyImageToBufferTestCase(testCtx, "whole", "Copy from image to buffer", params));
3452 // Copy buffer to image testcases.
3455 params.src.buffer.size = defaultSize * defaultSize;
3456 params.dst.image.format = VK_FORMAT_R8G8B8A8_UINT;
3457 params.dst.image.extent = defaultExtent;
3459 const VkBufferImageCopy bufferImageCopy =
3461 0u, // VkDeviceSize bufferOffset;
3462 0u, // uint32_t bufferRowLength;
3463 0u, // uint32_t bufferImageHeight;
3464 defaultSourceLayer, // VkImageSubresourceLayers imageSubresource;
3465 {0, 0, 0}, // VkOffset3D imageOffset;
3466 {defaultFourthSize, defaultFourthSize, 1} // VkExtent3D imageExtent;
3468 CopyRegion copyRegion;
3469 copyRegion.bufferImageCopy = bufferImageCopy;
3471 params.regions.push_back(copyRegion);
3473 bufferToImageTests->addChild(new CopyBufferToImageTestCase(testCtx, "whole", "Copy from buffer to image", params));
3476 // Copy buffer to buffer testcases.
3479 params.src.buffer.size = defaultSize;
3480 params.dst.buffer.size = defaultSize;
3482 const VkBufferCopy bufferCopy =
3484 0u, // VkDeviceSize srcOffset;
3485 0u, // VkDeviceSize dstOffset;
3486 defaultSize, // VkDeviceSize size;
3489 CopyRegion copyRegion;
3490 copyRegion.bufferCopy = bufferCopy;
3491 params.regions.push_back(copyRegion);
3493 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "whole", "Whole buffer", params));
3498 params.src.buffer.size = defaultFourthSize;
3499 params.dst.buffer.size = defaultFourthSize;
3501 const VkBufferCopy bufferCopy =
3503 12u, // VkDeviceSize srcOffset;
3504 4u, // VkDeviceSize dstOffset;
3505 1u, // VkDeviceSize size;
3508 CopyRegion copyRegion;
3509 copyRegion.bufferCopy = bufferCopy;
3510 params.regions.push_back(copyRegion);
3512 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "partial", "Partial", params));
3516 const deUint32 size = 16;
3518 params.src.buffer.size = size;
3519 params.dst.buffer.size = size * (size + 1);
3521 // Copy region with size 1..size
3522 for (unsigned int i = 1; i <= size; i++)
3524 const VkBufferCopy bufferCopy =
3526 0, // VkDeviceSize srcOffset;
3527 i * size, // VkDeviceSize dstOffset;
3528 i, // VkDeviceSize size;
3531 CopyRegion copyRegion;
3532 copyRegion.bufferCopy = bufferCopy;
3533 params.regions.push_back(copyRegion);
3536 bufferToBufferTests->addChild(new BufferToBufferTestCase(testCtx, "regions", "Multiple regions", params));
3539 // Blitting testcases.
3541 const std::string description ("Blit without scaling (whole)");
3542 const std::string testName ("whole");
3545 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3546 params.src.image.extent = defaultExtent;
3547 params.dst.image.extent = defaultExtent;
3550 const VkImageBlit imageBlit =
3552 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3555 {defaultSize, defaultSize, 1}
3556 }, // VkOffset3D srcOffsets[2];
3558 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3561 {defaultSize, defaultSize, 1}
3562 } // VkOffset3D dstOffset[2];
3566 region.imageBlit = imageBlit;
3567 params.regions.push_back(region);
3570 // Filter is VK_FILTER_NEAREST.
3572 params.filter = VK_FILTER_NEAREST;
3574 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3575 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3577 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3578 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3579 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3581 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3582 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3583 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3586 // Filter is VK_FILTER_LINEAR.
3588 params.filter = VK_FILTER_LINEAR;
3590 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3591 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3593 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3594 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3595 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3597 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3598 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3599 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3604 const std::string description ("Blit with scaling (whole, src extent bigger)");
3605 const std::string testName ("scaling_whole1");
3608 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3609 params.src.image.extent = defaultExtent;
3610 params.dst.image.extent = defaultHalfExtent;
3613 const VkImageBlit imageBlit =
3615 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3618 {defaultSize, defaultSize, 1}
3619 }, // VkOffset3D srcOffsets[2];
3621 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3624 {defaultHalfSize, defaultHalfSize, 1}
3625 } // VkOffset3D dstOffset[2];
3629 region.imageBlit = imageBlit;
3630 params.regions.push_back(region);
3633 // Filter is VK_FILTER_NEAREST.
3635 params.filter = VK_FILTER_NEAREST;
3637 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3638 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3640 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3641 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3642 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3644 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3645 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3646 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3649 // Filter is VK_FILTER_LINEAR.
3651 params.filter = VK_FILTER_LINEAR;
3653 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3654 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3656 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3657 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3658 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3660 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3661 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3662 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3667 const std::string description ("Blit with scaling (whole, dst extent bigger)");
3668 const std::string testName ("scaling_whole2");
3671 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3672 params.src.image.extent = defaultHalfExtent;
3673 params.dst.image.extent = defaultExtent;
3676 const VkImageBlit imageBlit =
3678 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3681 {defaultHalfSize, defaultHalfSize, 1}
3682 }, // VkOffset3D srcOffsets[2];
3684 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3687 {defaultSize, defaultSize, 1}
3688 } // VkOffset3D dstOffset[2];
3692 region.imageBlit = imageBlit;
3693 params.regions.push_back(region);
3696 // Filter is VK_FILTER_NEAREST.
3698 params.filter = VK_FILTER_NEAREST;
3700 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3701 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3703 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3704 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3705 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3707 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3708 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3709 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3712 // Filter is VK_FILTER_LINEAR.
3714 params.filter = VK_FILTER_LINEAR;
3716 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3717 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3719 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3720 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3721 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3723 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3724 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3725 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3730 const std::string description ("Blit with scaling and offset (whole, dst extent bigger)");
3731 const std::string testName ("scaling_and_offset");
3734 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3735 params.src.image.extent = defaultExtent;
3736 params.dst.image.extent = defaultExtent;
3739 const VkImageBlit imageBlit =
3741 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3743 {defaultHalfSize, defaultHalfSize, 0},
3744 {defaultHalfSize + 1, defaultHalfSize + 1, 1}
3745 }, // VkOffset3D srcOffsets[2];
3747 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3750 {defaultSize, defaultSize, 1}
3751 } // VkOffset3D dstOffset[2];
3755 region.imageBlit = imageBlit;
3756 params.regions.push_back(region);
3759 // Filter is VK_FILTER_NEAREST.
3761 params.filter = VK_FILTER_NEAREST;
3763 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3764 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3767 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3768 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3769 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3771 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3772 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3773 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3776 // Filter is VK_FILTER_LINEAR.
3778 params.filter = VK_FILTER_LINEAR;
3780 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3781 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3783 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3784 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3785 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3787 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3788 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3789 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3794 const std::string description ("Blit without scaling (partial)");
3795 const std::string testName ("without_scaling_partial");
3798 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3799 params.src.image.extent = defaultExtent;
3800 params.dst.image.extent = defaultExtent;
3804 for (int i = 0; i < defaultSize; i += defaultFourthSize)
3806 const VkImageBlit imageBlit =
3808 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3810 {defaultSize - defaultFourthSize - i, defaultSize - defaultFourthSize - i, 0},
3811 {defaultSize - i, defaultSize - i, 1}
3812 }, // VkOffset3D srcOffsets[2];
3814 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3817 {i + defaultFourthSize, i + defaultFourthSize, 1}
3818 } // VkOffset3D dstOffset[2];
3820 region.imageBlit = imageBlit;
3821 params.regions.push_back(region);
3825 // Filter is VK_FILTER_NEAREST.
3827 params.filter = VK_FILTER_NEAREST;
3829 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3830 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_nearest", description, params));
3833 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3834 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)");
3835 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToR32, params));
3837 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3838 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)");
3839 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_nearest", descriptionOfRGBAToBGRA, params));
3842 // Filter is VK_FILTER_LINEAR.
3844 params.filter = VK_FILTER_LINEAR;
3846 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
3847 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + "_linear", description + " (VK_FILTER_LINEAR)", params));
3849 params.dst.image.format = VK_FORMAT_R32_SFLOAT;
3850 const std::string descriptionOfRGBAToR32 (description + " and different formats (R8G8B8A8 -> R32)" + " (VK_FILTER_LINEAR)");
3851 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToR32, params));
3853 params.dst.image.format = VK_FORMAT_B8G8R8A8_UNORM;
3854 const std::string descriptionOfRGBAToBGRA (description + " and different formats (R8G8B8A8 -> B8G8R8A8)" + " (VK_FILTER_LINEAR)");
3855 blitImgSimpleTests->addChild(new BlittingTestCase(testCtx, testName + getFormatCaseName(params.dst.image.format) + "_linear", descriptionOfRGBAToBGRA, params));
3860 const std::string description ("Blit with scaling (partial)");
3861 const std::string testName ("scaling_partial");
3863 // Test Color formats.
3866 params.src.image.extent = defaultExtent;
3867 params.dst.image.extent = defaultExtent;
3870 for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
3872 const VkImageBlit imageBlit =
3874 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3877 {defaultSize, defaultSize, 1}
3878 }, // VkOffset3D srcOffsets[2];
3880 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3883 {i + defaultFourthSize / j, defaultFourthSize / j, 1}
3884 } // VkOffset3D dstOffset[2];
3886 region.imageBlit = imageBlit;
3887 params.regions.push_back(region);
3889 for (int i = 0; i < defaultSize; i += defaultFourthSize)
3891 const VkImageBlit imageBlit =
3893 defaultSourceLayer, // VkImageSubresourceLayers srcSubresource;
3896 {i + defaultFourthSize, i + defaultFourthSize, 1}
3897 }, // VkOffset3D srcOffsets[2];
3899 defaultSourceLayer, // VkImageSubresourceLayers dstSubresource;
3901 {i, defaultSize / 2, 0},
3902 {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1}
3903 } // VkOffset3D dstOffset[2];
3905 region.imageBlit = imageBlit;
3906 params.regions.push_back(region);
3909 addBlittingTestsAllFormats(blitImgAllFormatsTests.get(), testCtx, params);
3912 // Test Depth and Stencil formats.
3914 const VkFormat compatibleDepthAndStencilFormats[] =
3916 VK_FORMAT_D16_UNORM,
3917 VK_FORMAT_X8_D24_UNORM_PACK32,
3918 VK_FORMAT_D32_SFLOAT,
3920 VK_FORMAT_D16_UNORM_S8_UINT,
3921 VK_FORMAT_D24_UNORM_S8_UINT,
3922 VK_FORMAT_D32_SFLOAT_S8_UINT,
3925 for (size_t compatibleFormatsIndex = 0; compatibleFormatsIndex < DE_LENGTH_OF_ARRAY(compatibleDepthAndStencilFormats); ++compatibleFormatsIndex)
3929 params.src.image.extent = defaultExtent;
3930 params.dst.image.extent = defaultExtent;
3931 params.src.image.format = compatibleDepthAndStencilFormats[compatibleFormatsIndex];
3932 params.dst.image.format = params.src.image.format;
3933 std::ostringstream oss;
3934 oss << testName << "_" << getFormatCaseName(params.src.image.format) << "_" << getFormatCaseName(params.dst.image.format);
3936 const VkImageSubresourceLayers defaultDepthSourceLayer = { VK_IMAGE_ASPECT_DEPTH_BIT, 0u, 0u, 1u };
3937 const VkImageSubresourceLayers defaultStencilSourceLayer = { VK_IMAGE_ASPECT_STENCIL_BIT, 0u, 0u, 1u };
3940 for (int i = 0, j = 1; (i + defaultFourthSize / j < defaultSize) && (defaultFourthSize > j); i += defaultFourthSize / j++)
3942 const VkOffset3D srcOffset0 = {0, 0, 0};
3943 const VkOffset3D srcOffset1 = {defaultSize, defaultSize, 1};
3944 const VkOffset3D dstOffset0 = {i, 0, 0};
3945 const VkOffset3D dstOffset1 = {i + defaultFourthSize / j, defaultFourthSize / j, 1};
3947 if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
3949 const VkImageBlit imageBlit =
3951 defaultDepthSourceLayer, // VkImageSubresourceLayers srcSubresource;
3952 { srcOffset0 , srcOffset1 }, // VkOffset3D srcOffsets[2];
3953 defaultDepthSourceLayer, // VkImageSubresourceLayers dstSubresource;
3954 { dstOffset0 , dstOffset1 }, // VkOffset3D dstOffset[2];
3956 region.imageBlit = imageBlit;
3957 params.regions.push_back(region);
3959 if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
3961 const VkImageBlit imageBlit =
3963 defaultStencilSourceLayer, // VkImageSubresourceLayers srcSubresource;
3964 { srcOffset0 , srcOffset1 }, // VkOffset3D srcOffsets[2];
3965 defaultStencilSourceLayer, // VkImageSubresourceLayers dstSubresource;
3966 { dstOffset0 , dstOffset1 }, // VkOffset3D dstOffset[2];
3968 region.imageBlit = imageBlit;
3969 params.regions.push_back(region);
3972 for (int i = 0; i < defaultSize; i += defaultFourthSize)
3974 const VkOffset3D srcOffset0 = {i, i, 0};
3975 const VkOffset3D srcOffset1 = {i + defaultFourthSize, i + defaultFourthSize, 1};
3976 const VkOffset3D dstOffset0 = {i, defaultSize / 2, 0};
3977 const VkOffset3D dstOffset1 = {i + defaultFourthSize, defaultSize / 2 + defaultFourthSize, 1};
3979 if (tcu::hasDepthComponent(mapVkFormat(params.src.image.format).order))
3981 const VkImageBlit imageBlit =
3983 defaultDepthSourceLayer, // VkImageSubresourceLayers srcSubresource;
3984 { srcOffset0, srcOffset1 }, // VkOffset3D srcOffsets[2];
3985 defaultDepthSourceLayer, // VkImageSubresourceLayers dstSubresource;
3986 { dstOffset0, dstOffset1 } // VkOffset3D dstOffset[2];
3988 region.imageBlit = imageBlit;
3989 params.regions.push_back(region);
3991 if (tcu::hasStencilComponent(mapVkFormat(params.src.image.format).order))
3993 const VkImageBlit imageBlit =
3995 defaultStencilSourceLayer, // VkImageSubresourceLayers srcSubresource;
3996 { srcOffset0, srcOffset1 }, // VkOffset3D srcOffsets[2];
3997 defaultStencilSourceLayer, // VkImageSubresourceLayers dstSubresource;
3998 { dstOffset0, dstOffset1 } // VkOffset3D dstOffset[2];
4000 region.imageBlit = imageBlit;
4001 params.regions.push_back(region);
4005 params.filter = VK_FILTER_NEAREST;
4006 blitImgAllFormatsTests->addChild(new BlittingTestCase(testCtx, oss.str() + "_nearest", description, params));
4010 blittingImageTests->addChild(blitImgSimpleTests.release());
4011 blittingImageTests->addChild(blitImgAllFormatsTests.release());
4014 // Resolve image to image testcases.
4015 const VkSampleCountFlagBits samples[] =
4017 VK_SAMPLE_COUNT_2_BIT,
4018 VK_SAMPLE_COUNT_4_BIT,
4019 VK_SAMPLE_COUNT_8_BIT,
4020 VK_SAMPLE_COUNT_16_BIT,
4021 VK_SAMPLE_COUNT_32_BIT,
4022 VK_SAMPLE_COUNT_64_BIT
4024 const VkExtent3D resolveExtent = {256u, 256u, 1};
4027 const std::string description ("Resolve from image to image");
4028 const std::string testName ("whole");
4031 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4032 params.src.image.extent = resolveExtent;
4033 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4034 params.dst.image.extent = resolveExtent;
4037 const VkImageSubresourceLayers sourceLayer =
4039 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4040 0u, // uint32_t mipLevel;
4041 0u, // uint32_t baseArrayLayer;
4042 1u // uint32_t layerCount;
4044 const VkImageResolve testResolve =
4046 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4047 {0, 0, 0}, // VkOffset3D srcOffset;
4048 sourceLayer, // VkImageSubresourceLayers dstSubresource;
4049 {0, 0, 0}, // VkOffset3D dstOffset;
4050 resolveExtent, // VkExtent3D extent;
4053 CopyRegion imageResolve;
4054 imageResolve.imageResolve = testResolve;
4055 params.regions.push_back(imageResolve);
4058 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4060 params.samples = samples[samplesIndex];
4061 std::ostringstream caseName;
4062 caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4063 resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4068 const std::string description ("Resolve from image to image");
4069 const std::string testName ("partial");
4072 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4073 params.src.image.extent = resolveExtent;
4074 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4075 params.dst.image.extent = resolveExtent;
4078 const VkImageSubresourceLayers sourceLayer =
4080 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4081 0u, // uint32_t mipLevel;
4082 0u, // uint32_t baseArrayLayer;
4083 1u // uint32_t layerCount;
4085 const VkImageResolve testResolve =
4087 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4088 {0, 0, 0}, // VkOffset3D srcOffset;
4089 sourceLayer, // VkImageSubresourceLayers dstSubresource;
4090 {64u, 64u, 0}, // VkOffset3D dstOffset;
4091 {128u, 128u, 1u}, // VkExtent3D extent;
4094 CopyRegion imageResolve;
4095 imageResolve.imageResolve = testResolve;
4096 params.regions.push_back(imageResolve);
4099 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4101 params.samples = samples[samplesIndex];
4102 std::ostringstream caseName;
4103 caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4104 resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4109 const std::string description ("Resolve from image to image");
4110 const std::string testName ("with_regions");
4113 params.src.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4114 params.src.image.extent = resolveExtent;
4115 params.dst.image.format = VK_FORMAT_R8G8B8A8_UNORM;
4116 params.dst.image.extent = resolveExtent;
4119 const VkImageSubresourceLayers sourceLayer =
4121 VK_IMAGE_ASPECT_COLOR_BIT, // VkImageAspectFlags aspectMask;
4122 0u, // uint32_t mipLevel;
4123 0u, // uint32_t baseArrayLayer;
4124 1u // uint32_t layerCount;
4127 for (int i = 0; i < 256; i += 64)
4129 const VkImageResolve testResolve =
4131 sourceLayer, // VkImageSubresourceLayers srcSubresource;
4132 {i, i, 0}, // VkOffset3D srcOffset;
4133 sourceLayer, // VkImageSubresourceLayers dstSubresource;
4134 {i, 0, 0}, // VkOffset3D dstOffset;
4135 {64u, 64u, 1u}, // VkExtent3D extent;
4138 CopyRegion imageResolve;
4139 imageResolve.imageResolve = testResolve;
4140 params.regions.push_back(imageResolve);
4144 for (int samplesIndex = 0; samplesIndex < DE_LENGTH_OF_ARRAY(samples); ++samplesIndex)
4146 params.samples = samples[samplesIndex];
4147 std::ostringstream caseName;
4148 caseName << testName << "_" << getSampleCountCaseName(samples[samplesIndex]);
4149 resolveImageTests->addChild(new ResolveImageToImageTestCase(testCtx, caseName.str(), description, params));
4153 copiesAndBlittingTests->addChild(imageToImageTests.release());
4154 copiesAndBlittingTests->addChild(imageToBufferTests.release());
4155 copiesAndBlittingTests->addChild(bufferToImageTests.release());
4156 copiesAndBlittingTests->addChild(bufferToBufferTests.release());
4157 copiesAndBlittingTests->addChild(blittingImageTests.release());
4158 copiesAndBlittingTests->addChild(resolveImageTests.release());
4160 return copiesAndBlittingTests.release();