GPUDevice: Memoize preferred renderer for auto

This commit is contained in:
Stenzek 2024-03-02 17:45:39 +10:00
parent 713d396a7e
commit b8127facdc
No known key found for this signature in database
1 changed files with 18 additions and 11 deletions

View File

@ -215,28 +215,35 @@ GPUDevice::GPUDevice()
GPUDevice::~GPUDevice() = default; GPUDevice::~GPUDevice() = default;
RenderAPI GPUDevice::GetPreferredAPI() RenderAPI GPUDevice::GetPreferredAPI()
{
static RenderAPI preferred_renderer = RenderAPI::None;
if (preferred_renderer == RenderAPI::None) [[unlikely]]
{ {
#if defined(_WIN32) && !defined(_M_ARM64) #if defined(_WIN32) && !defined(_M_ARM64)
// Perfer DX11 on Windows, except ARM64, where QCom has slow DX11 drivers. // Perfer DX11 on Windows, except ARM64, where QCom has slow DX11 drivers.
return RenderAPI::D3D11; preferred_renderer = RenderAPI::D3D11;
#elif defined(_WIN32) && defined(_M_ARM64) #elif defined(_WIN32) && defined(_M_ARM64)
return RenderAPI::D3D12; preferred_renderer = RenderAPI::D3D12;
#elif defined(__APPLE__) #elif defined(__APPLE__)
// Prefer Metal on MacOS. // Prefer Metal on MacOS.
return RenderAPI::Metal; preferred_renderer = RenderAPI::Metal;
#elif defined(ENABLE_OPENGL) && defined(ENABLE_VULKAN) #elif defined(ENABLE_OPENGL) && defined(ENABLE_VULKAN)
// On Linux, if we have both GL and Vulkan, prefer VK if the driver isn't software. // On Linux, if we have both GL and Vulkan, prefer VK if the driver isn't software.
return VulkanDevice::IsSuitableDefaultRenderer() ? RenderAPI::Vulkan : RenderAPI::OpenGL; preferred_renderer = VulkanDevice::IsSuitableDefaultRenderer() ? RenderAPI::Vulkan : RenderAPI::OpenGL;
#elif defined(ENABLE_OPENGL) #elif defined(ENABLE_OPENGL)
return RenderAPI::OpenGL; preferred_renderer = RenderAPI::OpenGL;
#elif defined(ENABLE_VULKAN) #elif defined(ENABLE_VULKAN)
return RenderAPI::Vulkan; preferred_renderer = RenderAPI::Vulkan;
#else #else
// Uhhh, what? // Uhhh, what?
return RenderAPI::None; Log_ErrorPrint("Somehow don't have any renderers available...");
preferred_renderer = RenderAPI::None;
#endif #endif
} }
return preferred_renderer;
}
const char* GPUDevice::RenderAPIToString(RenderAPI api) const char* GPUDevice::RenderAPIToString(RenderAPI api)
{ {
switch (api) switch (api)