WebKit Bugzilla
Attachment 357086 Details for
Bug 192516
: [WebGPU] Implement WebGPUBuffer, and some nullibility consistency in WebGPU
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for landing
bug-192516-20181211165515.patch (text/plain), 62.24 KB, created by
Justin Fan
on 2018-12-11 16:55:16 PST
(
hide
)
Description:
Patch for landing
Filename:
MIME Type:
Creator:
Justin Fan
Created:
2018-12-11 16:55:16 PST
Size:
62.24 KB
patch
obsolete
>Subversion Revision: 239038 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index ab38a812fe9a30aba0b0b6e3fde5950626a6d390..581be8dcd2ed9aea37c972e283ac8431d2d24897 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,88 @@ >+2018-12-07 Justin Fan <justin_fan@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-10 Youenn Fablet <youenn@apple.com> > > Make mock capture happen in the process used for real capture >diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt >index 51e17d46688c0ae1f1e98c685f3bc6ed4878e800..cefb67febf82974131ee07b32e30ab8642de2c5f 100644 >--- a/Source/WebCore/CMakeLists.txt >+++ b/Source/WebCore/CMakeLists.txt >@@ -458,6 +458,9 @@ set(WebCore_NON_SVG_IDL_FILES > 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 >diff --git a/Source/WebCore/DerivedSources.make b/Source/WebCore/DerivedSources.make >index 971a638f939f436b44538d775a481d7a696cd421..b3d4c4692fd5ddfd7ab46b90bd94c0da175aa755 100644 >--- a/Source/WebCore/DerivedSources.make >+++ b/Source/WebCore/DerivedSources.make >@@ -375,6 +375,9 @@ JS_BINDING_IDLS = \ > $(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 \ >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp b/Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp >new file mode 100644 >index 0000000000000000000000000000000000000000..148daea5d1c91972ca1588f1cddf076c85827d2a >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WebGPUBuffer.cpp >@@ -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) >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBuffer.h b/Source/WebCore/Modules/webgpu/WebGPUBuffer.h >new file mode 100644 >index 0000000000000000000000000000000000000000..6336d5953ecc1de5f8439c057375c1b88e14cdde >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WebGPUBuffer.h >@@ -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) >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBuffer.idl b/Source/WebCore/Modules/webgpu/WebGPUBuffer.idl >new file mode 100644 >index 0000000000000000000000000000000000000000..308667ef4355de1d259c68a30d50a258ace88486 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WebGPUBuffer.idl >@@ -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(); >+}; >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.h b/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.h >new file mode 100644 >index 0000000000000000000000000000000000000000..b303f09bb68ecc5e0b7e246ec749ca3068cd7540 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.h >@@ -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) >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.idl b/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.idl >new file mode 100644 >index 0000000000000000000000000000000000000000..13e121047656a48ab341734fb6950eec9ac786ca >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WebGPUBufferDescriptor.idl >@@ -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; >+}; >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.h b/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.h >new file mode 100644 >index 0000000000000000000000000000000000000000..b958cf30e4537a3e33a75b57032089c9f381d4bd >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.h >@@ -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) >diff --git a/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.idl b/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.idl >new file mode 100644 >index 0000000000000000000000000000000000000000..ac37fac5d9872fe95f44e2280b9f6d05ada19db7 >--- /dev/null >+++ b/Source/WebCore/Modules/webgpu/WebGPUBufferUsage.idl >@@ -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; >+}; >diff --git a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp b/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp >index 0a4de2a1350a538a02a817bdc6dcdb99289e702c..dbb803be27321b9be6cdf59d911afbc033842942 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp >@@ -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 @@ RefPtr<WebGPURenderPassEncoder> WebGPUCommandBuffer::beginRenderPass(WebGPURende > } > > 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 >diff --git a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h b/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h >index 6d26aeaee23063efd87cc54dfac1b10aafef4816..72df312ff880b78f7eca116932526392437bd1ef 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h >@@ -41,7 +41,7 @@ struct WebGPURenderPassDescriptor; > > 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(); } > >diff --git a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp b/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >index 53d1392ded19bbf8720935e229b2a5cef794daae..7d6d0fc310a8cdff985ecfe37504165643b0b593 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp >@@ -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 @@ namespace WebCore { > 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 @@ RefPtr<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(WebGPURenderPipe > } > > 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() >diff --git a/Source/WebCore/Modules/webgpu/WebGPUDevice.h b/Source/WebCore/Modules/webgpu/WebGPUDevice.h >index 9fa3a07d94266ccc61c17410fc205bd69fd0194f..659b3ecf51a2904f79a91a59e670758a7a99adfb 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUDevice.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUDevice.h >@@ -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,7 +52,9 @@ public: > 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 @@ public: > 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; > }; > >diff --git a/Source/WebCore/Modules/webgpu/WebGPUDevice.idl b/Source/WebCore/Modules/webgpu/WebGPUDevice.idl >index 6bbdaa6c6865c3e681490b28d9f9a61823d38965..e098be915fd73b5904806b172d222b9f64e2427a 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUDevice.idl >+++ b/Source/WebCore/Modules/webgpu/WebGPUDevice.idl >@@ -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); > // >diff --git a/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp b/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp >index 0d918d8c28052d4240a55682d817733774b02007..b3766d47ff5efbb5ebd3df8f74826906abd07519 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp >@@ -36,10 +36,7 @@ namespace WebCore { > > 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) >diff --git a/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp b/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp >index 8eb0b46b7a777a45c2b9a2b919c00d97c1534cdc..12e6903f999bc30631a790e7adb5156f00af5229 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp >@@ -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) >diff --git a/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h b/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h >index c74da7a002ea2ecfa2413a0b1103ff669cbfd108..c38c9fdce99d406d09c8b47a5419d61885c82941 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h >+++ b/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h >@@ -38,7 +38,7 @@ class GPURenderPassEncoder; > > 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); > >diff --git a/Source/WebCore/Modules/webgpu/WebGPUShaderModule.cpp b/Source/WebCore/Modules/webgpu/WebGPUShaderModule.cpp >index 51fb694634e8c7f5c84c8891bf0eb9b49675ae3a..e823b044a8f02cd6bc5923041cf8e596b861b98e 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUShaderModule.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUShaderModule.cpp >@@ -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); >diff --git a/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h b/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h >index deac20ea98bdd4cf81afcff799cffb4bc5b2e4f8..4202994d47ec24a1fe09a6eb4c6f7457a0ac418d 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUShaderModule.h >@@ -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 >diff --git a/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl b/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl >index fe0daff160a8221027d92cd1bb91376d45cc3026..a0521a023bec66ea61af52b5016ff82f18b1e0b5 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl >+++ b/Source/WebCore/Modules/webgpu/WebGPUSwapChain.idl >@@ -40,7 +40,7 @@ typedef unsigned long u32; > Conditional=WEBGPU, > EnabledAtRuntime=WebGPU > ] dictionary WebGPUSwapChainDescriptor { >- WebGPUDevice device; // FIXME: Propose this addition to IDL. >+ WebGPUDevice? device; > // WebGPUTextureUsageFlags usage; > WebGPUTextureFormatEnum format; > u32 width; >diff --git a/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp b/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp >index d5b4b3bdceb4be5ff04171d19de421e026103c3b..c6780ef61b0299fee195f125f56ce4d8e862c727 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUTexture.cpp >@@ -34,10 +34,7 @@ namespace WebCore { > > 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 @@ WebGPUTexture::WebGPUTexture(Ref<GPUTexture>&& texture) > 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 >diff --git a/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp b/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp >index 7265945a23e9c10d26a703dfe442d0f47ab0f008..0459a53a288ecf3b268fc2c06645b74b1234651c 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp >+++ b/Source/WebCore/Modules/webgpu/WebGPUTextureView.cpp >@@ -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) >diff --git a/Source/WebCore/Modules/webgpu/WebGPUTextureView.h b/Source/WebCore/Modules/webgpu/WebGPUTextureView.h >index fbeb8bc665604277e0df39503f8791beca092adb..40fd81492b081dfcdc91bef5382ad3f798a936f7 100644 >--- a/Source/WebCore/Modules/webgpu/WebGPUTextureView.h >+++ b/Source/WebCore/Modules/webgpu/WebGPUTextureView.h >@@ -35,7 +35,7 @@ namespace WebCore { > > 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: >diff --git a/Source/WebCore/Sources.txt b/Source/WebCore/Sources.txt >index 6a9882dc90c81d487ad80f55babac42ddaa2b3d8..59c1ea034b996177cc34fe67085b8d45bb0eef6b 100644 >--- a/Source/WebCore/Sources.txt >+++ b/Source/WebCore/Sources.txt >@@ -303,6 +303,7 @@ Modules/websockets/WorkerThreadableWebSocketChannel.cpp > 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 >@@ -3219,6 +3220,9 @@ JSWebAnimation.cpp > JSWebGPU.cpp > JSWebGPUAdapter.cpp > JSWebGPUAdapterDescriptor.cpp >+JSWebGPUBuffer.cpp >+JSWebGPUBufferDescriptor.cpp >+JSWebGPUBufferUsage.cpp > JSWebGPUCommandBuffer.cpp > JSWebGPUColor.cpp > JSWebGPUDevice.cpp >diff --git a/Source/WebCore/SourcesCocoa.txt b/Source/WebCore/SourcesCocoa.txt >index e79abd4155d2be987e2be556bb8ec44b5ed77d80..f826a5ca12a8380ce683e7fc8b3cf6bbb6220e5a 100644 >--- a/Source/WebCore/SourcesCocoa.txt >+++ b/Source/WebCore/SourcesCocoa.txt >@@ -318,6 +318,7 @@ platform/graphics/cv/PixelBufferConformerCV.cpp > 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 >diff --git a/Source/WebCore/WebCore.xcodeproj/project.pbxproj b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >index 5f6c7303150dc0cf3f4f42100f4465cda486c4ff..554b455a2105bc9b925a956280825b57933e8f3f 100644 >--- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj >+++ b/Source/WebCore/WebCore.xcodeproj/project.pbxproj >@@ -4228,6 +4228,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 */, >@@ -25496,6 +25509,13 @@ > D00F5951216FFAC2000D71DB /* WebGPUAdapter.idl */, > D02C26912181416D00D818E4 /* WebGPUAdapterDescriptor.h */, > D02C26922181416D00D818E4 /* WebGPUAdapterDescriptor.idl */, >+ D0D8648D21B70676003C983C /* WebGPUBuffer.cpp */, >+ D0D8648C21B70676003C983C /* WebGPUBuffer.h */, >+ D0D8648E21B70676003C983C /* WebGPUBuffer.idl */, >+ D0D8648221B61727003C983C /* WebGPUBufferDescriptor.h */, >+ D0D8648321B61727003C983C /* WebGPUBufferDescriptor.idl */, >+ D063AE4E21C0810A000E6A35 /* WebGPUBufferUsage.h */, >+ D063AE4C21C07AB5000E6A35 /* WebGPUBufferUsage.idl */, > D001D9AC21B0C81A0023B9BC /* WebGPUColor.h */, > D001D9AD21B0C81A0023B9BC /* WebGPUColor.idl */, > D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */, >@@ -25554,6 +25574,7 @@ > D087CE3721ACA94200BDE174 /* cocoa */ = { > isa = PBXGroup; > children = ( >+ D0D8649121B760C4003C983C /* GPUBufferMetal.mm */, > D087CE3821ACA94200BDE174 /* GPUCommandBufferMetal.mm */, > D087CE3C21ACA94200BDE174 /* GPUDeviceMetal.mm */, > D087CE3B21ACA94200BDE174 /* GPUProgrammablePassEncoderMetal.mm */, >@@ -29989,7 +30010,6 @@ > 11310CF620BA4A560065A8D0 /* LayoutChildIterator.h in Headers */, > 1199FA46208E35A3002358CC /* LayoutContainer.h in Headers */, > 11310CF520BA4A4C0065A8D0 /* LayoutDescendantIterator.h in Headers */, >- 6F7CA3C6208C2957002F29AB /* LayoutState.h in Headers */, > 1199FA53208E38D3002358CC /* LayoutInlineBox.h in Headers */, > 1199FA4F208E3899002358CC /* LayoutInlineContainer.h in Headers */, > 11310CF420BA4A3D0065A8D0 /* LayoutIterator.h in Headers */, >@@ -30000,7 +30020,7 @@ > A12538D413F9B60A00024754 /* LayoutRepainter.h in Headers */, > 11310CF320BA4A370065A8D0 /* LayoutReplaced.h in Headers */, > 141DC054164834B900371E5A /* LayoutSize.h in Headers */, >- 2D9066070BE141D400956998 /* RenderLayoutState.h in Headers */, >+ 6F7CA3C6208C2957002F29AB /* LayoutState.h in Headers */, > 11310CF220BA4A320065A8D0 /* LayoutTreeBuilder.h in Headers */, > 141DC0481648348F00371E5A /* LayoutUnit.h in Headers */, > CDE8B5ED1A69777300B4B66A /* LegacyCDMPrivateClearKey.h in Headers */, >@@ -30602,6 +30622,7 @@ > 0F580CFF0F12DE9B0051D689 /* RenderLayerBacking.h in Headers */, > 0F580CFD0F12DE9B0051D689 /* RenderLayerCompositor.h in Headers */, > 3C244FEAA375AC633F88BE6F /* RenderLayerModelObject.h in Headers */, >+ 2D9066070BE141D400956998 /* RenderLayoutState.h in Headers */, > 0BE030A20F3112FB003C1A46 /* RenderLineBoxList.h in Headers */, > BCEA4864097D93020094C9E4 /* RenderLineBreak.h in Headers */, > ABB5419F0ACDDFE4002820EB /* RenderListBox.h in Headers */, >@@ -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 */, >diff --git a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h b/Source/WebCore/bindings/js/WebCoreBuiltinNames.h >index 79452de63fc48d13ec302c23f48ca35228bebcf2..d256827eb8dfcc87f31f0644b488acc424b47acd 100644 >--- a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h >+++ b/Source/WebCore/bindings/js/WebCoreBuiltinNames.h >@@ -189,8 +189,10 @@ namespace WebCore { > macro(WebGLVertexArrayObject) \ > macro(WebGPU) \ > macro(WebGPUAdapter) \ >- macro(WebGPUDevice) \ >+ macro(WebGPUBuffer) \ >+ macro(WebGPUBufferUsage) \ > macro(WebGPUCommandBuffer) \ >+ macro(WebGPUDevice) \ > macro(WebGPUQueue) \ > macro(WebGPUProgrammablePassEncoder) \ > macro(WebGPURenderingContext) \ >diff --git a/Source/WebCore/platform/graphics/gpu/GPUBuffer.h b/Source/WebCore/platform/graphics/gpu/GPUBuffer.h >new file mode 100644 >index 0000000000000000000000000000000000000000..deb583dc86a9da3832e5920e0590e32e18cfeafd >--- /dev/null >+++ b/Source/WebCore/platform/graphics/gpu/GPUBuffer.h >@@ -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) >diff --git a/Source/WebCore/platform/graphics/gpu/GPUBufferDescriptor.h b/Source/WebCore/platform/graphics/gpu/GPUBufferDescriptor.h >new file mode 100644 >index 0000000000000000000000000000000000000000..c04e52597262bd4cc8ce1b1bc8d346261558da1c >--- /dev/null >+++ b/Source/WebCore/platform/graphics/gpu/GPUBufferDescriptor.h >@@ -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) >diff --git a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp b/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >index ff1774e6c85ba2e5d6f1c91726a93d9a5fe3836a..b5b49193b1df823d073157301defae63b8227150 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >+++ b/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp >@@ -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)); >diff --git a/Source/WebCore/platform/graphics/gpu/GPUDevice.h b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >index 5816f183fc092d746fb97322446f8cb233c14fd0..356af152a1ccb0766c1d54da640bcc7b3235ad73 100644 >--- a/Source/WebCore/platform/graphics/gpu/GPUDevice.h >+++ b/Source/WebCore/platform/graphics/gpu/GPUDevice.h >@@ -41,9 +41,11 @@ namespace WebCore { > using PlatformDevice = MTLDevice; > using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>; > >+class GPUBuffer; > class GPURenderPipeline; > class GPUShaderModule; > >+struct GPUBufferDescriptor; > struct GPUShaderModuleDescriptor; > struct GPURenderPipelineDescriptor; > >@@ -51,6 +53,8 @@ class GPUDevice : public RefCounted<GPUDevice> { > public: > static RefPtr<GPUDevice> create(); > >+ RefPtr<GPUBuffer> createBuffer(GPUBufferDescriptor&&) const; >+ > RefPtr<GPUShaderModule> createShaderModule(GPUShaderModuleDescriptor&&) const; > RefPtr<GPURenderPipeline> createRenderPipeline(GPURenderPipelineDescriptor&&) const; > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm >new file mode 100644 >index 0000000000000000000000000000000000000000..406e085fff1f19a9dbfdb81c64931f468a4f9795 >--- /dev/null >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUBufferMetal.mm >@@ -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 <JavaScriptCore/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) >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >index d030a34d74364383ec3af0f4efe2a400fdafa324..fdecdeeace244ce963054cc36d9670e5a203a8ee 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUQueueMetal.mm >@@ -44,7 +44,7 @@ static NSString * const commandQueueLabelPrefix = @"com.apple.WebKit."; > 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 @@ RefPtr<GPUQueue> GPUQueue::create(const GPUDevice& device) > END_BLOCK_OBJC_EXCEPTIONS; > > if (!queue) { >- LOG(WebGPU, "GPUQueue::create(): Unable to create MTLCommandQueue."); >+ LOG(WebGPU, "GPUQueue::create(): Unable to create MTLCommandQueue!"); > return nullptr; > } > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >index 9eca4c1bf4929ffe2210785e83831db162252a7a..a8065febbad4783703bbb6e2ccc1af9c54de0485 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm >@@ -87,7 +87,7 @@ RefPtr<GPURenderPipeline> GPURenderPipeline::create(const GPUDevice& device, GPU > 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; > } > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >index 76e85390ca2c91be04f9e18b2316206c0d03543d..4553a15df5fcc073fc1a54137f607c0ae11404a7 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm >@@ -55,10 +55,7 @@ RefPtr<GPUShaderModule> GPUShaderModule::create(const GPUDevice& device, GPUShad > > 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) >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >index 95bdfd179e7d36c2d062b7888bff827d954e394e..2f1dd08ad63090b075dc7b19b7364ad5970fac31 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUSwapChainMetal.mm >@@ -73,7 +73,7 @@ GPUSwapChain::GPUSwapChain(PlatformSwapLayerSmartPtr&& platformLayer) > void GPUSwapChain::setDevice(const GPUDevice& device) > { > if (!device.platformDevice()) { >- LOG(WebGPU, "GPUSwapChain::setDevice(): MTLDevice does not exist!"); >+ LOG(WebGPU, "GPUSwapChain::setDevice(): Invalid GPUDevice!"); > return; > } > >diff --git a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm b/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >index 507857b6f3ab554aa0fa5ca7d3aba490e4c7fb79..5cbc1f95b696416f2d63cd30c45d74ede45e1e6d 100644 >--- a/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >+++ b/Source/WebCore/platform/graphics/gpu/cocoa/GPUTextureMetal.mm >@@ -40,7 +40,7 @@ Ref<GPUTexture> GPUTexture::create(PlatformTextureSmartPtr&& texture) > return adoptRef(*new GPUTexture(WTFMove(texture))); > } > >-GPUTexture::GPUTexture(RetainPtr<MTLTexture>&& texture) >+GPUTexture::GPUTexture(PlatformTextureSmartPtr&& texture) > : m_platformTexture(WTFMove(texture)) > { > } >diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 202893917e53d9aaa0af273fc573667ad8a8ea56..378dc0aabf3949edf2cce8b72fd220d90166f8d5 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,15 @@ >+2018-12-07 Justin Fan <justin_fan@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-09 Commit Queue <commit-queue@webkit.org> > > Unreviewed, rolling out r239010. >diff --git a/LayoutTests/webgpu/buffers-expected.txt b/LayoutTests/webgpu/buffers-expected.txt >new file mode 100644 >index 0000000000000000000000000000000000000000..ad0fb71b7e07b27e157b86d4223ac4465044e705 >--- /dev/null >+++ b/LayoutTests/webgpu/buffers-expected.txt >@@ -0,0 +1,4 @@ >+PASS [object WebGPU] is defined. >+ >+PASS createBuffer() on WebGPUDevice. >+ >diff --git a/LayoutTests/webgpu/buffers.html b/LayoutTests/webgpu/buffers.html >new file mode 100644 >index 0000000000000000000000000000000000000000..90024c9c9b4cb530f278b01431f797d5bea3cf51 >--- /dev/null >+++ b/LayoutTests/webgpu/buffers.html >@@ -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="../resources/testharness.js"></script> >+<script src="../resources/testharnessreport.js"></script> >+<script src="../resources/js-test-pre.js"></script> >+<script src="js/basic-webgpu-functions.js"></script> >+<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>
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192516
:
356840
|
356982
|
356983
|
356996
|
356998
|
357025
|
357026
|
357086
|
357087