mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-04-23 08:29:09 +00:00
Default to indirect rendering on Apple Silicon
Hopefully the UMA makes the performance impact of reimporting frames negligible until we can get a proper Metal renderer to replace AVSampleBufferDisplayLayer.
This commit is contained in:
@@ -434,6 +434,58 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = av_hwdevice_ctx_create(&m_HwContext,
|
||||||
|
AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
|
0);
|
||||||
|
if (err < 0) {
|
||||||
|
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"av_hwdevice_ctx_create() failed for VT decoder: %d",
|
||||||
|
err);
|
||||||
|
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") {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Using indirect rendering due to environment variable");
|
||||||
|
m_DirectRendering = false;
|
||||||
|
}
|
||||||
|
else if (params->videoFormat & VIDEO_FORMAT_MASK_10BIT) {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Using direct rendering for 10-bit content");
|
||||||
|
m_DirectRendering = true;
|
||||||
|
}
|
||||||
|
else if (isAppleSilicon) {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Using indirect rendering for 8-bit content on Apple Silicon");
|
||||||
|
m_DirectRendering = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"Using direct rendering for 8-bit content on Intel");
|
||||||
|
m_DirectRendering = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we're using direct rendering, set up the AVSampleBufferDisplayLayer
|
||||||
|
if (m_DirectRendering) {
|
||||||
SDL_SysWMinfo info;
|
SDL_SysWMinfo info;
|
||||||
|
|
||||||
SDL_VERSION(&info.version);
|
SDL_VERSION(&info.version);
|
||||||
@@ -466,15 +518,9 @@ 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 (!(params->videoFormat & VIDEO_FORMAT_MASK_10BIT) && (SDL_GetWindowFlags(params->window) & SDL_WINDOW_FULLSCREEN_DESKTOP) != SDL_WINDOW_FULLSCREEN) {
|
if (isAppleSilicon && !(params->videoFormat & VIDEO_FORMAT_MASK_10BIT)) {
|
||||||
int err;
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
uint32_t cpuType;
|
"Using layer rasterization workaround");
|
||||||
size_t size = sizeof(cpuType);
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
err = sysctlbyname("hw.cputype", &cpuType, &size, NULL, 0);
|
|
||||||
if (err == 0 && (cpuType & ~CPU_ARCH_MASK) == CPU_TYPE_ARM) {
|
|
||||||
if (info.info.cocoa.window.screen != nullptr) {
|
if (info.info.cocoa.window.screen != nullptr) {
|
||||||
m_DisplayLayer.shouldRasterize = YES;
|
m_DisplayLayer.shouldRasterize = YES;
|
||||||
m_DisplayLayer.rasterizationScale = info.info.cocoa.window.screen.backingScaleFactor;
|
m_DisplayLayer.rasterizationScale = info.info.cocoa.window.screen.backingScaleFactor;
|
||||||
@@ -485,11 +531,6 @@ public:
|
|||||||
SDL_assert(false);
|
SDL_assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (err != 0) {
|
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"sysctlbyname(hw.cputype) failed: %d", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a layer-hosted view by setting the layer before wantsLayer
|
// Create a layer-hosted view by setting the layer before wantsLayer
|
||||||
// This avoids us having to add our AVSampleBufferDisplayLayer as a
|
// This avoids us having to add our AVSampleBufferDisplayLayer as a
|
||||||
@@ -500,23 +541,12 @@ public:
|
|||||||
|
|
||||||
[contentView addSubview: m_StreamView];
|
[contentView addSubview: m_StreamView];
|
||||||
|
|
||||||
err = av_hwdevice_ctx_create(&m_HwContext,
|
|
||||||
AV_HWDEVICE_TYPE_VIDEOTOOLBOX,
|
|
||||||
nullptr,
|
|
||||||
nullptr,
|
|
||||||
0);
|
|
||||||
if (err < 0) {
|
|
||||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
|
||||||
"av_hwdevice_ctx_create() failed for VT decoder: %d",
|
|
||||||
err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params->enableFramePacing) {
|
if (params->enableFramePacing) {
|
||||||
if (!initializeVsyncCallback(&info)) {
|
if (!initializeVsyncCallback(&info)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -600,6 +630,11 @@ public:
|
|||||||
return RENDERER_ATTRIBUTE_HDR_SUPPORT;
|
return RENDERER_ATTRIBUTE_HDR_SUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isDirectRenderingSupported() override
|
||||||
|
{
|
||||||
|
return m_DirectRendering;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AVBufferRef* m_HwContext;
|
AVBufferRef* m_HwContext;
|
||||||
AVSampleBufferDisplayLayer* m_DisplayLayer;
|
AVSampleBufferDisplayLayer* m_DisplayLayer;
|
||||||
@@ -614,6 +649,7 @@ private:
|
|||||||
CGColorSpaceRef m_ColorSpace;
|
CGColorSpaceRef m_ColorSpace;
|
||||||
SDL_mutex* m_VsyncMutex;
|
SDL_mutex* m_VsyncMutex;
|
||||||
SDL_cond* m_VsyncPassed;
|
SDL_cond* m_VsyncPassed;
|
||||||
|
bool m_DirectRendering;
|
||||||
};
|
};
|
||||||
|
|
||||||
IFFmpegRenderer* VTRendererFactory::createRenderer() {
|
IFFmpegRenderer* VTRendererFactory::createRenderer() {
|
||||||
|
|||||||
Reference in New Issue
Block a user