mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-16 14:55:47 +00:00
Bug 1750817 - Fix WebGPU device cleanup r=jimb,jgilbert
Differential Revision: https://phabricator.services.mozilla.com/D136502
This commit is contained in:
parent
5fdc06d164
commit
41f4223223
@ -33,8 +33,9 @@ namespace webgpu {
|
||||
|
||||
mozilla::LazyLogModule gWebGPULog("WebGPU");
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED(Device, DOMEventTargetHelper, mBridge,
|
||||
mQueue)
|
||||
GPU_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_INHERITED(Device, DOMEventTargetHelper,
|
||||
mBridge, mQueue, mFeatures,
|
||||
mLimits);
|
||||
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED_0(Device, DOMEventTargetHelper)
|
||||
GPU_IMPL_JS_WRAP(Device)
|
||||
|
||||
@ -68,7 +69,7 @@ Device::Device(Adapter* const aParent, RawId aId,
|
||||
Device::~Device() { Cleanup(); }
|
||||
|
||||
void Device::Cleanup() {
|
||||
if (mValid && mBridge && mBridge->IsOpen()) {
|
||||
if (mValid && mBridge) {
|
||||
mValid = false;
|
||||
mBridge->UnregisterDevice(mId);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "nsTHashSet.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/WeakPtr.h"
|
||||
#include "mozilla/webgpu/WebGPUTypes.h"
|
||||
#include "mozilla/webrender/WebRenderAPI.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
@ -77,7 +78,7 @@ class WebGPUChild;
|
||||
|
||||
using MappingPromise = MozPromise<ipc::Shmem, ipc::ResponseRejectReason, true>;
|
||||
|
||||
class Device final : public DOMEventTargetHelper {
|
||||
class Device final : public DOMEventTargetHelper, public SupportsWeakPtr {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(Device, DOMEventTargetHelper)
|
||||
|
@ -84,6 +84,18 @@ class ObjectBase : public nsWrapperCache {
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END \
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(T)
|
||||
|
||||
#define GPU_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_INHERITED(T, P, ...) \
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(T) \
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(T, P) \
|
||||
tmp->Cleanup(); \
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(__VA_ARGS__) \
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER \
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_WEAK_PTR \
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END \
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(T, P) \
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(__VA_ARGS__) \
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
#define GPU_IMPL_CYCLE_COLLECTION(T, ...) \
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(T, AddRef) \
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(T, Release) \
|
||||
|
@ -934,7 +934,7 @@ ipc::IPCResult WebGPUChild::RecvDeviceUncapturedError(
|
||||
if (!aDeviceId || targetIter == mDeviceMap.end()) {
|
||||
JsWarning(nullptr, aMessage);
|
||||
} else {
|
||||
auto* target = targetIter->second;
|
||||
auto* target = targetIter->second.get();
|
||||
MOZ_ASSERT(target);
|
||||
// We don't want to spam the errors to the console indefinitely
|
||||
if (target->CheckNewWarning(aMessage)) {
|
||||
@ -985,7 +985,9 @@ void WebGPUChild::RegisterDevice(RawId aId, Device* aDevice) {
|
||||
|
||||
void WebGPUChild::UnregisterDevice(RawId aId) {
|
||||
mDeviceMap.erase(aId);
|
||||
SendDeviceDestroy(aId);
|
||||
if (IsOpen()) {
|
||||
SendDeviceDestroy(aId);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace webgpu
|
||||
|
@ -133,7 +133,7 @@ class WebGPUChild final : public PWebGPUChild, public SupportsWeakPtr {
|
||||
|
||||
ffi::WGPUClient* const mClient;
|
||||
bool mIPCOpen;
|
||||
std::unordered_map<RawId, Device*> mDeviceMap;
|
||||
std::unordered_map<RawId, WeakPtr<Device>> mDeviceMap;
|
||||
|
||||
public:
|
||||
ipc::IPCResult RecvDeviceUncapturedError(RawId aDeviceId,
|
||||
|
Loading…
Reference in New Issue
Block a user