Title: [281245] trunk
Revision
281245
Author
d...@apple.com
Date
2021-08-19 09:28:04 -0700 (Thu, 19 Aug 2021)

Log Message

WebGL via Metal experimental feature does not correctly toggle metal backend
https://bugs.webkit.org/show_bug.cgi?id=229267
<rdar://81855735>

Source/WebCore:

Patch by Kyle Piddington <kpidding...@apple.com> on 2021-08-19
Reviewed by Dean Jackson.

GraphicsContextGLAttributes defines 'useMetal' as 'true' by default.
Since this branch was only checking if Metal was enabled via the
setting, rather than checking the status of the flag, the metal backend
was never disabled, even when requested.

Tests: webgl/webgl-metal-disabled.html
       webgl/webgl-metal-enabled.html

* WebCore.xcodeproj/project.pbxproj:
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::create):
* testing/Internals.cpp:
(WebCore::Internals::requestedMetal):
* testing/Internals.h:
* testing/Internals.idl:
* testing/Internals.mm:
(WebCore::Internals::platformSupportsMetal):

LayoutTests:

Add tests to verify WebGL feature flag works as intended.

Patch by Kyle Piddington <kpidding...@apple.com> on 2021-08-19
Reviewed by Dean Jackson.

* webgl/webgl-metal-disabled-expected.txt: Added.
* webgl/webgl-metal-disabled.html: Added.
* webgl/webgl-metal-enabled-expected.txt: Added.
* webgl/webgl-metal-enabled.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (281244 => 281245)


--- trunk/LayoutTests/ChangeLog	2021-08-19 16:26:00 UTC (rev 281244)
+++ trunk/LayoutTests/ChangeLog	2021-08-19 16:28:04 UTC (rev 281245)
@@ -1,3 +1,18 @@
+2021-08-19  Kyle Piddington  <kpidding...@apple.com>
+
+        WebGL via Metal experimental feature does not correctly toggle metal backend
+        https://bugs.webkit.org/show_bug.cgi?id=229267
+        <rdar://81855735>
+
+        Add tests to verify WebGL feature flag works as intended.
+
+        Reviewed by Dean Jackson.
+
+        * webgl/webgl-metal-disabled-expected.txt: Added.
+        * webgl/webgl-metal-disabled.html: Added.
+        * webgl/webgl-metal-enabled-expected.txt: Added.
+        * webgl/webgl-metal-enabled.html: Added.
+
 2021-08-19  Antti Koivisto  <an...@apple.com>
 
         TextDecorationPainter should not depend on LegacyInlineTextBox

Added: trunk/LayoutTests/webgl/webgl-metal-disabled-expected.txt (0 => 281245)


--- trunk/LayoutTests/webgl/webgl-metal-disabled-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgl/webgl-metal-disabled-expected.txt	2021-08-19 16:28:04 UTC (rev 281245)
@@ -0,0 +1,2 @@
+Metal for WebGL1 disabled when requested: OK
+
Property changes on: trunk/LayoutTests/webgl/webgl-metal-disabled-expected.txt
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/plain \ No newline at end of property

Added: trunk/LayoutTests/webgl/webgl-metal-disabled.html (0 => 281245)


--- trunk/LayoutTests/webgl/webgl-metal-disabled.html	                        (rev 0)
+++ trunk/LayoutTests/webgl/webgl-metal-disabled.html	2021-08-19 16:28:04 UTC (rev 281245)
@@ -0,0 +1,31 @@
+<!-- webkit-test-runner [ WebGLUsingMetal=false ] -->
+<canvas id="a"></canvas>
+<script>
+if (window.testRunner)
+    window.testRunner.dumpAsText();
+
+function run()
+{
+    const out = document.querySelector("p");
+    let result = "";
+
+    if (!window.internals) {
+        out.innerText = "Test requires internals.";
+        return;
+    }
+
+    const canvasA = document.getElementById("a");
+    const glA = canvasA.getContext("webgl");
+    const requested = internals.requestedMetal(glA);
+    const supported = false;
+    let resultStr = "OK";
+    if (requested != supported)
+        resultStr = "FAIL";
+
+    result += `Metal for WebGL1 disabled when requested: ${resultStr}<br>`;
+    out.innerHTML = result;
+}
+
+window.addEventListener("load", run, false);
+</script>
+<p></p>
Property changes on: trunk/LayoutTests/webgl/webgl-metal-disabled.html
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Added: trunk/LayoutTests/webgl/webgl-metal-enabled-expected.txt (0 => 281245)


