mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-20 18:29:23 +00:00
Make the Device ref the Instance
This is needed before supporting instances, adapters, and devices on the wire so that the client cannot free the instance before the device. In Dawn native, the developer still needs to make sure the device is not freed before all child objects. Bug: dawn:384 Change-Id: I863d44c6a8acecc7b8ea0cc0ac483f7a864162fd Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/37003 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
8ef94f1684
commit
f6ef7530ab
@@ -84,7 +84,7 @@ namespace dawn_native {
|
||||
// DeviceBase
|
||||
|
||||
DeviceBase::DeviceBase(AdapterBase* adapter, const DeviceDescriptor* descriptor)
|
||||
: mAdapter(adapter) {
|
||||
: mInstance(adapter->GetInstance()), mAdapter(adapter) {
|
||||
if (descriptor != nullptr) {
|
||||
ApplyToggleOverrides(descriptor);
|
||||
ApplyExtensions(descriptor);
|
||||
@@ -94,8 +94,7 @@ namespace dawn_native {
|
||||
SetDefaultToggles();
|
||||
}
|
||||
|
||||
DeviceBase::~DeviceBase() {
|
||||
}
|
||||
DeviceBase::~DeviceBase() = default;
|
||||
|
||||
MaybeError DeviceBase::Initialize(QueueBase* defaultQueue) {
|
||||
mDefaultQueue = AcquireRef(defaultQueue);
|
||||
|
||||
@@ -364,6 +364,11 @@ namespace dawn_native {
|
||||
wgpu::DeviceLostCallback mDeviceLostCallback = nullptr;
|
||||
void* mDeviceLostUserdata = nullptr;
|
||||
|
||||
// The Device keeps a ref to the Instance so that any live Device keeps the Instance alive.
|
||||
// The Instance shouldn't need to ref child objects so this shouldn't introduce ref cycles.
|
||||
// The Device keeps a simple pointer to the Adapter because the Adapter is owned by the
|
||||
// Instance.
|
||||
Ref<InstanceBase> mInstance;
|
||||
AdapterBase* mAdapter = nullptr;
|
||||
|
||||
Ref<ErrorScope> mRootErrorScope;
|
||||
|
||||
Reference in New Issue
Block a user