Hash :
453cd955
Author :
Date :
2022-01-17T13:26:39
Add EGL_ANGLE_platform_angle_display_id to D3D11 backend. Uses the same LUID parts as ANGLE_platform_angle_d3d_luid. This new extension is available on D3D11 on Windows and Metal on Mac. Bug: angleproject:6903 Change-Id: Ib695affe47e822c4dfd7f41d8a62a85e74b9b90a Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3396416 Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jonah Ryan-Davis <jonahr@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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
//
// Copyright 2021 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:
// EGL extension EGL_ANGLE_display_power_preference
//
#include <gtest/gtest.h>
#include "common/debug.h"
#include "common/string_utils.h"
#include "gpu_info_util/SystemInfo.h"
#include "test_utils/ANGLETest.h"
#include "util/OSWindow.h"
using namespace angle;
class EGLDisplayPowerPreferenceTest : public ANGLETest
{
public:
void testSetUp() override { (void)GetSystemInfo(&mSystemInfo); }
protected:
// Returns the index of the low or high power GPU in SystemInfo depending on the argument.
int findGPU(bool lowPower)
{
if (mSystemInfo.gpus.size() < 2)
{
return 0;
}
for (int i = 0; i < static_cast<int>(mSystemInfo.gpus.size()); ++i)
{
if (lowPower && IsIntel(mSystemInfo.gpus[i].vendorId))
{
return i;
}
// Return the high power GPU, i.e any non-intel GPU
else if (!lowPower && !IsIntel(mSystemInfo.gpus[i].vendorId))
{
return i;
}
}
// Can't find GPU
ASSERT(false);
return 0;
}
// Returns the index of the active GPU in SystemInfo based on the renderer string.
int findActiveGPU()
{
char *renderer = (char *)glGetString(GL_RENDERER);
std::string rendererString(renderer);
for (int i = 0; i < static_cast<int>(mSystemInfo.gpus.size()); ++i)
{
std::vector<std::string> vendorTokens;
angle::SplitStringAlongWhitespace(VendorName(mSystemInfo.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;
}
SystemInfo mSystemInfo;
};
class EGLDisplayPowerPreferenceTestNoFixture : public EGLDisplayPowerPreferenceTest
{
protected:
void terminateWindow()
{
if (mOSWindow)
{
OSWindow::Delete(&mOSWindow);
}
}
void terminateDisplay(EGLDisplay display)
{
EXPECT_EGL_TRUE(eglTerminate(display));
EXPECT_EGL_SUCCESS();
}
void terminateContext(EGLDisplay display, EGLContext context)
{
if (context != EGL_NO_CONTEXT)
{
eglDestroyContext(display, context);
ASSERT_EGL_SUCCESS();
}
}
void initializeWindow()
{
mOSWindow = OSWindow::New();
mOSWindow->initialize("EGLDisplayPowerPreferenceTestMultiDisplay", kWindowWidth,
kWindowHeight);
setWindowVisible(mOSWindow, true);
}
void initializeContextForDisplay(EGLDisplay display, EGLContext *context)
{
// Find a default config.
const EGLint configAttributes[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_RED_SIZE, EGL_DONT_CARE, EGL_GREEN_SIZE,
EGL_DONT_CARE, EGL_BLUE_SIZE, EGL_DONT_CARE, EGL_ALPHA_SIZE, EGL_DONT_CARE,
EGL_DEPTH_SIZE, EGL_DONT_CARE, EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_NONE};
EGLint configCount;
EGLConfig config;
EGLint ret = eglChooseConfig(display, configAttributes, &config, 1, &configCount);
if (!ret || configCount == 0)
{
return;
}
EGLint contextAttributes[] = {
EGL_CONTEXT_MAJOR_VERSION_KHR,
GetParam().majorVersion,
EGL_CONTEXT_MINOR_VERSION_KHR,
GetParam().minorVersion,
EGL_NONE,
};
*context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttributes);
ASSERT_TRUE(*context != EGL_NO_CONTEXT);
}
static constexpr int kWindowWidth = 16;
static constexpr int kWindowHeight = 8;
OSWindow *mOSWindow = nullptr;
};
class EGLDisplayPowerPreferenceTestMultiDisplay : public EGLDisplayPowerPreferenceTestNoFixture
{
protected:
void initializeDisplayWithPowerPreference(EGLDisplay *display, EGLAttrib powerPreference)
{
GLenum platformType = GetParam().getRenderer();
GLenum deviceType = GetParam().getDeviceType();
std::vector<EGLint> displayAttributes;
displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
displayAttributes.push_back(platformType);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
displayAttributes.push_back(EGL_DONT_CARE);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
displayAttributes.push_back(EGL_DONT_CARE);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
displayAttributes.push_back(deviceType);
displayAttributes.push_back(EGL_POWER_PREFERENCE_ANGLE);
displayAttributes.push_back(powerPreference);
displayAttributes.push_back(EGL_NONE);
*display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
displayAttributes.data());
ASSERT_TRUE(*display != EGL_NO_DISPLAY);
EGLint majorVersion, minorVersion;
ASSERT_TRUE(eglInitialize(*display, &majorVersion, &minorVersion) == EGL_TRUE);
eglBindAPI(EGL_OPENGL_ES_API);
ASSERT_EGL_SUCCESS();
}
void runReinitializeDisplay(EGLAttrib powerPreference)
{
initializeWindow();
// Initialize the display with the selected power preferenc
EGLDisplay display;
EGLContext context;
initializeDisplayWithPowerPreference(&display, powerPreference);
initializeContextForDisplay(display, &context);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
bool lowPower = (powerPreference == EGL_LOW_POWER_ANGLE);
ASSERT_EQ(findGPU(lowPower), findActiveGPU());
// Terminate the display
terminateContext(display, context);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
terminateDisplay(display);
// Change the power preference
if (powerPreference == EGL_LOW_POWER_ANGLE)
{
powerPreference = EGL_HIGH_POWER_ANGLE;
}
else
{
powerPreference = EGL_LOW_POWER_ANGLE;
}
// Reinitialize the display with a new power preference
initializeDisplayWithPowerPreference(&display, powerPreference);
initializeContextForDisplay(display, &context);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
// Expect that the power preference has changed
lowPower = (powerPreference == EGL_LOW_POWER_ANGLE);
ASSERT_EQ(findGPU(lowPower), findActiveGPU());
// Terminate the display
terminateContext(display, context);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
terminateDisplay(display);
terminateWindow();
}
void runMultiDisplay()
{
initializeWindow();
// Initialize the first display with low power
EGLDisplay display1;
EGLContext context1;
initializeDisplayWithPowerPreference(&display1, EGL_LOW_POWER_ANGLE);
initializeContextForDisplay(display1, &context1);
eglMakeCurrent(display1, EGL_NO_SURFACE, EGL_NO_SURFACE, context1);
ASSERT_EQ(findGPU(true), findActiveGPU());
// Initialize the second display with high power
EGLDisplay display2;
EGLContext context2;
initializeDisplayWithPowerPreference(&display2, EGL_HIGH_POWER_ANGLE);
initializeContextForDisplay(display2, &context2);
eglMakeCurrent(display2, EGL_NO_SURFACE, EGL_NO_SURFACE, context2);
ASSERT_EQ(findGPU(false), findActiveGPU());
// Switch back to the first display to verify
eglMakeCurrent(display1, EGL_NO_SURFACE, EGL_NO_SURFACE, context1);
ASSERT_EQ(findGPU(true), findActiveGPU());
// Terminate the displays
terminateContext(display1, context1);
eglMakeCurrent(display1, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
terminateDisplay(display1);
terminateContext(display2, context2);
eglMakeCurrent(display2, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
terminateDisplay(display2);
terminateWindow();
}
};
TEST_P(EGLDisplayPowerPreferenceTest, SelectGPU)
{
ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_display_power_preference"));
ASSERT_NE(GetParam().eglParameters.displayPowerPreference, EGL_DONT_CARE);
bool lowPower = (GetParam().eglParameters.displayPowerPreference == EGL_LOW_POWER_ANGLE);
ASSERT_EQ(findGPU(lowPower), findActiveGPU());
}
TEST_P(EGLDisplayPowerPreferenceTestMultiDisplay, ReInitializePowerPreferenceLowToHigh)
{
ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_display_power_preference"));
runReinitializeDisplay(EGL_LOW_POWER_ANGLE);
}
TEST_P(EGLDisplayPowerPreferenceTestMultiDisplay, ReInitializePowerPreferenceHighToLow)
{
ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_display_power_preference"));
runReinitializeDisplay(EGL_HIGH_POWER_ANGLE);
}
TEST_P(EGLDisplayPowerPreferenceTestMultiDisplay, MultiDisplayTest)
{
ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_display_power_preference"));
runMultiDisplay();
}
class EGLDisplayPowerPreferenceTestDeviceId : public EGLDisplayPowerPreferenceTestNoFixture
{
protected:
void initializeDisplayWithDeviceId(EGLDisplay *display, uint64_t deviceId)
{
GLenum platformType = GetParam().getRenderer();
GLenum deviceType = GetParam().getDeviceType();
EGLAttrib high = ((deviceId >> 32) & 0xFFFFFFFF);
EGLAttrib low = (deviceId & 0xFFFFFFFF);
std::vector<EGLint> displayAttributes;
displayAttributes.push_back(EGL_PLATFORM_ANGLE_TYPE_ANGLE);
displayAttributes.push_back(platformType);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE);
displayAttributes.push_back(EGL_DONT_CARE);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE);
displayAttributes.push_back(EGL_DONT_CARE);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE);
displayAttributes.push_back(deviceType);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_ID_HIGH_ANGLE);
displayAttributes.push_back(high);
displayAttributes.push_back(EGL_PLATFORM_ANGLE_DEVICE_ID_LOW_ANGLE);
displayAttributes.push_back(low);
displayAttributes.push_back(EGL_NONE);
*display = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
reinterpret_cast<void *>(mOSWindow->getNativeDisplay()),
displayAttributes.data());
ASSERT_TRUE(*display != EGL_NO_DISPLAY);
EGLint majorVersion, minorVersion;
ASSERT_TRUE(eglInitialize(*display, &majorVersion, &minorVersion) == EGL_TRUE);
eglBindAPI(EGL_OPENGL_ES_API);
ASSERT_EGL_SUCCESS();
}
};
TEST_P(EGLDisplayPowerPreferenceTestDeviceId, DeviceId)
{
ANGLE_SKIP_TEST_IF(!IsEGLClientExtensionEnabled("EGL_ANGLE_platform_angle_device_id"));
initializeWindow();
for (size_t i = 0; i < mSystemInfo.gpus.size(); i++)
{
// Initialize the display with device id for each GPU
EGLDisplay display;
EGLContext context;
initializeDisplayWithDeviceId(&display, mSystemInfo.gpus[i].systemDeviceId);
initializeContextForDisplay(display, &context);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context);
ASSERT_EQ(static_cast<int>(i), findActiveGPU());
// Terminate the displays
terminateContext(display, context);
eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
terminateDisplay(display);
}
terminateWindow();
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLDisplayPowerPreferenceTest);
ANGLE_INSTANTIATE_TEST(EGLDisplayPowerPreferenceTest,
WithLowPowerGPU(ES2_METAL()),
WithLowPowerGPU(ES3_METAL()),
WithHighPowerGPU(ES2_METAL()),
WithHighPowerGPU(ES3_METAL()));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLDisplayPowerPreferenceTestMultiDisplay);
ANGLE_INSTANTIATE_TEST(EGLDisplayPowerPreferenceTestMultiDisplay,
WithNoFixture(ES2_METAL()),
WithNoFixture(ES3_METAL()));
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(EGLDisplayPowerPreferenceTestDeviceId);
ANGLE_INSTANTIATE_TEST(EGLDisplayPowerPreferenceTestDeviceId,
WithNoFixture(ES2_D3D11()),
WithNoFixture(ES3_D3D11()),
WithNoFixture(ES2_METAL()),
WithNoFixture(ES3_METAL()));