Title: [242931] trunk
Revision
242931
Author
justin_...@apple.com
Date
2019-03-13 18:42:12 -0700 (Wed, 13 Mar 2019)

Log Message

[Web GPU] Updates to GPUCommandBuffer for new GPUCommandQueue concept
https://bugs.webkit.org/show_bug.cgi?id=195083
<rdar://problem/48423591>

Reviewed by Dean Jackson.

Source/WebCore:

WebGPUCommandBuffer now represents a completed GPUCommandBuffer that can only be used in queue submits. The previous WebGPUCommandBuffer
is now WebGPUCommandEncoder.

Affected Web GPU tests updated to match new API.

New files and symbols:
* CMakeLists.txt:
* DerivedSources.make:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/WebCoreBuiltinNames.h:

Implement new WebGPUCommandBuffer, now just a DOM object carrier for a finished GPUCommandBuffer:
* Modules/webgpu/WebGPUCommandBuffer.cpp:
(WebCore::WebGPUCommandBuffer::create):
(WebCore::WebGPUCommandBuffer::WebGPUCommandBuffer):
(WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const): Deleted.
(WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const): Deleted.
(WebCore::WebGPUCommandBuffer::beginRenderPass): Deleted.
(WebCore::WebGPUCommandBuffer::copyBufferToBuffer): Deleted.
(WebCore::WebGPUCommandBuffer::copyBufferToTexture): Deleted.
(WebCore::WebGPUCommandBuffer::copyTextureToBuffer): Deleted.
(WebCore::WebGPUCommandBuffer::copyTextureToTexture): Deleted.
* Modules/webgpu/WebGPUCommandBuffer.h:
(WebCore::WebGPUCommandBuffer::commandBuffer):
(WebCore::WebGPUCommandBuffer::commandBuffer const): Deleted.
* Modules/webgpu/WebGPUCommandBuffer.idl:

Rename old WebGPUCommandBuffer to WebGPUCommandEncoder:
* Modules/webgpu/WebGPUCommandEncoder.cpp: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp.
(WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const):
(WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const):
(WebCore::WebGPUCommandEncoder::create):
(WebCore::WebGPUCommandEncoder::WebGPUCommandEncoder):
(WebCore::WebGPUCommandEncoder::beginRenderPass):
(WebCore::WebGPUCommandEncoder::copyBufferToBuffer):
(WebCore::WebGPUCommandEncoder::copyBufferToTexture):
(WebCore::WebGPUCommandEncoder::copyTextureToBuffer):
(WebCore::WebGPUCommandEncoder::copyTextureToTexture):
(WebCore::WebGPUCommandEncoder::finish): Added. "Completes" this and invalidates it. Returns its GPUCommandBuffer, ready for submission.
* Modules/webgpu/WebGPUCommandEncoder.h: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h.
* Modules/webgpu/WebGPUCommandEncoder.idl: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl.
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::createCommandEncoder const): Renamed fom createCommandBuffer. Now returns non-nullable.
(WebCore::WebGPUDevice::createCommandBuffer const): Deleted.
* Modules/webgpu/WebGPUDevice.h:
* Modules/webgpu/WebGPUDevice.idl:
* Modules/webgpu/WebGPUProgrammablePassEncoder.cpp:
(WebCore::WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder):
(WebCore::WebGPUProgrammablePassEncoder::endPass): No longer returns the original WebGPUCommandBuffer.
(WebCore::WebGPUProgrammablePassEncoder::setBindGroup const):
(WebCore::WebGPUProgrammablePassEncoder::setPipeline):
* Modules/webgpu/WebGPUProgrammablePassEncoder.h:
* Modules/webgpu/WebGPUProgrammablePassEncoder.idl:
* Modules/webgpu/WebGPUQueue.cpp:
(WebCore::WebGPUQueue::submit): Replace unnecessary rvalue reference parameter.
* Modules/webgpu/WebGPUQueue.h:
* Modules/webgpu/WebGPUQueue.idl:
* Modules/webgpu/WebGPURenderPassEncoder.cpp:
(WebCore::WebGPURenderPassEncoder::create):
(WebCore::WebGPURenderPassEncoder::WebGPURenderPassEncoder):
(WebCore::WebGPURenderPassEncoder::setVertexBuffers):
(WebCore::WebGPURenderPassEncoder::draw):
(WebCore::WebGPURenderPassEncoder::passEncoder const): Now returns a pointer since it is properly backed by a RefPtr.
* Modules/webgpu/WebGPURenderPassEncoder.h:
* Modules/webgpu/WebGPUSwapChain.cpp:
(WebCore::WebGPUSwapChain::getCurrentTexture): No longer invalidates m_currentTexture. Doh!
* platform/graphics/gpu/GPUCommandBuffer.h: Missing includes for the *CopyView structs.
* platform/graphics/gpu/GPUDevice.cpp:
(WebCore::GPUDevice::tryCreateCommandBuffer const): Renamed from createCommandBuffer.
(WebCore::GPUDevice::createCommandBuffer): Deleted.
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
(WebCore::GPUCommandBuffer::tryCreate): Renamed from create.
(WebCore::GPUCommandBuffer::create): Deleted.

