diff --git a/dom/webgpu/Instance.cpp b/dom/webgpu/Instance.cpp index 1453b91fc915..07c91d20d1b2 100644 --- a/dom/webgpu/Instance.cpp +++ b/dom/webgpu/Instance.cpp @@ -12,7 +12,7 @@ #include "ipc/WebGPUTypes.h" #include "mozilla/webgpu/ffi/wgpu.h" #include "mozilla/dom/Promise.h" -#include "mozilla/layers/CompositorBridgeChild.h" +#include "mozilla/gfx/CanvasManagerChild.h" namespace mozilla { namespace webgpu { @@ -24,7 +24,7 @@ already_AddRefed Instance::Create(nsIGlobalObject* aOwner) { RefPtr bridge; if (gfx::gfxConfig::IsEnabled(gfx::Feature::WEBGPU)) { - bridge = layers::CompositorBridgeChild::Get()->GetWebGPUChild(); + bridge = gfx::CanvasManagerChild::Get()->GetWebGPUChild(); if (NS_WARN_IF(!bridge)) { MOZ_CRASH("Failed to create an IPDL bridge for WebGPU!"); } diff --git a/dom/webgpu/ipc/PWebGPU.ipdl b/dom/webgpu/ipc/PWebGPU.ipdl index b93a7a98eae2..d47cc19f085e 100644 --- a/dom/webgpu/ipc/PWebGPU.ipdl +++ b/dom/webgpu/ipc/PWebGPU.ipdl @@ -16,7 +16,7 @@ using MaybeScopedError from "mozilla/webgpu/WebGPUTypes.h"; include "mozilla/ipc/ByteBufUtils.h"; include "mozilla/webgpu/WebGPUSerialize.h"; include "mozilla/layers/WebRenderMessageUtils.h"; -include protocol PCompositorBridge; +include protocol PCanvasManager; namespace mozilla { namespace webgpu { @@ -26,9 +26,9 @@ namespace webgpu { * command from the content process, and a WebGPUParent in the compositor * process that runs the commands. */ -async protocol PWebGPU +[RefCounted] async protocol PWebGPU { - manager PCompositorBridge; + manager PCanvasManager; parent: async DeviceAction(RawId selfId, ByteBuf buf); @@ -70,8 +70,6 @@ parent: async DevicePushErrorScope(RawId selfId); async DevicePopErrorScope(RawId selfId) returns (MaybeScopedError maybeError); - async Shutdown(); - child: async DeviceUncapturedError(RawId aDeviceId, nsCString message); async DropAction(ByteBuf buf); diff --git a/dom/webgpu/ipc/WebGPUChild.cpp b/dom/webgpu/ipc/WebGPUChild.cpp index ce1e39a64e8b..c908d7e13e25 100644 --- a/dom/webgpu/ipc/WebGPUChild.cpp +++ b/dom/webgpu/ipc/WebGPUChild.cpp @@ -164,7 +164,7 @@ static ffi::WGPUClient* initialize() { return infra.client; } -WebGPUChild::WebGPUChild() : mClient(initialize()), mIPCOpen(false) {} +WebGPUChild::WebGPUChild() : mClient(initialize()) {} WebGPUChild::~WebGPUChild() { if (mClient) { diff --git a/dom/webgpu/ipc/WebGPUChild.h b/dom/webgpu/ipc/WebGPUChild.h index 984d1e2e5567..fcfe4447acde 100644 --- a/dom/webgpu/ipc/WebGPUChild.h +++ b/dom/webgpu/ipc/WebGPUChild.h @@ -49,12 +49,12 @@ class WebGPUChild final : public PWebGPUChild, public SupportsWeakPtr { friend class layers::CompositorBridgeChild; NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(WebGPUChild) - NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(WebGPUChild) + NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING_INHERITED(WebGPUChild) public: explicit WebGPUChild(); - bool IsOpen() const { return mIPCOpen; } + bool IsOpen() const { return CanSend(); } RefPtr InstanceRequestAdapter( const dom::GPURequestAdapterOptions& aOptions); @@ -124,24 +124,7 @@ class WebGPUChild final : public PWebGPUChild, public SupportsWeakPtr { const dom::GPURenderPipelineDescriptor& aDesc, ipc::ByteBuf* const aByteBuf); - // AddIPDLReference and ReleaseIPDLReference are only to be called by - // CompositorBridgeChild's AllocPWebGPUChild and DeallocPWebGPUChild methods - // respectively. We intentionally make them private to prevent misuse. - // The purpose of these methods is to be aware of when the IPC system around - // this actor goes down: mIPCOpen is then set to false. - void AddIPDLReference() { - MOZ_ASSERT(!mIPCOpen); - mIPCOpen = true; - AddRef(); - } - void ReleaseIPDLReference() { - MOZ_ASSERT(mIPCOpen); - mIPCOpen = false; - Release(); - } - ffi::WGPUClient* const mClient; - bool mIPCOpen; std::unordered_map> mDeviceMap; public: diff --git a/dom/webgpu/ipc/WebGPUParent.cpp b/dom/webgpu/ipc/WebGPUParent.cpp index 51d37c55b416..faeb92f27a77 100644 --- a/dom/webgpu/ipc/WebGPUParent.cpp +++ b/dom/webgpu/ipc/WebGPUParent.cpp @@ -738,7 +738,7 @@ ipc::IPCResult WebGPUParent::RecvSwapChainDestroy( return IPC_OK(); } -ipc::IPCResult WebGPUParent::RecvShutdown() { +void WebGPUParent::ActorDestroy(ActorDestroyReason aWhy) { mTimer.Stop(); for (const auto& p : mCanvasMap) { const wr::ExternalImageId extId = {p.first}; @@ -747,7 +747,6 @@ ipc::IPCResult WebGPUParent::RecvShutdown() { mCanvasMap.clear(); ffi::wgpu_server_poll_all_devices(mContext, true); ffi::wgpu_server_delete(const_cast(mContext)); - return IPC_OK(); } ipc::IPCResult WebGPUParent::RecvDeviceAction(RawId aSelf, diff --git a/dom/webgpu/ipc/WebGPUParent.h b/dom/webgpu/ipc/WebGPUParent.h index 97eef2f6b916..f9cf65514552 100644 --- a/dom/webgpu/ipc/WebGPUParent.h +++ b/dom/webgpu/ipc/WebGPUParent.h @@ -21,7 +21,7 @@ struct ErrorScopeStack { }; class WebGPUParent final : public PWebGPUParent { - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebGPUParent) + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WebGPUParent, override) public: explicit WebGPUParent(); @@ -90,7 +90,7 @@ class WebGPUParent final : public PWebGPUParent { ipc::IPCResult RecvDevicePopErrorScope( RawId aSelfId, DevicePopErrorScopeResolver&& aResolver); - ipc::IPCResult RecvShutdown(); + void ActorDestroy(ActorDestroyReason aWhy) override; private: virtual ~WebGPUParent(); diff --git a/gfx/ipc/CanvasManagerChild.cpp b/gfx/ipc/CanvasManagerChild.cpp index 66ccd7b7b65a..e4dd68696160 100644 --- a/gfx/ipc/CanvasManagerChild.cpp +++ b/gfx/ipc/CanvasManagerChild.cpp @@ -11,6 +11,7 @@ #include "mozilla/gfx/Swizzle.h" #include "mozilla/ipc/Endpoint.h" #include "mozilla/layers/CompositorManagerChild.h" +#include "mozilla/webgpu/WebGPUChild.h" using namespace mozilla::dom; using namespace mozilla::layers; @@ -131,6 +132,17 @@ void CanvasManagerChild::Destroy() { return manager; } +RefPtr CanvasManagerChild::GetWebGPUChild() { + if (!mWebGPUChild) { + mWebGPUChild = MakeAndAddRef(); + if (!SendPWebGPUConstructor(mWebGPUChild)) { + mWebGPUChild = nullptr; + } + } + + return mWebGPUChild; +} + already_AddRefed CanvasManagerChild::GetSnapshot( uint32_t aManagerId, int32_t aProtocolId, bool aHasAlpha) { if (!CanSend()) { diff --git a/gfx/ipc/CanvasManagerChild.h b/gfx/ipc/CanvasManagerChild.h index 900fe851c41a..2538e3c17bca 100644 --- a/gfx/ipc/CanvasManagerChild.h +++ b/gfx/ipc/CanvasManagerChild.h @@ -16,6 +16,10 @@ class IPCWorkerRef; class WorkerPrivate; } // namespace dom +namespace webgpu { +class WebGPUChild; +} // namespace webgpu + namespace gfx { class DataSourceSurface; @@ -35,11 +39,14 @@ class CanvasManagerChild final : public PCanvasManagerChild { static bool CreateParent( mozilla::ipc::Endpoint&& aEndpoint); + RefPtr GetWebGPUChild(); + private: ~CanvasManagerChild(); void Destroy(); RefPtr mWorkerRef; + RefPtr mWebGPUChild; const uint32_t mId; static MOZ_THREAD_LOCAL(CanvasManagerChild*) sLocalManager; diff --git a/gfx/ipc/CanvasManagerParent.cpp b/gfx/ipc/CanvasManagerParent.cpp index 47f7e33ef99b..b0211091094d 100644 --- a/gfx/ipc/CanvasManagerParent.cpp +++ b/gfx/ipc/CanvasManagerParent.cpp @@ -9,6 +9,7 @@ #include "mozilla/gfx/gfxVars.h" #include "mozilla/ipc/Endpoint.h" #include "mozilla/layers/CompositorThread.h" +#include "mozilla/webgpu/WebGPUParent.h" #include "mozilla/webrender/RenderThread.h" #include "nsIThread.h" @@ -87,6 +88,11 @@ already_AddRefed CanvasManagerParent::AllocPWebGLParent() { return MakeAndAddRef(); } +already_AddRefed +CanvasManagerParent::AllocPWebGPUParent() { + return MakeAndAddRef(); +} + mozilla::ipc::IPCResult CanvasManagerParent::RecvInitialize( const uint32_t& aId) { if (!aId) { diff --git a/gfx/ipc/CanvasManagerParent.h b/gfx/ipc/CanvasManagerParent.h index a0966bd7b777..6cf0e7138be1 100644 --- a/gfx/ipc/CanvasManagerParent.h +++ b/gfx/ipc/CanvasManagerParent.h @@ -23,7 +23,10 @@ class CanvasManagerParent final : public PCanvasManagerParent { void Bind(Endpoint&& aEndpoint); void ActorDestroy(ActorDestroyReason aWhy) override; + already_AddRefed AllocPWebGLParent(); + already_AddRefed AllocPWebGPUParent(); + mozilla::ipc::IPCResult RecvInitialize(const uint32_t& aId); mozilla::ipc::IPCResult RecvGetSnapshot( const uint32_t& aManagerId, const int32_t& aProtocolId, diff --git a/gfx/ipc/PCanvasManager.ipdl b/gfx/ipc/PCanvasManager.ipdl index 65e7f0e50ceb..63778986ee71 100644 --- a/gfx/ipc/PCanvasManager.ipdl +++ b/gfx/ipc/PCanvasManager.ipdl @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ include protocol PWebGL; +include protocol PWebGPU; using mozilla::webgl::FrontBufferSnapshotIpc from "mozilla/dom/WebGLIpdl.h"; @@ -21,11 +22,15 @@ namespace gfx { [RefCounted] sync protocol PCanvasManager { manages PWebGL; + manages PWebGPU; parent: // Actor that represents one WebGL context. async PWebGL(); + // Actor that represents one WebGPU context. + async PWebGPU(); + // Set the local manager ID for the canvas manager. async Initialize(uint32_t aManagerId); diff --git a/gfx/layers/ipc/CompositorBridgeChild.cpp b/gfx/layers/ipc/CompositorBridgeChild.cpp index 1fe1ec2f0f9d..e087985b8dae 100644 --- a/gfx/layers/ipc/CompositorBridgeChild.cpp +++ b/gfx/layers/ipc/CompositorBridgeChild.cpp @@ -26,7 +26,6 @@ #include "mozilla/gfx/GPUProcessManager.h" #include "mozilla/gfx/Logging.h" #include "mozilla/ipc/Endpoint.h" -#include "mozilla/webgpu/WebGPUChild.h" #include "mozilla/mozalloc.h" // for operator new, etc #include "mozilla/Telemetry.h" #include "gfxConfig.h" @@ -177,12 +176,6 @@ void CompositorBridgeChild::Destroy() { Unused << child->SendDestroy(); } - AutoTArray webGPUChildren; - ManagedPWebGPUChild(webGPUChildren); - for (PWebGPUChild* child : webGPUChildren) { - Unused << child->SendShutdown(); - } - const ManagedContainer& textures = ManagedPTextureChild(); for (const auto& key : textures) { RefPtr texture = TextureClient::AsTextureClient(key); @@ -580,16 +573,6 @@ void CompositorBridgeChild::EndCanvasTransaction() { } } -RefPtr CompositorBridgeChild::GetWebGPUChild() { - MOZ_ASSERT(gfx::gfxConfig::IsEnabled(gfx::Feature::WEBGPU)); - if (!mWebGPUChild) { - webgpu::PWebGPUChild* bridge = SendPWebGPUConstructor(); - mWebGPUChild = static_cast(bridge); - } - - return mWebGPUChild; -} - bool CompositorBridgeChild::AllocUnsafeShmem( size_t aSize, ipc::SharedMemory::SharedMemoryType aType, ipc::Shmem* aShmem) { @@ -672,18 +655,6 @@ bool CompositorBridgeChild::DeallocPWebRenderBridgeChild( return true; } -webgpu::PWebGPUChild* CompositorBridgeChild::AllocPWebGPUChild() { - webgpu::WebGPUChild* child = new webgpu::WebGPUChild(); - child->AddIPDLReference(); - return child; -} - -bool CompositorBridgeChild::DeallocPWebGPUChild(webgpu::PWebGPUChild* aActor) { - webgpu::WebGPUChild* child = static_cast(aActor); - child->ReleaseIPDLReference(); - return true; -} - uint64_t CompositorBridgeChild::GetNextResourceId() { ++mResourceId; MOZ_RELEASE_ASSERT(mResourceId != UINT32_MAX); diff --git a/gfx/layers/ipc/CompositorBridgeChild.h b/gfx/layers/ipc/CompositorBridgeChild.h index 49cc4886df06..eff6f6e5f156 100644 --- a/gfx/layers/ipc/CompositorBridgeChild.h +++ b/gfx/layers/ipc/CompositorBridgeChild.h @@ -29,11 +29,6 @@ namespace dom { class BrowserChild; } // namespace dom -namespace webgpu { -class PWebGPUChild; -class WebGPUChild; -} // namespace webgpu - namespace widget { class CompositorWidget; } // namespace widget @@ -111,8 +106,6 @@ class CompositorBridgeChild final : public PCompositorBridgeChild, void EndCanvasTransaction(); - RefPtr GetWebGPUChild(); - // Beware that these methods don't override their super-class equivalent // (which are not virtual), they just overload them. All of these Send* // methods just add a sanity check (that it is not too late send a message) @@ -182,9 +175,6 @@ class CompositorBridgeChild final : public PCompositorBridgeChild, const WindowKind&); bool DeallocPWebRenderBridgeChild(PWebRenderBridgeChild* aActor); - webgpu::PWebGPUChild* AllocPWebGPUChild(); - bool DeallocPWebGPUChild(webgpu::PWebGPUChild* aActor); - wr::MaybeExternalImageId GetNextExternalImageId() override; wr::PipelineId GetNextPipelineId(); @@ -258,8 +248,6 @@ class CompositorBridgeChild final : public PCompositorBridgeChild, nsTArray> mTextureClientsForAsyncPaint; RefPtr mCanvasChild; - - RefPtr mWebGPUChild; }; } // namespace layers diff --git a/gfx/layers/ipc/CompositorBridgeParent.cpp b/gfx/layers/ipc/CompositorBridgeParent.cpp index a6871ad8f696..45d8b6c496e9 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.cpp +++ b/gfx/layers/ipc/CompositorBridgeParent.cpp @@ -57,7 +57,6 @@ #include "mozilla/layers/WebRenderBridgeParent.h" #include "mozilla/layers/AsyncImagePipelineManager.h" #include "mozilla/webrender/WebRenderAPI.h" -#include "mozilla/webgpu/WebGPUParent.h" #include "mozilla/webrender/RenderThread.h" #include "mozilla/media/MediaSystemResourceService.h" // for MediaSystemResourceService #include "mozilla/mozalloc.h" // for operator new, etc @@ -1289,28 +1288,6 @@ bool CompositorBridgeParent::DeallocPWebRenderBridgeParent( return true; } -webgpu::PWebGPUParent* CompositorBridgeParent::AllocPWebGPUParent() { - // This should only ever get called in the GPU process. - MOZ_ASSERT(XRE_IsGPUProcess()); - // Shouldn't re-initialize - MOZ_ASSERT(!mWebGPUBridge); - // We should only ever get this if WebGPU is enabled in this compositor. - MOZ_RELEASE_ASSERT(mOptions.UseWebGPU()); - - mWebGPUBridge = new webgpu::WebGPUParent(); - mWebGPUBridge.get()->AddRef(); // IPDL reference - return mWebGPUBridge; -} - -bool CompositorBridgeParent::DeallocPWebGPUParent( - webgpu::PWebGPUParent* aActor) { - webgpu::WebGPUParent* parent = static_cast(aActor); - MOZ_ASSERT(mWebGPUBridge == parent); - parent->Release(); // IPDL reference - mWebGPUBridge = nullptr; - return true; -} - void CompositorBridgeParent::NotifyMemoryPressure() { if (mWrBridge) { RefPtr api = mWrBridge->GetWebRenderAPI(); diff --git a/gfx/layers/ipc/CompositorBridgeParent.h b/gfx/layers/ipc/CompositorBridgeParent.h index 220e5e9f26c1..5a332cecf63a 100644 --- a/gfx/layers/ipc/CompositorBridgeParent.h +++ b/gfx/layers/ipc/CompositorBridgeParent.h @@ -50,11 +50,6 @@ class ProtocolFuzzerHelper; #endif } // namespace ipc -namespace webgpu { -class PWebGPUParent; -class WebGPUParent; -} // namespace webgpu - namespace widget { class CompositorWidget; } @@ -207,9 +202,6 @@ class CompositorBridgeParentBase : public PCompositorBridgeParent, virtual bool DeallocPWebRenderBridgeParent( PWebRenderBridgeParent* aActor) = 0; - virtual webgpu::PWebGPUParent* AllocPWebGPUParent() = 0; - virtual bool DeallocPWebGPUParent(webgpu::PWebGPUParent* aActor) = 0; - virtual PCompositorWidgetParent* AllocPCompositorWidgetParent( const CompositorWidgetInitData& aInitData) = 0; virtual bool DeallocPCompositorWidgetParent( @@ -555,9 +547,6 @@ class CompositorBridgeParent final : public CompositorBridgeParentBase, RefPtr GetWebRenderBridgeParent() const; Maybe GetTestingTimeStamp() const; - webgpu::PWebGPUParent* AllocPWebGPUParent() override; - bool DeallocPWebGPUParent(webgpu::PWebGPUParent* aActor) override; - static CompositorBridgeParent* GetCompositorBridgeParentFromLayersId( const LayersId& aLayersId); static RefPtr GetCompositorBridgeParentFromWindowId( @@ -572,7 +561,6 @@ class CompositorBridgeParent final : public CompositorBridgeParentBase, LayersId aLayersId); WebRenderBridgeParent* GetWrBridge() { return mWrBridge; } - webgpu::WebGPUParent* GetWebGPUBridge() { return mWebGPUBridge; } private: void Initialize(); @@ -686,7 +674,6 @@ class CompositorBridgeParent final : public CompositorBridgeParentBase, RefPtr mCompositor; RefPtr mAsyncImageManager; RefPtr mWrBridge; - RefPtr mWebGPUBridge; widget::CompositorWidget* mWidget; Maybe mTestTime; CSSToLayoutDeviceScale mScale; diff --git a/gfx/layers/ipc/ContentCompositorBridgeParent.cpp b/gfx/layers/ipc/ContentCompositorBridgeParent.cpp index c81171519240..588e928b095a 100644 --- a/gfx/layers/ipc/ContentCompositorBridgeParent.cpp +++ b/gfx/layers/ipc/ContentCompositorBridgeParent.cpp @@ -24,7 +24,6 @@ #include "mozilla/layers/RemoteContentController.h" #include "mozilla/layers/WebRenderBridgeParent.h" #include "mozilla/layers/AsyncImagePipelineManager.h" -#include "mozilla/webgpu/WebGPUParent.h" #include "mozilla/mozalloc.h" // for operator new, etc #include "nsDebug.h" // for NS_ASSERTION, etc #include "nsTArray.h" // for nsTArray @@ -205,19 +204,6 @@ bool ContentCompositorBridgeParent::DeallocPWebRenderBridgeParent( return true; } -webgpu::PWebGPUParent* ContentCompositorBridgeParent::AllocPWebGPUParent() { - webgpu::WebGPUParent* parent = new webgpu::WebGPUParent(); - parent->AddRef(); // IPDL reference - return parent; -} - -bool ContentCompositorBridgeParent::DeallocPWebGPUParent( - webgpu::PWebGPUParent* aActor) { - webgpu::WebGPUParent* parent = static_cast(aActor); - parent->Release(); // IPDL reference - return true; -} - mozilla::ipc::IPCResult ContentCompositorBridgeParent::RecvNotifyChildCreated( const LayersId& child, CompositorOptions* aOptions) { MonitorAutoLock lock(*sIndirectLayerTreesLock); diff --git a/gfx/layers/ipc/ContentCompositorBridgeParent.h b/gfx/layers/ipc/ContentCompositorBridgeParent.h index 00fbece5136e..f06842cde0c3 100644 --- a/gfx/layers/ipc/ContentCompositorBridgeParent.h +++ b/gfx/layers/ipc/ContentCompositorBridgeParent.h @@ -12,12 +12,7 @@ #include "mozilla/layers/CompositorThread.h" #include "mozilla/UniquePtr.h" -namespace mozilla { -namespace webgpu { -class PWebGPUParent; -} // namespace webgpu - -namespace layers { +namespace mozilla::layers { class CompositorOptions; @@ -169,9 +164,6 @@ class ContentCompositorBridgeParent final : public CompositorBridgeParentBase { const WindowKind& aWindowKind) override; bool DeallocPWebRenderBridgeParent(PWebRenderBridgeParent* aActor) override; - webgpu::PWebGPUParent* AllocPWebGPUParent() override; - bool DeallocPWebGPUParent(webgpu::PWebGPUParent* aActor) override; - void ObserveLayersUpdate(LayersId aLayersId, LayersObserverEpoch aEpoch, bool aActive) override; @@ -196,7 +188,6 @@ class ContentCompositorBridgeParent final : public CompositorBridgeParentBase { RefPtr mCanvasTranslator; }; -} // namespace layers -} // namespace mozilla +} // namespace mozilla::layers #endif // mozilla_layers_ContentCompositorBridgeParent_h diff --git a/gfx/layers/ipc/PCompositorBridge.ipdl b/gfx/layers/ipc/PCompositorBridge.ipdl index 6e0f723f8c16..a1b1d1e5dffc 100644 --- a/gfx/layers/ipc/PCompositorBridge.ipdl +++ b/gfx/layers/ipc/PCompositorBridge.ipdl @@ -17,7 +17,6 @@ include protocol PCompositorManager; include protocol PCompositorWidget; include protocol PTexture; include protocol PWebRenderBridge; -include protocol PWebGPU; include "mozilla/GfxMessageUtils.h"; include "mozilla/layers/LayersMessageUtils.h"; include "mozilla/layers/WebRenderMessageUtils.h"; @@ -98,7 +97,6 @@ struct FrameStats { manages PTexture; manages PCompositorWidget; manages PWebRenderBridge; - manages PWebGPU; child: // The child should invalidate retained layers. This is used for local @@ -139,10 +137,6 @@ parent: async PAPZ(LayersId layersId); async PAPZCTreeManager(LayersId layersId); - // Constructor for WebGPU IPDL - // Must be called before Initialize(). - async PWebGPU(); - // The child is about to be destroyed, so perform any necessary cleanup. sync WillClose();