Hash :
ba04fcfd
Author :
Date :
2022-03-11T13:58:52
Support ANGLE_PREFERRED_DEVICE on CGL Add the possibility to test both integrated and discrete GPU with ANGLE tests. Previously it was using only discrete. The binaries need the NSSupportsAutomaticGraphicsSwitching bundle property. This is needed to test ANGLE_power_preference. Changes the behavior of test apps: Previously, ./angle_end2end_tests would use discrete GPU. After, ./angle_end2end_tests or ANGLE_PREFERRED_DEVICE=intel ./angle_end2end_tests will use integrated GPU. ANGLE_PREFERRED_DEVICE=amd ./angle_end2end_tests will use discrete GPU. Bug: angleproject:7093 Change-Id: Ia64f6024e3215e69c2a1bde3ba4f67c3ca595476 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3516114 Reviewed-by: Kenneth Russell <kbr@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Yuly Novikov <ynovikov@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
//
// 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;
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(!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(!IsEGLDisplayExtensionEnabled(getDisplay(), "EGL_ANGLE_power_preference"));
size_t initialGPU = FindActiveOpenGLGPU(mSystemInfo);
size_t changedGPU = FindLowPowerGPU(mSystemInfo);
// On all platforms the extension is implemented (e.g. CGL): If we start with integrated, and
// force DGPU, we cannot eglHandleGPUSwitchANGLE() from DGPU to integrated.
// eglHandleGPUSwitchANGLE() will switch to the "default", which will be DGPU.
// If we start with DGPU and switch to integrated, we *can* eglHandleGPUSwitchANGLE() back
// to the default, DGPU.
ANGLE_SKIP_TEST_IF(initialGPU == changedGPU);
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());