LayoutTests:

Update existing Web GPU tests for GPUCommandEncoder and new GPUCommandBuffer.

* webgpu/blit-commands.html:
* webgpu/buffer-command-buffer-races.html:
* webgpu/buffer-resource-triangles.html:
* webgpu/command-buffers-expected.txt:
* webgpu/command-buffers.html:
* webgpu/depth-enabled-triangle-strip.html:
* webgpu/js/webgpu-functions.js:
(beginBasicRenderPass):
* webgpu/render-command-encoding.html:
* webgpu/simple-triangle-strip.html:
* webgpu/texture-triangle-strip.html:
* webgpu/vertex-buffer-triangle-strip.html:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (242930 => 242931)


--- trunk/LayoutTests/ChangeLog	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/ChangeLog	2019-03-14 01:42:12 UTC (rev 242931)
@@ -1,3 +1,26 @@
+2019-03-13  Justin Fan  <justin_...@apple.com>
+
+        [Web GPU] Updates to GPUCommandBuffer for new GPUCommandQueue concept
+        https://bugs.webkit.org/show_bug.cgi?id=195083
+        <rdar://problem/48423591>
+
+        Reviewed by Dean Jackson.
+
+        Update existing Web GPU tests for GPUCommandEncoder and new GPUCommandBuffer.
+
+        * webgpu/blit-commands.html:
+        * webgpu/buffer-command-buffer-races.html:
+        * webgpu/buffer-resource-triangles.html:
+        * webgpu/command-buffers-expected.txt:
+        * webgpu/command-buffers.html:
+        * webgpu/depth-enabled-triangle-strip.html:
+        * webgpu/js/webgpu-functions.js:
+        (beginBasicRenderPass):
+        * webgpu/render-command-encoding.html:
+        * webgpu/simple-triangle-strip.html:
+        * webgpu/texture-triangle-strip.html:
+        * webgpu/vertex-buffer-triangle-strip.html:
+
 2019-03-13  Alicia Boya GarcĂ­a  <ab...@igalia.com>
 
         [GTK] Unreviewed test gardening

Modified: trunk/LayoutTests/webgpu/blit-commands.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/blit-commands.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/blit-commands.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -85,12 +85,13 @@
         imageHeight: 0
     };
 
-    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]);
+    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()]);
     bufferA.destroy();
     bufferB.destroy();
     textureA.destroy();

Modified: trunk/LayoutTests/webgpu/buffer-command-buffer-races.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/buffer-command-buffer-races.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/buffer-command-buffer-races.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -76,13 +76,13 @@
 }
 
 function drawAndSubmitCommands(device, pipeline, attachment, vertexBuffer, colorBuffer) {
-    const commandBuffer = device.createCommandBuffer();
-    const encoder = commandBuffer.beginRenderPass({ colorAttachments: [attachment] });
+    const commandEncoder = device.createCommandEncoder();
+    const encoder = commandEncoder.beginRenderPass({ colorAttachments: [attachment] });
     encoder.setVertexBuffers(0, [vertexBuffer, colorBuffer], [0, 0]);
     encoder.setPipeline(pipeline);
     encoder.draw(3, 1, 0, 0);
     encoder.endPass();
-    device.getQueue().submit([commandBuffer]);
+    device.getQueue().submit([commandEncoder.finish()]);
 }
 
 async function test() {

Modified: trunk/LayoutTests/webgpu/buffer-resource-triangles.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/buffer-resource-triangles.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/buffer-resource-triangles.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -194,8 +194,8 @@
     });
 
     Promise.all(bufferPromises).then(() => {
-        const commandBuffer = device.createCommandBuffer();
-        const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
+        const commandEncoder = device.createCommandEncoder();
+        const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
         passEncoder.setPipeline(pipeline);
 
         // Vertex data for upper triangles.
@@ -205,9 +205,9 @@
         passEncoder.setVertexBuffers(0, [verticesBuffer], [0]);
         passEncoder.draw(9, 1, 0, 0);
 
-        const endCommandBuffer = passEncoder.endPass();
+        passEncoder.endPass();
         const queue = device.getQueue();
-        queue.submit([endCommandBuffer]);
+        queue.submit([commandEncoder.finish()]);
 
         if (window.testRunner)
             testRunner.notifyDone();

Modified: trunk/LayoutTests/webgpu/command-buffers-expected.txt (242930 => 242931)


--- trunk/LayoutTests/webgpu/command-buffers-expected.txt	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/command-buffers-expected.txt	2019-03-14 01:42:12 UTC (rev 242931)
@@ -1,3 +1,3 @@
 
-PASS Create a default GPUCommandBuffer. 
+PASS Create a default GPUCommandEncoder. 
 

Modified: trunk/LayoutTests/webgpu/command-buffers.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/command-buffers.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/command-buffers.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -6,10 +6,10 @@
 <script>
 promise_test(async () => {
     const device = await getBasicDevice();
-    const commandBuffer = device.createCommandBuffer();
-    assert_true(commandBuffer instanceof WebGPUCommandBuffer, "Successfully created GPUCommandBuffer.");
-}, "Create a default GPUCommandBuffer.");
+    const commandEncoder = device.createCommandEncoder();
+    assert_true(commandEncoder instanceof GPUCommandEncoder, "Successfully created GPUCommandEncoder.");
+}, "Create a default GPUCommandEncoder.");
 
