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

View File

@ -98,12 +98,6 @@ namespace dawn_wire {
// This may fail and return nullptr.
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 {
public:
ReadHandle();
@ -115,16 +109,33 @@ namespace dawn_wire {
// Serialize the handle into |serializePointer| so it can be received by the server.
virtual void SerializeCreate(void* serializePointer) = 0;
// Load initial data and open the handle for reading.
// This function takes in the serialized result of
// server::MemoryTransferService::ReadHandle::SerializeInitialData.
// This function should write to |data| and |dataLength| the pointer and size of the
// mapped data for reading. It must live at least until the ReadHandle is
// destructed.
// Simply return the base address of the allocation (without applying any offset)
// Returns nullptr if the allocation failed.
// The data must live at least until the ReadHandle is destructued
// TODO(dawn:773): change to pure virtual after update on chromium side.
virtual const void* GetData() {
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,
size_t deserializeSize,
const void** data,
size_t* dataLength) = 0;
size_t* dataLength) {
return false;
}
private:
ReadHandle(const ReadHandle&) = delete;
@ -142,17 +153,44 @@ namespace dawn_wire {
// Serialize the handle into |serializePointer| so it can be received by the server.
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.
// 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
virtual size_t SerializeFlushSize() = 0;
// Get the required serialization size for SerializeDataUpdate
// 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
// server.
virtual void SerializeFlush(void* serializePointer) = 0;
// Serialize a command to send the modified contents of
// the subrange (offset, offset + size) of the allocation at buffer unmap
// 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:
WriteHandle(const WriteHandle&) = delete;

View File

@ -91,14 +91,34 @@ namespace dawn_wire {
ReadHandle();
virtual ~ReadHandle();
// Get the required serialization size for SerializeInitialData
virtual size_t SerializeInitialDataSize(const void* data, size_t dataLength) = 0;
// Return the size of the command serialized if
// 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.
// Serialize into |serializePointer| so the client can update handle data.
// Gets called when a MapReadCallback resolves.
// 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,
size_t dataLength,
void* serializePointer) = 0;
void* serializePointer) {
}
private:
ReadHandle(const ReadHandle&) = delete;
@ -112,15 +132,27 @@ namespace dawn_wire {
// Set the target for writes from the client. DeserializeFlush should copy data
// into the target.
// TODO(dawn:773): only set backing buffer pointer data
void SetTarget(void* data, size_t dataLength);
// This function takes in the serialized result of
// client::MemoryTransferService::WriteHandle::SerializeFlush.
// TODO(dawn:773): remove after update on chromium side.
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:
void* mTargetData = nullptr;
// TODO(dawn:773): only set backing buffer pointer data
size_t mDataLength = 0;
private: