mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 00:59:44 -06:00
Vulkan: Fix present semaphores reuse
Fixes validation errors. See https://docs.vulkan.org/guide/latest/swapchain_semaphore_reuse.html
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
|
||||
#include "VideoBackends/Vulkan/VulkanContext.h"
|
||||
#include "VideoCommon/Constants.h"
|
||||
#include "vulkan/vulkan_core.h"
|
||||
|
||||
namespace Vulkan
|
||||
{
|
||||
@ -32,9 +33,9 @@ CommandBufferManager::~CommandBufferManager()
|
||||
DestroyCommandBuffers();
|
||||
}
|
||||
|
||||
bool CommandBufferManager::Initialize()
|
||||
bool CommandBufferManager::Initialize(size_t swapchain_image_count)
|
||||
{
|
||||
if (!CreateCommandBuffers())
|
||||
if (!CreateCommandBuffers(swapchain_image_count))
|
||||
return false;
|
||||
|
||||
if (m_use_threaded_submission && !CreateSubmitThread())
|
||||
@ -43,7 +44,7 @@ bool CommandBufferManager::Initialize()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CommandBufferManager::CreateCommandBuffers()
|
||||
bool CommandBufferManager::CreateCommandBuffers(size_t swapchain_image_count)
|
||||
{
|
||||
static constexpr VkSemaphoreCreateInfo semaphore_create_info = {
|
||||
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, nullptr, 0};
|
||||
@ -95,11 +96,17 @@ bool CommandBufferManager::CreateCommandBuffers()
|
||||
}
|
||||
}
|
||||
|
||||
res = vkCreateSemaphore(device, &semaphore_create_info, nullptr, &m_present_semaphore);
|
||||
if (res != VK_SUCCESS)
|
||||
m_present_semaphores.reserve(swapchain_image_count);
|
||||
for (uint32_t i = 0; i < swapchain_image_count; i++)
|
||||
{
|
||||
LOG_VULKAN_ERROR(res, "vkCreateSemaphore failed: ");
|
||||
return false;
|
||||
VkSemaphore present_semaphore;
|
||||
res = vkCreateSemaphore(device, &semaphore_create_info, nullptr, &present_semaphore);
|
||||
if (res != VK_SUCCESS)
|
||||
{
|
||||
LOG_VULKAN_ERROR(res, "vkCreateSemaphore failed: ");
|
||||
return false;
|
||||
}
|
||||
m_present_semaphores.push_back(present_semaphore);
|
||||
}
|
||||
|
||||
// Activate the first command buffer. BeginCommandBuffer moves forward, so start with the last
|
||||
@ -140,7 +147,10 @@ void CommandBufferManager::DestroyCommandBuffers()
|
||||
}
|
||||
}
|
||||
|
||||
vkDestroySemaphore(device, m_present_semaphore, nullptr);
|
||||
for (VkSemaphore present_semaphore : m_present_semaphores)
|
||||
{
|
||||
vkDestroySemaphore(device, present_semaphore, nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
VkDescriptorPool CommandBufferManager::CreateDescriptorPool(u32 max_descriptor_sets)
|
||||
@ -414,7 +424,7 @@ void CommandBufferManager::SubmitCommandBuffer(u32 command_buffer_index,
|
||||
if (present_swap_chain != VK_NULL_HANDLE)
|
||||
{
|
||||
submit_info.signalSemaphoreCount = 1;
|
||||
submit_info.pSignalSemaphores = &m_present_semaphore;
|
||||
submit_info.pSignalSemaphores = &m_present_semaphores[present_image_index];
|
||||
}
|
||||
|
||||
VkResult res =
|
||||
@ -433,7 +443,7 @@ void CommandBufferManager::SubmitCommandBuffer(u32 command_buffer_index,
|
||||
VkPresentInfoKHR present_info = {VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
|
||||
nullptr,
|
||||
1,
|
||||
&m_present_semaphore,
|
||||
&m_present_semaphores[present_image_index],
|
||||
1,
|
||||
&present_swap_chain,
|
||||
&present_image_index,
|
||||
|
Reference in New Issue
Block a user