-// FIXME: createCommandBuffer should take a GPUCommandBufferDescriptor, which is currently an empty dictionary.
+// FIXME: createCommandEncoder should take a GPUCommandEncoderDescriptor, which is currently an empty dictionary.
 </script>
 </html>
\ No newline at end of file

Modified: trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -89,7 +89,7 @@
     const inputStateDescriptor = createInputStateDescriptor();
     const depthStateDescriptor = createBasicDepthStateDescriptor();
     const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor, depthStateDescriptor);
-    const commandBuffer = device.createCommandBuffer();
+    const commandEncoder = device.createCommandEncoder();
 
     const basicAttachment = {
         attachment: swapChain.getCurrentTexture().createDefaultTextureView(),
@@ -105,7 +105,7 @@
         clearDepth: 1.0
     };
 
-    const encoder = commandBuffer.beginRenderPass({
+    const encoder = commandEncoder.beginRenderPass({
         colorAttachments: [basicAttachment],
         depthStencilAttachment: depthAttachment
     });
@@ -115,7 +115,7 @@
     encoder.draw(4, 2, 0, 0);
     encoder.endPass();
 
-    device.getQueue().submit([commandBuffer]);
+    device.getQueue().submit([commandEncoder.finish()]);
 
     if (window.testRunner)
         testRunner.notifyDone();

Modified: trunk/LayoutTests/webgpu/js/webgpu-functions.js (242930 => 242931)


--- trunk/LayoutTests/webgpu/js/webgpu-functions.js	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/js/webgpu-functions.js	2019-03-14 01:42:12 UTC (rev 242931)
@@ -66,7 +66,7 @@
     return device.createRenderPipeline(pipelineDescriptor);
 }
 
-function beginBasicRenderPass(swapChain, commandBuffer) {
+function beginBasicRenderPass(swapChain, commandEncoder) {
     const basicAttachment = {
         attachment: swapChain.getCurrentTexture().createDefaultTextureView(),
         loadOp: "clear",
@@ -75,7 +75,7 @@
     }
 
     // FIXME: Flesh out the rest of WebGPURenderPassDescriptor. 
-    return commandBuffer.beginRenderPass({ colorAttachments : [basicAttachment] });
+    return commandEncoder.beginRenderPass({ colorAttachments : [basicAttachment] });
 }
 
 function encodeBasicCommands(renderPassEncoder, renderPipeline, vertexBuffer) {
@@ -83,5 +83,5 @@
         renderPassEncoder.setVertexBuffers(0, [vertexBuffer], [0]);
     renderPassEncoder.setPipeline(renderPipeline);
     renderPassEncoder.draw(4, 1, 0, 0);
-    return renderPassEncoder.endPass();
+    renderPassEncoder.endPass();
 }
\ No newline at end of file

Modified: trunk/LayoutTests/webgpu/render-command-encoding.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/render-command-encoding.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/render-command-encoding.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -34,15 +34,14 @@
     const shaderModule = device.createShaderModule({ code: shaders });
     const pipeline = createBasicPipeline(shaderModule, device);
 
-    const commandBuffer = device.createCommandBuffer();
-    assert_true(commandBuffer instanceof WebGPUCommandBuffer, "createCommandBuffer returned a WebGPUCommandBuffer");
+    const commandEncoder = device.createCommandEncoder();
+    assert_true(commandEncoder instanceof GPUCommandEncoder, "createCommandEncoder returned a GPUCommandEncoder");
 
-    const encoder = beginBasicRenderPass(swapChain, commandBuffer);
+    const encoder = beginBasicRenderPass(swapChain, commandEncoder);
     assert_true(encoder instanceof WebGPURenderPassEncoder, "beginRenderPass() returned a WebGPURenderPassEncoder");
 
     encoder.setPipeline(pipeline);
-    const commandBufferEnd = encoder.endPass();
-    assert_true(commandBufferEnd instanceof WebGPUCommandBuffer, "endPass() returned a WebGPUCommandBuffer");
+    encoder.endPass();
 }, "WebGPURenderPassEncoder created and successfully ended");
 
 </script>

Modified: trunk/LayoutTests/webgpu/simple-triangle-strip.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/simple-triangle-strip.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/simple-triangle-strip.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -52,12 +52,12 @@
     // FIXME: Replace with non-MSL shaders.
     const shaderModule = device.createShaderModule({ code: shaderCode });
     const pipeline = createBasicPipeline(shaderModule, device);
-    const commandBuffer = device.createCommandBuffer();
-    const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
-    const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline);
+    const commandEncoder = device.createCommandEncoder();
+    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
+    encodeBasicCommands(passEncoder, pipeline);
     const queue = device.getQueue();
 
