Add placeholder virtual functions to dawn_wire Read/WriteHandle

Updated interface design is at
https://bugs.chromium.org/p/dawn/issues/detail?id=773#c21

Prelanding CL to avoid breaking change.
The proposed usage is at
https://dawn-review.googlesource.com/c/dawn/+/51164

Bug: dawn:773
Change-Id: If27396e60574b4a52fcda60e111bad33c9d63563
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/54140
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Shrek Shao <shrekshao@google.com>
This commit is contained in:
shrekshao 2021-06-28 18:22:31 +00:00 committed by Dawn LUCI CQ
parent a68489fb83
commit 81372da137
3 changed files with 98 additions and 38 deletions

View File

@ -62,16 +62,6 @@ namespace dawn_wire {
MemoryTransferService::~MemoryTransferService() = default; MemoryTransferService::~MemoryTransferService() = default;
MemoryTransferService::ReadHandle*
MemoryTransferService::CreateReadHandle(WGPUBuffer buffer, uint64_t offset, size_t size) {
return CreateReadHandle(size);
}
MemoryTransferService::WriteHandle*
MemoryTransferService::CreateWriteHandle(WGPUBuffer buffer, uint64_t offset, size_t size) {
return CreateWriteHandle(size);
}
MemoryTransferService::ReadHandle::ReadHandle() = default; MemoryTransferService::ReadHandle::ReadHandle() = default;
MemoryTransferService::ReadHandle::~ReadHandle() = default; MemoryTransferService::ReadHandle::~ReadHandle() = default;

View File

@ -98,12 +98,6 @@ namespace dawn_wire {
// This may fail and return nullptr. // This may fail and return nullptr.
virtual WriteHandle* CreateWriteHandle(size_t) = 0; virtual WriteHandle* CreateWriteHandle(size_t) = 0;
// Imported memory implementation needs to override these to create Read/Write
// handles associated with a particular buffer. The client should receive a file
// descriptor for the buffer out-of-band.
virtual ReadHandle* CreateReadHandle(WGPUBuffer, uint64_t offset, size_t size);
virtual WriteHandle* CreateWriteHandle(WGPUBuffer, uint64_t offset, size_t size);
class DAWN_WIRE_EXPORT ReadHandle { class DAWN_WIRE_EXPORT ReadHandle {
public: public:
ReadHandle(); ReadHandle();
@ -115,16 +109,33 @@ namespace dawn_wire {
// Serialize the handle into |serializePointer| so it can be received by the server. // Serialize the handle into |serializePointer| so it can be received by the server.
virtual void SerializeCreate(void* serializePointer) = 0; virtual void SerializeCreate(void* serializePointer) = 0;
// Load initial data and open the handle for reading. // Simply return the base address of the allocation (without applying any offset)
// This function takes in the serialized result of // Returns nullptr if the allocation failed.
// server::MemoryTransferService::ReadHandle::SerializeInitialData. // The data must live at least until the ReadHandle is destructued
// This function should write to |data| and |dataLength| the pointer and size of the // TODO(dawn:773): change to pure virtual after update on chromium side.
// mapped data for reading. It must live at least until the ReadHandle is virtual const void* GetData() {
// destructed. return nullptr;
}
// Gets called when a MapReadCallback resolves.
// deserialize the data update and apply
// it to the range (offset, offset + size) of allocation
// There could be nothing to be deserialized (if using shared memory)
// TODO(dawn:773): change to pure virtual after update on chromium side.
virtual bool DeserializeDataUpdate(const void* deserializePointer,
size_t deserializeSize,
size_t offset,
size_t size) {
return false;
}
// TODO(dawn:773): remove after update on chromium side.
virtual bool DeserializeInitialData(const void* deserializePointer, virtual bool DeserializeInitialData(const void* deserializePointer,
size_t deserializeSize, size_t deserializeSize,
const void** data, const void** data,
size_t* dataLength) = 0; size_t* dataLength) {
return false;
}
private: private:
ReadHandle(const ReadHandle&) = delete; ReadHandle(const ReadHandle&) = delete;
@ -142,17 +153,44 @@ namespace dawn_wire {
// Serialize the handle into |serializePointer| so it can be received by the server. // Serialize the handle into |serializePointer| so it can be received by the server.
virtual void SerializeCreate(void* serializePointer) = 0; virtual void SerializeCreate(void* serializePointer) = 0;
// Open the handle for reading. The data returned should be zero-initialized. // Simply return the base address of the allocation (without applying any offset)
// The data returned should be zero-initialized.
// The data returned must live at least until the WriteHandle is destructed. // The data returned must live at least until the WriteHandle is destructed.
// On failure, the pointer returned should be null. // On failure, the pointer returned should be null.
virtual std::pair<void*, size_t> Open() = 0; // TODO(dawn:773): change to pure virtual after update on chromium side.
virtual void* GetData() {
return nullptr;
}
// Get the required serialization size for SerializeFlush // Get the required serialization size for SerializeDataUpdate
virtual size_t SerializeFlushSize() = 0; // TODO(dawn:773): change to pure virtual after update on chromium side.
virtual size_t SizeOfSerializeDataUpdate(size_t offset, size_t size) {
return 0;
}
// Flush writes to the handle. This should serialize info to send updates to the // Serialize a command to send the modified contents of
// server. // the subrange (offset, offset + size) of the allocation at buffer unmap
virtual void SerializeFlush(void* serializePointer) = 0; // This subrange is always the whole mapped region for now
// There could be nothing to be serialized (if using shared memory)
// TODO(dawn:773): change to pure virtual after update on chromium side.
virtual void SerializeDataUpdate(void* serializePointer,
size_t offset,
size_t size) {
}
// TODO(dawn:773): remove after update on chromium side.
virtual std::pair<void*, size_t> Open() {
return std::make_pair(nullptr, 0);
}
// TODO(dawn:773): remove after update on chromium side.
virtual size_t SerializeFlushSize() {
return 0;
}
// TODO(dawn:773): remove after update on chromium side.
virtual void SerializeFlush(void* serializePointer) {
}
private: private:
WriteHandle(const WriteHandle&) = delete; WriteHandle(const WriteHandle&) = delete;

View File

@ -91,14 +91,34 @@ namespace dawn_wire {
ReadHandle(); ReadHandle();
virtual ~ReadHandle(); virtual ~ReadHandle();
// Get the required serialization size for SerializeInitialData // Return the size of the command serialized if
virtual size_t SerializeInitialDataSize(const void* data, size_t dataLength) = 0; // SerializeDataUpdate is called with the same offset/size args
// TODO(dawn:773): change to pure virtual after update on chromium side.
virtual size_t SizeOfSerializeDataUpdate(size_t offset, size_t size) {
return 0;
}
// Initialize the handle data. // Gets called when a MapReadCallback resolves.
// Serialize into |serializePointer| so the client can update handle data. // Serialize the data update for the range (offset, offset + size) into
// |serializePointer| to the client There could be nothing to be serialized (if
// using shared memory)
// TODO(dawn:773): change to pure virtual after update on chromium side.
virtual void SerializeDataUpdate(const void* data,
size_t offset,
size_t size,
void* serializePointer) {
}
// TODO(dawn:773): remove after update on chromium side.
virtual size_t SerializeInitialDataSize(const void* data, size_t dataLength) {
return 0;
}
// TODO(dawn:773): remove after update on chromium side.
virtual void SerializeInitialData(const void* data, virtual void SerializeInitialData(const void* data,
size_t dataLength, size_t dataLength,
void* serializePointer) = 0; void* serializePointer) {
}
private: private:
ReadHandle(const ReadHandle&) = delete; ReadHandle(const ReadHandle&) = delete;
@ -112,15 +132,27 @@ namespace dawn_wire {
// Set the target for writes from the client. DeserializeFlush should copy data // Set the target for writes from the client. DeserializeFlush should copy data
// into the target. // into the target.
// TODO(dawn:773): only set backing buffer pointer data
void SetTarget(void* data, size_t dataLength); void SetTarget(void* data, size_t dataLength);
// This function takes in the serialized result of // TODO(dawn:773): remove after update on chromium side.
// client::MemoryTransferService::WriteHandle::SerializeFlush.
virtual bool DeserializeFlush(const void* deserializePointer, virtual bool DeserializeFlush(const void* deserializePointer,
size_t deserializeSize) = 0; size_t deserializeSize) {
return false;
}
// This function takes in the serialized result of
// client::MemoryTransferService::WriteHandle::SerializeDataUpdate.
virtual bool DeserializeDataUpdate(const void* deserializePointer,
size_t deserializeSize,
size_t offset,
size_t size) {
return false;
}
protected: protected:
void* mTargetData = nullptr; void* mTargetData = nullptr;
// TODO(dawn:773): only set backing buffer pointer data
size_t mDataLength = 0; size_t mDataLength = 0;
private: private: