vk: Optimization - avoid touching the mutex at all if possible even when there is no contention

This commit is contained in:
kd-11 2021-02-28 22:34:01 +03:00 committed by kd-11
parent c9e8b87c60
commit 589ac1c5d4
2 changed files with 4 additions and 6 deletions

View File

@ -118,10 +118,9 @@ namespace vk
event* AsyncTaskScheduler::get_primary_sync_label()
{
std::lock_guard lock(m_submit_mutex);
if (m_sync_required)
if (m_sync_required) [[unlikely]]
{
std::lock_guard lock(m_submit_mutex); // For some reason this is inexplicably expensive. WTF!
ensure(m_current_cb);
insert_sync_event();
m_sync_required = false;
@ -132,13 +131,12 @@ namespace vk
void AsyncTaskScheduler::flush(VkSemaphore wait_semaphore, VkPipelineStageFlags wait_dst_stage_mask)
{
std::lock_guard lock(m_submit_mutex);
if (!m_current_cb)
{
return;
}
std::lock_guard lock(m_submit_mutex);
if (m_sync_required)
{
insert_sync_event();

View File

@ -29,7 +29,7 @@ namespace vk
// Sync
event* m_sync_label = nullptr;
bool m_sync_required = false;
atomic_t<bool> m_sync_required = false;
static constexpr u32 events_pool_size = 16384;
std::vector<xqueue_event> m_events_pool;