Skip to content

Commit

Permalink
GS/Vulkan: Prevent transition back to Undefined layout
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Aug 27, 2023
1 parent b15102d commit 0678bb0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ void GSTextureVK::UpdateFromBuffer(VkCommandBuffer cmdbuf, int level, u32 x, u32
u32 buffer_height, u32 row_length, VkBuffer buffer, u32 buffer_offset)
{
const Layout old_layout = m_layout;
if (old_layout != Layout::TransferDst)
if (old_layout == Layout::Undefined)
TransitionToLayout(cmdbuf, Layout::TransferDst);
else if (old_layout != Layout::TransferDst)
TransitionSubresourcesToLayout(cmdbuf, level, 1, old_layout, Layout::TransferDst);

const VkBufferImageCopy bic = {static_cast<VkDeviceSize>(buffer_offset), row_length, buffer_height,
Expand All @@ -351,7 +353,7 @@ void GSTextureVK::UpdateFromBuffer(VkCommandBuffer cmdbuf, int level, u32 x, u32

vkCmdCopyBufferToImage(cmdbuf, buffer, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &bic);

if (old_layout != Layout::TransferDst)
if (old_layout != Layout::TransferDst && old_layout != Layout::Undefined)
TransitionSubresourcesToLayout(cmdbuf, level, 1, Layout::TransferDst, old_layout);
}

Expand Down Expand Up @@ -499,6 +501,9 @@ void GSTextureVK::GenerateMipmap()
{
const VkCommandBuffer cmdbuf = GetCommandBufferForUpdate();

if (m_layout == Layout::Undefined)
TransitionToLayout(cmdbuf, Layout::TransferSrc);

for (int dst_level = 1; dst_level < m_mipmap_levels; dst_level++)
{
const int src_level = dst_level - 1;
Expand Down Expand Up @@ -885,7 +890,9 @@ void GSDownloadTextureVK::CopyFromTexture(
GL_INS("GSDownloadTextureVK::CopyFromTexture: {%d,%d} %ux%u", src.left, src.top, src.width(), src.height());

GSTextureVK::Layout old_layout = vkTex->GetLayout();
if (old_layout != GSTextureVK::Layout::TransferSrc)
if (old_layout == GSTextureVK::Layout::Undefined)
vkTex->TransitionToLayout(cmdbuf, GSTextureVK::Layout::TransferSrc);
else if (old_layout != GSTextureVK::Layout::TransferSrc)
vkTex->TransitionSubresourcesToLayout(cmdbuf, src_level, 1, old_layout, GSTextureVK::Layout::TransferSrc);

VkBufferImageCopy image_copy = {};
Expand Down Expand Up @@ -915,7 +922,7 @@ void GSDownloadTextureVK::CopyFromTexture(
vkCmdPipelineBarrier(
cmdbuf, VK_ACCESS_TRANSFER_WRITE_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 0, nullptr, 1, &buffer_info, 0, nullptr);

if (old_layout != GSTextureVK::Layout::TransferSrc)
if (old_layout != GSTextureVK::Layout::TransferSrc && old_layout != GSTextureVK::Layout::Undefined)
vkTex->TransitionSubresourcesToLayout(cmdbuf, src_level, 1, GSTextureVK::Layout::TransferSrc, old_layout);

m_copy_fence_counter = GSDeviceVK::GetInstance()->GetCurrentFenceCounter();
Expand Down

0 comments on commit 0678bb0

Please sign in to comment.