Title: [239094] trunk
Revision
239094
Author
justin_...@apple.com
Date
2018-12-11 17:40:06 -0800 (Tue, 11 Dec 2018)

Log Message

Source/WebCore:
[WebGPU] Implement WebGPUBuffer, and some nullibility consistency in WebGPU
https://bugs.webkit.org/show_bug.cgi?id=192516

Reviewed by Dean Jackson.

Test: webgpu/buffers.html

Enable basic creation of WebGPUBuffers, and fix nullability inconsitencies in WebGPU implementation.

Add necessary symbols and files for Web/GPUBuffer, Web/GPUBufferUsage, and Web/GPUBufferDescriptor:
* CMakeLists.txt:
* DerivedSources.make:
* Sources.txt:
* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:

* Modules/webgpu/WebGPUBuffer.cpp: Added.
(WebCore::WebGPUBuffer::create):
(WebCore::WebGPUBuffer::WebGPUBuffer):
* Modules/webgpu/WebGPUBuffer.h: Added.
(WebCore::WebGPUBuffer::mapping const):
(WebCore::WebGPUBuffer::unmap): Unimplemented stub, for now, as Metal equivalent is unclear.
(WebCore::WebGPUBuffer::destroy): Unimplemented stub.
* Modules/webgpu/WebGPUBuffer.idl: Added.
* Modules/webgpu/WebGPUBufferDescriptor.h: Added.
* Modules/webgpu/WebGPUBufferDescriptor.idl: Added.
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::createBuffer const): Added.
* platform/graphics/gpu/GPUBuffer.h:
(WebCore::GPUBuffer::platformBuffer const):
(WebCore::GPUBuffer::mapping const):
* platform/graphics/gpu/GPUBufferDescriptor.h: Added.
* platform/graphics/gpu/GPUDevice.cpp:
(WebCore::GPUDevice::createBuffer const): Added.
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/cocoa/GPUBufferMetal.mm: Added.
(WebCore::GPUBuffer::create): Attempt to create a page-aligned Gigacage to back the GPUBuffer's ArrayBuffer.
(WebCore::GPUBuffer::GPUBuffer):
(WebCore::GPUBuffer::~GPUBuffer): Dereference mapped ArrayBuffer first.

Small benign edits, most to make nullability more consistent in WebGPU classes:
* Modules/webgpu/WebGPUCommandBuffer.cpp:
(WebCore::WebGPUCommandBuffer::create):
(WebCore::WebGPUCommandBuffer::beginRenderPass):
* Modules/webgpu/WebGPUCommandBuffer.h:
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::create):
(WebCore::WebGPUDevice::WebGPUDevice):
(WebCore::WebGPUDevice::createShaderModule const):
(WebCore::WebGPUDevice::createRenderPipeline const):
(WebCore::WebGPUDevice::createCommandBuffer const):
* Modules/webgpu/WebGPUDevice.h:
(WebCore::WebGPUDevice::device const):
* Modules/webgpu/WebGPUDevice.idl:
* Modules/webgpu/WebGPUQueue.cpp:
(WebCore::WebGPUQueue::create):
* Modules/webgpu/WebGPURenderPassEncoder.cpp:
(WebCore::WebGPURenderPassEncoder::create):
* Modules/webgpu/WebGPURenderPassEncoder.h:
* Modules/webgpu/WebGPUShaderModule.cpp:
(WebCore::WebGPUShaderModule::create):
(WebCore::WebGPUShaderModule::WebGPUShaderModule):
* Modules/webgpu/WebGPUShaderModule.h:
(WebCore::WebGPUShaderModule::module const):
* Modules/webgpu/WebGPUSwapChain.idl: Sync with IDL changes.
* Modules/webgpu/WebGPUTexture.cpp:
(WebCore::WebGPUTexture::create):
(WebCore::WebGPUTexture::createDefaultTextureView):
* Modules/webgpu/WebGPUTextureView.cpp:
(WebCore::WebGPUTextureView::create):
* Modules/webgpu/WebGPUTextureView.h:
* platform/graphics/gpu/cocoa/GPUQueueMetal.mm:
(WebCore::GPUQueue::create):
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::GPURenderPipeline::create):
* platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm:
(WebCore::GPUShaderModule::create):
* platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm:
(WebCore::GPUSwapChain::setDevice):
* platform/graphics/gpu/cocoa/GPUTextureMetal.mm:
(WebCore::GPUTexture::GPUTexture):

LayoutTests:
[WebGPU] Implement WebGPUBuffer
https://bugs.webkit.org/show_bug.cgi?id=192516

Reviewed by Dean Jackson.

Basic test to create a WebGPUBuffer and ensure that its memory is valid.

* webgpu/buffers-expected.txt: Added.
* webgpu/buffers.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (239093 => 239094)


--- trunk/LayoutTests/ChangeLog	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/LayoutTests/ChangeLog	2018-12-12 01:40:06 UTC (rev 239094)
@@ -1,3 +1,15 @@
+2018-12-11  Justin Fan  <justin_...@apple.com>
+
+        [WebGPU] Implement WebGPUBuffer
+        https://bugs.webkit.org/show_bug.cgi?id=192516
+
+        Reviewed by Dean Jackson.
+
+        Basic test to create a WebGPUBuffer and ensure that its memory is valid.
+
+        * webgpu/buffers-expected.txt: Added.
+        * webgpu/buffers.html: Added.
+
 2018-12-11  Brent Fulgham  <bfulg...@apple.com>
 
         Don't attempt to compute animated values when there is no relevant animation

Added: trunk/LayoutTests/webgpu/buffers-expected.txt (0 => 239094)


--- trunk/LayoutTests/webgpu/buffers-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgpu/buffers-expected.txt	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,4 @@
+PASS [object WebGPU] is defined.
+
+PASS createBuffer() on WebGPUDevice. 
+

Added: trunk/LayoutTests/webgpu/buffers.html (0 => 239094)


