diff --git a/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp b/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp index f01f8ac25b..774afbf79d 100644 --- a/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp +++ b/Source/Core/VideoBackends/Vulkan/FramebufferManager.cpp @@ -738,9 +738,7 @@ bool FramebufferManager::PopulateColorReadbackTexture() } // Wait until the copy is complete. - g_command_buffer_mgr->ExecuteCommandBuffer(false, true); - StateTracker::GetInstance()->InvalidateDescriptorSets(); - StateTracker::GetInstance()->SetPendingRebind(); + Util::ExecuteCurrentCommandsAndRestoreState(false, true); // Map to host memory. if (!m_color_readback_texture->IsMapped() && !m_color_readback_texture->Map()) @@ -822,9 +820,7 @@ bool FramebufferManager::PopulateDepthReadbackTexture() } // Wait until the copy is complete. - g_command_buffer_mgr->ExecuteCommandBuffer(false, true); - StateTracker::GetInstance()->InvalidateDescriptorSets(); - StateTracker::GetInstance()->SetPendingRebind(); + Util::ExecuteCurrentCommandsAndRestoreState(false, true); // Map to host memory. if (!m_depth_readback_texture->IsMapped() && !m_depth_readback_texture->Map()) @@ -1212,7 +1208,7 @@ void FramebufferManager::DrawPokeVertices(const EFBPokeVertex* vertices, size_t { // Kick a command buffer first. WARN_LOG(VIDEO, "Kicking command buffer due to no EFB poke space."); - Util::ExecuteCurrentCommandsAndRestoreState(true); + Util::ExecuteCurrentCommandsAndRestoreState(false); command_buffer = g_command_buffer_mgr->GetCurrentCommandBuffer(); if (!m_poke_vertex_stream_buffer->ReserveMemory(vertices_size, sizeof(EfbPokeData), true, true, diff --git a/Source/Core/VideoBackends/Vulkan/Renderer.cpp b/Source/Core/VideoBackends/Vulkan/Renderer.cpp index f26117a084..2b8e0b63a6 100644 --- a/Source/Core/VideoBackends/Vulkan/Renderer.cpp +++ b/Source/Core/VideoBackends/Vulkan/Renderer.cpp @@ -326,6 +326,7 @@ void Renderer::BeginFrame() // Ensure that the state tracker rebinds everything, and allocates a new set // of descriptors out of the next pool. StateTracker::GetInstance()->InvalidateDescriptorSets(); + StateTracker::GetInstance()->InvalidateConstants(); StateTracker::GetInstance()->SetPendingRebind(); } diff --git a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp index 40a32b0087..67583782c9 100644 --- a/Source/Core/VideoBackends/Vulkan/StateTracker.cpp +++ b/Source/Core/VideoBackends/Vulkan/StateTracker.cpp @@ -710,11 +710,7 @@ bool StateTracker::Bind(bool rebind_all /*= false*/) { // We can fail to allocate descriptors if we exhaust the pool for this command buffer. WARN_LOG(VIDEO, "Failed to get a descriptor set, executing buffer"); - - // Try again after executing the current buffer. - g_command_buffer_mgr->ExecuteCommandBuffer(false, false); - InvalidateDescriptorSets(); - SetPendingRebind(); + Util::ExecuteCurrentCommandsAndRestoreState(false, false); if (!UpdateDescriptorSet()) { // Something strange going on. @@ -777,10 +773,7 @@ void StateTracker::OnDraw() m_scheduled_command_buffer_kicks.end(), m_draw_counter)) { // Kick a command buffer on the background thread. - EndRenderPass(); - g_command_buffer_mgr->ExecuteCommandBuffer(true, false); - InvalidateDescriptorSets(); - SetPendingRebind(); + Util::ExecuteCurrentCommandsAndRestoreState(true); } } diff --git a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp index d52ba671db..b607a91fd0 100644 --- a/Source/Core/VideoBackends/Vulkan/TextureCache.cpp +++ b/Source/Core/VideoBackends/Vulkan/TextureCache.cpp @@ -145,10 +145,10 @@ void TextureCache::CopyEFB(u8* dst, u32 format, u32 native_width, u32 bytes_per_ else src_texture = FramebufferManager::GetInstance()->ResolveEFBColorTexture(region); - // End render pass before barrier (since we have no self-dependencies) + // End render pass before barrier (since we have no self-dependencies). + // The barrier has to happen after the render pass, not inside it, as we are going to be + // reading from the texture immediately afterwards. StateTracker::GetInstance()->EndRenderPass(); - StateTracker::GetInstance()->SetPendingRebind(); - StateTracker::GetInstance()->InvalidateDescriptorSets(); StateTracker::GetInstance()->OnReadback(); // Transition to shader resource before reading. @@ -666,9 +666,7 @@ bool TextureCache::TCacheEntry::Save(const std::string& filename, unsigned int l VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); // Block until the GPU has finished copying to the staging texture. - g_command_buffer_mgr->ExecuteCommandBuffer(false, true); - StateTracker::GetInstance()->InvalidateDescriptorSets(); - StateTracker::GetInstance()->SetPendingRebind(); + Util::ExecuteCurrentCommandsAndRestoreState(false, true); // Map the staging texture so we can copy the contents out. if (staging_texture->Map()) diff --git a/Source/Core/VideoBackends/Vulkan/TextureEncoder.cpp b/Source/Core/VideoBackends/Vulkan/TextureEncoder.cpp index 404b30b09c..77a443a9e0 100644 --- a/Source/Core/VideoBackends/Vulkan/TextureEncoder.cpp +++ b/Source/Core/VideoBackends/Vulkan/TextureEncoder.cpp @@ -121,9 +121,7 @@ void TextureEncoder::EncodeTextureToRam(VkImageView src_texture, u8* dest_ptr, u render_width, render_height, 0, 0); // Block until the GPU has finished copying to the staging texture. - g_command_buffer_mgr->ExecuteCommandBuffer(false, true); - StateTracker::GetInstance()->InvalidateDescriptorSets(); - StateTracker::GetInstance()->SetPendingRebind(); + Util::ExecuteCurrentCommandsAndRestoreState(false, true); // Copy from staging texture to the final destination, adjusting pitch if necessary. m_download_texture->ReadTexels(0, 0, render_width, render_height, dest_ptr, memory_stride);