Skip to content
Permalink
Browse files
[WebGPU] Move 'gpu' API entry point from DOMWindow to Navigator
https://bugs.webkit.org/show_bug.cgi?id=197348

Reviewed by Myles C. Maxfield.

Source/WebCore:

Latest API provides 'gpu' through Navigator instead of DOMWindow. Replace DOMWindowWebGPU with NavigatorGPU.

Existing tests updated to match. Add test: webgpu-enabled-in-worker.html to ensure workers can access WebGPU.

* CMakeLists.txt:
* DerivedSources.make:
* Modules/webgpu/NavigatorGPU.cpp:
(WebCore::NavigatorGPU::from):
(WebCore::NavigatorGPU::supplementName):
(WebCore::NavigatorGPU::gpu):
(WebCore::NavigatorGPU::gpu const):
* Modules/webgpu/NavigatorGPU.h:
* Modules/webgpu/NavigatorGPU.idl:
* Modules/webgpu/WorkerNavigatorGPU.cpp:
(WebCore::WorkerNavigatorGPU::from):
(WebCore::WorkerNavigatorGPU::supplementName):
(WebCore::WorkerNavigatorGPU::gpu):
(WebCore::WorkerNavigatorGPU::gpu const):
* Modules/webgpu/WorkerNavigatorGPU.h:
* Modules/webgpu/WorkerNavigatorGPU.idl:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

LayoutTests:

WebGPU is now accessed through navigator.gpu instead of window.gpu.
Add webgpu-enabled-in-worker to ensure workers can access WebGPU.

* webgpu/adapter-options.html:
* webgpu/js/create-worker-device.js: Added.
(async.tryCreateDevice):
* webgpu/js/webgpu-functions.js:
(async.getBasicDevice):
* webgpu/queue-creation.html:
* webgpu/webgpu-enabled-in-worker-expected.txt: Added.
* webgpu/webgpu-enabled-in-worker.html: Added.
* webgpu/webgpu-enabled.html:
* webgpu/whlsl.html:

Add navigator.gpu to expectations for navigator-detached-no-crash.
* fast/dom/navigator-detached-no-crash-expected.txt:
* platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt:
* platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt:


Canonical link: https://commits.webkit.org/211602@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244777 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Justin Fan committed Apr 30, 2019
1 parent 4cd3193 commit 5ef00cf871790822f9e4dbda80540bd1df34c17d
Showing 23 changed files with 306 additions and 51 deletions.
@@ -1,3 +1,29 @@
2019-04-30 Justin Fan <justin_fan@apple.com>

[WebGPU] Move 'gpu' API entry point from DOMWindow to Navigator
https://bugs.webkit.org/show_bug.cgi?id=197348

Reviewed by Myles C. Maxfield.

WebGPU is now accessed through navigator.gpu instead of window.gpu.
Add webgpu-enabled-in-worker to ensure workers can access WebGPU.

* webgpu/adapter-options.html:
* webgpu/js/create-worker-device.js: Added.
(async.tryCreateDevice):
* webgpu/js/webgpu-functions.js:
(async.getBasicDevice):
* webgpu/queue-creation.html:
* webgpu/webgpu-enabled-in-worker-expected.txt: Added.
* webgpu/webgpu-enabled-in-worker.html: Added.
* webgpu/webgpu-enabled.html:
* webgpu/whlsl.html:

Add navigator.gpu to expectations for navigator-detached-no-crash.
* fast/dom/navigator-detached-no-crash-expected.txt:
* platform/mac-highsierra/fast/dom/navigator-detached-no-crash-expected.txt:
* platform/mac-wk2/fast/dom/navigator-detached-no-crash-expected.txt:

2019-04-30 Youenn Fablet <youenn@apple.com>

