From fcf7ed4faad154155e3419e8fb838f0b3edaed65 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 22 Jan 2022 20:25:50 -0600 Subject: [PATCH] Only use the VT rasterization workaround on Apple silicon --- app/streaming/video/ffmpeg-renderers/vt.mm | 37 ++++++++++++++++------ 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/app/streaming/video/ffmpeg-renderers/vt.mm b/app/streaming/video/ffmpeg-renderers/vt.mm index 28314dc8..3b73d15d 100644 --- a/app/streaming/video/ffmpeg-renderers/vt.mm +++ b/app/streaming/video/ffmpeg-renderers/vt.mm @@ -10,6 +10,8 @@ #include #include +#include +#include #import #import #import @@ -350,19 +352,34 @@ public: m_DisplayLayer.videoGravity = AVLayerVideoGravityResizeAspect; m_DisplayLayer.opaque = YES; - // This workaround prevents the image from going through processing that doesn't preserve - // the colorspace information properly in some cases. HDR seems to be okay without this, - // so we'll exclude it out of caution. - // See https://github.com/moonlight-stream/moonlight-qt/issues/493 for more details. + // This workaround prevents the image from going through processing that causes some + // color artifacts in some cases. HDR seems to be okay without this, so we'll exclude + // it out of caution. The artifacts seem to be far more significant on M1 Macs and + // the workaround can cause performance regressions on Intel Macs, so only use this + // on Apple silicon. + // + // https://github.com/moonlight-stream/moonlight-qt/issues/493 + // https://github.com/moonlight-stream/moonlight-qt/issues/722 if (params->videoFormat != VIDEO_FORMAT_H265_MAIN10) { - if (info.info.cocoa.window.screen != nullptr) { - m_DisplayLayer.shouldRasterize = YES; - m_DisplayLayer.rasterizationScale = info.info.cocoa.window.screen.backingScaleFactor; + int err; + uint32_t cpuType; + size_t size = sizeof(cpuType); + + err = sysctlbyname("hw.cputype", &cpuType, &size, NULL, 0); + if (err == 0 && cpuType == CPU_TYPE_ARM) { + if (info.info.cocoa.window.screen != nullptr) { + m_DisplayLayer.shouldRasterize = YES; + m_DisplayLayer.rasterizationScale = info.info.cocoa.window.screen.backingScaleFactor; + } + else { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Unable to rasterize layer due to missing NSScreen"); + SDL_assert(false); + } } - else { + else if (err != 0) { SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, - "Unable to rasterize layer due to missing NSScreen"); - SDL_assert(false); + "sysctlbyname(hw.cputype) failed: %d", err); } }