GS: Add Metal renderer to settings

This commit is contained in:
TellowKrinkle 2021-11-19 00:25:51 -06:00 committed by tellowkrinkle
parent 5ecaa9459d
commit c0628a64a6
7 changed files with 40 additions and 8 deletions

View File

@ -121,6 +121,7 @@ enum class GSRendererType : s8
OGL = 12,
SW = 13,
VK = 14,
Metal = 17,
};
enum class GSInterlaceMode : u8

View File

@ -26,6 +26,7 @@
#include "Renderers/Null/GSRendererNull.h"
#include "Renderers/Null/GSDeviceNull.h"
#include "Renderers/OpenGL/GSDeviceOGL.h"
#include "Renderers/Metal/GSMetalCPPAccessible.h"
#include "Renderers/HW/GSRendererNew.h"
#include "Renderers/HW/GSTextureReplacements.h"
#include "GSLzma.h"
@ -166,6 +167,10 @@ static HostDisplay::RenderAPI GetAPIForRenderer(GSRendererType renderer)
case GSRendererType::VK:
return HostDisplay::RenderAPI::Vulkan;
#ifdef __APPLE__
case GSRendererType::Metal:
return HostDisplay::RenderAPI::Metal;
#endif
#ifdef _WIN32
case GSRendererType::DX11:
case GSRendererType::SW:
@ -189,7 +194,11 @@ static bool DoGSOpen(GSRendererType renderer, u8* basemem)
g_gs_device = std::make_unique<GSDevice11>();
break;
#endif
#ifdef __APPLE__
case HostDisplay::RenderAPI::Metal:
g_gs_device = std::unique_ptr<GSDevice>(MakeGSDeviceMTL());
break;
#endif
case HostDisplay::RenderAPI::OpenGL:
case HostDisplay::RenderAPI::OpenGLES:
g_gs_device = std::make_unique<GSDeviceOGL>();
@ -1180,6 +1189,9 @@ void GSApp::Init()
m_gs_renderers.push_back(GSSetting(static_cast<u32>(GSRendererType::Auto), "Automatic", ""));
#ifdef _WIN32
m_gs_renderers.push_back(GSSetting(static_cast<u32>(GSRendererType::DX11), "Direct3D 11", ""));
#endif
#ifdef __APPLE__
m_gs_renderers.push_back(GSSetting(static_cast<u32>(GSRendererType::Metal), "Metal", ""));
#endif
m_gs_renderers.push_back(GSSetting(static_cast<u32>(GSRendererType::OGL), "OpenGL", ""));
#ifdef ENABLE_VULKAN

View File

@ -190,6 +190,9 @@ CRCHackLevel GSUtil::GetRecommendedCRCHackLevel(GSRendererType type)
GSRendererType GSUtil::GetPreferredRenderer()
{
#ifdef __APPLE__
return GSRendererType::Metal;
#endif
#ifdef _WIN32
if (D3D::ShouldPreferD3D())
return GSRendererType::DX11;

View File

@ -22,6 +22,7 @@
#ifdef _WIN32
#include "Frontend/D3D11HostDisplay.h"
#endif
#include "GS/Renderers/Metal/GSMetalCPPAccessible.h"
#ifdef ENABLE_VULKAN
#include "Frontend/VulkanHostDisplay.h"
@ -694,6 +695,11 @@ void Dialog::RendererChange()
case GSRendererType::VK:
list = VulkanHostDisplay::StaticGetAdapterAndModeList(nullptr);
break;
#endif
#ifdef __APPLE__
case GSRendererType::Metal:
list = GetMetalAdapterAndModeList();
break;
#endif
default:
break;
@ -774,7 +780,7 @@ void Dialog::Update()
else
{
// cross-tab dependencies yay
const bool is_hw = renderer == GSRendererType::OGL || renderer == GSRendererType::DX11 || renderer == GSRendererType::VK;
const bool is_hw = renderer == GSRendererType::OGL || renderer == GSRendererType::DX11 || renderer == GSRendererType::VK || renderer == GSRendererType::Metal;
const bool is_upscale = m_renderer_panel->m_internal_resolution->GetSelection() != 0;
m_hacks_panel->m_is_native_res = !is_hw || !is_upscale;
m_hacks_panel->m_is_hardware = is_hw;

View File

@ -143,6 +143,10 @@ std::unique_ptr<HostDisplay> HostDisplay::CreateDisplayForAPI(RenderAPI api)
case RenderAPI::D3D11:
return std::make_unique<D3D11HostDisplay>();
#endif
#ifdef __APPLE__
case HostDisplay::RenderAPI::Metal:
return std::unique_ptr<HostDisplay>(MakeMetalHostDisplay());
#endif
case RenderAPI::OpenGL:
case RenderAPI::OpenGLES:

View File

@ -271,6 +271,7 @@ const char* Pcsx2Config::GSOptions::GetRendererName(GSRendererType type)
{
case GSRendererType::Auto: return "Auto";
case GSRendererType::DX11: return "Direct3D 11";
case GSRendererType::Metal: return "Metal";
case GSRendererType::OGL: return "OpenGL";
case GSRendererType::VK: return "Vulkan";
case GSRendererType::SW: return "Software";
@ -637,7 +638,7 @@ void Pcsx2Config::GSOptions::MaskUpscalingHacks()
bool Pcsx2Config::GSOptions::UseHardwareRenderer() const
{
return (Renderer == GSRendererType::DX11 || Renderer == GSRendererType::OGL || Renderer == GSRendererType::VK);
return (Renderer == GSRendererType::DX11 || Renderer == GSRendererType::OGL || Renderer == GSRendererType::VK || Renderer == GSRendererType::Metal);
}
VsyncMode Pcsx2Config::GetEffectiveVsyncMode() const

View File

@ -129,6 +129,8 @@ Dialogs::GSDumpDialog::GSDumpDialog(wxWindow* parent)
#endif
#if defined(_WIN32)
rdoverrides.Add(Pcsx2Config::GSOptions::GetRendererName(GSRendererType::DX11));
#elif defined(__APPLE__)
rdoverrides.Add(Pcsx2Config::GSOptions::GetRendererName(GSRendererType::Metal));
#endif
m_renderer_overrides->Create(this, wxID_ANY, "Renderer overrides", wxDefaultPosition, wxDefaultSize, rdoverrides, 1);
@ -829,18 +831,21 @@ void Dialogs::GSDumpDialog::GSThread::ExecuteTaskInThread()
case 2:
renderer = GSRendererType::OGL;
break;
case 3:
#ifdef ENABLE_VULKAN
// Vulkan
case 3:
renderer = GSRendererType::VK;
break;
case 4:
#endif
#ifdef _WIN32
// D3D11
case 4: // WIN32 implies WITH_VULKAN so this is okay
renderer = GSRendererType::DX11;
break;
#elif defined(__APPLE__)
// Metal
renderer = GSRendererType::Metal;
#endif
break;
default:
break;
}