dawn::wire::client::ObjectBase: encapsulate remaining members.
ObjectBase::refcount is no longer exposed and instead Reference() and Release() methods are available to operate on it. The client is now exposed through a GetClient() accessor. Bug: dawn:1451 Change-Id: Ia47ed2de0a8f03ccc3275cb81d6335d2125060cb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93442 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Loko Kung <lokokung@google.com>
This commit is contained in:
parent
0f97df8c53
commit
0daef56b49
|
@ -58,7 +58,7 @@ namespace dawn::wire::client {
|
||||||
|
|
||||||
//* For object creation, store the object ID the client will use for the result.
|
//* For object creation, store the object ID the client will use for the result.
|
||||||
{% if method.return_type.category == "object" %}
|
{% if method.return_type.category == "object" %}
|
||||||
auto* returnObject = self->client->{{method.return_type.name.CamelCase()}}Allocator().New(self->client);
|
auto* returnObject = self->GetClient()->{{method.return_type.name.CamelCase()}}Allocator().New(self->GetClient());
|
||||||
cmd.result = returnObject->GetWireHandle();
|
cmd.result = returnObject->GetWireHandle();
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ namespace dawn::wire::client {
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
//* Allocate space to send the command and copy the value args over.
|
//* Allocate space to send the command and copy the value args over.
|
||||||
self->client->SerializeCommand(cmd);
|
self->GetClient()->SerializeCommand(cmd);
|
||||||
|
|
||||||
{% if method.return_type.category == "object" %}
|
{% if method.return_type.category == "object" %}
|
||||||
return ToAPI(returnObject);
|
return ToAPI(returnObject);
|
||||||
|
@ -86,9 +86,8 @@ namespace dawn::wire::client {
|
||||||
//* When an object's refcount reaches 0, notify the server side of it and delete it.
|
//* When an object's refcount reaches 0, notify the server side of it and delete it.
|
||||||
void Client{{as_MethodSuffix(type.name, Name("release"))}}({{cType}} cObj) {
|
void Client{{as_MethodSuffix(type.name, Name("release"))}}({{cType}} cObj) {
|
||||||
{{Type}}* obj = reinterpret_cast<{{Type}}*>(cObj);
|
{{Type}}* obj = reinterpret_cast<{{Type}}*>(cObj);
|
||||||
obj->refcount --;
|
|
||||||
|
|
||||||
if (obj->refcount > 0) {
|
if (!obj->Release()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,13 +95,13 @@ namespace dawn::wire::client {
|
||||||
cmd.objectType = ObjectType::{{type.name.CamelCase()}};
|
cmd.objectType = ObjectType::{{type.name.CamelCase()}};
|
||||||
cmd.objectId = obj->GetWireId();
|
cmd.objectId = obj->GetWireId();
|
||||||
|
|
||||||
obj->client->SerializeCommand(cmd);
|
Client* client = obj->GetClient();
|
||||||
obj->client->{{type.name.CamelCase()}}Allocator().Free(obj);
|
client->SerializeCommand(cmd);
|
||||||
|
client->{{type.name.CamelCase()}}Allocator().Free(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client{{as_MethodSuffix(type.name, Name("reference"))}}({{cType}} cObj) {
|
void Client{{as_MethodSuffix(type.name, Name("reference"))}}({{cType}} cObj) {
|
||||||
{{Type}}* obj = reinterpret_cast<{{Type}}*>(cObj);
|
reinterpret_cast<{{Type}}*>(cObj)->Reference();
|
||||||
obj->refcount ++;
|
|
||||||
}
|
}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
|
@ -65,6 +65,7 @@ void Adapter::GetProperties(WGPUAdapterProperties* properties) const {
|
||||||
void Adapter::RequestDevice(const WGPUDeviceDescriptor* descriptor,
|
void Adapter::RequestDevice(const WGPUDeviceDescriptor* descriptor,
|
||||||
WGPURequestDeviceCallback callback,
|
WGPURequestDeviceCallback callback,
|
||||||
void* userdata) {
|
void* userdata) {
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
callback(WGPURequestDeviceStatus_Error, nullptr, "GPU connection lost", userdata);
|
callback(WGPURequestDeviceStatus_Error, nullptr, "GPU connection lost", userdata);
|
||||||
return;
|
return;
|
||||||
|
@ -108,6 +109,7 @@ bool Adapter::OnRequestDeviceCallback(uint64_t requestSerial,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Client* client = GetClient();
|
||||||
Device* device = client->DeviceAllocator().GetObject(request.deviceObjectId);
|
Device* device = client->DeviceAllocator().GetObject(request.deviceObjectId);
|
||||||
|
|
||||||
// If the return status is a failure we should give a null device to the callback and
|
// If the return status is a failure we should give a null device to the callback and
|
||||||
|
|
|
@ -26,7 +26,7 @@ namespace dawn::wire::client {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
WGPUBuffer Buffer::Create(Device* device, const WGPUBufferDescriptor* descriptor) {
|
WGPUBuffer Buffer::Create(Device* device, const WGPUBufferDescriptor* descriptor) {
|
||||||
Client* wireClient = device->client;
|
Client* wireClient = device->GetClient();
|
||||||
|
|
||||||
bool mappable =
|
bool mappable =
|
||||||
(descriptor->usage & (WGPUBufferUsage_MapRead | WGPUBufferUsage_MapWrite)) != 0 ||
|
(descriptor->usage & (WGPUBufferUsage_MapRead | WGPUBufferUsage_MapWrite)) != 0 ||
|
||||||
|
@ -125,7 +125,9 @@ WGPUBuffer Buffer::Create(Device* device, const WGPUBufferDescriptor* descriptor
|
||||||
|
|
||||||
// static
|
// static
|
||||||
WGPUBuffer Buffer::CreateError(Device* device, const WGPUBufferDescriptor* descriptor) {
|
WGPUBuffer Buffer::CreateError(Device* device, const WGPUBufferDescriptor* descriptor) {
|
||||||
Buffer* buffer = device->client->BufferAllocator().New(device->client);
|
Client* client = device->GetClient();
|
||||||
|
|
||||||
|
Buffer* buffer = client->BufferAllocator().New(client);
|
||||||
buffer->mDevice = device;
|
buffer->mDevice = device;
|
||||||
buffer->mDeviceIsAlive = device->GetAliveWeakPtr();
|
buffer->mDeviceIsAlive = device->GetAliveWeakPtr();
|
||||||
buffer->mSize = descriptor->size;
|
buffer->mSize = descriptor->size;
|
||||||
|
@ -134,7 +136,7 @@ WGPUBuffer Buffer::CreateError(Device* device, const WGPUBufferDescriptor* descr
|
||||||
DeviceCreateErrorBufferCmd cmd;
|
DeviceCreateErrorBufferCmd cmd;
|
||||||
cmd.self = ToAPI(device);
|
cmd.self = ToAPI(device);
|
||||||
cmd.result = buffer->GetWireHandle();
|
cmd.result = buffer->GetWireHandle();
|
||||||
device->client->SerializeCommand(cmd);
|
client->SerializeCommand(cmd);
|
||||||
|
|
||||||
return ToAPI(buffer);
|
return ToAPI(buffer);
|
||||||
}
|
}
|
||||||
|
@ -161,6 +163,7 @@ void Buffer::MapAsync(WGPUMapModeFlags mode,
|
||||||
size_t size,
|
size_t size,
|
||||||
WGPUBufferMapCallback callback,
|
WGPUBufferMapCallback callback,
|
||||||
void* userdata) {
|
void* userdata) {
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
return callback(WGPUBufferMapAsyncStatus_DeviceLost, userdata);
|
return callback(WGPUBufferMapAsyncStatus_DeviceLost, userdata);
|
||||||
}
|
}
|
||||||
|
@ -288,6 +291,7 @@ void Buffer::Unmap() {
|
||||||
// - Server -> Client: Result of MapRequest1
|
// - Server -> Client: Result of MapRequest1
|
||||||
// - Unmap locally on the client
|
// - Unmap locally on the client
|
||||||
// - Server -> Client: Result of MapRequest2
|
// - Server -> Client: Result of MapRequest2
|
||||||
|
Client* client = GetClient();
|
||||||
|
|
||||||
// mWriteHandle can still be nullptr if buffer has been destroyed before unmap
|
// mWriteHandle can still be nullptr if buffer has been destroyed before unmap
|
||||||
if ((mMapState == MapState::MappedForWrite || mMapState == MapState::MappedAtCreation) &&
|
if ((mMapState == MapState::MappedForWrite || mMapState == MapState::MappedAtCreation) &&
|
||||||
|
@ -350,6 +354,8 @@ void Buffer::Unmap() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::Destroy() {
|
void Buffer::Destroy() {
|
||||||
|
Client* client = GetClient();
|
||||||
|
|
||||||
// Remove the current mapping and destroy Read/WriteHandles.
|
// Remove the current mapping and destroy Read/WriteHandles.
|
||||||
FreeMappedData();
|
FreeMappedData();
|
||||||
|
|
||||||
|
|
|
@ -151,6 +151,7 @@ void Device::SetDeviceLostCallback(WGPUDeviceLostCallback callback, void* userda
|
||||||
|
|
||||||
bool Device::PopErrorScope(WGPUErrorCallback callback, void* userdata) {
|
bool Device::PopErrorScope(WGPUErrorCallback callback, void* userdata) {
|
||||||
// TODO(crbug.com/dawn/1324) Replace bool return with void when users are updated.
|
// TODO(crbug.com/dawn/1324) Replace bool return with void when users are updated.
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
callback(WGPUErrorType_DeviceLost, "GPU device disconnected", userdata);
|
callback(WGPUErrorType_DeviceLost, "GPU device disconnected", userdata);
|
||||||
return true;
|
return true;
|
||||||
|
@ -192,7 +193,7 @@ void Device::InjectError(WGPUErrorType type, const char* message) {
|
||||||
cmd.self = ToAPI(this);
|
cmd.self = ToAPI(this);
|
||||||
cmd.type = type;
|
cmd.type = type;
|
||||||
cmd.message = message;
|
cmd.message = message;
|
||||||
client->SerializeCommand(cmd);
|
GetClient()->SerializeCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
WGPUBuffer Device::CreateBuffer(const WGPUBufferDescriptor* descriptor) {
|
WGPUBuffer Device::CreateBuffer(const WGPUBufferDescriptor* descriptor) {
|
||||||
|
@ -219,6 +220,7 @@ WGPUQueue Device::GetQueue() {
|
||||||
// on construction.
|
// on construction.
|
||||||
if (mQueue == nullptr) {
|
if (mQueue == nullptr) {
|
||||||
// Get the primary queue for this device.
|
// Get the primary queue for this device.
|
||||||
|
Client* client = GetClient();
|
||||||
mQueue = client->QueueAllocator().New(client);
|
mQueue = client->QueueAllocator().New(client);
|
||||||
|
|
||||||
DeviceGetQueueCmd cmd;
|
DeviceGetQueueCmd cmd;
|
||||||
|
@ -228,13 +230,14 @@ WGPUQueue Device::GetQueue() {
|
||||||
client->SerializeCommand(cmd);
|
client->SerializeCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
mQueue->refcount++;
|
mQueue->Reference();
|
||||||
return ToAPI(mQueue);
|
return ToAPI(mQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Device::CreateComputePipelineAsync(WGPUComputePipelineDescriptor const* descriptor,
|
void Device::CreateComputePipelineAsync(WGPUComputePipelineDescriptor const* descriptor,
|
||||||
WGPUCreateComputePipelineAsyncCallback callback,
|
WGPUCreateComputePipelineAsyncCallback callback,
|
||||||
void* userdata) {
|
void* userdata) {
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
return callback(WGPUCreatePipelineAsyncStatus_DeviceLost, nullptr,
|
return callback(WGPUCreatePipelineAsyncStatus_DeviceLost, nullptr,
|
||||||
"GPU device disconnected", userdata);
|
"GPU device disconnected", userdata);
|
||||||
|
@ -266,6 +269,7 @@ bool Device::OnCreateComputePipelineAsyncCallback(uint64_t requestSerial,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Client* client = GetClient();
|
||||||
auto* pipelineAllocation =
|
auto* pipelineAllocation =
|
||||||
client->ComputePipelineAllocator().GetObject(request.pipelineObjectID);
|
client->ComputePipelineAllocator().GetObject(request.pipelineObjectID);
|
||||||
|
|
||||||
|
@ -286,6 +290,7 @@ bool Device::OnCreateComputePipelineAsyncCallback(uint64_t requestSerial,
|
||||||
void Device::CreateRenderPipelineAsync(WGPURenderPipelineDescriptor const* descriptor,
|
void Device::CreateRenderPipelineAsync(WGPURenderPipelineDescriptor const* descriptor,
|
||||||
WGPUCreateRenderPipelineAsyncCallback callback,
|
WGPUCreateRenderPipelineAsyncCallback callback,
|
||||||
void* userdata) {
|
void* userdata) {
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
return callback(WGPUCreatePipelineAsyncStatus_DeviceLost, nullptr,
|
return callback(WGPUCreatePipelineAsyncStatus_DeviceLost, nullptr,
|
||||||
"GPU device disconnected", userdata);
|
"GPU device disconnected", userdata);
|
||||||
|
@ -317,6 +322,7 @@ bool Device::OnCreateRenderPipelineAsyncCallback(uint64_t requestSerial,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Client* client = GetClient();
|
||||||
auto* pipelineAllocation =
|
auto* pipelineAllocation =
|
||||||
client->RenderPipelineAllocator().GetObject(request.pipelineObjectID);
|
client->RenderPipelineAllocator().GetObject(request.pipelineObjectID);
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ void Instance::CancelCallbacksForDisconnect() {
|
||||||
void Instance::RequestAdapter(const WGPURequestAdapterOptions* options,
|
void Instance::RequestAdapter(const WGPURequestAdapterOptions* options,
|
||||||
WGPURequestAdapterCallback callback,
|
WGPURequestAdapterCallback callback,
|
||||||
void* userdata) {
|
void* userdata) {
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
callback(WGPURequestAdapterStatus_Error, nullptr, "GPU connection lost", userdata);
|
callback(WGPURequestAdapterStatus_Error, nullptr, "GPU connection lost", userdata);
|
||||||
return;
|
return;
|
||||||
|
@ -80,6 +81,7 @@ bool Instance::OnRequestAdapterCallback(uint64_t requestSerial,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Client* client = GetClient();
|
||||||
Adapter* adapter = client->AdapterAllocator().GetObject(request.adapterObjectId);
|
Adapter* adapter = client->AdapterAllocator().GetObject(request.adapterObjectId);
|
||||||
|
|
||||||
// If the return status is a failure we should give a null adapter to the callback and
|
// If the return status is a failure we should give a null adapter to the callback and
|
||||||
|
|
|
@ -14,10 +14,12 @@
|
||||||
|
|
||||||
#include "dawn/wire/client/ObjectBase.h"
|
#include "dawn/wire/client/ObjectBase.h"
|
||||||
|
|
||||||
|
#include "dawn/common/Assert.h"
|
||||||
|
|
||||||
namespace dawn::wire::client {
|
namespace dawn::wire::client {
|
||||||
|
|
||||||
ObjectBase::ObjectBase(const ObjectBaseParams& params)
|
ObjectBase::ObjectBase(const ObjectBaseParams& params)
|
||||||
: client(params.client), refcount(1), mHandle(params.handle) {}
|
: mClient(params.client), mHandle(params.handle), mRefcount(1) {}
|
||||||
|
|
||||||
ObjectBase::~ObjectBase() {
|
ObjectBase::~ObjectBase() {
|
||||||
RemoveFromList();
|
RemoveFromList();
|
||||||
|
@ -35,4 +37,18 @@ ObjectGeneration ObjectBase::GetWireGeneration() const {
|
||||||
return mHandle.generation;
|
return mHandle.generation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Client* ObjectBase::GetClient() const {
|
||||||
|
return mClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectBase::Reference() {
|
||||||
|
mRefcount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ObjectBase::Release() {
|
||||||
|
ASSERT(mRefcount != 0);
|
||||||
|
mRefcount--;
|
||||||
|
return mRefcount == 0;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dawn::wire::client
|
} // namespace dawn::wire::client
|
||||||
|
|
|
@ -44,13 +44,17 @@ class ObjectBase : public LinkNode<ObjectBase> {
|
||||||
const ObjectHandle& GetWireHandle() const;
|
const ObjectHandle& GetWireHandle() const;
|
||||||
ObjectId GetWireId() const;
|
ObjectId GetWireId() const;
|
||||||
ObjectGeneration GetWireGeneration() const;
|
ObjectGeneration GetWireGeneration() const;
|
||||||
|
Client* GetClient() const;
|
||||||
|
|
||||||
// TODO(dawn:1451): Make these members private.
|
void Reference();
|
||||||
Client* const client;
|
// Returns true if it was the last reference, indicating that the caller must destroy the
|
||||||
uint32_t refcount;
|
// object.
|
||||||
|
[[nodiscard]] bool Release();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Client* const mClient;
|
||||||
const ObjectHandle mHandle;
|
const ObjectHandle mHandle;
|
||||||
|
uint32_t mRefcount;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dawn::wire::client
|
} // namespace dawn::wire::client
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace dawn::wire::client {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
WGPUQuerySet QuerySet::Create(Device* device, const WGPUQuerySetDescriptor* descriptor) {
|
WGPUQuerySet QuerySet::Create(Device* device, const WGPUQuerySetDescriptor* descriptor) {
|
||||||
Client* wireClient = device->client;
|
Client* wireClient = device->GetClient();
|
||||||
QuerySet* querySet = wireClient->QuerySetAllocator().New(wireClient);
|
QuerySet* querySet = wireClient->QuerySetAllocator().New(wireClient);
|
||||||
|
|
||||||
// Copy over descriptor data for reflection.
|
// Copy over descriptor data for reflection.
|
||||||
|
|
|
@ -36,6 +36,7 @@ bool Queue::OnWorkDoneCallback(uint64_t requestSerial, WGPUQueueWorkDoneStatus s
|
||||||
void Queue::OnSubmittedWorkDone(uint64_t signalValue,
|
void Queue::OnSubmittedWorkDone(uint64_t signalValue,
|
||||||
WGPUQueueWorkDoneCallback callback,
|
WGPUQueueWorkDoneCallback callback,
|
||||||
void* userdata) {
|
void* userdata) {
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
callback(WGPUQueueWorkDoneStatus_DeviceLost, userdata);
|
callback(WGPUQueueWorkDoneStatus_DeviceLost, userdata);
|
||||||
return;
|
return;
|
||||||
|
@ -61,7 +62,7 @@ void Queue::WriteBuffer(WGPUBuffer cBuffer, uint64_t bufferOffset, const void* d
|
||||||
cmd.data = static_cast<const uint8_t*>(data);
|
cmd.data = static_cast<const uint8_t*>(data);
|
||||||
cmd.size = size;
|
cmd.size = size;
|
||||||
|
|
||||||
client->SerializeCommand(cmd);
|
GetClient()->SerializeCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Queue::WriteTexture(const WGPUImageCopyTexture* destination,
|
void Queue::WriteTexture(const WGPUImageCopyTexture* destination,
|
||||||
|
@ -77,7 +78,7 @@ void Queue::WriteTexture(const WGPUImageCopyTexture* destination,
|
||||||
cmd.dataLayout = dataLayout;
|
cmd.dataLayout = dataLayout;
|
||||||
cmd.writeSize = writeSize;
|
cmd.writeSize = writeSize;
|
||||||
|
|
||||||
client->SerializeCommand(cmd);
|
GetClient()->SerializeCommand(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Queue::CancelCallbacksForDisconnect() {
|
void Queue::CancelCallbacksForDisconnect() {
|
||||||
|
|
|
@ -23,6 +23,7 @@ ShaderModule::~ShaderModule() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShaderModule::GetCompilationInfo(WGPUCompilationInfoCallback callback, void* userdata) {
|
void ShaderModule::GetCompilationInfo(WGPUCompilationInfoCallback callback, void* userdata) {
|
||||||
|
Client* client = GetClient();
|
||||||
if (client->IsDisconnected()) {
|
if (client->IsDisconnected()) {
|
||||||
callback(WGPUCompilationInfoRequestStatus_DeviceLost, nullptr, userdata);
|
callback(WGPUCompilationInfoRequestStatus_DeviceLost, nullptr, userdata);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace dawn::wire::client {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
WGPUTexture Texture::Create(Device* device, const WGPUTextureDescriptor* descriptor) {
|
WGPUTexture Texture::Create(Device* device, const WGPUTextureDescriptor* descriptor) {
|
||||||
Client* wireClient = device->client;
|
Client* wireClient = device->GetClient();
|
||||||
Texture* texture = wireClient->TextureAllocator().New(wireClient);
|
Texture* texture = wireClient->TextureAllocator().New(wireClient);
|
||||||
|
|
||||||
// Copy over descriptor data for reflection.
|
// Copy over descriptor data for reflection.
|
||||||
|
|
Loading…
Reference in New Issue