From 99b8081e31f4114c7cad96278e12d01df5b3360c Mon Sep 17 00:00:00 2001 From: Le Hoang Quyen Date: Fri, 24 Mar 2023 15:50:50 +0000 Subject: [PATCH] Add AdapterBase::APIGetInstance This method is useful for Chrome to query the Instance from Device by calling device.GetAdapter().GetInstance(). Then instance.ProcessEvents() can be used to poll for events instead of device.Tick(). Bug: dawn:1726 Change-Id: I45b5760bc07869a191ae3fd02ec25b99d78b068b Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125360 Reviewed-by: Corentin Wallez Commit-Queue: Quyen Le Kokoro: Kokoro Reviewed-by: Austin Eng --- dawn.json | 5 +++++ dawn_wire.json | 1 + src/dawn/native/Adapter.cpp | 7 +++++++ src/dawn/native/Adapter.h | 4 ++++ src/dawn/wire/client/Adapter.cpp | 5 +++++ src/dawn/wire/client/Adapter.h | 1 + 6 files changed, 23 insertions(+) diff --git a/dawn.json b/dawn.json index 1df0d7cd97..8913c2ca48 100644 --- a/dawn.json +++ b/dawn.json @@ -78,6 +78,11 @@ "adapter": { "category": "object", "methods": [ + { + "name": "get instance", + "tags": ["dawn"], + "returns": "instance" + }, { "name": "get limits", "returns": "bool", diff --git a/dawn_wire.json b/dawn_wire.json index 46cba66009..d8c57e97eb 100644 --- a/dawn_wire.json +++ b/dawn_wire.json @@ -219,6 +219,7 @@ "TextureGetUsage" ], "client_handwritten_commands": [ + "AdapterGetInstance", "BufferDestroy", "BufferUnmap", "DeviceCreateErrorBuffer", diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp index a60e900553..376956c7a5 100644 --- a/src/dawn/native/Adapter.cpp +++ b/src/dawn/native/Adapter.cpp @@ -83,6 +83,13 @@ MaybeError AdapterBase::Initialize() { return {}; } +InstanceBase* AdapterBase::APIGetInstance() const { + auto instance = GetInstance(); + ASSERT(instance != nullptr); + instance->Reference(); + return instance; +} + bool AdapterBase::APIGetLimits(SupportedLimits* limits) const { return GetLimits(limits); } diff --git a/src/dawn/native/Adapter.h b/src/dawn/native/Adapter.h index 9d0eb7c2c6..2e8897573e 100644 --- a/src/dawn/native/Adapter.h +++ b/src/dawn/native/Adapter.h @@ -43,6 +43,7 @@ class AdapterBase : public RefCounted { MaybeError Initialize(); // WebGPU API + InstanceBase* APIGetInstance() const; bool APIGetLimits(SupportedLimits* limits) const; void APIGetProperties(AdapterProperties* properties) const; bool APIHasFeature(wgpu::FeatureName feature) const; @@ -56,6 +57,9 @@ class AdapterBase : public RefCounted { uint32_t GetDeviceId() const; const gpu_info::DriverVersion& GetDriverVersion() const; wgpu::BackendType GetBackendType() const; + + // This method differs from APIGetInstance() in that it won't increase the ref count of the + // instance. InstanceBase* GetInstance() const; void ResetInternalDeviceForTesting(); diff --git a/src/dawn/wire/client/Adapter.cpp b/src/dawn/wire/client/Adapter.cpp index 6edf63c813..becca1c3f2 100644 --- a/src/dawn/wire/client/Adapter.cpp +++ b/src/dawn/wire/client/Adapter.cpp @@ -127,6 +127,11 @@ bool Adapter::OnRequestDeviceCallback(uint64_t requestSerial, return true; } +WGPUInstance Adapter::GetInstance() const { + dawn::ErrorLog() << "adapter.GetInstance not supported with dawn_wire."; + return nullptr; +} + WGPUDevice Adapter::CreateDevice(const WGPUDeviceDescriptor*) { dawn::ErrorLog() << "adapter.CreateDevice not supported with dawn_wire."; return nullptr; diff --git a/src/dawn/wire/client/Adapter.h b/src/dawn/wire/client/Adapter.h index 9c4b36fe38..69e8fff417 100644 --- a/src/dawn/wire/client/Adapter.h +++ b/src/dawn/wire/client/Adapter.h @@ -51,6 +51,7 @@ class Adapter final : public ObjectBase { const WGPUFeatureName* features); // Unimplementable. Only availale in dawn_native. + WGPUInstance GetInstance() const; WGPUDevice CreateDevice(const WGPUDeviceDescriptor*); private: