mirror of
https://github.com/cemu-project/Cemu.git
synced 2024-12-25 17:21:52 +01:00
Vulkan: Cleanup image barrier code (#988)
This commit is contained in:
parent
db44a2d130
commit
d4a2a8e8de
@ -2801,47 +2801,18 @@ void VulkanRenderer::ClearColorImageRaw(VkImage image, uint32 sliceIndex, uint32
|
||||
{
|
||||
draw_endRenderPass();
|
||||
|
||||
VkImageMemoryBarrier barrier = {};
|
||||
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
barrier.oldLayout = inputLayout;
|
||||
barrier.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.image = image;
|
||||
barrier.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
barrier.subresourceRange.baseMipLevel = mipIndex;
|
||||
barrier.subresourceRange.levelCount = 1;
|
||||
barrier.subresourceRange.baseArrayLayer = sliceIndex;
|
||||
barrier.subresourceRange.layerCount = 1;
|
||||
VkImageSubresourceRange subresourceRange{};
|
||||
subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
subresourceRange.baseMipLevel = mipIndex;
|
||||
subresourceRange.levelCount = 1;
|
||||
subresourceRange.baseArrayLayer = sliceIndex;
|
||||
subresourceRange.layerCount = 1;
|
||||
|
||||
VkPipelineStageFlags srcStages = 0;
|
||||
VkPipelineStageFlags dstStages = 0;
|
||||
barrier.srcAccessMask = 0;
|
||||
barrier.dstAccessMask = 0;
|
||||
barrier_calcStageAndMask<SYNC_OP::ANY_TRANSFER | SYNC_OP::IMAGE_READ | SYNC_OP::IMAGE_WRITE>(srcStages, barrier.srcAccessMask);
|
||||
barrier_calcStageAndMask<SYNC_OP::ANY_TRANSFER>(dstStages, barrier.dstAccessMask);
|
||||
barrier_image<SYNC_OP::ANY_TRANSFER | SYNC_OP::IMAGE_READ | SYNC_OP::IMAGE_WRITE, SYNC_OP::ANY_TRANSFER>(image, subresourceRange, inputLayout, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
|
||||
|
||||
vkCmdPipelineBarrier(m_state.currentCommandBuffer, srcStages, dstStages, 0, 0, nullptr, 0, nullptr, 1, &barrier);
|
||||
vkCmdClearColorImage(m_state.currentCommandBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &color, 1, &subresourceRange);
|
||||
|
||||
VkImageSubresourceRange imageRange{};
|
||||
imageRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
imageRange.baseArrayLayer = sliceIndex;
|
||||
imageRange.layerCount = 1;
|
||||
imageRange.baseMipLevel = mipIndex;
|
||||
imageRange.levelCount = 1;
|
||||
|
||||
vkCmdClearColorImage(m_state.currentCommandBuffer, image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &color, 1, &imageRange);
|
||||
|
||||
barrier.oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
|
||||
barrier.newLayout = outputLayout;
|
||||
|
||||
srcStages = 0;
|
||||
dstStages = 0;
|
||||
barrier.srcAccessMask = 0;
|
||||
barrier.dstAccessMask = 0;
|
||||
barrier_calcStageAndMask<SYNC_OP::ANY_TRANSFER>(srcStages, barrier.srcAccessMask);
|
||||
barrier_calcStageAndMask<SYNC_OP::ANY_TRANSFER | SYNC_OP::IMAGE_READ | SYNC_OP::IMAGE_WRITE>(dstStages, barrier.dstAccessMask);
|
||||
vkCmdPipelineBarrier(m_state.currentCommandBuffer, srcStages, dstStages, 0, 0, nullptr, 0, nullptr, 1, &barrier);
|
||||
barrier_image<ANY_TRANSFER, SYNC_OP::ANY_TRANSFER | SYNC_OP::IMAGE_READ | SYNC_OP::IMAGE_WRITE>(image, subresourceRange, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, outputLayout);
|
||||
}
|
||||
|
||||
void VulkanRenderer::ClearColorImage(LatteTextureVk* vkTexture, uint32 sliceIndex, uint32 mipIndex, const VkClearColorValue& color, VkImageLayout outputLayout)
|
||||
|
@ -906,10 +906,8 @@ private:
|
||||
}
|
||||
|
||||
template<uint32 TSrcSyncOp, uint32 TDstSyncOp>
|
||||
void barrier_image(LatteTextureVk* vkTexture, VkImageSubresourceLayers& subresourceLayers, VkImageLayout newLayout)
|
||||
void barrier_image(VkImage imageVk, VkImageSubresourceRange& subresourceRange, VkImageLayout oldLayout, VkImageLayout newLayout)
|
||||
{
|
||||
VkImage imageVk = vkTexture->GetImageObj()->m_image;
|
||||
|
||||
VkPipelineStageFlags srcStages = 0;
|
||||
VkPipelineStageFlags dstStages = 0;
|
||||
|
||||
@ -922,22 +920,33 @@ private:
|
||||
barrier_calcStageAndMask<TSrcSyncOp>(srcStages, imageMemBarrier.srcAccessMask);
|
||||
barrier_calcStageAndMask<TDstSyncOp>(dstStages, imageMemBarrier.dstAccessMask);
|
||||
imageMemBarrier.image = imageVk;
|
||||
imageMemBarrier.subresourceRange.aspectMask = subresourceLayers.aspectMask;
|
||||
imageMemBarrier.subresourceRange.baseArrayLayer = subresourceLayers.baseArrayLayer;
|
||||
imageMemBarrier.subresourceRange.layerCount = subresourceLayers.layerCount;
|
||||
imageMemBarrier.subresourceRange.baseMipLevel = subresourceLayers.mipLevel;
|
||||
imageMemBarrier.subresourceRange.levelCount = 1;
|
||||
imageMemBarrier.oldLayout = vkTexture->GetImageLayout(imageMemBarrier.subresourceRange);
|
||||
imageMemBarrier.subresourceRange = subresourceRange;
|
||||
imageMemBarrier.oldLayout = oldLayout;
|
||||
imageMemBarrier.newLayout = newLayout;
|
||||
|
||||
vkCmdPipelineBarrier(m_state.currentCommandBuffer,
|
||||
srcStages, dstStages,
|
||||
0,
|
||||
0, NULL,
|
||||
0, NULL,
|
||||
1, &imageMemBarrier);
|
||||
srcStages, dstStages,
|
||||
0,
|
||||
0, NULL,
|
||||
0, NULL,
|
||||
1, &imageMemBarrier);
|
||||
}
|
||||
|
||||
vkTexture->SetImageLayout(imageMemBarrier.subresourceRange, newLayout);
|
||||
template<uint32 TSrcSyncOp, uint32 TDstSyncOp>
|
||||
void barrier_image(LatteTextureVk* vkTexture, VkImageSubresourceLayers& subresourceLayers, VkImageLayout newLayout)
|
||||
{
|
||||
VkImage imageVk = vkTexture->GetImageObj()->m_image;
|
||||
|
||||
VkImageSubresourceRange subresourceRange;
|
||||
subresourceRange.aspectMask = subresourceLayers.aspectMask;
|
||||
subresourceRange.baseArrayLayer = subresourceLayers.baseArrayLayer;
|
||||
subresourceRange.layerCount = subresourceLayers.layerCount;
|
||||
subresourceRange.baseMipLevel = subresourceLayers.mipLevel;
|
||||
subresourceRange.levelCount = 1;
|
||||
|
||||
barrier_image<TSrcSyncOp, TDstSyncOp>(imageVk, subresourceRange, vkTexture->GetImageLayout(subresourceRange), newLayout);
|
||||
|
||||
vkTexture->SetImageLayout(subresourceRange, newLayout);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user