--- trunk/LayoutTests/webgl/webgl-metal-enabled-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgl/webgl-metal-enabled-expected.txt	2021-08-19 16:28:04 UTC (rev 281245)
@@ -0,0 +1,2 @@
+Metal for WebGL1 enabled matches platform support: OK
+
Property changes on: trunk/LayoutTests/webgl/webgl-metal-enabled-expected.txt
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/plain \ No newline at end of property

Added: trunk/LayoutTests/webgl/webgl-metal-enabled.html (0 => 281245)


--- trunk/LayoutTests/webgl/webgl-metal-enabled.html	                        (rev 0)
+++ trunk/LayoutTests/webgl/webgl-metal-enabled.html	2021-08-19 16:28:04 UTC (rev 281245)
@@ -0,0 +1,30 @@
+<canvas id="a"></canvas>
+<script>
+if (window.testRunner)
+    window.testRunner.dumpAsText();
+
+function run()
+{
+    const out = document.querySelector("p");
+    let result = "";
+
+    if (!window.internals) {
+        out.innerText = "Test requires internals.";
+        return;
+    }
+
+    const canvasA = document.getElementById("a");
+    const glA = canvasA.getContext("webgl");
+    const requested = internals.requestedMetal(glA);
+    const supported = internals.platformSupportsMetal(false);
+    let resultStr = "OK";
+    if (requested != supported)
+        resultStr = "FAIL";
+
+    result += `Metal for WebGL1 enabled matches platform support: ${resultStr}<br>`;
+    out.innerHTML = result;
+}
+
+window.addEventListener("load", run, false);
+</script>
+<p></p>
Property changes on: trunk/LayoutTests/webgl/webgl-metal-enabled.html
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Date Revision \ No newline at end of property

Added: svn:mime-type

+text/html \ No newline at end of property

Modified: trunk/Source/WebCore/ChangeLog (281244 => 281245)


--- trunk/Source/WebCore/ChangeLog	2021-08-19 16:26:00 UTC (rev 281244)
+++ trunk/Source/WebCore/ChangeLog	2021-08-19 16:28:04 UTC (rev 281245)
@@ -1,3 +1,29 @@
+2021-08-19  Kyle Piddington  <kpidding...@apple.com>
+
+        WebGL via Metal experimental feature does not correctly toggle metal backend
+        https://bugs.webkit.org/show_bug.cgi?id=229267
+        <rdar://81855735>
+
+        Reviewed by Dean Jackson.
+
+        GraphicsContextGLAttributes defines 'useMetal' as 'true' by default.
+        Since this branch was only checking if Metal was enabled via the
+        setting, rather than checking the status of the flag, the metal backend
+        was never disabled, even when requested.
+
+        Tests: webgl/webgl-metal-disabled.html
+               webgl/webgl-metal-enabled.html
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/canvas/WebGLRenderingContextBase.cpp:
+        (WebCore::WebGLRenderingContextBase::create):
+        * testing/Internals.cpp:
+        (WebCore::Internals::requestedMetal):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        * testing/Internals.mm:
+        (WebCore::Internals::platformSupportsMetal):
+
 2021-08-19  Simon Fraser  <simon.fra...@apple.com>
 
         Avoid DOMRect overhead in VTTRegion

Modified: trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp (281244 => 281245)


--- trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-08-19 16:26:00 UTC (rev 281244)
+++ trunk/Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp	2021-08-19 16:28:04 UTC (rev 281245)
@@ -719,8 +719,7 @@
     attributes.webGLVersion = type;
 
 #if PLATFORM(COCOA)
-    if (scriptExecutionContext->settingsValues().webGLUsingMetal)
-        attributes.useMetal = true;
+    attributes.useMetal = scriptExecutionContext->settingsValues().webGLUsingMetal;
 #endif
 
     if (isPendingPolicyResolution) {

Modified: trunk/Source/WebCore/testing/Internals.cpp (281244 => 281245)


--- trunk/Source/WebCore/testing/Internals.cpp	2021-08-19 16:26:00 UTC (rev 281244)
+++ trunk/Source/WebCore/testing/Internals.cpp	2021-08-19 16:28:04 UTC (rev 281245)
@@ -5289,8 +5289,22 @@
 
     return RequestedGPU::Default;
 }