-    queue.submit([endCommandBuffer]);
+    queue.submit([commandEncoder.finish()]);
 
     requestAnimationFrame(() => { 
         if (window.testRunner)

Modified: trunk/LayoutTests/webgpu/texture-triangle-strip.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/texture-triangle-strip.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/texture-triangle-strip.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -186,7 +186,7 @@
 
     // Pipeline and render
     const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor);
-    const commandBuffer = device.createCommandBuffer();
+    const commandEncoder = device.createCommandEncoder();
 
     const bufferCopyView = {
         buffer: textureBuffer,
@@ -200,8 +200,8 @@
         arrayLayer: 0,
         origin: { x: 0, y: 0, z: 0 }
     };
-    commandBuffer.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
-    const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
+    commandEncoder.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
+    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
     passEncoder.setPipeline(pipeline);
     passEncoder.setBindGroup(bindGroupIndex, bindGroup);
     passEncoder.setVertexBuffers(positionBufferIndex, [positionBuffer, textureCoordBuffer], [0, 0]);
@@ -209,7 +209,7 @@
     passEncoder.endPass();
 
     const queue = device.getQueue();
-    queue.submit([commandBuffer]);
+    queue.submit([commandEncoder.finish()]);
     positionBuffer.destroy();
     textureCoordBuffer.destroy();
     texture.destroy();

Modified: trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html (242930 => 242931)


--- trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html	2019-03-14 01:42:12 UTC (rev 242931)
@@ -91,11 +91,11 @@
     const vertexBuffer = createVertexBuffer(device);
     const inputStateDescriptor = createInputStateDescriptor();
     const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor);
-    const commandBuffer = device.createCommandBuffer();
-    const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
-    const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline, vertexBuffer);
+    const commandEncoder = device.createCommandEncoder();
+    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
+    encodeBasicCommands(passEncoder, pipeline, vertexBuffer);
     const queue = device.getQueue();
-    queue.submit([endCommandBuffer]);
+    queue.submit([commandEncoder.finish()]);
     vertexBuffer.destroy();
 
     if (window.testRunner)

Modified: trunk/Source/WebCore/CMakeLists.txt (242930 => 242931)


--- trunk/Source/WebCore/CMakeLists.txt	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/CMakeLists.txt	2019-03-14 01:42:12 UTC (rev 242931)
@@ -494,6 +494,7 @@
     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

Modified: trunk/Source/WebCore/ChangeLog (242930 => 242931)


--- trunk/Source/WebCore/ChangeLog	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/ChangeLog	2019-03-14 01:42:12 UTC (rev 242931)
@@ -1,3 +1,87 @@
+2019-03-13  Justin Fan  <justin_...@apple.com>
+
+        [Web GPU] Updates to GPUCommandBuffer for new GPUCommandQueue concept
+        https://bugs.webkit.org/show_bug.cgi?id=195083
+        <rdar://problem/48423591>
+
+        Reviewed by Dean Jackson.
+
+        WebGPUCommandBuffer now represents a completed GPUCommandBuffer that can only be used in queue submits. The previous WebGPUCommandBuffer
+        is now WebGPUCommandEncoder.
+
+        Affected Web GPU tests updated to match new API.
+
+        New files and symbols:
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * Sources.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/WebCoreBuiltinNames.h:
+
+        Implement new WebGPUCommandBuffer, now just a DOM object carrier for a finished GPUCommandBuffer:
+        * Modules/webgpu/WebGPUCommandBuffer.cpp:
+        (WebCore::WebGPUCommandBuffer::create):
+        (WebCore::WebGPUCommandBuffer::WebGPUCommandBuffer):
+        (WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const): Deleted.
+        (WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const): Deleted.
+        (WebCore::WebGPUCommandBuffer::beginRenderPass): Deleted.
+        (WebCore::WebGPUCommandBuffer::copyBufferToBuffer): Deleted.
+        (WebCore::WebGPUCommandBuffer::copyBufferToTexture): Deleted.
+        (WebCore::WebGPUCommandBuffer::copyTextureToBuffer): Deleted.
+        (WebCore::WebGPUCommandBuffer::copyTextureToTexture): Deleted.
+        * Modules/webgpu/WebGPUCommandBuffer.h:
+        (WebCore::WebGPUCommandBuffer::commandBuffer):
+        (WebCore::WebGPUCommandBuffer::commandBuffer const): Deleted.
+        * Modules/webgpu/WebGPUCommandBuffer.idl:
+
+        Rename old WebGPUCommandBuffer to WebGPUCommandEncoder:
+        * Modules/webgpu/WebGPUCommandEncoder.cpp: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp.
+        (WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const):
+        (WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const):
+        (WebCore::WebGPUCommandEncoder::create):
+        (WebCore::WebGPUCommandEncoder::WebGPUCommandEncoder):
+        (WebCore::WebGPUCommandEncoder::beginRenderPass):
+        (WebCore::WebGPUCommandEncoder::copyBufferToBuffer):
+        (WebCore::WebGPUCommandEncoder::copyBufferToTexture):
+        (WebCore::WebGPUCommandEncoder::copyTextureToBuffer):
+        (WebCore::WebGPUCommandEncoder::copyTextureToTexture):
+        (WebCore::WebGPUCommandEncoder::finish): Added. "Completes" this and invalidates it. Returns its GPUCommandBuffer, ready for submission.
+        * Modules/webgpu/WebGPUCommandEncoder.h: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h.
+        * Modules/webgpu/WebGPUCommandEncoder.idl: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl.
+        * Modules/webgpu/WebGPUDevice.cpp:
+        (WebCore::WebGPUDevice::createCommandEncoder const): Renamed fom createCommandBuffer. Now returns non-nullable.
+        (WebCore::WebGPUDevice::createCommandBuffer const): Deleted.
+        * Modules/webgpu/WebGPUDevice.h:
+        * Modules/webgpu/WebGPUDevice.idl:
+        * Modules/webgpu/WebGPUProgrammablePassEncoder.cpp:
+        (WebCore::WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder):
+        (WebCore::WebGPUProgrammablePassEncoder::endPass): No longer returns the original WebGPUCommandBuffer.
+        (WebCore::WebGPUProgrammablePassEncoder::setBindGroup const):
+        (WebCore::WebGPUProgrammablePassEncoder::setPipeline):
+        * Modules/webgpu/WebGPUProgrammablePassEncoder.h:
+        * Modules/webgpu/WebGPUProgrammablePassEncoder.idl:
+        * Modules/webgpu/WebGPUQueue.cpp:
+        (WebCore::WebGPUQueue::submit): Replace unnecessary rvalue reference parameter.
+        * Modules/webgpu/WebGPUQueue.h:
+        * Modules/webgpu/WebGPUQueue.idl:
+        * Modules/webgpu/WebGPURenderPassEncoder.cpp:
+        (WebCore::WebGPURenderPassEncoder::create):
+        (WebCore::WebGPURenderPassEncoder::WebGPURenderPassEncoder):
+        (WebCore::WebGPURenderPassEncoder::setVertexBuffers):
+        (WebCore::WebGPURenderPassEncoder::draw):
+        (WebCore::WebGPURenderPassEncoder::passEncoder const): Now returns a pointer since it is properly backed by a RefPtr.
+        * Modules/webgpu/WebGPURenderPassEncoder.h:
+        * Modules/webgpu/WebGPUSwapChain.cpp:
+        (WebCore::WebGPUSwapChain::getCurrentTexture): No longer invalidates m_currentTexture. Doh!
+        * platform/graphics/gpu/GPUCommandBuffer.h: Missing includes for the *CopyView structs.
+        * platform/graphics/gpu/GPUDevice.cpp:
+        (WebCore::GPUDevice::tryCreateCommandBuffer const): Renamed from createCommandBuffer.
+        (WebCore::GPUDevice::createCommandBuffer): Deleted.
+        * platform/graphics/gpu/GPUDevice.h:
+        * platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
+        (WebCore::GPUCommandBuffer::tryCreate): Renamed from create.
+        (WebCore::GPUCommandBuffer::create): Deleted.
+
 2019-03-13  Zalan Bujtas  <za...@apple.com>
 
         [WeakPtr] RenderListMarker::m_listItem should be a WeakPtr

