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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
//
// 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.
//
// EGLPowerPreferenceTest.cpp:
// Checks the implementation of EGL_ANGLE_power_preference.
//
#include <gtest/gtest.h>
#include <tuple>
#include "common/debug.h"
#include "common/string_utils.h"
#include "gpu_info_util/SystemInfo.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/angle_test_platform.h"
#include "test_utils/system_info_util.h"
#include "util/OSWindow.h"
using namespace angle;
namespace
{
// TODO(anglebug.com/7093): Implement bundling of Info.plist to angle_end2end_tests
// In the mean time, change this manually to true and cp src/tests/end2end_tests/mac/Info.plist
// out/Debug/
const bool testRunnerSupportsAutomaticGraphicsSwitching = false;
} // namespace
class EGLPowerPreferenceTest : public ANGLETest
{
public:
void testSetUp() override { (void)GetSystemInfo(&mSystemInfo); }
protected:
auto getGpuIdParts(size_t gpuIndex) const
{
uint64_t deviceId = mSystemInfo.gpus[gpuIndex].systemDeviceId;
return std::make_tuple(GetSystemDeviceIdHighPart(deviceId),
GetSystemDeviceIdLowPart(deviceId));
}
EGLDisplay getDisplay() const { return getEGLWindow()->getDisplay(); }
SystemInfo mSystemInfo;
};
TEST_P(EGLPowerPreferenceTest, ForceGPUSwitch)
{
ANGLE_SKIP_TEST_IF(!testRunnerSupportsAutomaticGraphicsSwitching);
ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(getDisplay(), "EGL_ANGLE_power_preference"));
size_t lowPower = FindLowPowerGPU(mSystemInfo);
size_t highPower = FindHighPowerGPU(mSystemInfo);
size_t initialGPU = FindActiveOpenGLGPU(mSystemInfo);
ASSERT_TRUE(lowPower == initialGPU || highPower == initialGPU);
EGLint hi = 0;
EGLint lo = 0;
for (int i = 0; i < 5; ++i)
{
std::tie(hi, lo) = getGpuIdParts(lowPower);
eglForceGPUSwitchANGLE(getDisplay(), hi, lo);
EXPECT_EQ(lowPower, FindActiveOpenGLGPU(mSystemInfo));
std::tie(hi, lo) = getGpuIdParts(highPower);
eglForceGPUSwitchANGLE(getDisplay(), hi, lo);
EXPECT_EQ(highPower, FindActiveOpenGLGPU(mSystemInfo));
}
}
TEST_P(EGLPowerPreferenceTest, HandleGPUSwitchAfterForceGPUSwitch)
{
ANGLE_SKIP_TEST_IF(!testRunnerSupportsAutomaticGraphicsSwitching);
ANGLE_SKIP_TEST_IF(!IsEGLDisplayExtensionEnabled(getDisplay(), "EGL_ANGLE_power_preference"));
size_t initialGPU = FindActiveOpenGLGPU(mSystemInfo);
size_t changedGPU = FindLowPowerGPU(mSystemInfo);
if (initialGPU == changedGPU)
{
changedGPU = FindHighPowerGPU(mSystemInfo);
}
EGLint hi = 0;
EGLint lo = 0;
for (int i = 0; i < 5; ++i)
{
std::tie(hi, lo) = getGpuIdParts(changedGPU);
eglForceGPUSwitchANGLE(getDisplay(), hi, lo);
ASSERT_EQ(changedGPU, FindActiveOpenGLGPU(mSystemInfo));
eglHandleGPUSwitchANGLE(getDisplay());
ASSERT_EQ(initialGPU, FindActiveOpenGLGPU(mSystemInfo));
}
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLPowerPreferenceTest);
ANGLE_INSTANTIATE_TEST(EGLPowerPreferenceTest, ES2_OPENGL(), ES3_OPENGL());