Skip to content

Commit

Permalink
simpler barriers
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Oct 31, 2023
1 parent a1ed706 commit 79e348c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 37 deletions.
39 changes: 2 additions & 37 deletions src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2734,27 +2734,7 @@ void VulkanRenderer::PresentFrontBuffer(bool mainWindow)
barrierRange.baseMipLevel = 0;
barrierRange.levelCount = 1;

// discard swapchain image previous content and transition for transfer
// nothing has to wait because execution of copy doesn't start until semaphore is signalled
// again
VkImageMemoryBarrier imgBarrier{};
imgBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imgBarrier.image = chainImage;
imgBarrier.subresourceRange = barrierRange;
imgBarrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
imgBarrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
imgBarrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
imgBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imgBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;

vkCmdPipelineBarrier(m_state.currentCommandBuffer,
VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT,
0,
0, nullptr,
0, nullptr,
1, &imgBarrier);

barrier_image<0, TRANSFER_WRITE>(chainImage, barrierRange, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
barrier_image<IMAGE_WRITE | TRANSFER_WRITE, TRANSFER_READ>(frontBuffer.image, barrierRange, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);

VkImageSubresourceLayers subResourceLayers{};
Expand All @@ -2776,22 +2756,7 @@ void VulkanRenderer::PresentFrontBuffer(bool mainWindow)
// transition swapchain image into present layout. only the transfer needs to be forced done.
// specification states that no future work has to wait vkQueuePresent handles that, but barrier_image does not support this
// in a way that doesn't leave dstStageMask empty, which violates the spec.
imgBarrier = {};
imgBarrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
imgBarrier.image = chainImage;
imgBarrier.subresourceRange = barrierRange;
imgBarrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
imgBarrier.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
imgBarrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
imgBarrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
imgBarrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
vkCmdPipelineBarrier(m_state.currentCommandBuffer,
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT,
0,
0, nullptr,
0, nullptr,
1, &imgBarrier);
barrier_image<TRANSFER_WRITE, 0>(chainImage, barrierRange, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
}

VkSemaphore presentSemaphore = chainInfo.m_presentSemaphores[chainInfo.swapchainImageIndex];
Expand Down
4 changes: 4 additions & 0 deletions src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,10 @@ class VulkanRenderer : public Renderer
imageMemBarrier.dstAccessMask = 0;
barrier_calcStageAndMask<TSrcSyncOp>(srcStages, imageMemBarrier.srcAccessMask);
barrier_calcStageAndMask<TDstSyncOp>(dstStages, imageMemBarrier.dstAccessMask);
if(srcStages == VK_PIPELINE_STAGE_NONE)
srcStages = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
if(dstStages == VK_PIPELINE_STAGE_NONE)
dstStages = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
imageMemBarrier.image = imageVk;
imageMemBarrier.subresourceRange = subresourceRange;
imageMemBarrier.oldLayout = oldLayout;
Expand Down

0 comments on commit 79e348c

Please sign in to comment.