Modified: trunk/Source/WebCore/DerivedSources.make (242930 => 242931)


--- trunk/Source/WebCore/DerivedSources.make	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/DerivedSources.make	2019-03-14 01:42:12 UTC (rev 242931)
@@ -404,6 +404,7 @@
     $(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 \

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -28,112 +28,18 @@
 
 #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
+Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(RefPtr<GPUCommandBuffer>&& buffer)
 {
-    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(Ref<GPUCommandBuffer>&& buffer)
+WebGPUCommandBuffer::WebGPUCommandBuffer(RefPtr<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)

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -28,46 +28,21 @@
 #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(Ref<GPUCommandBuffer>&&);
+    static Ref<WebGPUCommandBuffer> create(RefPtr<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(Ref<GPUCommandBuffer>&&);
+    WebGPUCommandBuffer(RefPtr<GPUCommandBuffer>&&);
 
-    Ref<GPUCommandBuffer> m_commandBuffer;
+    RefPtr<GPUCommandBuffer> m_commandBuffer;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl	2019-03-14 01:42:12 UTC (rev 242931)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -24,60 +24,10 @@
  */
 // 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
+    ImplementationLacksVTable,
+    InterfaceName=GPUCommandBuffer
 ] 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();
 };

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp (from rev 242930, trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp) (0 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -0,0 +1,168 @@
+/*
+ * 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)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.h (from rev 242930, trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h) (0 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.h	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -0,0 +1,75 @@
+/*
+ * 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)

Copied: trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.idl (from rev 242930, trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl) (0 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.idl	                        (rev 0)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.idl	2019-03-14 01:42:12 UTC (rev 242931)
@@ -0,0 +1,86 @@
+/*
+ * 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();
+};

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -47,7 +47,7 @@
 #include "WebGPUBindGroupLayout.h"
 #include "WebGPUBuffer.h"
 #include "WebGPUBufferBinding.h"
-#include "WebGPUCommandBuffer.h"
+#include "WebGPUCommandEncoder.h"
 #include "WebGPUPipelineLayout.h"
 #include "WebGPUPipelineLayoutDescriptor.h"
 #include "WebGPUPipelineStageDescriptor.h"
@@ -137,11 +137,10 @@
     return WebGPURenderPipeline::create(WTFMove(pipeline));
 }
 
-RefPtr<WebGPUCommandBuffer> WebGPUDevice::createCommandBuffer() const
+Ref<WebGPUCommandEncoder> WebGPUDevice::createCommandEncoder() const
 {
-    if (auto commandBuffer = m_device->createCommandBuffer())
-        return WebGPUCommandBuffer::create(commandBuffer.releaseNonNull());
-    return nullptr;
+    auto commandBuffer = m_device->tryCreateCommandBuffer();
+    return WebGPUCommandEncoder::create(WTFMove(commandBuffer));
 }
 
 Ref<WebGPUSwapChain> WebGPUDevice::createSwapChain(const WebGPUSwapChainDescriptor& descriptor) const

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -41,7 +41,7 @@
 class WebGPUBindGroup;
 class WebGPUBindGroupLayout;
 class WebGPUBuffer;
-class WebGPUCommandBuffer;
+class WebGPUCommandEncoder;
 class WebGPUPipelineLayout;
 class WebGPURenderPipeline;
 class WebGPUSampler;
@@ -76,7 +76,7 @@
     RefPtr<WebGPUShaderModule> createShaderModule(WebGPUShaderModuleDescriptor&&) const;
     Ref<WebGPURenderPipeline> createRenderPipeline(const WebGPURenderPipelineDescriptor&) const;
 
-    RefPtr<WebGPUCommandBuffer> createCommandBuffer() const;
+    Ref<WebGPUCommandEncoder> createCommandEncoder() const;
 
     Ref<WebGPUSwapChain> createSwapChain(const WebGPUSwapChainDescriptor&) const;
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl	2019-03-14 01:42:12 UTC (rev 242931)
@@ -54,8 +54,8 @@
     WebGPUShaderModule createShaderModule(WebGPUShaderModuleDescriptor descriptor);
     WebGPURenderPipeline createRenderPipeline(WebGPURenderPipelineDescriptor descriptor);
 
-    // FIXME: Currently, WebGPUCommandBufferDescriptor is an empty dictionary.
-    WebGPUCommandBuffer createCommandBuffer(/*WebGPUCommandBufferDescriptor descriptor*/);
+    // FIXME: Currently, GPUCommandEncoderDescriptor is an empty dictionary.
+    WebGPUCommandEncoder createCommandEncoder(/*GPUCommandEncoderDescriptor descriptor*/);
 
     WebGPUSwapChain createSwapChain(WebGPUSwapChainDescriptor descriptor);
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -35,39 +35,50 @@
 
 namespace WebCore {
 
-WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder(Ref<WebGPUCommandBuffer>&& creator)
+WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder(Ref<WebGPUCommandEncoder>&& creator)
     : m_commandBuffer(WTFMove(creator))
 {
 }
 
-Ref<WebGPUCommandBuffer> WebGPUProgrammablePassEncoder::endPass()
+void WebGPUProgrammablePassEncoder::endPass()
 {
-    passEncoder().endPass();
-    return m_commandBuffer.copyRef();
+    if (!passEncoder()) {
+        LOG(WebGPU, "GPUProgrammablePassEncoder::endPass(): Invalid operation!");
+        return;
+    }
+    passEncoder()->endPass();
 }
 
 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, "WebGPUProgrammablePassEncoder::setBindGroup(): Invalid index!");
+        LOG(WebGPU, "GPUProgrammablePassEncoder::setBindGroup(): Invalid index!");
         return;
     }
     if (!bindGroup.bindGroup()) {
-        LOG(WebGPU, "WebGPUProgrammablePassEncoder::setBindGroup(): Invalid WebGPUBindGroup!");
+        LOG(WebGPU, "GPUProgrammablePassEncoder::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

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -27,7 +27,7 @@
 
 #if ENABLE(WEBGPU)
 
-#include "WebGPUCommandBuffer.h"
+#include "WebGPUCommandEncoder.h"
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
@@ -40,17 +40,17 @@
 public:
     virtual ~WebGPUProgrammablePassEncoder() = default;
 
-    Ref<WebGPUCommandBuffer> endPass();
+    void endPass();
     void setBindGroup(unsigned, WebGPUBindGroup&) const;
     void setPipeline(const WebGPURenderPipeline&);
 
 protected:
-    WebGPUProgrammablePassEncoder(Ref<WebGPUCommandBuffer>&&);
+    WebGPUProgrammablePassEncoder(Ref<WebGPUCommandEncoder>&&);
 
-    virtual GPUProgrammablePassEncoder& passEncoder() const = 0;
+    virtual GPUProgrammablePassEncoder* passEncoder() const = 0;
 
 private:
-    Ref<WebGPUCommandBuffer> m_commandBuffer;
+    Ref<WebGPUCommandEncoder> m_commandBuffer;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl	2019-03-14 01:42:12 UTC (rev 242931)
@@ -31,7 +31,7 @@
     EnabledAtRuntime=WebGPU,
     SkipVTableValidation
 ] interface WebGPUProgrammablePassEncoder {
-    WebGPUCommandBuffer endPass();
+    void endPass();
     void setBindGroup(u32 index, WebGPUBindGroup bindGroup/*, optional sequence<u32> dynamicOffsets*/);
     void setPipeline(WebGPURenderPipeline pipeline); // FIXME: Support WebGPUComputePipelines.
 };

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -30,6 +30,7 @@
 
 #include "GPUCommandBuffer.h"
 #include "GPUQueue.h"
+#include "Logging.h"
 #include "WebGPUCommandBuffer.h"
 
 namespace WebCore {
@@ -44,11 +45,19 @@
 {
 }
 
-void WebGPUQueue::submit(Vector<RefPtr<WebGPUCommandBuffer>>&& buffers)
+void WebGPUQueue::submit(const Vector<RefPtr<WebGPUCommandBuffer>>& buffers)
 {
-    auto gpuBuffers = buffers.map([] (auto& buffer) -> Ref<GPUCommandBuffer> {
-        return buffer->commandBuffer();
-    });
+    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()));
+    }
+
     m_queue->submit(WTFMove(gpuBuffers));
 }
 

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.h (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -41,7 +41,7 @@
 public:
     static RefPtr<WebGPUQueue> create(RefPtr<GPUQueue>&&);
 
-    void submit(Vector<RefPtr<WebGPUCommandBuffer>>&&);
+    void submit(const Vector<RefPtr<WebGPUCommandBuffer>>&);
 
     String label() const { return m_queue->label(); }
     void setLabel(const String& label) { m_queue->setLabel(label); }

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.idl (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.idl	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.idl	2019-03-14 01:42:12 UTC (rev 242931)
@@ -34,4 +34,4 @@
     // FIXME: Unimplemented.
     // void signal(WebGPUFence fence, u64 signalValue);
     // void wait(WebGPUFence fence, u64 valueToWait);
-};
\ No newline at end of file
+};

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -36,12 +36,12 @@
 
 namespace WebCore {
 
-Ref<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandBuffer>&& commandBuffer, Ref<GPURenderPassEncoder>&& encoder)
+Ref<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandEncoder>&& commandBuffer, RefPtr<GPURenderPassEncoder>&& encoder)
 {
     return adoptRef(*new WebGPURenderPassEncoder(WTFMove(commandBuffer), WTFMove(encoder)));
 }
 
