Changeset 242974 in webkit


Ignore:
Timestamp:
Mar 14, 2019 4:04:18 PM (5 years ago)
Author:
Justin Fan
Message:

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

Reviewed by Dean Jackson.

Fixing build error and re-introducing rolled-out changes.
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:
Location:
trunk
Files:
36 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r242971 r242974  
     12019-03-14  Justin Fan  <justin_fan@apple.com>
     2
     3        [Web GPU] Updates to GPUCommandBuffer for new GPUCommandEncoder concept
     4        https://bugs.webkit.org/show_bug.cgi?id=195083
     5        <rdar://problem/48423591>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Fixing build error and re-introducing rolled-out changes.
     10        Update existing Web GPU tests for GPUCommandEncoder and new GPUCommandBuffer.
     11
     12        * webgpu/blit-commands.html:
     13        * webgpu/buffer-command-buffer-races.html:
     14        * webgpu/buffer-resource-triangles.html:
     15        * webgpu/command-buffers-expected.txt:
     16        * webgpu/command-buffers.html:
     17        * webgpu/depth-enabled-triangle-strip.html:
     18        * webgpu/js/webgpu-functions.js:
     19        (beginBasicRenderPass):
     20        * webgpu/render-command-encoding.html:
     21        * webgpu/simple-triangle-strip.html:
     22        * webgpu/texture-triangle-strip.html:
     23        * webgpu/vertex-buffer-triangle-strip.html:
     24
    1252019-03-14  Ryan Haddad  <ryanhaddad@apple.com>
    226
  • trunk/LayoutTests/webgpu/blit-commands.html

    r242956 r242974  
    8686    };
    8787
    88     const commandBuffer = device.createCommandBuffer();
    89     commandBuffer.copyBufferToBuffer(bufferA, 0, bufferB, 0, imageData.data.byteLength);
    90     commandBuffer.copyBufferToTexture(bufferViewB, textureViewA, textureSize);
    91     commandBuffer.copyTextureToTexture(textureViewA, textureViewB, textureSize);
    92     commandBuffer.copyTextureToBuffer(textureViewB, readBufferView, textureSize);
    93     device.getQueue().submit([commandBuffer]);
     88    const commandEncoder = device.createCommandEncoder();
     89    commandEncoder.copyBufferToBuffer(bufferA, 0, bufferB, 0, imageData.data.byteLength);
     90    commandEncoder.copyBufferToTexture(bufferViewB, textureViewA, textureSize);
     91    commandEncoder.copyBufferToTexture(bufferViewB, textureViewA, textureSize);
     92    commandEncoder.copyTextureToTexture(textureViewA, textureViewB, textureSize);
     93    commandEncoder.copyTextureToBuffer(textureViewB, readBufferView, textureSize);
     94    device.getQueue().submit([commandEncoder.finish()]);
    9495    bufferA.destroy();
    9596    bufferB.destroy();
  • trunk/LayoutTests/webgpu/buffer-command-buffer-races.html

    r242956 r242974  
    7777
    7878function drawAndSubmitCommands(device, pipeline, attachment, vertexBuffer, colorBuffer) {
    79     const commandBuffer = device.createCommandBuffer();
    80     const encoder = commandBuffer.beginRenderPass({ colorAttachments: [attachment] });
     79    const commandEncoder = device.createCommandEncoder();
     80    const encoder = commandEncoder.beginRenderPass({ colorAttachments: [attachment] });
    8181    encoder.setVertexBuffers(0, [vertexBuffer, colorBuffer], [0, 0]);
    8282    encoder.setPipeline(pipeline);
    8383    encoder.draw(3, 1, 0, 0);
    8484    encoder.endPass();
    85     device.getQueue().submit([commandBuffer]);
     85    device.getQueue().submit([commandEncoder.finish()]);
    8686}
    8787
  • trunk/LayoutTests/webgpu/buffer-resource-triangles.html

    r242956 r242974  
    195195
    196196    Promise.all(bufferPromises).then(() => {
    197         const commandBuffer = device.createCommandBuffer();
    198         const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
     197        const commandEncoder = device.createCommandEncoder();
     198        const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
    199199        passEncoder.setPipeline(pipeline);
    200200
     
    206206        passEncoder.draw(9, 1, 0, 0);
    207207
    208         const endCommandBuffer = passEncoder.endPass();
     208        passEncoder.endPass();
    209209        const queue = device.getQueue();
    210         queue.submit([endCommandBuffer]);
     210        queue.submit([commandEncoder.finish()]);
    211211
    212212        if (window.testRunner)
  • trunk/LayoutTests/webgpu/command-buffers-expected.txt

    r242956 r242974  
    11
    2 PASS Create a default GPUCommandBuffer.
     2PASS Create a default GPUCommandEncoder.
    33
  • trunk/LayoutTests/webgpu/command-buffers.html

    r242956 r242974  
    77promise_test(async () => {
    88    const device = await getBasicDevice();
    9     const commandBuffer = device.createCommandBuffer();
    10     assert_true(commandBuffer instanceof WebGPUCommandBuffer, "Successfully created GPUCommandBuffer.");
    11 }, "Create a default GPUCommandBuffer.");
     9    const commandEncoder = device.createCommandEncoder();
     10    assert_true(commandEncoder instanceof GPUCommandEncoder, "Successfully created GPUCommandEncoder.");
     11}, "Create a default GPUCommandEncoder.");
    1212
    13 // FIXME: createCommandBuffer should take a GPUCommandBufferDescriptor, which is currently an empty dictionary.
     13// FIXME: createCommandEncoder should take a GPUCommandEncoderDescriptor, which is currently an empty dictionary.
    1414</script>
    1515</html>
  • trunk/LayoutTests/webgpu/depth-enabled-triangle-strip.html

    r242956 r242974  
    9090    const depthStateDescriptor = createBasicDepthStateDescriptor();
    9191    const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor, depthStateDescriptor);
    92     const commandBuffer = device.createCommandBuffer();
     92    const commandEncoder = device.createCommandEncoder();
    9393
    9494    const basicAttachment = {
     
    106106    };
    107107
    108     const encoder = commandBuffer.beginRenderPass({
     108    const encoder = commandEncoder.beginRenderPass({
    109109        colorAttachments: [basicAttachment],
    110110        depthStencilAttachment: depthAttachment
     
    116116    encoder.endPass();
    117117
    118     device.getQueue().submit([commandBuffer]);
     118    device.getQueue().submit([commandEncoder.finish()]);
    119119
    120120    if (window.testRunner)
  • trunk/LayoutTests/webgpu/js/webgpu-functions.js

    r242956 r242974  
    6767}
    6868
    69 function beginBasicRenderPass(swapChain, commandBuffer) {
     69function beginBasicRenderPass(swapChain, commandEncoder) {
    7070    const basicAttachment = {
    7171        attachment: swapChain.getCurrentTexture().createDefaultTextureView(),
     
    7676
    7777    // FIXME: Flesh out the rest of WebGPURenderPassDescriptor.
    78     return commandBuffer.beginRenderPass({ colorAttachments : [basicAttachment] });
     78    return commandEncoder.beginRenderPass({ colorAttachments : [basicAttachment] });
    7979}
    8080
     
    8484    renderPassEncoder.setPipeline(renderPipeline);
    8585    renderPassEncoder.draw(4, 1, 0, 0);
    86     return renderPassEncoder.endPass();
     86    renderPassEncoder.endPass();
    8787}
  • trunk/LayoutTests/webgpu/render-command-encoding.html

    r242956 r242974  
    3535    const pipeline = createBasicPipeline(shaderModule, device);
    3636
    37     const commandBuffer = device.createCommandBuffer();
    38     assert_true(commandBuffer instanceof WebGPUCommandBuffer, "createCommandBuffer returned a WebGPUCommandBuffer");
     37    const commandEncoder = device.createCommandEncoder();
     38    assert_true(commandEncoder instanceof GPUCommandEncoder, "createCommandEncoder returned a GPUCommandEncoder");
    3939
    40     const encoder = beginBasicRenderPass(swapChain, commandBuffer);
     40    const encoder = beginBasicRenderPass(swapChain, commandEncoder);
    4141    assert_true(encoder instanceof WebGPURenderPassEncoder, "beginRenderPass() returned a WebGPURenderPassEncoder");
    4242
    4343    encoder.setPipeline(pipeline);
    44     const commandBufferEnd = encoder.endPass();
    45     assert_true(commandBufferEnd instanceof WebGPUCommandBuffer, "endPass() returned a WebGPUCommandBuffer");
     44    encoder.endPass();
    4645}, "WebGPURenderPassEncoder created and successfully ended");
    4746
  • trunk/LayoutTests/webgpu/simple-triangle-strip.html

    r242956 r242974  
    5353    const shaderModule = device.createShaderModule({ code: shaderCode });
    5454    const pipeline = createBasicPipeline(shaderModule, device);
    55     const commandBuffer = device.createCommandBuffer();
    56     const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
    57     const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline);
     55    const commandEncoder = device.createCommandEncoder();
     56    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
     57    encodeBasicCommands(passEncoder, pipeline);
    5858    const queue = device.getQueue();
    5959
    60     queue.submit([endCommandBuffer]);
     60    queue.submit([commandEncoder.finish()]);
    6161
    6262    requestAnimationFrame(() => {
  • trunk/LayoutTests/webgpu/texture-triangle-strip.html

    r242956 r242974  
    187187    // Pipeline and render
    188188    const pipeline = createBasicPipeline(shaderModule, device, pipelineLayout, inputStateDescriptor);
    189     const commandBuffer = device.createCommandBuffer();
     189    const commandEncoder = device.createCommandEncoder();
    190190
    191191    const bufferCopyView = {
     
    201201        origin: { x: 0, y: 0, z: 0 }
    202202    };
    203     commandBuffer.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
    204     const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
     203    commandEncoder.copyBufferToTexture(bufferCopyView, textureCopyView, textureSize);
     204    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
    205205    passEncoder.setPipeline(pipeline);
    206206    passEncoder.setBindGroup(bindGroupIndex, bindGroup);
     
    210210
    211211    const queue = device.getQueue();
    212     queue.submit([commandBuffer]);
     212    queue.submit([commandEncoder.finish()]);
    213213    positionBuffer.destroy();
    214214    textureCoordBuffer.destroy();
  • trunk/LayoutTests/webgpu/vertex-buffer-triangle-strip.html

    r242956 r242974  
    9292    const inputStateDescriptor = createInputStateDescriptor();
    9393    const pipeline = createBasicPipeline(shaderModule, device, null, inputStateDescriptor);
    94     const commandBuffer = device.createCommandBuffer();
    95     const passEncoder = beginBasicRenderPass(swapChain, commandBuffer);
    96     const endCommandBuffer = encodeBasicCommands(passEncoder, pipeline, vertexBuffer);
     94    const commandEncoder = device.createCommandEncoder();
     95    const passEncoder = beginBasicRenderPass(swapChain, commandEncoder);
     96    encodeBasicCommands(passEncoder, pipeline, vertexBuffer);
    9797    const queue = device.getQueue();
    98     queue.submit([endCommandBuffer]);
     98    queue.submit([commandEncoder.finish()]);
    9999    vertexBuffer.destroy();
    100100
  • trunk/Source/WebCore/CMakeLists.txt

    r242972 r242974  
    494494    Modules/webgpu/WebGPUBufferBinding.idl
    495495    Modules/webgpu/WebGPUCommandBuffer.idl
     496    Modules/webgpu/WebGPUCommandEncoder.idl
    496497    Modules/webgpu/WebGPUDevice.idl
    497498    Modules/webgpu/WebGPUPipelineDescriptorBase.idl
  • trunk/Source/WebCore/ChangeLog

    r242972 r242974  
     12019-03-14  Justin Fan  <justin_fan@apple.com>
     2
     3        [Web GPU] Updates to GPUCommandBuffer for new GPUCommandEncoder concept
     4        https://bugs.webkit.org/show_bug.cgi?id=195083
     5        <rdar://problem/48423591>
     6
     7        Reviewed by Dean Jackson.
     8
     9        Fixing build error and re-introducing rolled-out changes.
     10        WebGPUCommandBuffer now represents a completed GPUCommandBuffer that can only be used in queue submits. The previous WebGPUCommandBuffer
     11        is now WebGPUCommandEncoder.
     12
     13        Affected Web GPU tests updated to match new API.
     14
     15        New files and symbols:
     16        * CMakeLists.txt:
     17        * DerivedSources.make:
     18        * Sources.txt:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * bindings/js/WebCoreBuiltinNames.h:
     21
     22        Implement new WebGPUCommandBuffer, now just a DOM object carrier for a finished GPUCommandBuffer:
     23        * Modules/webgpu/WebGPUCommandBuffer.cpp:
     24        (WebCore::WebGPUCommandBuffer::create):
     25        (WebCore::WebGPUCommandBuffer::WebGPUCommandBuffer):
     26        (WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const): Deleted.
     27        (WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const): Deleted.
     28        (WebCore::WebGPUCommandBuffer::beginRenderPass): Deleted.
     29        (WebCore::WebGPUCommandBuffer::copyBufferToBuffer): Deleted.
     30        (WebCore::WebGPUCommandBuffer::copyBufferToTexture): Deleted.
     31        (WebCore::WebGPUCommandBuffer::copyTextureToBuffer): Deleted.
     32        (WebCore::WebGPUCommandBuffer::copyTextureToTexture): Deleted.
     33        * Modules/webgpu/WebGPUCommandBuffer.h:
     34        (WebCore::WebGPUCommandBuffer::commandBuffer):
     35        (WebCore::WebGPUCommandBuffer::commandBuffer const): Deleted.
     36        * Modules/webgpu/WebGPUCommandBuffer.idl:
     37
     38        Rename old WebGPUCommandBuffer to WebGPUCommandEncoder:
     39        * Modules/webgpu/WebGPUCommandEncoder.cpp: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp.
     40        (WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const):
     41        (WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const):
     42        (WebCore::WebGPUCommandEncoder::create):
     43        (WebCore::WebGPUCommandEncoder::WebGPUCommandEncoder):
     44        (WebCore::WebGPUCommandEncoder::beginRenderPass):
     45        (WebCore::WebGPUCommandEncoder::copyBufferToBuffer):
     46        (WebCore::WebGPUCommandEncoder::copyBufferToTexture):
     47        (WebCore::WebGPUCommandEncoder::copyTextureToBuffer):
     48        (WebCore::WebGPUCommandEncoder::copyTextureToTexture):
     49        (WebCore::WebGPUCommandEncoder::finish): Added. "Completes" this and invalidates it. Returns its GPUCommandBuffer, ready for submission.
     50        * Modules/webgpu/WebGPUCommandEncoder.h: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h.
     51        * Modules/webgpu/WebGPUCommandEncoder.idl: Copied from Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl.
     52        * Modules/webgpu/WebGPUDevice.cpp:
     53        (WebCore::WebGPUDevice::createCommandEncoder const): Renamed fom createCommandBuffer. Now returns non-nullable.
     54        (WebCore::WebGPUDevice::createCommandBuffer const): Deleted.
     55        * Modules/webgpu/WebGPUDevice.h:
     56        * Modules/webgpu/WebGPUDevice.idl:
     57        * Modules/webgpu/WebGPUProgrammablePassEncoder.cpp:
     58        (WebCore::WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder):
     59        (WebCore::WebGPUProgrammablePassEncoder::endPass): No longer returns the original WebGPUCommandBuffer.
     60        (WebCore::WebGPUProgrammablePassEncoder::setBindGroup const):
     61        (WebCore::WebGPUProgrammablePassEncoder::setPipeline):
     62        * Modules/webgpu/WebGPUProgrammablePassEncoder.h:
     63        * Modules/webgpu/WebGPUProgrammablePassEncoder.idl:
     64        * Modules/webgpu/WebGPUQueue.cpp:
     65        (WebCore::WebGPUQueue::submit): Replace unnecessary rvalue reference parameter.
     66        * Modules/webgpu/WebGPUQueue.h:
     67        * Modules/webgpu/WebGPUQueue.idl:
     68        * Modules/webgpu/WebGPURenderPassEncoder.cpp:
     69        (WebCore::WebGPURenderPassEncoder::create):
     70        (WebCore::WebGPURenderPassEncoder::WebGPURenderPassEncoder):
     71        (WebCore::WebGPURenderPassEncoder::setVertexBuffers):
     72        (WebCore::WebGPURenderPassEncoder::draw):
     73        (WebCore::WebGPURenderPassEncoder::passEncoder const): Now returns a pointer since it is properly backed by a RefPtr.
     74        * Modules/webgpu/WebGPURenderPassEncoder.h:
     75        * Modules/webgpu/WebGPUSwapChain.cpp:
     76        (WebCore::WebGPUSwapChain::getCurrentTexture): No longer invalidates m_currentTexture. Doh!
     77        * platform/graphics/gpu/GPUCommandBuffer.h: Missing includes for the *CopyView structs.
     78        * platform/graphics/gpu/GPUDevice.cpp:
     79        (WebCore::GPUDevice::tryCreateCommandBuffer const): Renamed from createCommandBuffer.
     80        (WebCore::GPUDevice::createCommandBuffer): Deleted.
     81        * platform/graphics/gpu/GPUDevice.h:
     82        * platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
     83        (WebCore::GPUCommandBuffer::tryCreate): Renamed from create.
     84        (WebCore::GPUCommandBuffer::create): Deleted.
     85
    1862019-03-14  Justin Fan  <justin_fan@apple.com>
    287
  • trunk/Source/WebCore/DerivedSources.make

    r242972 r242974  
    404404        $(WebCore)/Modules/webgpu/WebGPUBufferBinding.idl \
    405405    $(WebCore)/Modules/webgpu/WebGPUCommandBuffer.idl \
     406    $(WebCore)/Modules/webgpu/WebGPUCommandEncoder.idl \
    406407    $(WebCore)/Modules/webgpu/WebGPUDevice.idl \
    407408    $(WebCore)/Modules/webgpu/WebGPUQueue.idl \
  • trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.cpp

    r242956 r242974  
    2929#if ENABLE(WEBGPU)
    3030
    31 #include "GPURenderPassDescriptor.h"
    32 #include "GPURenderPassEncoder.h"
    33 #include "WebGPUBuffer.h"
    34 #include "WebGPURenderPassDescriptor.h"
    35 #include "WebGPURenderPassEncoder.h"
    36 #include "WebGPUTexture.h"
    37 #include <wtf/Optional.h>
    38 
    3931namespace WebCore {
    4032
    41 Optional<GPUBufferCopyView> WebGPUBufferCopyView::tryCreateGPUBufferCopyView() const
    42 {
    43     if (!buffer || !buffer->buffer()) {
    44         LOG(WebGPU, "GPUCommandEncoder: Invalid buffer for copy!");
    45         return WTF::nullopt;
    46     }
    47 
    48     // FIXME: Add Web GPU validation.
    49 
    50     return GPUBufferCopyView { buffer->buffer().releaseNonNull(), *this };
    51 }
    52 
    53 Optional<GPUTextureCopyView> WebGPUTextureCopyView::tryCreateGPUTextureCopyView() const
    54 {
    55     if (!texture || !texture->texture()) {
    56         LOG(WebGPU, "GPUCommandEncoder: Invalid texture for copy!");
    57         return WTF::nullopt;
    58     }
    59 
    60     // FIXME: Add Web GPU validation.
    61 
    62     return GPUTextureCopyView { texture->texture().releaseNonNull(), *this };
    63 }
    64 
    65 Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(Ref<GPUCommandBuffer>&& buffer)
     33Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(RefPtr<GPUCommandBuffer>&& buffer)
    6634{
    6735    return adoptRef(*new WebGPUCommandBuffer(WTFMove(buffer)));
    6836}
    6937
    70 WebGPUCommandBuffer::WebGPUCommandBuffer(Ref<GPUCommandBuffer>&& buffer)
     38WebGPUCommandBuffer::WebGPUCommandBuffer(RefPtr<GPUCommandBuffer>&& buffer)
    7139    : m_commandBuffer(WTFMove(buffer))
    7240{
    73 }
    74 
    75 RefPtr<WebGPURenderPassEncoder> WebGPUCommandBuffer::beginRenderPass(WebGPURenderPassDescriptor&& descriptor)
    76 {
    77     auto gpuDescriptor = descriptor.tryCreateGPURenderPassDescriptor();
    78     if (!gpuDescriptor)
    79         return nullptr;
    80 
    81     if (auto encoder = GPURenderPassEncoder::tryCreate(m_commandBuffer.copyRef(), WTFMove(*gpuDescriptor)))
    82         return WebGPURenderPassEncoder::create(*this, encoder.releaseNonNull());
    83     return nullptr;
    84 }
    85 
    86 void WebGPUCommandBuffer::copyBufferToBuffer(const WebGPUBuffer& src, unsigned long srcOffset, const WebGPUBuffer& dst, unsigned long dstOffset, unsigned long size)
    87 {
    88     if (!src.buffer() || !dst.buffer()) {
    89         LOG(WebGPU, "GPUCommandBuffer::copyBufferToBuffer(): Invalid GPUBuffer!");
    90         return;
    91     }
    92 
    93     // FIXME: Add Web GPU validation.
    94 
    95     m_commandBuffer->copyBufferToBuffer(src.buffer().releaseNonNull(), srcOffset, dst.buffer().releaseNonNull(), dstOffset, size);
    96 }
    97 
    98 void WebGPUCommandBuffer::copyBufferToTexture(const WebGPUBufferCopyView& srcBuffer, const WebGPUTextureCopyView& dstTexture, const GPUExtent3D& size)
    99 {
    100     auto gpuBufferView = srcBuffer.tryCreateGPUBufferCopyView();
    101     auto gpuTextureView = dstTexture.tryCreateGPUTextureCopyView();
    102 
    103     if (!gpuBufferView || !gpuTextureView)
    104         return;
    105 
    106     // FIXME: Add Web GPU validation.
    107 
    108     m_commandBuffer->copyBufferToTexture(WTFMove(*gpuBufferView), WTFMove(*gpuTextureView), size);
    109 }
    110 
    111 void WebGPUCommandBuffer::copyTextureToBuffer(const WebGPUTextureCopyView& srcTexture, const WebGPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
    112 {
    113     auto gpuTextureView = srcTexture.tryCreateGPUTextureCopyView();
    114     auto gpuBufferView = dstBuffer.tryCreateGPUBufferCopyView();
    115 
    116     if (!gpuTextureView || !gpuBufferView)
    117         return;
    118 
    119     // FIXME: Add Web GPU validation.
    120 
    121     m_commandBuffer->copyTextureToBuffer(WTFMove(*gpuTextureView), WTFMove(*gpuBufferView), size);
    122 }
    123 
    124 void WebGPUCommandBuffer::copyTextureToTexture(const WebGPUTextureCopyView& src, const WebGPUTextureCopyView& dst, const GPUExtent3D& size)
    125 {
    126     auto gpuSrcView = src.tryCreateGPUTextureCopyView();
    127     auto gpuDstView = dst.tryCreateGPUTextureCopyView();
    128 
    129     if (!gpuSrcView || !gpuDstView)
    130         return;
    131 
    132     // FIXME: Add Web GPU validation.
    133 
    134     m_commandBuffer->copyTextureToTexture(WTFMove(*gpuSrcView), WTFMove(*gpuDstView), size);
    13541}
    13642
  • trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.h

    r242956 r242974  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2929
    3030#include "GPUCommandBuffer.h"
    31 
    3231#include <wtf/RefCounted.h>
     32#include <wtf/RefPtr.h>
    3333
    3434namespace WebCore {
    3535
    36 class WebGPUBuffer;
    37 class WebGPURenderPassEncoder;
    38 class WebGPUTexture;
    39 
    40 struct GPUExtent3D;
    41 struct WebGPURenderPassDescriptor;
    42 
    43 struct WebGPUBufferCopyView : GPUBufferCopyViewBase {
    44     Optional<GPUBufferCopyView> tryCreateGPUBufferCopyView() const;
    45 
    46     RefPtr<WebGPUBuffer> buffer;
    47 };
    48 
    49 struct WebGPUTextureCopyView : GPUTextureCopyViewBase {
    50     Optional<GPUTextureCopyView> tryCreateGPUTextureCopyView() const;
    51 
    52     RefPtr<WebGPUTexture> texture;
    53 };
    54 
    5536class WebGPUCommandBuffer : public RefCounted<WebGPUCommandBuffer> {
    5637public:
    57     static Ref<WebGPUCommandBuffer> create(Ref<GPUCommandBuffer>&&);
     38    static Ref<WebGPUCommandBuffer> create(RefPtr<GPUCommandBuffer>&&);
    5839
    59     GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
    60 
    61     RefPtr<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
    62     void copyBufferToBuffer(const WebGPUBuffer&, unsigned long srcOffset, const WebGPUBuffer&, unsigned long dstOffset, unsigned long size);
    63     void copyBufferToTexture(const WebGPUBufferCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
    64     void copyTextureToBuffer(const WebGPUTextureCopyView&, const WebGPUBufferCopyView&, const GPUExtent3D&);
    65     void copyTextureToTexture(const WebGPUTextureCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
     40    GPUCommandBuffer* commandBuffer() { return m_commandBuffer.get(); }
    6641
    6742private:
    68     WebGPUCommandBuffer(Ref<GPUCommandBuffer>&&);
     43    WebGPUCommandBuffer(RefPtr<GPUCommandBuffer>&&);
    6944
    70     Ref<GPUCommandBuffer> m_commandBuffer;
     45    RefPtr<GPUCommandBuffer> m_commandBuffer;
    7146};
    7247
  • trunk/Source/WebCore/Modules/webgpu/WebGPUCommandBuffer.idl

    r242956 r242974  
    11/*
    2  * Copyright (C) 2018 Apple Inc. All rights reserved.
     2 * Copyright (C) 2019 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525// https://github.com/gpuweb/gpuweb/blob/master/design/sketch.webidl
    2626
    27 typedef unsigned long u32;
    28 typedef unsigned long long u64;
    29 
    3027[
    3128    Conditional=WEBGPU,
    3229    EnabledAtRuntime=WebGPU,
    33     ImplementedAs=WebGPUBufferCopyView
    34 ] dictionary GPUBufferCopyView {
    35     WebGPUBuffer buffer;
    36     u64 offset;
    37     u64 rowPitch;
    38     u32 imageHeight;
     30    ImplementationLacksVTable,
     31    InterfaceName=GPUCommandBuffer
     32] interface WebGPUCommandBuffer {
    3933};
    40 
    41 [
    42     Conditional=WEBGPU,
    43     EnabledAtRuntime=WebGPU,
    44     ImplementedAs=WebGPUTextureCopyView
    45 ] dictionary GPUTextureCopyView {
    46     WebGPUTexture texture;
    47     u32 mipLevel;
    48     u32 arrayLayer;
    49     GPUOrigin3D origin;
    50 };
    51 
    52 [
    53     Conditional=WEBGPU,
    54     EnabledAtRuntime=WebGPU,
    55     ImplementationLacksVTable
    56 ] interface WebGPUCommandBuffer {
    57     WebGPURenderPassEncoder beginRenderPass(WebGPURenderPassDescriptor descriptor);
    58 
    59     void copyBufferToBuffer(
    60         WebGPUBuffer src,
    61         u64 srcOffset,
    62         WebGPUBuffer dst,
    63         u64 dstOffset,
    64         u64 size);
    65 
    66     void copyBufferToTexture(
    67         GPUBufferCopyView source,
    68         GPUTextureCopyView destination,
    69         GPUExtent3D copySize);
    70 
    71     void copyTextureToBuffer(
    72         GPUTextureCopyView source,
    73         GPUBufferCopyView destination,
    74         GPUExtent3D copySize);
    75 
    76     void copyTextureToTexture(
    77         GPUTextureCopyView source,
    78         GPUTextureCopyView destination,
    79         GPUExtent3D copySize);
    80 
    81     // Not Yet Implemented
    82     // WebGPUComputePassEncoder beginComputePass();
    83 };
  • trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.cpp

    r242973 r242974  
    2525
    2626#include "config.h"
    27 #include "WebGPUCommandBuffer.h"
     27#include "WebGPUCommandEncoder.h"
    2828
    2929#if ENABLE(WEBGPU)
     
    4242{
    4343    if (!buffer || !buffer->buffer()) {
    44         LOG(WebGPU, "GPUCommandEncoder: Invalid buffer for copy!");
     44        LOG(WebGPU, "WebGPUCommandEncoder: Invalid buffer for copy!");
    4545        return WTF::nullopt;
    4646    }
     
    5454{
    5555    if (!texture || !texture->texture()) {
    56         LOG(WebGPU, "GPUCommandEncoder: Invalid texture for copy!");
     56        LOG(WebGPU, "WebGPUCommandEncoder: Invalid texture for copy!");
    5757        return WTF::nullopt;
    5858    }
     
    6363}
    6464
    65 Ref<WebGPUCommandBuffer> WebGPUCommandBuffer::create(Ref<GPUCommandBuffer>&& buffer)
     65Ref<WebGPUCommandEncoder> WebGPUCommandEncoder::create(RefPtr<GPUCommandBuffer>&& buffer)
    6666{
    67     return adoptRef(*new WebGPUCommandBuffer(WTFMove(buffer)));
     67    return adoptRef(*new WebGPUCommandEncoder(WTFMove(buffer)));
    6868}
    6969
    70 WebGPUCommandBuffer::WebGPUCommandBuffer(Ref<GPUCommandBuffer>&& buffer)
     70WebGPUCommandEncoder::WebGPUCommandEncoder(RefPtr<GPUCommandBuffer>&& buffer)
    7171    : m_commandBuffer(WTFMove(buffer))
    7272{
    7373}
    7474
    75 RefPtr<WebGPURenderPassEncoder> WebGPUCommandBuffer::beginRenderPass(WebGPURenderPassDescriptor&& descriptor)
     75Ref<WebGPURenderPassEncoder> WebGPUCommandEncoder::beginRenderPass(WebGPURenderPassDescriptor&& descriptor)
    7676{
     77    if (!m_commandBuffer) {
     78        LOG(WebGPU, "WebGPUCommandEncoder::beginRenderPass(): Invalid operation!");
     79        return WebGPURenderPassEncoder::create(*this, nullptr);
     80    }
    7781    auto gpuDescriptor = descriptor.tryCreateGPURenderPassDescriptor();
    7882    if (!gpuDescriptor)
    79         return nullptr;
     83        return WebGPURenderPassEncoder::create(*this, nullptr);
    8084
    81     if (auto encoder = GPURenderPassEncoder::tryCreate(m_commandBuffer.copyRef(), WTFMove(*gpuDescriptor)))
    82         return WebGPURenderPassEncoder::create(*this, encoder.releaseNonNull());
    83     return nullptr;
     85    auto encoder = GPURenderPassEncoder::tryCreate(makeRef(*m_commandBuffer), WTFMove(*gpuDescriptor));
     86    return WebGPURenderPassEncoder::create(*this, WTFMove(encoder));
    8487}
    8588
    86 void WebGPUCommandBuffer::copyBufferToBuffer(const WebGPUBuffer& src, unsigned long srcOffset, const WebGPUBuffer& dst, unsigned long dstOffset, unsigned long size)
     89void WebGPUCommandEncoder::copyBufferToBuffer(const WebGPUBuffer& src, unsigned long srcOffset, const WebGPUBuffer& dst, unsigned long dstOffset, unsigned long size)
    8790{
     91    if (!m_commandBuffer) {
     92        LOG(WebGPU, "WebGPUCommandEncoder::copyBufferToBuffer(): Invalid operation!");
     93        return;
     94    }
    8895    if (!src.buffer() || !dst.buffer()) {
    89         LOG(WebGPU, "GPUCommandBuffer::copyBufferToBuffer(): Invalid GPUBuffer!");
     96        LOG(WebGPU, "WebGPUCommandEncoder::copyBufferToBuffer(): Invalid GPUBuffer!");
    9097        return;
    9198    }
     
    93100    // FIXME: Add Web GPU validation.
    94101
    95     m_commandBuffer->copyBufferToBuffer(src.buffer().releaseNonNull(), srcOffset, dst.buffer().releaseNonNull(), dstOffset, size);
     102    m_commandBuffer->copyBufferToBuffer(makeRef(*src.buffer()), srcOffset, makeRef(*dst.buffer()), dstOffset, size);
    96103}
    97104
    98 void WebGPUCommandBuffer::copyBufferToTexture(const WebGPUBufferCopyView& srcBuffer, const WebGPUTextureCopyView& dstTexture, const GPUExtent3D& size)
     105void WebGPUCommandEncoder::copyBufferToTexture(const WebGPUBufferCopyView& srcBuffer, const WebGPUTextureCopyView& dstTexture, const GPUExtent3D& size)
    99106{
     107    if (!m_commandBuffer) {
     108        LOG(WebGPU, "WebGPUCommandEncoder::copyBufferToTexture(): Invalid operation!");
     109        return;
     110    }
    100111    auto gpuBufferView = srcBuffer.tryCreateGPUBufferCopyView();
    101112    auto gpuTextureView = dstTexture.tryCreateGPUTextureCopyView();
     
    109120}
    110121
    111 void WebGPUCommandBuffer::copyTextureToBuffer(const WebGPUTextureCopyView& srcTexture, const WebGPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
     122void WebGPUCommandEncoder::copyTextureToBuffer(const WebGPUTextureCopyView& srcTexture, const WebGPUBufferCopyView& dstBuffer, const GPUExtent3D& size)
    112123{
     124    if (!m_commandBuffer) {
     125        LOG(WebGPU, "WebGPUCommandEncoder::copyTextureToBuffer(): Invalid operation!");
     126        return;
     127    }
    113128    auto gpuTextureView = srcTexture.tryCreateGPUTextureCopyView();
    114129    auto gpuBufferView = dstBuffer.tryCreateGPUBufferCopyView();
     
    122137}
    123138
    124 void WebGPUCommandBuffer::copyTextureToTexture(const WebGPUTextureCopyView& src, const WebGPUTextureCopyView& dst, const GPUExtent3D& size)
     139void WebGPUCommandEncoder::copyTextureToTexture(const WebGPUTextureCopyView& src, const WebGPUTextureCopyView& dst, const GPUExtent3D& size)
    125140{
     141    if (!m_commandBuffer) {
     142        LOG(WebGPU, "WebGPUCommandEncoder::copyTextureToTexture(): Invalid operation!");
     143        return;
     144    }
    126145    auto gpuSrcView = src.tryCreateGPUTextureCopyView();
    127146    auto gpuDstView = dst.tryCreateGPUTextureCopyView();
     
    134153    m_commandBuffer->copyTextureToTexture(WTFMove(*gpuSrcView), WTFMove(*gpuDstView), size);
    135154}
     155   
     156Ref<WebGPUCommandBuffer> WebGPUCommandEncoder::finish()
     157{
     158    if (!m_commandBuffer) {
     159        LOG(WebGPU, "WebGPUCommandEncoder::finish(): Invalid operation!");
     160        return WebGPUCommandBuffer::create(nullptr);
     161    }
     162    // Passes the referenced GPUCommandBuffer to the WebGPUCommandBuffer, invalidating this WebGPUCommandEncoder.
     163    return WebGPUCommandBuffer::create(m_commandBuffer.releaseNonNull());
     164}
    136165
    137166} // namespace WebCore
  • trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.h

    r242973 r242974  
    2929
    3030#include "GPUCommandBuffer.h"
    31 
     31#include "WebGPUCommandBuffer.h"
    3232#include <wtf/RefCounted.h>
     33#include <wtf/RefPtr.h>
    3334
    3435namespace WebCore {
     
    5354};
    5455
    55 class WebGPUCommandBuffer : public RefCounted<WebGPUCommandBuffer> {
     56class WebGPUCommandEncoder : public RefCounted<WebGPUCommandEncoder> {
    5657public:
    57     static Ref<WebGPUCommandBuffer> create(Ref<GPUCommandBuffer>&&);
     58    static Ref<WebGPUCommandEncoder> create(RefPtr<GPUCommandBuffer>&&);
    5859
    59     GPUCommandBuffer& commandBuffer() const { return m_commandBuffer.get(); }
    60 
    61     RefPtr<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
     60    Ref<WebGPURenderPassEncoder> beginRenderPass(WebGPURenderPassDescriptor&&);
    6261    void copyBufferToBuffer(const WebGPUBuffer&, unsigned long srcOffset, const WebGPUBuffer&, unsigned long dstOffset, unsigned long size);
    6362    void copyBufferToTexture(const WebGPUBufferCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
    6463    void copyTextureToBuffer(const WebGPUTextureCopyView&, const WebGPUBufferCopyView&, const GPUExtent3D&);
    6564    void copyTextureToTexture(const WebGPUTextureCopyView&, const WebGPUTextureCopyView&, const GPUExtent3D&);
     65    Ref<WebGPUCommandBuffer> finish();
    6666
    6767private:
    68     WebGPUCommandBuffer(Ref<GPUCommandBuffer>&&);
     68    WebGPUCommandEncoder(RefPtr<GPUCommandBuffer>&&);
    6969
    70     Ref<GPUCommandBuffer> m_commandBuffer;
     70    RefPtr<GPUCommandBuffer> m_commandBuffer;
    7171};
    7272
  • trunk/Source/WebCore/Modules/webgpu/WebGPUCommandEncoder.idl

    r242973 r242974  
    5353    Conditional=WEBGPU,
    5454    EnabledAtRuntime=WebGPU,
    55     ImplementationLacksVTable
    56 ] interface WebGPUCommandBuffer {
     55    ImplementationLacksVTable,
     56    InterfaceName=GPUCommandEncoder
     57] interface WebGPUCommandEncoder {
    5758    WebGPURenderPassEncoder beginRenderPass(WebGPURenderPassDescriptor descriptor);
    5859
     
    7980        GPUExtent3D copySize);
    8081
     82    WebGPUCommandBuffer finish();
     83
    8184    // Not Yet Implemented
    8285    // WebGPUComputePassEncoder beginComputePass();
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.cpp

    r242956 r242974  
    4545#include "WebGPUBindGroup.h"
    4646#include "WebGPUBindGroupBinding.h"
     47#include "WebGPUBindGroupDescriptor.h"
    4748#include "WebGPUBindGroupLayout.h"
    4849#include "WebGPUBuffer.h"
    4950#include "WebGPUBufferBinding.h"
    50 #include "WebGPUCommandBuffer.h"
     51#include "WebGPUCommandEncoder.h"
    5152#include "WebGPUPipelineLayout.h"
    5253#include "WebGPUPipelineLayoutDescriptor.h"
     
    138139}
    139140
    140 RefPtr<WebGPUCommandBuffer> WebGPUDevice::createCommandBuffer() const
     141Ref<WebGPUCommandEncoder> WebGPUDevice::createCommandEncoder() const
    141142{
    142     if (auto commandBuffer = m_device->createCommandBuffer())
    143         return WebGPUCommandBuffer::create(commandBuffer.releaseNonNull());
    144     return nullptr;
     143    auto commandBuffer = m_device->tryCreateCommandBuffer();
     144    return WebGPUCommandEncoder::create(WTFMove(commandBuffer));
    145145}
    146146
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.h

    r242956 r242974  
    4242class WebGPUBindGroupLayout;
    4343class WebGPUBuffer;
    44 class WebGPUCommandBuffer;
     44class WebGPUCommandEncoder;
    4545class WebGPUPipelineLayout;
    4646class WebGPURenderPipeline;
     
    7777    Ref<WebGPURenderPipeline> createRenderPipeline(const WebGPURenderPipelineDescriptor&) const;
    7878
    79     RefPtr<WebGPUCommandBuffer> createCommandBuffer() const;
     79    Ref<WebGPUCommandEncoder> createCommandEncoder() const;
    8080
    8181    Ref<WebGPUSwapChain> createSwapChain(const WebGPUSwapChainDescriptor&) const;
  • trunk/Source/WebCore/Modules/webgpu/WebGPUDevice.idl

    r242956 r242974  
    5555    WebGPURenderPipeline createRenderPipeline(WebGPURenderPipelineDescriptor descriptor);
    5656
    57     // FIXME: Currently, WebGPUCommandBufferDescriptor is an empty dictionary.
    58     WebGPUCommandBuffer createCommandBuffer(/*WebGPUCommandBufferDescriptor descriptor*/);
     57    // FIXME: Currently, GPUCommandEncoderDescriptor is an empty dictionary.
     58    WebGPUCommandEncoder createCommandEncoder(/*GPUCommandEncoderDescriptor descriptor*/);
    5959
    6060    WebGPUSwapChain createSwapChain(WebGPUSwapChainDescriptor descriptor);
  • trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.cpp

    r242956 r242974  
    3636namespace WebCore {
    3737
    38 WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder(Ref<WebGPUCommandBuffer>&& creator)
     38WebGPUProgrammablePassEncoder::WebGPUProgrammablePassEncoder(Ref<WebGPUCommandEncoder>&& creator)
    3939    : m_commandBuffer(WTFMove(creator))
    4040{
    4141}
    4242
    43 Ref<WebGPUCommandBuffer> WebGPUProgrammablePassEncoder::endPass()
     43void WebGPUProgrammablePassEncoder::endPass()
    4444{
    45     passEncoder().endPass();
    46     return m_commandBuffer.copyRef();
     45    if (!passEncoder()) {
     46        LOG(WebGPU, "GPUProgrammablePassEncoder::endPass(): Invalid operation!");
     47        return;
     48    }
     49    passEncoder()->endPass();
    4750}
    4851
    4952void WebGPUProgrammablePassEncoder::setBindGroup(unsigned index, WebGPUBindGroup& bindGroup) const
    5053{
     54    if (!passEncoder()) {
     55        LOG(WebGPU, "GPUProgrammablePassEncoder::setBindGroup(): Invalid operation!");
     56        return;
     57    }
    5158    // Maximum number of bind groups supported in Web GPU.
    5259    if (index >= 4) {
    53         LOG(WebGPU, "WebGPUProgrammablePassEncoder::setBindGroup(): Invalid index!");
     60        LOG(WebGPU, "GPUProgrammablePassEncoder::setBindGroup(): Invalid index!");
    5461        return;
    5562    }
    5663    if (!bindGroup.bindGroup()) {
    57         LOG(WebGPU, "WebGPUProgrammablePassEncoder::setBindGroup(): Invalid WebGPUBindGroup!");
     64        LOG(WebGPU, "GPUProgrammablePassEncoder::setBindGroup(): Invalid WebGPUBindGroup!");
    5865        return;
    5966    }
    6067    // FIXME: Any validation (e.g. index duplicates, not in pipeline layout).
    61     passEncoder().setBindGroup(index, *bindGroup.bindGroup());
     68    passEncoder()->setBindGroup(index, *bindGroup.bindGroup());
    6269}
    6370
    6471void WebGPUProgrammablePassEncoder::setPipeline(const WebGPURenderPipeline& pipeline)
    6572{
     73    if (!passEncoder()) {
     74        LOG(WebGPU, "GPUProgrammablePassEncoder::setPipeline(): Invalid operation!");
     75        return;
     76    }
    6677    if (!pipeline.renderPipeline()) {
    6778        LOG(WebGPU, "GPUProgrammablePassEncoder::setPipeline(): Invalid pipeline!");
    6879        return;
    6980    }
    70     passEncoder().setPipeline(makeRef(*pipeline.renderPipeline()));
     81    passEncoder()->setPipeline(makeRef(*pipeline.renderPipeline()));
    7182}
    7283
  • trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.h

    r242956 r242974  
    2828#if ENABLE(WEBGPU)
    2929
    30 #include "WebGPUCommandBuffer.h"
     30#include "WebGPUCommandEncoder.h"
    3131#include <wtf/RefCounted.h>
    3232
     
    4141    virtual ~WebGPUProgrammablePassEncoder() = default;
    4242
    43     Ref<WebGPUCommandBuffer> endPass();
     43    void endPass();
    4444    void setBindGroup(unsigned, WebGPUBindGroup&) const;
    4545    void setPipeline(const WebGPURenderPipeline&);
    4646
    4747protected:
    48     WebGPUProgrammablePassEncoder(Ref<WebGPUCommandBuffer>&&);
     48    WebGPUProgrammablePassEncoder(Ref<WebGPUCommandEncoder>&&);
    4949
    50     virtual GPUProgrammablePassEncoder& passEncoder() const = 0;
     50    virtual GPUProgrammablePassEncoder* passEncoder() const = 0;
    5151
    5252private:
    53     Ref<WebGPUCommandBuffer> m_commandBuffer;
     53    Ref<WebGPUCommandEncoder> m_commandBuffer;
    5454};
    5555
  • trunk/Source/WebCore/Modules/webgpu/WebGPUProgrammablePassEncoder.idl

    r242956 r242974  
    3232    SkipVTableValidation
    3333] interface WebGPUProgrammablePassEncoder {
    34     WebGPUCommandBuffer endPass();
     34    void endPass();
    3535    void setBindGroup(u32 index, WebGPUBindGroup bindGroup/*, optional sequence<u32> dynamicOffsets*/);
    3636    void setPipeline(WebGPURenderPipeline pipeline); // FIXME: Support WebGPUComputePipelines.
  • trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.cpp

    r242956 r242974  
    3131#include "GPUCommandBuffer.h"
    3232#include "GPUQueue.h"
     33#include "Logging.h"
    3334#include "WebGPUCommandBuffer.h"
    3435
     
    4546}
    4647
    47 void WebGPUQueue::submit(Vector<RefPtr<WebGPUCommandBuffer>>&& buffers)
     48void WebGPUQueue::submit(const Vector<RefPtr<WebGPUCommandBuffer>>& buffers)
    4849{
    49     auto gpuBuffers = buffers.map([] (auto& buffer) -> Ref<GPUCommandBuffer> {
    50         return buffer->commandBuffer();
    51     });
     50    Vector<Ref<GPUCommandBuffer>> gpuBuffers;
     51    gpuBuffers.reserveCapacity(buffers.size());
     52   
     53    for (auto& buffer : buffers) {
     54        if (!buffer || !buffer->commandBuffer()) {
     55            LOG(WebGPU, "GPUQueue::submit(): Invalid GPUCommandBuffer in list!");
     56            return;
     57        }
     58        gpuBuffers.uncheckedAppend(makeRef(*buffer->commandBuffer()));
     59    }
     60
    5261    m_queue->submit(WTFMove(gpuBuffers));
    5362}
  • trunk/Source/WebCore/Modules/webgpu/WebGPUQueue.h

    r242956 r242974  
    4242    static RefPtr<WebGPUQueue> create(RefPtr<GPUQueue>&&);
    4343
    44     void submit(Vector<RefPtr<WebGPUCommandBuffer>>&&);
     44    void submit(const Vector<RefPtr<WebGPUCommandBuffer>>&);
    4545
    4646    String label() const { return m_queue->label(); }
  • trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.cpp

    r242956 r242974  
    3737namespace WebCore {
    3838
    39 Ref<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandBuffer>&& commandBuffer, Ref<GPURenderPassEncoder>&& encoder)
     39Ref<WebGPURenderPassEncoder> WebGPURenderPassEncoder::create(Ref<WebGPUCommandEncoder>&& commandBuffer, RefPtr<GPURenderPassEncoder>&& encoder)
    4040{
    4141    return adoptRef(*new WebGPURenderPassEncoder(WTFMove(commandBuffer), WTFMove(encoder)));
    4242}
    4343
    44 WebGPURenderPassEncoder::WebGPURenderPassEncoder(Ref<WebGPUCommandBuffer>&& creator, Ref<GPURenderPassEncoder>&& encoder)
     44WebGPURenderPassEncoder::WebGPURenderPassEncoder(Ref<WebGPUCommandEncoder>&& creator, RefPtr<GPURenderPassEncoder>&& encoder)
    4545    : WebGPUProgrammablePassEncoder(WTFMove(creator))
    4646    , m_passEncoder(WTFMove(encoder))
     
    5353    const char* const functionName = "GPURenderPassEncoder::setVertexBuffers()";
    5454#endif
     55    if (!m_passEncoder) {
     56        LOG(WebGPU, "%s: Invalid operation!", functionName);
     57        return;
     58    }
    5559    if (buffers.isEmpty() || buffers.size() != offsets.size()) {
    5660        LOG(WebGPU, "%s: Invalid number of buffers or offsets!", functionName);
    5761        return;
    5862    }
    59 
    6063    if (startSlot + buffers.size() > maxVertexBuffers) {
    6164        LOG(WebGPU, "%s: Invalid startSlot %lu for %lu buffers!", functionName, startSlot, buffers.size());
     
    8588void WebGPURenderPassEncoder::draw(unsigned long vertexCount, unsigned long instanceCount, unsigned long firstVertex, unsigned long firstInstance)
    8689{
     90    if (!m_passEncoder) {
     91        LOG(WebGPU, "GPURenderPassEncoder::draw(): Invalid operation!");
     92        return;
     93    }
    8794    // FIXME: What kind of validation do we need to handle here?
    8895    m_passEncoder->draw(vertexCount, instanceCount, firstVertex, firstInstance);
    8996}
    9097
    91 GPUProgrammablePassEncoder& WebGPURenderPassEncoder::passEncoder() const
     98GPUProgrammablePassEncoder* WebGPURenderPassEncoder::passEncoder() const
    9299{
    93100    return m_passEncoder.get();
  • trunk/Source/WebCore/Modules/webgpu/WebGPURenderPassEncoder.h

    r242956 r242974  
    4141class WebGPURenderPassEncoder final : public WebGPUProgrammablePassEncoder {
    4242public:
    43     static Ref<WebGPURenderPassEncoder> create(Ref<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
     43    static Ref<WebGPURenderPassEncoder> create(Ref<WebGPUCommandEncoder>&&, RefPtr<GPURenderPassEncoder>&&);
    4444
    4545    void setVertexBuffers(unsigned long, Vector<RefPtr<WebGPUBuffer>>&&, Vector<unsigned long long>&&);
     
    4747
    4848private:
    49     WebGPURenderPassEncoder(Ref<WebGPUCommandBuffer>&&, Ref<GPURenderPassEncoder>&&);
     49    WebGPURenderPassEncoder(Ref<WebGPUCommandEncoder>&&, RefPtr<GPURenderPassEncoder>&&);
    5050
    51     GPUProgrammablePassEncoder& passEncoder() const final;
     51    GPUProgrammablePassEncoder* passEncoder() const final;
    5252
    53     Ref<GPURenderPassEncoder> m_passEncoder;
     53    RefPtr<GPURenderPassEncoder> m_passEncoder;
    5454};
    5555
  • trunk/Source/WebCore/Modules/webgpu/WebGPUSwapChain.cpp

    r242956 r242974  
    5151    }
    5252    m_currentTexture = WebGPUTexture::create(m_swapChain->tryGetCurrentTexture());
    53     return m_currentTexture.releaseNonNull();
     53    return makeRef(*m_currentTexture);
    5454}
    5555
  • trunk/Source/WebCore/Sources.txt

    r242972 r242974  
    353353Modules/webgpu/WebGPUBindGroup.cpp
    354354Modules/webgpu/WebGPUBindGroupDescriptor.cpp
     355Modules/webgpu/WebGPUCommandBuffer.cpp
     356Modules/webgpu/WebGPUCommandEncoder.cpp
    355357Modules/webgpu/WebGPUAdapter.cpp
    356358Modules/webgpu/WebGPUBindGroupLayout.cpp
    357359Modules/webgpu/WebGPUBuffer.cpp
    358 Modules/webgpu/WebGPUCommandBuffer.cpp
    359360Modules/webgpu/WebGPUDevice.cpp
    360361Modules/webgpu/WebGPUQueue.cpp
     
    33393340JSWebGPUBufferBinding.cpp
    33403341JSWebGPUCommandBuffer.cpp
     3342JSWebGPUCommandEncoder.cpp
    33413343JSWebGPUDevice.cpp
    33423344JSWebGPUQueue.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r242972 r242974  
    1408514085                D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FormatBlockCommand.cpp; sourceTree = "<group>"; };
    1408614086                D05CED280A40BB2C00C5AF38 /* FormatBlockCommand.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = FormatBlockCommand.h; sourceTree = "<group>"; };
     14087                D05DD6DD223884060097A834 /* WebGPUCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandBuffer.cpp; sourceTree = "<group>"; };
     14088                D05DD6DE223884070097A834 /* WebGPUCommandBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandBuffer.h; sourceTree = "<group>"; };
     14089                D05DD6DF223884070097A834 /* WebGPUCommandBuffer.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandBuffer.idl; sourceTree = "<group>"; };
    1408714090                D060D88421825D5F00339318 /* WebGPUShaderModuleDescriptor.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUShaderModuleDescriptor.idl; sourceTree = "<group>"; };
    1408814091                D060D8872182697000339318 /* WebGPUShaderModuleDescriptor.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUShaderModuleDescriptor.h; sourceTree = "<group>"; };
     
    1419414197                D0DE8FB8222E09E200882550 /* GPUShaderStageBit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GPUShaderStageBit.h; sourceTree = "<group>"; };
    1419514198                D0DE8FB9222E09E200882550 /* GPUShaderStageBit.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = GPUShaderStageBit.idl; sourceTree = "<group>"; };
    14196                 D0EACF7621937228000FA75C /* WebGPUCommandBuffer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandBuffer.h; sourceTree = "<group>"; };
    14197                 D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandBuffer.cpp; sourceTree = "<group>"; };
    14198                 D0EACF7821937228000FA75C /* WebGPUCommandBuffer.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandBuffer.idl; sourceTree = "<group>"; };
     14199                D0EACF7621937228000FA75C /* WebGPUCommandEncoder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUCommandEncoder.h; sourceTree = "<group>"; };
     14200                D0EACF7721937228000FA75C /* WebGPUCommandEncoder.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUCommandEncoder.cpp; sourceTree = "<group>"; };
     14201                D0EACF7821937228000FA75C /* WebGPUCommandEncoder.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = WebGPUCommandEncoder.idl; sourceTree = "<group>"; };
    1419914202                D0EACF842193B02E000FA75C /* WebGPUTexture.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebGPUTexture.h; sourceTree = "<group>"; };
    1420014203                D0EACF852193B02E000FA75C /* WebGPUTexture.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = WebGPUTexture.cpp; sourceTree = "<group>"; };
     
    2617326176                                D0BE104C21E68F1500E42A89 /* WebGPUBufferBinding.h */,
    2617426177                                D0BE104D21E68F1500E42A89 /* WebGPUBufferBinding.idl */,
    26175                                 D0EACF7721937228000FA75C /* WebGPUCommandBuffer.cpp */,
    26176                                 D0EACF7621937228000FA75C /* WebGPUCommandBuffer.h */,
    26177                                 D0EACF7821937228000FA75C /* WebGPUCommandBuffer.idl */,
     26178                                D05DD6DD223884060097A834 /* WebGPUCommandBuffer.cpp */,
     26179                                D05DD6DE223884070097A834 /* WebGPUCommandBuffer.h */,
     26180                                D05DD6DF223884070097A834 /* WebGPUCommandBuffer.idl */,
     26181                                D0EACF7721937228000FA75C /* WebGPUCommandEncoder.cpp */,
     26182                                D0EACF7621937228000FA75C /* WebGPUCommandEncoder.h */,
     26183                                D0EACF7821937228000FA75C /* WebGPUCommandEncoder.idl */,
    2617826184                                D00F595321701D8C000D71DB /* WebGPUDevice.cpp */,
    2617926185                                D00F595221701D8C000D71DB /* WebGPUDevice.h */,
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r242956 r242974  
    8585    macro(GPUCanvasContext) \
    8686    macro(GPUShaderModule) \
     87    macro(GPUCommandBuffer) \
     88    macro(GPUCommandEncoder) \
    8789    macro(GPUShaderStageBit) \
    8890    macro(GPUSwapChain) \
     
    202204    macro(WebGPUBindGroupLayout) \
    203205    macro(WebGPUBuffer) \
    204     macro(WebGPUCommandBuffer) \
    205206    macro(WebGPUDevice) \
    206207    macro(WebGPUIndexFormat) \
  • trunk/Source/WebCore/platform/graphics/gpu/GPUCommandBuffer.h

    r242956 r242974  
    2828#if ENABLE(WEBGPU)
    2929
     30#include "GPUBuffer.h"
    3031#include "GPUOrigin3D.h"
     32#include "GPUTexture.h"
    3133#include <wtf/RefCounted.h>
    3234#include <wtf/RefPtr.h>
     
    3941namespace WebCore {
    4042
    41 class GPUBuffer;
    4243class GPUDevice;
    43 class GPUTexture;
    4444
    4545struct GPUExtent3D;
     
    8282class GPUCommandBuffer : public RefCounted<GPUCommandBuffer> {
    8383public:
    84     static RefPtr<GPUCommandBuffer> create(GPUDevice&);
     84    static RefPtr<GPUCommandBuffer> tryCreate(const GPUDevice&);
    8585
    8686    PlatformCommandBuffer* platformCommandBuffer() const { return m_platformCommandBuffer.get(); }
  • trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.cpp

    r242956 r242974  
    8484}
    8585
    86 RefPtr<GPUCommandBuffer> GPUDevice::createCommandBuffer()
     86RefPtr<GPUCommandBuffer> GPUDevice::tryCreateCommandBuffer() const
    8787{
    88     return GPUCommandBuffer::create(*this);
     88    return GPUCommandBuffer::tryCreate(*this);
    8989}
    9090
  • trunk/Source/WebCore/platform/graphics/gpu/GPUDevice.h

    r242956 r242974  
    3838namespace WebCore {
    3939
    40 using PlatformDevice = MTLDevice;
    41 using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>;
    42 
    4340class GPUBindGroupLayout;
    4441class GPUBuffer;
     
    5956struct GPUShaderModuleDescriptor;
    6057struct GPUTextureDescriptor;
     58   
     59using PlatformDevice = MTLDevice;
     60using PlatformDeviceSmartPtr = RetainPtr<MTLDevice>;
    6161
    6262class GPUDevice : public RefCounted<GPUDevice>, public CanMakeWeakPtr<GPUDevice> {
     
    7474    RefPtr<GPURenderPipeline> createRenderPipeline(GPURenderPipelineDescriptor&&) const;
    7575
    76     RefPtr<GPUCommandBuffer> createCommandBuffer();
     76    RefPtr<GPUCommandBuffer> tryCreateCommandBuffer() const;
    7777
    7878    RefPtr<GPUSwapChain> tryCreateSwapChain(const GPUSwapChainDescriptor&, int width, int height) const;
  • trunk/Source/WebCore/platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm

    r242956 r242974  
    2929#if ENABLE(WEBGPU)
    3030
    31 #import "GPUBuffer.h"
    3231#import "GPUDevice.h"
    3332#import "GPUExtent3D.h"
    3433#import "GPUQueue.h"
    35 #import "GPUTexture.h"
    3634#import "Logging.h"
    3735
     
    4240namespace WebCore {
    4341
    44 RefPtr<GPUCommandBuffer> GPUCommandBuffer::create(GPUDevice& device)
     42RefPtr<GPUCommandBuffer> GPUCommandBuffer::tryCreate(const GPUDevice& device)
    4543{
    4644    if (!device.platformDevice()) {
Note: See TracChangeset for help on using the changeset viewer.