--- trunk/LayoutTests/webgpu/buffers.html	                        (rev 0)
+++ trunk/LayoutTests/webgpu/buffers.html	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,31 @@
+<!DOCTYPE html><!-- webkit-test-runner [ experimental:WebGPUEnabled=true ] -->
+<meta charset=utf-8>
+<title>Get the WebGPUDevice, create a WebGPUBuffer, and write vertex data to it.</title>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script>
+function createBuffer() {
+    const buffer = defaultDevice.createBuffer({ size: 16, usage: WebGPUBufferUsage.MAP_WRITE });
+    assert_true(buffer instanceof WebGPUBuffer, "createBuffer returned a WebGPUBuffer");
+    
+    let arrayBuffer = buffer.mapping;
+    let floatArray = new Float32Array(arrayBuffer);
+    assert_equals(floatArray.length, 4);
+
+    floatArray[0] = -1;
+    floatArray[1] = 1;
+    floatArray[2] = 0;
+    floatArray[3] = 1;
+}
+
+promise_test(async t => {
+    const canvas = document.createElement("canvas");
+    await setUpContexts(canvas);
+    createBuffer();
+}, "createBuffer() on WebGPUDevice.");
+
+</script>
+</body>

Modified: trunk/Source/WebCore/CMakeLists.txt (239093 => 239094)


--- trunk/Source/WebCore/CMakeLists.txt	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/CMakeLists.txt	2018-12-12 01:40:06 UTC (rev 239094)
@@ -458,6 +458,9 @@
     Modules/webgpu/WebGPU.idl
     Modules/webgpu/WebGPUAdapter.idl
     Modules/webgpu/WebGPUAdapterDescriptor.idl
+    Modules/webgpu/WebGPUBuffer.idl
+    Modules/webgpu/WebGPUBufferDescriptor.idl
+    Modules/webgpu/WebGPUBufferUsage.idl
     Modules/webgpu/WebGPUColor.idl
     Modules/webgpu/WebGPUCommandBuffer.idl
     Modules/webgpu/WebGPUDevice.idl

Modified: trunk/Source/WebCore/ChangeLog (239093 => 239094)


--- trunk/Source/WebCore/ChangeLog	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/ChangeLog	2018-12-12 01:40:06 UTC (rev 239094)
@@ -1,3 +1,88 @@
+2018-12-11  Justin Fan  <justin_...@apple.com>
+
+        [WebGPU] Implement WebGPUBuffer, and some nullibility consistency in WebGPU
+        https://bugs.webkit.org/show_bug.cgi?id=192516
+
+        Reviewed by Dean Jackson.
+
+        Test: webgpu/buffers.html
+
+        Enable basic creation of WebGPUBuffers, and fix nullability inconsitencies in WebGPU implementation.
+
+        Add necessary symbols and files for Web/GPUBuffer, Web/GPUBufferUsage, and Web/GPUBufferDescriptor:
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * Sources.txt:
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreBuiltinNames.h:
+
+        * Modules/webgpu/WebGPUBuffer.cpp: Added.
+        (WebCore::WebGPUBuffer::create):
+        (WebCore::WebGPUBuffer::WebGPUBuffer):
+        * Modules/webgpu/WebGPUBuffer.h: Added.
+        (WebCore::WebGPUBuffer::mapping const):
+        (WebCore::WebGPUBuffer::unmap): Unimplemented stub, for now, as Metal equivalent is unclear.
+        (WebCore::WebGPUBuffer::destroy): Unimplemented stub.
+        * Modules/webgpu/WebGPUBuffer.idl: Added.
+        * Modules/webgpu/WebGPUBufferDescriptor.h: Added.
+        * Modules/webgpu/WebGPUBufferDescriptor.idl: Added.
+        * Modules/webgpu/WebGPUDevice.cpp:
+        (WebCore::WebGPUDevice::createBuffer const): Added.
+        * platform/graphics/gpu/GPUBuffer.h:
+        (WebCore::GPUBuffer::platformBuffer const):
+        (WebCore::GPUBuffer::mapping const):
+        * platform/graphics/gpu/GPUBufferDescriptor.h: Added.
+        * platform/graphics/gpu/GPUDevice.cpp:
+        (WebCore::GPUDevice::createBuffer const): Added.
+        * platform/graphics/gpu/GPUDevice.h:
+        * platform/graphics/gpu/cocoa/GPUBufferMetal.mm: Added.
+        (WebCore::GPUBuffer::create): Attempt to create a page-aligned Gigacage to back the GPUBuffer's ArrayBuffer. 
+        (WebCore::GPUBuffer::GPUBuffer):
+        (WebCore::GPUBuffer::~GPUBuffer): Dereference mapped ArrayBuffer first.
+
+        Small benign edits, most to make nullability more consistent in WebGPU classes:
+        * Modules/webgpu/WebGPUCommandBuffer.cpp:
+        (WebCore::WebGPUCommandBuffer::create):
+        (WebCore::WebGPUCommandBuffer::beginRenderPass):
+        * Modules/webgpu/WebGPUCommandBuffer.h:
+        * Modules/webgpu/WebGPUDevice.cpp:
+        (WebCore::WebGPUDevice::create):
+        (WebCore::WebGPUDevice::WebGPUDevice):
+        (WebCore::WebGPUDevice::createShaderModule const):
+        (WebCore::WebGPUDevice::createRenderPipeline const):
+        (WebCore::WebGPUDevice::createCommandBuffer const):
+        * Modules/webgpu/WebGPUDevice.h:
+        (WebCore::WebGPUDevice::device const):
+        * Modules/webgpu/WebGPUDevice.idl:
+        * Modules/webgpu/WebGPUQueue.cpp:
+        (WebCore::WebGPUQueue::create):
+        * Modules/webgpu/WebGPURenderPassEncoder.cpp:
+        (WebCore::WebGPURenderPassEncoder::create):
+        * Modules/webgpu/WebGPURenderPassEncoder.h:
+        * Modules/webgpu/WebGPUShaderModule.cpp:
+        (WebCore::WebGPUShaderModule::create):
+        (WebCore::WebGPUShaderModule::WebGPUShaderModule):
+        * Modules/webgpu/WebGPUShaderModule.h:
+        (WebCore::WebGPUShaderModule::module const):
+        * Modules/webgpu/WebGPUSwapChain.idl: Sync with IDL changes.
+        * Modules/webgpu/WebGPUTexture.cpp:
+        (WebCore::WebGPUTexture::create):
+        (WebCore::WebGPUTexture::createDefaultTextureView):
+        * Modules/webgpu/WebGPUTextureView.cpp:
+        (WebCore::WebGPUTextureView::create):
+        * Modules/webgpu/WebGPUTextureView.h:
+        * platform/graphics/gpu/cocoa/GPUQueueMetal.mm:
+        (WebCore::GPUQueue::create):
+        * platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
+        (WebCore::GPURenderPipeline::create):
+        * platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm:
+        (WebCore::GPUShaderModule::create):
+        * platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm:
+        (WebCore::GPUSwapChain::setDevice):
+        * platform/graphics/gpu/cocoa/GPUTextureMetal.mm:
+        (WebCore::GPUTexture::GPUTexture):
+
 2018-12-11  Fujii Hironori  <hironori.fu...@sony.com>
 
         [Win][Clang] Fix warning -Wmissing-field-initializers

