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
This commit is contained in:
TellowKrinkle 2021-11-23 01:42:46 -06:00 committed by tellowkrinkle
parent f471c30036
commit 4e762c75b0
6 changed files with 57 additions and 67 deletions

View File

@ -146,15 +146,8 @@ int _GSopen(const WindowInfo& wi, const char* title, GSRendererType renderer, in
if (renderer == GSRendererType::Undefined)
{
renderer = static_cast<GSRendererType>(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<GSRendererType>(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;

View File

@ -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

View File

@ -23,6 +23,7 @@
#ifdef _WIN32
#include <VersionHelpers.h>
#include "svnrev.h"
#include "Renderers/DX11/D3D.h"
#include <wil/com.h>
#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<std::string> 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)
{

View File

@ -41,6 +41,8 @@ public:
static bool CheckSSE();
static CRCHackLevel GetRecommendedCRCHackLevel(GSRendererType type);
static GSRendererType GetPreferredRenderer();
static std::vector<std::string> GetAdapterList(GSRendererType renderer, size_t& default_adapter);
};
#ifdef _WIN32

View File

@ -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<int>(m_adapter_arr_string.Count()))
current = m_adapter_arr_string[current_sel].ToUTF8();
size_t default_adapter = 0;
std::vector<std::string> 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<int>(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<int>(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();

View File

@ -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;