Title: [290258] trunk/Source/WebGPU
- Revision
- 290258
- Author
- [email protected]
- Date
- 2022-02-21 11:58:46 -0800 (Mon, 21 Feb 2022)
Log Message
[WebGPU] Tracer bullet part 6: Give a RunLoop to Instance
https://bugs.webkit.org/show_bug.cgi?id=236899
Reviewed by Dean Jackson.
The shared header has a function, wgpuInstanceProcessEvents(), which is supposed
to synchronously call all outstanding callbacks. A natural way to do this is to
hook this up to [NSRunLoop runMode:beforeDate:].
* WebGPU/Instance.h:
(WebGPU::Instance::runLoop const):
(WebGPU::Instance::create): Deleted.
* WebGPU/Instance.mm:
(WebGPU::Instance::create):
(WebGPU::Instance::Instance):
(WebGPU::Instance::createSurface):
(WebGPU::Instance::processEvents):
(wgpuCreateInstance):
Modified Paths
Diff
Modified: trunk/Source/WebGPU/ChangeLog (290257 => 290258)
--- trunk/Source/WebGPU/ChangeLog 2022-02-21 19:48:07 UTC (rev 290257)
+++ trunk/Source/WebGPU/ChangeLog 2022-02-21 19:58:46 UTC (rev 290258)
@@ -1,5 +1,26 @@
2022-02-21 Myles C. Maxfield <[email protected]>
+ [WebGPU] Tracer bullet part 6: Give a RunLoop to Instance
+ https://bugs.webkit.org/show_bug.cgi?id=236899
+
+ Reviewed by Dean Jackson.
+
+ The shared header has a function, wgpuInstanceProcessEvents(), which is supposed
+ to synchronously call all outstanding callbacks. A natural way to do this is to
+ hook this up to [NSRunLoop runMode:beforeDate:].
+
+ * WebGPU/Instance.h:
+ (WebGPU::Instance::runLoop const):
+ (WebGPU::Instance::create): Deleted.
+ * WebGPU/Instance.mm:
+ (WebGPU::Instance::create):
+ (WebGPU::Instance::Instance):
+ (WebGPU::Instance::createSurface):
+ (WebGPU::Instance::processEvents):
+ (wgpuCreateInstance):
+
+2022-02-21 Myles C. Maxfield <[email protected]>
+
[WebGPU] Tracer bullet part 5: Give Metal objects to WebGPU objects
https://bugs.webkit.org/show_bug.cgi?id=236898
Modified: trunk/Source/WebGPU/WebGPU/Instance.h (290257 => 290258)
--- trunk/Source/WebGPU/WebGPU/Instance.h 2022-02-21 19:48:07 UTC (rev 290257)
+++ trunk/Source/WebGPU/WebGPU/Instance.h 2022-02-21 19:58:46 UTC (rev 290258)
@@ -26,6 +26,7 @@
#pragma once
#import "WebGPU.h"
+#import <Foundation/Foundation.h>
#import <wtf/FastMalloc.h>
#import <wtf/Function.h>
#import <wtf/Ref.h>
@@ -40,10 +41,7 @@
class Instance : public RefCounted<Instance> {
WTF_MAKE_FAST_ALLOCATED;
public:
- static Ref<Instance> create()
- {
- return adoptRef(*new Instance());
- }
+ static RefPtr<Instance> create(const WGPUInstanceDescriptor*);
~Instance();
@@ -51,8 +49,12 @@
void processEvents();
void requestAdapter(const WGPURequestAdapterOptions*, WTF::Function<void(WGPURequestAdapterStatus, RefPtr<Adapter>&&, const char*)>&& callback);
+ NSRunLoop *runLoop() const { return m_runLoop; }
+
private:
- Instance();
+ Instance(NSRunLoop *);
+
+ NSRunLoop *m_runLoop;
};
} // namespace WebGPU
Modified: trunk/Source/WebGPU/WebGPU/Instance.mm (290257 => 290258)
--- trunk/Source/WebGPU/WebGPU/Instance.mm 2022-02-21 19:48:07 UTC (rev 290257)
+++ trunk/Source/WebGPU/WebGPU/Instance.mm 2022-02-21 19:58:46 UTC (rev 290258)
@@ -34,12 +34,30 @@
namespace WebGPU {
-Instance::Instance() = default;
+static constexpr NSString *runLoopMode = @"kCFRunLoopWebGPUMode";
+RefPtr<Instance> Instance::create(const WGPUInstanceDescriptor* descriptor)
+{
+ if (descriptor->nextInChain)
+ return nullptr;
+
+ NSRunLoop *runLoop = NSRunLoop.currentRunLoop;
+ if (!runLoop)
+ return nullptr;
+
+ return adoptRef(*new Instance(runLoop));
+}
+
+Instance::Instance(NSRunLoop *runLoop)
+ : m_runLoop(runLoop)
+{
+}
+
Instance::~Instance() = default;
RefPtr<Surface> Instance::createSurface(const WGPUSurfaceDescriptor* descriptor)
{
+ // FIXME: Implement this.
UNUSED_PARAM(descriptor);
return Surface::create();
}
@@ -46,6 +64,15 @@
void Instance::processEvents()
{
+ // NSRunLoops are not thread-safe, but then again neither is WebGPU.
+ // If the caller does all the necessary synchronization themselves, this will be safe.
+ // In that situation, we have to make sure we're using the run loop we were created on,
+ // so tasks that were queued up on one thread actually get executed here, even if
+ // this is executing on a different thread.
+ BOOL result;
+ do {
+ result = [m_runLoop runMode:runLoopMode beforeDate:[NSDate date]];
+ } while (result);
}
void Instance::requestAdapter(const WGPURequestAdapterOptions* options, WTF::Function<void(WGPURequestAdapterStatus, RefPtr<Adapter>&&, const char*)>&& callback)
@@ -64,8 +91,8 @@
WGPUInstance wgpuCreateInstance(const WGPUInstanceDescriptor* descriptor)
{
- UNUSED_PARAM(descriptor);
- return new WGPUInstanceImpl { WebGPU::Instance::create() };
+ auto result = WebGPU::Instance::create(descriptor);
+ return result ? new WGPUInstanceImpl { result.releaseNonNull() } : nullptr;
}
WGPUProc wgpuGetProcAddress(WGPUDevice device, const char* procName)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes