Cleanup: Rename dawn_wire Object "serial" to "generation"

This is a more accurate name and conflicts less with the callback
request serials.

Bug: none
Change-Id: I0f9660c24468064dadffb3ab9b3392d403f93c41
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19260
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Austin Eng 2020-04-13 17:50:51 +00:00 committed by Commit Bot service account
parent 077a427499
commit 518c8e77ab
12 changed files with 41 additions and 36 deletions

View File

@ -422,16 +422,20 @@ namespace dawn_wire {
} while (0)
ObjectHandle::ObjectHandle() = default;
ObjectHandle::ObjectHandle(ObjectId id, ObjectSerial serial) : id(id), serial(serial) {}
ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs) : id(rhs.id), serial(rhs.serial) {}
ObjectHandle::ObjectHandle(ObjectId id, ObjectGeneration generation)
: id(id), generation(generation) {
}
ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs)
: id(rhs.id), generation(rhs.generation) {
}
ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) {
id = rhs.id;
serial = rhs.serial;
generation = rhs.generation;
return *this;
}
ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) {
id = rhs.id;
serial = rhs.serial;
generation = rhs.generation;
return *this;
}

View File

@ -20,13 +20,13 @@
namespace dawn_wire {
using ObjectId = uint32_t;
using ObjectSerial = uint32_t;
using ObjectGeneration = uint32_t;
struct ObjectHandle {
ObjectId id;
ObjectSerial serial;
ObjectGeneration generation;
ObjectHandle();
ObjectHandle(ObjectId id, ObjectSerial serial);
ObjectHandle(ObjectId id, ObjectGeneration generation);
ObjectHandle(const volatile ObjectHandle& rhs);
// MSVC has a bug where it thinks the volatile copy assignment is a duplicate.

View File

@ -47,7 +47,7 @@ namespace dawn_wire { namespace client {
//* For object creation, store the object ID the client will use for the result.
{% if method.return_type.category == "object" %}
auto* allocation = self->device->GetClient()->{{method.return_type.name.CamelCase()}}Allocator().New(self->device);
cmd.result = ObjectHandle{allocation->object->id, allocation->serial};
cmd.result = ObjectHandle{allocation->object->id, allocation->generation};
{% endif %}
{% for arg in method.arguments %}

View File

@ -33,8 +33,8 @@ namespace dawn_wire { namespace client {
{% if member.type.dict_name == "ObjectHandle" %}
{{Type}}* {{name}} = {{Type}}Allocator().GetObject(cmd.{{name}}.id);
uint32_t {{name}}Serial = {{Type}}Allocator().GetSerial(cmd.{{name}}.id);
if ({{name}}Serial != cmd.{{name}}.serial) {
uint32_t {{name}}Generation = {{Type}}Allocator().GetGeneration(cmd.{{name}}.id);
if ({{name}}Generation != cmd.{{name}}.generation) {
{{name}} = nullptr;
}
{% endif %}

View File

@ -52,7 +52,7 @@ namespace dawn_wire { namespace server {
if ({{name}}Data == nullptr) {
return false;
}
{{name}}Data->serial = cmd.{{name}}.serial;
{{name}}Data->generation = cmd.{{name}}.generation;
{% endfor %}
//* Do command

View File

@ -121,7 +121,7 @@ namespace dawn_wire { namespace client {
DeviceCreateBufferCmd cmd;
cmd.self = cDevice;
cmd.descriptor = descriptor;
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->serial};
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->generation};
size_t requiredSize = cmd.GetRequiredSize();
char* allocatedBuffer = static_cast<char*>(wireClient->GetCmdSpace(requiredSize));
@ -176,7 +176,7 @@ namespace dawn_wire { namespace client {
DeviceCreateBufferMappedCmd cmd;
cmd.device = cDevice;
cmd.descriptor = descriptor;
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->serial};
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->generation};
cmd.handleCreateInfoLength = handleCreateInfoLength;
cmd.handleCreateInfo = nullptr;
@ -252,7 +252,7 @@ namespace dawn_wire { namespace client {
cmd.device = cDevice;
cmd.descriptor = descriptor;
cmd.requestSerial = serial;
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->serial};
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->generation};
cmd.handleCreateInfoLength = handleCreateInfoLength;
cmd.handleCreateInfo = nullptr;
@ -391,7 +391,7 @@ namespace dawn_wire { namespace client {
QueueCreateFenceCmd cmd;
cmd.self = cSelf;
auto* allocation = device->GetClient()->FenceAllocator().New(device);
cmd.result = ObjectHandle{allocation->object->id, allocation->serial};
cmd.result = ObjectHandle{allocation->object->id, allocation->generation};
cmd.descriptor = descriptor;
size_t requiredSize = cmd.GetRequiredSize();

View File

@ -40,7 +40,7 @@ namespace dawn_wire { namespace client {
ReservedTexture result;
result.texture = reinterpret_cast<WGPUTexture>(allocation->object.get());
result.id = allocation->object->id;
result.generation = allocation->serial;
result.generation = allocation->generation;
return result;
}

View File

@ -33,11 +33,11 @@ namespace dawn_wire { namespace client {
public:
struct ObjectAndSerial {
ObjectAndSerial(std::unique_ptr<T> object, uint32_t serial)
: object(std::move(object)), serial(serial) {
ObjectAndSerial(std::unique_ptr<T> object, uint32_t generation)
: object(std::move(object)), generation(generation) {
}
std::unique_ptr<T> object;
uint32_t serial;
uint32_t generation;
};
ObjectAllocator() {
@ -55,10 +55,10 @@ namespace dawn_wire { namespace client {
} else {
ASSERT(mObjects[id].object == nullptr);
mObjects[id].serial++;
// The serial should never overflow. We don't recycle ObjectIds that would overflow
// their next serial.
ASSERT(mObjects[id].serial != 0);
mObjects[id].generation++;
// The generation should never overflow. We don't recycle ObjectIds that would
// overflow their next generation.
ASSERT(mObjects[id].generation != 0);
mObjects[id].object = std::move(object);
}
@ -66,8 +66,9 @@ namespace dawn_wire { namespace client {
return &mObjects[id];
}
void Free(T* obj) {
if (DAWN_LIKELY(mObjects[obj->id].serial != std::numeric_limits<uint32_t>::max())) {
// Only recycle this ObjectId if the serial won't overflow on the next allocation.
if (DAWN_LIKELY(mObjects[obj->id].generation != std::numeric_limits<uint32_t>::max())) {
// Only recycle this ObjectId if the generation won't overflow on the next
// allocation.
FreeId(obj->id);
}
mObjects[obj->id].object = nullptr;
@ -80,11 +81,11 @@ namespace dawn_wire { namespace client {
return mObjects[id].object.get();
}
uint32_t GetSerial(uint32_t id) {
uint32_t GetGeneration(uint32_t id) {
if (id >= mObjects.size()) {
return 0;
}
return mObjects[id].serial;
return mObjects[id].generation;
}
private:

View File

@ -25,9 +25,9 @@ namespace dawn_wire { namespace server {
template <typename T>
struct ObjectDataBase {
// The backend-provided handle and serial to this object.
// The backend-provided handle and generation to this object.
T handle;
uint32_t serial = 0;
uint32_t generation = 0;
// Whether this object has been allocated, used by the KnownObjects queries
// TODO(cwallez@chromium.org): make this an internal bit vector in KnownObjects.

View File

@ -50,7 +50,7 @@ namespace dawn_wire { namespace server {
}
data->handle = texture;
data->serial = generation;
data->generation = generation;
data->allocated = true;
// The texture is externally owned so it shouldn't be destroyed when we receive a destroy

View File

@ -70,7 +70,7 @@ namespace dawn_wire { namespace server {
std::unique_ptr<MapUserdata> userdata = std::make_unique<MapUserdata>();
userdata->server = this;
userdata->buffer = ObjectHandle{bufferId, buffer->serial};
userdata->buffer = ObjectHandle{bufferId, buffer->generation};
userdata->requestSerial = requestSerial;
// The handle will point to the mapped memory or staging memory for the mapping.
@ -120,7 +120,7 @@ namespace dawn_wire { namespace server {
if (resultData == nullptr) {
return false;
}
resultData->serial = bufferResult.serial;
resultData->generation = bufferResult.generation;
WGPUCreateBufferMappedResult result = mProcs.deviceCreateBufferMapped(device, descriptor);
ASSERT(result.buffer != nullptr);
@ -168,7 +168,7 @@ namespace dawn_wire { namespace server {
ASSERT(bufferData != nullptr);
ReturnBufferMapWriteAsyncCallbackCmd cmd;
cmd.buffer = ObjectHandle{bufferResult.id, bufferResult.serial};
cmd.buffer = ObjectHandle{bufferResult.id, bufferResult.generation};
cmd.requestSerial = requestSerial;
cmd.status = bufferData->mapWriteState == BufferMapWriteState::Mapped
? WGPUBufferMapAsyncStatus_Success
@ -260,7 +260,7 @@ namespace dawn_wire { namespace server {
// Skip sending the callback if the buffer has already been destroyed.
auto* bufferData = BufferObjects().Get(data->buffer.id);
if (bufferData == nullptr || bufferData->serial != data->buffer.serial) {
if (bufferData == nullptr || bufferData->generation != data->buffer.generation) {
return;
}
@ -302,7 +302,7 @@ namespace dawn_wire { namespace server {
// Skip sending the callback if the buffer has already been destroyed.
auto* bufferData = BufferObjects().Get(data->buffer.id);
if (bufferData == nullptr || bufferData->serial != data->buffer.serial) {
if (bufferData == nullptr || bufferData->generation != data->buffer.generation) {
return;
}

View File

@ -31,7 +31,7 @@ namespace dawn_wire { namespace server {
FenceCompletionUserdata* userdata = new FenceCompletionUserdata;
userdata->server = this;
userdata->fence = ObjectHandle{fenceId, fence->serial};
userdata->fence = ObjectHandle{fenceId, fence->generation};
userdata->value = signalValue;
mProcs.fenceOnCompletion(cFence, signalValue, ForwardFenceCompletedValue, userdata);