⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 211028 in webkit


Ignore:
Timestamp:
Jan 22, 2017, 10:51:09 AM (10 years ago)
Author:
dino@apple.com
Message:

[WebGL] Do not allow GPU muxing on some old Mac hardware
https://bugs.webkit.org/show_bug.cgi?id=167259
<rdar://problem/30060378>

Reviewed by Simon Fraser and Darin Adler.

Some old Macbook Pro models should never use the
integrated GPU for WebGL, because they are unstable
when swapping between that and the discrete GPU.

Unfortunately this hardware configuration isn't in our
testing infrastructure, so it was confirmed manually.
Meanwhile, our existing tests make sure this patch
doesn't break anything elsewhere.

  • platform/graphics/mac/GraphicsContext3DMac.mm:

(WebCore::attachToAppleGraphicsControl): Helper function
to get a mach port that talks to Apple's Graphics Control
system.
(WebCore::hasMuxCapability): Decides whether a system
can do live GPU switching, based on whether or not it
has a muxable GPU, and if that GPU is not the old hardware
we know is problematic.
(WebCore::hasMuxableGPU): Helper to return the static hasMuxCapability value.
(WebCore::setPixelFormat): Only request the integrated card when the
GPU is muxable.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r211027 r211028  
     12017-01-20  Dean Jackson  <dino@apple.com>
     2
     3        [WebGL] Do not allow GPU muxing on some old Mac hardware
     4        https://bugs.webkit.org/show_bug.cgi?id=167259
     5        <rdar://problem/30060378>
     6
     7        Reviewed by Simon Fraser and Darin Adler.
     8
     9        Some old Macbook Pro models should never use the
     10        integrated GPU for WebGL, because they are unstable
     11        when swapping between that and the discrete GPU.
     12
     13        Unfortunately this hardware configuration isn't in our
     14        testing infrastructure, so it was confirmed manually.
     15        Meanwhile, our existing tests make sure this patch
     16        doesn't break anything elsewhere.
     17
     18        * platform/graphics/mac/GraphicsContext3DMac.mm:
     19        (WebCore::attachToAppleGraphicsControl): Helper function
     20        to get a mach port that talks to Apple's Graphics Control
     21        system.
     22        (WebCore::hasMuxCapability): Decides whether a system
     23        can do live GPU switching, based on whether or not it
     24        has a muxable GPU, and if that GPU is not the old hardware
     25        we know is problematic.
     26        (WebCore::hasMuxableGPU): Helper to return the static hasMuxCapability value.
     27        (WebCore::setPixelFormat): Only request the integrated card when the
     28        GPU is muxable.
     29
    1302017-01-22  Don Olmstead <don.olmstead@am.sony.com> and Myles C. Maxfield <mmaxfield@apple.com>
    231
  • trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm

    r209549 r211028  
    4242#include "ImageBuffer.h"
    4343#include "Logging.h"
     44#include "WebGLLayer.h"
     45#include "WebGLObject.h"
     46#include "WebGLRenderingContextBase.h"
     47#include <sys/sysctl.h>
     48#include <sysexits.h>
     49#include <wtf/text/CString.h>
     50
    4451#if PLATFORM(IOS)
    4552#import "OpenGLESSPI.h"
     
    4956#import <QuartzCore/QuartzCore.h>
    5057#else
     58#include <IOKit/IOKitLib.h>
    5159#include <OpenGL/CGLRenderers.h>
    5260#include <OpenGL/gl.h>
    5361#endif
    54 #include "WebGLLayer.h"
    55 #include "WebGLObject.h"
    56 #include "WebGLRenderingContextBase.h"
    57 #include <sysexits.h>
    58 #include <wtf/text/CString.h>
    5962
    6063namespace WebCore {
     
    7982};
    8083
    81 #if !PLATFORM(IOS)
     84#if PLATFORM(MAC)
     85
     86enum {
     87    kAGCOpen,
     88    kAGCClose
     89};
     90
     91static io_connect_t attachToAppleGraphicsControl()
     92{
     93    mach_port_t masterPort;
     94
     95    if (IOMasterPort(MACH_PORT_NULL, &masterPort) != KERN_SUCCESS)
     96        return MACH_PORT_NULL;
     97
     98    CFDictionaryRef classToMatch = IOServiceMatching("AppleGraphicsControl");
     99    if (!classToMatch)
     100        return MACH_PORT_NULL;
     101
     102    kern_return_t kernResult;
     103    io_iterator_t iterator;
     104    if ((kernResult = IOServiceGetMatchingServices(masterPort, classToMatch, &iterator)) != KERN_SUCCESS)
     105        return MACH_PORT_NULL;
     106
     107    io_service_t serviceObject = IOIteratorNext(iterator);
     108    IOObjectRelease(iterator);
     109    if (!serviceObject)
     110        return MACH_PORT_NULL;
     111
     112    io_connect_t dataPort;
     113    IOObjectRetain(serviceObject);
     114    kernResult = IOServiceOpen(serviceObject, mach_task_self(), 0, &dataPort);
     115    IOObjectRelease(serviceObject);
     116
     117    return (kernResult == KERN_SUCCESS) ? dataPort : MACH_PORT_NULL;
     118}
     119
     120static bool hasMuxCapability()
     121{
     122    io_connect_t dataPort = attachToAppleGraphicsControl();
     123
     124    if (dataPort == MACH_PORT_NULL)
     125        return false;
     126
     127    bool result;
     128    if (IOConnectCallScalarMethod(dataPort, kAGCOpen, nullptr, 0, nullptr, nullptr) == KERN_SUCCESS) {
     129        IOConnectCallScalarMethod(dataPort, kAGCClose, nullptr, 0, nullptr, nullptr);
     130        result = true;
     131    } else
     132        result = false;
     133
     134    IOServiceClose(dataPort);
     135
     136    if (result) {
     137        // This is detecting Mac hardware with an Intel g575 GPU, which
     138        // we don't want to make available to muxing.
     139        // Based on information from Apple's OpenGL team, such devices
     140        // have four or fewer processors.
     141        // <rdar://problem/30060378>
     142        int names[2] = { CTL_HW, HW_NCPU };
     143        int cpuCount;
     144        size_t cpuCountLength = sizeof(cpuCount);
     145        sysctl(names, 2, &cpuCount, &cpuCountLength, nullptr, 0);
     146        result = cpuCount > 4;
     147    }
     148
     149    return result;
     150}
     151
     152static bool hasMuxableGPU()
     153{
     154    static bool canMux = hasMuxCapability();
     155    return canMux;
     156}
     157
    82158static void setPixelFormat(Vector<CGLPixelFormatAttribute>& attribs, int colorBits, int depthBits, bool accelerated, bool supersample, bool closest, bool antialias, bool allowOffline, bool useGLES3)
    83159{
     
    93169    // system, and not force the discrete GPU.
    94170    // See https://developer.apple.com/library/mac/technotes/tn2229/_index.html
    95     if (allowOffline)
     171    if (allowOffline && hasMuxableGPU())
    96172        attribs.append(kCGLPFAAllowOfflineRenderers);
    97173
Note: See TracChangeset for help on using the changeset viewer.