From a0653a1a34310d916b2a0ae0392f6171d88fa928 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 12 Nov 2018 01:02:32 +1000 Subject: [PATCH] Vulkan: Fix incorrect fence being assigned to staging texture --- Source/Core/VideoBackends/Vulkan/VKTexture.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp index 63b88195c0..304c5cc908 100644 --- a/Source/Core/VideoBackends/Vulkan/VKTexture.cpp +++ b/Source/Core/VideoBackends/Vulkan/VKTexture.cpp @@ -407,7 +407,7 @@ void VKStagingTexture::CopyFromTexture(const AbstractTexture* src, const MathUtil::Rectangle& src_rect, u32 src_layer, u32 src_level, const MathUtil::Rectangle& dst_rect) { - ASSERT(m_type == StagingTextureType::Readback); + ASSERT(m_type == StagingTextureType::Readback || m_type == StagingTextureType::Mutable); ASSERT(src_rect.GetWidth() == dst_rect.GetWidth() && src_rect.GetHeight() == dst_rect.GetHeight()); ASSERT(src_rect.left >= 0 && static_cast(src_rect.right) <= src->GetConfig().width && @@ -459,9 +459,15 @@ void VKStagingTexture::CopyFromTexture(Texture2D* src, const MathUtil::Rectangle g_command_buffer_mgr->AddFencePointCallback(this, [this](VkCommandBuffer buf, VkFence fence) { ASSERT(m_needs_flush); + if (m_flush_fence != VK_NULL_HANDLE) + return; + m_flush_fence = fence; }, [this](VkFence fence) { + if (m_flush_fence != fence) + return; + m_flush_fence = VK_NULL_HANDLE; m_needs_flush = false; g_command_buffer_mgr->RemoveFencePointCallback( @@ -474,7 +480,7 @@ void VKStagingTexture::CopyToTexture(const MathUtil::Rectangle& src_rect, A const MathUtil::Rectangle& dst_rect, u32 dst_layer, u32 dst_level) { - ASSERT(m_type == StagingTextureType::Upload); + ASSERT(m_type == StagingTextureType::Upload || m_type == StagingTextureType::Mutable); ASSERT(src_rect.GetWidth() == dst_rect.GetWidth() && src_rect.GetHeight() == dst_rect.GetHeight()); ASSERT(src_rect.left >= 0 && static_cast(src_rect.right) <= m_config.width && @@ -520,9 +526,15 @@ void VKStagingTexture::CopyToTexture(const MathUtil::Rectangle& src_rect, A g_command_buffer_mgr->AddFencePointCallback(this, [this](VkCommandBuffer buf, VkFence fence) { ASSERT(m_needs_flush); + if (m_flush_fence != VK_NULL_HANDLE) + return; + m_flush_fence = fence; }, [this](VkFence fence) { + if (m_flush_fence != fence) + return; + m_flush_fence = VK_NULL_HANDLE; m_needs_flush = false; g_command_buffer_mgr->RemoveFencePointCallback( @@ -563,7 +575,7 @@ void VKStagingTexture::Flush() m_needs_flush = false; // For readback textures, invalidate the CPU cache as there is new data there. - if (m_type == StagingTextureType::Readback) + if (m_type == StagingTextureType::Readback || m_type == StagingTextureType::Mutable) m_staging_buffer->InvalidateCPUCache(); }