summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Notes <me@axn.io>2017-07-27 14:37:58 +0200
committerAkemi <der.richter@gmx.de>2017-07-31 20:23:58 +0200
commitbda32d99d79bb059f5ddef3c47991c1e461e0f4e (patch)
tree80246a060e21d7a9964d4d9c53c50416f8a7022d
parent80758eda17ed565ff158a682f0735f167aa2c275 (diff)
downloadmpv-bda32d99d79bb059f5ddef3c47991c1e461e0f4e.tar.bz2
mpv-bda32d99d79bb059f5ddef3c47991c1e461e0f4e.tar.xz
cocoa: fix the support of multiple renderers (GPU switch)
So far, switching between integrated and discrete GPU would cause the kernel to kill mpv due to an indecipherable buffer error. The technical note TN2229 from Apple recommends to enable OpenGL Offline Renderers for every Mac with more GPUs than displays to handle the switch between GPU. By ordering the array from the least commonly rejected to the most, we can sequentially remove PixelFormat attributes to fit the host. Fixes #2371
-rw-r--r--video/out/opengl/context_cocoa.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/video/out/opengl/context_cocoa.c b/video/out/opengl/context_cocoa.c
index c61f9e282d..1d9a10cf38 100644
--- a/video/out/opengl/context_cocoa.c
+++ b/video/out/opengl/context_cocoa.c
@@ -67,22 +67,31 @@ static CGLError test_gl_version(struct MPGLContext *ctx, CGLOpenGLProfile ver)
struct priv *p = ctx->priv;
CGLPixelFormatAttribute attrs[] = {
+ // let this array ordered by the inverse order of the most probably
+ // rejected attribute to preserve the fallback code
kCGLPFAOpenGLProfile,
(CGLPixelFormatAttribute) ver,
kCGLPFAAccelerated,
- // leave this as the last entry of the array to not break the fallback
- // code
+ kCGLPFAAllowOfflineRenderers,
+ // keep this one last to apply the cocoa-force-dedicated-gpu option
kCGLPFASupportsAutomaticGraphicsSwitching,
0
};
GLint npix;
CGLError err;
+ int supported_attribute = MP_ARRAY_SIZE(attrs)-1;
+
+ if (p->opts->cocoa_force_dedicated_gpu)
+ attrs[--supported_attribute] = 0;
+
err = CGLChoosePixelFormat(attrs, &p->pix, &npix);
- if (p->opts->cocoa_force_dedicated_gpu || err == kCGLBadAttribute) {
- // kCGLPFASupportsAutomaticGraphicsSwitching is probably not supported
- // by the current hardware. Falling back to not using it.
- attrs[MP_ARRAY_SIZE(attrs) - 2] = 0;
+ while (err == kCGLBadAttribute && supported_attribute > 3) {
+ // kCGLPFASupportsAutomaticGraphicsSwitching is probably not
+ // supported by the current hardware. Falling back to not using
+ // it and disallowing Offline Renderers if further restrictions
+ // apply
+ attrs[--supported_attribute] = 0;
err = CGLChoosePixelFormat(attrs, &p->pix, &npix);
}