Skip to content
Permalink
Browse files
[Web GPU] Standardize Web GPU object reference counting and creation …
…logic

https://bugs.webkit.org/show_bug.cgi?id=196183

Reviewed by Dean Jackson.

Source/WebCore:

Make getters return raw refs/pointers and provide const versions if necessary.
All Web GPU objects are non-nullable, but become no-op if invalid, and descriptors are not moved unless needed.

No new tests; no change in behavior.

Getter updates and const qualifications:
* Modules/webgpu/WebGPUAdapter.h:
(WebCore::WebGPUAdapter::options const):
* Modules/webgpu/WebGPUBindGroup.h:
(WebCore::WebGPUBindGroup::bindGroup):
(WebCore::WebGPUBindGroup::bindGroup const): Deleted.
* Modules/webgpu/WebGPUBindGroupDescriptor.cpp:
(WebCore::WebGPUBindGroupDescriptor::tryCreateGPUBindGroupDescriptor const):
* Modules/webgpu/WebGPUBindGroupDescriptor.h:
* Modules/webgpu/WebGPUBindGroupLayout.h:
(WebCore::WebGPUBindGroupLayout::bindGroupLayout const):
* Modules/webgpu/WebGPUBuffer.h:
(WebCore::WebGPUBuffer::buffer):
(WebCore::WebGPUBuffer::buffer const):
* Modules/webgpu/WebGPURenderPassDescriptor.cpp:
(WebCore::WebGPURenderPassDescriptor::tryCreateGPURenderPassDescriptor const):
* Modules/webgpu/WebGPURenderPassEncoder.cpp:
(WebCore::WebGPURenderPassEncoder::setVertexBuffers):
* Modules/webgpu/WebGPUSampler.h:
(WebCore::WebGPUSampler::sampler const):
* Modules/webgpu/WebGPUSwapChain.h:
(WebCore::WebGPUSwapChain::swapChain):
(WebCore::WebGPUSwapChain::swapChain const): Deleted.
* Modules/webgpu/WebGPUTexture.h:
(WebCore::WebGPUTexture::texture):
(WebCore::WebGPUTexture::texture const): Deleted.
* Modules/webgpu/WebGPUTextureView.h:
(WebCore::WebGPUTextureView::texture):
(WebCore::WebGPUTextureView::texture const): Deleted.
* platform/graphics/gpu/GPUBindGroupBinding.h:
* platform/graphics/gpu/GPUBindGroupDescriptor.h:
* platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm:
(WebCore::tryGetResourceAsMTLSamplerState):

