Unreviewed, rolling out r242931.
authorsroberts@apple.com <sroberts@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 19:46:32 +0000 (19:46 +0000)
committersroberts@apple.com <sroberts@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Mar 2019 19:46:32 +0000 (19:46 +0000)
Causing internal watch/tv OS build failures

Reverted changeset:

"[Web GPU] Updates to GPUCommandBuffer for new GPUCommandQueue
concept"
https://bugs.webkit.org/show_bug.cgi?id=195083
https://trac.webkit.org/changeset/242931

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242956 268f45cc-cd09-0410-ab3c-d52691b4dbfc

40 files changed:
LayoutTests/ChangeLog
LayoutTests/webgpu/blit-commands.html
LayoutTests/webgpu/buffer-command-buffer-races.html
LayoutTests/webgpu/buffer-resource-triangles.html
LayoutTests/webgpu/command-buffers-expected.txt
LayoutTests/webgpu/command-buffers.html
LayoutTests/webgpu/depth-enabled-triangle-strip.html
LayoutTests/webgpu/js/webgpu-functions.js
LayoutTests/webgpu/render-command-encoding.html
LayoutTests/webgpu/simple-triangle-strip.html
LayoutTests/webgpu/texture-triangle-strip.html
LayoutTests/webgpu/vertex-buffer-triangle-strip.html
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp
Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h
Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl
Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp [deleted file]
Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.h [deleted file]
Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.idl [deleted file]
Source/WebCore/Modules/webgpu/WebGPUDevice.cpp
Source/WebCore/Modules/webgpu/WebGPUDevice.h
Source/WebCore/Modules/webgpu/WebGPUDevice.idl
Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp
Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h
Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl
Source/WebCore/Modules/webgpu/WebGPUQueue.cpp
Source/WebCore/Modules/webgpu/WebGPUQueue.h
Source/WebCore/Modules/webgpu/WebGPUQueue.idl
Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp
Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h
Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp
Source/WebCore/Sources.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/WebCoreBuiltinNames.h
Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h
Source/WebCore/platform/graphics/gpu/GPUDevice.cpp
Source/WebCore/platform/graphics/gpu/GPUDevice.h
Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm

index 9cf8f5f..d7ddfbf 100644 (file)
@@ -1,3 +1,16 @@
+2019-03-14  Shawn Roberts  <sroberts@apple.com>
+
+        Unreviewed, rolling out r242931.
+
+        Causing internal watch/tv OS build failures
+
+        Reverted changeset:
+
+        "[Web GPU] Updates to GPUCommandBuffer for new GPUCommandQueue
+        concept"
+        https://bugs.webkit.org/show_bug.cgi?id=195083
+        https://trac.webkit.org/changeset/242931
+
 2019-03-14  Chris Dumez  <cdumez@apple.com>
 
         Device orientation's permission should only require a user gesture to prompt the user
index d71947e..1493f5b 100644 (file)
@@ -85,13 +85,12 @@ async function test(image) {
         imageHeight: 0
     };
 
-    const commandEncoder = device.createCommandEncoder();
-    commandEncoder.copyBufferToBuffer(bufferA, 0, bufferB, 0, imageData.data.byteLength);
-    commandEncoder.copyBufferToTexture(bufferViewB, textureViewA, textureSize);
-    commandEncoder.copyBufferToTexture(bufferViewB, textureViewA, textureSize);
-    commandEncoder.copyTextureToTexture(textureViewA, textureViewB, textureSize);
-    commandEncoder.copyTextureToBuffer(textureViewB, readBufferView, textureSize);
-    device.getQueue().submit([commandEncoder.finish()]);
+    const commandBuffer = device.createCommandBuffer();
+    commandBuffer.copyBufferToBuffer(bufferA, 0, bufferB, 0, imageData.data.byteLength);
+    commandBuffer.copyBufferToTexture(bufferViewB, textureViewA, textureSize);
+    commandBuffer.copyTextureToTexture(textureViewA, textureViewB, textureSize);
+    commandBuffer.copyTextureToBuffer(textureViewB, readBufferView, textureSize);
+    device.getQueue().submit([commandBuffer]);
     bufferA.destroy();
     bufferB.destroy();
     textureA.destroy();
