From 47948aa2d1c744cb2d761f17271660d69cbd66c1 Mon Sep 17 00:00:00 2001 From: goeiecool9999 <7033575+goeiecool9999@users.noreply.github.com> Date: Tue, 7 Apr 2026 19:55:22 +0200 Subject: [PATCH] Fix deadlocking issue --- .../Latte/Renderer/Vulkan/VulkanRenderer.cpp | 41 ++++++++++++------- src/main.cpp | 6 +++ 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp index 9af7c09d..a8a496c3 100644 --- a/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp +++ b/src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp @@ -339,6 +339,31 @@ void VulkanRenderer::GetDeviceFeatures() #if BOOST_OS_LINUX #include +int BreathOfTheWildChildProcessMain() +{ + InitializeGlobalVulkan(); + struct sigaction sa{.sa_handler = [](int unused){_exit(1);}}; + int ret = sigaction(SIGABRT, &sa, nullptr); + + freopen("/dev/null", "w", stderr); + + setenv("RADV_DEBUG", "llvm", 1); + + VkInstanceCreateInfo create_info{}; + create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; + VkInstance instance = VK_NULL_HANDLE; + if (vkCreateInstance(&create_info, nullptr, &instance) != VK_SUCCESS) + return 1; + InitializeInstanceVulkan(instance); + + // this function will abort() when LLVM is absent + uint32_t count = 0; + vkEnumeratePhysicalDevices(instance, &count, nullptr); + + vkDestroyInstance(instance, nullptr); + return 0; +} + static void LinuxBreathOfTheWildWorkaround(VkInstance& instance, const VkInstanceCreateInfo* create_info) { @@ -390,20 +415,8 @@ static void LinuxBreathOfTheWildWorkaround(VkInstance& instance, const VkInstanc int childID = fork(); if (childID == 0) // inside this if statement runs in child { - struct sigaction sa{.sa_handler = [](int unused){_exit(1);}}; - sigaction(SIGABRT, &sa, nullptr); - - freopen("/dev/null", "w", stderr); - - setenv("RADV_DEBUG", "llvm", 1); - - VkInstance instance = VK_NULL_HANDLE; - vkCreateInstance(create_info, nullptr, &instance); - // this function will abort() when LLVM is absent - uint32_t count = 0; - vkEnumeratePhysicalDevices(instance, &count, nullptr); - vkDestroyInstance(instance, nullptr); - _exit(0); + setenv("CEMU_DETECT_RADV","1", 1); + execl("/proc/self/exe", "/proc/self/exe", nullptr); } int childStatus = 0; diff --git a/src/main.cpp b/src/main.cpp index df2b57fb..adce2680 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -255,8 +255,14 @@ int main(int argc, char* argv[]) #else +int BreathOfTheWildChildProcessMain(); int main(int argc, char *argv[]) { +#if BOOST_OS_LINUX + if (getenv("CEMU_DETECT_RADV") != nullptr) + return BreathOfTheWildChildProcessMain(); +#endif + #if BOOST_OS_LINUX || BOOST_OS_BSD XInitThreads(); #endif