Web GPU object creation logic:
* Modules/webgpu/WebGPUCommandEncoder.cpp:
(WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const):
(WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const):
(WebCore::WebGPUCommandEncoder::beginRenderPass):
(WebCore::WebGPUCommandEncoder::copyBufferToBuffer):
* Modules/webgpu/WebGPUCommandEncoder.h:
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::createBuffer const):
(WebCore::WebGPUDevice::createTexture const):
(WebCore::WebGPUDevice::createPipelineLayout const):
(WebCore::WebGPUDevice::createBindGroup const):
(WebCore::WebGPUDevice::createShaderModule const):
(WebCore::WebGPUDevice::createRenderPipeline const):
(WebCore::WebGPUDevice::getQueue const):
* Modules/webgpu/WebGPUDevice.h:
* Modules/webgpu/WebGPUPipelineLayout.cpp:
(WebCore::WebGPUPipelineLayout::create):
(WebCore::WebGPUPipelineLayout::WebGPUPipelineLayout):
* Modules/webgpu/WebGPUPipelineLayout.h:
(WebCore::WebGPUPipelineLayout::pipelineLayout):
* Modules/webgpu/WebGPUPipelineLayoutDescriptor.cpp:
(WebCore::WebGPUPipelineLayoutDescriptor::tryCreateGPUPipelineLayoutDescriptor const):
* Modules/webgpu/WebGPUPipelineLayoutDescriptor.h:
* Modules/webgpu/WebGPUQueue.cpp:
(WebCore::WebGPUQueue::create):
(WebCore::WebGPUQueue::WebGPUQueue):
(WebCore::WebGPUQueue::submit):
* Modules/webgpu/WebGPUQueue.h:
* Modules/webgpu/WebGPUShaderModule.cpp:
(WebCore::WebGPUShaderModule::create):
(WebCore::WebGPUShaderModule::WebGPUShaderModule):
* Modules/webgpu/WebGPUShaderModule.h:
(WebCore::WebGPUShaderModule::module const):
* platform/graphics/gpu/GPUBuffer.h:
* platform/graphics/gpu/GPUDevice.cpp:
(WebCore::GPUDevice::tryCreateBuffer):
(WebCore::GPUDevice::tryCreateTexture const):
(WebCore::GPUDevice::tryCreateShaderModule const):
(WebCore::GPUDevice::tryCreateRenderPipeline const):
(WebCore::GPUDevice::tryGetQueue const):
(WebCore::GPUDevice::createShaderModule const): Deleted.
(WebCore::GPUDevice::createRenderPipeline const): Deleted.
(WebCore::GPUDevice::getQueue const): Deleted.
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/GPUPipelineLayout.cpp:
(WebCore::GPUPipelineLayout::create):
(WebCore::GPUPipelineLayout::GPUPipelineLayout):
* platform/graphics/gpu/GPUPipelineLayout.h:
(WebCore::GPUPipelineLayout::bindGroupLayouts const):
* platform/graphics/gpu/GPUPipelineLayoutDescriptor.h:
* platform/graphics/gpu/GPURenderPipeline.h:
* platform/graphics/gpu/GPUShaderModule.h:
* platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
(WebCore::GPUBuffer::tryCreate):
(WebCore::GPUBuffer::GPUBuffer):
(WebCore::GPUBuffer::setSubData):
* platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
(WebCore::GPUCommandBuffer::tryCreate):
* platform/graphics/gpu/cocoa/GPUDeviceMetal.mm:
(WebCore::GPUDevice::tryCreate):
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::GPURenderPipeline::tryCreate):
(WebCore::GPURenderPipeline::GPURenderPipeline):
(WebCore::GPURenderPipeline::create): Deleted.
* platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm:
(WebCore::GPUShaderModule::tryCreate):
(WebCore::GPUShaderModule::create): Deleted.

Add WebGPUPipelineLayoutDescriptor.cpp to project:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

LayoutTests:

GPUShaderModule is no longer nullable.

* webgpu/shader-modules.html:


Canonical link: https://commits.webkit.org/210611@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@243563 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Justin Fan committed Mar 27, 2019
1 parent e114843 commit b5b66c4fec6a75f6d1dad4330f3502768c4cb3ec
Show file tree
Hide file tree
Showing 45 changed files with 319 additions and 146 deletions.
@@ -1,3 +1,14 @@
2019-03-27 Justin Fan <justin_fan@apple.com>

[Web GPU] Standardize Web GPU object reference counting and creation logic
https://bugs.webkit.org/show_bug.cgi?id=196183

Reviewed by Dean Jackson.

GPUShaderModule is no longer nullable.

* webgpu/shader-modules.html:

2019-03-27 Shawn Roberts <sroberts@apple.com>