-WebGPURenderPassEncoder::WebGPURenderPassEncoder(Ref<WebGPUCommandBuffer>&& creator, Ref<GPURenderPassEncoder>&& encoder)
+WebGPURenderPassEncoder::WebGPURenderPassEncoder(Ref<WebGPUCommandEncoder>&& creator, RefPtr<GPURenderPassEncoder>&& encoder)
     : WebGPUProgrammablePassEncoder(WTFMove(creator))
     , m_passEncoder(WTFMove(encoder))
 {
@@ -52,11 +52,14 @@
 #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;
@@ -84,11 +87,15 @@
 
 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();
 }

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -40,17 +40,17 @@
 
 class WebGPURenderPassEncoder final : public WebGPUProgrammablePassEncoder {
 public:
-    static Ref<WebGPURenderPassEncoder> create(Ref<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
+    static Ref<WebGPURenderPassEncoder> create(Ref<WebGPUCommandEncoder>&&, RefPtr<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<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
+    WebGPURenderPassEncoder(Ref<WebGPUCommandEncoder>&&, RefPtr<GPURenderPassEncoder>&&);
 
-    GPUProgrammablePassEncoder& passEncoder() const final;
+    GPUProgrammablePassEncoder* passEncoder() const final;
 
-    Ref<GPURenderPassEncoder> m_passEncoder;
+    RefPtr<GPURenderPassEncoder> m_passEncoder;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp (242930 => 242931)


--- trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -50,7 +50,7 @@
         return WebGPUTexture::create(nullptr);
     }
     m_currentTexture = WebGPUTexture::create(m_swapChain->tryGetCurrentTexture());
-    return m_currentTexture.releaseNonNull();
+    return makeRef(*m_currentTexture);
 }
 
 void WebGPUSwapChain::destroy()

Modified: trunk/Source/WebCore/Sources.txt (242930 => 242931)


--- trunk/Source/WebCore/Sources.txt	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/Sources.txt	2019-03-14 01:42:12 UTC (rev 242931)
@@ -352,10 +352,11 @@
 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
@@ -3337,6 +3338,7 @@
 JSWebGPUBuffer.cpp
 JSWebGPUBufferBinding.cpp
 JSWebGPUCommandBuffer.cpp
+JSWebGPUCommandEncoder.cpp
 JSWebGPUDevice.cpp
 JSWebGPUQueue.cpp
 JSWebGPUPipelineDescriptorBase.cpp

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (242930 => 242931)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2019-03-14 01:42:12 UTC (rev 242931)
@@ -14080,6 +14080,9 @@
 		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>"; };
@@ -14189,9 +14192,9 @@
 		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 /* 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>"; };
+		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>"; };
 		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>"; };
@@ -26166,9 +26169,12 @@
 				D0D8648E21B70676003C983C /* WebGPUBuffer.idl */,
 				D0BE104C21E68F1500E42A89 /* WebGPUBufferBinding.h */,
 				D0BE104D21E68F1500E42A89 /* WebGPUBufferBinding.idl */,
-				D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */,
-				D0EACF7621937228000FA75C /* WebGPUCommandBuffer.h */,
-				D0EACF7821937228000FA75C /* WebGPUCommandBuffer.idl */,
+				D05DD6DD223884060097A834 /* WebGPUCommandBuffer.cpp */,
+				D05DD6DE223884070097A834 /* WebGPUCommandBuffer.h */,
+				D05DD6DF223884070097A834 /* WebGPUCommandBuffer.idl */,
+				D0EACF7721937228000FA75C /* WebGPUCommandEncoder.cpp */,
+				D0EACF7621937228000FA75C /* WebGPUCommandEncoder.h */,
+				D0EACF7821937228000FA75C /* WebGPUCommandEncoder.idl */,
 				D00F595321701D8C000D71DB /* WebGPUDevice.cpp */,
 				D00F595221701D8C000D71DB /* WebGPUDevice.h */,
 				D00F595421701D8C000D71DB /* WebGPUDevice.idl */,

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (242930 => 242931)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -84,6 +84,8 @@
     macro(GPUBufferUsage) \
     macro(GPUCanvasContext) \
     macro(GPUShaderModule) \
+    macro(GPUCommandBuffer) \
+    macro(GPUCommandEncoder) \
     macro(GPUShaderStageBit) \
     macro(GPUSwapChain) \
     macro(GPUTextureUsage) \
@@ -201,7 +203,6 @@
     macro(WebGPUBindGroup) \
     macro(WebGPUBindGroupLayout) \
     macro(WebGPUBuffer) \
-    macro(WebGPUCommandBuffer) \
     macro(WebGPUDevice) \
     macro(WebGPUIndexFormat) \
     macro(WebGPUInputStepMode) \

Modified: trunk/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h (242930 => 242931)


--- trunk/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -27,7 +27,9 @@
 
 #if ENABLE(WEBGPU)
 
+#include "GPUBuffer.h"
 #include "GPUOrigin3D.h"
+#include "GPUTexture.h"
 #include <wtf/RefCounted.h>
 #include <wtf/RefPtr.h>
 #include <wtf/RetainPtr.h>
@@ -38,9 +40,7 @@
 
 namespace WebCore {
 
-class GPUBuffer;
 class GPUDevice;
-class GPUTexture;
 
 struct GPUExtent3D;
 
@@ -81,7 +81,7 @@
 
 class GPUCommandBuffer : public RefCounted<GPUCommandBuffer> {
 public:
-    static RefPtr<GPUCommandBuffer> create(GPUDevice&);
+    static RefPtr<GPUCommandBuffer> tryCreate(const GPUDevice&);
 
     PlatformCommandBuffer* platformCommandBuffer() const { return m_platformCommandBuffer.get(); }
     const Vector<Ref<GPUBuffer>>& usedBuffers() const { return m_usedBuffers; }

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


--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp	2019-03-14 01:42:12 UTC (rev 242931)
@@ -83,9 +83,9 @@
     return GPURenderPipeline::create(*this, WTFMove(descriptor));
 }
 
-RefPtr<GPUCommandBuffer> GPUDevice::createCommandBuffer()
+RefPtr<GPUCommandBuffer> GPUDevice::tryCreateCommandBuffer() const
 {
-    return GPUCommandBuffer::create(*this);
+    return GPUCommandBuffer::tryCreate(*this);
 }
 
 RefPtr<GPUSwapChain> GPUDevice::tryCreateSwapChain(const GPUSwapChainDescriptor& descriptor, int width, int height) const

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


--- trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h	2019-03-14 01:42:12 UTC (rev 242931)
@@ -37,9 +37,6 @@
 
 namespace WebCore {
 
-using PlatformDevice = MTLDevice;
-using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>;
-
 class GPUBindGroupLayout;
 class GPUBuffer;
 class GPUCommandBuffer;
@@ -58,6 +55,9 @@
 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 @@
     RefPtr<GPUShaderModule> createShaderModule(GPUShaderModuleDescriptor&&) const;
     RefPtr<GPURenderPipeline> createRenderPipeline(GPURenderPipelineDescriptor&&) const;
 
-    RefPtr<GPUCommandBuffer> createCommandBuffer();
+    RefPtr<GPUCommandBuffer> tryCreateCommandBuffer() const;
 
     RefPtr<GPUSwapChain> tryCreateSwapChain(const GPUSwapChainDescriptor&, int width, int height) const;
 

Modified: trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm (242930 => 242931)


--- trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm	2019-03-14 01:40:05 UTC (rev 242930)
+++ trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm	2019-03-14 01:42:12 UTC (rev 242931)
@@ -28,11 +28,9 @@
 
 #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>
@@ -41,7 +39,7 @@
 
 namespace WebCore {
 
-RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUDevice& device)
+RefPtr<GPUCommandBuffer> GPUCommandBuffer::tryCreate(const GPUDevice& device)
 {
     if (!device.platformDevice()) {
         LOG(WebGPU, "GPUCommandBuffer::create(): Invalid GPUDevice!");
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to