Don't use CAMetalDisplayLink on Intel Macs

When in Direct mode, skipping a frame will cause the display to flash black on Tahoe.
This commit is contained in:
Cameron Gutman
2025-10-23 21:16:53 -05:00
parent 57db20016a
commit ccaca68570
4 changed files with 24 additions and 21 deletions
@@ -12,6 +12,8 @@ public:
void setHdrMode(bool enabled) override; void setHdrMode(bool enabled) override;
protected: protected:
bool isAppleSilicon();
bool m_HdrMetadataChanged; // Manual reset bool m_HdrMetadataChanged; // Manual reset
CFDataRef m_MasteringDisplayColorVolume; CFDataRef m_MasteringDisplayColorVolume;
CFDataRef m_ContentLightLevelInfo; CFDataRef m_ContentLightLevelInfo;
@@ -10,8 +10,6 @@
#include <streaming/session.h> #include <streaming/session.h>
#include <mach/mach_time.h> #include <mach/mach_time.h>
#include <mach/machine.h>
#include <sys/sysctl.h>
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <VideoToolbox/VideoToolbox.h> #import <VideoToolbox/VideoToolbox.h>
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
@@ -325,23 +323,6 @@ public:
return false; return false;
} }
bool isAppleSilicon = false;
{
uint32_t cpuType;
size_t size = sizeof(cpuType);
err = sysctlbyname("hw.cputype", &cpuType, &size, NULL, 0);
if (err == 0) {
// Apple Silicon Macs have CPU_ARCH_ABI64 set, so we need to mask that off.
// For some reason, 64-bit Intel Macs don't seem to have CPU_ARCH_ABI64 set.
isAppleSilicon = (cpuType & ~CPU_ARCH_MASK) == CPU_TYPE_ARM;
}
else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"sysctlbyname(hw.cputype) failed: %d", err);
}
}
if (qgetenv("VT_FORCE_INDIRECT") == "1") { if (qgetenv("VT_FORCE_INDIRECT") == "1") {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Using indirect rendering due to environment variable"); "Using indirect rendering due to environment variable");
@@ -385,7 +366,7 @@ public:
// //
// https://github.com/moonlight-stream/moonlight-qt/issues/493 // https://github.com/moonlight-stream/moonlight-qt/issues/493
// https://github.com/moonlight-stream/moonlight-qt/issues/722 // https://github.com/moonlight-stream/moonlight-qt/issues/722
if (isAppleSilicon && !(params->videoFormat & VIDEO_FORMAT_MASK_10BIT)) { if (isAppleSilicon() && !(params->videoFormat & VIDEO_FORMAT_MASK_10BIT)) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Using layer rasterization workaround"); "Using layer rasterization workaround");
if (info.info.cocoa.window.screen != nullptr) { if (info.info.cocoa.window.screen != nullptr) {
@@ -9,6 +9,9 @@
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
#import <Metal/Metal.h> #import <Metal/Metal.h>
#include <mach/machine.h>
#include <sys/sysctl.h>
VTBaseRenderer::VTBaseRenderer(IFFmpegRenderer::RendererType type) : VTBaseRenderer::VTBaseRenderer(IFFmpegRenderer::RendererType type) :
IFFmpegRenderer(type), IFFmpegRenderer(type),
m_HdrMetadataChanged(false), m_HdrMetadataChanged(false),
@@ -27,6 +30,23 @@ VTBaseRenderer::~VTBaseRenderer() {
} }
} }
bool VTBaseRenderer::isAppleSilicon() {
static uint32_t cpuType = 0;
if (cpuType == 0) {
size_t size = sizeof(cpuType);
int err = sysctlbyname("hw.cputype", &cpuType, &size, NULL, 0);
if (err != 0) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"sysctlbyname(hw.cputype) failed: %d", err);
return false;
}
}
// Apple Silicon Macs have CPU_ARCH_ABI64 set, so we need to mask that off.
// For some reason, 64-bit Intel Macs don't seem to have CPU_ARCH_ABI64 set.
return (cpuType & ~CPU_ARCH_MASK) == CPU_TYPE_ARM;
}
bool VTBaseRenderer::checkDecoderCapabilities(id<MTLDevice> device, PDECODER_PARAMETERS params) { bool VTBaseRenderer::checkDecoderCapabilities(id<MTLDevice> device, PDECODER_PARAMETERS params) {
if (params->videoFormat & VIDEO_FORMAT_MASK_H264) { if (params->videoFormat & VIDEO_FORMAT_MASK_H264) {
if (!VTIsHardwareDecodeSupported(kCMVideoCodecType_H264)) { if (!VTIsHardwareDecodeSupported(kCMVideoCodecType_H264)) {
@@ -828,7 +828,7 @@ public:
void startDisplayLink() void startDisplayLink()
{ {
if (@available(macOS 14, *)) { if (@available(macOS 14, *)) {
if (m_MetalDisplayLink != nullptr || !m_MetalLayer.displaySyncEnabled) { if (m_MetalDisplayLink != nullptr || !m_MetalLayer.displaySyncEnabled || !isAppleSilicon()) {
return; return;
} }