index 9994ded..d332966 100644 (file)
@@ -76,13 +76,13 @@ function createAndSetVertexBuffer(device, vertices) {
 }
 
 function drawAndSubmitCommands(device, pipeline, attachment, vertexBuffer, colorBuffer) {
-    const commandEncoder = device.createCommandEncoder();
-    const encoder = commandEncoder.beginRenderPass({ colorAttachments: [attachment] });
+    const commandBuffer = device.createCommandBuffer();
+    const encoder = commandBuffer.beginRenderPass({ colorAttachments: [attachment] });
     encoder.setVertexBuffers(0, [vertexBuffer, colorBuffer], [0, 0]);
     encoder.setPipeline(pipeline);
     encoder.draw(3, 1, 0, 0);
     encoder.endPass();
-    device.getQueue().submit([commandEncoder.finish()]);
+    device.getQueue().submit([commandBuffer]);
 }
 
 async function test() {
index 63fbf3a..60e27d5 100644 (file)
@@ -194,8 +194,8 @@ async function test() {
     });
 
     Promise.all(bufferPromises).then(() => {
-        const commandEncoder = device.createCommandEncoder();
-        const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
+        const commandBuffer = device.createCommandBuffer();
+        const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
         passEncoder.setPipeline(pipeline);
 
         // Vertex data for upper triangles.
@@ -205,9 +205,9 @@ async function test() {
         passEncoder.setVertexBuffers(0, [verticesBuffer], [0]);
         passEncoder.draw(9, 1, 0, 0);
 
-        passEncoder.endPass();
+        const endCommandBuffer = passEncoder.endPass();
         const queue = device.getQueue();
-        queue.submit([commandEncoder.finish()]);
+        queue.submit([endCommandBuffer]);
 
         if (window.testRunner)
             testRunner.notifyDone();
index e0cf41d..d7ce05d 100644 (file)
@@ -1,3 +1,3 @@
 
-PASS Create a default GPUCommandEncoder. 
+PASS Create a default GPUCommandBuffer. 
 
index 833a383..baf6379 100644 (file)
@@ -6,10 +6,10 @@
 <script>
 promise_test(async () => {
     const device = await getBasicDevice();
-    const commandEncoder = device.createCommandEncoder();
-    assert_true(commandEncoder instanceof GPUCommandEncoder, "Successfully created GPUCommandEncoder.");
-}, "Create a default GPUCommandEncoder.");
+    const commandBuffer = device.createCommandBuffer();
+    assert_true(commandBuffer instanceof WebGPUCommandBuffer, "Successfully created GPUCommandBuffer.");
+}, "Create a default GPUCommandBuffer.");
 
-// FIXME: createCommandEncoder should take a GPUCommandEncoderDescriptor, which is currently an empty dictionary.
+// FIXME: createCommandBuffer should take a GPUCommandBufferDescriptor, which is currently an empty dictionary.
 </script>
 </html>
\ No newline at end of file
index 540718d..66048e8 100644 (file)
@@ -89,7 +89,7 @@ async function test() {
     const inputStateDescriptor = createInputStateDescriptor();
     const depthStateDescriptor = createBasicDepthStateDescriptor();
     const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor, depthStateDescriptor);
-    const commandEncoder = device.createCommandEncoder();
+    const commandBuffer = device.createCommandBuffer();
 
     const basicAttachment = {
         attachment: swapChain.getCurrentTexture().createDefaultTextureView(),
@@ -105,7 +105,7 @@ async function test() {
         clearDepth: 1.0
     };
 
-    const encoder = commandEncoder.beginRenderPass({
+    const encoder = commandBuffer.beginRenderPass({
         colorAttachments: [basicAttachment],
         depthStencilAttachment: depthAttachment
     });
@@ -115,7 +115,7 @@ async function test() {
     encoder.draw(4, 2, 0, 0);
     encoder.endPass();
 
-    device.getQueue().submit([commandEncoder.finish()]);
+    device.getQueue().submit([commandBuffer]);
 
     if (window.testRunner)
         testRunner.notifyDone();
index 2417baf..3cda28e 100644 (file)
@@ -66,7 +66,7 @@ function createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDes
     return device.createRenderPipeline(pipelineDescriptor);
 }
 
-function beginBasicRenderPass(swapChain, commandEncoder) {
+function beginBasicRenderPass(swapChain, commandBuffer) {
     const basicAttachment = {
         attachment: swapChain.getCurrentTexture().createDefaultTextureView(),
         loadOp: "clear",
@@ -75,7 +75,7 @@ function beginBasicRenderPass(swapChain, commandEncoder) {
     }
 
     // FIXME: Flesh out the rest of WebGPURenderPassDescriptor. 
-    return commandEncoder.beginRenderPass({ colorAttachments : [basicAttachment] });
+    return commandBuffer.beginRenderPass({ colorAttachments : [basicAttachment] });
 }
 
 function encodeBasicCommands(renderPassEncoder, renderPipeline, vertexBuffer) {
@@ -83,5 +83,5 @@ function encodeBasicCommands(renderPassEncoder, renderPipeline, vertexBuffer) {
         renderPassEncoder.setVertexBuffers(0, [vertexBuffer], [0]);
     renderPassEncoder.setPipeline(renderPipeline);
     renderPassEncoder.draw(4, 1, 0, 0);
-    renderPassEncoder.endPass();
+    return renderPassEncoder.endPass();
 }
\ No newline at end of file
index c03a480..bcaabb5 100644 (file)
@@ -34,14 +34,15 @@ promise_test(async () => {
     const shaderModule = device.createShaderModule({ code: shaders });
     const pipeline = createBasicPipeline(shaderModule, device);
 
-    const commandEncoder = device.createCommandEncoder();
-    assert_true(commandEncoder instanceof GPUCommandEncoder, "createCommandEncoder returned a GPUCommandEncoder");
+    const commandBuffer = device.createCommandBuffer();
+    assert_true(commandBuffer instanceof WebGPUCommandBuffer, "createCommandBuffer returned a WebGPUCommandBuffer");
 
-    const encoder = beginBasicRenderPass(swapChain, commandEncoder);
+    const encoder = beginBasicRenderPass(swapChain, commandBuffer);
     assert_true(encoder instanceof WebGPURenderPassEncoder, "beginRenderPass() returned a WebGPURenderPassEncoder");
 
     encoder.setPipeline(pipeline);
-    encoder.endPass();
+    const commandBufferEnd = encoder.endPass();
+    assert_true(commandBufferEnd instanceof WebGPUCommandBuffer, "endPass() returned a WebGPUCommandBuffer");
 }, "WebGPURenderPassEncoder created and successfully ended");
 
 </script>
index 088e491..e0e28c5 100644 (file)
@@ -52,12 +52,12 @@ async function test() {
     // FIXME: Replace with non-MSL shaders.
     const shaderModule = device.createShaderModule({ code: shaderCode });
     const pipeline = createBasicPipeline(shaderModule, device);
-    const commandEncoder = device.createCommandEncoder();
-    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
-    encodeBasicCommands(passEncoder, pipeline);
+    const commandBuffer = device.createCommandBuffer();
+    const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
+    const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline);
     const queue = device.getQueue();
 
-    queue.submit([commandEncoder.finish()]);
+    queue.submit([endCommandBuffer]);
 
     requestAnimationFrame(() => { 
         if (window.testRunner)
index b9deb12..c0f5881 100644 (file)
@@ -186,7 +186,7 @@ async function test() {
 
     // Pipeline and render
     const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor);
-    const commandEncoder = device.createCommandEncoder();
+    const commandBuffer = device.createCommandBuffer();
 
     const bufferCopyView = {
         buffer: textureBuffer,
@@ -200,8 +200,8 @@ async function test() {
         arrayLayer: 0,
         origin: { x: 0, y: 0, z: 0 }
     };
-    commandEncoder.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
-    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
+    commandBuffer.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
+    const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
     passEncoder.setPipeline(pipeline);
     passEncoder.setBindGroup(bindGroupIndex, bindGroup);
     passEncoder.setVertexBuffers(positionBufferIndex, [positionBuffer, textureCoordBuffer], [0, 0]);
@@ -209,7 +209,7 @@ async function test() {
     passEncoder.endPass();
 
     const queue = device.getQueue();
-    queue.submit([commandEncoder.finish()]);
+    queue.submit([commandBuffer]);
     positionBuffer.destroy();
     textureCoordBuffer.destroy();
     texture.destroy();
index 2a50c1a..ca1ba96 100644 (file)
@@ -91,11 +91,11 @@ async function test() {
     const vertexBuffer = createVertexBuffer(device);
     const inputStateDescriptor = createInputStateDescriptor();
     const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor);
-    const commandEncoder = device.createCommandEncoder();
-    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
-    encodeBasicCommands(passEncoder, pipeline, vertexBuffer);
+    const commandBuffer = device.createCommandBuffer();
+    const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
+    const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline, vertexBuffer);
     const queue = device.getQueue();
-    queue.submit([commandEncoder.finish()]);
+    queue.submit([endCommandBuffer]);
     vertexBuffer.destroy();
 
     if (window.testRunner)
index 6d1f108..5c73f47 100644 (file)
@@ -494,7 +494,6 @@ set(WebCore_NON_SVG_IDL_FILES
     Modules/webgpu/WebGPUBuffer.idl
     Modules/webgpu/WebGPUBufferBinding.idl
     Modules/webgpu/WebGPUCommandBuffer.idl
-    Modules/webgpu/WebGPUCommandEncoder.idl
     Modules/webgpu/WebGPUDevice.idl
     Modules/webgpu/WebGPUPipelineDescriptorBase.idl
     Modules/webgpu/WebGPUPipelineLayout.idl
index 954ad4d..5c5a794 100644 (file)
@@ -1,3 +1,16 @@
+2019-03-14  Shawn Roberts  <sroberts@apple.com>
+
+        Unreviewed, rolling out r242931.
+
+        Causing internal watch/tv OS build failures
+
+        Reverted changeset:
+
+        "[Web GPU] Updates to GPUCommandBuffer for new GPUCommandQueue
+        concept"
+        https://bugs.webkit.org/show_bug.cgi?id=195083
+        https://trac.webkit.org/changeset/242931
+
 2019-03-14  Chris Dumez  <cdumez@apple.com>
 
         Device orientation's permission should only require a user gesture to prompt the user
index d41f607..859aea1 100644 (file)
@@ -404,7 +404,6 @@ JS_BINDING_IDLS = \
     $(WebCore)/Modules/webgpu/WebGPUBuffer.idl \
        $(WebCore)/Modules/webgpu/WebGPUBufferBinding.idl \
     $(WebCore)/Modules/webgpu/WebGPUCommandBuffer.idl \
-    $(WebCore)/Modules/webgpu/WebGPUCommandEncoder.idl \
     $(WebCore)/Modules/webgpu/WebGPUDevice.idl \
     $(WebCore)/Modules/webgpu/WebGPUQueue.idl \
     $(WebCore)/Modules/webgpu/WebGPUPipelineDescriptorBase.idl \
index a510511..127e032 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#include "GPURenderPassDescriptor.h"
+#include "GPURenderPassEncoder.h"
+#include "WebGPUBuffer.h"
+#include "WebGPURenderPassDescriptor.h"
+#include "WebGPURenderPassEncoder.h"
+#include "WebGPUTexture.h"
+#include <wtf/Optional.h>
+
 namespace WebCore {
 
-Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(RefPtr<GPUCommandBuffer>&& buffer)
+Optional<GPUBufferCopyView> WebGPUBufferCopyView::tryCreateGPUBufferCopyView() const
+{
+    if (!buffer || !buffer->buffer()) {
+        LOG(WebGPU, "GPUCommandEncoder: Invalid buffer for copy!");
+        return WTF::nullopt;
+    }
+
+    // FIXME: Add Web GPU validation.
+
+    return GPUBufferCopyView { buffer->buffer().releaseNonNull(), *this };
+}
+
+Optional<GPUTextureCopyView> WebGPUTextureCopyView::tryCreateGPUTextureCopyView() const
+{
+    if (!texture || !texture->texture()) {
+        LOG(WebGPU, "GPUCommandEncoder: Invalid texture for copy!");
+        return WTF::nullopt;
+    }
+
+    // FIXME: Add Web GPU validation.
+
+    return GPUTextureCopyView { texture->texture().releaseNonNull(), *this };
+}
+
+Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(Ref<GPUCommandBuffer>&& buffer)
 {
     return adoptRef(*new WebGPUCommandBuffer(WTFMove(buffer)));
 }
 
-WebGPUCommandBuffer::WebGPUCommandBuffer(RefPtr<GPUCommandBuffer>&& buffer)
+WebGPUCommandBuffer::WebGPUCommandBuffer(Ref<GPUCommandBuffer>&& buffer)
     : m_commandBuffer(WTFMove(buffer))
 {
 }
 
+RefPtr<WebGPURenderPassEncoder> WebGPUCommandBuffer::beginRenderPass(WebGPURenderPassDescriptor&& descriptor)
+{
+    auto gpuDescriptor = descriptor.tryCreateGPURenderPassDescriptor();
+    if (!gpuDescriptor)
+        return nullptr;
+
+    if (auto encoder = GPURenderPassEncoder::tryCreate(m_commandBuffer.copyRef(), WTFMove(*gpuDescriptor)))
+        return WebGPURenderPassEncoder::create(*this, encoder.releaseNonNull());
+    return nullptr;
+}
+
+void WebGPUCommandBuffer::copyBufferToBuffer(const WebGPUBuffer& src, unsigned long srcOffset, const WebGPUBuffer& dst, unsigned long dstOffset, unsigned long size)
+{
+    if (!src.buffer() || !dst.buffer()) {
+        LOG(WebGPU, "GPUCommandBuffer::copyBufferToBuffer(): Invalid GPUBuffer!");
+        return;
+    }
+
+    // FIXME: Add Web GPU validation.
+
+    m_commandBuffer->copyBufferToBuffer(src.buffer().releaseNonNull(), srcOffset, dst.buffer().releaseNonNull(), dstOffset, size);
+}
+
+void WebGPUCommandBuffer::copyBufferToTexture(const WebGPUBufferCopyView& srcBuffer, const WebGPUTextureCopyView& dstTexture, const GPUExtent3D& size)
+{
+    auto gpuBufferView = srcBuffer.tryCreateGPUBufferCopyView();
+    auto gpuTextureView = dstTexture.tryCreateGPUTextureCopyView();
+
+    if (!gpuBufferView || !gpuTextureView)
+        return;
+
+    // FIXME: Add Web GPU validation.
+
+    m_commandBuffer->copyBufferToTexture(WTFMove(*gpuBufferView), WTFMove(*gpuTextureView), size);
+}
+
+void WebGPUCommandBuffer::copyTextureToBuffer(const WebGPUTextureCopyView& srcTexture, const WebGPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
+{
+    auto gpuTextureView = srcTexture.tryCreateGPUTextureCopyView();
+    auto gpuBufferView = dstBuffer.tryCreateGPUBufferCopyView();
+
+    if (!gpuTextureView || !gpuBufferView)
+        return;
+
+    // FIXME: Add Web GPU validation.
+
+    m_commandBuffer->copyTextureToBuffer(WTFMove(*gpuTextureView), WTFMove(*gpuBufferView), size);
+}
+
+void WebGPUCommandBuffer::copyTextureToTexture(const WebGPUTextureCopyView& src, const WebGPUTextureCopyView& dst, const GPUExtent3D& size)
+{
+    auto gpuSrcView = src.tryCreateGPUTextureCopyView();
+    auto gpuDstView = dst.tryCreateGPUTextureCopyView();
+
+    if (!gpuSrcView || !gpuDstView)
+        return;
+
+    // FIXME: Add Web GPU validation.
+
+    m_commandBuffer->copyTextureToTexture(WTFMove(*gpuSrcView), WTFMove(*gpuDstView), size);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEBGPU)
index 83a1da4..5464704 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * 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
 #if ENABLE(WEBGPU)
 
 #include "GPUCommandBuffer.h"
+
 #include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
 
 namespace WebCore {
 
+class WebGPUBuffer;
+class WebGPURenderPassEncoder;
+class WebGPUTexture;
+
+struct GPUExtent3D;
+struct WebGPURenderPassDescriptor;
+
+struct WebGPUBufferCopyView : GPUBufferCopyViewBase {
+    Optional<GPUBufferCopyView> tryCreateGPUBufferCopyView() const;
+
+    RefPtr<WebGPUBuffer> buffer;
+};
+
+struct WebGPUTextureCopyView : GPUTextureCopyViewBase {
+    Optional<GPUTextureCopyView> tryCreateGPUTextureCopyView() const;
+
+    RefPtr<WebGPUTexture> texture;
+};
+
 class WebGPUCommandBuffer : public RefCounted<WebGPUCommandBuffer> {
 public:
-    static Ref<WebGPUCommandBuffer> create(RefPtr<GPUCommandBuffer>&&);
+    static Ref<WebGPUCommandBuffer> create(Ref<GPUCommandBuffer>&&);
+
+    GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
 
-    GPUCommandBuffer* commandBuffer() { return m_commandBuffer.get(); }
+    RefPtr<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
+    void copyBufferToBuffer(const WebGPUBuffer&, unsigned long srcOffset, const WebGPUBuffer&, unsigned long dstOffset, unsigned long size);
+    void copyBufferToTexture(const WebGPUBufferCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
+    void copyTextureToBuffer(const WebGPUTextureCopyView&, const WebGPUBufferCopyView&, const GPUExtent3D&);
+    void copyTextureToTexture(const WebGPUTextureCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
 
 private:
-    WebGPUCommandBuffer(RefPtr<GPUCommandBuffer>&&);
+    WebGPUCommandBuffer(Ref<GPUCommandBuffer>&&);
 
-    RefPtr<GPUCommandBuffer> m_commandBuffer;
+    Ref<GPUCommandBuffer> m_commandBuffer;
 };
 
 } // namespace WebCore
index 2670187..1bd6f54 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2019 Apple Inc. All rights reserved.
+ * 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
  */
 // https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
 
+typedef unsigned long u32;
+typedef unsigned long long u64;
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU,
+    ImplementedAs=WebGPUBufferCopyView
+] dictionary GPUBufferCopyView {
+    WebGPUBuffer buffer;
+    u64 offset;
+    u64 rowPitch;
+    u32 imageHeight;
+};
+
+[
+    Conditional=WEBGPU,
+    EnabledAtRuntime=WebGPU,
+    ImplementedAs=WebGPUTextureCopyView
+] dictionary GPUTextureCopyView {
+    WebGPUTexture texture;
+    u32 mipLevel;
+    u32 arrayLayer;
+    GPUOrigin3D origin;
+};
+
 [
     Conditional=WEBGPU,
     EnabledAtRuntime=WebGPU,
-    ImplementationLacksVTable,
-    InterfaceName=GPUCommandBuffer
+    ImplementationLacksVTable
 ] interface WebGPUCommandBuffer {
+    WebGPURenderPassEncoder beginRenderPass(WebGPURenderPassDescriptor descriptor);
+
+    void copyBufferToBuffer(
+        WebGPUBuffer src,
+        u64 srcOffset,
+        WebGPUBuffer dst,
+        u64 dstOffset,
+        u64 size);
+
+    void copyBufferToTexture(
+        GPUBufferCopyView source,
+        GPUTextureCopyView destination,
+        GPUExtent3D copySize);
+
+    void copyTextureToBuffer(
+        GPUTextureCopyView source,
+        GPUBufferCopyView destination,
+        GPUExtent3D copySize);
+
+    void copyTextureToTexture(
+        GPUTextureCopyView source,
+        GPUTextureCopyView destination,
+        GPUExtent3D copySize);
+
+    // Not Yet Implemented
+    // WebGPUComputePassEncoder beginComputePass();
 };
diff --git a/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp b/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp
deleted file mode 100644 (file)
index 0c165a3..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WebGPUCommandEncoder.h"
-
-#if ENABLE(WEBGPU)
-
-#include "GPURenderPassDescriptor.h"
-#include "GPURenderPassEncoder.h"
-#include "WebGPUBuffer.h"
-#include "WebGPURenderPassDescriptor.h"
-#include "WebGPURenderPassEncoder.h"
-#include "WebGPUTexture.h"
-#include <wtf/Optional.h>
-
-namespace WebCore {
-
-Optional<GPUBufferCopyView> WebGPUBufferCopyView::tryCreateGPUBufferCopyView() const
-{
-    if (!buffer || !buffer->buffer()) {
-        LOG(WebGPU, "WebGPUCommandEncoder: Invalid buffer for copy!");
-        return WTF::nullopt;
-    }
-
-    // FIXME: Add Web GPU validation.
-
-    return GPUBufferCopyView { buffer->buffer().releaseNonNull(), *this };
-}
-
-Optional<GPUTextureCopyView> WebGPUTextureCopyView::tryCreateGPUTextureCopyView() const
-{
-    if (!texture || !texture->texture()) {
-        LOG(WebGPU, "WebGPUCommandEncoder: Invalid texture for copy!");
-        return WTF::nullopt;
-    }
-
-    // FIXME: Add Web GPU validation.
-
-    return GPUTextureCopyView { texture->texture().releaseNonNull(), *this };
-}
-
-Ref<WebGPUCommandEncoder> WebGPUCommandEncoder::create(RefPtr<GPUCommandBuffer>&& buffer)
-{
-    return adoptRef(*new WebGPUCommandEncoder(WTFMove(buffer)));
-}
-
-WebGPUCommandEncoder::WebGPUCommandEncoder(RefPtr<GPUCommandBuffer>&& buffer)
-    : m_commandBuffer(WTFMove(buffer))
-{
-}
-
-Ref<WebGPURenderPassEncoder> WebGPUCommandEncoder::beginRenderPass(WebGPURenderPassDescriptor&& descriptor)
-{
-    if (!m_commandBuffer) {
-        LOG(WebGPU, "WebGPUCommandEncoder::beginRenderPass(): Invalid operation!");
-        return WebGPURenderPassEncoder::create(*this, nullptr);
-    }
-    auto gpuDescriptor = descriptor.tryCreateGPURenderPassDescriptor();
-    if (!gpuDescriptor)
-        return WebGPURenderPassEncoder::create(*this, nullptr);
-
-    auto encoder = GPURenderPassEncoder::tryCreate(makeRef(*m_commandBuffer), WTFMove(*gpuDescriptor));
-    return WebGPURenderPassEncoder::create(*this, WTFMove(encoder));
-}
-
-void WebGPUCommandEncoder::copyBufferToBuffer(const WebGPUBuffer& src, unsigned long srcOffset, const WebGPUBuffer& dst, unsigned long dstOffset, unsigned long size)
-{
-    if (!m_commandBuffer) {
-        LOG(WebGPU, "WebGPUCommandEncoder::copyBufferToBuffer(): Invalid operation!");
-        return;
-    }
-    if (!src.buffer() || !dst.buffer()) {
-        LOG(WebGPU, "WebGPUCommandEncoder::copyBufferToBuffer(): Invalid GPUBuffer!");
-        return;
-    }
-
-    // FIXME: Add Web GPU validation.
-
-    m_commandBuffer->copyBufferToBuffer(makeRef(*src.buffer()), srcOffset, makeRef(*dst.buffer()), dstOffset, size);
-}
-
-void WebGPUCommandEncoder::copyBufferToTexture(const WebGPUBufferCopyView& srcBuffer, const WebGPUTextureCopyView& dstTexture, const GPUExtent3D& size)
-{
-    if (!m_commandBuffer) {
-        LOG(WebGPU, "WebGPUCommandEncoder::copyBufferToTexture(): Invalid operation!");
-        return;
-    }
-    auto gpuBufferView = srcBuffer.tryCreateGPUBufferCopyView();
-    auto gpuTextureView = dstTexture.tryCreateGPUTextureCopyView();
-
-    if (!gpuBufferView || !gpuTextureView)
-        return;
-
-    // FIXME: Add Web GPU validation.
-
-    m_commandBuffer->copyBufferToTexture(WTFMove(*gpuBufferView), WTFMove(*gpuTextureView), size);
-}
-
-void WebGPUCommandEncoder::copyTextureToBuffer(const WebGPUTextureCopyView& srcTexture, const WebGPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
-{
-    if (!m_commandBuffer) {
-        LOG(WebGPU, "WebGPUCommandEncoder::copyTextureToBuffer(): Invalid operation!");
-        return;
-    }
-    auto gpuTextureView = srcTexture.tryCreateGPUTextureCopyView();
-    auto gpuBufferView = dstBuffer.tryCreateGPUBufferCopyView();
-
-    if (!gpuTextureView || !gpuBufferView)
-        return;
-
-    // FIXME: Add Web GPU validation.
-
-    m_commandBuffer->copyTextureToBuffer(WTFMove(*gpuTextureView), WTFMove(*gpuBufferView), size);
-}
-
-void WebGPUCommandEncoder::copyTextureToTexture(const WebGPUTextureCopyView& src, const WebGPUTextureCopyView& dst, const GPUExtent3D& size)
-{
-    if (!m_commandBuffer) {
-        LOG(WebGPU, "WebGPUCommandEncoder::copyTextureToTexture(): Invalid operation!");
-        return;
-    }
-    auto gpuSrcView = src.tryCreateGPUTextureCopyView();
-    auto gpuDstView = dst.tryCreateGPUTextureCopyView();
-
-    if (!gpuSrcView || !gpuDstView)
-        return;
-
-    // FIXME: Add Web GPU validation.
-
-    m_commandBuffer->copyTextureToTexture(WTFMove(*gpuSrcView), WTFMove(*gpuDstView), size);
-}
-    
-Ref<WebGPUCommandBuffer> WebGPUCommandEncoder::finish()
-{
-    if (!m_commandBuffer) {
-        LOG(WebGPU, "WebGPUCommandEncoder::finish(): Invalid operation!");
-        return WebGPUCommandBuffer::create(nullptr);
-    }
-    // Passes the referenced GPUCommandBuffer to the WebGPUCommandBuffer, invalidating this WebGPUCommandEncoder.
-    return WebGPUCommandBuffer::create(m_commandBuffer.releaseNonNull());
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.h b/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.h
deleted file mode 100644 (file)
index 24d71ba..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#if ENABLE(WEBGPU)
-
-#include "GPUCommandBuffer.h"
-#include "WebGPUCommandBuffer.h"
-#include <wtf/RefCounted.h>
-#include <wtf/RefPtr.h>
-
-namespace WebCore {
-
-class WebGPUBuffer;
-class WebGPURenderPassEncoder;
-class WebGPUTexture;
-
-struct GPUExtent3D;
-struct WebGPURenderPassDescriptor;
-
-struct WebGPUBufferCopyView : GPUBufferCopyViewBase {
-    Optional<GPUBufferCopyView> tryCreateGPUBufferCopyView() const;
-
-    RefPtr<WebGPUBuffer> buffer;
-};
-
-struct WebGPUTextureCopyView : GPUTextureCopyViewBase {
-    Optional<GPUTextureCopyView> tryCreateGPUTextureCopyView() const;
-
-    RefPtr<WebGPUTexture> texture;
-};
-
-class WebGPUCommandEncoder : public RefCounted<WebGPUCommandEncoder> {
-public:
-    static Ref<WebGPUCommandEncoder> create(RefPtr<GPUCommandBuffer>&&);
-
-    Ref<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
-    void copyBufferToBuffer(const WebGPUBuffer&, unsigned long srcOffset, const WebGPUBuffer&, unsigned long dstOffset, unsigned long size);
-    void copyBufferToTexture(const WebGPUBufferCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
-    void copyTextureToBuffer(const WebGPUTextureCopyView&, const WebGPUBufferCopyView&, const GPUExtent3D&);
-    void copyTextureToTexture(const WebGPUTextureCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
-    Ref<WebGPUCommandBuffer> finish();
-
-private:
-    WebGPUCommandEncoder(RefPtr<GPUCommandBuffer>&&);
-
-    RefPtr<GPUCommandBuffer> m_commandBuffer;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(WEBGPU)
diff --git a/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.idl b/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.idl
deleted file mode 100644 (file)
index bb96b4a..0000000
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
-
-typedef unsigned long u32;
-typedef unsigned long long u64;
-
-[
-    Conditional=WEBGPU,
-    EnabledAtRuntime=WebGPU,
-    ImplementedAs=WebGPUBufferCopyView
-] dictionary GPUBufferCopyView {
-    WebGPUBuffer buffer;
-    u64 offset;
-    u64 rowPitch;
-    u32 imageHeight;
-};
-
-[
-    Conditional=WEBGPU,
-    EnabledAtRuntime=WebGPU,
-    ImplementedAs=WebGPUTextureCopyView
-] dictionary GPUTextureCopyView {
-    WebGPUTexture texture;
-    u32 mipLevel;
-    u32 arrayLayer;
-    GPUOrigin3D origin;
-};
-
-[
-    Conditional=WEBGPU,
-    EnabledAtRuntime=WebGPU,
-    ImplementationLacksVTable,
-    InterfaceName=GPUCommandEncoder
-] interface WebGPUCommandEncoder {
-    WebGPURenderPassEncoder beginRenderPass(WebGPURenderPassDescriptor descriptor);
-
-    void copyBufferToBuffer(
-        WebGPUBuffer src,
-        u64 srcOffset,
-        WebGPUBuffer dst,
-        u64 dstOffset,
-        u64 size);
-
-    void copyBufferToTexture(
-        GPUBufferCopyView source,
-        GPUTextureCopyView destination,
-        GPUExtent3D copySize);
-
-    void copyTextureToBuffer(
-        GPUTextureCopyView source,
-        GPUBufferCopyView destination,
-        GPUExtent3D copySize);
-
-    void copyTextureToTexture(
-        GPUTextureCopyView source,
-        GPUTextureCopyView destination,
-        GPUExtent3D copySize);
-
-    WebGPUCommandBuffer finish();
-
-    // Not Yet Implemented
-    // WebGPUComputePassEncoder beginComputePass();
-};
index 361109f..3d689ec 100644 (file)
@@ -47,7 +47,7 @@
 #include "WebGPUBindGroupLayout.h"
 #include "WebGPUBuffer.h"
 #include "WebGPUBufferBinding.h"
-#include "WebGPUCommandEncoder.h"
+#include "WebGPUCommandBuffer.h"
 #include "WebGPUPipelineLayout.h"
 #include "WebGPUPipelineLayoutDescriptor.h"
 #include "WebGPUPipelineStageDescriptor.h"
@@ -137,10 +137,11 @@ Ref<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(const WebGPURenderP
     return WebGPURenderPipeline::create(WTFMove(pipeline));
 }
 
-Ref<WebGPUCommandEncoder> WebGPUDevice::createCommandEncoder() const
+RefPtr<WebGPUCommandBuffer> WebGPUDevice::createCommandBuffer() const
 {
-    auto commandBuffer = m_device->tryCreateCommandBuffer();
-    return WebGPUCommandEncoder::create(WTFMove(commandBuffer));
+    if (auto commandBuffer = m_device->createCommandBuffer())
+        return WebGPUCommandBuffer::create(commandBuffer.releaseNonNull());
+    return nullptr;
 }
 
 Ref<WebGPUSwapChain> WebGPUDevice::createSwapChain(const WebGPUSwapChainDescriptor& descriptor) const
index 41feae0..86d57c3 100644 (file)
@@ -41,7 +41,7 @@ class ScriptExecutionContext;
 class WebGPUBindGroup;
 class WebGPUBindGroupLayout;
 class WebGPUBuffer;
-class WebGPUCommandEncoder;
+class WebGPUCommandBuffer;
 class WebGPUPipelineLayout;
 class WebGPURenderPipeline;
 class WebGPUSampler;
@@ -76,7 +76,7 @@ public:
     RefPtr<WebGPUShaderModule> createShaderModule(WebGPUShaderModuleDescriptor&&) const;
     Ref<WebGPURenderPipeline> createRenderPipeline(const WebGPURenderPipelineDescriptor&) const;
 
-    Ref<WebGPUCommandEncoder> createCommandEncoder() const;
+    RefPtr<WebGPUCommandBuffer> createCommandBuffer() const;
 
     Ref<WebGPUSwapChain> createSwapChain(const WebGPUSwapChainDescriptor&) const;
 
index 4abaa18..f4635a3 100644 (file)
@@ -54,8 +54,8 @@ typedef unsigned long GPUTextureUsageFlags;
     WebGPUShaderModule createShaderModule(WebGPUShaderModuleDescriptor descriptor);
     WebGPURenderPipeline createRenderPipeline(WebGPURenderPipelineDescriptor descriptor);
 
-    // FIXME: Currently, GPUCommandEncoderDescriptor is an empty dictionary.
-    WebGPUCommandEncoder createCommandEncoder(/*GPUCommandEncoderDescriptor descriptor*/);
+    // FIXME: Currently, WebGPUCommandBufferDescriptor is an empty dictionary.
+    WebGPUCommandBuffer createCommandBuffer(/*WebGPUCommandBufferDescriptor descriptor*/);
 
     WebGPUSwapChain createSwapChain(WebGPUSwapChainDescriptor descriptor);
 
index 2cdeca7..1ebba92 100644 (file)
 
 namespace WebCore {
 
-WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder(Ref<WebGPUCommandEncoder>&& creator)
+WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder(Ref<WebGPUCommandBuffer>&& creator)
     : m_commandBuffer(WTFMove(creator))
 {
 }
 
-void WebGPUProgrammablePassEncoder::endPass()
+Ref<WebGPUCommandBuffer> WebGPUProgrammablePassEncoder::endPass()
 {
-    if (!passEncoder()) {
-        LOG(WebGPU, "GPUProgrammablePassEncoder::endPass(): Invalid operation!");
-        return;
-    }
-    passEncoder()->endPass();
+    passEncoder().endPass();
+    return m_commandBuffer.copyRef();
 }
 
 void WebGPUProgrammablePassEncoder::setBindGroup(unsigned index, WebGPUBindGroup& bindGroup) const
 {
-    if (!passEncoder()) {
-        LOG(WebGPU, "GPUProgrammablePassEncoder::setBindGroup(): Invalid operation!");
-        return;
-    }
     // Maximum number of bind groups supported in Web GPU.
     if (index >= 4) {
-        LOG(WebGPU, "GPUProgrammablePassEncoder::setBindGroup(): Invalid index!");
+        LOG(WebGPU, "WebGPUProgrammablePassEncoder::setBindGroup(): Invalid index!");
         return;
     }
     if (!bindGroup.bindGroup()) {
-        LOG(WebGPU, "GPUProgrammablePassEncoder::setBindGroup(): Invalid WebGPUBindGroup!");
+        LOG(WebGPU, "WebGPUProgrammablePassEncoder::setBindGroup(): Invalid WebGPUBindGroup!");
         return;
     }
     // FIXME: Any validation (e.g. index duplicates, not in pipeline layout).
-    passEncoder()->setBindGroup(index, *bindGroup.bindGroup());
+    passEncoder().setBindGroup(index, *bindGroup.bindGroup());
 }
 
 void WebGPUProgrammablePassEncoder::setPipeline(const WebGPURenderPipeline& pipeline)
 {
-    if (!passEncoder()) {
-        LOG(WebGPU, "GPUProgrammablePassEncoder::setPipeline(): Invalid operation!");
-        return;
-    }
     if (!pipeline.renderPipeline()) {
         LOG(WebGPU, "GPUProgrammablePassEncoder::setPipeline(): Invalid pipeline!");
         return;
     }
-    passEncoder()->setPipeline(makeRef(*pipeline.renderPipeline()));
+    passEncoder().setPipeline(makeRef(*pipeline.renderPipeline()));
 }
 
 } // namespace WebCore
index 356ecb3..5400414 100644 (file)
@@ -27,7 +27,7 @@
 
 #if ENABLE(WEBGPU)
 
-#include "WebGPUCommandEncoder.h"
+#include "WebGPUCommandBuffer.h"
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
@@ -40,17 +40,17 @@ class WebGPUProgrammablePassEncoder : public RefCounted<WebGPUProgrammablePassEn
 public:
     virtual ~WebGPUProgrammablePassEncoder() = default;
 
-    void endPass();
+    Ref<WebGPUCommandBuffer> endPass();
     void setBindGroup(unsigned, WebGPUBindGroup&) const;
     void setPipeline(const WebGPURenderPipeline&);
 
 protected:
-    WebGPUProgrammablePassEncoder(Ref<WebGPUCommandEncoder>&&);
+    WebGPUProgrammablePassEncoder(Ref<WebGPUCommandBuffer>&&);
 
-    virtual GPUProgrammablePassEncoder* passEncoder() const = 0;
+    virtual GPUProgrammablePassEncoder& passEncoder() const = 0;
 
 private:
-    Ref<WebGPUCommandEncoder> m_commandBuffer;
+    Ref<WebGPUCommandBuffer> m_commandBuffer;
 };
 
 } // namespace WebCore
index 57718c2..3acd639 100644 (file)
@@ -31,7 +31,7 @@ typedef unsigned long u32;
     EnabledAtRuntime=WebGPU,
     SkipVTableValidation
 ] interface WebGPUProgrammablePassEncoder {
-    void endPass();
+    WebGPUCommandBuffer endPass();
     void setBindGroup(u32 index, WebGPUBindGroup bindGroup/*, optional sequence<u32> dynamicOffsets*/);
     void setPipeline(WebGPURenderPipeline pipeline); // FIXME: Support WebGPUComputePipelines.
 };
index b4f83e4..b75dd75 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "GPUCommandBuffer.h"
 #include "GPUQueue.h"
-#include "Logging.h"
 #include "WebGPUCommandBuffer.h"
 
 namespace WebCore {
@@ -45,19 +44,11 @@ WebGPUQueue::WebGPUQueue(Ref<GPUQueue>&& queue)
 {
 }
 
-void WebGPUQueue::submit(const Vector<RefPtr<WebGPUCommandBuffer>>& buffers)
+void WebGPUQueue::submit(Vector<RefPtr<WebGPUCommandBuffer>>&& buffers)
 {
-    Vector<Ref<GPUCommandBuffer>> gpuBuffers;
-    gpuBuffers.reserveCapacity(buffers.size());
-    
-    for (auto& buffer : buffers) {
-        if (!buffer || !buffer->commandBuffer()) {
-            LOG(WebGPU, "GPUQueue::submit(): Invalid GPUCommandBuffer in list!");
-            return;
-        }
-        gpuBuffers.uncheckedAppend(makeRef(*buffer->commandBuffer()));
-    }
-
+    auto gpuBuffers = buffers.map([] (auto& buffer) -> Ref<GPUCommandBuffer> {
+        return buffer->commandBuffer();
+    });
     m_queue->submit(WTFMove(gpuBuffers));
 }
 
index f0a76f8..446edf8 100644 (file)
@@ -41,7 +41,7 @@ class WebGPUQueue : public RefCounted<WebGPUQueue> {
 public:
     static RefPtr<WebGPUQueue> create(RefPtr<GPUQueue>&&);
 
-    void submit(const Vector<RefPtr<WebGPUCommandBuffer>>&);
+    void submit(Vector<RefPtr<WebGPUCommandBuffer>>&&);
 
     String label() const { return m_queue->label(); }
     void setLabel(const String& label) { m_queue->setLabel(label); }
index 5a1a15a..2f6a709 100644 (file)
@@ -34,4 +34,4 @@
     // FIXME: Unimplemented.
     // void signal(WebGPUFence fence, u64 signalValue);
     // void wait(WebGPUFence fence, u64 valueToWait);
-};
+};
\ No newline at end of file
index ff58aa4..988329b 100644 (file)
 
 namespace WebCore {
 
-Ref<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandEncoder>&& commandBuffer, RefPtr<GPURenderPassEncoder>&& encoder)
+Ref<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandBuffer>&& commandBuffer, Ref<GPURenderPassEncoder>&& encoder)
 {
     return adoptRef(*new WebGPURenderPassEncoder(WTFMove(commandBuffer), WTFMove(encoder)));
 }
 
-WebGPURenderPassEncoder::WebGPURenderPassEncoder(Ref<WebGPUCommandEncoder>&& creator, RefPtr<GPURenderPassEncoder>&& encoder)
+WebGPURenderPassEncoder::WebGPURenderPassEncoder(Ref<WebGPUCommandBuffer>&& creator, Ref<GPURenderPassEncoder>&& encoder)
     : WebGPUProgrammablePassEncoder(WTFMove(creator))
     , m_passEncoder(WTFMove(encoder))
 {
@@ -52,14 +52,11 @@ void WebGPURenderPassEncoder::setVertexBuffers(unsigned long startSlot, Vector<R
 #if !LOG_DISABLED
     const char* const functionName = "GPURenderPassEncoder::setVertexBuffers()";
 #endif
-    if (!m_passEncoder) {
-        LOG(WebGPU, "%s: Invalid operation!", functionName);
-        return;
-    }
     if (buffers.isEmpty() || buffers.size() != offsets.size()) {
         LOG(WebGPU, "%s: Invalid number of buffers or offsets!", functionName);
         return;
     }
+
     if (startSlot + buffers.size() > maxVertexBuffers) {
         LOG(WebGPU, "%s: Invalid startSlot %lu for %lu buffers!", functionName, startSlot, buffers.size());
         return;
@@ -87,15 +84,11 @@ void WebGPURenderPassEncoder::setVertexBuffers(unsigned long startSlot, Vector<R
 
 void WebGPURenderPassEncoder::draw(unsigned long vertexCount, unsigned long instanceCount, unsigned long firstVertex, unsigned long firstInstance)
 {
-    if (!m_passEncoder) {
-        LOG(WebGPU, "GPURenderPassEncoder::draw(): Invalid operation!");
-        return;
-    }
     // FIXME: What kind of validation do we need to handle here?
     m_passEncoder->draw(vertexCount, instanceCount, firstVertex, firstInstance);
 }
 
-GPUProgrammablePassEncoder* WebGPURenderPassEncoder::passEncoder() const
+GPUProgrammablePassEncoder& WebGPURenderPassEncoder::passEncoder() const
 {
     return m_passEncoder.get();
 }
index 479279c..d0de0d7 100644 (file)
@@ -40,17 +40,17 @@ class WebGPUBuffer;
 
 class WebGPURenderPassEncoder final : public WebGPUProgrammablePassEncoder {
 public:
-    static Ref<WebGPURenderPassEncoder> create(Ref<WebGPUCommandEncoder>&&, RefPtr<GPURenderPassEncoder>&&);
+    static Ref<WebGPURenderPassEncoder> create(Ref<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
 
     void setVertexBuffers(unsigned long, Vector<RefPtr<WebGPUBuffer>>&&, Vector<unsigned long long>&&);
     void draw(unsigned long vertexCount, unsigned long instanceCount, unsigned long firstVertex, unsigned long firstInstance);
 
 private:
-    WebGPURenderPassEncoder(Ref<WebGPUCommandEncoder>&&, RefPtr<GPURenderPassEncoder>&&);
+    WebGPURenderPassEncoder(Ref<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
 
-    GPUProgrammablePassEncoder* passEncoder() const final;
+    GPUProgrammablePassEncoder& passEncoder() const final;
 
-    RefPtr<GPURenderPassEncoder> m_passEncoder;
+    Ref<GPURenderPassEncoder> m_passEncoder;
 };
 
 } // namespace WebCore
index 36259d7..db61d47 100644 (file)
@@ -50,7 +50,7 @@ Ref<WebGPUTexture> WebGPUSwapChain::getCurrentTexture()
         return WebGPUTexture::create(nullptr);
     }
     m_currentTexture = WebGPUTexture::create(m_swapChain->tryGetCurrentTexture());
-    return makeRef(*m_currentTexture);
+    return m_currentTexture.releaseNonNull();
 }
 
 void WebGPUSwapChain::destroy()
index 66345c6..5d188d3 100644 (file)
@@ -352,11 +352,10 @@ Modules/webgpu/WHLSL/WHLSLPrepare.cpp
 Modules/webgpu/WebGPU.cpp
 Modules/webgpu/WebGPUBindGroup.cpp
 Modules/webgpu/WebGPUBindGroupDescriptor.cpp
-Modules/webgpu/WebGPUCommandBuffer.cpp
-Modules/webgpu/WebGPUCommandEncoder.cpp
 Modules/webgpu/WebGPUAdapter.cpp
 Modules/webgpu/WebGPUBindGroupLayout.cpp
 Modules/webgpu/WebGPUBuffer.cpp
+Modules/webgpu/WebGPUCommandBuffer.cpp
 Modules/webgpu/WebGPUDevice.cpp
 Modules/webgpu/WebGPUQueue.cpp
 Modules/webgpu/WebGPUPipelineLayout.cpp
@@ -3340,7 +3339,6 @@ JSWebGPUBindGroupLayout.cpp
 JSWebGPUBuffer.cpp
 JSWebGPUBufferBinding.cpp
 JSWebGPUCommandBuffer.cpp
-JSWebGPUCommandEncoder.cpp
 JSWebGPUDevice.cpp
 JSWebGPUQueue.cpp
 JSWebGPUPipelineDescriptorBase.cpp
index 343467c..1812e90 100644 (file)
                D05A99E621C9BF2C00032B75 /* WebGPUPipelineLayout.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUPipelineLayout.idl; sourceTree = "<group>"; };
                D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FormatBlockCommand.cpp; sourceTree = "<group>"; };
                D05CED280A40BB2C00C5AF38 /* FormatBlockCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FormatBlockCommand.h; sourceTree = "<group>"; };
-               D05DD6DD223884060097A834 /* WebGPUCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandBuffer.cpp; sourceTree = "<group>"; };
-               D05DD6DE223884070097A834 /* WebGPUCommandBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandBuffer.h; sourceTree = "<group>"; };
-               D05DD6DF223884070097A834 /* WebGPUCommandBuffer.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandBuffer.idl; sourceTree = "<group>"; };
                D060D88421825D5F00339318 /* WebGPUShaderModuleDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUShaderModuleDescriptor.idl; sourceTree = "<group>"; };
                D060D8872182697000339318 /* WebGPUShaderModuleDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUShaderModuleDescriptor.h; sourceTree = "<group>"; };
                D0615FCC217FE5C6008A48A8 /* WebGPUShaderModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUShaderModule.h; sourceTree = "<group>"; };
                D0DA0BE6217930E2007FE2AC /* WebGPUSwapChain.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUSwapChain.idl; sourceTree = "<group>"; };
                D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUShaderStageBit.h; sourceTree = "<group>"; };
                D0DE8FB9222E09E200882550 /* GPUShaderStageBit.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUShaderStageBit.idl; sourceTree = "<group>"; };
-               D0EACF7621937228000FA75C /* WebGPUCommandEncoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandEncoder.h; sourceTree = "<group>"; };
-               D0EACF7721937228000FA75C /* WebGPUCommandEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandEncoder.cpp; sourceTree = "<group>"; };
-               D0EACF7821937228000FA75C /* WebGPUCommandEncoder.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandEncoder.idl; sourceTree = "<group>"; };
+               D0EACF7621937228000FA75C /* WebGPUCommandBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandBuffer.h; sourceTree = "<group>"; };
+               D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandBuffer.cpp; sourceTree = "<group>"; };
+               D0EACF7821937228000FA75C /* WebGPUCommandBuffer.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandBuffer.idl; sourceTree = "<group>"; };
                D0EACF842193B02E000FA75C /* WebGPUTexture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUTexture.h; sourceTree = "<group>"; };
                D0EACF852193B02E000FA75C /* WebGPUTexture.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUTexture.cpp; sourceTree = "<group>"; };
                D0EACF862193B02E000FA75C /* WebGPUTexture.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUTexture.idl; sourceTree = "<group>"; };
                                D0D8648E21B70676003C983C /* WebGPUBuffer.idl */,
                                D0BE104C21E68F1500E42A89 /* WebGPUBufferBinding.h */,
                                D0BE104D21E68F1500E42A89 /* WebGPUBufferBinding.idl */,
-                               D05DD6DD223884060097A834 /* WebGPUCommandBuffer.cpp */,
-                               D05DD6DE223884070097A834 /* WebGPUCommandBuffer.h */,
-                               D05DD6DF223884070097A834 /* WebGPUCommandBuffer.idl */,
-                               D0EACF7721937228000FA75C /* WebGPUCommandEncoder.cpp */,
-                               D0EACF7621937228000FA75C /* WebGPUCommandEncoder.h */,
-                               D0EACF7821937228000FA75C /* WebGPUCommandEncoder.idl */,
+                               D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */,
+                               D0EACF7621937228000FA75C /* WebGPUCommandBuffer.h */,
+                               D0EACF7821937228000FA75C /* WebGPUCommandBuffer.idl */,
                                D00F595321701D8C000D71DB /* WebGPUDevice.cpp */,
                                D00F595221701D8C000D71DB /* WebGPUDevice.h */,
                                D00F595421701D8C000D71DB /* WebGPUDevice.idl */,
index c349593..e6f109c 100644 (file)
@@ -84,8 +84,6 @@ namespace WebCore {
     macro(GPUBufferUsage) \
     macro(GPUCanvasContext) \
     macro(GPUShaderModule) \
-    macro(GPUCommandBuffer) \
-    macro(GPUCommandEncoder) \
     macro(GPUShaderStageBit) \
     macro(GPUSwapChain) \
     macro(GPUTextureUsage) \
@@ -203,6 +201,7 @@ namespace WebCore {
     macro(WebGPUBindGroup) \
     macro(WebGPUBindGroupLayout) \
     macro(WebGPUBuffer) \
+    macro(WebGPUCommandBuffer) \
     macro(WebGPUDevice) \
     macro(WebGPUIndexFormat) \
     macro(WebGPUInputStepMode) \
index cbb22b9..3a928bb 100644 (file)
@@ -27,9 +27,7 @@
 
 #if ENABLE(WEBGPU)
 
-#include "GPUBuffer.h"
 #include "GPUOrigin3D.h"
-#include "GPUTexture.h"
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
@@ -40,7 +38,9 @@ OBJC_PROTOCOL(MTLCommandBuffer);
 
 namespace WebCore {
 
+class GPUBuffer;
 class GPUDevice;
+class GPUTexture;
 
 struct GPUExtent3D;
 
@@ -81,7 +81,7 @@ struct GPUTextureCopyView final : GPUTextureCopyViewBase {
 
 class GPUCommandBuffer : public RefCounted<GPUCommandBuffer> {
 public:
-    static RefPtr<GPUCommandBuffer> tryCreate(const GPUDevice&);
+    static RefPtr<GPUCommandBuffer> create(GPUDevice&);
 
     PlatformCommandBuffer* platformCommandBuffer() const { return m_platformCommandBuffer.get(); }
     const Vector<Ref<GPUBuffer>>& usedBuffers() const { return m_usedBuffers; }
index 9bdf666..8b73518 100644 (file)
@@ -83,9 +83,9 @@ RefPtr<GPURenderPipeline> GPUDevice::createRenderPipeline(GPURenderPipelineDescr
     return GPURenderPipeline::create(*this, WTFMove(descriptor));
 }
 
-RefPtr<GPUCommandBuffer> GPUDevice::tryCreateCommandBuffer() const
+RefPtr<GPUCommandBuffer> GPUDevice::createCommandBuffer()
 {
-    return GPUCommandBuffer::tryCreate(*this);
+    return GPUCommandBuffer::create(*this);
 }
 
 RefPtr<GPUSwapChain> GPUDevice::tryCreateSwapChain(const GPUSwapChainDescriptor& descriptor, int width, int height) const
index 8fe9693..5cf4eb7 100644 (file)
@@ -37,6 +37,9 @@ OBJC_PROTOCOL(MTLDevice);
 
 namespace WebCore {
 
+using PlatformDevice = MTLDevice;
+using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>;
+
 class GPUBindGroupLayout;
 class GPUBuffer;
 class GPUCommandBuffer;
@@ -55,9 +58,6 @@ struct GPURequestAdapterOptions;
 struct GPUSamplerDescriptor;
 struct GPUShaderModuleDescriptor;
 struct GPUTextureDescriptor;
-    
-using PlatformDevice = MTLDevice;
-using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>;
 
 class GPUDevice : public RefCounted<GPUDevice>, public CanMakeWeakPtr<GPUDevice> {
 public:
@@ -73,7 +73,7 @@ public:
     RefPtr<GPUShaderModule> createShaderModule(GPUShaderModuleDescriptor&&) const;
     RefPtr<GPURenderPipeline> createRenderPipeline(GPURenderPipelineDescriptor&&) const;
 
-    RefPtr<GPUCommandBuffer> tryCreateCommandBuffer() const;
+    RefPtr<GPUCommandBuffer> createCommandBuffer();
 
     RefPtr<GPUSwapChain> tryCreateSwapChain(const GPUSwapChainDescriptor&, int width, int height) const;
 
index e4c4239..c92c544 100644 (file)
 
 #if ENABLE(WEBGPU)
 
+#import "GPUBuffer.h"
 #import "GPUDevice.h"
 #import "GPUExtent3D.h"
 #import "GPUQueue.h"
+#import "GPUTexture.h"
 #import "Logging.h"
 
 #import <Metal/Metal.h>
@@ -39,7 +41,7 @@
 
 namespace WebCore {
 
-RefPtr<GPUCommandBuffer> GPUCommandBuffer::tryCreate(const GPUDevice& device)
+RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUDevice& device)
 {
     if (!device.platformDevice()) {
         LOG(WebGPU, "GPUCommandBuffer::create(): Invalid GPUDevice!");