From c20daa8867b9ea4736691c05caa993a459f71446 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 5 Nov 2019 18:36:43 -0800 Subject: [PATCH] Add compatibility checks for HEVC Main10 in VT backend --- app/app.pro | 2 +- app/streaming/video/ffmpeg-renderers/vt.mm | 47 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/app/app.pro b/app/app.pro index e9e7cd2e..74412d93 100644 --- a/app/app.pro +++ b/app/app.pro @@ -114,7 +114,7 @@ win32:!winrt { } macx { LIBS += -lssl -lcrypto -lavcodec.58 -lavutil.56 -lopus -framework SDL2 -framework SDL2_ttf - LIBS += -lobjc -framework VideoToolbox -framework AVFoundation -framework CoreVideo -framework CoreGraphics -framework CoreMedia -framework AppKit + LIBS += -lobjc -framework VideoToolbox -framework AVFoundation -framework CoreVideo -framework CoreGraphics -framework CoreMedia -framework AppKit -framework Metal # For libsoundio LIBS += -framework CoreAudio -framework AudioUnit diff --git a/app/streaming/video/ffmpeg-renderers/vt.mm b/app/streaming/video/ffmpeg-renderers/vt.mm index ce7490d9..d955ecb6 100644 --- a/app/streaming/video/ffmpeg-renderers/vt.mm +++ b/app/streaming/video/ffmpeg-renderers/vt.mm @@ -14,6 +14,7 @@ #import #import #import +#import class VTRenderer : public IFFmpegRenderer { @@ -234,6 +235,52 @@ public: "No HW accelerated HEVC decode via VT"); return false; } + + // HEVC Main10 requires more extensive checks because there's no + // simple API to check for Main10 hardware decoding, and if we don't + // have it, we'll silently get software decoding with horrible performance. + if (params->videoFormat == VIDEO_FORMAT_H265_MAIN10) { + #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101400 + if (__builtin_available(macOS 10.14, *)) { + id device = MTLCreateSystemDefaultDevice(); + if (device == nullptr) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "Unable to get default Metal device"); + return false; + } + + // Exclude all GPUs earlier than macOSGPUFamily2 + // https://developer.apple.com/documentation/metal/mtlfeatureset/mtlfeatureset_macos_gpufamily2_v1 + if ([device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily2_v1]) { + if ([device.name containsString:@"Intel"]) { + // 500-series Intel GPUs are Skylake and don't support Main10 hardware decoding + if ([device.name containsString:@" 5"]) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "No HEVC Main10 support on Skylake iGPU"); + return false; + } + } + else if ([device.name containsString:@"AMD"]) { + // FirePro D, M200, and M300 series GPUs don't support Main10 hardware decoding + if ([device.name containsString:@"FirePro D"] || + [device.name containsString:@" M2"] || + [device.name containsString:@" M3"]) { + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "No HEVC Main10 support on AMD GPUs until Polaris"); + return false; + } + } + } + } + else + #endif + { + // Fail closed for HEVC Main10 if we're not on 10.14+ + SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, + "No HEVC Main10 support on < macOS 10.14"); + return false; + } + } } else #endif