Settings: Add GPU adapter option and hook up to D3D11/Vulkan

This commit is contained in:
Connor McLaughlin
2020-06-20 03:33:57 +10:00
parent 1b5f8db2fc
commit 77291096db
23 changed files with 150 additions and 93 deletions

View File

@ -18,10 +18,10 @@ SDLD3D11HostDisplay::~SDLD3D11HostDisplay()
SDL_DestroyWindow(m_window);
}
std::unique_ptr<HostDisplay> SDLD3D11HostDisplay::Create(SDL_Window* window, bool debug_device)
std::unique_ptr<HostDisplay> SDLD3D11HostDisplay::Create(SDL_Window* window, std::string_view adapter_name, bool debug_device)
{
std::unique_ptr<SDLD3D11HostDisplay> display = std::make_unique<SDLD3D11HostDisplay>(window);
if (!display->Initialize(debug_device))
if (!display->Initialize(adapter_name, debug_device))
return {};
return display;
@ -74,13 +74,13 @@ void SDLD3D11HostDisplay::SetVSync(bool enabled)
m_interface.SetVSync(enabled);
}
bool SDLD3D11HostDisplay::Initialize(bool debug_device)
bool SDLD3D11HostDisplay::Initialize(std::string_view adapter_name, bool debug_device)
{
std::optional<WindowInfo> wi = SDLUtil::GetWindowInfoForSDLWindow(m_window);
if (!wi.has_value())
return false;
if (!m_interface.CreateContextAndSwapChain(wi.value(), true, debug_device))
if (!m_interface.CreateContextAndSwapChain(wi.value(), adapter_name, true, debug_device))
return false;
if (!m_interface.CreateResources())

View File

@ -12,7 +12,7 @@ public:
SDLD3D11HostDisplay(SDL_Window* window);
~SDLD3D11HostDisplay();
static std::unique_ptr<HostDisplay> Create(SDL_Window* window, bool debug_device);
static std::unique_ptr<HostDisplay> Create(SDL_Window* window, std::string_view adapter_name, bool debug_device);
RenderAPI GetRenderAPI() const override;
void* GetRenderDevice() const override;
@ -35,5 +35,5 @@ private:
FrontendCommon::D3D11HostDisplay m_interface;
bool Initialize(bool debug_device);
bool Initialize(std::string_view adapter_name, bool debug_device);
};

View File

@ -129,27 +129,27 @@ void SDLHostInterface::DestroySDLWindow()
bool SDLHostInterface::CreateDisplay()
{
const bool debug_device = m_settings.gpu_use_debug_device;
const std::string shader_cache_directory(GetShaderCacheDirectory());
std::unique_ptr<HostDisplay> display;
switch (m_settings.gpu_renderer)
{
case GPURenderer::HardwareVulkan:
display = SDLVulkanHostDisplay::Create(m_window, shader_cache_directory, debug_device);
display = SDLVulkanHostDisplay::Create(m_window, m_settings.gpu_adapter, shader_cache_directory,
m_settings.gpu_use_debug_device);
break;
case GPURenderer::HardwareOpenGL:
#ifndef WIN32
default:
#endif
display = OpenGLHostDisplay::Create(m_window, debug_device);
display = OpenGLHostDisplay::Create(m_window, m_settings.gpu_use_debug_device);
break;
#ifdef WIN32
case GPURenderer::HardwareD3D11:
default:
display = SDLD3D11HostDisplay::Create(m_window, debug_device);
display = SDLD3D11HostDisplay::Create(m_window, m_settings.gpu_adapter, m_settings.gpu_use_debug_device);
break;
#endif
}

View File

@ -27,11 +27,11 @@ SDLVulkanHostDisplay::~SDLVulkanHostDisplay()
SDL_DestroyWindow(m_window);
}
std::unique_ptr<HostDisplay> SDLVulkanHostDisplay::Create(SDL_Window* window, std::string_view shader_cache_directory,
bool debug_device)
std::unique_ptr<HostDisplay> SDLVulkanHostDisplay::Create(SDL_Window* window, std::string_view adapter_name,
std::string_view shader_cache_directory, bool debug_device)
{
std::unique_ptr<SDLVulkanHostDisplay> display = std::make_unique<SDLVulkanHostDisplay>(window);
if (!display->Initialize(shader_cache_directory, debug_device))
if (!display->Initialize(adapter_name, shader_cache_directory, debug_device))
return nullptr;
return display;
@ -84,7 +84,8 @@ void SDLVulkanHostDisplay::SetVSync(bool enabled)
m_display.SetVSync(enabled);
}
bool SDLVulkanHostDisplay::Initialize(std::string_view shader_cache_directory, bool debug_device)
bool SDLVulkanHostDisplay::Initialize(std::string_view adapter_name, std::string_view shader_cache_directory,
bool debug_device)
{
std::optional<WindowInfo> wi = SDLUtil::GetWindowInfoForSDLWindow(m_window);
if (!wi.has_value())
@ -93,7 +94,7 @@ bool SDLVulkanHostDisplay::Initialize(std::string_view shader_cache_directory, b
return false;
}
if (!m_display.CreateContextAndSwapChain(wi.value(), debug_device))
if (!m_display.CreateContextAndSwapChain(wi.value(), adapter_name, debug_device))
return false;
m_display.CreateShaderCache(shader_cache_directory, debug_device);

View File

@ -10,8 +10,8 @@ public:
SDLVulkanHostDisplay(SDL_Window* window);
~SDLVulkanHostDisplay();
static std::unique_ptr<HostDisplay> Create(SDL_Window* window, std::string_view shader_cache_directory,
bool debug_device);
static std::unique_ptr<HostDisplay> Create(SDL_Window* window, std::string_view adapter_name,
std::string_view shader_cache_directory, bool debug_device);
RenderAPI GetRenderAPI() const override;
void* GetRenderDevice() const override;
@ -33,7 +33,7 @@ public:
void Render() override;
private:
bool Initialize(std::string_view shader_cache_directory, bool debug_device);
bool Initialize(std::string_view adapter_name, std::string_view shader_cache_directory, bool debug_device);
SDL_Window* m_window = nullptr;
FrontendCommon::VulkanHostDisplay m_display;