Skip to content
Permalink
Browse files
[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:


Canonical link: https://commits.webkit.org/210021@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242931 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Justin Fan committed Mar 14, 2019
1 parent 1c896c8 commit 429d4547d79953c3652832914e747d4855d57cc5
Showing 40 changed files with 581 additions and 279 deletions.
@@ -1,3 +1,26 @@
2019-03-13 Justin Fan <justin_fan@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 <aboya@igalia.com>

[GTK] Unreviewed test gardening
@@ -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();
@@ -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() {
@@ -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();
@@ -1,3 +1,3 @@

PASS Create a default GPUCommandBuffer.
PASS Create a default GPUCommandEncoder.

@@ -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>
@@ -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();
@@ -66,7 +66,7 @@ function createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDes
return device.createRenderPipeline(pipelineDescriptor);
}

function beginBasicRenderPass(swapChain, commandBuffer) {
function beginBasicRenderPass(swapChain, commandEncoder) {
const basicAttachment = {
attachment: swapChain.getCurrentTexture().createDefaultTextureView(),
loadOp: "clear",
@@ -75,13 +75,13 @@ function beginBasicRenderPass(swapChain, commandBuffer) {
}

// FIXME: Flesh out the rest of WebGPURenderPassDescriptor.
return commandBuffer.beginRenderPass({ colorAttachments : [basicAttachment] });
return commandEncoder.beginRenderPass({ colorAttachments : [basicAttachment] });
}

function encodeBasicCommands(renderPassEncoder, renderPipeline, vertexBuffer) {
if (vertexBuffer)
renderPassEncoder.setVertexBuffers(0, [vertexBuffer], [0]);
renderPassEncoder.setPipeline(renderPipeline);
renderPassEncoder.draw(4, 1, 0, 0);
return renderPassEncoder.endPass();
renderPassEncoder.endPass();
}
@@ -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>
@@ -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)
@@ -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,16 +200,16 @@
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]);
passEncoder.draw(4, 1, 0, 0);
passEncoder.endPass();

const queue = device.getQueue();
queue.submit([commandBuffer]);
queue.submit([commandEncoder.finish()]);
positionBuffer.destroy();
textureCoordBuffer.destroy();
texture.destroy();
@@ -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)
@@ -494,6 +494,7 @@ 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
@@ -1,3 +1,87 @@
2019-03-13 Justin Fan <justin_fan@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 <zalan@apple.com>

[WeakPtr] RenderListMarker::m_listItem should be a WeakPtr
@@ -404,6 +404,7 @@ 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 \

0 comments on commit 429d454

Please sign in to comment.