Modified: trunk/Source/WebCore/DerivedSources.make (239093 => 239094)


--- trunk/Source/WebCore/DerivedSources.make	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/DerivedSources.make	2018-12-12 01:40:06 UTC (rev 239094)
@@ -375,6 +375,9 @@
     $(WebCore)/Modules/webgpu/WebGPU.idl \
     $(WebCore)/Modules/webgpu/WebGPUAdapter.idl \
     $(WebCore)/Modules/webgpu/WebGPUAdapterDescriptor.idl \
+    $(WebCore)/Modules/webgpu/WebGPUBuffer.idl \
+    $(WebCore)/Modules/webgpu/WebGPUBufferDescriptor.idl \
+    $(WebCore)/Modules/webgpu/WebGPUBufferUsage.idl \
     $(WebCore)/Modules/webgpu/WebGPUColor.idl \
     $(WebCore)/Modules/webgpu/WebGPUCommandBuffer.idl \
     $(WebCore)/Modules/webgpu/WebGPUDevice.idl \

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp) (0 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,46 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "WebGPUBuffer.h"
+
+#if ENABLE(WEBGPU)
+
+namespace WebCore {
+
+RefPtr<WebGPUBuffer> WebGPUBuffer::create(Ref<GPUBuffer>&& buffer)
+{
+    return adoptRef(new WebGPUBuffer(WTFMove(buffer)));
+}
+
+WebGPUBuffer::WebGPUBuffer(Ref<GPUBuffer>&& buffer)
+    : m_buffer(WTFMove(buffer))
+{
+    UNUSED_PARAM(m_buffer);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.h (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h) (0 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,53 @@
+/*
+ * 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)
+
+#include "GPUBuffer.h"
+
+#include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+class WebGPUBuffer : public RefCounted<WebGPUBuffer> {
+public:
+    static RefPtr<WebGPUBuffer> create(Ref<GPUBuffer>&&);
+
+    JSC::ArrayBuffer* mapping() const { return m_buffer->mapping(); }
+    void unmap() { /* FIXME: Unimplemented stub. */ }
+    void destroy() { /* FIXME: Unimplemented stub. */ }
+
+private:
+    explicit WebGPUBuffer(Ref<GPUBuffer>&&);
+
+    Ref<GPUBuffer> m_buffer;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.idl (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp) (0 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBuffer.idl	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU,
+    ImplementationLacksVTable
+] interface WebGPUBuffer {
+    readonly attribute ArrayBuffer? mapping;
+    void unmap();
+
+    void destroy();
+};

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.h (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp) (0 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,40 @@
+/*
+ * 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)
+
+#include "GPUBufferDescriptor.h"
+
+namespace WebCore {
+
+using WebGPUBufferDescriptor = GPUBufferDescriptor;
+using WebGPUBufferUsageFlags = GPUBufferUsageFlags;
+using WebGPUBufferUsage = GPUBufferUsage;
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.idl (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp) (0 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.idl	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,36 @@
+/*
+ * 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
+
+typedef unsigned long u32;
+typedef u32 WebGPUBufferUsageFlags;
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU
+] dictionary WebGPUBufferDescriptor {
+    u32 size;
+    WebGPUBufferUsageFlags usage;
+};

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.h (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp) (0 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,38 @@
+/*
+ * 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)
+
+#include "GPUBufferDescriptor.h"
+
+namespace WebCore {
+
+using WebGPUBufferUsage = GPUBufferUsage;
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.idl (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl) (0 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.idl	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,42 @@
+/*
+ * 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
+
+[
+    Conditional=WEBGPU,
+    DoNotCheckConstants,
+    EnabledAtRuntime=WebGPU,
+    ImplementationLacksVTable
+] interface WebGPUBufferUsage {
+    const u32 NONE = 0;
+    const u32 MAP_READ = 1;
+    const u32 MAP_WRITE = 2;
+    const u32 TRANSFER_SRC = 4;
+    const u32 TRANSFER_DST = 8;
+    const u32 INDEX = 16;
+    const u32 VERTEX = 32;
+    const u32 UNIFORM = 64;
+    const u32 STORAGE = 128;
+};

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -37,12 +37,9 @@
 
 namespace WebCore {
 
-RefPtr<WebGPUCommandBuffer> WebGPUCommandBuffer::create(RefPtr<GPUCommandBuffer>&& buffer)
+RefPtr<WebGPUCommandBuffer> WebGPUCommandBuffer::create(Ref<GPUCommandBuffer>&& buffer)
 {
-    if (!buffer)
-        return nullptr;
-
-    return adoptRef(new WebGPUCommandBuffer(buffer.releaseNonNull()));
+    return adoptRef(new WebGPUCommandBuffer(WTFMove(buffer)));
 }
 
 WebGPUCommandBuffer::WebGPUCommandBuffer(Ref<GPUCommandBuffer>&& buffer)
@@ -69,11 +66,7 @@
     }
 
     auto encoder = GPURenderPassEncoder::create(m_commandBuffer.get(), WTFMove(gpuRenderPassDescriptor));
-
-    if (!encoder)
-        return nullptr;
-
-    return WebGPURenderPassEncoder::create(*this, encoder.releaseNonNull());
+    return encoder ? WebGPURenderPassEncoder::create(*this, encoder.releaseNonNull()) : nullptr;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -41,7 +41,7 @@
 
 class WebGPUCommandBuffer : public RefCounted<WebGPUCommandBuffer> {
 public:
-    static RefPtr<WebGPUCommandBuffer> create(RefPtr<GPUCommandBuffer>&&);
+    static RefPtr<WebGPUCommandBuffer> create(Ref<GPUCommandBuffer>&&);
 
     const GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -33,6 +33,7 @@
 #include "GPURenderPipelineDescriptor.h"
 #include "GPUShaderModuleDescriptor.h"
 #include "Logging.h"
+#include "WebGPUBuffer.h"
 #include "WebGPUCommandBuffer.h"
 #include "WebGPUPipelineStageDescriptor.h"
 #include "WebGPUQueue.h"
@@ -47,22 +48,28 @@
 RefPtr<WebGPUDevice> WebGPUDevice::create(Ref<WebGPUAdapter>&& adapter)
 {
     auto device = GPUDevice::create(); // FIXME: Take adapter into account when creating m_device.
-    if (!device)
-        return nullptr;
-
-    return adoptRef(new WebGPUDevice(WTFMove(adapter), WTFMove(device)));
+    return device ? adoptRef(new WebGPUDevice(WTFMove(adapter), device.releaseNonNull())) : nullptr;
 }
 
-WebGPUDevice::WebGPUDevice(Ref<WebGPUAdapter>&& adapter, RefPtr<GPUDevice>&& device)
+WebGPUDevice::WebGPUDevice(Ref<WebGPUAdapter>&& adapter, Ref<GPUDevice>&& device)
     : m_adapter(WTFMove(adapter))
-    , m_device(device)
+    , m_device(WTFMove(device))
 {
     UNUSED_PARAM(m_adapter);
 }
 
+RefPtr<WebGPUBuffer> WebGPUDevice::createBuffer(WebGPUBufferDescriptor&& descriptor) const
+{
+    // FIXME: Validation on descriptor needed?
+    auto buffer = m_device->createBuffer(GPUBufferDescriptor { descriptor.size, descriptor.usage });
+    return buffer ? WebGPUBuffer::create(buffer.releaseNonNull()) : nullptr;
+}
+
 RefPtr<WebGPUShaderModule> WebGPUDevice::createShaderModule(WebGPUShaderModuleDescriptor&& descriptor) const
 {
-    return WebGPUShaderModule::create(m_device->createShaderModule(GPUShaderModuleDescriptor { descriptor.code }));
+    // FIXME: What can be validated here?
+    auto module = m_device->createShaderModule(GPUShaderModuleDescriptor { descriptor.code });
+    return module ? WebGPUShaderModule::create(module.releaseNonNull()) : nullptr;
 }
 
 RefPtr<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(WebGPURenderPipelineDescriptor&& descriptor) const
@@ -118,16 +125,13 @@
     }
 
     auto pipeline = m_device->createRenderPipeline(GPURenderPipelineDescriptor { WTFMove(vertexStage), WTFMove(fragmentStage), descriptor.primitiveTopology });
-
-    if (!pipeline)
-        return nullptr;
-
-    return WebGPURenderPipeline::create(pipeline.releaseNonNull());
+    return pipeline ? WebGPURenderPipeline::create(pipeline.releaseNonNull()) : nullptr;
 }
 
 RefPtr<WebGPUCommandBuffer> WebGPUDevice::createCommandBuffer() const
 {
-    return WebGPUCommandBuffer::create(m_device->createCommandBuffer());
+    auto commandBuffer = m_device->createCommandBuffer();
+    return commandBuffer ? WebGPUCommandBuffer::create(commandBuffer.releaseNonNull()) : nullptr;
 }
 
 RefPtr<WebGPUQueue> WebGPUDevice::getQueue()

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -29,7 +29,9 @@
 
 #include "GPUDevice.h"
 #include "WebGPUAdapter.h"
+#include "WebGPUBufferDescriptor.h"
 #include "WebGPUQueue.h"
+
 #include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
@@ -37,6 +39,7 @@
 namespace WebCore {
 
 class ScriptExecutionContext;
+class WebGPUBuffer;
 class WebGPUCommandBuffer;
 class WebGPURenderPipeline;
 class WebGPUShaderModule;
@@ -49,8 +52,10 @@
     static RefPtr<WebGPUDevice> create(Ref<WebGPUAdapter>&&);
 
     const WebGPUAdapter& adapter() const { return m_adapter.get(); }
-    const GPUDevice& device() const { return *m_device; }
+    const GPUDevice& device() const { return m_device.get(); }
 
+    RefPtr<WebGPUBuffer> createBuffer(WebGPUBufferDescriptor&&) const;
+
     RefPtr<WebGPUShaderModule> createShaderModule(WebGPUShaderModuleDescriptor&&) const;
     RefPtr<WebGPURenderPipeline> createRenderPipeline(WebGPURenderPipelineDescriptor&&) const;
 
@@ -58,10 +63,10 @@
     RefPtr<WebGPUQueue> getQueue();
 
 private:
-    WebGPUDevice(Ref<WebGPUAdapter>&&, RefPtr<GPUDevice>&&);
+    WebGPUDevice(Ref<WebGPUAdapter>&&, Ref<GPUDevice>&&);
 
     Ref<WebGPUAdapter> m_adapter;
-    RefPtr<GPUDevice> m_device;
+    Ref<GPUDevice> m_device;
     RefPtr<WebGPUQueue> m_queue;
 };
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl	2018-12-12 01:40:06 UTC (rev 239094)
@@ -33,6 +33,8 @@
     // readonly attribute WebGPULimits limits;
     readonly attribute WebGPUAdapter adapter;
 
+    WebGPUBuffer createBuffer(WebGPUBufferDescriptor descriptor);
+
     WebGPUShaderModule createShaderModule(WebGPUShaderModuleDescriptor descriptor);
     WebGPURenderPipeline createRenderPipeline(WebGPURenderPipelineDescriptor descriptor);
 
@@ -42,7 +44,6 @@
     WebGPUQueue getQueue();
 
     // FIXME: Unimplemented.
-    // WebGPUBuffer createBuffer(WebGPUBufferDescriptor descriptor);
     // WebGPUTexture createTexture(WebGPUTextureDescriptor descriptor);
     // WebGPUSampler createSampler(WebGPUSamplerDescriptor descriptor);
     //

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -36,10 +36,7 @@
 
 RefPtr<WebGPUQueue> WebGPUQueue::create(RefPtr<GPUQueue>&& queue)
 {
-    if (!queue)
-        return nullptr;
-
-    return adoptRef(new WebGPUQueue(queue.releaseNonNull()));
+    return queue ? adoptRef(new WebGPUQueue(queue.releaseNonNull())) : nullptr;
 }
 
 WebGPUQueue::WebGPUQueue(Ref<GPUQueue>&& queue)

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -33,9 +33,9 @@
 
 namespace WebCore {
 
-Ref<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandBuffer>&& creator, Ref<GPURenderPassEncoder>&& encoder)
+RefPtr<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandBuffer>&& commandBuffer, Ref<GPURenderPassEncoder>&& encoder)
 {
-    return adoptRef(*new WebGPURenderPassEncoder(WTFMove(creator), WTFMove(encoder)));
+    return adoptRef(new WebGPURenderPassEncoder(WTFMove(commandBuffer), WTFMove(encoder)));
 }
 
 WebGPURenderPassEncoder::WebGPURenderPassEncoder(Ref<WebGPUCommandBuffer>&& creator, Ref<GPURenderPassEncoder>&& encoder)

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -38,7 +38,7 @@
 
 class WebGPURenderPassEncoder final : public WebGPUProgrammablePassEncoder {
 public:
-    static Ref<WebGPURenderPassEncoder> create(Ref<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
+    static RefPtr<WebGPURenderPassEncoder> create(Ref<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
 
     void draw(unsigned long, unsigned long, unsigned long, unsigned long);
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.cpp (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -30,15 +30,12 @@
 
 namespace WebCore {
 
-RefPtr<WebGPUShaderModule> WebGPUShaderModule::create(RefPtr<GPUShaderModule>&& module)
+RefPtr<WebGPUShaderModule> WebGPUShaderModule::create(Ref<GPUShaderModule>&& module)
 {
-    if (!module)
-        return nullptr;
-
     return adoptRef(new WebGPUShaderModule(WTFMove(module)));
 }
 
-WebGPUShaderModule::WebGPUShaderModule(RefPtr<GPUShaderModule>&& module)
+WebGPUShaderModule::WebGPUShaderModule(Ref<GPUShaderModule>&& module)
     : m_module(WTFMove(module))
 {
     UNUSED_PARAM(m_module);

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -29,21 +29,21 @@
 
 #include "GPUShaderModule.h"
 
-#include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
+#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
 class WebGPUShaderModule : public RefCounted<WebGPUShaderModule> {
 public:
-    static RefPtr<WebGPUShaderModule> create(RefPtr<GPUShaderModule>&&);
+    static RefPtr<WebGPUShaderModule> create(Ref<GPUShaderModule>&&);
 
-    const GPUShaderModule* module() const { return m_module.get(); }
+    const GPUShaderModule* module() const { return m_module.ptr(); }
 
 private:
-    WebGPUShaderModule(RefPtr<GPUShaderModule>&&);
+    WebGPUShaderModule(Ref<GPUShaderModule>&&);
 
-    RefPtr<GPUShaderModule> m_module;
+    Ref<GPUShaderModule> m_module;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl	2018-12-12 01:40:06 UTC (rev 239094)
@@ -40,7 +40,7 @@
     Conditional=WEBGPU,
     EnabledAtRuntime=WebGPU
 ] dictionary WebGPUSwapChainDescriptor {
-    WebGPUDevice device; // FIXME: Propose this addition to IDL.
+    WebGPUDevice? device;
     // WebGPUTextureUsageFlags usage;
     WebGPUTextureFormatEnum format;
     u32 width;

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -34,10 +34,7 @@
 
 RefPtr<WebGPUTexture> WebGPUTexture::create(RefPtr<GPUTexture>&& texture)
 {
-    if (!texture)
-        return nullptr;
-
-    return adoptRef(new WebGPUTexture(texture.releaseNonNull()));
+    return texture ? adoptRef(new WebGPUTexture(texture.releaseNonNull())) : nullptr;
 }
 
 WebGPUTexture::WebGPUTexture(Ref<GPUTexture>&& texture)
@@ -48,11 +45,7 @@
 RefPtr<WebGPUTextureView> WebGPUTexture::createDefaultTextureView()
 {
     auto gpuTexture = m_texture->createDefaultTextureView();
-
-    if (!gpuTexture)
-        return nullptr;
-
-    return WebGPUTextureView::create(gpuTexture.releaseNonNull());
+    return gpuTexture ? WebGPUTextureView::create(gpuTexture.releaseNonNull()) : nullptr;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -30,9 +30,9 @@
 
 namespace WebCore {
 
-Ref<WebGPUTextureView> WebGPUTextureView::create(Ref<GPUTexture>&& view)
+RefPtr<WebGPUTextureView> WebGPUTextureView::create(Ref<GPUTexture>&& view)
 {
-    return adoptRef(*new WebGPUTextureView(WTFMove(view)));
+    return adoptRef(new WebGPUTextureView(WTFMove(view)));
 }
 
 WebGPUTextureView::WebGPUTextureView(Ref<GPUTexture>&& view)

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.h (239093 => 239094)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.h	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUTextureView.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -35,7 +35,7 @@
 
 class WebGPUTextureView : public RefCounted<WebGPUTextureView> {
 public:
-    static Ref<WebGPUTextureView> create(Ref<GPUTexture>&&);
+    static RefPtr<WebGPUTextureView> create(Ref<GPUTexture>&&);
 
     Ref<GPUTexture> texture() { return m_texture.copyRef(); }
 private:

Modified: trunk/Source/WebCore/Sources.txt (239093 => 239094)


--- trunk/Source/WebCore/Sources.txt	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/Sources.txt	2018-12-12 01:40:06 UTC (rev 239094)
@@ -303,6 +303,7 @@
 Modules/webgpu/DOMWindowWebGPU.cpp
 Modules/webgpu/WebGPU.cpp
 Modules/webgpu/WebGPUAdapter.cpp
+Modules/webgpu/WebGPUBuffer.cpp
 Modules/webgpu/WebGPUCommandBuffer.cpp
 Modules/webgpu/WebGPUDevice.cpp
 Modules/webgpu/WebGPUQueue.cpp
@@ -3221,6 +3222,9 @@
 JSWebGPU.cpp
 JSWebGPUAdapter.cpp
 JSWebGPUAdapterDescriptor.cpp
+JSWebGPUBuffer.cpp
+JSWebGPUBufferDescriptor.cpp
+JSWebGPUBufferUsage.cpp
 JSWebGPUCommandBuffer.cpp
 JSWebGPUColor.cpp
 JSWebGPUDevice.cpp

Modified: trunk/Source/WebCore/SourcesCocoa.txt (239093 => 239094)


--- trunk/Source/WebCore/SourcesCocoa.txt	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/SourcesCocoa.txt	2018-12-12 01:40:06 UTC (rev 239094)
@@ -318,6 +318,7 @@
 platform/graphics/cv/TextureCacheCV.mm
 platform/graphics/cv/VideoTextureCopierCV.cpp
 
+platform/graphics/gpu/cocoa/GPUBufferMetal.mm
 platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm
 platform/graphics/gpu/cocoa/GPUDeviceMetal.mm
 platform/graphics/gpu/cocoa/GPUProgrammablePassEncoderMetal.mm

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (239093 => 239094)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2018-12-12 01:40:06 UTC (rev 239094)
@@ -4227,6 +4227,7 @@
 		D0B0556809C6700100307E43 /* CreateLinkCommand.h in Headers */ = {isa = PBXBuildFile; fileRef = D0B0556609C6700100307E43 /* CreateLinkCommand.h */; };
 		D0BC54491443AC4A00E105DA /* CachedStyleSheetClient.h in Headers */ = {isa = PBXBuildFile; fileRef = D0BC54481443AC4A00E105DA /* CachedStyleSheetClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		D0BD4F5D1408850F006839B6 /* DictationCommandIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = D0BD4F5B1408850F006839B6 /* DictationCommandIOS.h */; };
+		D0D8648421B61727003C983C /* WebGPUBufferDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = D0D8648221B61727003C983C /* WebGPUBufferDescriptor.h */; };
 		D0EDA775143E303C0028E383 /* CachedRawResource.h in Headers */ = {isa = PBXBuildFile; fileRef = D0EDA773143E303C0028E383 /* CachedRawResource.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		D0FF2A5E11F8C45A007E74E0 /* PingLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = D0FF2A5C11F8C45A007E74E0 /* PingLoader.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		D302754A12A5FE84004BD828 /* RenderDetailsMarker.h in Headers */ = {isa = PBXBuildFile; fileRef = D302754612A5FE84004BD828 /* RenderDetailsMarker.h */; };
@@ -13797,6 +13798,8 @@
 		D0615FCC217FE5C6008A48A8 /* WebGPUShaderModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUShaderModule.h; sourceTree = "<group>"; };
 		D0615FCD217FE5C6008A48A8 /* WebGPUShaderModule.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUShaderModule.cpp; sourceTree = "<group>"; };
 		D0615FCE217FE5C6008A48A8 /* WebGPUShaderModule.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUShaderModule.idl; sourceTree = "<group>"; };
+		D063AE4C21C07AB5000E6A35 /* WebGPUBufferUsage.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBufferUsage.idl; sourceTree = "<group>"; };
+		D063AE4E21C0810A000E6A35 /* WebGPUBufferUsage.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUBufferUsage.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>"; };
@@ -13842,6 +13845,14 @@
 		D0CAAE9C216824A7001C91C7 /* WebMetalComputeCommandEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebMetalComputeCommandEncoder.cpp; sourceTree = "<group>"; };
 		D0CAAE9D216824A7001C91C7 /* WebMetalBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebMetalBuffer.h; sourceTree = "<group>"; };
 		D0CAAE9E216824A8001C91C7 /* WebMetalCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebMetalCommandBuffer.cpp; sourceTree = "<group>"; };
+		D0D8648221B61727003C983C /* WebGPUBufferDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUBufferDescriptor.h; sourceTree = "<group>"; };
+		D0D8648321B61727003C983C /* WebGPUBufferDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBufferDescriptor.idl; sourceTree = "<group>"; };
+		D0D8648721B64CAA003C983C /* GPUBufferDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBufferDescriptor.h; sourceTree = "<group>"; };
+		D0D8648C21B70676003C983C /* WebGPUBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUBuffer.h; sourceTree = "<group>"; };
+		D0D8648D21B70676003C983C /* WebGPUBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUBuffer.cpp; sourceTree = "<group>"; };
+		D0D8648E21B70676003C983C /* WebGPUBuffer.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUBuffer.idl; sourceTree = "<group>"; };
+		D0D8649121B760C4003C983C /* GPUBufferMetal.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = GPUBufferMetal.mm; sourceTree = "<group>"; };
+		D0D8649221B760F2003C983C /* GPUBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUBuffer.h; sourceTree = "<group>"; };
 		D0DA0BE4217930E2007FE2AC /* WebGPUSwapChain.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUSwapChain.h; sourceTree = "<group>"; };
 		D0DA0BE5217930E2007FE2AC /* WebGPUSwapChain.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUSwapChain.cpp; sourceTree = "<group>"; };
 		D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUSwapChain.idl; sourceTree = "<group>"; };
@@ -18007,6 +18018,8 @@
 			children = (
 				D087CE3721ACA94200BDE174 /* cocoa */,
 				312FF8CE21A4C33F00EB199D /* legacy */,
+				D0D8649221B760F2003C983C /* GPUBuffer.h */,
+				D0D8648721B64CAA003C983C /* GPUBufferDescriptor.h */,
 				D001D9AB21B0C7BF0023B9BC /* GPUColor.h */,
 				312FF8BD21A4C2F100EB199D /* GPUCommandBuffer.h */,
 				312FF8BF21A4C2F100EB199D /* GPUDevice.cpp */,
@@ -25497,6 +25510,11 @@
 				D00F5951216FFAC2000D71DB /* WebGPUAdapter.idl */,
 				D02C26912181416D00D818E4 /* WebGPUAdapterDescriptor.h */,
 				D02C26922181416D00D818E4 /* WebGPUAdapterDescriptor.idl */,
+				D0D8648D21B70676003C983C /* WebGPUBuffer.cpp */,
+				D0D8648C21B70676003C983C /* WebGPUBuffer.h */,
+				D0D8648E21B70676003C983C /* WebGPUBuffer.idl */,
+				D0D8648221B61727003C983C /* WebGPUBufferDescriptor.h */,
+				D0D8648321B61727003C983C /* WebGPUBufferDescriptor.idl */,
 				D001D9AC21B0C81A0023B9BC /* WebGPUColor.h */,
 				D001D9AD21B0C81A0023B9BC /* WebGPUColor.idl */,
 				D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */,
@@ -25548,6 +25566,8 @@
 				D0EACF882193EE4E000FA75C /* WebGPUTextureView.cpp */,
 				D0EACF872193EE4E000FA75C /* WebGPUTextureView.h */,
 				D0EACF892193EE4E000FA75C /* WebGPUTextureView.idl */,
+				D063AE4C21C07AB5000E6A35 /* WebGPUBufferUsage.idl */,
+				D063AE4E21C0810A000E6A35 /* WebGPUBufferUsage.h */,
 			);
 			path = webgpu;
 			sourceTree = "<group>";
@@ -25555,6 +25575,7 @@
 		D087CE3721ACA94200BDE174 /* cocoa */ = {
 			isa = PBXGroup;
 			children = (
+				D0D8649121B760C4003C983C /* GPUBufferMetal.mm */,
 				D087CE3821ACA94200BDE174 /* GPUCommandBufferMetal.mm */,
 				D087CE3C21ACA94200BDE174 /* GPUDeviceMetal.mm */,
 				D087CE3B21ACA94200BDE174 /* GPUProgrammablePassEncoderMetal.mm */,
@@ -31664,6 +31685,7 @@
 				0C3F1F5B10C8871200D72CE1 /* WebGLUniformLocation.h in Headers */,
 				6F995A261A7078B100A735F4 /* WebGLVertexArrayObject.h in Headers */,
 				77A17A7812F28642004E02F6 /* WebGLVertexArrayObjectOES.h in Headers */,
+				D0D8648421B61727003C983C /* WebGPUBufferDescriptor.h in Headers */,
 				318436DE21B9DAAF00ED383E /* WebGPULayer.h in Headers */,
 				A5B81CB71FAA44620037D1E6 /* WebHeapAgent.h in Headers */,
 				A5840E25187B8AC200843B10 /* WebInjectedScriptHost.h in Headers */,

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (239093 => 239094)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -189,8 +189,10 @@
     macro(WebGLVertexArrayObject) \
     macro(WebGPU) \
     macro(WebGPUAdapter) \
+    macro(WebGPUBuffer) \
+    macro(WebGPUBufferUsage) \
+    macro(WebGPUCommandBuffer) \
     macro(WebGPUDevice) \
-    macro(WebGPUCommandBuffer) \
     macro(WebGPUQueue) \
     macro(WebGPUProgrammablePassEncoder) \
     macro(WebGPURenderingContext) \

Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUBuffer.h (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h) (0 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUBuffer.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUBuffer.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,68 @@
+/*
+ * 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)
+
+#include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
+
+OBJC_PROTOCOL(MTLBuffer);
+
+namespace JSC {
+class ArrayBuffer;
+}
+
+namespace WebCore {
+
+class GPUDevice;
+
+struct GPUBufferDescriptor;
+
+using PlatformBuffer = MTLBuffer;
+using PlatformBufferSmartPtr = RetainPtr<MTLBuffer>;
+
+class GPUBuffer : public RefCounted<GPUBuffer> {
+public:
+    ~GPUBuffer();
+
+    static RefPtr<GPUBuffer> create(const GPUDevice&, GPUBufferDescriptor&&);
+
+    PlatformBuffer *platformBuffer() const { return m_platformBuffer.get(); }
+
+    JSC::ArrayBuffer* mapping() const { return m_mapping.get(); }
+
+private:
+    explicit GPUBuffer(PlatformBufferSmartPtr&&, RefPtr<JSC::ArrayBuffer>&&);
+
+    PlatformBufferSmartPtr m_platformBuffer;
+    RefPtr<JSC::ArrayBuffer> m_mapping;
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Copied: trunk/Source/WebCore/platform/graphics/gpu/GPUBufferDescriptor.h (from rev 239093, trunk/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h) (0 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUBufferDescriptor.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUBufferDescriptor.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,58 @@
+/*
+ * 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)
+
+#include <wtf/RefCounted.h>
+
+namespace WebCore {
+
+using GPUBufferUsageFlags = unsigned long;
+
+struct GPUBufferDescriptor {
+    unsigned long size;
+    GPUBufferUsageFlags usage;
+};
+
+class GPUBufferUsage : public RefCounted<GPUBufferUsage> {
+public:
+    enum Flags : GPUBufferUsageFlags {
+        None = 0,
+        MapRead = 1,
+        MapWrite = 2,
+        TransferSrc = 4,
+        TransferDst = 8,
+        Index = 16,
+        Vertex = 32,
+        Uniform = 64,
+        Storage = 128
+    };
+};
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp (239093 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp	2018-12-12 01:40:06 UTC (rev 239094)
@@ -28,6 +28,8 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPUBuffer.h"
+#include "GPUBufferDescriptor.h"
 #include "GPURenderPipeline.h"
 #include "GPURenderPipelineDescriptor.h"
 #include "GPUShaderModule.h"
@@ -35,6 +37,11 @@
 
 namespace WebCore {
 
+RefPtr<GPUBuffer> GPUDevice::createBuffer(GPUBufferDescriptor&& descriptor) const
+{
+    return GPUBuffer::create(*this, WTFMove(descriptor));
+}
+
 RefPtr<GPUShaderModule> GPUDevice::createShaderModule(GPUShaderModuleDescriptor&& descriptor) const
 {
     return GPUShaderModule::create(*this, WTFMove(descriptor));

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


--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2018-12-12 01:40:06 UTC (rev 239094)
@@ -41,9 +41,11 @@
 using PlatformDevice = MTLDevice;
 using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>;
 
+class GPUBuffer;
 class GPURenderPipeline;
 class GPUShaderModule;
 
+struct GPUBufferDescriptor;
 struct GPUShaderModuleDescriptor;
 struct GPURenderPipelineDescriptor;
 
@@ -51,6 +53,8 @@
 public:
     static RefPtr<GPUDevice> create();
 
+    RefPtr<GPUBuffer> createBuffer(GPUBufferDescriptor&&) const;
+
     RefPtr<GPUShaderModule> createShaderModule(GPUShaderModuleDescriptor&&) const;
     RefPtr<GPURenderPipeline> createRenderPipeline(GPURenderPipelineDescriptor&&) const;
 

Added: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm (0 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm	2018-12-12 01:40:06 UTC (rev 239094)
@@ -0,0 +1,97 @@
+/*
+ * 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.
+ */
+
+#include "config.h"
+#include "GPUBuffer.h"
+
+#if ENABLE(WEBGPU)
+
+#import "GPUBufferDescriptor.h"
+#import "GPUDevice.h"
+#import "Logging.h"
+
+#import <Foundation/NSRange.h>
+#import <_javascript_Core/ArrayBuffer.h>
+#import <Metal/Metal.h>
+#import <wtf/Gigacage.h>
+#import <wtf/PageBlock.h>
+
+namespace WebCore {
+
+RefPtr<GPUBuffer> GPUBuffer::create(const GPUDevice& device, GPUBufferDescriptor&& descriptor)
+{
+    if (!device.platformDevice()) {
+        LOG(WebGPU, "GPUBuffer::create(): Invalid GPUDevice!");
+        return nullptr;
+    }
+
+    size_t pageSize = WTF::pageSize();
+    size_t pageAlignedSize = roundUpToMultipleOf(pageSize, descriptor.size);
+    void* pageAlignedCopy = Gigacage::tryAlignedMalloc(Gigacage::Primitive, pageSize, pageAlignedSize);
+    if (!pageAlignedCopy) {
+        LOG(WebGPU, "GPUBuffer::create(): Unable to allocate memory!");
+        return nullptr;
+    }
+
+    RefPtr<ArrayBuffer> arrayBuffer = ArrayBuffer::createFromBytes(pageAlignedCopy, descriptor.size, [] (void* ptr) {
+        Gigacage::alignedFree(Gigacage::Primitive, ptr);
+    });
+    arrayBuffer->ref();
+    ArrayBuffer* arrayBufferContents = arrayBuffer.get();
+    // FIXME: Default this MTLResourceOptions.
+    PlatformBufferSmartPtr mtlBuffer = adoptNS([device.platformDevice()
+        newBufferWithBytesNoCopy:arrayBuffer->data()
+        length:pageAlignedSize
+        options:MTLResourceCPUCacheModeDefaultCache
+        deallocator:^(void*, NSUInteger) {
+            arrayBufferContents->deref();
+        }]);
+
+    if (!mtlBuffer) {
+        LOG(WebGPU, "GPUBuffer::create(): Unable to create MTLBuffer!");
+        arrayBuffer->deref();
+        return nullptr;
+    }
+
+    return adoptRef(*new GPUBuffer(WTFMove(mtlBuffer), WTFMove(arrayBuffer)));
+}
+
+GPUBuffer::GPUBuffer(PlatformBufferSmartPtr&& platformBuffer, RefPtr<ArrayBuffer>&& arrayBuffer)
+    : m_platformBuffer(WTFMove(platformBuffer))
+    , m_mapping(WTFMove(arrayBuffer))
+{
+}
+
+GPUBuffer::~GPUBuffer()
+{
+    if (m_mapping) {
+        m_mapping->deref();
+        m_mapping = nullptr;
+    }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(WEBGPU)

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm (239093 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm	2018-12-12 01:40:06 UTC (rev 239094)
@@ -44,7 +44,7 @@
 RefPtr<GPUQueue> GPUQueue::create(const GPUDevice& device)
 {
     if (!device.platformDevice()) {
-        LOG(WebGPU, "GPUQueue::create(): Invalid GPUDevice.");
+        LOG(WebGPU, "GPUQueue::create(): Invalid GPUDevice!");
         return nullptr;
     }
 
@@ -58,7 +58,7 @@
     END_BLOCK_OBJC_EXCEPTIONS;
 
     if (!queue) {
-        LOG(WebGPU, "GPUQueue::create(): Unable to create MTLCommandQueue.");
+        LOG(WebGPU, "GPUQueue::create(): Unable to create MTLCommandQueue!");
         return nullptr;
     }
 

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm (239093 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm	2018-12-12 01:40:06 UTC (rev 239094)
@@ -87,7 +87,7 @@
     const char* const functionName = "GPURenderPipeline::create()";
 
     if (!device.platformDevice()) {
-        LOG(WebGPU, "%s: MTLDevice does not exist!", functionName);
+        LOG(WebGPU, "%s: Invalid GPUDevice!", functionName);
         return nullptr;
     }
 

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm (239093 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm	2018-12-12 01:40:06 UTC (rev 239094)
@@ -55,10 +55,7 @@
 
     END_BLOCK_OBJC_EXCEPTIONS;
 
-    if (!module)
-        return nullptr;
-
-    return adoptRef(new GPUShaderModule(WTFMove(module)));
+    return module ? adoptRef(new GPUShaderModule(WTFMove(module))) : nullptr;
 }
 
 GPUShaderModule::GPUShaderModule(PlatformShaderModuleSmartPtr&& module)

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm (239093 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm	2018-12-12 01:40:06 UTC (rev 239094)
@@ -73,7 +73,7 @@
 void GPUSwapChain::setDevice(const GPUDevice& device)
 {
     if (!device.platformDevice()) {
-        LOG(WebGPU, "GPUSwapChain::setDevice(): MTLDevice does not exist!");
+        LOG(WebGPU, "GPUSwapChain::setDevice(): Invalid GPUDevice!");
         return;
     }
 

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm (239093 => 239094)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm	2018-12-12 01:34:05 UTC (rev 239093)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm	2018-12-12 01:40:06 UTC (rev 239094)
@@ -40,7 +40,7 @@
     return adoptRef(*new GPUTexture(WTFMove(texture)));
 }
 
-GPUTexture::GPUTexture(RetainPtr<MTLTexture>&& texture)
+GPUTexture::GPUTexture(PlatformTextureSmartPtr&& texture)
     : m_platformTexture(WTFMove(texture))
 {
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to