vk: Properly clean up async scheduler

This commit is contained in:
kd-11 2021-02-28 22:18:14 +03:00 committed by kd-11
parent 41f5158247
commit c9e8b87c60
3 changed files with 23 additions and 10 deletions

View File

@ -67,18 +67,11 @@ namespace vk
AsyncTaskScheduler::~AsyncTaskScheduler() AsyncTaskScheduler::~AsyncTaskScheduler()
{ {
*g_fxo->get<async_scheduler_thread>() = thread_state::aborting; if (!m_async_command_queue.empty())
while (has_refs()) _mm_pause();
for (auto& cb : m_async_command_queue)
{ {
cb.destroy(); // Driver resources should be destroyed before driver is detached or you get crashes. RAII won't save you here.
rsx_log.error("Async task scheduler resources were not freed correctly!");
} }
m_async_command_queue.clear();
m_next_cb_index = 0;
m_command_pool.destroy();
m_events_pool.clear();
} }
command_buffer* AsyncTaskScheduler::get_current() command_buffer* AsyncTaskScheduler::get_current()
@ -158,4 +151,20 @@ namespace vk
m_current_cb = nullptr; m_current_cb = nullptr;
m_sync_required = false; m_sync_required = false;
} }
void AsyncTaskScheduler::kill()
{
*g_fxo->get<async_scheduler_thread>() = thread_state::aborting;
while (has_refs()) _mm_pause();
for (auto& cb : m_async_command_queue)
{
cb.destroy();
}
m_async_command_queue.clear();
m_next_cb_index = 0;
m_command_pool.destroy();
m_events_pool.clear();
}
} }

View File

@ -49,6 +49,7 @@ namespace vk
event* get_primary_sync_label(); event* get_primary_sync_label();
void flush(VkSemaphore wait_semaphore = VK_NULL_HANDLE, VkPipelineStageFlags wait_dst_stage_mask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT); void flush(VkSemaphore wait_semaphore = VK_NULL_HANDLE, VkPipelineStageFlags wait_dst_stage_mask = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT);
void kill();
// Thread entry-point // Thread entry-point
void operator()(); void operator()();

View File

@ -558,6 +558,9 @@ VKGSRender::~VKGSRender()
return; return;
} }
// Globals. TODO: Refactor lifetime management
g_fxo->get<vk::async_scheduler_thread>()->kill();
//Wait for device to finish up with resources //Wait for device to finish up with resources
vkDeviceWaitIdle(*m_device); vkDeviceWaitIdle(*m_device);