Title: [240807] trunk
Revision
240807
Author
justin_...@apple.com
Date
2019-01-31 12:53:50 -0800 (Thu, 31 Jan 2019)

Log Message

[WebGPU] WebGPUAdapterDescriptor -> GPURequestAdapterOptions and take powerPreference into account
https://bugs.webkit.org/show_bug.cgi?id=194068
<rdar://problem/47680215>

Reviewed by Dean Jackson.
Source/WebCore:

Per the Web GPU IDL, WebGPUAdapterDescriptor is now known as GPURequestAdapterOptions and is optional.
In addition, Web GPU now actually attempts to return an integrated GPU when a low-power adapter is requested.

Test: adapter-options.html

* Modules/webgpu/GPURequestAdapterOptions.idl: Renamed from Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.idl.
* Modules/webgpu/WebGPU.cpp:
(WebCore::WebGPU::requestAdapter const):
* Modules/webgpu/WebGPU.h:
* Modules/webgpu/WebGPU.idl:
* Modules/webgpu/WebGPUAdapter.cpp:
(WebCore::WebGPUAdapter::create):
(WebCore::WebGPUAdapter::WebGPUAdapter):
* Modules/webgpu/WebGPUAdapter.h:
(WebCore::WebGPUAdapter::options const):
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::create):
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/GPURequestAdapterOptions.h: Renamed from Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.h.
* platform/graphics/gpu/cocoa/GPUDeviceMetal.mm:
(WebCore::GPUDevice::create):

LayoutTests:

Add simple test to create device with all options. Update helper functions for other Web GPU
tests to request different adapters. (No change in test behavior expected.)

* webgpu/adapter-options-expected.txt: Added.
* webgpu/adapter-options.html: Added.
* webgpu/js/basic-webgpu-functions.js:
(async.setUpContexts): Update to use no adapter request argument at all.
* webgpu/js/webgpu-functions.js:
(async.getBasicDevice): Update to request the low-power adapter.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (240806 => 240807)


--- trunk/LayoutTests/ChangeLog	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/LayoutTests/ChangeLog	2019-01-31 20:53:50 UTC (rev 240807)
@@ -1,3 +1,21 @@
+2019-01-31  Justin Fan  <justin_...@apple.com>
+
+        [WebGPU] WebGPUAdapterDescriptor -> GPURequestAdapterOptions and take powerPreference into account
+        https://bugs.webkit.org/show_bug.cgi?id=194068
+        <rdar://problem/47680215>
+
+        Reviewed by Dean Jackson.
+
+        Add simple test to create device with all options. Update helper functions for other Web GPU
+        tests to request different adapters. (No change in test behavior expected.)
+
+        * webgpu/adapter-options-expected.txt: Added.
+        * webgpu/adapter-options.html: Added.
+        * webgpu/js/basic-webgpu-functions.js:
+        (async.setUpContexts): Update to use no adapter request argument at all. 
+        * webgpu/js/webgpu-functions.js:
+        (async.getBasicDevice): Update to request the low-power adapter.
+
 2019-01-31  Zalan Bujtas  <za...@apple.com>
 
         [LFC] Use the used margin values in outOfFlowReplacedHorizontalGeometry consistently

Added: trunk/LayoutTests/webgpu/adapter-options-expected.txt (0 => 240807)


--- trunk/LayoutTests/webgpu/adapter-options-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgpu/adapter-options-expected.txt	2019-01-31 20:53:50 UTC (rev 240807)
@@ -0,0 +1,5 @@
+
+PASS Create the default device. 
+PASS Create a device with a low-power option. 
+PASS Create a device with a high-performance option. 
+

Added: trunk/LayoutTests/webgpu/adapter-options.html (0 => 240807)


--- trunk/LayoutTests/webgpu/adapter-options.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/adapter-options.html	2019-01-31 20:53:50 UTC (rev 240807)
@@ -0,0 +1,29 @@
+<!DOCTYPE html><!-- webkit-test-runner [ experimental:WebGPUEnabled=true ] -->
+<meta charset=utf-8>
+<title>Create GPUDevices from various options.</title>
+<body>
+<script src=""
+<script src=""
+<script>
+promise_test(async () => {
+    const defaultAdapter = await webgpu.requestAdapter();
+    const device = defaultAdapter.createDevice();
+
+    assert_true(device instanceof WebGPUDevice, "Default device successfully created.");
+}, "Create the default device.");
+
+promise_test(async () => {
+    const lowPowerAdapter = await webgpu.requestAdapter({ powerPreference: "low-power" });
+    const device = lowPowerAdapter.createDevice();
+
+    assert_true(device instanceof WebGPUDevice, "Device successfully created using low-power option.");
+}, "Create a device with a low-power option.");
+
+promise_test(async () => {
+    const highPerfAdapter = await webgpu.requestAdapter({ powerPreference: "high-performance" });
+    const device = highPerfAdapter.createDevice();
+
+    assert_true(device instanceof WebGPUDevice, "Device successfully created using high-performance option.");
+}, "Create a device with a high-performance option.");
+</script>
+</body>
\ No newline at end of file

