2018-07-18 09:40:26 +00:00
|
|
|
//* Copyright 2017 The Dawn Authors
|
2017-04-20 18:38:20 +00:00
|
|
|
//*
|
|
|
|
//* 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.
|
|
|
|
|
2018-07-26 13:07:57 +00:00
|
|
|
#ifndef DAWNWIRE_WIRECMD_AUTOGEN_H_
|
|
|
|
#define DAWNWIRE_WIRECMD_AUTOGEN_H_
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2022-04-19 14:24:04 +00:00
|
|
|
#include "dawn/webgpu.h"
|
2019-01-15 20:49:53 +00:00
|
|
|
|
2022-02-04 12:51:25 +00:00
|
|
|
#include "dawn/wire/BufferConsumer.h"
|
|
|
|
#include "dawn/wire/ObjectType_autogen.h"
|
|
|
|
#include "dawn/wire/WireResult.h"
|
2020-11-11 19:46:18 +00:00
|
|
|
|
2022-01-11 09:57:33 +00:00
|
|
|
namespace dawn::wire {
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-06-06 15:36:49 +00:00
|
|
|
using ObjectId = uint32_t;
|
2020-04-13 17:50:51 +00:00
|
|
|
using ObjectGeneration = uint32_t;
|
2019-01-15 20:49:53 +00:00
|
|
|
struct ObjectHandle {
|
|
|
|
ObjectId id;
|
2020-04-13 17:50:51 +00:00
|
|
|
ObjectGeneration generation;
|
2019-10-07 20:38:47 +00:00
|
|
|
|
|
|
|
ObjectHandle();
|
2020-04-13 17:50:51 +00:00
|
|
|
ObjectHandle(ObjectId id, ObjectGeneration generation);
|
2020-04-24 17:02:53 +00:00
|
|
|
|
2019-10-07 20:38:47 +00:00
|
|
|
ObjectHandle(const volatile ObjectHandle& rhs);
|
2020-04-24 17:02:53 +00:00
|
|
|
ObjectHandle& operator=(const volatile ObjectHandle& rhs);
|
2019-10-15 07:30:35 +00:00
|
|
|
|
|
|
|
// MSVC has a bug where it thinks the volatile copy assignment is a duplicate.
|
|
|
|
// Workaround this by forwarding to a different function AssignFrom.
|
|
|
|
template <typename T>
|
|
|
|
ObjectHandle& operator=(const T& rhs) {
|
|
|
|
return AssignFrom(rhs);
|
|
|
|
}
|
|
|
|
ObjectHandle& AssignFrom(const ObjectHandle& rhs);
|
|
|
|
ObjectHandle& AssignFrom(const volatile ObjectHandle& rhs);
|
2019-01-15 20:49:53 +00:00
|
|
|
};
|
2018-06-06 15:36:49 +00:00
|
|
|
|
|
|
|
// Interface to allocate more space to deserialize pointed-to data.
|
|
|
|
// nullptr is treated as an error.
|
|
|
|
class DeserializeAllocator {
|
|
|
|
public:
|
|
|
|
virtual void* GetSpace(size_t size) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Interface to convert an ID to a server object, if possible.
|
2019-04-01 21:04:17 +00:00
|
|
|
// Methods return FatalError if the ID is for a non-existent object and Success otherwise.
|
2018-06-06 15:36:49 +00:00
|
|
|
class ObjectIdResolver {
|
|
|
|
public:
|
|
|
|
{% for type in by_category["object"] %}
|
2021-02-25 20:21:25 +00:00
|
|
|
virtual WireResult GetFromId(ObjectId id, {{as_cType(type.name)}}* out) const = 0;
|
|
|
|
virtual WireResult GetOptionalFromId(ObjectId id, {{as_cType(type.name)}}* out) const = 0;
|
2018-06-06 15:36:49 +00:00
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Interface to convert a client object to its ID for the wiring.
|
|
|
|
class ObjectIdProvider {
|
|
|
|
public:
|
|
|
|
{% for type in by_category["object"] %}
|
2021-09-10 20:36:20 +00:00
|
|
|
virtual WireResult GetId({{as_cType(type.name)}} object, ObjectId* out) const = 0;
|
|
|
|
virtual WireResult GetOptionalId({{as_cType(type.name)}} object, ObjectId* out) const = 0;
|
2018-06-06 15:36:49 +00:00
|
|
|
{% endfor %}
|
|
|
|
};
|
2017-04-20 18:38:20 +00:00
|
|
|
|
|
|
|
//* Enum used as a prefix to each command on the wire format.
|
|
|
|
enum class WireCmd : uint32_t {
|
2019-01-15 20:49:53 +00:00
|
|
|
{% for command in cmd_records["command"] %}
|
|
|
|
{{command.name.CamelCase()}},
|
2017-04-20 18:38:20 +00:00
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
|
2017-04-20 18:42:36 +00:00
|
|
|
//* Enum used as a prefix to each command on the return wire format.
|
|
|
|
enum class ReturnWireCmd : uint32_t {
|
2019-01-15 20:49:53 +00:00
|
|
|
{% for command in cmd_records["return command"] %}
|
|
|
|
{{command.name.CamelCase()}},
|
2017-04-20 18:43:11 +00:00
|
|
|
{% endfor %}
|
2017-04-20 18:42:36 +00:00
|
|
|
};
|
|
|
|
|
2020-10-13 22:35:34 +00:00
|
|
|
struct CmdHeader {
|
|
|
|
uint64_t commandSize;
|
|
|
|
};
|
|
|
|
|
2019-01-15 20:49:53 +00:00
|
|
|
{% macro write_command_struct(command, is_return_command) %}
|
|
|
|
{% set Return = "Return" if is_return_command else "" %}
|
|
|
|
{% set Cmd = command.name.CamelCase() + "Cmd" %}
|
|
|
|
struct {{Return}}{{Cmd}} {
|
|
|
|
//* From a filled structure, compute how much size will be used in the serialization buffer.
|
|
|
|
size_t GetRequiredSize() const;
|
|
|
|
|
|
|
|
//* Serialize the structure and everything it points to into serializeBuffer which must be
|
|
|
|
//* big enough to contain all the data (as queried from GetRequiredSize).
|
2021-11-16 09:25:35 +00:00
|
|
|
WireResult Serialize(size_t commandSize, SerializeBuffer* serializeBuffer, const ObjectIdProvider& objectIdProvider) const;
|
|
|
|
// Override which produces a FatalError if any object is used.
|
|
|
|
WireResult Serialize(size_t commandSize, SerializeBuffer* serializeBuffer) const;
|
2019-01-15 20:49:53 +00:00
|
|
|
|
|
|
|
//* Deserializes the structure from a buffer, consuming a maximum of *size bytes. When this
|
|
|
|
//* function returns, buffer and size will be updated by the number of bytes consumed to
|
|
|
|
//* deserialize the structure. Structures containing pointers will use allocator to get
|
|
|
|
//* scratch space to deserialize the pointed-to data.
|
|
|
|
//* Deserialize returns:
|
|
|
|
//* - Success if everything went well (yay!)
|
|
|
|
//* - FatalError is something bad happened (buffer too small for example)
|
2021-11-16 09:25:35 +00:00
|
|
|
WireResult Deserialize(DeserializeBuffer* deserializeBuffer, DeserializeAllocator* allocator, const ObjectIdResolver& resolver);
|
|
|
|
// Override which produces a FatalError if any object is used.
|
|
|
|
WireResult Deserialize(DeserializeBuffer* deserializeBuffer, DeserializeAllocator* allocator);
|
2019-01-15 20:49:53 +00:00
|
|
|
|
|
|
|
{% if command.derived_method %}
|
|
|
|
//* Command handlers want to know the object ID in addition to the backing object.
|
|
|
|
//* Doesn't need to be filled before Serialize, or GetRequiredSize.
|
|
|
|
ObjectId selfId;
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% for member in command.members %}
|
|
|
|
{{as_annotated_cType(member)}};
|
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
{% endmacro %}
|
|
|
|
|
|
|
|
{% for command in cmd_records["command"] %}
|
|
|
|
{{write_command_struct(command, False)}}
|
|
|
|
{% endfor %}
|
2017-04-20 18:43:11 +00:00
|
|
|
|
2019-01-15 20:49:53 +00:00
|
|
|
{% for command in cmd_records["return command"] %}
|
|
|
|
{{write_command_struct(command, True)}}
|
2017-04-20 18:43:11 +00:00
|
|
|
{% endfor %}
|
|
|
|
|
2022-01-11 09:57:33 +00:00
|
|
|
} // namespace dawn::wire
|
2017-04-20 18:38:20 +00:00
|
|
|
|
2018-07-26 13:07:57 +00:00
|
|
|
#endif // DAWNWIRE_WIRECMD_AUTOGEN_H_
|