Bug 193341 - [WebGPU] WebGPUBindGroup and device::createBindGroup prototype
Summary: [WebGPU] WebGPUBindGroup and device::createBindGroup prototype
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Justin Fan
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-01-10 14:53 PST by Justin Fan
Modified: 2019-01-10 18:14 PST (History)
4 users (show)

See Also:


Attachments
Patch (23.15 KB, patch)
2019-01-10 15:05 PST, Justin Fan
no flags Details | Formatted Diff | Diff
Patch (27.42 KB, patch)
2019-01-10 16:55 PST, Justin Fan
no flags Details | Formatted Diff | Diff
Patch for landing (27.29 KB, patch)
2019-01-10 17:34 PST, Justin Fan
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Fan 2019-01-10 14:53:10 PST
[WebGPU] WebGPUBindGroup and device::createBindGroup prototype
Comment 1 Justin Fan 2019-01-10 15:05:03 PST
Created attachment 358840 [details]
Patch
Comment 2 Justin Fan 2019-01-10 16:55:49 PST
Created attachment 358852 [details]
Patch
Comment 3 Myles C. Maxfield 2019-01-10 17:07:01 PST
Comment on attachment 358852 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=358852&action=review

> Source/WebCore/Modules/webgpu/WebGPUBindGroup.cpp:33
> +Ref<WebGPUBindGroup> WebGPUBindGroup::create(RefPtr<GPUBindGroup>&& bindGroup)

Why not use Ref<>? You won't have to perform as many null checks.

> Source/WebCore/Modules/webgpu/WebGPUDevice.cpp:118
> +        return WebGPUBindGroup::create(nullptr);

This should refuse to create the object. In JS, if you call this function with garbage, it should return null, not a real object with nothing inside it.

> Source/WebCore/Modules/webgpu/WebGPUDevice.cpp:125
> +        auto bindingResource = WTF::visit(BindingResourceVisitor(), binding.resource);

Please use WTF::makeVisitor()

> Source/WebCore/Modules/webgpu/WebGPUDevice.cpp:130
> +            return WebGPUBindGroup::create(nullptr);

Ditto from above
Comment 4 Dean Jackson 2019-01-10 17:08:07 PST
Comment on attachment 358840 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=358840&action=review

> Source/WebCore/Modules/webgpu/WebGPUDevice.cpp:112
> +struct BindingResourceVisitor {
> +    Optional<GPUBindingResource> operator()(RefPtr<WebGPUTextureView> textureView) const
> +    {
> +        if (textureView)
> +            return static_cast<GPUBindingResource>(textureView->texture());
> +        return WTF::nullopt;
> +    }
> +
> +    Optional<GPUBindingResource> operator()(WebGPUBufferBinding binding) const
> +    {
> +        // FIXME: What kind of validation should be performed on binding.offset and binding.size?
> +        if (binding.buffer)
> +            return static_cast<GPUBindingResource>(GPUBufferBinding { binding.buffer->buffer(), binding.offset, binding.size });
> +        return WTF::nullopt;
> +    }
> +};

We usually do this with WTF::makeVisitor inline, just above the call to ::visit.

Also, we tend to use inline function syntax rather than operator()... so it would be something like this:

auto visitor = WTF::makeVisitor([&](RefPtr<WebGPUTextureView> textureView) -> Optional<GPUBindingResource> {
        ...
    }, [&](WebGPUBufferBinding binding) -> Optional<GPUBindingResource> {
        ...
    });

> Source/WebCore/Modules/webgpu/WebGPUDevice.cpp:124
> +    Vector<GPUBindGroupBinding> bindGroupBindings;
> +    bindGroupBindings.reserveCapacity(descriptor.bindings.size());
> +
> +    for (const auto& binding : descriptor.bindings) {

You could do this with Vector::map. e.g.

auto bindGroupBindings = descriptor.bindings.map([] (const auto& binding) { .... } );

However, if you want to handle errors... I guess you'd have to have a variable outside the scope of the function.

> Source/WebCore/Modules/webgpu/WebGPUDevice.cpp:125
> +        auto bindingResource = WTF::visit(BindingResourceVisitor(), binding.resource);

See WebGLRenderingContextBase::texSubImage2D for an example.
Comment 5 Justin Fan 2019-01-10 17:34:30 PST
Created attachment 358856 [details]
Patch for landing
Comment 6 WebKit Commit Bot 2019-01-10 18:13:07 PST
Comment on attachment 358856 [details]
Patch for landing

Clearing flags on attachment: 358856

Committed r239853: <https://trac.webkit.org/changeset/239853>
Comment 7 WebKit Commit Bot 2019-01-10 18:13:08 PST
All reviewed patches have been landed.  Closing bug.
Comment 8 Radar WebKit Bug Importer 2019-01-10 18:14:28 PST
<rdar://problem/47197555>