diff --git a/BUILD.gn b/BUILD.gn index 8a100902ec..786b23100c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -671,6 +671,7 @@ config("libdawn_wire_export") { dawn_generator("libdawn_wire_gen") { target = "dawn_wire" outputs = [ + "dawn_wire/TypeTraits_autogen.h", "dawn_wire/WireServer.cpp", "dawn_wire/WireCmd_autogen.h", "dawn_wire/WireClient.cpp", diff --git a/generator/main.py b/generator/main.py index 017a941a54..a5c5a7d114 100644 --- a/generator/main.py +++ b/generator/main.py @@ -479,6 +479,7 @@ def get_renders_for_targets(api_params, targets): 'as_wireType': lambda typ: typ.name.CamelCase() + '*' if typ.category == 'object' else as_cppType(typ.name) } ] + renders.append(FileRender('dawn_wire/TypeTraits.h', 'dawn_wire/TypeTraits_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/WireCmd.h', 'dawn_wire/WireCmd_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/WireCmd.cpp', 'dawn_wire/WireCmd_autogen.cpp', wire_params)) renders.append(FileRender('dawn_wire/WireClient.cpp', 'dawn_wire/WireClient.cpp', wire_params)) diff --git a/generator/templates/dawn_wire/TypeTraits.h b/generator/templates/dawn_wire/TypeTraits.h new file mode 100644 index 0000000000..26a91eeff2 --- /dev/null +++ b/generator/templates/dawn_wire/TypeTraits.h @@ -0,0 +1,35 @@ +//* 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. + +#ifndef DAWNWIRE_TYPETRAITS_AUTOGEN_H_ +#define DAWNWIRE_TYPETRAITS_AUTOGEN_H_ + +#include + +//* This file can be removed when WebGPU error handling is implemented +namespace dawn_wire { + template + struct IsBuilderType { + static constexpr bool value = false; + }; + + {% for type in by_category["object"] if type.is_builder %} + template<> + struct IsBuilderType<{{as_cType(type.name)}}> { + static constexpr bool value = true; + }; + {% endfor %} +} + +#endif // DAWNWIRE_TYPETRAITS_AUTOGEN_H_ diff --git a/generator/templates/dawn_wire/WireServer.cpp b/generator/templates/dawn_wire/WireServer.cpp index 9ea671ac1e..49a9f7120d 100644 --- a/generator/templates/dawn_wire/WireServer.cpp +++ b/generator/templates/dawn_wire/WireServer.cpp @@ -12,6 +12,7 @@ //* See the License for the specific language governing permissions and //* limitations under the License. +#include "dawn_wire/TypeTraits_autogen.h" #include "dawn_wire/Wire.h" #include "dawn_wire/WireCmd.h" @@ -44,18 +45,12 @@ namespace dawn_wire { uint64_t value; }; - //* Stores what the backend knows about the type. - template + template struct ObjectDataBase { //* The backend-provided handle and serial to this object. T handle; uint32_t serial = 0; - //* Built object ID and serial, needed to send to the client along with builder error callbacks - //* TODO(cwallez@chromium.org) only have this for builder T - uint32_t builtObjectId = 0; - uint32_t builtObjectSerial = 0; - //* Used by the error-propagation mechanism to know if this object is an error. //* TODO(cwallez@chromium.org): this is doubling the memory usage of //* std::vector consider making it a special marker value in handle instead. @@ -63,8 +58,22 @@ namespace dawn_wire { //* Whether this object has been allocated, used by the KnownObjects queries //* TODO(cwallez@chromium.org): make this an internal bit vector in KnownObjects. bool allocated; + }; - //* TODO(cwallez@chromium.org): this is only useful for buffers + //* Stores what the backend knows about the type. + template::value> + struct ObjectData : public ObjectDataBase { + }; + + + template + struct ObjectData : public ObjectDataBase { + uint32_t builtObjectId = 0; + uint32_t builtObjectSerial = 0; + }; + + template <> + struct ObjectData : public ObjectDataBase { void* mappedData = nullptr; size_t mappedDataSize = 0; }; @@ -73,7 +82,7 @@ namespace dawn_wire { template class KnownObjects { public: - using Data = ObjectDataBase; + using Data = ObjectData; KnownObjects() { //* Pre-allocate ID 0 to refer to the null handle.