Diff
Modified: trunk/Source/WebCore/ChangeLog (291223 => 291224)
--- trunk/Source/WebCore/ChangeLog 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/ChangeLog 2022-03-14 12:45:36 UTC (rev 291224)
@@ -1,3 +1,45 @@
+2022-03-14 Kimmo Kinnunen <[email protected]>
+
+ WebGL context should use discrete gpu if the context is created when the window is on external monitor, ANGLE Metal backend
+ https://bugs.webkit.org/show_bug.cgi?id=236487
+
+ Reviewed by Kenneth Russell.
+
+ Add GraphicsContextGLAttributes::windowGPUID which describes the GPU ID
+ for the window that the context is on.
+ Create the ANGLE Metal context based on this, unless high-performance GPU
+ is requested.
+
+ Changes the behavior so that new WebGL contexts will use dgpu is always when user has
+ external display plugged in. The system changes all the windows to the dgpu, so
+ this is consistent with the system expectation.
+
+ Notable difference due to the above is that we get different layout tests for a developer
+ that has a external monitor than before.
+
+ Tested by new unit tests.
+
+ * html/canvas/WebGLRenderingContextBase.cpp:
+ (WebCore::WebGLRenderingContextBase::create):
+ * page/Chrome.cpp:
+ (WebCore::Chrome::createGraphicsContextGL const):
+ * page/ChromeClient.cpp:
+ (WebCore::ChromeClient::createGraphicsContextGL const):
+ * page/ChromeClient.h:
+ * platform/PlatformScreen.h:
+ * platform/ScreenProperties.h:
+ (WebCore::ScreenData::decode):
+ * platform/graphics/GraphicsContextGLAttributes.h:
+ (WebCore::GraphicsContextGLAttributes::encode const):
+ (WebCore::GraphicsContextGLAttributes::decode):
+ * platform/graphics/cocoa/GraphicsContextGLCocoa.mm:
+ (WebCore::initializeEGLDisplay):
+ * platform/mac/PlatformScreenMac.mm:
+ (WebCore::collectScreenProperties):
+ (WebCore::primaryGPUID):
+ (WebCore::gpuIDForDisplay):
+ (WebCore::gpuIDForDisplayMask):
+
2022-03-14 Zan Dobersek <[email protected]>
Unreviewed, fixing an incomplete-type build error in InlineIteratorLine
Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (291223 => 291224)
--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp 2022-03-14 12:45:36 UTC (rev 291224)
@@ -150,6 +150,10 @@
#endif
#endif
+#if PLATFORM(MAC)
+#include "PlatformScreen.h"
+#endif
+
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(WebGLRenderingContextBase);
@@ -893,7 +897,11 @@
attributes.shareResources = false;
attributes.initialPowerPreference = attributes.powerPreference;
attributes.webGLVersion = type;
-
+#if PLATFORM(MAC)
+ // FIXME: Add MACCATALYST support for gpuIDForDisplay.
+ if (hostWindow)
+ attributes.windowGPUID = gpuIDForDisplay(hostWindow->displayID());
+#endif
#if PLATFORM(COCOA)
attributes.useMetal = scriptExecutionContext->settingsValues().webGLUsingMetal;
#endif
Modified: trunk/Source/WebCore/page/Chrome.cpp (291223 => 291224)
--- trunk/Source/WebCore/page/Chrome.cpp 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/page/Chrome.cpp 2022-03-14 12:45:36 UTC (rev 291224)
@@ -542,7 +542,7 @@
#if ENABLE(WEBGL)
RefPtr<GraphicsContextGL> Chrome::createGraphicsContextGL(const GraphicsContextGLAttributes& attributes) const
{
- return m_client.createGraphicsContextGL(attributes, displayID());
+ return m_client.createGraphicsContextGL(attributes);
}
#endif
Modified: trunk/Source/WebCore/page/ChromeClient.cpp (291223 => 291224)
--- trunk/Source/WebCore/page/ChromeClient.cpp 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/page/ChromeClient.cpp 2022-03-14 12:45:36 UTC (rev 291224)
@@ -37,7 +37,7 @@
ChromeClient::~ChromeClient() = default;
#if ENABLE(WEBGL)
-RefPtr<GraphicsContextGL> ChromeClient::createGraphicsContextGL(const GraphicsContextGLAttributes& attributes, WebCore::PlatformDisplayID) const
+RefPtr<GraphicsContextGL> ChromeClient::createGraphicsContextGL(const GraphicsContextGLAttributes& attributes) const
{
return createWebProcessGraphicsContextGL(attributes);
}
Modified: trunk/Source/WebCore/page/ChromeClient.h (291223 => 291224)
--- trunk/Source/WebCore/page/ChromeClient.h 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/page/ChromeClient.h 2022-03-14 12:45:36 UTC (rev 291224)
@@ -364,7 +364,7 @@
virtual RefPtr<ImageBuffer> createImageBuffer(const FloatSize&, RenderingMode, RenderingPurpose, float, const DestinationColorSpace&, PixelFormat) const { return nullptr; }
#if ENABLE(WEBGL)
- WEBCORE_EXPORT virtual RefPtr<GraphicsContextGL> createGraphicsContextGL(const GraphicsContextGLAttributes&, WebCore::PlatformDisplayID) const;
+ WEBCORE_EXPORT virtual RefPtr<GraphicsContextGL> createGraphicsContextGL(const GraphicsContextGLAttributes&) const;
#endif
virtual RefPtr<PAL::WebGPU::GPU> createGPUForWebGPU() const { return nullptr; }
Modified: trunk/Source/WebCore/platform/PlatformScreen.h (291223 => 291224)
--- trunk/Source/WebCore/platform/PlatformScreen.h 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/platform/PlatformScreen.h 2022-03-14 12:45:36 UTC (rev 291224)
@@ -63,12 +63,8 @@
using PlatformDisplayID = uint32_t;
-#if PLATFORM(MAC)
+using PlatformGPUID = uint64_t; // On MAC, MACCATALYST, global IOKit registryID that can identify a GPU across process boundaries.
-using IORegistryGPUID = int64_t; // Global IOKit I/O registryID that can match a GPU across process boundaries.
-
-#endif
-
int screenDepth(Widget*);
int screenDepthPerComponent(Widget*);
bool screenIsMonochrome(Widget*);
@@ -136,9 +132,9 @@
uint32_t primaryOpenGLDisplayMask();
uint32_t displayMaskForDisplay(PlatformDisplayID);
-IORegistryGPUID primaryGPUID();
-IORegistryGPUID gpuIDForDisplay(PlatformDisplayID);
-IORegistryGPUID gpuIDForDisplayMask(uint32_t);
+PlatformGPUID primaryGPUID();
+PlatformGPUID gpuIDForDisplay(PlatformDisplayID);
+PlatformGPUID gpuIDForDisplayMask(uint32_t);
WEBCORE_EXPORT FloatRect safeScreenFrame(NSScreen *);
Modified: trunk/Source/WebCore/platform/ScreenProperties.h (291223 => 291224)
--- trunk/Source/WebCore/platform/ScreenProperties.h 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/platform/ScreenProperties.h 2022-03-14 12:45:36 UTC (rev 291224)
@@ -47,7 +47,7 @@
#if PLATFORM(MAC)
bool screenIsMonochrome { false };
uint32_t displayMask { 0 };
- IORegistryGPUID gpuID { 0 };
+ PlatformGPUID gpuID { 0 };
DynamicRangeMode preferredDynamicRangeMode { DynamicRangeMode::Standard };
#endif
@@ -159,7 +159,7 @@
if (!displayMask)
return std::nullopt;
- std::optional<IORegistryGPUID> gpuID;
+ std::optional<PlatformGPUID> gpuID;
decoder >> gpuID;
if (!gpuID)
return std::nullopt;
Modified: trunk/Source/WebCore/platform/graphics/GraphicsContextGLAttributes.h (291223 => 291224)
--- trunk/Source/WebCore/platform/graphics/GraphicsContextGLAttributes.h 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContextGLAttributes.h 2022-03-14 12:45:36 UTC (rev 291224)
@@ -44,6 +44,10 @@
#endif
};
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+using PlatformGPUID = uint64_t;
+#endif
+
struct GraphicsContextGLAttributes {
// WebGLContextAttributes
bool alpha { true };
@@ -64,6 +68,9 @@
using WebGLVersion = GraphicsContextGLWebGLVersion;
WebGLVersion webGLVersion { WebGLVersion::WebGL1 };
bool forceRequestForHighPerformanceGPU { false };
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+ PlatformGPUID windowGPUID { 0 };
+#endif
#if PLATFORM(COCOA)
bool useMetal { true };
#endif
@@ -70,6 +77,7 @@
#if ENABLE(WEBXR)
bool xrCompatible { false };
#endif
+
PowerPreference effectivePowerPreference() const
{
if (forceRequestForHighPerformanceGPU)
@@ -102,6 +110,9 @@
<< initialPowerPreference
<< webGLVersion
<< forceRequestForHighPerformanceGPU;
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+ encoder << windowGPUID;
+#endif
#if PLATFORM(COCOA)
encoder << useMetal;
#endif
@@ -127,6 +138,9 @@
auto initialPowerPreference = decoder.template decode<PowerPreference>();
auto webGLVersion = decoder.template decode<WebGLVersion>();
auto forceRequestForHighPerformanceGPU = decoder.template decode<bool>();
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+ auto windowGPUID = decoder.template decode<PlatformGPUID>();
+#endif
#if PLATFORM(COCOA)
auto useMetal = decoder.template decode<bool>();
#endif
@@ -150,6 +164,9 @@
*initialPowerPreference,
*webGLVersion,
*forceRequestForHighPerformanceGPU,
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+ *windowGPUID,
+#endif
#if PLATFORM(COCOA)
*useMetal,
#endif
Modified: trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm (291223 => 291224)
--- trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLCocoa.mm 2022-03-14 12:45:36 UTC (rev 291224)
@@ -120,11 +120,11 @@
WTFLogAlways("Failed to load ANGLE shared library.");
return EGL_NO_DISPLAY;
}
+#if ASSERT_ENABLED
+ const char* clientExtensions = EGL_QueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+ ASSERT(clientExtensions);
+#endif
- EGLint majorVersion = 0;
- EGLint minorVersion = 0;
- EGLDisplay display;
-
Vector<EGLint> displayAttributes;
// FIXME: This should come in from the GraphicsContextGLAttributes.
@@ -146,18 +146,35 @@
// These properties are defined for EGL_ANGLE_power_preference as EGLContext attributes,
// but Metal backend uses EGLDisplay attributes.
auto powerPreference = attrs.effectivePowerPreference();
- if (powerPreference == GraphicsContextGLAttributes::PowerPreference::LowPower) {
+ if (powerPreference == GraphicsContextGLAttributes::PowerPreference::HighPerformance) {
displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
- displayAttributes.append(EGL_LOW_POWER_ANGLE);
- } else if (powerPreference == GraphicsContextGLAttributes::PowerPreference::HighPerformance) {
- displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
displayAttributes.append(EGL_HIGH_POWER_ANGLE);
+ } else {
+ if (powerPreference == GraphicsContextGLAttributes::PowerPreference::LowPower) {
+ displayAttributes.append(EGL_POWER_PREFERENCE_ANGLE);
+ displayAttributes.append(EGL_LOW_POWER_ANGLE);
+ }
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+ ASSERT(strstr(clientExtensions, "EGL_ANGLE_platform_angle_device_id"));
+ // If the power preference is default, use the GPU the context window is on.
+ // If the power preference is low power, and we know which GPU the context window is on,
+ // most likely the lowest power is the GPU that drives the context window, as that GPU
+ // is anyway already powered on.
+ if (attrs.windowGPUID) {
+ // EGL_PLATFORM_ANGLE_DEVICE_ID_*_ANGLE is the IOKit registry id on EGL_PLATFORM_ANGLE_TYPE_METAL_ANGLE.
+ displayAttributes.append(EGL_PLATFORM_ANGLE_DEVICE_ID_HIGH_ANGLE);
+ displayAttributes.append(static_cast<EGLAttrib>(attrs.windowGPUID >> 32));
+ displayAttributes.append(EGL_PLATFORM_ANGLE_DEVICE_ID_LOW_ANGLE);
+ displayAttributes.append(static_cast<EGLAttrib>(attrs.windowGPUID));
+ }
+#endif
}
}
-
displayAttributes.append(EGL_NONE);
- display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), displayAttributes.data());
+ EGLDisplay display = EGL_GetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE, reinterpret_cast<void*>(EGL_DEFAULT_DISPLAY), displayAttributes.data());
+ EGLint majorVersion = 0;
+ EGLint minorVersion = 0;
if (EGL_Initialize(display, &majorVersion, &minorVersion) == EGL_FALSE) {
LOG(WebGL, "EGLDisplay Initialization failed.");
return EGL_NO_DISPLAY;
Modified: trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm (291223 => 291224)
--- trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm 2022-03-14 12:45:36 UTC (rev 291224)
@@ -136,7 +136,7 @@
bool screenSupportsExtendedColor = [screen canRepresentDisplayGamut:NSDisplayGamutP3];
bool screenIsMonochrome = CGDisplayUsesForceToGray();
uint32_t displayMask = CGDisplayIDToOpenGLDisplayMask(displayID);
- IORegistryGPUID gpuID = 0;
+ PlatformGPUID gpuID = 0;
bool screenSupportsHighDynamicRange = false;
float scaleFactor = screen.backingScaleFactor;
DynamicRangeMode dynamicRangeMode = DynamicRangeMode::None;
@@ -193,12 +193,12 @@
return 0;
}
-IORegistryGPUID primaryGPUID()
+PlatformGPUID primaryGPUID()
{
return gpuIDForDisplay(primaryScreenDisplayID());
}
-IORegistryGPUID gpuIDForDisplay(PlatformDisplayID displayID)
+PlatformGPUID gpuIDForDisplay(PlatformDisplayID displayID)
{
if (auto data = ""
return data->gpuID;
@@ -206,7 +206,7 @@
return 0;
}
-IORegistryGPUID gpuIDForDisplayMask(GLuint displayMask)
+PlatformGPUID gpuIDForDisplayMask(GLuint displayMask)
{
GLint numRenderers = 0;
CGLRendererInfoObj rendererInfo = nullptr;
@@ -222,6 +222,9 @@
return 0;
}
+ // (kCGLRPRegistryIDHigh, kCGLRPRegistryIDLow) are defined as (upper, lower) 32-bits
+ // of the uint64_t IORegistryGPUID, even though they're obtained through the signed GLint getter.
+ // Thus care must be taken when converting them to unsigned PlatformGPUID.
GLint gpuIDLow = 0;
GLint gpuIDHigh = 0;
@@ -238,7 +241,7 @@
}
CGLDestroyRendererInfo(rendererInfo);
- return (IORegistryGPUID) gpuIDHigh << 32 | gpuIDLow;
+ return static_cast<PlatformGPUID>(static_cast<uint32_t>(gpuIDHigh)) << 32 | static_cast<uint32_t>(gpuIDLow);
}
static const ScreenData* screenProperties(Widget* widget)
Modified: trunk/Source/WebKit/ChangeLog (291223 => 291224)
--- trunk/Source/WebKit/ChangeLog 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebKit/ChangeLog 2022-03-14 12:45:36 UTC (rev 291224)
@@ -1,3 +1,17 @@
+2022-03-14 Kimmo Kinnunen <[email protected]>
+
+ WebGL context should use discrete gpu if the context is created when the window is on external monitor, ANGLE Metal backend
+ https://bugs.webkit.org/show_bug.cgi?id=236487
+
+ Reviewed by Kenneth Russell.
+
+ Before, the ChromeClient passed PlatformDisplayID to the createGraphicsContextGL. This was ignored.
+ After, pass the PlatformGPUID as part of GraphicsContextGLAttributes.
+
+ * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+ (WebKit::WebChromeClient::createGraphicsContextGL const):
+ * WebProcess/WebCoreSupport/WebChromeClient.h:
+
2022-03-12 Simon Fraser <[email protected]>
In RemoteLayerBackingStore, group makeFrontBufferNonVolatile() and swapToValidFrontBuffer() into a single function
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (291223 => 291224)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp 2022-03-14 12:45:36 UTC (rev 291224)
@@ -941,7 +941,7 @@
#endif
#if ENABLE(WEBGL)
-RefPtr<GraphicsContextGL> WebChromeClient::createGraphicsContextGL(const GraphicsContextGLAttributes& attributes, PlatformDisplayID) const
+RefPtr<GraphicsContextGL> WebChromeClient::createGraphicsContextGL(const GraphicsContextGLAttributes& attributes) const
{
#if ENABLE(GPU_PROCESS) && (PLATFORM(COCOA) || PLATFORM(WIN))
if (WebProcess::singleton().shouldUseRemoteRenderingForWebGL())
Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (291223 => 291224)
--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h 2022-03-14 12:45:36 UTC (rev 291224)
@@ -250,7 +250,7 @@
RefPtr<WebCore::ImageBuffer> createImageBuffer(const WebCore::FloatSize&, WebCore::RenderingMode, WebCore::RenderingPurpose, float resolutionScale, const WebCore::DestinationColorSpace&, WebCore::PixelFormat) const final;
#endif
#if ENABLE(WEBGL)
- RefPtr<WebCore::GraphicsContextGL> createGraphicsContextGL(const WebCore::GraphicsContextGLAttributes&, WebCore::PlatformDisplayID hostWindowDisplayID) const final;
+ RefPtr<WebCore::GraphicsContextGL> createGraphicsContextGL(const WebCore::GraphicsContextGLAttributes&) const final;
#endif
RefPtr<PAL::WebGPU::GPU> createGPUForWebGPU() const final;
Modified: trunk/Tools/ChangeLog (291223 => 291224)
--- trunk/Tools/ChangeLog 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Tools/ChangeLog 2022-03-14 12:45:36 UTC (rev 291224)
@@ -1,3 +1,22 @@
+2022-03-14 Kimmo Kinnunen <[email protected]>
+
+ WebGL context should use discrete gpu if the context is created when the window is on external monitor, ANGLE Metal backend
+ https://bugs.webkit.org/show_bug.cgi?id=236487
+
+ Reviewed by Kenneth Russell.
+
+ Add tests to test that the windowGPUID affects the contexts being created.
+ Avoid ifdefs by always compiling the tests and move the "platform can have
+ multiple gpus / there is no multiple gpus in the platform" ifdef aspects
+ to helper functions.
+
+ * TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm:
+ (TestWebKitAPI::allDevices):
+ (TestWebKitAPI::lowPowerDevice):
+ (TestWebKitAPI::highPerformanceDevice):
+ (TestWebKitAPI::hasMultipleGPUs):
+ (TestWebKitAPI::TEST_F):
+
2022-03-12 Tim Horton <[email protected]>
Adopt FALLBACK_PLATFORM_NAME in place of FALLBACK_PLATFORM
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm (291223 => 291224)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm 2022-03-14 12:04:48 UTC (rev 291223)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/cocoa/TestGraphicsContextGLCocoa.mm 2022-03-14 12:45:36 UTC (rev 291224)
@@ -110,29 +110,56 @@
return ::testing::AssertionSuccess();
}
+#if PLATFORM(MAC) || PLATFORM(MACCATALYST)
+static RetainPtr<NSArray<id<MTLDevice>>> allDevices()
+{
+ return adoptNS(MTLCopyAllDevices());
+}
+
+static RetainPtr<id<MTLDevice>> lowPowerDevice()
+{
+ auto devices = allDevices();
+ for (id<MTLDevice> device in devices.get()) {
+ if (device.lowPower)
+ return device;
+ }
+ return nullptr;
+}
+
+static RetainPtr<id<MTLDevice>> highPerformanceDevice()
+{
+ auto devices = allDevices();
+ for (id<MTLDevice> device in devices.get()) {
+ if (!device.lowPower && !device.removable)
+ return device;
+ }
+ return nullptr;
+}
+
static bool hasMultipleGPUs()
{
-#if (PLATFORM(MAC) || PLATFORM(MACCATALYST))
- auto devices = adoptNS(MTLCopyAllDevices());
- return [devices count] > 1;
-#else
- return false;
-#endif
+ return highPerformanceDevice() && lowPowerDevice();
}
-#if HAVE(WEBGL_COMPATIBLE_METAL) && (PLATFORM(MAC) || PLATFORM(MACCATALYST))
-#define MAYBE_MultipleGPUsDifferentPowerPreferenceMetal MultipleGPUsDifferentPowerPreferenceMetal
-#else
-#define MAYBE_MultipleGPUsDifferentPowerPreferenceMetal DISABLED_MultipleGPUsDifferentPowerPreferenceMetal
-#endif
+// Sanity check for the MultipleGPUs* tests.
+TEST_F(GraphicsContextGLCocoaTest, MultipleGPUsHaveDifferentGPUs)
+{
+ if (!hasMultipleGPUs())
+ return;
+ auto a = highPerformanceDevice();
+ auto b = lowPowerDevice();
+ EXPECT_NE(a.get(), nullptr);
+ EXPECT_NE(b.get(), nullptr);
+ EXPECT_NE(a.get(), b.get());
+}
+
// Tests for a bug where high-performance context would use low-power GPU if low-power or default
// context was created first. Test is applicable only for Metal, since GPU selection for OpenGL is
// very different.
-TEST_F(GraphicsContextGLCocoaTest, MAYBE_MultipleGPUsDifferentPowerPreferenceMetal)
+TEST_F(GraphicsContextGLCocoaTest, MultipleGPUsDifferentPowerPreferenceMetal)
{
if (!hasMultipleGPUs())
return;
-
WebCore::GraphicsContextGLAttributes attributes;
attributes.useMetal = true;
EXPECT_EQ(attributes.powerPreference, WebCore::GraphicsContextGLPowerPreference::Default);
@@ -151,6 +178,93 @@
EXPECT_EQ(defaultContext->getString(WebCore::GraphicsContextGL::RENDERER), lowPowerContext->getString(WebCore::GraphicsContextGL::RENDERER));
}
+// Tests that requesting context with windowGPUID from low power device results
+// to same thing as requesting default low power context.
+// Tests that windowGPUID from low power device still respects high performance request.
+TEST_F(GraphicsContextGLCocoaTest, MultipleGPUsExplicitLowPowerDeviceMetal)
+{
+ if (!hasMultipleGPUs())
+ return;
+ WebCore::GraphicsContextGLAttributes attributes1;
+ attributes1.useMetal = true;
+ attributes1.powerPreference = WebCore::GraphicsContextGLPowerPreference::LowPower;
+ auto lowPowerContext = TestedGraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes1 });
+ ASSERT_NE(lowPowerContext, nullptr);
+
+ WebCore::GraphicsContextGLAttributes attributes2;
+ attributes2.useMetal = true;
+ attributes2.windowGPUID = [lowPowerDevice() registryID];
+ auto explicitDeviceContext = TestedGraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes2 });
+ ASSERT_NE(explicitDeviceContext.get(), nullptr);
+
+ // Context with windowGPUID from low power device results to same thing as requesting default low power context.
+ EXPECT_EQ(lowPowerContext->getString(WebCore::GraphicsContextGL::RENDERER), explicitDeviceContext->getString(WebCore::GraphicsContextGL::RENDERER));
+
+ // High performance request on a low power explicit device as windowGPUID respects the high performance request.
+ attributes2.powerPreference = WebCore::GraphicsContextGLPowerPreference::HighPerformance;
+ auto highPerformanceExplicitDeviceContext = TestedGraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes2 });
+ ASSERT_NE(highPerformanceExplicitDeviceContext.get(), nullptr);
+ EXPECT_NE(highPerformanceExplicitDeviceContext->getString(WebCore::GraphicsContextGL::RENDERER), explicitDeviceContext->getString(WebCore::GraphicsContextGL::RENDERER));
+}
+
+// Tests that requesting context with windowGPUID from high performance device results to same thing
+// as requesting default high performance context.
+// Tests that windowGPUID from high performance device still uses that device even when low-power context is requested.
+// It is likely that context on a specific window + gpu is the lowest power if the window is on that gpu.
+TEST_F(GraphicsContextGLCocoaTest, MultipleGPUsExplicitHighPerformanceDeviceMetal)
+{
+ if (!hasMultipleGPUs())
+ return;
+ WebCore::GraphicsContextGLAttributes attributes1;
+ attributes1.useMetal = true;
+ attributes1.powerPreference = WebCore::GraphicsContextGLPowerPreference::HighPerformance;
+ auto highPerformanceContext = TestedGraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes1 });
+ ASSERT_NE(highPerformanceContext, nullptr);
+
+ WebCore::GraphicsContextGLAttributes attributes2;
+ attributes2.useMetal = true;
+ attributes2.windowGPUID = [highPerformanceDevice() registryID];
+ auto explicitDeviceContext = TestedGraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes2 });
+ ASSERT_NE(explicitDeviceContext.get(), nullptr);
+
+ // Context with windowGPUID from high performance device results to same thing as requesting default high performance context.
+ EXPECT_EQ(highPerformanceContext->getString(WebCore::GraphicsContextGL::RENDERER), explicitDeviceContext->getString(WebCore::GraphicsContextGL::RENDERER));
+
+ // Low power request on a high performance explicit device as windowGPUID ignores the low power request.
+ attributes2.powerPreference = WebCore::GraphicsContextGLPowerPreference::LowPower;
+ auto lowPowerExplicitDeviceContext = TestedGraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes2 });
+ ASSERT_NE(lowPowerExplicitDeviceContext.get(), nullptr);
+ EXPECT_EQ(lowPowerExplicitDeviceContext->getString(WebCore::GraphicsContextGL::RENDERER), explicitDeviceContext->getString(WebCore::GraphicsContextGL::RENDERER));
+}
+
+// Tests that requesting GraphicsContextGL instances with different devices results in different underlying
+// EGLDisplays.
+TEST_F(GraphicsContextGLCocoaTest, MultipleGPUsDifferentGPUIDsMetal)
+{
+ if (!hasMultipleGPUs())
+ return;
+ Vector<Ref<TestedGraphicsContextGLCocoa>> contexts;
+ auto devices = allDevices();
+ for (id<MTLDevice> device in devices.get()) {
+ WebCore::GraphicsContextGLAttributes attributes;
+ attributes.useMetal = true;
+ attributes.windowGPUID = [device registryID];
+ auto context = TestedGraphicsContextGLCocoa::create(WebCore::GraphicsContextGLAttributes { attributes });
+ EXPECT_NE(context.get(), nullptr);
+ if (!context)
+ continue;
+ contexts.append(context.releaseNonNull());
+ }
+ EXPECT_GT(contexts.size(), 1u);
+
+ // The requested EGLDisplays must differ if the devices differ.
+ for (auto itA = contexts.begin(); itA != contexts.end(); ++itA) {
+ for (auto itB = itA + 1; itB != contexts.end(); ++itB)
+ EXPECT_NE((*itA)->platformDisplay(), (*itB)->platformDisplay());
+ }
+}
+#endif
+
TEST_F(GraphicsContextGLCocoaTest, DisplayBuffersAreRecycled)
{
auto context = createDefaultTestContext({ 20, 20 });