This commit is contained in:
goeiecool9999 2026-04-07 12:17:20 +02:00 committed by GitHub
commit eb939921ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 112 additions and 29 deletions

View File

@ -336,6 +336,109 @@ void VulkanRenderer::GetDeviceFeatures()
cemuLog_log(LogType::Force, fmt::format("VulkanLimits: UBAlignment {0} nonCoherentAtomSize {1}", prop2.properties.limits.minUniformBufferOffsetAlignment, prop2.properties.limits.nonCoherentAtomSize));
}
#if BOOST_OS_LINUX
#include <sys/wait.h>
static void LinuxBreathOfTheWildWorkaround(VkInstance& instance, const VkInstanceCreateInfo* create_info)
{
// if the user specified either shader backend, do nothing.
// should parse the flag list but there are currently no other flags containing llvm or aco as a substring
std::string_view debugEnv = getenv("RADV_DEBUG");
if (debugEnv.find("aco") != std::string_view::npos || debugEnv.find("llvm") != std::string_view::npos)
return;
uint32_t count = 0;
vkEnumeratePhysicalDevices(instance, &count, nullptr);
std::vector<VkPhysicalDevice> physicalDevices{count};
vkEnumeratePhysicalDevices(instance, &count, physicalDevices.data());
// Find the first AMD device using a RADV driver and store its version
int version = 0;
for (auto& i : physicalDevices)
{
VkPhysicalDeviceDriverProperties driverProps{};
driverProps.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
VkPhysicalDeviceProperties2 prop{};
prop.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
prop.pNext = &driverProps;
vkGetPhysicalDeviceProperties2(i, &prop);
if (prop.properties.vendorID != 0x1002 || driverProps.driverID != VK_DRIVER_ID_MESA_RADV)
continue;
version = prop.properties.driverVersion;
break;
}
if (version == 0)
return;
int major = VK_API_VERSION_MAJOR(version);
int minor = VK_API_VERSION_MINOR(version);
int patch = VK_API_VERSION_PATCH(version);
// If the driver is unaffected skip the workaround.
// affected drivers:
// 25.3.0 - 26.0.4
if ((major <= 25 && minor < 3) || (major == 26 && (minor > 0 || patch >= 5)) || major > 26)
return;
// check if running with LLVM would crash because mesa is LLVM-less.
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);
}
int childStatus = 0;
waitpid(childID, &childStatus, 0);
if (WEXITSTATUS(childStatus) == 1)
cemuLog_log(LogType::Force, "BOTW/RADV workaround not applied because mesa was built without LLVM");
// only continue if the process exits with code zero, which means it didn't crash
if (WEXITSTATUS(childStatus) != 0)
return;
cemuLog_log(LogType::Force, "BOTW/RADV workaround active. Adding \"llvm\" to RADV_DEBUG environment variable");
if (debugEnv.empty())
{
setenv("RADV_DEBUG", "llvm", 1);
}
else
{
std::string appendedDebugEnv{debugEnv};
appendedDebugEnv.append(",llvm");
setenv("RADV_DEBUG", appendedDebugEnv.c_str(), 1);
}
// recreate the vulkan instance to update debug setting
vkDestroyInstance(instance, nullptr);
VkResult err = vkCreateInstance(create_info, nullptr, &instance);
// re-check for errors just in case.
if (err != VK_SUCCESS)
throw std::runtime_error(fmt::format("Unable to re-create a Vulkan instance after RADV/LLVM workaround: {}", err));
InitializeInstanceVulkan(instance);
}
#endif
VulkanRenderer::VulkanRenderer()
{
glslang::InitializeProcess();
@ -395,6 +498,15 @@ VulkanRenderer::VulkanRenderer()
if (!InitializeInstanceVulkan(m_instance))
throw std::runtime_error("Unable to load instanced Vulkan functions");
// Workaround for BOTW + RADV. Runes like Magnesis and the camera cause GPU crashes.
#if BOOST_OS_LINUX
uint64 currentTitleId = CafeSystem::GetForegroundTitleId();
if (currentTitleId == 0x00050000101c9500 || currentTitleId == 0x00050000101c9400 || currentTitleId == 0x00050000101c9300)
{
LinuxBreathOfTheWildWorkaround(m_instance, &create_info);
}
#endif
uint32_t device_count = 0;
vkEnumeratePhysicalDevices(m_instance, &device_count, nullptr);
if (device_count == 0)

View File

@ -621,35 +621,6 @@ bool MainWindow::FileLoad(const fs::path launchPath, wxLaunchGameEvent::INITIATE
cemuLog_log(LogType::Force, "GameMode has been started.");
}
}
#endif
// Workaround for BOTW + Mesa. Runes like Magnesis and the camera cause GPU crashes.
// Using the LLVM shader compiler prevents crashes which points to an issue with the default ACO compiler.
// Either that or Cemu is violating a specification (GLSL?) causing the shaders to be broken after compilation.
#if BOOST_OS_LINUX
uint64 currentTitleId = CafeSystem::GetForegroundTitleId();
if (currentTitleId == 0x00050000101c9500 || currentTitleId == 0x00050000101c9400 || currentTitleId == 0x00050000101c9300)
{
// if the variable is empty set it to llvm, otherwise check if it contains llvm/aco and if not append it
if (const char* value; (value = getenv("RADV_DEBUG")) != NULL && strlen(value) != 0)
{
std::string valueStr{value};
// only append ,llvm when llvm or aco are not already passed as flags.
// "aco" is not a mesa flag (anymore, it used to be when llvm was default)
// but it will provide users with a way to override this workaround by setting RADV_DEBUG=aco
// should parse the flag list but there are currently no other flags containing llvm or aco as a substring
if (valueStr.find("llvm") == std::string::npos && valueStr.find("aco") == std::string::npos)
{
valueStr.append(",llvm");
setenv("RADV_DEBUG", valueStr.c_str(), 1);
}
}
else
{
setenv("RADV_DEBUG", "llvm", 1);
}
}
#endif
CreateCanvas();