Diff
Modified: trunk/Source/WebGPU/ChangeLog (290189 => 290190)
--- trunk/Source/WebGPU/ChangeLog 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/ChangeLog 2022-02-19 01:03:29 UTC (rev 290190)
@@ -1,3 +1,79 @@
+2022-02-18 Myles C. Maxfield <[email protected]>
+
+ [WebGPU] Any object-creation function that takes a descriptor can fail
+ https://bugs.webkit.org/show_bug.cgi?id=236855
+
+ Reviewed by Dean Jackson.
+
+ Generally, we view allocation failure as catastrophic, and crash. Because of that, I originally
+ made these methods return Refs, because I expected the failure case to cause intentional crashes
+ rather than return nullptr.
+
+ However, descriptors the shared header have a nextInChain pointer, which allows callers to pass
+ in extra extension-specific structs, as a linked list. If the WebGPU implementation sees one of
+ these extra structs that it doesn't know what to do with, it has to fail. That means that it's
+ possible to fail in a way other than an allocation failure, which means these functions have to
+ return RefPtrs instead of Refs.
+
+ * WebGPU/Adapter.h:
+ * WebGPU/Adapter.mm:
+ (WebGPU::Adapter::requestDevice):
+ (wgpuAdapterRequestDevice):
+ * WebGPU/CommandEncoder.h:
+ * WebGPU/CommandEncoder.mm:
+ (WebGPU::CommandEncoder::beginComputePass):
+ (WebGPU::CommandEncoder::beginRenderPass):
+ (WebGPU::CommandEncoder::finish):
+ (wgpuCommandEncoderBeginComputePass):
+ (wgpuCommandEncoderBeginRenderPass):
+ (wgpuCommandEncoderFinish):
+ * WebGPU/Device.h:
+ * WebGPU/Device.mm:
+ (WebGPU::Device::createBindGroup):
+ (WebGPU::Device::createBindGroupLayout):
+ (WebGPU::Device::createBuffer):
+ (WebGPU::Device::createCommandEncoder):
+ (WebGPU::Device::createComputePipeline):
+ (WebGPU::Device::createComputePipelineAsync):
+ (WebGPU::Device::createPipelineLayout):
+ (WebGPU::Device::createQuerySet):
+ (WebGPU::Device::createRenderBundleEncoder):
+ (WebGPU::Device::createRenderPipeline):
+ (WebGPU::Device::createRenderPipelineAsync):
+ (WebGPU::Device::createSampler):
+ (WebGPU::Device::createShaderModule):
+ (WebGPU::Device::createSwapChain):
+ (WebGPU::Device::createTexture):
+ (WebGPU::Device::getQueue):
+ (wgpuDeviceCreateBindGroup):
+ (wgpuDeviceCreateBindGroupLayout):
+ (wgpuDeviceCreateBuffer):
+ (wgpuDeviceCreateCommandEncoder):
+ (wgpuDeviceCreateComputePipeline):
+ (wgpuDeviceCreateComputePipelineAsync):
+ (wgpuDeviceCreatePipelineLayout):
+ (wgpuDeviceCreateQuerySet):
+ (wgpuDeviceCreateRenderBundleEncoder):
+ (wgpuDeviceCreateRenderPipeline):
+ (wgpuDeviceCreateRenderPipelineAsync):
+ (wgpuDeviceCreateSampler):
+ (wgpuDeviceCreateShaderModule):
+ (wgpuDeviceCreateSwapChain):
+ (wgpuDeviceCreateTexture):
+ (wgpuDeviceGetQueue):
+ * WebGPU/Instance.h:
+ * WebGPU/Instance.mm:
+ (WebGPU::Instance::createSurface):
+ (wgpuInstanceCreateSurface):
+ * WebGPU/RenderBundleEncoder.h:
+ * WebGPU/RenderBundleEncoder.mm:
+ (WebGPU::RenderBundleEncoder::finish):
+ (wgpuRenderBundleEncoderFinish):
+ * WebGPU/Texture.h:
+ * WebGPU/Texture.mm:
+ (WebGPU::Texture::createView):
+ (wgpuTextureCreateView):
+
2022-02-18 Robert Jenner <[email protected]>
Unreviewed, reverting r290149.
Modified: trunk/Source/WebGPU/WebGPU/Adapter.h (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Adapter.h 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Adapter.h 2022-02-19 01:03:29 UTC (rev 290190)
@@ -30,6 +30,7 @@
#import <wtf/Function.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
+#import <wtf/RefPtr.h>
namespace WebGPU {
@@ -49,7 +50,7 @@
bool getLimits(WGPUSupportedLimits*);
void getProperties(WGPUAdapterProperties*);
bool hasFeature(WGPUFeatureName);
- void requestDevice(const WGPUDeviceDescriptor*, WTF::Function<void(WGPURequestDeviceStatus, Ref<Device>&&, const char*)>&& callback);
+ void requestDevice(const WGPUDeviceDescriptor*, WTF::Function<void(WGPURequestDeviceStatus, RefPtr<Device>&&, const char*)>&& callback);
private:
Adapter();
Modified: trunk/Source/WebGPU/WebGPU/Adapter.mm (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-02-19 01:03:29 UTC (rev 290190)
@@ -59,7 +59,7 @@
return false;
}
-void Adapter::requestDevice(const WGPUDeviceDescriptor* descriptor, WTF::Function<void(WGPURequestDeviceStatus, Ref<Device>&&, const char*)>&& callback)
+void Adapter::requestDevice(const WGPUDeviceDescriptor* descriptor, WTF::Function<void(WGPURequestDeviceStatus, RefPtr<Device>&&, const char*)>&& callback)
{
UNUSED_PARAM(descriptor);
UNUSED_PARAM(callback);
@@ -94,7 +94,7 @@
void wgpuAdapterRequestDevice(WGPUAdapter adapter, const WGPUDeviceDescriptor* descriptor, WGPURequestDeviceCallback callback, void* userdata)
{
- adapter->adapter->requestDevice(descriptor, [callback, userdata] (WGPURequestDeviceStatus status, Ref<WebGPU::Device>&& device, const char* message) {
- callback(status, new WGPUDeviceImpl { WTFMove(device) }, message, userdata);
+ adapter->adapter->requestDevice(descriptor, [callback, userdata] (WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, const char* message) {
+ callback(status, device ? new WGPUDeviceImpl { device.releaseNonNull() } : nullptr, message, userdata);
});
}
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.h (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.h 2022-02-19 01:03:29 UTC (rev 290190)
@@ -29,6 +29,7 @@
#import <wtf/FastMalloc.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
+#import <wtf/RefPtr.h>
namespace WebGPU {
@@ -48,14 +49,14 @@
~CommandEncoder();
- Ref<ComputePassEncoder> beginComputePass(const WGPUComputePassDescriptor*);
- Ref<RenderPassEncoder> beginRenderPass(const WGPURenderPassDescriptor*);
+ RefPtr<ComputePassEncoder> beginComputePass(const WGPUComputePassDescriptor*);
+ RefPtr<RenderPassEncoder> beginRenderPass(const WGPURenderPassDescriptor*);
void copyBufferToBuffer(const Buffer& source, uint64_t sourceOffset, const Buffer& destination, uint64_t destinationOffset, uint64_t size);
void copyBufferToTexture(const WGPUImageCopyBuffer* source, const WGPUImageCopyTexture* destination, const WGPUExtent3D* copySize);
void copyTextureToBuffer(const WGPUImageCopyTexture* source, const WGPUImageCopyBuffer* destination, const WGPUExtent3D* copySize);
void copyTextureToTexture(const WGPUImageCopyTexture* source, const WGPUImageCopyTexture* destination, const WGPUExtent3D* copySize);
void clearBuffer(const Buffer&, uint64_t offset, uint64_t size);
- Ref<CommandBuffer> finish(const WGPUCommandBufferDescriptor*);
+ RefPtr<CommandBuffer> finish(const WGPUCommandBufferDescriptor*);
void insertDebugMarker(const char* markerLabel);
void popDebugGroup();
void pushDebugGroup(const char* groupLabel);
Modified: trunk/Source/WebGPU/WebGPU/CommandEncoder.mm (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/CommandEncoder.mm 2022-02-19 01:03:29 UTC (rev 290190)
@@ -39,13 +39,13 @@
CommandEncoder::~CommandEncoder() = default;
-Ref<ComputePassEncoder> CommandEncoder::beginComputePass(const WGPUComputePassDescriptor* descriptor)
+RefPtr<ComputePassEncoder> CommandEncoder::beginComputePass(const WGPUComputePassDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return ComputePassEncoder::create();
}
-Ref<RenderPassEncoder> CommandEncoder::beginRenderPass(const WGPURenderPassDescriptor* descriptor)
+RefPtr<RenderPassEncoder> CommandEncoder::beginRenderPass(const WGPURenderPassDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return RenderPassEncoder::create();
@@ -88,7 +88,7 @@
UNUSED_PARAM(size);
}
-Ref<CommandBuffer> CommandEncoder::finish(const WGPUCommandBufferDescriptor* descriptor)
+RefPtr<CommandBuffer> CommandEncoder::finish(const WGPUCommandBufferDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return CommandBuffer::create();
@@ -137,12 +137,14 @@
WGPUComputePassEncoder wgpuCommandEncoderBeginComputePass(WGPUCommandEncoder commandEncoder, const WGPUComputePassDescriptor* descriptor)
{
- return new WGPUComputePassEncoderImpl { commandEncoder->commandEncoder->beginComputePass(descriptor) };
+ auto result = commandEncoder->commandEncoder->beginComputePass(descriptor);
+ return result ? new WGPUComputePassEncoderImpl { result.releaseNonNull() } : nullptr;
}
WGPURenderPassEncoder wgpuCommandEncoderBeginRenderPass(WGPUCommandEncoder commandEncoder, const WGPURenderPassDescriptor* descriptor)
{
- return new WGPURenderPassEncoderImpl { commandEncoder->commandEncoder->beginRenderPass(descriptor) };
+ auto result = commandEncoder->commandEncoder->beginRenderPass(descriptor);
+ return result ? new WGPURenderPassEncoderImpl { result.releaseNonNull() } : nullptr;
}
void wgpuCommandEncoderCopyBufferToBuffer(WGPUCommandEncoder commandEncoder, WGPUBuffer source, uint64_t sourceOffset, WGPUBuffer destination, uint64_t destinationOffset, uint64_t size)
@@ -172,7 +174,8 @@
WGPUCommandBuffer wgpuCommandEncoderFinish(WGPUCommandEncoder commandEncoder, const WGPUCommandBufferDescriptor* descriptor)
{
- return new WGPUCommandBufferImpl { commandEncoder->commandEncoder->finish(descriptor) };
+ auto result = commandEncoder->commandEncoder->finish(descriptor);
+ return result ? new WGPUCommandBufferImpl { result.releaseNonNull() } : nullptr;
}
void wgpuCommandEncoderInsertDebugMarker(WGPUCommandEncoder commandEncoder, const char* markerLabel)
Modified: trunk/Source/WebGPU/WebGPU/Device.h (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Device.h 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Device.h 2022-02-19 01:03:29 UTC (rev 290190)
@@ -30,6 +30,7 @@
#import <wtf/Function.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
+#import <wtf/RefPtr.h>
namespace WebGPU {
@@ -59,25 +60,25 @@
~Device();
- Ref<BindGroup> createBindGroup(const WGPUBindGroupDescriptor*);
- Ref<BindGroupLayout> createBindGroupLayout(const WGPUBindGroupLayoutDescriptor*);
- Ref<Buffer> createBuffer(const WGPUBufferDescriptor*);
- Ref<CommandEncoder> createCommandEncoder(const WGPUCommandEncoderDescriptor*);
- Ref<ComputePipeline> createComputePipeline(const WGPUComputePipelineDescriptor*);
- void createComputePipelineAsync(const WGPUComputePipelineDescriptor*, WTF::Function<void(WGPUCreatePipelineAsyncStatus, Ref<ComputePipeline>&&, const char* message)>&& callback);
- Ref<PipelineLayout> createPipelineLayout(const WGPUPipelineLayoutDescriptor*);
- Ref<QuerySet> createQuerySet(const WGPUQuerySetDescriptor*);
- Ref<RenderBundleEncoder> createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor*);
- Ref<RenderPipeline> createRenderPipeline(const WGPURenderPipelineDescriptor*);
- void createRenderPipelineAsync(const WGPURenderPipelineDescriptor*, WTF::Function<void(WGPUCreatePipelineAsyncStatus, Ref<RenderPipeline>&&, const char* message)>&& callback);
- Ref<Sampler> createSampler(const WGPUSamplerDescriptor*);
- Ref<ShaderModule> createShaderModule(const WGPUShaderModuleDescriptor*);
- Ref<SwapChain> createSwapChain(const Surface&, const WGPUSwapChainDescriptor*);
- Ref<Texture> createTexture(const WGPUTextureDescriptor*);
+ RefPtr<BindGroup> createBindGroup(const WGPUBindGroupDescriptor*);
+ RefPtr<BindGroupLayout> createBindGroupLayout(const WGPUBindGroupLayoutDescriptor*);
+ RefPtr<Buffer> createBuffer(const WGPUBufferDescriptor*);
+ RefPtr<CommandEncoder> createCommandEncoder(const WGPUCommandEncoderDescriptor*);
+ RefPtr<ComputePipeline> createComputePipeline(const WGPUComputePipelineDescriptor*);
+ void createComputePipelineAsync(const WGPUComputePipelineDescriptor*, WTF::Function<void(WGPUCreatePipelineAsyncStatus, RefPtr<ComputePipeline>&&, const char* message)>&& callback);
+ RefPtr<PipelineLayout> createPipelineLayout(const WGPUPipelineLayoutDescriptor*);
+ RefPtr<QuerySet> createQuerySet(const WGPUQuerySetDescriptor*);
+ RefPtr<RenderBundleEncoder> createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor*);
+ RefPtr<RenderPipeline> createRenderPipeline(const WGPURenderPipelineDescriptor*);
+ void createRenderPipelineAsync(const WGPURenderPipelineDescriptor*, WTF::Function<void(WGPUCreatePipelineAsyncStatus, RefPtr<RenderPipeline>&&, const char* message)>&& callback);
+ RefPtr<Sampler> createSampler(const WGPUSamplerDescriptor*);
+ RefPtr<ShaderModule> createShaderModule(const WGPUShaderModuleDescriptor*);
+ RefPtr<SwapChain> createSwapChain(const Surface&, const WGPUSwapChainDescriptor*);
+ RefPtr<Texture> createTexture(const WGPUTextureDescriptor*);
void destroy();
size_t enumerateFeatures(WGPUFeatureName* features);
bool getLimits(WGPUSupportedLimits*);
- Ref<Queue> getQueue();
+ RefPtr<Queue> getQueue();
bool hasFeature(WGPUFeatureName);
bool popErrorScope(WTF::Function<void(WGPUErrorType, const char*)>&& callback);
void pushErrorScope(WGPUErrorFilter);
Modified: trunk/Source/WebGPU/WebGPU/Device.mm (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Device.mm 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Device.mm 2022-02-19 01:03:29 UTC (rev 290190)
@@ -50,85 +50,85 @@
Device::~Device() = default;
-Ref<BindGroup> Device::createBindGroup(const WGPUBindGroupDescriptor* descriptor)
+RefPtr<BindGroup> Device::createBindGroup(const WGPUBindGroupDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return BindGroup::create();
}
-Ref<BindGroupLayout> Device::createBindGroupLayout(const WGPUBindGroupLayoutDescriptor* descriptor)
+RefPtr<BindGroupLayout> Device::createBindGroupLayout(const WGPUBindGroupLayoutDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return BindGroupLayout::create();
}
-Ref<Buffer> Device::createBuffer(const WGPUBufferDescriptor* descriptor)
+RefPtr<Buffer> Device::createBuffer(const WGPUBufferDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return Buffer::create();
}
-Ref<CommandEncoder> Device::createCommandEncoder(const WGPUCommandEncoderDescriptor* descriptor)
+RefPtr<CommandEncoder> Device::createCommandEncoder(const WGPUCommandEncoderDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return CommandEncoder::create();
}
-Ref<ComputePipeline> Device::createComputePipeline(const WGPUComputePipelineDescriptor* descriptor)
+RefPtr<ComputePipeline> Device::createComputePipeline(const WGPUComputePipelineDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return ComputePipeline::create();
}
-void Device::createComputePipelineAsync(const WGPUComputePipelineDescriptor* descriptor, WTF::Function<void(WGPUCreatePipelineAsyncStatus, Ref<ComputePipeline>&&, const char* message)>&& callback)
+void Device::createComputePipelineAsync(const WGPUComputePipelineDescriptor* descriptor, WTF::Function<void(WGPUCreatePipelineAsyncStatus, RefPtr<ComputePipeline>&&, const char* message)>&& callback)
{
UNUSED_PARAM(descriptor);
UNUSED_PARAM(callback);
}
-Ref<PipelineLayout> Device::createPipelineLayout(const WGPUPipelineLayoutDescriptor* descriptor)
+RefPtr<PipelineLayout> Device::createPipelineLayout(const WGPUPipelineLayoutDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return PipelineLayout::create();
}
-Ref<QuerySet> Device::createQuerySet(const WGPUQuerySetDescriptor* descriptor)
+RefPtr<QuerySet> Device::createQuerySet(const WGPUQuerySetDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return QuerySet::create();
}
-Ref<RenderBundleEncoder> Device::createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor* descriptor)
+RefPtr<RenderBundleEncoder> Device::createRenderBundleEncoder(const WGPURenderBundleEncoderDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return RenderBundleEncoder::create();
}
-Ref<RenderPipeline> Device::createRenderPipeline(const WGPURenderPipelineDescriptor* descriptor)
+RefPtr<RenderPipeline> Device::createRenderPipeline(const WGPURenderPipelineDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return RenderPipeline::create();
}
-void Device::createRenderPipelineAsync(const WGPURenderPipelineDescriptor* descriptor, WTF::Function<void(WGPUCreatePipelineAsyncStatus, Ref<RenderPipeline>&&, const char* message)>&& callback)
+void Device::createRenderPipelineAsync(const WGPURenderPipelineDescriptor* descriptor, WTF::Function<void(WGPUCreatePipelineAsyncStatus, RefPtr<RenderPipeline>&&, const char* message)>&& callback)
{
UNUSED_PARAM(descriptor);
UNUSED_PARAM(callback);
}
-Ref<Sampler> Device::createSampler(const WGPUSamplerDescriptor* descriptor)
+RefPtr<Sampler> Device::createSampler(const WGPUSamplerDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return Sampler::create();
}
-Ref<ShaderModule> Device::createShaderModule(const WGPUShaderModuleDescriptor* descriptor)
+RefPtr<ShaderModule> Device::createShaderModule(const WGPUShaderModuleDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return ShaderModule::create();
}
-Ref<SwapChain> Device::createSwapChain(const Surface& surface, const WGPUSwapChainDescriptor* descriptor)
+RefPtr<SwapChain> Device::createSwapChain(const Surface& surface, const WGPUSwapChainDescriptor* descriptor)
{
UNUSED_PARAM(surface);
UNUSED_PARAM(descriptor);
@@ -135,7 +135,7 @@
return SwapChain::create();
}
-Ref<Texture> Device::createTexture(const WGPUTextureDescriptor* descriptor)
+RefPtr<Texture> Device::createTexture(const WGPUTextureDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return Texture::create();
@@ -157,7 +157,7 @@
return false;
}
-Ref<Queue> Device::getQueue()
+RefPtr<Queue> Device::getQueue()
{
return Queue::create();
}
@@ -203,81 +203,94 @@
WGPUBindGroup wgpuDeviceCreateBindGroup(WGPUDevice device, const WGPUBindGroupDescriptor* descriptor)
{
- return new WGPUBindGroupImpl { device->device->createBindGroup(descriptor) };
+ auto result = device->device->createBindGroup(descriptor);
+ return result ? new WGPUBindGroupImpl { result.releaseNonNull() } : nullptr;
}
WGPUBindGroupLayout wgpuDeviceCreateBindGroupLayout(WGPUDevice device, const WGPUBindGroupLayoutDescriptor* descriptor)
{
- return new WGPUBindGroupLayoutImpl { device->device->createBindGroupLayout(descriptor) };
+ auto result = device->device->createBindGroupLayout(descriptor);
+ return result ? new WGPUBindGroupLayoutImpl { result.releaseNonNull() } : nullptr;
}
WGPUBuffer wgpuDeviceCreateBuffer(WGPUDevice device, const WGPUBufferDescriptor* descriptor)
{
- return new WGPUBufferImpl { device->device->createBuffer(descriptor) };
+ auto result = device->device->createBuffer(descriptor);
+ return result ? new WGPUBufferImpl { result.releaseNonNull() } : nullptr;
}
WGPUCommandEncoder wgpuDeviceCreateCommandEncoder(WGPUDevice device, const WGPUCommandEncoderDescriptor* descriptor)
{
- return new WGPUCommandEncoderImpl { device->device->createCommandEncoder(descriptor) };
+ auto result = device->device->createCommandEncoder(descriptor);
+ return result ? new WGPUCommandEncoderImpl { result.releaseNonNull() } : nullptr;
}
WGPUComputePipeline wgpuDeviceCreateComputePipeline(WGPUDevice device, const WGPUComputePipelineDescriptor* descriptor)
{
- return new WGPUComputePipelineImpl { device->device->createComputePipeline(descriptor) };
+ auto result = device->device->createComputePipeline(descriptor);
+ return result ? new WGPUComputePipelineImpl { result.releaseNonNull() } : nullptr;
}
void wgpuDeviceCreateComputePipelineAsync(WGPUDevice device, const WGPUComputePipelineDescriptor* descriptor, WGPUCreateComputePipelineAsyncCallback callback, void* userdata)
{
- device->device->createComputePipelineAsync(descriptor, [callback, userdata] (WGPUCreatePipelineAsyncStatus status, Ref<WebGPU::ComputePipeline>&& pipeline, const char* message) {
- callback(status, new WGPUComputePipelineImpl { WTFMove(pipeline) }, message, userdata);
+ device->device->createComputePipelineAsync(descriptor, [callback, userdata] (WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::ComputePipeline>&& pipeline, const char* message) {
+ callback(status, pipeline ? new WGPUComputePipelineImpl { pipeline.releaseNonNull() } : nullptr, message, userdata);
});
}
WGPUPipelineLayout wgpuDeviceCreatePipelineLayout(WGPUDevice device, const WGPUPipelineLayoutDescriptor* descriptor)
{
- return new WGPUPipelineLayoutImpl { device->device->createPipelineLayout(descriptor) };
+ auto result = device->device->createPipelineLayout(descriptor);
+ return result ? new WGPUPipelineLayoutImpl { result.releaseNonNull() } : nullptr;
}
WGPUQuerySet wgpuDeviceCreateQuerySet(WGPUDevice device, const WGPUQuerySetDescriptor* descriptor)
{
- return new WGPUQuerySetImpl { device->device->createQuerySet(descriptor) };
+ auto result = device->device->createQuerySet(descriptor);
+ return result ? new WGPUQuerySetImpl { result.releaseNonNull() } : nullptr;
}
WGPURenderBundleEncoder wgpuDeviceCreateRenderBundleEncoder(WGPUDevice device, const WGPURenderBundleEncoderDescriptor* descriptor)
{
- return new WGPURenderBundleEncoderImpl { device->device->createRenderBundleEncoder(descriptor) };
+ auto result = device->device->createRenderBundleEncoder(descriptor);
+ return result ? new WGPURenderBundleEncoderImpl { result.releaseNonNull() } : nullptr;
}
WGPURenderPipeline wgpuDeviceCreateRenderPipeline(WGPUDevice device, const WGPURenderPipelineDescriptor* descriptor)
{
- return new WGPURenderPipelineImpl { device->device->createRenderPipeline(descriptor) };
+ auto result = device->device->createRenderPipeline(descriptor);
+ return result ? new WGPURenderPipelineImpl { result.releaseNonNull() } : nullptr;
}
void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, const WGPURenderPipelineDescriptor* descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata)
{
- device->device->createRenderPipelineAsync(descriptor, [callback, userdata] (WGPUCreatePipelineAsyncStatus status, Ref<WebGPU::RenderPipeline>&& pipeline, const char* message) {
- callback(status, new WGPURenderPipelineImpl { WTFMove(pipeline) }, message, userdata);
+ device->device->createRenderPipelineAsync(descriptor, [callback, userdata] (WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::RenderPipeline>&& pipeline, const char* message) {
+ callback(status, pipeline ? new WGPURenderPipelineImpl { pipeline.releaseNonNull() } : nullptr, message, userdata);
});
}
WGPUSampler wgpuDeviceCreateSampler(WGPUDevice device, const WGPUSamplerDescriptor* descriptor)
{
- return new WGPUSamplerImpl { device->device->createSampler(descriptor) };
+ auto result = device->device->createSampler(descriptor);
+ return result ? new WGPUSamplerImpl { result.releaseNonNull() } : nullptr;
}
WGPUShaderModule wgpuDeviceCreateShaderModule(WGPUDevice device, const WGPUShaderModuleDescriptor* descriptor)
{
- return new WGPUShaderModuleImpl { device->device->createShaderModule(descriptor) };
+ auto result = device->device->createShaderModule(descriptor);
+ return result ? new WGPUShaderModuleImpl { result.releaseNonNull() } : nullptr;
}
WGPUSwapChain wgpuDeviceCreateSwapChain(WGPUDevice device, WGPUSurface surface, const WGPUSwapChainDescriptor* descriptor)
{
- return new WGPUSwapChainImpl { device->device->createSwapChain(surface->surface, descriptor) };
+ auto result = device->device->createSwapChain(surface->surface, descriptor);
+ return result ? new WGPUSwapChainImpl { result.releaseNonNull() } : nullptr;
}
WGPUTexture wgpuDeviceCreateTexture(WGPUDevice device, const WGPUTextureDescriptor* descriptor)
{
- return new WGPUTextureImpl { device->device->createTexture(descriptor) };
+ auto result = device->device->createTexture(descriptor);
+ return result ? new WGPUTextureImpl { result.releaseNonNull() } : nullptr;
}
void wgpuDeviceDestroy(WGPUDevice device)
@@ -297,7 +310,8 @@
WGPUQueue wgpuDeviceGetQueue(WGPUDevice device)
{
- return new WGPUQueueImpl { device->device->getQueue() };
+ auto result = device->device->getQueue();
+ return result ? new WGPUQueueImpl { result.releaseNonNull() } : nullptr;
}
bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName feature)
Modified: trunk/Source/WebGPU/WebGPU/Instance.h (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Instance.h 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Instance.h 2022-02-19 01:03:29 UTC (rev 290190)
@@ -30,6 +30,7 @@
#import <wtf/Function.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
+#import <wtf/RefPtr.h>
namespace WebGPU {
@@ -46,7 +47,7 @@
~Instance();
- Ref<Surface> createSurface(const WGPUSurfaceDescriptor*);
+ RefPtr<Surface> createSurface(const WGPUSurfaceDescriptor*);
void processEvents();
void requestAdapter(const WGPURequestAdapterOptions*, WTF::Function<void(WGPURequestAdapterStatus, Ref<Adapter>&&, const char*)>&& callback);
Modified: trunk/Source/WebGPU/WebGPU/Instance.mm (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Instance.mm 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Instance.mm 2022-02-19 01:03:29 UTC (rev 290190)
@@ -38,7 +38,7 @@
Instance::~Instance() = default;
-Ref<Surface> Instance::createSurface(const WGPUSurfaceDescriptor* descriptor)
+RefPtr<Surface> Instance::createSurface(const WGPUSurfaceDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return Surface::create();
@@ -300,7 +300,8 @@
WGPUSurface wgpuInstanceCreateSurface(WGPUInstance instance, const WGPUSurfaceDescriptor* descriptor)
{
- return new WGPUSurfaceImpl { instance->instance->createSurface(descriptor) };
+ auto result = instance->instance->createSurface(descriptor);
+ return result ? new WGPUSurfaceImpl { result.releaseNonNull() } : nullptr;
}
void wgpuInstanceProcessEvents(WGPUInstance instance)
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.h 2022-02-19 01:03:29 UTC (rev 290190)
@@ -29,6 +29,7 @@
#import <wtf/FastMalloc.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
+#import <wtf/RefPtr.h>
namespace WebGPU {
@@ -51,7 +52,7 @@
void drawIndexed(uint32_t indexCount, uint32_t instanceCount, uint32_t firstIndex, int32_t baseVertex, uint32_t firstInstance);
void drawIndexedIndirect(const Buffer& indirectBuffer, uint64_t indirectOffset);
void drawIndirect(const Buffer& indirectBuffer, uint64_t indirectOffset);
- Ref<RenderBundle> finish(const WGPURenderBundleDescriptor*);
+ RefPtr<RenderBundle> finish(const WGPURenderBundleDescriptor*);
void insertDebugMarker(const char* markerLabel);
void popDebugGroup();
void pushDebugGroup(const char* groupLabel);
Modified: trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/RenderBundleEncoder.mm 2022-02-19 01:03:29 UTC (rev 290190)
@@ -67,7 +67,7 @@
UNUSED_PARAM(indirectOffset);
}
-Ref<RenderBundle> RenderBundleEncoder::finish(const WGPURenderBundleDescriptor* descriptor)
+RefPtr<RenderBundle> RenderBundleEncoder::finish(const WGPURenderBundleDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return RenderBundle::create();
@@ -151,7 +151,8 @@
WGPURenderBundle wgpuRenderBundleEncoderFinish(WGPURenderBundleEncoder renderBundleEncoder, const WGPURenderBundleDescriptor* descriptor)
{
- return new WGPURenderBundleImpl { renderBundleEncoder->renderBundleEncoder->finish(descriptor) };
+ auto result = renderBundleEncoder->renderBundleEncoder->finish(descriptor);
+ return result ? new WGPURenderBundleImpl { result.releaseNonNull() } : nullptr;
}
void wgpuRenderBundleEncoderInsertDebugMarker(WGPURenderBundleEncoder renderBundleEncoder, const char* markerLabel)
Modified: trunk/Source/WebGPU/WebGPU/Texture.h (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Texture.h 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Texture.h 2022-02-19 01:03:29 UTC (rev 290190)
@@ -29,6 +29,7 @@
#import <wtf/FastMalloc.h>
#import <wtf/Ref.h>
#import <wtf/RefCounted.h>
+#import <wtf/RefPtr.h>
namespace WebGPU {
@@ -44,7 +45,7 @@
~Texture();
- Ref<TextureView> createView(const WGPUTextureViewDescriptor*);
+ RefPtr<TextureView> createView(const WGPUTextureViewDescriptor*);
void destroy();
void setLabel(const char*);
Modified: trunk/Source/WebGPU/WebGPU/Texture.mm (290189 => 290190)
--- trunk/Source/WebGPU/WebGPU/Texture.mm 2022-02-19 01:02:27 UTC (rev 290189)
+++ trunk/Source/WebGPU/WebGPU/Texture.mm 2022-02-19 01:03:29 UTC (rev 290190)
@@ -35,7 +35,7 @@
Texture::~Texture() = default;
-Ref<TextureView> Texture::createView(const WGPUTextureViewDescriptor* descriptor)
+RefPtr<TextureView> Texture::createView(const WGPUTextureViewDescriptor* descriptor)
{
UNUSED_PARAM(descriptor);
return TextureView::create();
@@ -59,7 +59,8 @@
WGPUTextureView wgpuTextureCreateView(WGPUTexture texture, const WGPUTextureViewDescriptor* descriptor)
{
- return new WGPUTextureViewImpl { texture->texture->createView(descriptor) };
+ auto result = texture->texture->createView(descriptor);
+ return result ? new WGPUTextureViewImpl { result.releaseNonNull() } : nullptr;
}
void wgpuTextureDestroy(WGPUTexture texture)