Diff
Modified: trunk/Source/WebCore/PAL/ChangeLog (291383 => 291384)
--- trunk/Source/WebCore/PAL/ChangeLog 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/ChangeLog 2022-03-17 03:02:09 UTC (rev 291384)
@@ -1,3 +1,49 @@
+2022-03-16 Myles C. Maxfield <mmaxfi...@apple.com>
+
+ [WebGPU] Use block-based WebGPU API instead of function pointer & userdata API
+ https://bugs.webkit.org/show_bug.cgi?id=237932
+
+ Reviewed by Kimmo Kinnunen.
+
+ Thanks to the magic of makeBlockPtr(), we can use lambdas to pass asynchronous callbacks
+ to WebGPU methods, instead of having to save callbacks in a queue manually. This is much
+ safer because A) it's significantly less code, which means fewer bugs, and B) the
+ callbacks are allowed to fire out-of-order now.
+
+ * pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.cpp:
+ (PAL::WebGPU::AdapterImpl::requestDevice):
+ (PAL::WebGPU::requestDeviceCallback): Deleted.
+ (PAL::WebGPU::AdapterImpl::requestDeviceCallback): Deleted.
+ * pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.h:
+ * pal/graphics/WebGPU/Impl/WebGPUBufferImpl.cpp:
+ (PAL::WebGPU::BufferImpl::mapAsync):
+ (PAL::WebGPU::mapCallback): Deleted.
+ (PAL::WebGPU::BufferImpl::mapCallback): Deleted.
+ * pal/graphics/WebGPU/Impl/WebGPUBufferImpl.h:
+ * pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.cpp:
+ (PAL::WebGPU::DeviceImpl::createComputePipelineAsync):
+ (PAL::WebGPU::DeviceImpl::createRenderPipelineAsync):
+ (PAL::WebGPU::DeviceImpl::popErrorScope):
+ (PAL::WebGPU::createComputePipelineAsyncCallback): Deleted.
+ (PAL::WebGPU::DeviceImpl::createComputePipelineAsyncCallback): Deleted.
+ (PAL::WebGPU::createRenderPipelineAsyncCallback): Deleted.
+ (PAL::WebGPU::DeviceImpl::createRenderPipelineAsyncCallback): Deleted.
+ (PAL::WebGPU::popErrorScopeCallback): Deleted.
+ (PAL::WebGPU::DeviceImpl::popErrorScopeCallback): Deleted.
+ * pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.h:
+ * pal/graphics/WebGPU/Impl/WebGPUImpl.cpp:
+ (PAL::WebGPU::GPUImpl::requestAdapter):
+ (PAL::WebGPU::requestAdapterCallback): Deleted.
+ (PAL::WebGPU::GPUImpl::requestAdapterCallback): Deleted.
+ * pal/graphics/WebGPU/Impl/WebGPUImpl.h:
+ * pal/graphics/WebGPU/Impl/WebGPUQueueImpl.cpp:
+ (PAL::WebGPU::QueueImpl::onSubmittedWorkDone):
+ (PAL::WebGPU::onSubmittedWorkDoneCallback): Deleted.
+ (PAL::WebGPU::QueueImpl::onSubmittedWorkDoneCallback): Deleted.
+ * pal/graphics/WebGPU/Impl/WebGPUQueueImpl.h:
+ * pal/graphics/WebGPU/Impl/WebGPUShaderModuleImpl.cpp:
+ (PAL::WebGPU::ShaderModuleImpl::compilationInfo):
+
2022-03-15 Myles C. Maxfield <mmaxfi...@apple.com>
[WebGPU] Migrate from WTF::Function to WTF::CompletionHandler
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.cpp (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.cpp 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.cpp 2022-03-17 03:02:09 UTC (rev 291384)
@@ -31,6 +31,7 @@
#include "WebGPUConvertToBackingContext.h"
#include "WebGPUDeviceImpl.h"
#include <WebGPU/WebGPUExt.h>
+#include <wtf/BlockPtr.h>
namespace PAL::WebGPU {
@@ -140,16 +141,8 @@
wgpuAdapterRelease(m_backing);
}
-void requestDeviceCallback(WGPURequestDeviceStatus status, WGPUDevice device, const char* message, void* userdata)
-{
- auto adapter = adoptRef(*static_cast<AdapterImpl*>(userdata)); // adoptRef is balanced by leakRef in requestDevice() below. We have to do this because we're using a C API with no concept of reference counting or blocks.
- adapter->requestDeviceCallback(status, device, message);
-}
-
void AdapterImpl::requestDevice(const DeviceDescriptor& descriptor, CompletionHandler<void(Ref<Device>&&)>&& callback)
{
- Ref protectedThis(*this);
-
auto label = descriptor.label.utf8();
auto features = descriptor.requiredFeatures.map([this] (auto featureName) {
@@ -195,18 +188,11 @@
&limits,
};
- m_callbacks.append(WTFMove(callback));
-
- wgpuAdapterRequestDevice(m_backing, &backingDescriptor, &WebGPU::requestDeviceCallback, &protectedThis.leakRef()); // leakRef is balanced by adoptRef in requestDeviceCallback() above. We have to do this because we're using a C API with no concept of reference counting or blocks.
+ wgpuAdapterRequestDeviceWithBlock(m_backing, &backingDescriptor, makeBlockPtr([protectedThis = Ref { *this }, convertToBackingContext = m_convertToBackingContext.copyRef(), callback = WTFMove(callback)](WGPURequestDeviceStatus, WGPUDevice device, const char*) mutable {
+ callback(DeviceImpl::create(device, Ref { protectedThis->features() }, Ref { protectedThis->limits() }, convertToBackingContext));
+ }).get());
}
-void AdapterImpl::requestDeviceCallback(WGPURequestDeviceStatus, WGPUDevice device, const char* message)
-{
- UNUSED_PARAM(message);
- auto callback = m_callbacks.takeFirst();
- callback(DeviceImpl::create(device, Ref { features() }, Ref { limits() }, m_convertToBackingContext));
-}
-
} // namespace PAL::WebGPU
#endif // HAVE(WEBGPU_IMPLEMENTATION)
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.h (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.h 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUAdapterImpl.h 2022-03-17 03:02:09 UTC (rev 291384)
@@ -47,7 +47,6 @@
private:
friend class DowncastConvertToBackingContext;
- friend void requestDeviceCallback(WGPURequestDeviceStatus, WGPUDevice, const char* message, void* userdata);
AdapterImpl(WGPUAdapter, ConvertToBackingContext&);
@@ -58,11 +57,8 @@
WGPUAdapter backing() const { return m_backing; }
- void requestDeviceCallback(WGPURequestDeviceStatus, WGPUDevice, const char* message);
void requestDevice(const DeviceDescriptor&, CompletionHandler<void(Ref<Device>&&)>&&) final;
- Deque<CompletionHandler<void(Ref<Device>&&)>> m_callbacks;
-
WGPUAdapter m_backing { nullptr };
Ref<ConvertToBackingContext> m_convertToBackingContext;
};
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUBufferImpl.cpp (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUBufferImpl.cpp 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUBufferImpl.cpp 2022-03-17 03:02:09 UTC (rev 291384)
@@ -30,6 +30,7 @@
#include "WebGPUConvertToBackingContext.h"
#include <WebGPU/WebGPUExt.h>
+#include <wtf/BlockPtr.h>
namespace PAL::WebGPU {
@@ -44,33 +45,18 @@
wgpuBufferRelease(m_backing);
}
-void mapCallback(WGPUBufferMapAsyncStatus status, void* userdata)
-{
- auto buffer = adoptRef(*static_cast<BufferImpl*>(userdata)); // adoptRef is balanced by leakRef in mapAsync() below. We have to do this because we're using a C API with no concept of reference counting or blocks.
- buffer->mapCallback(status);
-}
-
void BufferImpl::mapAsync(MapModeFlags mapModeFlags, Size64 offset, std::optional<Size64> size, CompletionHandler<void()>&& callback)
{
- Ref protectedThis(*this);
-
auto backingMapModeFlags = m_convertToBackingContext->convertMapModeFlagsToBacking(mapModeFlags);
auto usedSize = size.value_or(WGPU_WHOLE_MAP_SIZE);
- m_callbacks.append(WTFMove(callback));
-
// FIXME: Check the casts.
- wgpuBufferMapAsync(m_backing, backingMapModeFlags, static_cast<size_t>(offset), static_cast<size_t>(usedSize), &WebGPU::mapCallback, &protectedThis.leakRef()); // leakRef is balanced by adoptRef in mapCallback() above. We have to do this because we're using a C API with no concept of reference counting or blocks.
+ wgpuBufferMapAsyncWithBlock(m_backing, backingMapModeFlags, static_cast<size_t>(offset), static_cast<size_t>(usedSize), makeBlockPtr([callback = WTFMove(callback)](WGPUBufferMapAsyncStatus) mutable {
+ callback();
+ }).get());
}
-void BufferImpl::mapCallback(WGPUBufferMapAsyncStatus status)
-{
- UNUSED_PARAM(status);
- auto callback = m_callbacks.takeFirst();
- callback();
-}
-
auto BufferImpl::getMappedRange(Size64 offset, std::optional<Size64> size) -> MappedRange
{
auto usedSize = size.value_or(WGPU_WHOLE_MAP_SIZE);
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUBufferImpl.h (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUBufferImpl.h 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUBufferImpl.h 2022-03-17 03:02:09 UTC (rev 291384)
@@ -47,7 +47,6 @@
private:
friend class DowncastConvertToBackingContext;
- friend void mapCallback(WGPUBufferMapAsyncStatus, void* userdata);
BufferImpl(WGPUBuffer, ConvertToBackingContext&);
@@ -58,7 +57,6 @@
WGPUBuffer backing() const { return m_backing; }
- void mapCallback(WGPUBufferMapAsyncStatus);
void mapAsync(MapModeFlags, Size64 offset, std::optional<Size64> sizeForMap, CompletionHandler<void()>&&) final;
MappedRange getMappedRange(Size64 offset, std::optional<Size64>) final;
void unmap() final;
@@ -67,8 +65,6 @@
void setLabelInternal(const String&) final;
- Deque<CompletionHandler<void()>> m_callbacks;
-
WGPUBuffer m_backing { nullptr };
Ref<ConvertToBackingContext> m_convertToBackingContext;
};
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.cpp (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.cpp 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.cpp 2022-03-17 03:02:09 UTC (rev 291384)
@@ -58,6 +58,7 @@
#include "WebGPUTextureViewImpl.h"
#include "WebGPUValidationError.h"
#include <WebGPU/WebGPUExt.h>
+#include <wtf/BlockPtr.h>
namespace PAL::WebGPU {
@@ -509,54 +510,24 @@
});
}
-void createComputePipelineAsyncCallback(WGPUCreatePipelineAsyncStatus status, WGPUComputePipeline pipeline, const char* message, void* userdata)
-{
- auto device = adoptRef(*static_cast<DeviceImpl*>(userdata)); // adoptRef is balanced by leakRef in createComputePipelineAsync() below. We have to do this because we're using a C API with no concept of reference counting or blocks.
- device->createComputePipelineAsyncCallback(status, pipeline, message);
-}
-
void DeviceImpl::createComputePipelineAsync(const ComputePipelineDescriptor& descriptor, CompletionHandler<void(Ref<ComputePipeline>&&)>&& callback)
{
- Ref protectedThis(*this);
-
- m_createComputePipelineAsyncCallbacks.append(WTFMove(callback));
-
- convertToBacking(descriptor, m_convertToBackingContext, [this, protectedThis = WTFMove(protectedThis)] (const WGPUComputePipelineDescriptor& backingDescriptor) mutable {
- wgpuDeviceCreateComputePipelineAsync(m_backing, &backingDescriptor, &WebGPU::createComputePipelineAsyncCallback, &protectedThis.leakRef()); // leakRef is balanced by adoptRef in requestDeviceCallback() above. We have to do this because we're using a C API with no concept of reference counting or blocks.
+ convertToBacking(descriptor, m_convertToBackingContext, [this, callback = WTFMove(callback)] (const WGPUComputePipelineDescriptor& backingDescriptor) mutable {
+ wgpuDeviceCreateComputePipelineAsyncWithBlock(m_backing, &backingDescriptor, makeBlockPtr([convertToBackingContext = m_convertToBackingContext.copyRef(), callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus, WGPUComputePipeline pipeline, const char*) mutable {
+ callback(ComputePipelineImpl::create(pipeline, convertToBackingContext));
+ }).get());
});
}
-void DeviceImpl::createComputePipelineAsyncCallback(WGPUCreatePipelineAsyncStatus, WGPUComputePipeline pipeline, const char* message)
-{
- UNUSED_PARAM(message);
- auto callback = m_createComputePipelineAsyncCallbacks.takeFirst();
- callback(ComputePipelineImpl::create(pipeline, m_convertToBackingContext));
-}
-
-void createRenderPipelineAsyncCallback(WGPUCreatePipelineAsyncStatus status, WGPURenderPipeline pipeline, const char* message, void* userdata)
-{
- auto device = adoptRef(*static_cast<DeviceImpl*>(userdata)); // adoptRef is balanced by leakRef in createRenderPipelineAsync() below. We have to do this because we're using a C API with no concept of reference counting or blocks.
- device->createRenderPipelineAsyncCallback(status, pipeline, message);
-}
-
void DeviceImpl::createRenderPipelineAsync(const RenderPipelineDescriptor& descriptor, CompletionHandler<void(Ref<RenderPipeline>&&)>&& callback)
{
- Ref protectedThis(*this);
-
- m_createRenderPipelineAsyncCallbacks.append(WTFMove(callback));
-
- convertToBacking(descriptor, m_convertToBackingContext, [this, protectedThis = WTFMove(protectedThis)] (const WGPURenderPipelineDescriptor& backingDescriptor) mutable {
- wgpuDeviceCreateRenderPipelineAsync(m_backing, &backingDescriptor, &WebGPU::createRenderPipelineAsyncCallback, &protectedThis.leakRef()); // leakRef is balanced by adoptRef in requestDeviceCallback() above. We have to do this because we're using a C API with no concept of reference counting or blocks.
+ convertToBacking(descriptor, m_convertToBackingContext, [this, callback = WTFMove(callback)] (const WGPURenderPipelineDescriptor& backingDescriptor) mutable {
+ wgpuDeviceCreateRenderPipelineAsyncWithBlock(m_backing, &backingDescriptor, makeBlockPtr([convertToBackingContext = m_convertToBackingContext.copyRef(), callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus, WGPURenderPipeline pipeline, const char*) mutable {
+ callback(RenderPipelineImpl::create(pipeline, convertToBackingContext));
+ }).get());
});
}
-void DeviceImpl::createRenderPipelineAsyncCallback(WGPUCreatePipelineAsyncStatus, WGPURenderPipeline pipeline, const char* message)
-{
- UNUSED_PARAM(message);
- auto callback = m_createRenderPipelineAsyncCallbacks.takeFirst();
- callback(RenderPipelineImpl::create(pipeline, m_convertToBackingContext));
-}
-
Ref<CommandEncoder> DeviceImpl::createCommandEncoder(const std::optional<CommandEncoderDescriptor>& descriptor)
{
CString label = descriptor ? descriptor->label.utf8() : CString("");
@@ -612,46 +583,32 @@
wgpuDevicePushErrorScope(m_backing, m_convertToBackingContext->convertToBacking(errorFilter));
}
-void popErrorScopeCallback(WGPUErrorType type, const char* message, void* userdata)
-{
- auto device = adoptRef(*static_cast<DeviceImpl*>(userdata)); // adoptRef is balanced by leakRef in popErrorScope() below. We have to do this because we're using a C API with no concept of reference counting or blocks.
- device->popErrorScopeCallback(type, message);
-}
-
void DeviceImpl::popErrorScope(CompletionHandler<void(std::optional<Error>&&)>&& callback)
{
- Ref protectedThis(*this);
+ wgpuDevicePopErrorScopeWithBlock(m_backing, makeBlockPtr([callback = WTFMove(callback)](WGPUErrorType errorType, const char* message) mutable {
+ std::optional<Error> error;
+ switch (errorType) {
+ case WGPUErrorType_NoError:
+ case WGPUErrorType_Force32:
+ break;
+ case WGPUErrorType_Validation:
+ error = { { ValidationError::create(message) } };
+ break;
+ case WGPUErrorType_OutOfMemory:
+ error = { { OutOfMemoryError::create() } };
+ break;
+ case WGPUErrorType_Unknown:
+ error = { { OutOfMemoryError::create() } };
+ break;
+ case WGPUErrorType_DeviceLost:
+ error = { { OutOfMemoryError::create() } };
+ break;
+ }
- m_popErrorScopeCallbacks.append(WTFMove(callback));
-
- wgpuDevicePopErrorScope(m_backing, &WebGPU::popErrorScopeCallback, &protectedThis.leakRef()); // leakRef is balanced by adoptRef in requestDeviceCallback() above. We have to do this because we're using a C API with no concept of reference counting or blocks.
+ callback(WTFMove(error));
+ }).get());
}
-void DeviceImpl::popErrorScopeCallback(WGPUErrorType errorType, const char* message)
-{
- std::optional<Error> error;
- switch (errorType) {
- case WGPUErrorType_NoError:
- case WGPUErrorType_Force32:
- break;
- case WGPUErrorType_Validation:
- error = { { ValidationError::create(message) } };
- break;
- case WGPUErrorType_OutOfMemory:
- error = { { OutOfMemoryError::create() } };
- break;
- case WGPUErrorType_Unknown:
- error = { { OutOfMemoryError::create() } };
- break;
- case WGPUErrorType_DeviceLost:
- error = { { OutOfMemoryError::create() } };
- break;
- }
-
- auto callback = m_popErrorScopeCallbacks.takeFirst();
- callback(WTFMove(error));
-}
-
void DeviceImpl::setLabelInternal(const String& label)
{
wgpuDeviceSetLabel(m_backing, label.utf8().data());
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.h (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.h 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUDeviceImpl.h 2022-03-17 03:02:09 UTC (rev 291384)
@@ -47,9 +47,6 @@
private:
friend class DowncastConvertToBackingContext;
- friend void createComputePipelineAsyncCallback(WGPUCreatePipelineAsyncStatus, WGPUComputePipeline, const char* message, void* userdata);
- friend void createRenderPipelineAsyncCallback(WGPUCreatePipelineAsyncStatus, WGPURenderPipeline, const char* message, void* userdata);
- friend void popErrorScopeCallback(WGPUErrorType, const char* message, void* userdata);
DeviceImpl(WGPUDevice, Ref<SupportedFeatures>&&, Ref<SupportedLimits>&&, ConvertToBackingContext&);
@@ -74,9 +71,7 @@
Ref<ShaderModule> createShaderModule(const ShaderModuleDescriptor&) final;
Ref<ComputePipeline> createComputePipeline(const ComputePipelineDescriptor&) final;
Ref<RenderPipeline> createRenderPipeline(const RenderPipelineDescriptor&) final;
- void createComputePipelineAsyncCallback(WGPUCreatePipelineAsyncStatus, WGPUComputePipeline, const char* message);
void createComputePipelineAsync(const ComputePipelineDescriptor&, CompletionHandler<void(Ref<ComputePipeline>&&)>&&) final;
- void createRenderPipelineAsyncCallback(WGPUCreatePipelineAsyncStatus, WGPURenderPipeline, const char* message);
void createRenderPipelineAsync(const RenderPipelineDescriptor&, CompletionHandler<void(Ref<RenderPipeline>&&)>&&) final;
Ref<CommandEncoder> createCommandEncoder(const std::optional<CommandEncoderDescriptor>&) final;
@@ -85,15 +80,10 @@
Ref<QuerySet> createQuerySet(const QuerySetDescriptor&) final;
void pushErrorScope(ErrorFilter) final;
- void popErrorScopeCallback(WGPUErrorType, const char* message);
void popErrorScope(CompletionHandler<void(std::optional<Error>&&)>&&) final;
void setLabelInternal(const String&) final;
- Deque<CompletionHandler<void(Ref<ComputePipeline>&&)>> m_createComputePipelineAsyncCallbacks;
- Deque<CompletionHandler<void(Ref<RenderPipeline>&&)>> m_createRenderPipelineAsyncCallbacks;
- Deque<CompletionHandler<void(std::optional<Error>&&)>> m_popErrorScopeCallbacks;
-
WGPUDevice m_backing { nullptr };
Ref<ConvertToBackingContext> m_convertToBackingContext;
};
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.cpp (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.cpp 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.cpp 2022-03-17 03:02:09 UTC (rev 291384)
@@ -76,16 +76,8 @@
wgpuInstanceRelease(m_backing);
}
-void requestAdapterCallback(WGPURequestAdapterStatus status, WGPUAdapter adapter, const char* message, void* userdata)
-{
- auto gpu = adoptRef(*static_cast<GPUImpl*>(userdata)); // adoptRef is balanced by leakRef in requestAdapter() below. We have to do this because we're using a C API with no concept of reference counting or blocks.
- gpu->requestAdapterCallback(status, adapter, message);
-}
-
void GPUImpl::requestAdapter(const RequestAdapterOptions& options, CompletionHandler<void(RefPtr<Adapter>&&)>&& callback)
{
- Ref protectedThis(*this);
-
WGPURequestAdapterOptions backingOptions {
nullptr,
nullptr,
@@ -93,18 +85,11 @@
options.forceFallbackAdapter,
};
- m_callbacks.append(WTFMove(callback));
-
- wgpuInstanceRequestAdapter(m_backing, &backingOptions, &WebGPU::requestAdapterCallback, &protectedThis.leakRef()); // leakRef is balanced by adoptRef in requestAdapterCallback() above. We have to do this because we're using a C API with no concept of reference counting or blocks.
+ wgpuInstanceRequestAdapterWithBlock(m_backing, &backingOptions, makeBlockPtr([convertToBackingContext = m_convertToBackingContext.copyRef(), callback = WTFMove(callback)](WGPURequestAdapterStatus, WGPUAdapter adapter, const char*) mutable {
+ callback(AdapterImpl::create(adapter, convertToBackingContext));
+ }).get());
}
-void GPUImpl::requestAdapterCallback(WGPURequestAdapterStatus, WGPUAdapter adapter, const char* message)
-{
- UNUSED_PARAM(message);
- auto callback = m_callbacks.takeFirst();
- callback(AdapterImpl::create(adapter, m_convertToBackingContext));
-}
-
} // namespace PAL::WebGPU
#endif // HAVE(WEBGPU_IMPLEMENTATION)
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.h (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.h 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUImpl.h 2022-03-17 03:02:09 UTC (rev 291384)
@@ -53,7 +53,6 @@
private:
friend class DowncastConvertToBackingContext;
- friend void requestAdapterCallback(WGPURequestAdapterStatus, WGPUAdapter, const char* message, void* userdata);
GPUImpl(WGPUInstance, ConvertToBackingContext&);
@@ -64,11 +63,8 @@
WGPUInstance backing() const { return m_backing; }
- void requestAdapterCallback(WGPURequestAdapterStatus, WGPUAdapter, const char* message);
void requestAdapter(const RequestAdapterOptions&, CompletionHandler<void(RefPtr<Adapter>&&)>&&) final;
- Deque<CompletionHandler<void(RefPtr<Adapter>&&)>> m_callbacks;
-
WGPUInstance m_backing { nullptr };
Ref<ConvertToBackingContext> m_convertToBackingContext;
};
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUQueueImpl.cpp (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUQueueImpl.cpp 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUQueueImpl.cpp 2022-03-17 03:02:09 UTC (rev 291384)
@@ -33,6 +33,7 @@
#include "WebGPUConvertToBackingContext.h"
#include "WebGPUTextureImpl.h"
#include <WebGPU/WebGPUExt.h>
+#include <wtf/BlockPtr.h>
namespace PAL::WebGPU {
@@ -56,29 +57,15 @@
wgpuQueueSubmit(m_backing, backingCommandBuffers.size(), backingCommandBuffers.data());
}
-void onSubmittedWorkDoneCallback(WGPUQueueWorkDoneStatus status, void* userdata)
-{
- auto queue = adoptRef(*static_cast<QueueImpl*>(userdata)); // adoptRef is balanced by leakRef in onSubmittedWorkDone() below. We have to do this because we're using a C API with no concept of reference counting or blocks.
- queue->onSubmittedWorkDoneCallback(status);
-}
-
void QueueImpl::onSubmittedWorkDone(CompletionHandler<void()>&& callback)
{
- Ref protectedThis(*this);
+ wgpuQueueOnSubmittedWorkDoneWithBlock(m_backing, m_signalValue, makeBlockPtr([callback = WTFMove(callback)](WGPUQueueWorkDoneStatus) mutable {
+ callback();
+ }).get());
- m_callbacks.append(WTFMove(callback));
-
- wgpuQueueOnSubmittedWorkDone(m_backing, m_signalValue, &WebGPU::onSubmittedWorkDoneCallback, &protectedThis.leakRef()); // leakRef is balanced by adoptRef in onSubmittedWorkDoneCallback() above. We have to do this because we're using a C API with no concept of reference counting or blocks.
-
++m_signalValue;
}
-void QueueImpl::onSubmittedWorkDoneCallback(WGPUQueueWorkDoneStatus)
-{
- auto callback = m_callbacks.takeFirst();
- callback();
-}
-
void QueueImpl::writeBuffer(
const Buffer& buffer,
Size64 bufferOffset,
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUQueueImpl.h (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUQueueImpl.h 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUQueueImpl.h 2022-03-17 03:02:09 UTC (rev 291384)
@@ -47,7 +47,6 @@
private:
friend class DowncastConvertToBackingContext;
- friend void onSubmittedWorkDoneCallback(WGPUQueueWorkDoneStatus, void* userdata);
QueueImpl(WGPUQueue, ConvertToBackingContext&);
@@ -60,7 +59,6 @@
void submit(Vector<std::reference_wrapper<CommandBuffer>>&&) final;
- void onSubmittedWorkDoneCallback(WGPUQueueWorkDoneStatus);
void onSubmittedWorkDone(CompletionHandler<void()>&&) final;
void writeBuffer(
@@ -87,8 +85,6 @@
uint64_t m_signalValue { 1 };
- Deque<CompletionHandler<void()>> m_callbacks;
-
WGPUQueue m_backing { nullptr };
Ref<ConvertToBackingContext> m_convertToBackingContext;
};
Modified: trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUShaderModuleImpl.cpp (291383 => 291384)
--- trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUShaderModuleImpl.cpp 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebCore/PAL/pal/graphics/WebGPU/Impl/WebGPUShaderModuleImpl.cpp 2022-03-17 03:02:09 UTC (rev 291384)
@@ -46,6 +46,7 @@
void ShaderModuleImpl::compilationInfo(CompletionHandler<void(Ref<CompilationInfo>&&)>&&)
{
+ // FIXME: Implement this.
}
void ShaderModuleImpl::setLabelInternal(const String& label)
Modified: trunk/Source/WebGPU/ChangeLog (291383 => 291384)
--- trunk/Source/WebGPU/ChangeLog 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebGPU/ChangeLog 2022-03-17 03:02:09 UTC (rev 291384)
@@ -1,5 +1,41 @@
2022-03-16 Myles C. Maxfield <mmaxfi...@apple.com>
+ [WebGPU] Use block-based WebGPU API instead of function pointer & userdata API
+ https://bugs.webkit.org/show_bug.cgi?id=237932
+
+ Reviewed by Kimmo Kinnunen.
+
+ Move callbacks instead of copying them. Also, update according to the style guide.
+
+ * WebGPU/Adapter.mm:
+ (wgpuAdapterRequestDevice):
+ (wgpuAdapterRequestDeviceWithBlock):
+ * WebGPU/Buffer.mm:
+ (wgpuBufferMapAsync):
+ (wgpuBufferMapAsyncWithBlock):
+ * WebGPU/Device.mm:
+ (wgpuDeviceCreateComputePipelineAsync):
+ (wgpuDeviceCreateComputePipelineAsyncWithBlock):
+ (wgpuDeviceCreateRenderPipelineAsync):
+ (wgpuDeviceCreateRenderPipelineAsyncWithBlock):
+ (wgpuDevicePopErrorScope):
+ (wgpuDevicePopErrorScopeWithBlock):
+ (wgpuDeviceSetDeviceLostCallback):
+ (wgpuDeviceSetDeviceLostCallbackWithBlock):
+ (wgpuDeviceSetUncapturedErrorCallback):
+ (wgpuDeviceSetUncapturedErrorCallbackWithBlock):
+ * WebGPU/Instance.mm:
+ (wgpuInstanceRequestAdapter):
+ (wgpuInstanceRequestAdapterWithBlock):
+ * WebGPU/Queue.mm:
+ (wgpuQueueOnSubmittedWorkDone):
+ (wgpuQueueOnSubmittedWorkDoneWithBlock):
+ * WebGPU/ShaderModule.mm:
+ (wgpuShaderModuleGetCompilationInfo):
+ (wgpuShaderModuleGetCompilationInfoWithBlock):
+
+2022-03-16 Myles C. Maxfield <mmaxfi...@apple.com>
+
[WebGPU] Implement queue submission methods according to the spec
https://bugs.webkit.org/show_bug.cgi?id=237869
Modified: trunk/Source/WebGPU/WebGPU/Adapter.mm (291383 => 291384)
--- trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebGPU/WebGPU/Adapter.mm 2022-03-17 03:02:09 UTC (rev 291384)
@@ -155,7 +155,7 @@
void wgpuAdapterRequestDevice(WGPUAdapter adapter, const WGPUDeviceDescriptor* descriptor, WGPURequestDeviceCallback callback, void* userdata)
{
- WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback, userdata] (WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, String&& message) {
+ WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback, userdata](WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, String&& message) {
if (device) {
auto& queue = device->getQueue();
callback(status, new WGPUDeviceImpl { device.releaseNonNull(), { queue } }, message.utf8().data(), userdata);
@@ -166,7 +166,7 @@
void wgpuAdapterRequestDeviceWithBlock(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceBlockCallback callback)
{
- WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback] (WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, String&& message) {
+ WebGPU::fromAPI(adapter).requestDevice(*descriptor, [callback = WTFMove(callback)](WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, String&& message) {
if (device) {
auto& queue = device->getQueue();
callback(status, new WGPUDeviceImpl { device.releaseNonNull(), { queue } }, message.utf8().data());
Modified: trunk/Source/WebGPU/WebGPU/Buffer.mm (291383 => 291384)
--- trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebGPU/WebGPU/Buffer.mm 2022-03-17 03:02:09 UTC (rev 291384)
@@ -294,7 +294,7 @@
m_mapMode = mode;
// "Enqueue an operation on the default queue’s Queue timeline that will execute the following:"
- m_device->getQueue().onSubmittedWorkDone(0, [protectedThis = Ref { *this }, offset, rangeSize, callback = WTFMove(callback)] (WGPUQueueWorkDoneStatus status) mutable {
+ m_device->getQueue().onSubmittedWorkDone(0, [protectedThis = Ref { *this }, offset, rangeSize, callback = WTFMove(callback)](WGPUQueueWorkDoneStatus status) mutable {
// "If this.[[state]] is mapping pending:"
if (protectedThis->m_state == State::MappingPending) {
// "Let m be a new ArrayBuffer of size rangeSize."
@@ -412,7 +412,7 @@
void wgpuBufferMapAsync(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapCallback callback, void* userdata)
{
- WebGPU::fromAPI(buffer).mapAsync(mode, offset, size, [callback, userdata] (WGPUBufferMapAsyncStatus status) {
+ WebGPU::fromAPI(buffer).mapAsync(mode, offset, size, [callback, userdata](WGPUBufferMapAsyncStatus status) {
callback(status, userdata);
});
}
@@ -419,7 +419,7 @@
void wgpuBufferMapAsyncWithBlock(WGPUBuffer buffer, WGPUMapModeFlags mode, size_t offset, size_t size, WGPUBufferMapBlockCallback callback)
{
- WebGPU::fromAPI(buffer).mapAsync(mode, offset, size, [callback] (WGPUBufferMapAsyncStatus status) {
+ WebGPU::fromAPI(buffer).mapAsync(mode, offset, size, [callback = WTFMove(callback)](WGPUBufferMapAsyncStatus status) {
callback(status);
});
}
Modified: trunk/Source/WebGPU/WebGPU/Device.mm (291383 => 291384)
--- trunk/Source/WebGPU/WebGPU/Device.mm 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebGPU/WebGPU/Device.mm 2022-03-17 03:02:09 UTC (rev 291384)
@@ -171,7 +171,7 @@
void wgpuDeviceCreateComputePipelineAsync(WGPUDevice device, const WGPUComputePipelineDescriptor* descriptor, WGPUCreateComputePipelineAsyncCallback callback, void* userdata)
{
- WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback, userdata] (WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::ComputePipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback, userdata](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::ComputePipeline>&& pipeline, String&& message) {
callback(status, pipeline ? new WGPUComputePipelineImpl { pipeline.releaseNonNull() } : nullptr, message.utf8().data(), userdata);
});
}
@@ -178,7 +178,7 @@
void wgpuDeviceCreateComputePipelineAsyncWithBlock(WGPUDevice device, WGPUComputePipelineDescriptor const * descriptor, WGPUCreateComputePipelineAsyncBlockCallback callback)
{
- WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback] (WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::ComputePipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createComputePipelineAsync(*descriptor, [callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::ComputePipeline>&& pipeline, String&& message) {
callback(status, pipeline ? new WGPUComputePipelineImpl { pipeline.releaseNonNull() } : nullptr, message.utf8().data());
});
}
@@ -209,7 +209,7 @@
void wgpuDeviceCreateRenderPipelineAsync(WGPUDevice device, const WGPURenderPipelineDescriptor* descriptor, WGPUCreateRenderPipelineAsyncCallback callback, void* userdata)
{
- WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback, userdata] (WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::RenderPipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback, userdata](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::RenderPipeline>&& pipeline, String&& message) {
callback(status, pipeline ? new WGPURenderPipelineImpl { pipeline.releaseNonNull() } : nullptr, message.utf8().data(), userdata);
});
}
@@ -216,7 +216,7 @@
void wgpuDeviceCreateRenderPipelineAsyncWithBlock(WGPUDevice device, WGPURenderPipelineDescriptor const * descriptor, WGPUCreateRenderPipelineAsyncBlockCallback callback)
{
- WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback] (WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::RenderPipeline>&& pipeline, String&& message) {
+ WebGPU::fromAPI(device).createRenderPipelineAsync(*descriptor, [callback = WTFMove(callback)](WGPUCreatePipelineAsyncStatus status, RefPtr<WebGPU::RenderPipeline>&& pipeline, String&& message) {
callback(status, pipeline ? new WGPURenderPipelineImpl { pipeline.releaseNonNull() } : nullptr, message.utf8().data());
});
}
@@ -272,7 +272,7 @@
bool wgpuDevicePopErrorScope(WGPUDevice device, WGPUErrorCallback callback, void* userdata)
{
- return WebGPU::fromAPI(device).popErrorScope([callback, userdata] (WGPUErrorType type, String&& message) {
+ return WebGPU::fromAPI(device).popErrorScope([callback, userdata](WGPUErrorType type, String&& message) {
callback(type, message.utf8().data(), userdata);
});
}
@@ -279,7 +279,7 @@
bool wgpuDevicePopErrorScopeWithBlock(WGPUDevice device, WGPUErrorBlockCallback callback)
{
- return WebGPU::fromAPI(device).popErrorScope([callback] (WGPUErrorType type, String&& message) {
+ return WebGPU::fromAPI(device).popErrorScope([callback = WTFMove(callback)](WGPUErrorType type, String&& message) {
callback(type, message.utf8().data());
});
}
@@ -291,7 +291,7 @@
void wgpuDeviceSetDeviceLostCallback(WGPUDevice device, WGPUDeviceLostCallback callback, void* userdata)
{
- return WebGPU::fromAPI(device).setDeviceLostCallback([callback, userdata] (WGPUDeviceLostReason reason, String&& message) {
+ return WebGPU::fromAPI(device).setDeviceLostCallback([callback, userdata](WGPUDeviceLostReason reason, String&& message) {
if (callback)
callback(reason, message.utf8().data(), userdata);
});
@@ -299,7 +299,7 @@
void wgpuDeviceSetDeviceLostCallbackWithBlock(WGPUDevice device, WGPUDeviceLostBlockCallback callback)
{
- return WebGPU::fromAPI(device).setDeviceLostCallback([callback] (WGPUDeviceLostReason reason, String&& message) {
+ return WebGPU::fromAPI(device).setDeviceLostCallback([callback = WTFMove(callback)](WGPUDeviceLostReason reason, String&& message) {
if (callback)
callback(reason, message.utf8().data());
});
@@ -307,7 +307,7 @@
void wgpuDeviceSetUncapturedErrorCallback(WGPUDevice device, WGPUErrorCallback callback, void* userdata)
{
- return WebGPU::fromAPI(device).setUncapturedErrorCallback([callback, userdata] (WGPUErrorType type, String&& message) {
+ return WebGPU::fromAPI(device).setUncapturedErrorCallback([callback, userdata](WGPUErrorType type, String&& message) {
if (callback)
callback(type, message.utf8().data(), userdata);
});
@@ -315,7 +315,7 @@
void wgpuDeviceSetUncapturedErrorCallbackWithBlock(WGPUDevice device, WGPUErrorBlockCallback callback)
{
- return WebGPU::fromAPI(device).setUncapturedErrorCallback([callback] (WGPUErrorType type, String&& message) {
+ return WebGPU::fromAPI(device).setUncapturedErrorCallback([callback = WTFMove(callback)](WGPUErrorType type, String&& message) {
if (callback)
callback(type, message.utf8().data());
});
Modified: trunk/Source/WebGPU/WebGPU/Instance.mm (291383 => 291384)
--- trunk/Source/WebGPU/WebGPU/Instance.mm 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebGPU/WebGPU/Instance.mm 2022-03-17 03:02:09 UTC (rev 291384)
@@ -444,7 +444,7 @@
void wgpuInstanceRequestAdapter(WGPUInstance instance, const WGPURequestAdapterOptions* options, WGPURequestAdapterCallback callback, void* userdata)
{
- WebGPU::fromAPI(instance).requestAdapter(*options, [callback, userdata] (WGPURequestAdapterStatus status, RefPtr<WebGPU::Adapter>&& adapter, String&& message) {
+ WebGPU::fromAPI(instance).requestAdapter(*options, [callback, userdata](WGPURequestAdapterStatus status, RefPtr<WebGPU::Adapter>&& adapter, String&& message) {
callback(status, adapter ? new WGPUAdapterImpl { adapter.releaseNonNull() } : nullptr, message.utf8().data(), userdata);
});
}
@@ -451,7 +451,7 @@
void wgpuInstanceRequestAdapterWithBlock(WGPUInstance instance, WGPURequestAdapterOptions const * options, WGPURequestAdapterBlockCallback callback)
{
- WebGPU::fromAPI(instance).requestAdapter(*options, [callback] (WGPURequestAdapterStatus status, RefPtr<WebGPU::Adapter>&& adapter, String&& message) {
+ WebGPU::fromAPI(instance).requestAdapter(*options, [callback = WTFMove(callback)](WGPURequestAdapterStatus status, RefPtr<WebGPU::Adapter>&& adapter, String&& message) {
callback(status, adapter ? new WGPUAdapterImpl { adapter.releaseNonNull() } : nullptr, message.utf8().data());
});
}
Modified: trunk/Source/WebGPU/WebGPU/Queue.mm (291383 => 291384)
--- trunk/Source/WebGPU/WebGPU/Queue.mm 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebGPU/WebGPU/Queue.mm 2022-03-17 03:02:09 UTC (rev 291384)
@@ -85,7 +85,7 @@
// "For each commandBuffer in commandBuffers:"
for (auto commandBuffer : commands) {
ASSERT(commandBuffer.get().commandBuffer().commandQueue == m_commandQueue); //
- [commandBuffer.get().commandBuffer() addCompletedHandler:[protectedThis = Ref { *this }] (id<MTLCommandBuffer>) {
+ [commandBuffer.get().commandBuffer() addCompletedHandler:[protectedThis = Ref { *this }](id<MTLCommandBuffer>) {
protectedThis->scheduleWork(CompletionHandler<void(void)>([protectedThis = protectedThis.copyRef()]() {
++(protectedThis->m_completedCommandBufferCount);
for (auto& callback : protectedThis->m_onSubmittedWorkDoneCallbacks.take(protectedThis->m_completedCommandBufferCount))
@@ -136,7 +136,7 @@
void wgpuQueueOnSubmittedWorkDone(WGPUQueue queue, uint64_t signalValue, WGPUQueueWorkDoneCallback callback, void* userdata)
{
- WebGPU::fromAPI(queue).onSubmittedWorkDone(signalValue, [callback, userdata] (WGPUQueueWorkDoneStatus status) {
+ WebGPU::fromAPI(queue).onSubmittedWorkDone(signalValue, [callback, userdata](WGPUQueueWorkDoneStatus status) {
callback(status, userdata);
});
}
@@ -143,7 +143,7 @@
void wgpuQueueOnSubmittedWorkDoneWithBlock(WGPUQueue queue, uint64_t signalValue, WGPUQueueWorkDoneBlockCallback callback)
{
- WebGPU::fromAPI(queue).onSubmittedWorkDone(signalValue, [callback] (WGPUQueueWorkDoneStatus status) {
+ WebGPU::fromAPI(queue).onSubmittedWorkDone(signalValue, [callback = WTFMove(callback)](WGPUQueueWorkDoneStatus status) {
callback(status);
});
}
Modified: trunk/Source/WebGPU/WebGPU/ShaderModule.mm (291383 => 291384)
--- trunk/Source/WebGPU/WebGPU/ShaderModule.mm 2022-03-17 02:51:04 UTC (rev 291383)
+++ trunk/Source/WebGPU/WebGPU/ShaderModule.mm 2022-03-17 03:02:09 UTC (rev 291384)
@@ -152,7 +152,7 @@
Vector<WGPUCompilationMessage> flattenedCompilationMessages;
Vector<CString> flattenedMessages;
- auto populateMessages = [&] (const Messages& compilationMessages) {
+ auto populateMessages = [&](const Messages& compilationMessages) {
for (const auto& compilationMessage : compilationMessages.messages)
flattenedMessages.append(compilationMessage.message().utf8());
};
@@ -161,7 +161,7 @@
if (messages2)
populateMessages(*messages2);
- auto populateCompilationMessages = [&] (const Messages& compilationMessages, size_t base) {
+ auto populateCompilationMessages = [&](const Messages& compilationMessages, size_t base) {
for (size_t i = 0; i < compilationMessages.messages.size(); ++i) {
const auto& compilationMessage = compilationMessages.messages[i];
flattenedCompilationMessages.append({
@@ -185,7 +185,7 @@
void ShaderModule::getCompilationInfo(CompletionHandler<void(WGPUCompilationInfoRequestStatus, const WGPUCompilationInfo&)>&& callback)
{
- WTF::switchOn(m_checkResult, [&] (const WGSL::SuccessfulCheck& successfulCheck) {
+ WTF::switchOn(m_checkResult, [&](const WGSL::SuccessfulCheck& successfulCheck) {
auto compilationMessageData(convertMessages({ successfulCheck.warnings, WGPUCompilationMessageType_Warning }));
WGPUCompilationInfo compilationInfo {
nullptr,
@@ -193,7 +193,7 @@
compilationMessageData.compilationMessages.data(),
};
callback(WGPUCompilationInfoRequestStatus_Success, compilationInfo);
- }, [&] (const WGSL::FailedCheck& failedCheck) {
+ }, [&](const WGSL::FailedCheck& failedCheck) {
auto compilationMessageData(convertMessages(
{ failedCheck.errors, WGPUCompilationMessageType_Error },
{ { failedCheck.warnings, WGPUCompilationMessageType_Warning } }));
@@ -221,9 +221,9 @@
const WGSL::AST::ShaderModule* ShaderModule::ast() const
{
- return WTF::switchOn(m_checkResult, [&] (const WGSL::SuccessfulCheck& successfulCheck) -> const WGSL::AST::ShaderModule* {
+ return WTF::switchOn(m_checkResult, [&](const WGSL::SuccessfulCheck& successfulCheck) -> const WGSL::AST::ShaderModule* {
return successfulCheck.ast.ptr();
- }, [&] (const WGSL::FailedCheck&) -> const WGSL::AST::ShaderModule* {
+ }, [&](const WGSL::FailedCheck&) -> const WGSL::AST::ShaderModule* {
return nullptr;
});
}
@@ -253,7 +253,7 @@
void wgpuShaderModuleGetCompilationInfo(WGPUShaderModule shaderModule, WGPUCompilationInfoCallback callback, void * userdata)
{
- WebGPU::fromAPI(shaderModule).getCompilationInfo([callback, userdata] (WGPUCompilationInfoRequestStatus status, const WGPUCompilationInfo& compilationInfo) {
+ WebGPU::fromAPI(shaderModule).getCompilationInfo([callback, userdata](WGPUCompilationInfoRequestStatus status, const WGPUCompilationInfo& compilationInfo) {
callback(status, &compilationInfo, userdata);
});
}
@@ -260,7 +260,7 @@
void wgpuShaderModuleGetCompilationInfoWithBlock(WGPUShaderModule shaderModule, WGPUCompilationInfoBlockCallback callback)
{
- WebGPU::fromAPI(shaderModule).getCompilationInfo([callback] (WGPUCompilationInfoRequestStatus status, const WGPUCompilationInfo& compilationInfo) {
+ WebGPU::fromAPI(shaderModule).getCompilationInfo([callback = WTFMove(callback)](WGPUCompilationInfoRequestStatus status, const WGPUCompilationInfo& compilationInfo) {
callback(status, &compilationInfo);
});
}