From bf3243568c9b55a58594c401b10aa4e31c6acb8d Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 18 Aug 2022 18:02:00 +0000 Subject: [PATCH] Add DeviceBase::APIGetAdapter Adds a way to query the adapter from a device. Only valid in Dawn Native. Returns a new reference to the caller. The caller is responsible for releasing it. This is needed so in Chrome, SharedImage can query the WGPUAdapter from the WGPUDevice, and then WGPUAdapterProperties may be queried from the WGPUAdapter. Change-Id: I719a8728eff06ab7a22be3db5fb5cfd2ebb2f0f7 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/99703 Reviewed-by: Zhenyao Mo Commit-Queue: Austin Eng --- dawn.json | 5 +++++ dawn_wire.json | 1 + src/dawn/native/Device.cpp | 5 +++++ src/dawn/native/Device.h | 1 + src/dawn/wire/client/Device.cpp | 6 ++++++ src/dawn/wire/client/Device.h | 1 + 6 files changed, 19 insertions(+) diff --git a/dawn.json b/dawn.json index 3d6ead9f74..e07bb57b75 100644 --- a/dawn.json +++ b/dawn.json @@ -1141,6 +1141,11 @@ {"name": "features", "type": "feature name", "annotation": "*"} ] }, + { + "name": "get adapter", + "returns": "adapter", + "tags": ["dawn"] + }, { "name": "get queue", "returns": "queue" diff --git a/dawn_wire.json b/dawn_wire.json index 55098d006a..c26d4cdcad 100644 --- a/dawn_wire.json +++ b/dawn_wire.json @@ -224,6 +224,7 @@ "DeviceCreateQuerySet", "DeviceCreateTexture", "DeviceCreateErrorTexture", + "DeviceGetAdapter", "DeviceGetQueue", "DeviceInjectError" ], diff --git a/src/dawn/native/Device.cpp b/src/dawn/native/Device.cpp index e3145a9246..f737e47d09 100644 --- a/src/dawn/native/Device.cpp +++ b/src/dawn/native/Device.cpp @@ -1284,6 +1284,11 @@ MaybeError DeviceBase::Tick() { return {}; } +AdapterBase* DeviceBase::APIGetAdapter() { + mAdapter->Reference(); + return mAdapter; +} + QueueBase* DeviceBase::APIGetQueue() { // Backends gave the primary queue during initialization. ASSERT(mQueue != nullptr); diff --git a/src/dawn/native/Device.h b/src/dawn/native/Device.h index 0a046457b9..b8b145b032 100644 --- a/src/dawn/native/Device.h +++ b/src/dawn/native/Device.h @@ -269,6 +269,7 @@ class DeviceBase : public RefCountedWithExternalCount { ExternalTextureBase* APICreateErrorExternalTexture(); TextureBase* APICreateErrorTexture(const TextureDescriptor* desc); + AdapterBase* APIGetAdapter(); QueueBase* APIGetQueue(); bool APIGetLimits(SupportedLimits* limits) const; diff --git a/src/dawn/wire/client/Device.cpp b/src/dawn/wire/client/Device.cpp index ace00a1839..f2bffe2cdf 100644 --- a/src/dawn/wire/client/Device.cpp +++ b/src/dawn/wire/client/Device.cpp @@ -216,6 +216,12 @@ WGPUTexture Device::CreateErrorTexture(const WGPUTextureDescriptor* descriptor) return Texture::CreateError(this, descriptor); } +WGPUAdapter Device::GetAdapter() { + // Not implemented in the wire. + UNREACHABLE(); + return nullptr; +} + WGPUQueue Device::GetQueue() { // The queue is lazily created because if a Device is created by // Reserve/Inject, we cannot send the GetQueue message until diff --git a/src/dawn/wire/client/Device.h b/src/dawn/wire/client/Device.h index d1af3432fd..6e021feba9 100644 --- a/src/dawn/wire/client/Device.h +++ b/src/dawn/wire/client/Device.h @@ -71,6 +71,7 @@ class Device final : public ObjectBase { void SetLimits(const WGPUSupportedLimits* limits); void SetFeatures(const WGPUFeatureName* features, uint32_t featuresCount); + WGPUAdapter GetAdapter(); // Not implemented in the wire. WGPUQueue GetQueue(); void CancelCallbacksForDisconnect() override;