From 73b09a8374f121d09b8aa17817469e666eab5dd5 Mon Sep 17 00:00:00 2001 From: FakeMichau <49685661+FakeMichau@users.noreply.github.com> Date: Thu, 26 Mar 2026 14:20:15 +0100 Subject: [PATCH] Mutex the access to commandPoolToQueueFamilyMap --- OptiScaler/Config.h | 2 +- OptiScaler/hooks/VulkanwDx12_Hooks.cpp | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/OptiScaler/Config.h b/OptiScaler/Config.h index 8c5aa4be..73883eac 100644 --- a/OptiScaler/Config.h +++ b/OptiScaler/Config.h @@ -315,7 +315,7 @@ class Config L"idtechlauncher.exe|cefviewwing.exe|ace-setup64.exe|ace-service64.exe|qtwebengineprocess.exe|" L"platformprocess.exe|bugsplathd64.exe|bssndrpt64.exe|pspcsdkappmgr.exe|pspcsdkcore.exe|pspcsdkstttts.exe|" L"pspcsdktelemetry.exe|pspcsdkui.exe|pspcsdkupdatechecker.exe|pspcsdkvoicechat.exe|pspcsdkwebview.exe|windhawk." - L"exe|vscodium.exe|crash_reporter.exe|steamerrorreporter64.exe" + L"exe|vscodium.exe|crash_reporter.exe|steamerrorreporter64.exe|crashreportclient.exe" }; // Hotfixes diff --git a/OptiScaler/hooks/VulkanwDx12_Hooks.cpp b/OptiScaler/hooks/VulkanwDx12_Hooks.cpp index f00c88b5..bcf7b839 100644 --- a/OptiScaler/hooks/VulkanwDx12_Hooks.cpp +++ b/OptiScaler/hooks/VulkanwDx12_Hooks.cpp @@ -25,6 +25,7 @@ static PFN_vkAllocateCommandBuffers o_vkAllocateCommandBuffers = nullptr; static PFN_vkDestroyCommandPool o_vkDestroyCommandPool = nullptr; static PFN_vkCreateCommandPool o_vkCreateCommandPool = nullptr; +static std::mutex mutexCommandPoolToQueueFamilyMap; static std::unordered_map commandPoolToQueueFamilyMap; // #define LOG_ALL_RECORDS @@ -6048,7 +6049,10 @@ VkResult Vulkan_wDx12::hk_vkCreateCommandPool(VkDevice device, const VkCommandPo if (result == VK_SUCCESS && pCommandPool && *pCommandPool != VK_NULL_HANDLE && pCreateInfo) { - commandPoolToQueueFamilyMap[*pCommandPool] = pCreateInfo->queueFamilyIndex; + { + std::scoped_lock lock(mutexCommandPoolToQueueFamilyMap); + commandPoolToQueueFamilyMap[*pCommandPool] = pCreateInfo->queueFamilyIndex; + } LOG_DEBUG("Command pool {:X} created for queue family {}", (size_t) *pCommandPool, pCreateInfo->queueFamilyIndex); @@ -7195,8 +7199,13 @@ VkResult Vulkan_wDx12::hk_vkAllocateCommandBuffers(VkDevice device, const VkComm if (result == VK_SUCCESS && pAllocateInfo != nullptr && pCommandBuffers != nullptr) { - auto it = commandPoolToQueueFamilyMap.find(pAllocateInfo->commandPool); - uint32_t queueFamily = (it != commandPoolToQueueFamilyMap.end()) ? it->second : 0; + uint32_t queueFamily = 0; + + { + std::scoped_lock lock(mutexCommandPoolToQueueFamilyMap); + auto it = commandPoolToQueueFamilyMap.find(pAllocateInfo->commandPool); + queueFamily = (it != commandPoolToQueueFamilyMap.end()) ? it->second : 0; + } // Notify state tracker about new command buffers cmdBufferStateTracker.OnAllocateCommandBuffers(pAllocateInfo->commandPool, pAllocateInfo->commandBufferCount,