Title: [291315] trunk/Source/WebGPU
Revision
291315
Author
[email protected]
Date
2022-03-15 14:30:06 -0700 (Tue, 15 Mar 2022)

Log Message

[WebGPU] Repeated calls to wgpuDeviceGetQueue() are supposed to return the same pointer
https://bugs.webkit.org/show_bug.cgi?id=237861

Reviewed by Kimmo Kinnunen.

Previously, wgpuDeviceGetQueue() had "new WGPUQueueImpl { ... }" but this is wrong because
the default queue doesn't change from one call to the next.

* WebGPU/Adapter.mm:
(WebGPU::Adapter::requestDevice):
(wgpuAdapterRequestDevice):
(wgpuAdapterRequestDeviceWithBlock):
* WebGPU/Device.h:
* WebGPU/Device.mm:
(WebGPU::Device::create):
(WebGPU::Device::getQueue):
(wgpuDeviceGetQueue):

Modified Paths

Diff

Modified: trunk/Source/WebGPU/ChangeLog (291314 => 291315)


--- trunk/Source/WebGPU/ChangeLog	2022-03-15 21:30:05 UTC (rev 291314)
+++ trunk/Source/WebGPU/ChangeLog	2022-03-15 21:30:06 UTC (rev 291315)
@@ -1,5 +1,25 @@
 2022-03-15  Myles C. Maxfield  <[email protected]>
 
+        [WebGPU] Repeated calls to wgpuDeviceGetQueue() are supposed to return the same pointer
+        https://bugs.webkit.org/show_bug.cgi?id=237861
+
+        Reviewed by Kimmo Kinnunen.
+
+        Previously, wgpuDeviceGetQueue() had "new WGPUQueueImpl { ... }" but this is wrong because
+        the default queue doesn't change from one call to the next.
+
+        * WebGPU/Adapter.mm:
+        (WebGPU::Adapter::requestDevice):
+        (wgpuAdapterRequestDevice):
+        (wgpuAdapterRequestDeviceWithBlock):
+        * WebGPU/Device.h:
+        * WebGPU/Device.mm:
+        (WebGPU::Device::create):
+        (WebGPU::Device::getQueue):
+        (wgpuDeviceGetQueue):
+
+2022-03-15  Myles C. Maxfield  <[email protected]>
+
         [WebGPU] Allow for scheduling asynchronous work
         https://bugs.webkit.org/show_bug.cgi?id=237755
 

Modified: trunk/Source/WebGPU/WebGPU/Adapter.mm (291314 => 291315)


--- trunk/Source/WebGPU/WebGPU/Adapter.mm	2022-03-15 21:30:05 UTC (rev 291314)
+++ trunk/Source/WebGPU/WebGPU/Adapter.mm	2022-03-15 21:30:06 UTC (rev 291315)
@@ -120,9 +120,7 @@
         return;
     }
 
-    // See the comment in Device::setLabel() about why we're not setting the label here.
-
-    callback(WGPURequestDeviceStatus_Success, Device::create(m_device), nullptr);
+    callback(WGPURequestDeviceStatus_Success, Device::create(m_device, descriptor.label), nullptr);
 }
 
 } // namespace WebGPU
@@ -155,7 +153,11 @@
 void wgpuAdapterRequestDevice(WGPUAdapter adapter, const WGPUDeviceDescriptor* descriptor, WGPURequestDeviceCallback callback, void* 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);
+        if (device) {
+            auto& queue = device->getQueue();
+            callback(status, new WGPUDeviceImpl { device.releaseNonNull(), { queue } }, message, userdata);
+        } else
+            callback(status, nullptr, message, userdata);
     });
 }
 
@@ -162,6 +164,10 @@
 void wgpuAdapterRequestDeviceWithBlock(WGPUAdapter adapter, WGPUDeviceDescriptor const * descriptor, WGPURequestDeviceBlockCallback callback)
 {
     adapter->adapter->requestDevice(*descriptor, [callback] (WGPURequestDeviceStatus status, RefPtr<WebGPU::Device>&& device, const char* message) {
-        callback(status, device ? new WGPUDeviceImpl { device.releaseNonNull() } : nullptr, message);
+        if (device) {
+            auto& queue = device->getQueue();
+            callback(status, new WGPUDeviceImpl { device.releaseNonNull(), { queue } }, message);
+        } else
+            callback(status, nullptr, message);
     });
 }

Modified: trunk/Source/WebGPU/WebGPU/Device.h (291314 => 291315)


--- trunk/Source/WebGPU/WebGPU/Device.h	2022-03-15 21:30:05 UTC (rev 291314)
+++ trunk/Source/WebGPU/WebGPU/Device.h	2022-03-15 21:30:06 UTC (rev 291315)
@@ -25,6 +25,7 @@
 
 #pragma once
 
+#import "Queue.h"
 #import <wtf/FastMalloc.h>
 #import <wtf/Function.h>
 #import <wtf/Ref.h>
@@ -47,12 +48,11 @@
 class Surface;
 class SwapChain;
 class Texture;
-class Queue;
 
 class Device : public RefCounted<Device> {
     WTF_MAKE_FAST_ALLOCATED;
 public:
-    static RefPtr<Device> create(id<MTLDevice>);
+    static RefPtr<Device> create(id<MTLDevice>, const char* deviceLabel);
 
     ~Device();
 
@@ -74,7 +74,7 @@
     void destroy();
     size_t enumerateFeatures(WGPUFeatureName* features);
     bool getLimits(WGPUSupportedLimits&);
-    RefPtr<Queue> getQueue();
+    Queue& getQueue();
     bool hasFeature(WGPUFeatureName);
     bool popErrorScope(WTF::Function<void(WGPUErrorType, const char*)>&& callback);
     void pushErrorScope(WGPUErrorFilter);
@@ -93,4 +93,5 @@
 
 struct WGPUDeviceImpl {
     Ref<WebGPU::Device> device;
+    WGPUQueueImpl defaultQueue;
 };

Modified: trunk/Source/WebGPU/WebGPU/Device.mm (291314 => 291315)


--- trunk/Source/WebGPU/WebGPU/Device.mm	2022-03-15 21:30:05 UTC (rev 291314)
+++ trunk/Source/WebGPU/WebGPU/Device.mm	2022-03-15 21:30:06 UTC (rev 291315)
@@ -45,7 +45,7 @@
 
 namespace WebGPU {
 
-RefPtr<Device> Device::create(id<MTLDevice> device)
+RefPtr<Device> Device::create(id<MTLDevice> device, const char* deviceLabel)
 {
     id<MTLCommandQueue> commandQueue = [device newCommandQueue];
     if (!commandQueue)
@@ -52,6 +52,12 @@
         return nullptr;
     auto queue = Queue::create(commandQueue);
 
+    // See the comment in Device::setLabel() about why we're not setting the label on the MTLDevice here.
+
+    commandQueue.label = @"Default queue";
+    if (deviceLabel && deviceLabel[0] != '\0')
+        commandQueue.label = [NSString stringWithFormat:@"Default queue for device %s", deviceLabel];
+
     return adoptRef(*new Device(device, WTFMove(queue)));
 }
 
@@ -84,9 +90,9 @@
     return true;
 }
 
-RefPtr<Queue> Device::getQueue()
+Queue& Device::getQueue()
 {
-    return m_defaultQueue.copyRef();
+    return m_defaultQueue;
 }
 
 bool Device::hasFeature(WGPUFeatureName)
@@ -255,8 +261,7 @@
 
 WGPUQueue wgpuDeviceGetQueue(WGPUDevice device)
 {
-    auto result = device->device->getQueue();
-    return result ? new WGPUQueueImpl { result.releaseNonNull() } : nullptr;
+    return &device->defaultQueue;
 }
 
 bool wgpuDeviceHasFeature(WGPUDevice device, WGPUFeatureName feature)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to