Unreviewed, rolling out r243346.
@@ -27,35 +27,10 @@
}
`

const incompleteShaders = `
#include <metal_stdlib>
using namespace metal;
vertex Vertex vertex_main(uint vid [[vertex_id]])
{
return Vertex { float4(0, 0, 0, 1) };
}
fragment float4 fragment_main(Vertex vertexIn [[stage_in]])
{
rreturn vertexIn.position;
}
`

promise_test(async () => {
const device = await getBasicDevice();

const shaderDescriptor0 = {
code : "Hello World"
};
let shaderModule = device.createShaderModule(shaderDescriptor0);
assert_equals(shaderModule, null, "Bad shader code did not create a module.");

shaderModule = device.createShaderModule({ code: incompleteShaders });
assert_equals(shaderModule, null, "Incomplete shader code did not create a module.");

shaderModule = device.createShaderModule({ code: shaders });
let shaderModule = device.createShaderModule({ code: shaders });
assert_true(shaderModule instanceof GPUShaderModule, "Shader module created successfully.");
}, "Test shader code validation when creating modules.");
</script>
@@ -1,3 +1,122 @@
2019-03-27 Justin Fan <justin_fan@apple.com>

[Web GPU] Standardize Web GPU object reference counting and creation logic
https://bugs.webkit.org/show_bug.cgi?id=196183

Reviewed by Dean Jackson.

Make getters return raw refs/pointers and provide const versions if necessary.
All Web GPU objects are non-nullable, but become no-op if invalid, and descriptors are not moved unless needed.

No new tests; no change in behavior.

Getter updates and const qualifications:
* Modules/webgpu/WebGPUAdapter.h:
(WebCore::WebGPUAdapter::options const):
* Modules/webgpu/WebGPUBindGroup.h:
(WebCore::WebGPUBindGroup::bindGroup):
(WebCore::WebGPUBindGroup::bindGroup const): Deleted.
* Modules/webgpu/WebGPUBindGroupDescriptor.cpp:
(WebCore::WebGPUBindGroupDescriptor::tryCreateGPUBindGroupDescriptor const):
* Modules/webgpu/WebGPUBindGroupDescriptor.h:
* Modules/webgpu/WebGPUBindGroupLayout.h:
(WebCore::WebGPUBindGroupLayout::bindGroupLayout const):
* Modules/webgpu/WebGPUBuffer.h:
(WebCore::WebGPUBuffer::buffer):
(WebCore::WebGPUBuffer::buffer const):
* Modules/webgpu/WebGPURenderPassDescriptor.cpp:
(WebCore::WebGPURenderPassDescriptor::tryCreateGPURenderPassDescriptor const):
* Modules/webgpu/WebGPURenderPassEncoder.cpp:
(WebCore::WebGPURenderPassEncoder::setVertexBuffers):
* Modules/webgpu/WebGPUSampler.h:
(WebCore::WebGPUSampler::sampler const):
* Modules/webgpu/WebGPUSwapChain.h:
(WebCore::WebGPUSwapChain::swapChain):
(WebCore::WebGPUSwapChain::swapChain const): Deleted.
* Modules/webgpu/WebGPUTexture.h:
(WebCore::WebGPUTexture::texture):
(WebCore::WebGPUTexture::texture const): Deleted.
* Modules/webgpu/WebGPUTextureView.h:
(WebCore::WebGPUTextureView::texture):
(WebCore::WebGPUTextureView::texture const): Deleted.
* platform/graphics/gpu/GPUBindGroupBinding.h:
* platform/graphics/gpu/GPUBindGroupDescriptor.h:
* platform/graphics/gpu/cocoa/GPUBindGroupMetal.mm:
(WebCore::tryGetResourceAsMTLSamplerState):

Web GPU object creation logic:
* Modules/webgpu/WebGPUCommandEncoder.cpp:
(WebCore::WebGPUBufferCopyView::tryCreateGPUBufferCopyView const):
(WebCore::WebGPUTextureCopyView::tryCreateGPUTextureCopyView const):
(WebCore::WebGPUCommandEncoder::beginRenderPass):
(WebCore::WebGPUCommandEncoder::copyBufferToBuffer):
* Modules/webgpu/WebGPUCommandEncoder.h:
* Modules/webgpu/WebGPUDevice.cpp:
(WebCore::WebGPUDevice::createBuffer const):
(WebCore::WebGPUDevice::createTexture const):
(WebCore::WebGPUDevice::createPipelineLayout const):
(WebCore::WebGPUDevice::createBindGroup const):
(WebCore::WebGPUDevice::createShaderModule const):
(WebCore::WebGPUDevice::createRenderPipeline const):
(WebCore::WebGPUDevice::getQueue const):
* Modules/webgpu/WebGPUDevice.h:
* Modules/webgpu/WebGPUPipelineLayout.cpp:
(WebCore::WebGPUPipelineLayout::create):
(WebCore::WebGPUPipelineLayout::WebGPUPipelineLayout):
* Modules/webgpu/WebGPUPipelineLayout.h:
(WebCore::WebGPUPipelineLayout::pipelineLayout):
* Modules/webgpu/WebGPUPipelineLayoutDescriptor.cpp:
(WebCore::WebGPUPipelineLayoutDescriptor::tryCreateGPUPipelineLayoutDescriptor const):
* Modules/webgpu/WebGPUPipelineLayoutDescriptor.h:
* Modules/webgpu/WebGPUQueue.cpp:
(WebCore::WebGPUQueue::create):
(WebCore::WebGPUQueue::WebGPUQueue):
(WebCore::WebGPUQueue::submit):
* Modules/webgpu/WebGPUQueue.h:
* Modules/webgpu/WebGPUShaderModule.cpp:
(WebCore::WebGPUShaderModule::create):
(WebCore::WebGPUShaderModule::WebGPUShaderModule):
* Modules/webgpu/WebGPUShaderModule.h:
(WebCore::WebGPUShaderModule::module const):
* platform/graphics/gpu/GPUBuffer.h:
* platform/graphics/gpu/GPUDevice.cpp:
(WebCore::GPUDevice::tryCreateBuffer):
(WebCore::GPUDevice::tryCreateTexture const):
(WebCore::GPUDevice::tryCreateShaderModule const):
(WebCore::GPUDevice::tryCreateRenderPipeline const):
(WebCore::GPUDevice::tryGetQueue const):
(WebCore::GPUDevice::createShaderModule const): Deleted.
(WebCore::GPUDevice::createRenderPipeline const): Deleted.
(WebCore::GPUDevice::getQueue const): Deleted.
* platform/graphics/gpu/GPUDevice.h:
* platform/graphics/gpu/GPUPipelineLayout.cpp:
(WebCore::GPUPipelineLayout::create):
(WebCore::GPUPipelineLayout::GPUPipelineLayout):
* platform/graphics/gpu/GPUPipelineLayout.h:
(WebCore::GPUPipelineLayout::bindGroupLayouts const):
* platform/graphics/gpu/GPUPipelineLayoutDescriptor.h:
* platform/graphics/gpu/GPURenderPipeline.h:
* platform/graphics/gpu/GPUShaderModule.h:
* platform/graphics/gpu/cocoa/GPUBufferMetal.mm:
(WebCore::GPUBuffer::tryCreate):
(WebCore::GPUBuffer::GPUBuffer):
(WebCore::GPUBuffer::setSubData):
* platform/graphics/gpu/cocoa/GPUCommandBufferMetal.mm:
(WebCore::GPUCommandBuffer::tryCreate):
* platform/graphics/gpu/cocoa/GPUDeviceMetal.mm:
(WebCore::GPUDevice::tryCreate):
* platform/graphics/gpu/cocoa/GPURenderPipelineMetal.mm:
(WebCore::GPURenderPipeline::tryCreate):
(WebCore::GPURenderPipeline::GPURenderPipeline):
(WebCore::GPURenderPipeline::create): Deleted.
* platform/graphics/gpu/cocoa/GPUShaderModuleMetal.mm:
(WebCore::GPUShaderModule::tryCreate):
(WebCore::GPUShaderModule::create): Deleted.

Add WebGPUPipelineLayoutDescriptor.cpp to project:
* Sources.txt:
* WebCore.xcodeproj/project.pbxproj:

2019-03-27 Shawn Roberts <sroberts@apple.com>

Unreviewed, rolling out r243346.
@@ -45,7 +45,7 @@ class WebGPUAdapter : public RefCounted<WebGPUAdapter> {
using DeviceRequestPromise = DOMPromiseDeferred<IDLInterface<WebGPUDevice>>;
void requestDevice(DeviceRequestPromise&&) const;

Optional<GPURequestAdapterOptions> options() const { return m_options; }
const Optional<GPURequestAdapterOptions>& options() const { return m_options; }

private:
explicit WebGPUAdapter(Optional<GPURequestAdapterOptions>&&);
@@ -37,7 +37,7 @@ class WebGPUBindGroup : public RefCounted<WebGPUBindGroup> {
public:
static Ref<WebGPUBindGroup> create(RefPtr<GPUBindGroup>&&);

GPUBindGroup* bindGroup() const { return m_bindGroup.get(); }
GPUBindGroup* bindGroup() { return m_bindGroup.get(); }

private:
explicit WebGPUBindGroup(RefPtr<GPUBindGroup>&&);
@@ -103,18 +103,18 @@ Optional<GPUBindGroupDescriptor> WebGPUBindGroupDescriptor::tryCreateGPUBindGrou
if (!texture)
return WTF::nullopt;

return static_cast<GPUBindingResource>(texture.releaseNonNull());
return static_cast<GPUBindingResource>(makeRef(*texture));
}, [&layoutBinding, functionName] (WebGPUBufferBinding bufferBinding) -> Optional<GPUBindingResource> {
if (!bufferBinding.buffer)
return WTF::nullopt;
auto buffer = bufferBinding.buffer->buffer();
if (!buffer)
return WTF::nullopt;

if (!validateBufferBindingType(buffer.get(), layoutBinding, functionName))
if (!validateBufferBindingType(buffer, layoutBinding, functionName))
return WTF::nullopt;

return static_cast<GPUBindingResource>(GPUBufferBinding { buffer.releaseNonNull(), bufferBinding.offset, bufferBinding.size });
return static_cast<GPUBindingResource>(GPUBufferBinding { makeRef(*buffer), bufferBinding.offset, bufferBinding.size });
});

auto bindingResource = WTF::visit(bindingResourceVisitor, binding.resource);
@@ -126,7 +126,7 @@ Optional<GPUBindGroupDescriptor> WebGPUBindGroupDescriptor::tryCreateGPUBindGrou
bindGroupBindings.uncheckedAppend(GPUBindGroupBinding { binding.binding, WTFMove(bindingResource.value()) });
}

return GPUBindGroupDescriptor { layout->bindGroupLayout().releaseNonNull(), WTFMove(bindGroupBindings) };
return GPUBindGroupDescriptor { makeRef(*layout->bindGroupLayout()), WTFMove(bindGroupBindings) };
}

} // namespace WebCore
@@ -40,7 +40,7 @@ struct GPUBindGroupDescriptor;
struct WebGPUBindGroupDescriptor {
Optional<GPUBindGroupDescriptor> tryCreateGPUBindGroupDescriptor() const;

RefPtr<WebGPUBindGroupLayout> layout;
RefPtr<const WebGPUBindGroupLayout> layout;
Vector<WebGPUBindGroupBinding> bindings;
};

@@ -28,7 +28,6 @@
#if ENABLE(WEBGPU)

#include "GPUBindGroupLayout.h"

#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>

@@ -38,7 +37,7 @@ class WebGPUBindGroupLayout : public RefCounted<WebGPUBindGroupLayout> {
public:
static Ref<WebGPUBindGroupLayout> create(RefPtr<GPUBindGroupLayout>&&);

RefPtr<GPUBindGroupLayout> bindGroupLayout() const { return m_bindGroupLayout; }
const GPUBindGroupLayout* bindGroupLayout() const { return m_bindGroupLayout.get(); }

private:
explicit WebGPUBindGroupLayout(RefPtr<GPUBindGroupLayout>&&);
@@ -45,7 +45,8 @@ class WebGPUBuffer : public RefCounted<WebGPUBuffer> {
public:
static Ref<WebGPUBuffer> create(RefPtr<GPUBuffer>&&);

RefPtr<GPUBuffer> buffer() const { return m_buffer; }
GPUBuffer* buffer() { return m_buffer.get(); }
const GPUBuffer* buffer() const { return m_buffer.get(); }

void setSubData(unsigned long long, const JSC::ArrayBuffer&);
using BufferMappingPromise = DOMPromiseDeferred<IDLInterface<JSC::ArrayBuffer>>;
@@ -47,7 +47,7 @@ Optional<GPUBufferCopyView> WebGPUBufferCopyView::tryCreateGPUBufferCopyView() c

// FIXME: Add Web GPU validation.

return GPUBufferCopyView { buffer->buffer().releaseNonNull(), *this };
return GPUBufferCopyView { makeRef(*buffer->buffer()), *this };
}

Optional<GPUTextureCopyView> WebGPUTextureCopyView::tryCreateGPUTextureCopyView() const
@@ -59,7 +59,7 @@ Optional<GPUTextureCopyView> WebGPUTextureCopyView::tryCreateGPUTextureCopyView(

// FIXME: Add Web GPU validation.

return GPUTextureCopyView { texture->texture().releaseNonNull(), *this };
return GPUTextureCopyView { makeRef(*texture->texture()), *this };
}

Ref<WebGPUCommandEncoder> WebGPUCommandEncoder::create(RefPtr<GPUCommandBuffer>&& buffer)
@@ -72,7 +72,7 @@ WebGPUCommandEncoder::WebGPUCommandEncoder(RefPtr<GPUCommandBuffer>&& buffer)
{
}

Ref<WebGPURenderPassEncoder> WebGPUCommandEncoder::beginRenderPass(WebGPURenderPassDescriptor&& descriptor)
Ref<WebGPURenderPassEncoder> WebGPUCommandEncoder::beginRenderPass(const WebGPURenderPassDescriptor& descriptor)
{
if (!m_commandBuffer) {
LOG(WebGPU, "WebGPUCommandEncoder::beginRenderPass(): Invalid operation!");
@@ -86,7 +86,7 @@ Ref<WebGPURenderPassEncoder> WebGPUCommandEncoder::beginRenderPass(WebGPURenderP
return WebGPURenderPassEncoder::create(*this, WTFMove(encoder));
}

void WebGPUCommandEncoder::copyBufferToBuffer(const WebGPUBuffer& src, unsigned long srcOffset, const WebGPUBuffer& dst, unsigned long dstOffset, unsigned long size)
void WebGPUCommandEncoder::copyBufferToBuffer(WebGPUBuffer& src, unsigned long srcOffset, WebGPUBuffer& dst, unsigned long dstOffset, unsigned long size)
{
if (!m_commandBuffer) {
LOG(WebGPU, "WebGPUCommandEncoder::copyBufferToBuffer(): Invalid operation!");
@@ -57,8 +57,8 @@ 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);
Ref<WebGPURenderPassEncoder> beginRenderPass(const WebGPURenderPassDescriptor&);
void copyBufferToBuffer(WebGPUBuffer&, unsigned long srcOffset, 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&);
@@ -76,15 +76,15 @@ WebGPUDevice::WebGPUDevice(Ref<const WebGPUAdapter>&& adapter, Ref<GPUDevice>&&
{
}

Ref<WebGPUBuffer> WebGPUDevice::createBuffer(GPUBufferDescriptor&& descriptor) const
Ref<WebGPUBuffer> WebGPUDevice::createBuffer(const GPUBufferDescriptor& descriptor) const
{
auto buffer = m_device->tryCreateBuffer(WTFMove(descriptor));
auto buffer = m_device->tryCreateBuffer(descriptor);
return WebGPUBuffer::create(WTFMove(buffer));
}

Ref<WebGPUTexture> WebGPUDevice::createTexture(GPUTextureDescriptor&& descriptor) const
Ref<WebGPUTexture> WebGPUDevice::createTexture(const GPUTextureDescriptor& descriptor) const
{
auto texture = m_device->tryCreateTexture(WTFMove(descriptor));
auto texture = m_device->tryCreateTexture(descriptor);
return WebGPUTexture::create(WTFMove(texture));
}

@@ -100,16 +100,17 @@ Ref<WebGPUBindGroupLayout> WebGPUDevice::createBindGroupLayout(const GPUBindGrou
return WebGPUBindGroupLayout::create(WTFMove(layout));
}

Ref<WebGPUPipelineLayout> WebGPUDevice::createPipelineLayout(WebGPUPipelineLayoutDescriptor&& descriptor) const
Ref<WebGPUPipelineLayout> WebGPUDevice::createPipelineLayout(const WebGPUPipelineLayoutDescriptor& descriptor) const
{
auto bindGroupLayouts = descriptor.bindGroupLayouts.map([] (const auto& layout) -> RefPtr<const GPUBindGroupLayout> {
return layout->bindGroupLayout();
});
auto layout = m_device->createPipelineLayout(GPUPipelineLayoutDescriptor { WTFMove(bindGroupLayouts) });
auto gpuDescriptor = descriptor.tryCreateGPUPipelineLayoutDescriptor();
if (!gpuDescriptor)
return WebGPUPipelineLayout::create(nullptr);

auto layout = m_device->createPipelineLayout(WTFMove(*gpuDescriptor));
return WebGPUPipelineLayout::create(WTFMove(layout));
}

Ref<WebGPUBindGroup> WebGPUDevice::createBindGroup(WebGPUBindGroupDescriptor&& descriptor) const
Ref<WebGPUBindGroup> WebGPUDevice::createBindGroup(const WebGPUBindGroupDescriptor& descriptor) const
{
auto gpuDescriptor = descriptor.tryCreateGPUBindGroupDescriptor();
if (!gpuDescriptor)
@@ -119,12 +120,11 @@ Ref<WebGPUBindGroup> WebGPUDevice::createBindGroup(WebGPUBindGroupDescriptor&& d
return WebGPUBindGroup::create(WTFMove(bindGroup));
}

RefPtr<WebGPUShaderModule> WebGPUDevice::createShaderModule(WebGPUShaderModuleDescriptor&& descriptor) const
Ref<WebGPUShaderModule> WebGPUDevice::createShaderModule(const WebGPUShaderModuleDescriptor& descriptor) const
{
// FIXME: What can be validated here?
if (auto module = m_device->createShaderModule(GPUShaderModuleDescriptor { descriptor.code, descriptor.isWHLSL }))
return WebGPUShaderModule::create(module.releaseNonNull());
return nullptr;
auto module = m_device->tryCreateShaderModule(GPUShaderModuleDescriptor { descriptor.code, descriptor.isWHLSL });
return WebGPUShaderModule::create(WTFMove(module));
}

Ref<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(const WebGPURenderPipelineDescriptor& descriptor) const
@@ -133,7 +133,7 @@ Ref<WebGPURenderPipeline> WebGPUDevice::createRenderPipeline(const WebGPURenderP
if (!gpuDescriptor)
return WebGPURenderPipeline::create(nullptr);

auto pipeline = m_device->createRenderPipeline(WTFMove(*gpuDescriptor));
auto pipeline = m_device->tryCreateRenderPipeline(*gpuDescriptor);
return WebGPURenderPipeline::create(WTFMove(pipeline));
}

@@ -157,12 +157,12 @@ Ref<WebGPUSwapChain> WebGPUDevice::createSwapChain(const WebGPUSwapChainDescript
return newSwapChain;
}

RefPtr<WebGPUQueue> WebGPUDevice::getQueue() const
Ref<WebGPUQueue> WebGPUDevice::getQueue() const
{
if (!m_queue)
m_queue = WebGPUQueue::create(m_device->getQueue());
m_queue = WebGPUQueue::create(m_device->tryGetQueue());

return m_queue;
return makeRef(*m_queue.get());
}

} // namespace WebCore

0 comments on commit b5b66c4

Please sign in to comment.