summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorOatmealDome <OatmealDome@users.noreply.github.com>2026-04-02 23:55:16 -0400
committerGitHub <noreply@github.com>2026-04-02 23:55:16 -0400
commit5e95d5e7f56aa4b758f4e758dabf8a716a20cc85 (patch)
tree25bc1799049bc3ded7810ee6d16975d6925d7238 /Source/Core
parent0531286906ec65edf3736813517496c95bf87ada (diff)
parent26e58ea3492d0bb3004359b9a72f3a738f3c2134 (diff)
Merge pull request #14492 from OatmealDome/apple-discard-bug-fixed-3
VideoBackends/Vulkan: Drop BUG_BROKEN_DISCARD_WITH_EARLY_Z workaround
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Common/CMakeLists.txt2
-rw-r--r--Source/Core/Common/CommonFuncs.h17
-rw-r--r--Source/Core/Common/CommonFuncsObjC.mm15
-rw-r--r--Source/Core/Core/DolphinAnalytics.cpp36
-rw-r--r--Source/Core/VideoBackends/Metal/MTLUtil.mm4
-rw-r--r--Source/Core/VideoBackends/Vulkan/VulkanContext.cpp21
-rw-r--r--Source/Core/VideoCommon/DriverDetails.cpp18
-rw-r--r--Source/Core/VideoCommon/UberShaderPixel.cpp3
8 files changed, 70 insertions, 46 deletions
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 <string>
+#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<std::wstring> 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 <Foundation/Foundation.h>
+
+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 <Windows.h>
#include "Common/WindowsRegistry.h"
-#elif defined(__APPLE__)
-#include <objc/message.h>
#endif
#if defined(ANDROID)
#include <functional>
#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<id (*)(Class, SEL)>(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<OSVersion (*)(id, SEL)>(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__)
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/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,
diff --git a/Source/Core/VideoCommon/DriverDetails.cpp b/Source/Core/VideoCommon/DriverDetails.cpp
index 705bd66bab..b657d7721c 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
@@ -148,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,
@@ -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();
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.