dawn::wire::client: Write ObjectBase constructor params in a struct.

This will allow easily adding new parameters to ObjectBase in the future
(like an object generation).

Bug: dawn:1451
Change-Id: I4fc81384987cdd9c33e672d15fcd960dbf0367a0
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93144
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2022-06-14 09:31:46 +00:00 committed by Dawn LUCI CQ
parent ff2dc652f5
commit 60f3832435
19 changed files with 21 additions and 27 deletions

View File

@ -19,8 +19,6 @@
namespace dawn::wire::client { namespace dawn::wire::client {
Adapter::Adapter(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Adapter::~Adapter() { Adapter::~Adapter() {
mRequestDeviceRequests.CloseAll([](RequestDeviceData* request) { mRequestDeviceRequests.CloseAll([](RequestDeviceData* request) {
request->callback(WGPURequestDeviceStatus_Unknown, nullptr, request->callback(WGPURequestDeviceStatus_Unknown, nullptr,

View File

@ -27,7 +27,7 @@ namespace dawn::wire::client {
class Adapter final : public ObjectBase { class Adapter final : public ObjectBase {
public: public:
Adapter(Client* client, uint32_t refcount, uint32_t id); using ObjectBase::ObjectBase;
~Adapter(); ~Adapter();
void CancelCallbacksForDisconnect() override; void CancelCallbacksForDisconnect() override;

View File

@ -140,8 +140,6 @@ WGPUBuffer Buffer::CreateError(Device* device, const WGPUBufferDescriptor* descr
return ToAPI(allocation->object.get()); return ToAPI(allocation->object.get());
} }
Buffer::Buffer(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Buffer::~Buffer() { Buffer::~Buffer() {
ClearAllCallbacks(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback); ClearAllCallbacks(WGPUBufferMapAsyncStatus_DestroyedBeforeCallback);
FreeMappedData(); FreeMappedData();

View File

@ -31,7 +31,7 @@ class Buffer final : public ObjectBase {
static WGPUBuffer Create(Device* device, const WGPUBufferDescriptor* descriptor); static WGPUBuffer Create(Device* device, const WGPUBufferDescriptor* descriptor);
static WGPUBuffer CreateError(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(); ~Buffer();
bool OnMapAsyncCallback(uint64_t requestSerial, bool OnMapAsyncCallback(uint64_t requestSerial,

View File

@ -24,8 +24,8 @@
namespace dawn::wire::client { namespace dawn::wire::client {
Device::Device(Client* clientIn, uint32_t initialRefcount, uint32_t initialId) Device::Device(const ObjectBaseParams& params)
: ObjectBase(clientIn, initialRefcount, initialId), mIsAlive(std::make_shared<bool>()) { : ObjectBase(params), mIsAlive(std::make_shared<bool>()) {
#if defined(DAWN_ENABLE_ASSERTS) #if defined(DAWN_ENABLE_ASSERTS)
mErrorCallback = [](WGPUErrorType, char const*, void*) { mErrorCallback = [](WGPUErrorType, char const*, void*) {
static bool calledOnce = false; static bool calledOnce = false;

View File

@ -32,7 +32,7 @@ class Queue;
class Device final : public ObjectBase { class Device final : public ObjectBase {
public: public:
Device(Client* client, uint32_t refcount, uint32_t id); explicit Device(const ObjectBaseParams& params);
~Device(); ~Device();
void SetUncapturedErrorCallback(WGPUErrorCallback errorCallback, void* errorUserdata); void SetUncapturedErrorCallback(WGPUErrorCallback errorCallback, void* errorUserdata);

View File

@ -18,8 +18,6 @@
namespace dawn::wire::client { namespace dawn::wire::client {
Instance::Instance(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Instance::~Instance() { Instance::~Instance() {
mRequestAdapterRequests.CloseAll([](RequestAdapterData* request) { mRequestAdapterRequests.CloseAll([](RequestAdapterData* request) {
request->callback(WGPURequestAdapterStatus_Unknown, nullptr, request->callback(WGPURequestAdapterStatus_Unknown, nullptr,

View File

@ -26,7 +26,7 @@ namespace dawn::wire::client {
class Instance final : public ObjectBase { class Instance final : public ObjectBase {
public: public:
Instance(Client* client, uint32_t refcount, uint32_t id); using ObjectBase::ObjectBase;
~Instance(); ~Instance();
void CancelCallbacksForDisconnect() override; void CancelCallbacksForDisconnect() override;

View File

@ -44,7 +44,8 @@ class ObjectAllocator {
template <typename Client> template <typename Client>
ObjectAndSerial* New(Client* client) { ObjectAndSerial* New(Client* client) {
uint32_t id = GetNewId(); uint32_t id = GetNewId();
auto object = std::make_unique<T>(client, 1, id); ObjectBaseParams params = {client, id};
auto object = std::make_unique<T>(params);
client->TrackObject(object.get()); client->TrackObject(object.get());
if (id >= mObjects.size()) { if (id >= mObjects.size()) {

View File

@ -16,8 +16,8 @@
namespace dawn::wire::client { namespace dawn::wire::client {
ObjectBase::ObjectBase(Client* client, uint32_t refcount, uint32_t id) ObjectBase::ObjectBase(const ObjectBaseParams& params)
: client(client), refcount(refcount), id(id) {} : client(params.client), refcount(1), id(params.id) {}
ObjectBase::~ObjectBase() { ObjectBase::~ObjectBase() {
RemoveFromList(); RemoveFromList();

View File

@ -24,13 +24,18 @@ namespace dawn::wire::client {
class Client; class Client;
struct ObjectBaseParams {
Client* client;
uint32_t id;
};
// All objects on the client side have: // All objects on the client side have:
// - A pointer to the Client to get where to serialize commands // - 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 // - 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. // - A next/prev pointer. They are part of a linked list of objects of the same type.
struct ObjectBase : public LinkNode<ObjectBase> { struct ObjectBase : public LinkNode<ObjectBase> {
ObjectBase(Client* client, uint32_t refcount, uint32_t id); explicit ObjectBase(const ObjectBaseParams& params);
~ObjectBase(); ~ObjectBase();
virtual void CancelCallbacksForDisconnect() {} virtual void CancelCallbacksForDisconnect() {}

View File

@ -40,7 +40,6 @@ WGPUQuerySet QuerySet::Create(Device* device, const WGPUQuerySetDescriptor* desc
return ToAPI(querySet); return ToAPI(querySet);
} }
QuerySet::QuerySet(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
QuerySet::~QuerySet() = default; QuerySet::~QuerySet() = default;
WGPUQueryType QuerySet::GetType() const { WGPUQueryType QuerySet::GetType() const {

View File

@ -27,7 +27,7 @@ class QuerySet final : public ObjectBase {
public: public:
static WGPUQuerySet Create(Device* device, const WGPUQuerySetDescriptor* descriptor); static WGPUQuerySet Create(Device* device, const WGPUQuerySetDescriptor* descriptor);
QuerySet(Client* client, uint32_t refcount, uint32_t id); using ObjectBase::ObjectBase;
~QuerySet(); ~QuerySet();
// Note that these values can be arbitrary since they aren't validated in the wire client. // Note that these values can be arbitrary since they aren't validated in the wire client.

View File

@ -19,8 +19,6 @@
namespace dawn::wire::client { namespace dawn::wire::client {
Queue::Queue(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Queue::~Queue() { Queue::~Queue() {
ClearAllCallbacks(WGPUQueueWorkDoneStatus_Unknown); ClearAllCallbacks(WGPUQueueWorkDoneStatus_Unknown);
} }

View File

@ -25,7 +25,7 @@ namespace dawn::wire::client {
class Queue final : public ObjectBase { class Queue final : public ObjectBase {
public: public:
Queue(Client* client, uint32_t refcount, uint32_t id); using ObjectBase::ObjectBase;
~Queue(); ~Queue();
bool OnWorkDoneCallback(uint64_t requestSerial, WGPUQueueWorkDoneStatus status); bool OnWorkDoneCallback(uint64_t requestSerial, WGPUQueueWorkDoneStatus status);

View File

@ -18,8 +18,6 @@
namespace dawn::wire::client { namespace dawn::wire::client {
ShaderModule::ShaderModule(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
ShaderModule::~ShaderModule() { ShaderModule::~ShaderModule() {
ClearAllCallbacks(WGPUCompilationInfoRequestStatus_Unknown); ClearAllCallbacks(WGPUCompilationInfoRequestStatus_Unknown);
} }

View File

@ -24,7 +24,7 @@ namespace dawn::wire::client {
class ShaderModule final : public ObjectBase { class ShaderModule final : public ObjectBase {
public: public:
ShaderModule(Client* client, uint32_t refcount, uint32_t id); using ObjectBase::ObjectBase;
~ShaderModule(); ~ShaderModule();
void GetCompilationInfo(WGPUCompilationInfoCallback callback, void* userdata); void GetCompilationInfo(WGPUCompilationInfoCallback callback, void* userdata);

View File

@ -44,7 +44,6 @@ WGPUTexture Texture::Create(Device* device, const WGPUTextureDescriptor* descrip
return ToAPI(texture); return ToAPI(texture);
} }
Texture::Texture(Client* c, uint32_t r, uint32_t i) : ObjectBase(c, r, i) {}
Texture::~Texture() = default; Texture::~Texture() = default;
uint32_t Texture::GetWidth() const { uint32_t Texture::GetWidth() const {

View File

@ -27,7 +27,7 @@ class Texture final : public ObjectBase {
public: public:
static WGPUTexture Create(Device* device, const WGPUTextureDescriptor* descriptor); static WGPUTexture Create(Device* device, const WGPUTextureDescriptor* descriptor);
Texture(Client* client, uint32_t refcount, uint32_t id); using ObjectBase::ObjectBase;
~Texture(); ~Texture();
// Note that these values can be arbitrary since they aren't validated in the wire client. // Note that these values can be arbitrary since they aren't validated in the wire client.