GPUDevice: Memoize preferred renderer for auto
This commit is contained in:
parent
713d396a7e
commit
b8127facdc
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue