From 36d8dbc590580bd5694b143c62350f092c4fcdb6 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Fri, 9 Jan 2026 20:15:52 -0500 Subject: [PATCH 1/5] CommonFuncsObjC: Make function to fetch the current macOS version common --- Source/Core/Common/CMakeLists.txt | 2 ++ Source/Core/Common/CommonFuncs.h | 17 +++++++++++++ Source/Core/Common/CommonFuncsObjC.mm | 15 +++++++++++ Source/Core/Core/DolphinAnalytics.cpp | 36 ++++++--------------------- 4 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 Source/Core/Common/CommonFuncsObjC.mm diff --git a/Source/Core/Common/CMakeLists.txt b/Source/Core/Common/CMakeLists.txt index e134acabd3..fe7aa9f72b 100644 --- a/Source/Core/Common/CMakeLists.txt +++ b/Source/Core/Common/CMakeLists.txt @@ -204,6 +204,7 @@ if (APPLE) PRIVATE ${APPKIT_LIBRARY} ${COREFOUNDATION_LIBRARY} + ${FOUNDATION_LIBRARY} ${IOK_LIBRARY} ) elseif(WIN32) @@ -239,6 +240,7 @@ elseif(WIN32) ) elseif(APPLE) target_sources(common PRIVATE + CommonFuncsObjC.mm Logging/ConsoleListenerNix.cpp MemArenaDarwin.cpp ) diff --git a/Source/Core/Common/CommonFuncs.h b/Source/Core/Common/CommonFuncs.h index a2c20c67e3..b9238dad1c 100644 --- a/Source/Core/Common/CommonFuncs.h +++ b/Source/Core/Common/CommonFuncs.h @@ -8,6 +8,10 @@ #endif #include +#ifdef __APPLE__ +#include "Common/CommonTypes.h" +#endif + #ifndef _WIN32 // go to debugger mode @@ -61,4 +65,17 @@ std::string GetWin32ErrorString(unsigned long error_code); // Obtains a full path to the specified module. std::optional GetModuleName(void* hInstance); #endif + +#ifdef __APPLE__ +struct MacOSVersion // NSOperatingSystemVersion +{ + s64 major; // NSInteger majorVersion + s64 minor; // NSInteger minorVersion + s64 patch; // NSInteger patchVersion +}; + +// Helper function to get the current macOS version, which is easy to do with +// from Objective-C code, but a little harder from C++. +MacOSVersion GetMacOSVersion(); +#endif } // namespace Common diff --git a/Source/Core/Common/CommonFuncsObjC.mm b/Source/Core/Common/CommonFuncsObjC.mm new file mode 100644 index 0000000000..fdc7f48ce2 --- /dev/null +++ b/Source/Core/Common/CommonFuncsObjC.mm @@ -0,0 +1,15 @@ +// Copyright 2026 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "Common/CommonFuncs.h" + +#include + +namespace Common +{ +MacOSVersion GetMacOSVersion() +{ + const NSOperatingSystemVersion ver = [[NSProcessInfo processInfo] operatingSystemVersion]; + return {ver.majorVersion, ver.minorVersion, ver.patchVersion}; +} +} // namespace Common diff --git a/Source/Core/Core/DolphinAnalytics.cpp b/Source/Core/Core/DolphinAnalytics.cpp index 8b207c658c..f4f7c01c41 100644 --- a/Source/Core/Core/DolphinAnalytics.cpp +++ b/Source/Core/Core/DolphinAnalytics.cpp @@ -15,14 +15,16 @@ #if defined(_WIN32) #include #include "Common/WindowsRegistry.h" -#elif defined(__APPLE__) -#include #endif #if defined(ANDROID) #include #endif +#if defined(__APPLE__) +#include "Common/CommonFuncs.h" +#endif + #include "Common/Analytics.h" #include "Common/CPUDetect.h" #include "Common/CommonTypes.h" @@ -300,32 +302,10 @@ void DolphinAnalytics::MakeBaseBuilder() #elif defined(__APPLE__) builder.AddData("os-type", "osx"); - // id processInfo = [NSProcessInfo processInfo] - id processInfo = reinterpret_cast(objc_msgSend)( - objc_getClass("NSProcessInfo"), sel_getUid("processInfo")); - if (processInfo) - { - struct OSVersion // NSOperatingSystemVersion - { - s64 major_version; // NSInteger majorVersion - s64 minor_version; // NSInteger minorVersion - s64 patch_version; // NSInteger patchVersion - }; - // Under arm64, we need to call objc_msgSend to receive a struct. - // On x86_64, we need to explicitly call objc_msgSend_stret for a struct. -#ifdef _M_ARM_64 -#define msgSend objc_msgSend -#else -#define msgSend objc_msgSend_stret -#endif - // NSOperatingSystemVersion version = [processInfo operatingSystemVersion] - OSVersion version = reinterpret_cast(msgSend)( - processInfo, sel_getUid("operatingSystemVersion")); -#undef msgSend - builder.AddData("osx-ver-major", version.major_version); - builder.AddData("osx-ver-minor", version.minor_version); - builder.AddData("osx-ver-bugfix", version.patch_version); - } + Common::MacOSVersion version = Common::GetMacOSVersion(); + builder.AddData("osx-ver-major", version.major); + builder.AddData("osx-ver-minor", version.minor); + builder.AddData("osx-ver-bugfix", version.patch); #elif defined(__linux__) builder.AddData("os-type", "linux"); #elif defined(__FreeBSD__) From 750c6ed705071bf70cf4b35161cdb327043fecde Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Fri, 20 Mar 2026 21:22:22 -0400 Subject: [PATCH 2/5] DriverDetails: Use macOS version as the driver version --- Source/Core/VideoBackends/Metal/MTLUtil.mm | 4 +--- Source/Core/VideoCommon/DriverDetails.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoBackends/Metal/MTLUtil.mm b/Source/Core/VideoBackends/Metal/MTLUtil.mm index ad52653ee3..719a38dca2 100644 --- a/Source/Core/VideoBackends/Metal/MTLUtil.mm +++ b/Source/Core/VideoBackends/Metal/MTLUtil.mm @@ -253,9 +253,7 @@ void Metal::Util::PopulateBackendInfoFeatures(const VideoConfig& config, Backend vendor = DriverDetails::VENDOR_INTEL; else if (name.find("Apple") != std::string::npos) vendor = DriverDetails::VENDOR_APPLE; - const NSOperatingSystemVersion cocoa_ver = [[NSProcessInfo processInfo] operatingSystemVersion]; - double version = cocoa_ver.majorVersion * 100 + cocoa_ver.minorVersion; - DriverDetails::Init(DriverDetails::API_METAL, vendor, DriverDetails::DRIVER_APPLE, version, + DriverDetails::Init(DriverDetails::API_METAL, vendor, DriverDetails::DRIVER_APPLE, 0.0, DriverDetails::Family::UNKNOWN, std::move(name)); #if TARGET_OS_OSX diff --git a/Source/Core/VideoCommon/DriverDetails.cpp b/Source/Core/VideoCommon/DriverDetails.cpp index 705bd66bab..099afeab73 100644 --- a/Source/Core/VideoCommon/DriverDetails.cpp +++ b/Source/Core/VideoCommon/DriverDetails.cpp @@ -7,6 +7,10 @@ #include "Core/DolphinAnalytics.h" +#ifdef __APPLE__ +#include "Common/CommonFuncs.h" +#endif + namespace DriverDetails { struct BugInfo @@ -198,6 +202,16 @@ void Init(API api, Vendor vendor, Driver driver, const double version, const Fam } } +#ifdef __APPLE__ + // The Metal graphics drivers are part of macOS, so we use the current macOS version as the + // driver version for Metal and Vulkan on Metal. + if (api == API_METAL || (api == API_VULKAN && driver == DRIVER_PORTABILITY)) + { + Common::MacOSVersion mac_version = Common::GetMacOSVersion(); + m_version = mac_version.major * 100 + mac_version.minor; + } +#endif + // Clear bug list, as the API may have changed m_bugs.clear(); From 98ca65377410e42c57dbed6b8eb1a7372293e735 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Fri, 9 Jan 2026 20:17:59 -0500 Subject: [PATCH 3/5] DriverDetails: Mark BUG_BROKEN_DISCARD_WITH_EARLY_Z as fixed in macOS 14.0+ --- Source/Core/VideoCommon/DriverDetails.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/DriverDetails.cpp b/Source/Core/VideoCommon/DriverDetails.cpp index 099afeab73..b657d7721c 100644 --- a/Source/Core/VideoCommon/DriverDetails.cpp +++ b/Source/Core/VideoCommon/DriverDetails.cpp @@ -152,9 +152,9 @@ constexpr BugInfo m_known_bugs[] = { {API_VULKAN, OS_ALL, VENDOR_QUALCOMM, DRIVER_QUALCOMM, Family::UNKNOWN, BUG_PRIMITIVE_RESTART, -1.0, -1.0, true}, {API_VULKAN, OS_OSX, VENDOR_APPLE, DRIVER_PORTABILITY, Family::UNKNOWN, - BUG_BROKEN_DISCARD_WITH_EARLY_Z, -1.0, -1.0, true}, + BUG_BROKEN_DISCARD_WITH_EARLY_Z, 1100, 1400, true}, {API_METAL, OS_OSX, VENDOR_APPLE, DRIVER_APPLE, Family::UNKNOWN, - BUG_BROKEN_DISCARD_WITH_EARLY_Z, -1.0, -1.0, true}, + BUG_BROKEN_DISCARD_WITH_EARLY_Z, 1100, 1400, true}, {API_VULKAN, OS_OSX, VENDOR_INTEL, DRIVER_PORTABILITY, Family::UNKNOWN, BUG_BROKEN_DYNAMIC_SAMPLER_INDEXING, -1.0, -1.0, true}, {API_METAL, OS_OSX, VENDOR_INTEL, DRIVER_APPLE, Family::UNKNOWN, From 5a94e63e4289d25964a4df3bf16f87f3c0f5ca61 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Fri, 9 Jan 2026 20:18:23 -0500 Subject: [PATCH 4/5] UberShaderPixel: Fix missing check for framebuffer fetch for BUG_BROKEN_DISCARD_WITH_EARLY_Z workaround --- Source/Core/VideoCommon/UberShaderPixel.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/Core/VideoCommon/UberShaderPixel.cpp b/Source/Core/VideoCommon/UberShaderPixel.cpp index be6571ff7f..3370f878ad 100644 --- a/Source/Core/VideoCommon/UberShaderPixel.cpp +++ b/Source/Core/VideoCommon/UberShaderPixel.cpp @@ -1005,7 +1005,8 @@ ShaderCode GenPixelShader(APIType api_type, const ShaderHostConfig& host_config, out.Write(" // Alpha Test\n"); - if (early_depth && DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DISCARD_WITH_EARLY_Z)) + if (early_depth && DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DISCARD_WITH_EARLY_Z) && + host_config.backend_shader_framebuffer_fetch) { // Instead of using discard, fetch the framebuffer's color value and use it as the output // for this fragment. From 26e58ea3492d0bb3004359b9a72f3a738f3c2134 Mon Sep 17 00:00:00 2001 From: OatmealDome Date: Fri, 9 Jan 2026 20:18:45 -0500 Subject: [PATCH 5/5] VulkanContext: Drop support for BUG_BROKEN_DISCARD_WITH_EARLY_Z workaround --- .../VideoBackends/Vulkan/VulkanContext.cpp | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index 93cd5a969b..2d302c0f38 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -10,6 +10,7 @@ #include "Common/Assert.h" #include "Common/Contains.h" #include "Common/Logging/Log.h" +#include "Common/MsgHandler.h" #include "VideoCommon/DriverDetails.h" #include "VideoCommon/VideoCommon.h" @@ -450,7 +451,6 @@ void VulkanContext::PopulateBackendInfo(BackendInfo* backend_info) backend_info->bSupportsBPTCTextures = false; // Dependent on features. backend_info->bSupportsLogicOp = false; // Dependent on features. backend_info->bSupportsLargePoints = false; // Dependent on features. - backend_info->bSupportsFramebufferFetch = false; // Dependent on OS and features. backend_info->bSupportsCoarseDerivatives = true; // Assumed support. backend_info->bSupportsTextureQueryLevels = true; // Assumed support. backend_info->bSupportsLodBiasInSampler = false; // Dependent on OS. @@ -510,17 +510,6 @@ void VulkanContext::PopulateBackendInfoFeatures(BackendInfo* backend_info, VkPhy backend_info->bSupportsLargePoints = info.largePoints && info.pointSizeRange[0] <= 1.0f && info.pointSizeRange[1] >= 16; - std::string device_name = info.deviceName; - u32 vendor_id = info.vendorID; - bool is_moltenvk = info.driverID == VK_DRIVER_ID_MOLTENVK; - - // Only Apple family GPUs support framebuffer fetch. - // We currently use a hacked MoltenVK to implement this, so don't attempt outside of MVK - if (is_moltenvk && (vendor_id == 0x106B || device_name.find("Apple") != std::string::npos)) - { - backend_info->bSupportsFramebufferFetch = true; - } - // Our usage of primitive restart appears to be broken on AMD's binary drivers. // Seems to be fine on GCN Gen 1-2, unconfirmed on GCN Gen 3, causes driver resets on GCN Gen 4. if (DriverDetails::HasBug(DriverDetails::BUG_PRIMITIVE_RESTART)) @@ -534,6 +523,14 @@ void VulkanContext::PopulateBackendInfoFeatures(BackendInfo* backend_info, VkPhy // Dynamic sampler indexing locks up Intel GPUs on MoltenVK/Metal if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DYNAMIC_SAMPLER_INDEXING)) backend_info->bSupportsDynamicSamplerIndexing = false; + + if (DriverDetails::HasBug(DriverDetails::BUG_BROKEN_DISCARD_WITH_EARLY_Z)) + { + PanicAlertFmtT( + "You are attempting to use the Vulkan backend on an unsupported operating system. " + "To prevent visual glitches and artifacts, please use the Metal backend or update " + "to macOS Sonoma 14 or newer."); + } } void VulkanContext::PopulateBackendInfoMultisampleModes(BackendInfo* backend_info,