Try creating the D3D12 device again if redirection to Vulkan fails. (#1504)
Some checks failed
validate-internal / build (push) Failing after 7s

This commit is contained in:
Skyth (Asilkan) 2025-04-03 16:02:30 +03:00 committed by GitHub
parent 8370312454
commit 21be4e17fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1679,10 +1679,16 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
std::vector<RenderInterfaceFunction *> interfaceFunctions;
#ifdef UNLEASHED_RECOMP_D3D12
bool allowVulkanRedirection = true;
if (graphicsApiRetry)
{
// If we are attempting to create again after a reboot due to a crash, swap the order.
g_vulkan = !g_vulkan;
// Don't allow redirection to Vulkan if we are retrying after a crash,
// so the user can at least boot the game with D3D12 if Vulkan fails to work.
allowVulkanRedirection = false;
}
interfaceFunctions.push_back(g_vulkan ? CreateVulkanInterfaceWrapper : CreateD3D12Interface);
@ -1691,8 +1697,10 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
interfaceFunctions.push_back(CreateVulkanInterfaceWrapper);
#endif
for (RenderInterfaceFunction *interfaceFunction : interfaceFunctions)
for (size_t i = 0; i < interfaceFunctions.size(); i++)
{
RenderInterfaceFunction* interfaceFunction = interfaceFunctions[i];
#ifdef UNLEASHED_RECOMP_D3D12
// Wrap the device creation in __try/__except to survive from driver crashes.
__try
@ -1711,6 +1719,8 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
#ifdef UNLEASHED_RECOMP_D3D12
if (interfaceFunction == CreateD3D12Interface)
{
if (allowVulkanRedirection)
{
bool redirectToVulkan = false;
@ -1731,14 +1741,22 @@ bool Video::CreateHostDevice(const char *sdlVideoDriver, bool graphicsApiRetry)
redirectToVulkan = true;
}
// Allow redirection to Vulkan only if we are not retrying after a crash,
// so the user can at least boot the game with D3D12 if Vulkan fails to work.
if (!graphicsApiRetry && redirectToVulkan)
if (redirectToVulkan)
{
g_device.reset();
g_interface.reset();
// In case Vulkan fails to initialize, we will try D3D12 again afterwards,
// just to get the game to boot. This only really happens in very old Intel GPU drivers.
if (!g_vulkan)
{
interfaceFunctions.push_back(CreateD3D12Interface);
allowVulkanRedirection = false;
}
continue;
}
}
// Hardware resolve seems to be completely bugged on Intel D3D12 drivers.
g_hardwareResolve = (deviceDescription.vendor != RenderDeviceVendor::INTEL);