+
+bool Internals::requestedMetal(WebGLRenderingContext& context)
+{
+    UNUSED_PARAM(context);
+#if PLATFORM(COCOA)
+    if (auto optionalAttributes = context.getContextAttributes()) {
+        auto attributes = *optionalAttributes;
+
+        return attributes.useMetal;
+    }
 #endif
 
+    return false;
+}
+#endif
+
 void Internals::setPageVisibility(bool isVisible)
 {
     auto* document = contextDocument();
@@ -6508,4 +6522,11 @@
     return { };
 }
 
+#if ENABLE(WEBGL) && !PLATFORM(COCOA)
+bool Internals::platformSupportsMetal(bool)
+{
+    return false;
+}
+#endif
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/testing/Internals.h (281244 => 281245)


--- trunk/Source/WebCore/testing/Internals.h	2021-08-19 16:26:00 UTC (rev 281244)
+++ trunk/Source/WebCore/testing/Internals.h	2021-08-19 16:28:04 UTC (rev 281245)
@@ -825,6 +825,8 @@
         HighPerformance
     };
     RequestedGPU requestedGPU(WebGLRenderingContext&);
+    bool requestedMetal(WebGLRenderingContext&);
+    bool platformSupportsMetal(bool isWebGL2);
 #endif
 
     void setPageVisibility(bool isVisible);

Modified: trunk/Source/WebCore/testing/Internals.idl (281244 => 281245)


--- trunk/Source/WebCore/testing/Internals.idl	2021-08-19 16:26:00 UTC (rev 281244)
+++ trunk/Source/WebCore/testing/Internals.idl	2021-08-19 16:28:04 UTC (rev 281245)
@@ -855,6 +855,8 @@
     [Conditional=WEBGL] undefined simulateEventForWebGLContext(SimulatedWebGLContextEvent event, WebGLRenderingContext context);
     [Conditional=WEBGL] boolean hasLowAndHighPowerGPUs();
     [Conditional=WEBGL] RequestedGPU requestedGPU(WebGLRenderingContext context);
+    [Conditional=WEBGL] boolean requestedMetal(WebGLRenderingContext context);
+    [Conditional=WEBGL] boolean platformSupportsMetal(boolean isWebGL2);
 
     undefined setPageVisibility(boolean isVisible);
     undefined setPageIsFocusedAndActive(boolean isFocused);

Modified: trunk/Source/WebCore/testing/Internals.mm (281244 => 281245)


--- trunk/Source/WebCore/testing/Internals.mm	2021-08-19 16:26:00 UTC (rev 281244)
+++ trunk/Source/WebCore/testing/Internals.mm	2021-08-19 16:28:04 UTC (rev 281245)
@@ -38,6 +38,9 @@
 #import "SimpleRange.h"
 #import "UTIUtilities.h"
 #import <AVFoundation/AVPlayer.h>
+#if PLATFORM(COCOA)
+#import <Metal/Metal.h>
+#endif
 #import <pal/spi/cocoa/NSAccessibilitySPI.h>
 #import <wtf/cocoa/NSURLExtras.h>
 #import <wtf/spi/darwin/SandboxSPI.h>
@@ -46,6 +49,8 @@
 #import <pal/ios/UIKitSoftLink.h>
 #endif
 
+
+
 namespace WebCore {
 
 String Internals::userVisibleString(const DOMURL& url)
@@ -146,4 +151,25 @@
     return !sandbox_check(pid, "iokit-open", static_cast<enum sandbox_filter_type>(SANDBOX_FILTER_IOKIT_CONNECTION | SANDBOX_CHECK_NO_REPORT), ioKitClass.utf8().data());
 }
 
+#if ENABLE(WEBGL) && PLATFORM(COCOA)
+bool Internals::platformSupportsMetal(bool isWebGL2)
+{
+    auto device = MTLCreateSystemDefaultDevice();
+
+    if (device) {
+#if PLATFORM(IOS_FAMILY) && !PLATFORM(IOS_FAMILY_SIMULATOR)
+        // A8 devices (iPad Mini 4, iPad Air 2) cannot use WebGL2 via Metal.
+        // This check can be removed once they are no longer supported.
+        if (isWebGL2)
+            return [device supportsFamily:MTLGPUFamilyApple3];
+#else
+        UNUSED_PARAM(isWebGL2);
+#endif
+        return true;
+    }
+
+    return false;
 }
+#endif
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to