diff --git a/src/dawn/wire/client/Adapter.cpp b/src/dawn/wire/client/Adapter.cpp index 3e9cbd2ac7..3f55044188 100644 --- a/src/dawn/wire/client/Adapter.cpp +++ b/src/dawn/wire/client/Adapter.cpp @@ -19,8 +19,6 @@ namespace dawn::wire::client { -Adapter::Adapter(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {} - Adapter::~Adapter() { mRequestDeviceRequests.CloseAll([](RequestDeviceData* request) { request->callback(WGPURequestDeviceStatus_Unknown, nullptr, diff --git a/src/dawn/wire/client/Adapter.h b/src/dawn/wire/client/Adapter.h index 024da0b249..de9d167aa6 100644 --- a/src/dawn/wire/client/Adapter.h +++ b/src/dawn/wire/client/Adapter.h @@ -27,7 +27,7 @@ namespace dawn::wire::client { class Adapter final : public ObjectBase { public: - Adapter(Client* client, uint32_t refcount, uint32_t id); + using ObjectBase::ObjectBase; ~Adapter(); void CancelCallbacksForDisconnect() override; diff --git a/src/dawn/wire/client/Buffer.cpp b/src/dawn/wire/client/Buffer.cpp index eb9fa617d0..0321031116 100644 --- a/src/dawn/wire/client/Buffer.cpp +++ b/src/dawn/wire/client/Buffer.cpp @@ -140,8 +140,6 @@ WGPUBuffer Buffer::CreateError(Device* device, const WGPUBufferDescriptor* descr return ToAPI(allocation->object.get()); } -Buffer::Buffer(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {} - Buffer::~Buffer() { ClearAllCallbacks(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback); FreeMappedData(); diff --git a/src/dawn/wire/client/Buffer.h b/src/dawn/wire/client/Buffer.h index 2644a4fe74..caeaa6f815 100644 --- a/src/dawn/wire/client/Buffer.h +++ b/src/dawn/wire/client/Buffer.h @@ -31,7 +31,7 @@ class Buffer final : public ObjectBase { static WGPUBuffer Create(Device* device, const WGPUBufferDescriptor* descriptor); static WGPUBuffer CreateError(Device* device, const WGPUBufferDescriptor* descriptor); - Buffer(Client* client, uint32_t refcount, uint32_t id); + using ObjectBase::ObjectBase; ~Buffer(); bool OnMapAsyncCallback(uint64_t requestSerial, diff --git a/src/dawn/wire/client/Device.cpp b/src/dawn/wire/client/Device.cpp index 4b86888883..10292de3e5 100644 --- a/src/dawn/wire/client/Device.cpp +++ b/src/dawn/wire/client/Device.cpp @@ -24,8 +24,8 @@ namespace dawn::wire::client { -Device::Device(Client* clientIn, uint32_t initialRefcount, uint32_t initialId) - : ObjectBase(clientIn, initialRefcount, initialId), mIsAlive(std::make_shared()) { +Device::Device(const ObjectBaseParams& params) + : ObjectBase(params), mIsAlive(std::make_shared()) { #if defined(DAWN_ENABLE_ASSERTS) mErrorCallback = [](WGPUErrorType, char const*, void*) { static bool calledOnce = false; diff --git a/src/dawn/wire/client/Device.h b/src/dawn/wire/client/Device.h index f932607cdd..14599ba851 100644 --- a/src/dawn/wire/client/Device.h +++ b/src/dawn/wire/client/Device.h @@ -32,7 +32,7 @@ class Queue; class Device final : public ObjectBase { public: - Device(Client* client, uint32_t refcount, uint32_t id); + explicit Device(const ObjectBaseParams& params); ~Device(); void SetUncapturedErrorCallback(WGPUErrorCallback errorCallback, void* errorUserdata); diff --git a/src/dawn/wire/client/Instance.cpp b/src/dawn/wire/client/Instance.cpp index 8e441d9727..b3a996f8c7 100644 --- a/src/dawn/wire/client/Instance.cpp +++ b/src/dawn/wire/client/Instance.cpp @@ -18,8 +18,6 @@ namespace dawn::wire::client { -Instance::Instance(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {} - Instance::~Instance() { mRequestAdapterRequests.CloseAll([](RequestAdapterData* request) { request->callback(WGPURequestAdapterStatus_Unknown, nullptr, diff --git a/src/dawn/wire/client/Instance.h b/src/dawn/wire/client/Instance.h index 625bd96b57..5b876a252b 100644 --- a/src/dawn/wire/client/Instance.h +++ b/src/dawn/wire/client/Instance.h @@ -26,7 +26,7 @@ namespace dawn::wire::client { class Instance final : public ObjectBase { public: - Instance(Client* client, uint32_t refcount, uint32_t id); + using ObjectBase::ObjectBase; ~Instance(); void CancelCallbacksForDisconnect() override; diff --git a/src/dawn/wire/client/ObjectAllocator.h b/src/dawn/wire/client/ObjectAllocator.h index 60b8fa875f..f8d22e69fc 100644 --- a/src/dawn/wire/client/ObjectAllocator.h +++ b/src/dawn/wire/client/ObjectAllocator.h @@ -44,7 +44,8 @@ class ObjectAllocator { template ObjectAndSerial* New(Client* client) { uint32_t id = GetNewId(); - auto object = std::make_unique(client, 1, id); + ObjectBaseParams params = {client, id}; + auto object = std::make_unique(params); client->TrackObject(object.get()); if (id >= mObjects.size()) { diff --git a/src/dawn/wire/client/ObjectBase.cpp b/src/dawn/wire/client/ObjectBase.cpp index 1d581ef58f..f0f8f680ba 100644 --- a/src/dawn/wire/client/ObjectBase.cpp +++ b/src/dawn/wire/client/ObjectBase.cpp @@ -16,8 +16,8 @@ namespace dawn::wire::client { -ObjectBase::ObjectBase(Client* client, uint32_t refcount, uint32_t id) - : client(client), refcount(refcount), id(id) {} +ObjectBase::ObjectBase(const ObjectBaseParams& params) + : client(params.client), refcount(1), id(params.id) {} ObjectBase::~ObjectBase() { RemoveFromList(); diff --git a/src/dawn/wire/client/ObjectBase.h b/src/dawn/wire/client/ObjectBase.h index 417c7c7b64..26a6acb875 100644 --- a/src/dawn/wire/client/ObjectBase.h +++ b/src/dawn/wire/client/ObjectBase.h @@ -24,13 +24,18 @@ namespace dawn::wire::client { class Client; +struct ObjectBaseParams { + Client* client; + uint32_t id; +}; + // All objects on the client side have: // - A pointer to the Client to get where to serialize commands -// - The external reference count +// - The external reference count, starting at 1. // - An ID that is used to refer to this object when talking with the server side // - A next/prev pointer. They are part of a linked list of objects of the same type. struct ObjectBase : public LinkNode { - ObjectBase(Client* client, uint32_t refcount, uint32_t id); + explicit ObjectBase(const ObjectBaseParams& params); ~ObjectBase(); virtual void CancelCallbacksForDisconnect() {} diff --git a/src/dawn/wire/client/QuerySet.cpp b/src/dawn/wire/client/QuerySet.cpp index c9b1a2dac2..0dfd7e89b5 100644 --- a/src/dawn/wire/client/QuerySet.cpp +++ b/src/dawn/wire/client/QuerySet.cpp @@ -40,7 +40,6 @@ WGPUQuerySet QuerySet::Create(Device* device, const WGPUQuerySetDescriptor* desc return ToAPI(querySet); } -QuerySet::QuerySet(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {} QuerySet::~QuerySet() = default; WGPUQueryType QuerySet::GetType() const { diff --git a/src/dawn/wire/client/QuerySet.h b/src/dawn/wire/client/QuerySet.h index 4afb9dc7c6..ee152e5260 100644 --- a/src/dawn/wire/client/QuerySet.h +++ b/src/dawn/wire/client/QuerySet.h @@ -27,7 +27,7 @@ class QuerySet final : public ObjectBase { public: static WGPUQuerySet Create(Device* device, const WGPUQuerySetDescriptor* descriptor); - QuerySet(Client* client, uint32_t refcount, uint32_t id); + using ObjectBase::ObjectBase; ~QuerySet(); // Note that these values can be arbitrary since they aren't validated in the wire client. diff --git a/src/dawn/wire/client/Queue.cpp b/src/dawn/wire/client/Queue.cpp index 618f99c65a..79f5632433 100644 --- a/src/dawn/wire/client/Queue.cpp +++ b/src/dawn/wire/client/Queue.cpp @@ -19,8 +19,6 @@ namespace dawn::wire::client { -Queue::Queue(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {} - Queue::~Queue() { ClearAllCallbacks(WGPUQueueWorkDoneStatus_Unknown); } diff --git a/src/dawn/wire/client/Queue.h b/src/dawn/wire/client/Queue.h index 35e583ebe4..6b59d96b4e 100644 --- a/src/dawn/wire/client/Queue.h +++ b/src/dawn/wire/client/Queue.h @@ -25,7 +25,7 @@ namespace dawn::wire::client { class Queue final : public ObjectBase { public: - Queue(Client* client, uint32_t refcount, uint32_t id); + using ObjectBase::ObjectBase; ~Queue(); bool OnWorkDoneCallback(uint64_t requestSerial, WGPUQueueWorkDoneStatus status); diff --git a/src/dawn/wire/client/ShaderModule.cpp b/src/dawn/wire/client/ShaderModule.cpp index 63bc534b37..e7cbb4ec15 100644 --- a/src/dawn/wire/client/ShaderModule.cpp +++ b/src/dawn/wire/client/ShaderModule.cpp @@ -18,8 +18,6 @@ namespace dawn::wire::client { -ShaderModule::ShaderModule(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {} - ShaderModule::~ShaderModule() { ClearAllCallbacks(WGPUCompilationInfoRequestStatus_Unknown); } diff --git a/src/dawn/wire/client/ShaderModule.h b/src/dawn/wire/client/ShaderModule.h index 5ae920d8bc..d8869ba8e6 100644 --- a/src/dawn/wire/client/ShaderModule.h +++ b/src/dawn/wire/client/ShaderModule.h @@ -24,7 +24,7 @@ namespace dawn::wire::client { class ShaderModule final : public ObjectBase { public: - ShaderModule(Client* client, uint32_t refcount, uint32_t id); + using ObjectBase::ObjectBase; ~ShaderModule(); void GetCompilationInfo(WGPUCompilationInfoCallback callback, void* userdata); diff --git a/src/dawn/wire/client/Texture.cpp b/src/dawn/wire/client/Texture.cpp index f4c0b97236..a5842b4c08 100644 --- a/src/dawn/wire/client/Texture.cpp +++ b/src/dawn/wire/client/Texture.cpp @@ -44,7 +44,6 @@ WGPUTexture Texture::Create(Device* device, const WGPUTextureDescriptor* descrip return ToAPI(texture); } -Texture::Texture(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {} Texture::~Texture() = default; uint32_t Texture::GetWidth() const { diff --git a/src/dawn/wire/client/Texture.h b/src/dawn/wire/client/Texture.h index 0bce2ea66c..db7d7059d4 100644 --- a/src/dawn/wire/client/Texture.h +++ b/src/dawn/wire/client/Texture.h @@ -27,7 +27,7 @@ class Texture final : public ObjectBase { public: static WGPUTexture Create(Device* device, const WGPUTextureDescriptor* descriptor); - Texture(Client* client, uint32_t refcount, uint32_t id); + using ObjectBase::ObjectBase; ~Texture(); // Note that these values can be arbitrary since they aren't validated in the wire client.