Update WPT service-worker resource-timing test to use hosts[alt]
@@ -8,6 +8,7 @@ navigator.appVersion is OK
navigator.cookieEnabled is OK
navigator.credentials is OK
navigator.getStorageUpdates() is OK
navigator.gpu is OK
navigator.javaEnabled() is OK
navigator.language is OK
navigator.languages is OK
@@ -33,6 +34,7 @@ navigator.appVersion is OK
navigator.cookieEnabled is OK
navigator.credentials is OK
navigator.getStorageUpdates() is OK
navigator.gpu is OK
navigator.javaEnabled() is OK
navigator.language is OK
navigator.languages is OK
@@ -7,6 +7,7 @@ navigator.appVersion is OK
navigator.cookieEnabled is OK
navigator.credentials is OK
navigator.getStorageUpdates() is OK
navigator.gpu is OK
navigator.javaEnabled() is OK
navigator.language is OK
navigator.languages is OK
@@ -30,6 +31,7 @@ navigator.appVersion is OK
navigator.cookieEnabled is OK
navigator.credentials is OK
navigator.getStorageUpdates() is OK
navigator.gpu is OK
navigator.javaEnabled() is OK
navigator.language is OK
navigator.languages is OK
@@ -8,6 +8,7 @@ navigator.appVersion is OK
navigator.cookieEnabled is OK
navigator.credentials is OK
navigator.getStorageUpdates() is OK
navigator.gpu is OK
navigator.javaEnabled() is OK
navigator.language is OK
navigator.languages is OK
@@ -32,6 +33,7 @@ navigator.appVersion is OK
navigator.cookieEnabled is OK
navigator.credentials is OK
navigator.getStorageUpdates() is OK
navigator.gpu is OK
navigator.javaEnabled() is OK
navigator.language is OK
navigator.languages is OK
@@ -6,21 +6,21 @@
<script src="../resources/testharnessreport.js"></script>
<script>
promise_test(async () => {
const defaultAdapter = await gpu.requestAdapter();
const defaultAdapter = await navigator.gpu.requestAdapter();
const device = await defaultAdapter.requestDevice();

assert_true(device instanceof WebGPUDevice, "Default device successfully created.");
}, "Create the default device.");

promise_test(async () => {
const lowPowerAdapter = await gpu.requestAdapter({ powerPreference: "low-power" });
const lowPowerAdapter = await navigator.gpu.requestAdapter({ powerPreference: "low-power" });
const device = await lowPowerAdapter.requestDevice();

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 gpu.requestAdapter({ powerPreference: "high-performance" });
const highPerfAdapter = await navigator.gpu.requestAdapter({ powerPreference: "high-performance" });
const device = await highPerfAdapter.requestDevice();

assert_true(device instanceof WebGPUDevice, "Device successfully created using high-performance option.");
@@ -0,0 +1,11 @@
async function tryCreateDevice() {
if (!navigator.gpu)
postMessage(false);

const adapter = await navigator.gpu.requestAdapter();
await adapter.requestDevice();

postMessage(true);
}

tryCreateDevice();
@@ -1,5 +1,5 @@
async function getBasicDevice() {
const adapter = await gpu.requestAdapter({ powerPreference: "low-power" });
const adapter = await navigator.gpu.requestAdapter({ powerPreference: "low-power" });
const device = await adapter.requestDevice();
return device;
}
@@ -9,12 +9,12 @@
'use strict';

promise_test(async t => {
assert_not_equals(window.gpu, undefined, "window.gpu exists");
assert_not_equals(navigator.gpu, undefined, "navigator.gpu exists");

const context = document.createElement("canvas").getContext("gpu");
assert_true(context instanceof GPUCanvasContext, "getContext returned a GPUCanvasContext.");

const adapter = await window.gpu.requestAdapter({});
const adapter = await navigator.gpu.requestAdapter({});
assert_true(adapter instanceof WebGPUAdapter, "requestAdapter returned a WebGPUAdapter.");

const device = await adapter.requestDevice();
@@ -0,0 +1,3 @@

PASS Test if WebGPU is enabled for workers.

@@ -0,0 +1,20 @@
<!DOCTYPE html><!-- webkit-test-runner [ experimental:WebGPUEnabled=true ] -->
<html>
<meta charset=utf-8>
<title>Test if WebGPU is enabled for workers.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script>
if (window.testRunner)
testRunner.waitUntilDone();

const worker = new Worker('js/create-worker-device.js');

worker.onmessage = event => {
test(() => { assert_true(event.data, "Create GPUDevice with a worker."); });

if (window.testRunner)
testRunner.notifyDone();
};
</script>
</html>
@@ -10,9 +10,10 @@
const context = canvas.getContext("gpu");
assert_true(context instanceof GPUCanvasContext, "Created GPUCanvasContext.");

assert_not_equals(window.gpu, undefined, "window.gpu is defined.");
assert_equals(window.gpu, undefined, "window.gpu should not be defined.")
assert_not_equals(navigator.gpu, undefined, "navigator.gpu is defined.");

const adapter = await window.gpu.requestAdapter();
const adapter = await navigator.gpu.requestAdapter();
assert_true(adapter instanceof WebGPUAdapter, "Created default GPUAdapter.");

const device = await adapter.requestDevice();
@@ -15,7 +15,7 @@
}
`;
async function start() {
const adapter = await window.gpu.requestAdapter();
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();

const shaderModule = device.createShaderModule({code: shaderSource, isWHLSL: true});
@@ -468,7 +468,6 @@ set(WebCore_NON_SVG_IDL_FILES

Modules/webdriver/NavigatorWebDriver.idl

Modules/webgpu/DOMWindowWebGPU.idl
Modules/webgpu/GPUBindGroupLayoutBinding.idl
Modules/webgpu/GPUBindGroupLayoutDescriptor.idl
Modules/webgpu/GPUBlendDescriptor.idl
@@ -493,6 +492,7 @@ set(WebCore_NON_SVG_IDL_FILES
Modules/webgpu/GPUTextureUsage.idl
Modules/webgpu/GPUVertexAttributeDescriptor.idl
Modules/webgpu/GPUVertexInputDescriptor.idl
Modules/webgpu/NavigatorGPU.idl
Modules/webgpu/WebGPU.idl
Modules/webgpu/WebGPUAdapter.idl
Modules/webgpu/WebGPUBindGroup.idl
@@ -523,6 +523,7 @@ set(WebCore_NON_SVG_IDL_FILES
Modules/webgpu/WebGPUSwapChain.idl
Modules/webgpu/WebGPUTexture.idl
Modules/webgpu/WebGPUTextureView.idl
Modules/webgpu/WorkerNavigatorGPU.idl

Modules/websockets/CloseEvent.idl
Modules/websockets/WebSocket.idl
@@ -1,3 +1,33 @@
2019-04-30 Justin Fan <justin_fan@apple.com>

[WebGPU] Move 'gpu' API entry point from DOMWindow to Navigator
https://bugs.webkit.org/show_bug.cgi?id=197348

Reviewed by Myles C. Maxfield.

Latest API provides 'gpu' through Navigator instead of DOMWindow. Replace DOMWindowWebGPU with NavigatorGPU.

Existing tests updated to match. Add test: webgpu-enabled-in-worker.html to ensure workers can access WebGPU.

* CMakeLists.txt:
* DerivedSources.make:
* Modules/webgpu/NavigatorGPU.cpp:
(WebCore::NavigatorGPU::from):
(WebCore::NavigatorGPU::supplementName):
(WebCore::NavigatorGPU::gpu):
(WebCore::NavigatorGPU::gpu const):
* Modules/webgpu/NavigatorGPU.h:
* Modules/webgpu/NavigatorGPU.idl:
* Modules/webgpu/WorkerNavigatorGPU.cpp:
(WebCore::WorkerNavigatorGPU::from):
(WebCore::WorkerNavigatorGPU::supplementName):
(WebCore::WorkerNavigatorGPU::gpu):
(WebCore::WorkerNavigatorGPU::gpu const):
* Modules/webgpu/WorkerNavigatorGPU.h:
* Modules/webgpu/WorkerNavigatorGPU.idl:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

2019-04-30 Zalan Bujtas <zalan@apple.com>

Double-tapping a post to like doesn't work on Instagram.com (needs 'dblclick' event)
@@ -374,7 +374,6 @@ JS_BINDING_IDLS = \
$(WebCore)/Modules/webdatabase/SQLTransactionCallback.idl \
$(WebCore)/Modules/webdatabase/SQLTransactionErrorCallback.idl \
$(WebCore)/Modules/webdriver/NavigatorWebDriver.idl \
$(WebCore)/Modules/webgpu/DOMWindowWebGPU.idl \
$(WebCore)/Modules/webgpu/GPUCanvasContext.idl \
$(WebCore)/Modules/webgpu/GPUColor.idl \
$(WebCore)/Modules/webgpu/GPUColorStateDescriptor.idl \
@@ -399,6 +398,7 @@ JS_BINDING_IDLS = \
$(WebCore)/Modules/webgpu/GPUTextureUsage.idl \
$(WebCore)/Modules/webgpu/GPUVertexAttributeDescriptor.idl \
$(WebCore)/Modules/webgpu/GPUVertexInputDescriptor.idl \
$(WebCore)/Modules/webgpu/NavigatorGPU.idl \
$(WebCore)/Modules/webgpu/WebGPU.idl \
$(WebCore)/Modules/webgpu/WebGPUAdapter.idl \
$(WebCore)/Modules/webgpu/WebGPUBindGroup.idl \
@@ -429,6 +429,7 @@ JS_BINDING_IDLS = \
$(WebCore)/Modules/webgpu/WebGPUSwapChain.idl \
$(WebCore)/Modules/webgpu/WebGPUTexture.idl \
$(WebCore)/Modules/webgpu/WebGPUTextureView.idl \
$(WebCore)/Modules/webgpu/WorkerNavigatorGPU.idl \
$(WebCore)/Modules/websockets/CloseEvent.idl \
$(WebCore)/Modules/websockets/WebSocket.idl \
$(WebCore)/Modules/webvr/DOMWindowWebVR.idl \
@@ -24,47 +24,42 @@
*/

#include "config.h"
#include "DOMWindowWebGPU.h"
#include "NavigatorGPU.h"

#if ENABLE(WEBGPU)

#include "DOMWindow.h"
#include "Navigator.h"
#include "RuntimeEnabledFeatures.h"
#include "WebGPU.h"

namespace WebCore {

DOMWindowWebGPU::DOMWindowWebGPU(DOMWindow* window)
: DOMWindowProperty(window)
NavigatorGPU* NavigatorGPU::from(Navigator* navigator)
{
}

const char* DOMWindowWebGPU::supplementName()
{
return "DOMWindowWebGPU";
}

DOMWindowWebGPU* DOMWindowWebGPU::from(DOMWindow* window)
{
DOMWindowWebGPU* supplement = static_cast<DOMWindowWebGPU*>(Supplement<DOMWindow>::from(window, supplementName()));
NavigatorGPU* supplement = static_cast<NavigatorGPU*>(Supplement<Navigator>::from(navigator, supplementName()));
if (!supplement) {
auto newSupplement = std::make_unique<DOMWindowWebGPU>(window);
auto newSupplement = std::make_unique<NavigatorGPU>();
supplement = newSupplement.get();
provideTo(window, supplementName(), WTFMove(newSupplement));
provideTo(navigator, supplementName(), WTFMove(newSupplement));
}
return supplement;
}

WebGPU* DOMWindowWebGPU::gpu(DOMWindow& window)
const char* NavigatorGPU::supplementName()
{
return "NavigatorGPU";
}

const WebGPU* NavigatorGPU::gpu(Navigator& navigator)
{
return DOMWindowWebGPU::from(&window)->gpu();
return NavigatorGPU::from(&navigator)->gpu();
}

WebGPU* DOMWindowWebGPU::gpu() const
const WebGPU* NavigatorGPU::gpu() const
{
ASSERT(RuntimeEnabledFeatures::sharedFeatures().webGPUEnabled());

if (!m_gpu && frame())
if (!m_gpu)
m_gpu = WebGPU::create();
return m_gpu.get();
}
@@ -27,25 +27,23 @@

#if ENABLE(WEBGPU)

#include "DOMWindowProperty.h"
#include "Supplementable.h"

namespace WebCore {

class DOMWindow;
class Navigator;
class WebGPU;

class DOMWindowWebGPU : public Supplement<DOMWindow>, public DOMWindowProperty {
class NavigatorGPU final : public Supplement<Navigator> {
WTF_MAKE_FAST_ALLOCATED;
public:
explicit DOMWindowWebGPU(DOMWindow*);
virtual ~DOMWindowWebGPU() = default;
static DOMWindowWebGPU* from(DOMWindow*);
static WebGPU* gpu(DOMWindow&);
WebGPU* gpu() const;
static const WebGPU* gpu(Navigator&);

private:
static NavigatorGPU* from(Navigator*);
static const char* supplementName();

const WebGPU* gpu() const;

mutable RefPtr<WebGPU> m_gpu;
};
@@ -0,0 +1,33 @@
/*
* 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/spec/index.bs

[
Conditional=WEBGPU,
EnabledAtRuntime=WebGPU,
Exposed=Window
] partial interface Navigator {
[SameObject] readonly attribute WebGPU gpu;
};

0 comments on commit 5ef00cf

Please sign in to comment.