2022-02-04 12:51:25 +00:00
|
|
|
// Copyright 2019 The Dawn Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-04-11 18:30:50 +00:00
|
|
|
#ifndef INCLUDE_DAWN_WIRE_WIRECLIENT_H_
|
|
|
|
#define INCLUDE_DAWN_WIRE_WIRECLIENT_H_
|
2022-02-04 12:51:25 +00:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-04-12 17:48:19 +00:00
|
|
|
#include "dawn/dawn_proc_table.h"
|
|
|
|
#include "dawn/wire/Wire.h"
|
|
|
|
|
2022-02-04 12:51:25 +00:00
|
|
|
namespace dawn::wire {
|
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
namespace client {
|
|
|
|
class Client;
|
|
|
|
class MemoryTransferService;
|
|
|
|
|
|
|
|
DAWN_WIRE_EXPORT const DawnProcTable& GetProcs();
|
|
|
|
} // namespace client
|
|
|
|
|
|
|
|
struct ReservedTexture {
|
|
|
|
WGPUTexture texture;
|
|
|
|
uint32_t id;
|
|
|
|
uint32_t generation;
|
|
|
|
uint32_t deviceId;
|
|
|
|
uint32_t deviceGeneration;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ReservedSwapChain {
|
|
|
|
WGPUSwapChain swapchain;
|
|
|
|
uint32_t id;
|
|
|
|
uint32_t generation;
|
|
|
|
uint32_t deviceId;
|
|
|
|
uint32_t deviceGeneration;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ReservedDevice {
|
|
|
|
WGPUDevice device;
|
|
|
|
uint32_t id;
|
|
|
|
uint32_t generation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ReservedInstance {
|
|
|
|
WGPUInstance instance;
|
|
|
|
uint32_t id;
|
|
|
|
uint32_t generation;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DAWN_WIRE_EXPORT WireClientDescriptor {
|
|
|
|
CommandSerializer* serializer;
|
|
|
|
client::MemoryTransferService* memoryTransferService = nullptr;
|
|
|
|
};
|
|
|
|
|
|
|
|
class DAWN_WIRE_EXPORT WireClient : public CommandHandler {
|
|
|
|
public:
|
|
|
|
explicit WireClient(const WireClientDescriptor& descriptor);
|
|
|
|
~WireClient() override;
|
|
|
|
|
2022-05-12 13:17:47 +00:00
|
|
|
const volatile char* HandleCommands(const volatile char* commands, size_t size) override;
|
2022-05-01 14:40:55 +00:00
|
|
|
|
2022-06-19 20:13:01 +00:00
|
|
|
ReservedTexture ReserveTexture(WGPUDevice device,
|
2022-06-28 15:55:16 +00:00
|
|
|
const WGPUTextureDescriptor* descriptor);
|
2022-05-01 14:40:55 +00:00
|
|
|
ReservedSwapChain ReserveSwapChain(WGPUDevice device);
|
|
|
|
ReservedDevice ReserveDevice();
|
|
|
|
ReservedInstance ReserveInstance();
|
|
|
|
|
|
|
|
void ReclaimTextureReservation(const ReservedTexture& reservation);
|
|
|
|
void ReclaimSwapChainReservation(const ReservedSwapChain& reservation);
|
|
|
|
void ReclaimDeviceReservation(const ReservedDevice& reservation);
|
|
|
|
void ReclaimInstanceReservation(const ReservedInstance& reservation);
|
|
|
|
|
|
|
|
// Disconnects the client.
|
|
|
|
// Commands allocated after this point will not be sent.
|
|
|
|
void Disconnect();
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<client::Client> mImpl;
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace client {
|
|
|
|
class DAWN_WIRE_EXPORT MemoryTransferService {
|
|
|
|
public:
|
|
|
|
MemoryTransferService();
|
|
|
|
virtual ~MemoryTransferService();
|
|
|
|
|
|
|
|
class ReadHandle;
|
|
|
|
class WriteHandle;
|
|
|
|
|
|
|
|
// Create a handle for reading server data.
|
|
|
|
// This may fail and return nullptr.
|
|
|
|
virtual ReadHandle* CreateReadHandle(size_t) = 0;
|
|
|
|
|
|
|
|
// Create a handle for writing server data.
|
|
|
|
// This may fail and return nullptr.
|
|
|
|
virtual WriteHandle* CreateWriteHandle(size_t) = 0;
|
|
|
|
|
|
|
|
class DAWN_WIRE_EXPORT ReadHandle {
|
|
|
|
public:
|
|
|
|
ReadHandle();
|
|
|
|
virtual ~ReadHandle();
|
|
|
|
|
|
|
|
// Get the required serialization size for SerializeCreate
|
|
|
|
virtual size_t SerializeCreateSize() = 0;
|
|
|
|
|
|
|
|
// Serialize the handle into |serializePointer| so it can be received by the server.
|
|
|
|
virtual void SerializeCreate(void* serializePointer) = 0;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
virtual const void* GetData() = 0;
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
// Needs to check potential offset/size OOB and overflow
|
|
|
|
virtual bool DeserializeDataUpdate(const void* deserializePointer,
|
|
|
|
size_t deserializeSize,
|
|
|
|
size_t offset,
|
|
|
|
size_t size) = 0;
|
2022-02-04 12:51:25 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
private:
|
|
|
|
ReadHandle(const ReadHandle&) = delete;
|
|
|
|
ReadHandle& operator=(const ReadHandle&) = delete;
|
2022-02-04 12:51:25 +00:00
|
|
|
};
|
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
class DAWN_WIRE_EXPORT WriteHandle {
|
2022-02-04 12:51:25 +00:00
|
|
|
public:
|
2022-05-01 14:40:55 +00:00
|
|
|
WriteHandle();
|
|
|
|
virtual ~WriteHandle();
|
2022-02-04 12:51:25 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
// Get the required serialization size for SerializeCreate
|
|
|
|
virtual size_t SerializeCreateSize() = 0;
|
2022-02-04 12:51:25 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
// Serialize the handle into |serializePointer| so it can be received by the server.
|
|
|
|
virtual void SerializeCreate(void* serializePointer) = 0;
|
2022-02-04 12:51:25 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
// 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 void* GetData() = 0;
|
2022-02-04 12:51:25 +00:00
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
// Get the required serialization size for SerializeDataUpdate
|
|
|
|
virtual size_t SizeOfSerializeDataUpdate(size_t offset, size_t size) = 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)
|
|
|
|
virtual void SerializeDataUpdate(void* serializePointer, size_t offset, size_t size) = 0;
|
2022-02-04 12:51:25 +00:00
|
|
|
|
|
|
|
private:
|
2022-05-01 14:40:55 +00:00
|
|
|
WriteHandle(const WriteHandle&) = delete;
|
|
|
|
WriteHandle& operator=(const WriteHandle&) = delete;
|
2022-02-04 12:51:25 +00:00
|
|
|
};
|
|
|
|
|
2022-05-01 14:40:55 +00:00
|
|
|
private:
|
|
|
|
MemoryTransferService(const MemoryTransferService&) = delete;
|
|
|
|
MemoryTransferService& operator=(const MemoryTransferService&) = delete;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Backdoor to get the order of the ProcMap for testing
|
|
|
|
DAWN_WIRE_EXPORT std::vector<const char*> GetProcMapNamesForTesting();
|
|
|
|
} // namespace client
|
2022-02-04 12:51:25 +00:00
|
|
|
} // namespace dawn::wire
|
|
|
|
|
2022-04-11 18:30:50 +00:00
|
|
|
#endif // INCLUDE_DAWN_WIRE_WIRECLIENT_H_
|