From 50d3ad58df017703f90db3bfe70a771172a72ded Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sat, 23 Jul 2022 04:27:28 -0400 Subject: [PATCH 1/6] CMakeLists: Link videometal with Foundation --- Source/Core/VideoBackends/Metal/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/VideoBackends/Metal/CMakeLists.txt b/Source/Core/VideoBackends/Metal/CMakeLists.txt index 744cb2f755..698ed2678b 100644 --- a/Source/Core/VideoBackends/Metal/CMakeLists.txt +++ b/Source/Core/VideoBackends/Metal/CMakeLists.txt @@ -35,6 +35,7 @@ PUBLIC videocommon PRIVATE spirv_cross + ${FOUNDATION_LIBRARY} ${METAL_LIBRARY} ${QUARTZCORE_LIBRARY} ) From 7edd3aff7547db157a984dd890527ea5e526cecf Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sat, 23 Jul 2022 04:28:50 -0400 Subject: [PATCH 2/6] MTLUtil: Don't attempt to get all GPUs on non-macOS platforms --- Source/Core/VideoBackends/Metal/MTLUtil.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Core/VideoBackends/Metal/MTLUtil.mm b/Source/Core/VideoBackends/Metal/MTLUtil.mm index 50916a38e3..b6e2babbbd 100644 --- a/Source/Core/VideoBackends/Metal/MTLUtil.mm +++ b/Source/Core/VideoBackends/Metal/MTLUtil.mm @@ -22,12 +22,15 @@ std::vector>> Metal::Util::GetAdapterList() if (default_dev) list.push_back(MRCTransfer(default_dev)); +#if TARGET_OS_OSX auto devices = MRCTransfer(MTLCopyAllDevices()); for (id device in devices.Get()) { if (device != default_dev) list.push_back(MRCRetain(device)); } +#endif + return list; } From 8ad7fa0313ab43cc827f052451e0945203a76d90 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sat, 23 Jul 2022 04:29:19 -0400 Subject: [PATCH 3/6] MTLUtil: Return invalid for non-supported texture formats on non-macOS platforms --- Source/Core/VideoBackends/Metal/MTLUtil.mm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoBackends/Metal/MTLUtil.mm b/Source/Core/VideoBackends/Metal/MTLUtil.mm index b6e2babbbd..1ef4a4d85f 100644 --- a/Source/Core/VideoBackends/Metal/MTLUtil.mm +++ b/Source/Core/VideoBackends/Metal/MTLUtil.mm @@ -241,13 +241,17 @@ AbstractTextureFormat Metal::Util::ToAbstract(MTLPixelFormat format) { case MTLPixelFormatRGBA8Unorm: return AbstractTextureFormat::RGBA8; case MTLPixelFormatBGRA8Unorm: return AbstractTextureFormat::BGRA8; +#if TARGET_OS_OSX case MTLPixelFormatBC1_RGBA: return AbstractTextureFormat::DXT1; case MTLPixelFormatBC2_RGBA: return AbstractTextureFormat::DXT3; case MTLPixelFormatBC3_RGBA: return AbstractTextureFormat::DXT5; case MTLPixelFormatBC7_RGBAUnorm: return AbstractTextureFormat::BPTC; +#endif case MTLPixelFormatR16Unorm: return AbstractTextureFormat::R16; case MTLPixelFormatDepth16Unorm: return AbstractTextureFormat::D16; +#if TARGET_OS_OSX case MTLPixelFormatDepth24Unorm_Stencil8: return AbstractTextureFormat::D24_S8; +#endif case MTLPixelFormatR32Float: return AbstractTextureFormat::R32F; case MTLPixelFormatDepth32Float: return AbstractTextureFormat::D32F; case MTLPixelFormatDepth32Float_Stencil8: return AbstractTextureFormat::D32F_S8; @@ -261,17 +265,21 @@ MTLPixelFormat Metal::Util::FromAbstract(AbstractTextureFormat format) { case AbstractTextureFormat::RGBA8: return MTLPixelFormatRGBA8Unorm; case AbstractTextureFormat::BGRA8: return MTLPixelFormatBGRA8Unorm; +#if TARGET_OS_OSX case AbstractTextureFormat::DXT1: return MTLPixelFormatBC1_RGBA; case AbstractTextureFormat::DXT3: return MTLPixelFormatBC2_RGBA; case AbstractTextureFormat::DXT5: return MTLPixelFormatBC3_RGBA; case AbstractTextureFormat::BPTC: return MTLPixelFormatBC7_RGBAUnorm; +#endif case AbstractTextureFormat::R16: return MTLPixelFormatR16Unorm; case AbstractTextureFormat::D16: return MTLPixelFormatDepth16Unorm; +#if TARGET_OS_OSX case AbstractTextureFormat::D24_S8: return MTLPixelFormatDepth24Unorm_Stencil8; +#endif case AbstractTextureFormat::R32F: return MTLPixelFormatR32Float; case AbstractTextureFormat::D32F: return MTLPixelFormatDepth32Float; case AbstractTextureFormat::D32F_S8: return MTLPixelFormatDepth32Float_Stencil8; - case AbstractTextureFormat::Undefined: return MTLPixelFormatInvalid; + default: return MTLPixelFormatInvalid; } } From b32b27ae9a4ab7e76a4ba9c5073d3c33c7b5b1a4 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sat, 23 Jul 2022 04:30:48 -0400 Subject: [PATCH 4/6] MTLMain: Only compile NSView manipulation code on macOS --- Source/Core/VideoBackends/Metal/MTLMain.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/Core/VideoBackends/Metal/MTLMain.mm b/Source/Core/VideoBackends/Metal/MTLMain.mm index f294f297f2..18e800e547 100644 --- a/Source/Core/VideoBackends/Metal/MTLMain.mm +++ b/Source/Core/VideoBackends/Metal/MTLMain.mm @@ -3,7 +3,10 @@ #include "VideoBackends/Metal/VideoBackend.h" +#if TARGET_OS_OSX #include +#endif + #include #include @@ -156,6 +159,7 @@ void Metal::VideoBackend::InitBackendInfo() void Metal::VideoBackend::PrepareWindow(WindowSystemInfo& wsi) { +#if TARGET_OS_OSX if (wsi.type != WindowSystemType::MacOS) return; NSView* view = static_cast(wsi.render_surface); @@ -163,4 +167,5 @@ void Metal::VideoBackend::PrepareWindow(WindowSystemInfo& wsi) [view setWantsLayer:YES]; [view setLayer:layer]; wsi.render_surface = layer; +#endif } From 77f44f1600e0ff42795ed4998ec07dd870efc250 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sat, 23 Jul 2022 14:22:44 -0400 Subject: [PATCH 5/6] MTLMain: Include TargetConditionals --- Source/Core/VideoBackends/Metal/MTLMain.mm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Core/VideoBackends/Metal/MTLMain.mm b/Source/Core/VideoBackends/Metal/MTLMain.mm index 18e800e547..15cce280b0 100644 --- a/Source/Core/VideoBackends/Metal/MTLMain.mm +++ b/Source/Core/VideoBackends/Metal/MTLMain.mm @@ -3,6 +3,9 @@ #include "VideoBackends/Metal/VideoBackend.h" +// This must be included before we use any TARGET_OS_* macros. +#include + #if TARGET_OS_OSX #include #endif From 700162b8bdeb36ab66363aabab8a0e50e5542fca Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Sat, 23 Jul 2022 14:27:04 -0400 Subject: [PATCH 6/6] MTLUtil: Include TargetConditionals --- Source/Core/VideoBackends/Metal/MTLUtil.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/Core/VideoBackends/Metal/MTLUtil.mm b/Source/Core/VideoBackends/Metal/MTLUtil.mm index 1ef4a4d85f..14c83b5c17 100644 --- a/Source/Core/VideoBackends/Metal/MTLUtil.mm +++ b/Source/Core/VideoBackends/Metal/MTLUtil.mm @@ -6,6 +6,7 @@ #include #include +#include #include #include "Common/MsgHandler.h"