From c4c52fc4b65badbc91a2971d8557b95ff306186e Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 8 Dec 2021 15:54:26 +0000 Subject: [PATCH] WIP: Bug 1622846 - Support WebGPU adapter isFallbackAdapter r=emilio Differential Revision: https://phabricator.services.mozilla.com/D133208 --- dom/webgpu/Adapter.cpp | 3 +-- dom/webgpu/Adapter.h | 4 ++-- dom/webgpu/ipc/WebGPUParent.cpp | 1 + dom/webgpu/ipc/WebGPUSerialize.h | 2 +- dom/webidl/WebGPU.webidl | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/dom/webgpu/Adapter.cpp b/dom/webgpu/Adapter.cpp index 29f7e5fa1f44..6a3653fb0caa 100644 --- a/dom/webgpu/Adapter.cpp +++ b/dom/webgpu/Adapter.cpp @@ -26,7 +26,7 @@ Adapter::Adapter(Instance* const aParent, mId(aInfo.id), mFeatures(new AdapterFeatures(this)), mLimits(new SupportedLimits(this, aInfo.limits)), - mIsSoftware(aInfo.ty == ffi::WGPUDeviceType_Cpu) {} + mIsFallbackAdapter(aInfo.ty == ffi::WGPUDeviceType_Cpu) {} Adapter::~Adapter() { Cleanup(); } @@ -39,7 +39,6 @@ void Adapter::Cleanup() { const RefPtr& Adapter::Features() const { return mFeatures; } const RefPtr& Adapter::Limits() const { return mLimits; } -bool Adapter::IsSoftware() const { return mIsSoftware; } already_AddRefed Adapter::RequestDevice( const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv) { diff --git a/dom/webgpu/Adapter.h b/dom/webgpu/Adapter.h index 8cee1d451e64..bcd14d79f9c2 100644 --- a/dom/webgpu/Adapter.h +++ b/dom/webgpu/Adapter.h @@ -47,14 +47,14 @@ class Adapter final : public ObjectBase, public ChildOf { // to unlink them in CC unlink. RefPtr mFeatures; RefPtr mLimits; - const bool mIsSoftware = false; + const bool mIsFallbackAdapter = false; public: Adapter(Instance* const aParent, const ffi::WGPUAdapterInformation& aInfo); void GetName(nsString& out) const { out = mName; } const RefPtr& Features() const; const RefPtr& Limits() const; - bool IsSoftware() const; + bool IsFallbackAdapter() const { return mIsFallbackAdapter; } already_AddRefed RequestDevice( const dom::GPUDeviceDescriptor& aDesc, ErrorResult& aRv); diff --git a/dom/webgpu/ipc/WebGPUParent.cpp b/dom/webgpu/ipc/WebGPUParent.cpp index 4aae3d14d8fc..8327b4ad2533 100644 --- a/dom/webgpu/ipc/WebGPUParent.cpp +++ b/dom/webgpu/ipc/WebGPUParent.cpp @@ -235,6 +235,7 @@ ipc::IPCResult WebGPUParent::RecvInstanceRequestAdapter( options.power_preference = static_cast( aOptions.mPowerPreference.Value()); } + options.force_fallback_adapter = aOptions.mForceFallbackAdapter; // TODO: make available backends configurable by prefs ErrorBuffer error; diff --git a/dom/webgpu/ipc/WebGPUSerialize.h b/dom/webgpu/ipc/WebGPUSerialize.h index 4eff8e43f1f8..18ed6f885369 100644 --- a/dom/webgpu/ipc/WebGPUSerialize.h +++ b/dom/webgpu/ipc/WebGPUSerialize.h @@ -31,7 +31,7 @@ DEFINE_IPC_SERIALIZER_FFI_ENUM(mozilla::webgpu::ffi::WGPUHostMap); DEFINE_IPC_SERIALIZER_WITHOUT_FIELDS(mozilla::dom::GPUCommandBufferDescriptor); DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::GPURequestAdapterOptions, - mPowerPreference); + mPowerPreference, mForceFallbackAdapter); DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::webgpu::ScopedError, operationError, validationMessage); diff --git a/dom/webidl/WebGPU.webidl b/dom/webidl/WebGPU.webidl index 094a454af348..1bb84cfbfdf8 100644 --- a/dom/webidl/WebGPU.webidl +++ b/dom/webidl/WebGPU.webidl @@ -82,6 +82,7 @@ enum GPUPowerPreference { dictionary GPURequestAdapterOptions { GPUPowerPreference powerPreference; + boolean forceFallbackAdapter = false; }; [Pref="dom.webgpu.enabled", @@ -132,7 +133,7 @@ interface GPUAdapter { readonly attribute DOMString name; [SameObject] readonly attribute GPUAdapterFeatures features; [SameObject] readonly attribute GPUSupportedLimits limits; - readonly attribute boolean isSoftware; + readonly attribute boolean isFallbackAdapter; [NewObject] Promise requestDevice(optional GPUDeviceDescriptor descriptor = {});