{"id":16614,"date":"2016-12-13T19:42:22","date_gmt":"2016-12-14T00:42:22","guid":{"rendered":"http:\/\/mjtsai.com\/blog\/?p=16614"},"modified":"2016-12-13T20:09:06","modified_gmt":"2016-12-14T01:09:06","slug":"the-discrete-gpu-and-you","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2016\/12\/13\/the-discrete-gpu-and-you\/","title":{"rendered":"The Discrete GPU and You"},"content":{"rendered":"<p><a href=\"http:\/\/supermegaultragroovy.com\/\/2016\/12\/10\/auto-graphics-switching\/\">Chris Liscio<\/a>:<\/p>\n<blockquote cite=\"http:\/\/supermegaultragroovy.com\/\/2016\/12\/10\/auto-graphics-switching\/\"><p>The combination of a dGPU and lower-capacity battery means that the practical battery life of these machines gets cut in half (or worse) when the dGPU is active. I&rsquo;m not sure that previous models had nearly as bad a &ldquo;battery life delta&rdquo; as these ones, but boy-howdy is it noticeable in practice on this system.<\/p><p>[&#8230;]<\/p><p>This whole problem can be very easy to solve. You just have to set <code>NSSupportsAutomaticGraphicsSwitching<\/code> key to <code>YES<\/code> in your application&rsquo;s Info.plist. The trouble is that an OpenGL context is being created, which defaults to switching the dGPU on. Enabling this flag in the plist will very likely fix the problem on its own, as the frameworks should Do the Right Thing (more details below) if they need access to OpenGL.<\/p><p>[&#8230;]<\/p><p>To solve the bug I had, it turned out that I was making a call to <code>-[NSOpenGLContext clearDrawable]<\/code> in the <code>dealloc<\/code> method of my custom <code>NSOpenGLView<\/code>. My <code>NSOpenGLContext<\/code> was already destructed, and a whole new <code>NSOpenGLPixelFormat<\/code> was getting created and kicked the GPU on again. The call I should have used instead was <code>-[NSOpenGLView clearGLContext]<\/code> (though I don&rsquo;t even know if that&rsquo;s really <em>required<\/em>, to be honest.<\/p><\/blockquote>\n<p>Previously: <a href=\"http:\/\/mjtsai.com\/blog\/2016\/12\/13\/macos-10-12-2-removes-battery-time-remaining-estimate\/\">macOS 10.12.2 Removes Battery Time Remaining Estimate<\/a>, <a href=\"http:\/\/mjtsai.com\/blog\/2012\/07\/07\/gfxcardstatus\/\">gfxCardStatus<\/a>.<\/p>\n<p>Update (2016-12-13): <a href=\"https:\/\/twitter.com\/McCloudStrife\/status\/808840280950476801\">McCloud<\/a>:<\/p>\n<blockquote cite=\"https:\/\/twitter.com\/McCloudStrife\/status\/808840280950476801\"><p>you can explicitly ask CoreGL not to turn on the discrete GPU<\/p><\/blockquote>\n<blockquote cite=\"https:\/\/twitter.com\/McCloudStrife\/status\/808840411460423681\"><p>You need to create your context with kCGLPFASupportsAutomaticGraphicsSwitching - won&rsquo;t trigger discrete transition.<\/p><\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Chris Liscio: The combination of a dGPU and lower-capacity battery means that the practical battery life of these machines gets cut in half (or worse) when the dGPU is active. I&rsquo;m not sure that previous models had nearly as bad a &ldquo;battery life delta&rdquo; as these ones, but boy-howdy is it noticeable in practice on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[28,131,69,30,100,1381,440,71],"class_list":["post-16614","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-batterylife","tag-bug","tag-cocoa","tag-mac","tag-macbookpro","tag-macos-10-12","tag-opengl","tag-programming"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16614","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=16614"}],"version-history":[{"count":2,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16614\/revisions"}],"predecessor-version":[{"id":16616,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/16614\/revisions\/16616"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=16614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=16614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=16614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}