From 5a66639d78c65fe3847a6f27bba933a9cd2a5b8a Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sun, 14 Feb 2021 00:33:35 +1000 Subject: [PATCH] HostDisplay: Add virtual method for getting resolutions --- src/core/host_display.h | 8 ++++++++ src/duckstation-qt/displaysettingswidget.cpp | 21 ++++++++------------ src/frontend-common/d3d11_host_display.cpp | 15 +++++++++----- src/frontend-common/d3d11_host_display.h | 10 +++------- src/frontend-common/opengl_host_display.cpp | 5 +++++ src/frontend-common/opengl_host_display.h | 1 + src/frontend-common/vulkan_host_display.cpp | 18 ++++++++++++----- src/frontend-common/vulkan_host_display.h | 3 ++- 8 files changed, 50 insertions(+), 31 deletions(-) diff --git a/src/core/host_display.h b/src/core/host_display.h index 69a285317..aae82258f 100644 --- a/src/core/host_display.h +++ b/src/core/host_display.h @@ -3,6 +3,7 @@ #include "common/window_info.h" #include "types.h" #include +#include #include #include #include @@ -52,6 +53,12 @@ public: RightOrBottom }; + struct AdapterAndModeList + { + std::vector adapter_names; + std::vector fullscreen_modes; + }; + virtual ~HostDisplay(); ALWAYS_INLINE s32 GetWindowWidth() const { return static_cast(m_window_info.surface_width); } @@ -85,6 +92,7 @@ public: virtual bool SupportsFullscreen() const = 0; virtual bool IsFullscreen() = 0; virtual bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) = 0; + virtual AdapterAndModeList GetAdapterAndModeList() = 0; virtual bool CreateResources() = 0; virtual void DestroyResources() = 0; diff --git a/src/duckstation-qt/displaysettingswidget.cpp b/src/duckstation-qt/displaysettingswidget.cpp index 42367d57a..42aaead0a 100644 --- a/src/duckstation-qt/displaysettingswidget.cpp +++ b/src/duckstation-qt/displaysettingswidget.cpp @@ -171,24 +171,19 @@ void DisplaySettingsWidget::setupAdditionalUi() void DisplaySettingsWidget::populateGPUAdaptersAndResolutions() { - std::vector adapter_names; - std::vector fullscreen_modes; + HostDisplay::AdapterAndModeList aml; bool thread_supported = false; bool threaded_presentation_supported = false; switch (static_cast(m_ui.renderer->currentIndex())) { #ifdef WIN32 case GPURenderer::HardwareD3D11: - { - FrontendCommon::D3D11HostDisplay::AdapterInfo adapter_info = FrontendCommon::D3D11HostDisplay::GetAdapterInfo(); - adapter_names = std::move(adapter_info.adapter_names); - fullscreen_modes = std::move(adapter_info.fullscreen_modes); - } - break; + aml = FrontendCommon::D3D11HostDisplay::StaticGetAdapterAndModeList(); + break; #endif case GPURenderer::HardwareVulkan: - adapter_names = FrontendCommon::VulkanHostDisplay::EnumerateAdapterNames(); + aml = FrontendCommon::VulkanHostDisplay::StaticGetAdapterAndModeList(); threaded_presentation_supported = true; break; @@ -209,7 +204,7 @@ void DisplaySettingsWidget::populateGPUAdaptersAndResolutions() m_ui.adapter->addItem(tr("(Default)")); // add the other adapters - for (const std::string& adapter_name : adapter_names) + for (const std::string& adapter_name : aml.adapter_names) { m_ui.adapter->addItem(QString::fromStdString(adapter_name)); @@ -218,7 +213,7 @@ void DisplaySettingsWidget::populateGPUAdaptersAndResolutions() } // disable it if we don't have a choice - m_ui.adapter->setEnabled(!adapter_names.empty()); + m_ui.adapter->setEnabled(!aml.adapter_names.empty()); } { @@ -229,7 +224,7 @@ void DisplaySettingsWidget::populateGPUAdaptersAndResolutions() m_ui.fullscreenMode->addItem(tr("Borderless Fullscreen")); m_ui.fullscreenMode->setCurrentIndex(0); - for (const std::string& mode_name : fullscreen_modes) + for (const std::string& mode_name : aml.fullscreen_modes) { m_ui.fullscreenMode->addItem(QString::fromStdString(mode_name)); @@ -238,7 +233,7 @@ void DisplaySettingsWidget::populateGPUAdaptersAndResolutions() } // disable it if we don't have a choice - m_ui.fullscreenMode->setEnabled(!fullscreen_modes.empty()); + m_ui.fullscreenMode->setEnabled(!aml.fullscreen_modes.empty()); } m_ui.gpuThread->setEnabled(thread_supported); diff --git a/src/frontend-common/d3d11_host_display.cpp b/src/frontend-common/d3d11_host_display.cpp index 1a4aa1570..f15a8796a 100644 --- a/src/frontend-common/d3d11_host_display.cpp +++ b/src/frontend-common/d3d11_host_display.cpp @@ -256,7 +256,7 @@ bool D3D11HostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view u32 adapter_index; if (!adapter_name.empty()) { - AdapterInfo adapter_info = GetAdapterInfo(temp_dxgi_factory.Get()); + AdapterAndModeList adapter_info(GetAdapterAndModeList(temp_dxgi_factory.Get())); for (adapter_index = 0; adapter_index < static_cast(adapter_info.adapter_names.size()); adapter_index++) { if (adapter_name == adapter_info.adapter_names[adapter_index]) @@ -795,19 +795,19 @@ void D3D11HostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 he m_context->Draw(3, 0); } -D3D11HostDisplay::AdapterInfo D3D11HostDisplay::GetAdapterInfo() +HostDisplay::AdapterAndModeList D3D11HostDisplay::StaticGetAdapterAndModeList() { ComPtr dxgi_factory; HRESULT hr = CreateDXGIFactory(IID_PPV_ARGS(dxgi_factory.GetAddressOf())); if (FAILED(hr)) return {}; - return GetAdapterInfo(dxgi_factory.Get()); + return GetAdapterAndModeList(dxgi_factory.Get()); } -D3D11HostDisplay::AdapterInfo D3D11HostDisplay::GetAdapterInfo(IDXGIFactory* dxgi_factory) +HostDisplay::AdapterAndModeList D3D11HostDisplay::GetAdapterAndModeList(IDXGIFactory* dxgi_factory) { - AdapterInfo adapter_info; + AdapterAndModeList adapter_info; ComPtr current_adapter; while (SUCCEEDED(dxgi_factory->EnumAdapters(static_cast(adapter_info.adapter_names.size()), current_adapter.ReleaseAndGetAddressOf()))) @@ -873,6 +873,11 @@ D3D11HostDisplay::AdapterInfo D3D11HostDisplay::GetAdapterInfo(IDXGIFactory* dxg return adapter_info; } +HostDisplay::AdapterAndModeList D3D11HostDisplay::GetAdapterAndModeList() +{ + return GetAdapterAndModeList(m_dxgi_factory.Get()); +} + bool D3D11HostDisplay::SetPostProcessingChain(const std::string_view& config) { if (config.empty()) diff --git a/src/frontend-common/d3d11_host_display.h b/src/frontend-common/d3d11_host_display.h index 89dcffdee..5ed518430 100644 --- a/src/frontend-common/d3d11_host_display.h +++ b/src/frontend-common/d3d11_host_display.h @@ -46,6 +46,7 @@ public: virtual bool SupportsFullscreen() const override; virtual bool IsFullscreen() override; virtual bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override; + virtual AdapterAndModeList GetAdapterAndModeList() override; virtual void DestroyRenderSurface() override; virtual bool SetPostProcessingChain(const std::string_view& config) override; @@ -68,17 +69,12 @@ public: virtual bool Render() override; - struct AdapterInfo - { - std::vector adapter_names; - std::vector fullscreen_modes; - }; - static AdapterInfo GetAdapterInfo(); + static AdapterAndModeList StaticGetAdapterAndModeList(); protected: static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16; - static AdapterInfo GetAdapterInfo(IDXGIFactory* dxgi_factory); + static AdapterAndModeList GetAdapterAndModeList(IDXGIFactory* dxgi_factory); virtual bool CreateResources() override; virtual void DestroyResources() override; diff --git a/src/frontend-common/opengl_host_display.cpp b/src/frontend-common/opengl_host_display.cpp index de0bd3eaa..e74bd2763 100644 --- a/src/frontend-common/opengl_host_display.cpp +++ b/src/frontend-common/opengl_host_display.cpp @@ -510,6 +510,11 @@ bool OpenGLHostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, fl return false; } +HostDisplay::AdapterAndModeList OpenGLHostDisplay::GetAdapterAndModeList() +{ + return {}; +} + void OpenGLHostDisplay::DestroyRenderSurface() { if (!m_gl_context) diff --git a/src/frontend-common/opengl_host_display.h b/src/frontend-common/opengl_host_display.h index 10493cdde..0eef611a2 100644 --- a/src/frontend-common/opengl_host_display.h +++ b/src/frontend-common/opengl_host_display.h @@ -44,6 +44,7 @@ public: virtual bool SupportsFullscreen() const override; virtual bool IsFullscreen() override; virtual bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override; + virtual AdapterAndModeList GetAdapterAndModeList() override; virtual void DestroyRenderSurface() override; virtual bool SetPostProcessingChain(const std::string_view& config) override; diff --git a/src/frontend-common/vulkan_host_display.cpp b/src/frontend-common/vulkan_host_display.cpp index 0053a5f16..6c5e40fdd 100644 --- a/src/frontend-common/vulkan_host_display.cpp +++ b/src/frontend-common/vulkan_host_display.cpp @@ -139,6 +139,11 @@ bool VulkanHostDisplay::SetFullscreen(bool fullscreen, u32 width, u32 height, fl return false; } +HostDisplay::AdapterAndModeList VulkanHostDisplay::GetAdapterAndModeList() +{ + return StaticGetAdapterAndModeList(); +} + void VulkanHostDisplay::DestroyRenderSurface() { m_window_info = {}; @@ -747,12 +752,15 @@ void VulkanHostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 h vkCmdDraw(cmdbuffer, 3, 1, 0, 0); } -std::vector VulkanHostDisplay::EnumerateAdapterNames() +HostDisplay::AdapterAndModeList VulkanHostDisplay::StaticGetAdapterAndModeList() { - if (g_vulkan_context) - return Vulkan::Context::EnumerateGPUNames(g_vulkan_context->GetVulkanInstance()); + AdapterAndModeList ret; - if (Vulkan::LoadVulkanLibrary()) + if (g_vulkan_context) + { + ret.adapter_names = Vulkan::Context::EnumerateGPUNames(g_vulkan_context->GetVulkanInstance()); + } + else if (Vulkan::LoadVulkanLibrary()) { Common::ScopeGuard lib_guard([]() { Vulkan::UnloadVulkanLibrary(); }); @@ -762,7 +770,7 @@ std::vector VulkanHostDisplay::EnumerateAdapterNames() Common::ScopeGuard instance_guard([&instance]() { vkDestroyInstance(instance, nullptr); }); if (Vulkan::LoadVulkanInstanceFunctions(instance)) - return Vulkan::Context::EnumerateGPUNames(instance); + ret.adapter_names = Vulkan::Context::EnumerateGPUNames(instance); } } diff --git a/src/frontend-common/vulkan_host_display.h b/src/frontend-common/vulkan_host_display.h index 90bdc68ee..3d8f54234 100644 --- a/src/frontend-common/vulkan_host_display.h +++ b/src/frontend-common/vulkan_host_display.h @@ -43,6 +43,7 @@ public: virtual bool SupportsFullscreen() const override; virtual bool IsFullscreen() override; virtual bool SetFullscreen(bool fullscreen, u32 width, u32 height, float refresh_rate) override; + virtual AdapterAndModeList GetAdapterAndModeList() override; virtual void DestroyRenderSurface() override; virtual bool SetPostProcessingChain(const std::string_view& config) override; @@ -64,7 +65,7 @@ public: virtual bool Render() override; - static std::vector EnumerateAdapterNames(); + static AdapterAndModeList StaticGetAdapterAndModeList(); protected: struct PushConstants