From 4e762c75b0cda1b1900fc366e9d4d15868ca5096 Mon Sep 17 00:00:00 2001 From: TellowKrinkle Date: Tue, 23 Nov 2021 01:42:46 -0600 Subject: [PATCH] GS: Move adapter list stuff to module in GSUtil Will be helpful for when renderers other than DX that let you choose adapters are added --- pcsx2/GS/GS.cpp | 20 +--------- pcsx2/GS/GS.h | 6 --- pcsx2/GS/GSUtil.cpp | 23 +++++++++++ pcsx2/GS/GSUtil.h | 2 + pcsx2/GS/Window/GSwxDialog.cpp | 71 ++++++++++++++-------------------- pcsx2/GS/Window/GSwxDialog.h | 2 - 6 files changed, 57 insertions(+), 67 deletions(-) diff --git a/pcsx2/GS/GS.cpp b/pcsx2/GS/GS.cpp index d5e1c920cc..dfd6250d55 100644 --- a/pcsx2/GS/GS.cpp +++ b/pcsx2/GS/GS.cpp @@ -146,15 +146,8 @@ int _GSopen(const WindowInfo& wi, const char* title, GSRendererType renderer, in if (renderer == GSRendererType::Undefined) { renderer = static_cast(theApp.GetConfigI("Renderer")); -#ifdef _WIN32 if (renderer == GSRendererType::Default) - { - if (D3D::ShouldPreferD3D()) - renderer = GSRendererType::DX1011_HW; - else - renderer = GSRendererType::OGL_HW; - } -#endif + renderer = GSUtil::GetPreferredRenderer(); } if (threads == -1) @@ -286,23 +279,14 @@ int GSopen2(const WindowInfo& wi, u32 flags) break; #endif case GSRendererType::OGL_SW: -#ifdef _WIN32 { const auto config_renderer = static_cast(theApp.GetConfigI("Renderer")); if (current_renderer == config_renderer) - { - if (D3D::ShouldPreferD3D()) - current_renderer = GSRendererType::DX1011_HW; - else - current_renderer = GSRendererType::OGL_HW; - } + current_renderer = GSUtil::GetPreferredRenderer(); else current_renderer = config_renderer; } -#else - current_renderer = GSRendererType::OGL_HW; -#endif break; case GSRendererType::OGL_HW: current_renderer = GSRendererType::OGL_SW; diff --git a/pcsx2/GS/GS.h b/pcsx2/GS/GS.h index d7a359048b..79c880609c 100644 --- a/pcsx2/GS/GS.h +++ b/pcsx2/GS/GS.h @@ -36,13 +36,7 @@ enum class GSRendererType : int8_t OGL_HW = 12, OGL_SW = 13, -#ifdef _WIN32 Default = Undefined -#else - // Use ogl renderer as default otherwise it crash at startup - // GSRenderOGL only GSDeviceOGL (not GSDeviceNULL) - Default = OGL_HW -#endif }; // ST_WRITE is defined in libc, avoid this diff --git a/pcsx2/GS/GSUtil.cpp b/pcsx2/GS/GSUtil.cpp index 7d6d7b6bf9..9aff3850d7 100644 --- a/pcsx2/GS/GSUtil.cpp +++ b/pcsx2/GS/GSUtil.cpp @@ -23,6 +23,7 @@ #ifdef _WIN32 #include #include "svnrev.h" +#include "Renderers/DX11/D3D.h" #include #else #define SVN_REV 0 @@ -187,6 +188,28 @@ CRCHackLevel GSUtil::GetRecommendedCRCHackLevel(GSRendererType type) return type == GSRendererType::OGL_HW ? CRCHackLevel::Partial : CRCHackLevel::Full; } +GSRendererType GSUtil::GetPreferredRenderer() +{ +#ifdef _WIN32 + if (D3D::ShouldPreferD3D()) + return GSRendererType::DX1011_HW; +#endif + return GSRendererType::OGL_HW; +} + +std::vector GSUtil::GetAdapterList(GSRendererType renderer, size_t& default_adapter) +{ +#ifdef _WIN32 + if (renderer == GSRendererType::DX1011_HW) + { + default_adapter = 0; + auto factory = D3D::CreateFactory(false); + return D3D::GetAdapterList(factory.get()); + } +#endif + return {}; +} + #ifdef _WIN32 void GSmkdir(const wchar_t* dir) { diff --git a/pcsx2/GS/GSUtil.h b/pcsx2/GS/GSUtil.h index 680f669ef1..2e554c0c2c 100644 --- a/pcsx2/GS/GSUtil.h +++ b/pcsx2/GS/GSUtil.h @@ -41,6 +41,8 @@ public: static bool CheckSSE(); static CRCHackLevel GetRecommendedCRCHackLevel(GSRendererType type); + static GSRendererType GetPreferredRenderer(); + static std::vector GetAdapterList(GSRendererType renderer, size_t& default_adapter); }; #ifdef _WIN32 diff --git a/pcsx2/GS/Window/GSwxDialog.cpp b/pcsx2/GS/Window/GSwxDialog.cpp index 67885f84f2..c0d2925820 100644 --- a/pcsx2/GS/Window/GSwxDialog.cpp +++ b/pcsx2/GS/Window/GSwxDialog.cpp @@ -16,11 +16,7 @@ #include "PrecompiledHeader.h" #include "GSwxDialog.h" #include "gui/AppConfig.h" - -#ifdef _WIN32 -#include "GS/GSExtra.h" -#include "GS/Renderers/DX11/D3D.h" -#endif +#include "GS/GSUtil.h" using namespace GSSettingsDialog; @@ -616,11 +612,9 @@ Dialog::Dialog() m_renderer_select = m_ui.addComboBoxAndLabel(top_grid, "Renderer:", "Renderer", &theApp.m_gs_renderers).first; m_renderer_select->Bind(wxEVT_CHOICE, &Dialog::OnRendererChange, this); -#ifdef _WIN32 add_label(this, top_grid, "Adapter:"); m_adapter_select = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, {}); top_grid->Add(m_adapter_select, wxSizerFlags().Expand()); -#endif m_ui.addComboBoxAndLabel(top_grid, "Interlacing (F5):", "interlace", &theApp.m_gs_interlace); @@ -687,33 +681,37 @@ GSRendererType Dialog::GetSelectedRendererType() void Dialog::RendererChange() { -#ifdef _WIN32 GSRendererType renderer = GetSelectedRendererType(); + std::string current; + int current_sel = m_adapter_select->GetSelection(); + if (current_sel >= 0 && current_sel < static_cast(m_adapter_arr_string.Count())) + current = m_adapter_arr_string[current_sel].ToUTF8(); + + size_t default_adapter = 0; + std::vector adapters = GSUtil::GetAdapterList(renderer, default_adapter); + m_adapter_select->Clear(); - - if (renderer == GSRendererType::DX1011_HW) - { - auto factory = D3D::CreateFactory(false); - auto adapter_list = D3D::GetAdapterList(factory.get()); - - wxArrayString adapter_arr_string; - for (const auto name : adapter_list) - { - adapter_arr_string.push_back( - convert_utf8_to_utf16(name) - ); - } - - m_adapter_select->Insert(adapter_arr_string, 0); - m_adapter_select->Enable(); - m_adapter_select->SetSelection( - theApp.GetConfigI("adapter_index") - ); - } - else + if (adapters.empty()) { m_adapter_select->Disable(); } + else + { + m_adapter_arr_string.Clear(); + int new_sel = theApp.GetConfigI("adapter_index"); + if (new_sel < 0 || new_sel >= static_cast(adapters.size())) + new_sel = default_adapter; + for (std::string& adapter : adapters) + { + if (adapter == current) + new_sel = m_adapter_arr_string.Count(); + m_adapter_arr_string.Add(fromUTF8(adapter)); + } + m_adapter_select->Set(m_adapter_arr_string); + m_adapter_select->SetSelection(new_sel); + m_adapter_select->Enable(); + } +#ifdef _WIN32 m_renderer_panel->UpdateBlendMode(renderer); m_renderer_panel->Layout(); // The version of wx we use on Windows is dumb and something prevents relayout from happening to notebook pages @@ -723,12 +721,10 @@ void Dialog::RendererChange() void Dialog::Load() { m_ui.Load(); -#ifdef _WIN32 GSRendererType renderer = GSRendererType(theApp.GetConfigI("Renderer")); if (renderer == GSRendererType::Undefined) - renderer = D3D::ShouldPreferD3D() ? GSRendererType::DX1011_HW : GSRendererType::OGL_HW; + renderer = GSUtil::GetPreferredRenderer(); m_renderer_select->SetSelection(get_config_index(theApp.m_gs_renderers, static_cast(renderer))); -#endif RendererChange(); @@ -743,17 +739,10 @@ void Dialog::Load() void Dialog::Save() { m_ui.Save(); -#ifdef _WIN32 // only save the adapter when it makes sense to // prevents changing the adapter, switching to another renderer and saving - if (GetSelectedRendererType() == GSRendererType::DX1011_HW) - { - const int current_adapter = - m_adapter_select->GetSelection(); - - theApp.SetConfig("adapter_index", current_adapter); - } -#endif + if (m_adapter_select->GetCount()) + theApp.SetConfig("adapter_index", m_adapter_select->GetSelection()); m_hacks_panel->Save(); m_renderer_panel->Save(); diff --git a/pcsx2/GS/Window/GSwxDialog.h b/pcsx2/GS/Window/GSwxDialog.h index ebed4fc2ba..572ed8f081 100644 --- a/pcsx2/GS/Window/GSwxDialog.h +++ b/pcsx2/GS/Window/GSwxDialog.h @@ -185,9 +185,7 @@ namespace GSSettingsDialog wxBoxSizer* m_top_box; wxChoice* m_renderer_select; -#ifdef _WIN32 wxChoice* m_adapter_select; -#endif wxChoice* m_bifilter_select; wxArrayString m_adapter_arr_string; RendererTab* m_renderer_panel;