Hash :
89e38b57
Author :
Date :
2022-06-22T15:04:08
Refactor to use ANGLETest vs ANGLETestWithParam Bug: angleproject:6747 Change-Id: I72ad52d0268eae0e1a401f12f3e94cc5efa402f2 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3719002 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Cody Northrop <cnorthrop@google.com>
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());