| 1431 | } |
| 1432 | |
| 1433 | static void ProcessDefragmentationPass(VmaDefragmentationPassMoveInfo& stepInfo) |
| 1434 | { |
| 1435 | std::vector<VkImageMemoryBarrier> beginImageBarriers; |
| 1436 | std::vector<VkImageMemoryBarrier> finalizeImageBarriers; |
| 1437 | |
| 1438 | VkPipelineStageFlags beginSrcStageMask = 0; |
| 1439 | VkPipelineStageFlags beginDstStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; |
| 1440 | |
| 1441 | VkPipelineStageFlags finalizeSrcStageMask = VK_PIPELINE_STAGE_TRANSFER_BIT; |
| 1442 | VkPipelineStageFlags finalizeDstStageMask = 0; |
| 1443 | |
| 1444 | bool wantsMemoryBarrier = false; |
| 1445 | |
| 1446 | VkMemoryBarrier beginMemoryBarrier = { VK_STRUCTURE_TYPE_MEMORY_BARRIER }; |
| 1447 | VkMemoryBarrier finalizeMemoryBarrier = { VK_STRUCTURE_TYPE_MEMORY_BARRIER }; |
| 1448 | |
| 1449 | for (uint32_t i = 0; i < stepInfo.moveCount; ++i) |
| 1450 | { |
| 1451 | VmaAllocationInfo info; |
| 1452 | vmaGetAllocationInfo(g_hAllocator, stepInfo.pMoves[i].srcAllocation, &info); |
| 1453 | |
| 1454 | AllocInfo* allocInfo = (AllocInfo*)info.pUserData; |
| 1455 | // Allocation comes from this test and it is movable. |
| 1456 | if(stepInfo.pMoves[i].operation == VMA_DEFRAGMENTATION_MOVE_OPERATION_COPY && |
| 1457 | allocInfo != nullptr && allocInfo->m_DefragmentationMovable) |
| 1458 | { |
| 1459 | if (allocInfo->m_Image) |
| 1460 | { |
| 1461 | VkImage newImage; |
| 1462 | |
| 1463 | const VkResult result = vkCreateImage(g_hDevice, &allocInfo->m_ImageInfo, g_Allocs, &newImage); |
| 1464 | TEST(result >= VK_SUCCESS); |
| 1465 | |
| 1466 | vmaBindImageMemory(g_hAllocator, stepInfo.pMoves[i].dstTmpAllocation, newImage); |
| 1467 | allocInfo->m_NewImage = newImage; |
| 1468 | |
| 1469 | // Keep track of our pipeline stages that we need to wait/signal on |
| 1470 | beginSrcStageMask |= VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
| 1471 | finalizeDstStageMask |= VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; |
| 1472 | |
| 1473 | // We need one pipeline barrier and two image layout transitions here |
| 1474 | // First we'll have to turn our newly created image into VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL |
| 1475 | // And the second one is turning the old image into VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL |
| 1476 | |
| 1477 | VkImageSubresourceRange subresourceRange = { |
| 1478 | VK_IMAGE_ASPECT_COLOR_BIT, |
| 1479 | 0, VK_REMAINING_MIP_LEVELS, |
| 1480 | 0, VK_REMAINING_ARRAY_LAYERS |
| 1481 | }; |
| 1482 | |
| 1483 | VkImageMemoryBarrier barrier = { VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER }; |
| 1484 | barrier.srcAccessMask = 0; |
| 1485 | barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT; |
| 1486 | barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED; |
| 1487 | barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; |
| 1488 | barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 1489 | barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED; |
| 1490 | barrier.image = newImage; |
no test coverage detected