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 {
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,

View File

@ -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;

View File

@ -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();

View File

@ -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,

View File

@ -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<bool>()) {
Device::Device(const ObjectBaseParams& params)
: ObjectBase(params), mIsAlive(std::make_shared<bool>()) {
#if defined(DAWN_ENABLE_ASSERTS)
mErrorCallback = [](WGPUErrorType, char const*, void*) {
static bool calledOnce = false;

View File

@ -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);

View File

@ -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,

View File

@ -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;

View File

@ -44,7 +44,8 @@ class ObjectAllocator {
template <typename Client>
ObjectAndSerial* New(Client* client) {
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());
if (id >= mObjects.size()) {

View File

@ -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();

View File

@ -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> {
ObjectBase(Client* client, uint32_t refcount, uint32_t id);
explicit ObjectBase(const ObjectBaseParams& params);
~ObjectBase();
virtual void CancelCallbacksForDisconnect() {}

View File

@ -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 {

View File

@ -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.

View File

@ -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);
}

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -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 {

View File

@ -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.