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:
parent
077a427499
commit
518c8e77ab
|
@ -422,16 +422,20 @@ namespace dawn_wire {
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
ObjectHandle::ObjectHandle() = default;
|
ObjectHandle::ObjectHandle() = default;
|
||||||
ObjectHandle::ObjectHandle(ObjectId id, ObjectSerial serial) : id(id), serial(serial) {}
|
ObjectHandle::ObjectHandle(ObjectId id, ObjectGeneration generation)
|
||||||
ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs) : id(rhs.id), serial(rhs.serial) {}
|
: id(id), generation(generation) {
|
||||||
|
}
|
||||||
|
ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs)
|
||||||
|
: id(rhs.id), generation(rhs.generation) {
|
||||||
|
}
|
||||||
ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) {
|
ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) {
|
||||||
id = rhs.id;
|
id = rhs.id;
|
||||||
serial = rhs.serial;
|
generation = rhs.generation;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) {
|
ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) {
|
||||||
id = rhs.id;
|
id = rhs.id;
|
||||||
serial = rhs.serial;
|
generation = rhs.generation;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,13 @@
|
||||||
namespace dawn_wire {
|
namespace dawn_wire {
|
||||||
|
|
||||||
using ObjectId = uint32_t;
|
using ObjectId = uint32_t;
|
||||||
using ObjectSerial = uint32_t;
|
using ObjectGeneration = uint32_t;
|
||||||
struct ObjectHandle {
|
struct ObjectHandle {
|
||||||
ObjectId id;
|
ObjectId id;
|
||||||
ObjectSerial serial;
|
ObjectGeneration generation;
|
||||||
|
|
||||||
ObjectHandle();
|
ObjectHandle();
|
||||||
ObjectHandle(ObjectId id, ObjectSerial serial);
|
ObjectHandle(ObjectId id, ObjectGeneration generation);
|
||||||
ObjectHandle(const volatile ObjectHandle& rhs);
|
ObjectHandle(const volatile ObjectHandle& rhs);
|
||||||
|
|
||||||
// MSVC has a bug where it thinks the volatile copy assignment is a duplicate.
|
// MSVC has a bug where it thinks the volatile copy assignment is a duplicate.
|
||||||
|
|
|
@ -47,7 +47,7 @@ namespace dawn_wire { namespace 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* allocation = self->device->GetClient()->{{method.return_type.name.CamelCase()}}Allocator().New(self->device);
|
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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% for arg in method.arguments %}
|
{% for arg in method.arguments %}
|
||||||
|
|
|
@ -33,8 +33,8 @@ namespace dawn_wire { namespace client {
|
||||||
|
|
||||||
{% if member.type.dict_name == "ObjectHandle" %}
|
{% if member.type.dict_name == "ObjectHandle" %}
|
||||||
{{Type}}* {{name}} = {{Type}}Allocator().GetObject(cmd.{{name}}.id);
|
{{Type}}* {{name}} = {{Type}}Allocator().GetObject(cmd.{{name}}.id);
|
||||||
uint32_t {{name}}Serial = {{Type}}Allocator().GetSerial(cmd.{{name}}.id);
|
uint32_t {{name}}Generation = {{Type}}Allocator().GetGeneration(cmd.{{name}}.id);
|
||||||
if ({{name}}Serial != cmd.{{name}}.serial) {
|
if ({{name}}Generation != cmd.{{name}}.generation) {
|
||||||
{{name}} = nullptr;
|
{{name}} = nullptr;
|
||||||
}
|
}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace dawn_wire { namespace server {
|
||||||
if ({{name}}Data == nullptr) {
|
if ({{name}}Data == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
{{name}}Data->serial = cmd.{{name}}.serial;
|
{{name}}Data->generation = cmd.{{name}}.generation;
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
//* Do command
|
//* Do command
|
||||||
|
|
|
@ -121,7 +121,7 @@ namespace dawn_wire { namespace client {
|
||||||
DeviceCreateBufferCmd cmd;
|
DeviceCreateBufferCmd cmd;
|
||||||
cmd.self = cDevice;
|
cmd.self = cDevice;
|
||||||
cmd.descriptor = descriptor;
|
cmd.descriptor = descriptor;
|
||||||
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->serial};
|
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->generation};
|
||||||
|
|
||||||
size_t requiredSize = cmd.GetRequiredSize();
|
size_t requiredSize = cmd.GetRequiredSize();
|
||||||
char* allocatedBuffer = static_cast<char*>(wireClient->GetCmdSpace(requiredSize));
|
char* allocatedBuffer = static_cast<char*>(wireClient->GetCmdSpace(requiredSize));
|
||||||
|
@ -176,7 +176,7 @@ namespace dawn_wire { namespace client {
|
||||||
DeviceCreateBufferMappedCmd cmd;
|
DeviceCreateBufferMappedCmd cmd;
|
||||||
cmd.device = cDevice;
|
cmd.device = cDevice;
|
||||||
cmd.descriptor = descriptor;
|
cmd.descriptor = descriptor;
|
||||||
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->serial};
|
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->generation};
|
||||||
cmd.handleCreateInfoLength = handleCreateInfoLength;
|
cmd.handleCreateInfoLength = handleCreateInfoLength;
|
||||||
cmd.handleCreateInfo = nullptr;
|
cmd.handleCreateInfo = nullptr;
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ namespace dawn_wire { namespace client {
|
||||||
cmd.device = cDevice;
|
cmd.device = cDevice;
|
||||||
cmd.descriptor = descriptor;
|
cmd.descriptor = descriptor;
|
||||||
cmd.requestSerial = serial;
|
cmd.requestSerial = serial;
|
||||||
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->serial};
|
cmd.result = ObjectHandle{buffer->id, bufferObjectAndSerial->generation};
|
||||||
cmd.handleCreateInfoLength = handleCreateInfoLength;
|
cmd.handleCreateInfoLength = handleCreateInfoLength;
|
||||||
cmd.handleCreateInfo = nullptr;
|
cmd.handleCreateInfo = nullptr;
|
||||||
|
|
||||||
|
@ -391,7 +391,7 @@ namespace dawn_wire { namespace client {
|
||||||
QueueCreateFenceCmd cmd;
|
QueueCreateFenceCmd cmd;
|
||||||
cmd.self = cSelf;
|
cmd.self = cSelf;
|
||||||
auto* allocation = device->GetClient()->FenceAllocator().New(device);
|
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;
|
cmd.descriptor = descriptor;
|
||||||
|
|
||||||
size_t requiredSize = cmd.GetRequiredSize();
|
size_t requiredSize = cmd.GetRequiredSize();
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace dawn_wire { namespace client {
|
||||||
ReservedTexture result;
|
ReservedTexture result;
|
||||||
result.texture = reinterpret_cast<WGPUTexture>(allocation->object.get());
|
result.texture = reinterpret_cast<WGPUTexture>(allocation->object.get());
|
||||||
result.id = allocation->object->id;
|
result.id = allocation->object->id;
|
||||||
result.generation = allocation->serial;
|
result.generation = allocation->generation;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,11 @@ namespace dawn_wire { namespace client {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
struct ObjectAndSerial {
|
struct ObjectAndSerial {
|
||||||
ObjectAndSerial(std::unique_ptr<T> object, uint32_t serial)
|
ObjectAndSerial(std::unique_ptr<T> object, uint32_t generation)
|
||||||
: object(std::move(object)), serial(serial) {
|
: object(std::move(object)), generation(generation) {
|
||||||
}
|
}
|
||||||
std::unique_ptr<T> object;
|
std::unique_ptr<T> object;
|
||||||
uint32_t serial;
|
uint32_t generation;
|
||||||
};
|
};
|
||||||
|
|
||||||
ObjectAllocator() {
|
ObjectAllocator() {
|
||||||
|
@ -55,10 +55,10 @@ namespace dawn_wire { namespace client {
|
||||||
} else {
|
} else {
|
||||||
ASSERT(mObjects[id].object == nullptr);
|
ASSERT(mObjects[id].object == nullptr);
|
||||||
|
|
||||||
mObjects[id].serial++;
|
mObjects[id].generation++;
|
||||||
// The serial should never overflow. We don't recycle ObjectIds that would overflow
|
// The generation should never overflow. We don't recycle ObjectIds that would
|
||||||
// their next serial.
|
// overflow their next generation.
|
||||||
ASSERT(mObjects[id].serial != 0);
|
ASSERT(mObjects[id].generation != 0);
|
||||||
|
|
||||||
mObjects[id].object = std::move(object);
|
mObjects[id].object = std::move(object);
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,9 @@ namespace dawn_wire { namespace client {
|
||||||
return &mObjects[id];
|
return &mObjects[id];
|
||||||
}
|
}
|
||||||
void Free(T* obj) {
|
void Free(T* obj) {
|
||||||
if (DAWN_LIKELY(mObjects[obj->id].serial != std::numeric_limits<uint32_t>::max())) {
|
if (DAWN_LIKELY(mObjects[obj->id].generation != std::numeric_limits<uint32_t>::max())) {
|
||||||
// Only recycle this ObjectId if the serial won't overflow on the next allocation.
|
// Only recycle this ObjectId if the generation won't overflow on the next
|
||||||
|
// allocation.
|
||||||
FreeId(obj->id);
|
FreeId(obj->id);
|
||||||
}
|
}
|
||||||
mObjects[obj->id].object = nullptr;
|
mObjects[obj->id].object = nullptr;
|
||||||
|
@ -80,11 +81,11 @@ namespace dawn_wire { namespace client {
|
||||||
return mObjects[id].object.get();
|
return mObjects[id].object.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t GetSerial(uint32_t id) {
|
uint32_t GetGeneration(uint32_t id) {
|
||||||
if (id >= mObjects.size()) {
|
if (id >= mObjects.size()) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return mObjects[id].serial;
|
return mObjects[id].generation;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -25,9 +25,9 @@ namespace dawn_wire { namespace server {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct ObjectDataBase {
|
struct ObjectDataBase {
|
||||||
// The backend-provided handle and serial to this object.
|
// The backend-provided handle and generation to this object.
|
||||||
T handle;
|
T handle;
|
||||||
uint32_t serial = 0;
|
uint32_t generation = 0;
|
||||||
|
|
||||||
// Whether this object has been allocated, used by the KnownObjects queries
|
// Whether this object has been allocated, used by the KnownObjects queries
|
||||||
// TODO(cwallez@chromium.org): make this an internal bit vector in KnownObjects.
|
// TODO(cwallez@chromium.org): make this an internal bit vector in KnownObjects.
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace dawn_wire { namespace server {
|
||||||
}
|
}
|
||||||
|
|
||||||
data->handle = texture;
|
data->handle = texture;
|
||||||
data->serial = generation;
|
data->generation = generation;
|
||||||
data->allocated = true;
|
data->allocated = true;
|
||||||
|
|
||||||
// The texture is externally owned so it shouldn't be destroyed when we receive a destroy
|
// The texture is externally owned so it shouldn't be destroyed when we receive a destroy
|
||||||
|
|
|
@ -70,7 +70,7 @@ namespace dawn_wire { namespace server {
|
||||||
|
|
||||||
std::unique_ptr<MapUserdata> userdata = std::make_unique<MapUserdata>();
|
std::unique_ptr<MapUserdata> userdata = std::make_unique<MapUserdata>();
|
||||||
userdata->server = this;
|
userdata->server = this;
|
||||||
userdata->buffer = ObjectHandle{bufferId, buffer->serial};
|
userdata->buffer = ObjectHandle{bufferId, buffer->generation};
|
||||||
userdata->requestSerial = requestSerial;
|
userdata->requestSerial = requestSerial;
|
||||||
|
|
||||||
// The handle will point to the mapped memory or staging memory for the mapping.
|
// 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) {
|
if (resultData == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
resultData->serial = bufferResult.serial;
|
resultData->generation = bufferResult.generation;
|
||||||
|
|
||||||
WGPUCreateBufferMappedResult result = mProcs.deviceCreateBufferMapped(device, descriptor);
|
WGPUCreateBufferMappedResult result = mProcs.deviceCreateBufferMapped(device, descriptor);
|
||||||
ASSERT(result.buffer != nullptr);
|
ASSERT(result.buffer != nullptr);
|
||||||
|
@ -168,7 +168,7 @@ namespace dawn_wire { namespace server {
|
||||||
ASSERT(bufferData != nullptr);
|
ASSERT(bufferData != nullptr);
|
||||||
|
|
||||||
ReturnBufferMapWriteAsyncCallbackCmd cmd;
|
ReturnBufferMapWriteAsyncCallbackCmd cmd;
|
||||||
cmd.buffer = ObjectHandle{bufferResult.id, bufferResult.serial};
|
cmd.buffer = ObjectHandle{bufferResult.id, bufferResult.generation};
|
||||||
cmd.requestSerial = requestSerial;
|
cmd.requestSerial = requestSerial;
|
||||||
cmd.status = bufferData->mapWriteState == BufferMapWriteState::Mapped
|
cmd.status = bufferData->mapWriteState == BufferMapWriteState::Mapped
|
||||||
? WGPUBufferMapAsyncStatus_Success
|
? WGPUBufferMapAsyncStatus_Success
|
||||||
|
@ -260,7 +260,7 @@ namespace dawn_wire { namespace server {
|
||||||
|
|
||||||
// Skip sending the callback if the buffer has already been destroyed.
|
// Skip sending the callback if the buffer has already been destroyed.
|
||||||
auto* bufferData = BufferObjects().Get(data->buffer.id);
|
auto* bufferData = BufferObjects().Get(data->buffer.id);
|
||||||
if (bufferData == nullptr || bufferData->serial != data->buffer.serial) {
|
if (bufferData == nullptr || bufferData->generation != data->buffer.generation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ namespace dawn_wire { namespace server {
|
||||||
|
|
||||||
// Skip sending the callback if the buffer has already been destroyed.
|
// Skip sending the callback if the buffer has already been destroyed.
|
||||||
auto* bufferData = BufferObjects().Get(data->buffer.id);
|
auto* bufferData = BufferObjects().Get(data->buffer.id);
|
||||||
if (bufferData == nullptr || bufferData->serial != data->buffer.serial) {
|
if (bufferData == nullptr || bufferData->generation != data->buffer.generation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace dawn_wire { namespace server {
|
||||||
|
|
||||||
FenceCompletionUserdata* userdata = new FenceCompletionUserdata;
|
FenceCompletionUserdata* userdata = new FenceCompletionUserdata;
|
||||||
userdata->server = this;
|
userdata->server = this;
|
||||||
userdata->fence = ObjectHandle{fenceId, fence->serial};
|
userdata->fence = ObjectHandle{fenceId, fence->generation};
|
||||||
userdata->value = signalValue;
|
userdata->value = signalValue;
|
||||||
|
|
||||||
mProcs.fenceOnCompletion(cFence, signalValue, ForwardFenceCompletedValue, userdata);
|
mProcs.fenceOnCompletion(cFence, signalValue, ForwardFenceCompletedValue, userdata);
|
||||||
|
|
Loading…
Reference in New Issue