Hash :
9637185c
        
        Author :
  
        
        Date :
2022-03-10T15:38:13
        
      
Add ForceGPUSwitch to EGL_ANGLE_power_preference eglHandleGPUSwitch() does not work with WebKit sandbox profile. The root cause is that we do not know the primary display, and as such we do not know which GPU drives this. Add eglForceGPUSwitchANGLE(display, gpuIDHigh, gpuIDLow). This lets the caller figure out the GPU in another process. Then the caller can just set the GPU in the sandboxed process. Add tests that are disabled by default until the runner and the infrastructure supports running the tests with automatic switching enabled. Bug: angleproject:7092 Change-Id: I316ee431156596effbdb89659a5e24291719a204 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3516274 Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Reviewed-by: Kenneth Russell <kbr@chromium.org> Commit-Queue: Kenneth Russell <kbr@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
//
// Copyright 2022 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// system_info_util.h:
//   Implementation of common test utilities for operating with SystemInfo.
//
#include "system_info_util.h"
#include "common/debug.h"
#include "common/string_utils.h"
#include "gpu_info_util/SystemInfo.h"
#include "util/util_gl.h"
using namespace angle;
namespace
{
size_t findGPU(const SystemInfo &systemInfo, bool lowPower)
{
    if (systemInfo.gpus.size() < 2)
    {
        return 0;
    }
    for (size_t i = 0; i < systemInfo.gpus.size(); ++i)
    {
        if (lowPower && IsIntel(systemInfo.gpus[i].vendorId))
        {
            return i;
        }
        // Return the high power GPU, i.e any non-intel GPU
        else if (!lowPower && !IsIntel(systemInfo.gpus[i].vendorId))
        {
            return i;
        }
    }
    // Can't find GPU
    ASSERT(false);
    return 0;
}
}  // namespace
size_t FindLowPowerGPU(const SystemInfo &systemInfo)
{
    return findGPU(systemInfo, true);
}
size_t FindHighPowerGPU(const SystemInfo &systemInfo)
{
    return findGPU(systemInfo, false);
}
size_t FindActiveOpenGLGPU(const SystemInfo &systemInfo)
{
    char *renderer = (char *)glGetString(GL_RENDERER);
    std::string rendererString(renderer);
    for (size_t i = 0; i < systemInfo.gpus.size(); ++i)
    {
        std::vector<std::string> vendorTokens;
        angle::SplitStringAlongWhitespace(VendorName(systemInfo.gpus[i].vendorId), &vendorTokens);
        for (std::string &token : vendorTokens)
        {
            if (rendererString.find(token) != std::string::npos)
            {
                return i;
            }
        }
    }
    // Can't find active GPU
    ASSERT(false);
    return 0;
}