Modified: trunk/LayoutTests/webgpu/js/basic-webgpu-functions.js (240806 => 240807)


--- trunk/LayoutTests/webgpu/js/basic-webgpu-functions.js	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/LayoutTests/webgpu/js/basic-webgpu-functions.js	2019-01-31 20:53:50 UTC (rev 240807)
@@ -60,8 +60,7 @@
 
     shouldBeDefined(window.webgpu);
     
-    // FIXME: requestAdapter should take a WebGPUAdapterDescriptor.
-    adapter = await window.webgpu.requestAdapter({});
+    adapter = await window.webgpu.requestAdapter();
     if (!adapter) {
         testFailed("Could not create default WebGPUAdapter!")
         return;

Modified: trunk/LayoutTests/webgpu/js/webgpu-functions.js (240806 => 240807)


--- trunk/LayoutTests/webgpu/js/webgpu-functions.js	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/LayoutTests/webgpu/js/webgpu-functions.js	2019-01-31 20:53:50 UTC (rev 240807)
@@ -1,6 +1,5 @@
 async function getBasicDevice() {
-    // FIXME: requestAdapter should take a WebGPUAdapterDescriptor.
-    const adapter = await window.webgpu.requestAdapter({});
+    const adapter = await window.webgpu.requestAdapter({ powerPreference: "low-power" });
     const device = adapter.createDevice();
     return device;
 }

Modified: trunk/Source/WebCore/CMakeLists.txt (240806 => 240807)


--- trunk/Source/WebCore/CMakeLists.txt	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/CMakeLists.txt	2019-01-31 20:53:50 UTC (rev 240807)
@@ -464,9 +464,9 @@
     Modules/webgpu/DOMWindowWebGPU.idl
     Modules/webgpu/GPUCompareFunction.idl
     Modules/webgpu/GPUDepthStencilStateDescriptor.idl
+    Modules/webgpu/GPURequestAdapterOptions.idl
     Modules/webgpu/WebGPU.idl
     Modules/webgpu/WebGPUAdapter.idl
-    Modules/webgpu/WebGPUAdapterDescriptor.idl
     Modules/webgpu/WebGPUBindGroup.idl
     Modules/webgpu/WebGPUBindGroupBinding.idl
     Modules/webgpu/WebGPUBindGroupDescriptor.idl

Modified: trunk/Source/WebCore/ChangeLog (240806 => 240807)


--- trunk/Source/WebCore/ChangeLog	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/ChangeLog	2019-01-31 20:53:50 UTC (rev 240807)
@@ -1,3 +1,33 @@
+2019-01-31  Justin Fan  <justin_...@apple.com>
+
+        [WebGPU] WebGPUAdapterDescriptor -> GPURequestAdapterOptions and take powerPreference into account
+        https://bugs.webkit.org/show_bug.cgi?id=194068
+        <rdar://problem/47680215>
+
+        Reviewed by Dean Jackson.
+        
+        Per the Web GPU IDL, WebGPUAdapterDescriptor is now known as GPURequestAdapterOptions and is optional.
+        In addition, Web GPU now actually attempts to return an integrated GPU when a low-power adapter is requested.
+
+        Test: adapter-options.html
+
+        * Modules/webgpu/GPURequestAdapterOptions.idl: Renamed from Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.idl.
+        * Modules/webgpu/WebGPU.cpp:
+        (WebCore::WebGPU::requestAdapter const):
+        * Modules/webgpu/WebGPU.h:
+        * Modules/webgpu/WebGPU.idl:
+        * Modules/webgpu/WebGPUAdapter.cpp:
+        (WebCore::WebGPUAdapter::create):
+        (WebCore::WebGPUAdapter::WebGPUAdapter):
+        * Modules/webgpu/WebGPUAdapter.h:
+        (WebCore::WebGPUAdapter::options const):
+        * Modules/webgpu/WebGPUDevice.cpp:
+        (WebCore::WebGPUDevice::create):
+        * platform/graphics/gpu/GPUDevice.h:
+        * platform/graphics/gpu/GPURequestAdapterOptions.h: Renamed from Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.h.
+        * platform/graphics/gpu/cocoa/GPUDeviceMetal.mm:
+        (WebCore::GPUDevice::create):
+
 2019-01-31  Jiewen Tan  <jiewen_...@apple.com>
 
         Formalize WebKitAdditions mechanism of LoadOptimizer

Modified: trunk/Source/WebCore/DerivedSources.make (240806 => 240807)


--- trunk/Source/WebCore/DerivedSources.make	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/DerivedSources.make	2019-01-31 20:53:50 UTC (rev 240807)
@@ -374,9 +374,9 @@
     $(WebCore)/Modules/webgpu/DOMWindowWebGPU.idl \
     $(WebCore)/Modules/webgpu/GPUCompareFunction.idl \
     $(WebCore)/Modules/webgpu/GPUDepthStencilStateDescriptor.idl \
+    $(WebCore)/Modules/webgpu/GPURequestAdapterOptions.idl \
     $(WebCore)/Modules/webgpu/WebGPU.idl \
     $(WebCore)/Modules/webgpu/WebGPUAdapter.idl \
-    $(WebCore)/Modules/webgpu/WebGPUAdapterDescriptor.idl \
     $(WebCore)/Modules/webgpu/WebGPUBindGroup.idl \
     $(WebCore)/Modules/webgpu/WebGPUBindGroupBinding.idl \
     $(WebCore)/Modules/webgpu/WebGPUBindGroupDescriptor.idl \

Copied: trunk/Source/WebCore/Modules/webgpu/GPURequestAdapterOptions.idl (from rev 240806, trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.idl) (0 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/GPURequestAdapterOptions.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/GPURequestAdapterOptions.idl	2019-01-31 20:53:50 UTC (rev 240807)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
+
+enum GPUPowerPreference {
+    "low-power",
+    "high-performance"
+};
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU
+] dictionary GPURequestAdapterOptions {
+    GPUPowerPreference powerPreference;
+};

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPU.cpp (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPU.cpp	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPU.cpp	2019-01-31 20:53:50 UTC (rev 240807)
@@ -28,6 +28,7 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPURequestAdapterOptions.h"
 #include "JSWebGPUAdapter.h"
 
 namespace WebCore {
@@ -37,9 +38,9 @@
     return adoptRef(*new WebGPU);
 }
 
-void WebGPU::requestAdapter(const WebGPUAdapterDescriptor& descriptor, WebGPUAdapterPromise&& deferred) const
+void WebGPU::requestAdapter(Optional<GPURequestAdapterOptions>&& options, WebGPUAdapterPromise&& deferred) const
 {
-    auto adapter = WebGPUAdapter::create(descriptor);
+    auto adapter = WebGPUAdapter::create(WTFMove(options));
     deferred.resolve(adapter.get());
 }
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPU.h (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPU.h	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPU.h	2019-01-31 20:53:50 UTC (rev 240807)
@@ -28,12 +28,13 @@
 #if ENABLE(WEBGPU)
 
 #include "JSDOMPromiseDeferred.h"
+#include <wtf/Optional.h>
 
 namespace WebCore {
 
 class WebGPUAdapter;
 
-struct WebGPUAdapterDescriptor;
+struct GPURequestAdapterOptions;
 
 class WebGPU : public RefCounted<WebGPU> {
 public:
@@ -41,7 +42,7 @@
 
     using WebGPUAdapterPromise = DOMPromiseDeferred<IDLInterface<WebGPUAdapter>>;
 
-    void requestAdapter(const WebGPUAdapterDescriptor&, WebGPUAdapterPromise&&) const;
+    void requestAdapter(Optional<GPURequestAdapterOptions>&&, WebGPUAdapterPromise&&) const;
 
 private:
     WebGPU() = default;

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPU.idl (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPU.idl	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPU.idl	2019-01-31 20:53:50 UTC (rev 240807)
@@ -29,5 +29,5 @@
     EnabledAtRuntime=WebGPU,
     ImplementationLacksVTable
 ] interface WebGPU {
-    Promise<WebGPUAdapter> requestAdapter(WebGPUAdapterDescriptor desc);
+    Promise<WebGPUAdapter> requestAdapter(optional GPURequestAdapterOptions options);
 };

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUAdapter.cpp (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUAdapter.cpp	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUAdapter.cpp	2019-01-31 20:53:50 UTC (rev 240807)
@@ -29,21 +29,18 @@
 #if ENABLE(WEBGPU)
 
 #include "ScriptExecutionContext.h"
-#include "WebGPUAdapterDescriptor.h"
 #include "WebGPUDevice.h"
 
 namespace WebCore {
 
-Ref<WebGPUAdapter> WebGPUAdapter::create(const WebGPUAdapterDescriptor& descriptor)
+Ref<WebGPUAdapter> WebGPUAdapter::create(Optional<GPURequestAdapterOptions>&& options)
 {
-    // FIXME: Validation on descriptor.
-    return adoptRef(*new WebGPUAdapter(descriptor));
+    return adoptRef(*new WebGPUAdapter(WTFMove(options)));
 }
 
-WebGPUAdapter::WebGPUAdapter(const WebGPUAdapterDescriptor& descriptor)
-    : m_descriptor(descriptor)
+WebGPUAdapter::WebGPUAdapter(Optional<GPURequestAdapterOptions>&& options)
+    : m_options(WTFMove(options))
 {
-    UNUSED_PARAM(m_descriptor);
 }
 
 RefPtr<WebGPUDevice> WebGPUAdapter::createDevice()

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUAdapter.h (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUAdapter.h	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUAdapter.h	2019-01-31 20:53:50 UTC (rev 240807)
@@ -27,6 +27,8 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPURequestAdapterOptions.h"
+#include <wtf/Optional.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 
@@ -35,18 +37,18 @@
 class ScriptExecutionContext;
 class WebGPUDevice;
 
-struct WebGPUAdapterDescriptor;
-
 class WebGPUAdapter : public RefCounted<WebGPUAdapter> {
 public:
-    static Ref<WebGPUAdapter> create(const WebGPUAdapterDescriptor&);
+    static Ref<WebGPUAdapter> create(Optional<GPURequestAdapterOptions>&&);
 
     RefPtr<WebGPUDevice> createDevice();
+    
+    Optional<GPURequestAdapterOptions> options() const { return m_options; }
 
 private:
-    WebGPUAdapter(const WebGPUAdapterDescriptor&);
+    explicit WebGPUAdapter(Optional<GPURequestAdapterOptions>&&);
 
-    const WebGPUAdapterDescriptor& m_descriptor;
+    Optional<GPURequestAdapterOptions> m_options;
 };
 
 } // namespace WebCore

Deleted: trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.h (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.h	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.h	2019-01-31 20:53:50 UTC (rev 240807)
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(WEBGPU)
-
-namespace WebCore {
-
-struct WebGPUAdapterDescriptor {
-    enum class PowerPreference {
-        Default,
-        LowPower,
-        HighPerformance
-    };
-
-    PowerPreference powerPreference = PowerPreference::Default;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(WEBGPU)

Deleted: trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.idl (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.idl	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.idl	2019-01-31 20:53:50 UTC (rev 240807)
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
-
-enum WebGPUPowerPreference {
-    "default",
-    "low-power",
-    "high-performance"
-};
-
-[
-    Conditional=WEBGPU,
-    EnabledAtRuntime=WebGPU
-] dictionary WebGPUAdapterDescriptor {
-    WebGPUPowerPreference powerPreference = "default";
-};

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (240806 => 240807)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2019-01-31 20:53:50 UTC (rev 240807)
@@ -58,7 +58,7 @@
 
 RefPtr<WebGPUDevice> WebGPUDevice::create(Ref<WebGPUAdapter>&& adapter)
 {
-    if (auto device = GPUDevice::create()) // FIXME: Take adapter into account when creating m_device.
+    if (auto device = GPUDevice::create(adapter->options()))
         return adoptRef(new WebGPUDevice(WTFMove(adapter), device.releaseNonNull()));
     return nullptr;
 }

Modified: trunk/Source/WebCore/Sources.txt (240806 => 240807)


--- trunk/Source/WebCore/Sources.txt	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/Sources.txt	2019-01-31 20:53:50 UTC (rev 240807)
@@ -2770,6 +2770,7 @@
 JSGlobalCrypto.cpp
 JSGlobalEventHandlers.cpp
 JSGlobalPerformance.cpp
+JSGPURequestAdapterOptions.cpp
 JSHTMLAllCollection.cpp
 JSHTMLAnchorElement.cpp
 JSHTMLAppletElement.cpp
@@ -3294,7 +3295,6 @@
 JSWebAnimation.cpp
 JSWebGPU.cpp
 JSWebGPUAdapter.cpp
-JSWebGPUAdapterDescriptor.cpp
 JSWebGPUBindGroup.cpp
 JSWebGPUBindGroupBinding.cpp
 JSWebGPUBindGroupDescriptor.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (240806 => 240807)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-01-31 20:53:50 UTC (rev 240807)
@@ -13948,8 +13948,7 @@
 		D0232B5821CB49B7009483B9 /* GPUBindGroupLayoutMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUBindGroupLayoutMetal.mm; sourceTree = "<group>"; };
 		D02454D021C4A41C00B73628 /* GPUBindGroupLayout.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBindGroupLayout.h; sourceTree = "<group>"; };
 		D02B83ED21C8397A00F85473 /* WebGPUBindGroupLayoutDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBindGroupLayoutDescriptor.idl; sourceTree = "<group>"; };
-		D02C26912181416D00D818E4 /* WebGPUAdapterDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUAdapterDescriptor.h; sourceTree = "<group>"; };
-		D02C26922181416D00D818E4 /* WebGPUAdapterDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUAdapterDescriptor.idl; sourceTree = "<group>"; };
+		D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPURequestAdapterOptions.idl; sourceTree = "<group>"; };
 		D02F854E21682A4A0088EE74 /* WebMetalCommandQueue.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebMetalCommandQueue.idl; sourceTree = "<group>"; };
 		D02F855021682A560088EE74 /* WebMetalComputeCommandEncoder.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = WebMetalComputeCommandEncoder.idl; sourceTree = "<group>"; };
 		D02F855121682A560088EE74 /* WebMetalComputePipelineState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebMetalComputePipelineState.h; sourceTree = "<group>"; };
@@ -14043,6 +14042,7 @@
 		D063AE4721C06626000E6A35 /* WebGPUInputStepMode.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUInputStepMode.idl; sourceTree = "<group>"; };
 		D063AE4821C066DB000E6A35 /* WebGPUIndexFormat.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUIndexFormat.h; sourceTree = "<group>"; };
 		D063AE4921C066DB000E6A35 /* WebGPUIndexFormat.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUIndexFormat.idl; sourceTree = "<group>"; };
+		D06A9A2122026C7A0083C662 /* GPURequestAdapterOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPURequestAdapterOptions.h; sourceTree = "<group>"; };
 		D06C0D8D0CFD11460065F43F /* RemoveFormatCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RemoveFormatCommand.h; sourceTree = "<group>"; };
 		D06C0D8E0CFD11460065F43F /* RemoveFormatCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RemoveFormatCommand.cpp; sourceTree = "<group>"; };
 		D07DEAB70A36554A00CA30F8 /* InsertListCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = InsertListCommand.cpp; sourceTree = "<group>"; };
@@ -18464,6 +18464,7 @@
 				D03211CE21AC954E00763CF2 /* GPURenderPassEncoder.h */,
 				312FF8B921A4C2EF00EB199D /* GPURenderPipeline.h */,
 				312FF8BC21A4C2F000EB199D /* GPURenderPipelineDescriptor.h */,
+				D06A9A2122026C7A0083C662 /* GPURequestAdapterOptions.h */,
 				312FF8BB21A4C2F000EB199D /* GPUShaderModule.h */,
 				312FF8C021A4C2F200EB199D /* GPUShaderModuleDescriptor.h */,
 				312FF8BA21A4C2EF00EB199D /* GPUSwapChain.h */,
@@ -26031,6 +26032,7 @@
 				D00F5942216ECC7A000D71DB /* DOMWindowWebGPU.idl */,
 				D03C849E21FFCF000002227F /* GPUCompareFunction.idl */,
 				D03C84A221FFD7230002227F /* GPUDepthStencilStateDescriptor.idl */,
+				D02C26922181416D00D818E4 /* GPURequestAdapterOptions.idl */,
 				D00F5947216EFE54000D71DB /* WebGPU.cpp */,
 				D00F5946216EFE54000D71DB /* WebGPU.h */,
 				D00F5948216EFE54000D71DB /* WebGPU.idl */,
@@ -26037,8 +26039,6 @@
 				D00F5950216FFAC2000D71DB /* WebGPUAdapter.cpp */,
 				D00F594F216FFAC2000D71DB /* WebGPUAdapter.h */,
 				D00F5951216FFAC2000D71DB /* WebGPUAdapter.idl */,
-				D02C26912181416D00D818E4 /* WebGPUAdapterDescriptor.h */,
-				D02C26922181416D00D818E4 /* WebGPUAdapterDescriptor.idl */,
 				D0BE106121E6C0EB00E42A89 /* WebGPUBindGroup.cpp */,
 				D0BE106021E6C0EB00E42A89 /* WebGPUBindGroup.h */,
 				D0BE106221E6C0EB00E42A89 /* WebGPUBindGroup.idl */,

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h (240806 => 240807)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2019-01-31 20:53:50 UTC (rev 240807)
@@ -28,6 +28,7 @@
 #if ENABLE(WEBGPU)
 
 #include "GPUQueue.h"
+#include <wtf/Optional.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
@@ -50,11 +51,12 @@
 struct GPUBufferDescriptor;
 struct GPUPipelineLayoutDescriptor;
 struct GPURenderPipelineDescriptor;
+struct GPURequestAdapterOptions;
 struct GPUShaderModuleDescriptor;
 
 class GPUDevice : public RefCounted<GPUDevice> {
 public:
-    static RefPtr<GPUDevice> create();
+    static RefPtr<GPUDevice> create(Optional<GPURequestAdapterOptions>&&);
 
     RefPtr<GPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
 

Copied: trunk/Source/WebCore/platform/graphics/gpu/GPURequestAdapterOptions.h (from rev 240806, trunk/Source/WebCore/Modules/webgpu/WebGPUAdapterDescriptor.h) (0 => 240807)


--- trunk/Source/WebCore/platform/graphics/gpu/GPURequestAdapterOptions.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPURequestAdapterOptions.h	2019-01-31 20:53:50 UTC (rev 240807)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+
+struct GPURequestAdapterOptions {
+    enum class PowerPreference {
+        LowPower,
+        HighPerformance
+    };
+    
+    PowerPreference powerPreference;
+};
+    
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm (240806 => 240807)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm	2019-01-31 20:15:48 UTC (rev 240806)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUDeviceMetal.mm	2019-01-31 20:53:50 UTC (rev 240807)
@@ -28,6 +28,7 @@
 
 #if ENABLE(WEBGPU)
 
+#import "GPURequestAdapterOptions.h"
 #import "Logging.h"
 
 #import <Metal/Metal.h>
@@ -35,23 +36,35 @@
 
 namespace WebCore {
 
-RefPtr<GPUDevice> GPUDevice::create()
+RefPtr<GPUDevice> GPUDevice::create(Optional<GPURequestAdapterOptions>&& options)
 {
-    PlatformDeviceSmartPtr device;
+    PlatformDeviceSmartPtr devicePtr;
 
     BEGIN_BLOCK_OBJC_EXCEPTIONS;
+    
+    if (options && options->powerPreference == GPURequestAdapterOptions::PowerPreference::LowPower) {
+        auto devices = adoptNS(MTLCopyAllDevices());
+        
+        for (id <MTLDevice> device : devices.get()) {
+            if (device.lowPower) {
+                devicePtr = retainPtr(device);
+                break;
+            }
+        }
+    }
+    
+    if (!devicePtr)
+        devicePtr = adoptNS(MTLCreateSystemDefaultDevice());
 
-    device = adoptNS(MTLCreateSystemDefaultDevice()); // FIXME: Take WebGPUPowerPreference into account.
-
     END_BLOCK_OBJC_EXCEPTIONS;
 
-    if (!device) {
+    if (!devicePtr) {
         LOG(WebGPU, "GPUDevice::GPUDevice(): Unable to create GPUDevice!");
         return nullptr;
     }
 
-    LOG(WebGPU, "GPUDevice::GPUDevice(): MTLDevice is %p", device.get());
-    return adoptRef(new GPUDevice(WTFMove(device)));
+    LOG(WebGPU, "GPUDevice::GPUDevice(): MTLDevice is %p", devicePtr.get());
+    return adoptRef(new GPUDevice(WTFMove(devicePtr)));
 }
 
 GPUDevice::GPUDevice(PlatformDeviceSmartPtr&& device)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to