diff --git a/generator/templates/dawn/wire/WireCmd.cpp b/generator/templates/dawn/wire/WireCmd.cpp index d0a220d729..fd51af28a0 100644 --- a/generator/templates/dawn/wire/WireCmd.cpp +++ b/generator/templates/dawn/wire/WireCmd.cpp @@ -651,31 +651,6 @@ namespace dawn::wire { - ObjectHandle::ObjectHandle() = default; - ObjectHandle::ObjectHandle(ObjectId id, ObjectGeneration generation) - : id(id), generation(generation) { - } - - ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs) - : id(rhs.id), generation(rhs.generation) { - } - ObjectHandle& ObjectHandle::operator=(const volatile ObjectHandle& rhs) { - id = rhs.id; - generation = rhs.generation; - return *this; - } - - ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) { - id = rhs.id; - generation = rhs.generation; - return *this; - } - ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) { - id = rhs.id; - generation = rhs.generation; - return *this; - } - namespace { // Allocates enough space from allocator to countain T[count] and return it in out. // Return FatalError if the allocator couldn't allocate the memory. diff --git a/generator/templates/dawn/wire/WireCmd.h b/generator/templates/dawn/wire/WireCmd.h index 23a8685e7d..e4b4444d5d 100644 --- a/generator/templates/dawn/wire/WireCmd.h +++ b/generator/templates/dawn/wire/WireCmd.h @@ -19,32 +19,11 @@ #include "dawn/wire/BufferConsumer.h" #include "dawn/wire/ObjectType_autogen.h" +#include "dawn/wire/ObjectHandle.h" #include "dawn/wire/WireResult.h" namespace dawn::wire { - using ObjectId = uint32_t; - using ObjectGeneration = uint32_t; - struct ObjectHandle { - ObjectId id; - ObjectGeneration generation; - - ObjectHandle(); - ObjectHandle(ObjectId id, ObjectGeneration generation); - - ObjectHandle(const volatile ObjectHandle& rhs); - ObjectHandle& operator=(const volatile ObjectHandle& rhs); - - // MSVC has a bug where it thinks the volatile copy assignment is a duplicate. - // Workaround this by forwarding to a different function AssignFrom. - template - ObjectHandle& operator=(const T& rhs) { - return AssignFrom(rhs); - } - ObjectHandle& AssignFrom(const ObjectHandle& rhs); - ObjectHandle& AssignFrom(const volatile ObjectHandle& rhs); - }; - // Interface to allocate more space to deserialize pointed-to data. // nullptr is treated as an error. class DeserializeAllocator { diff --git a/src/dawn/wire/BUILD.gn b/src/dawn/wire/BUILD.gn index 7189bd5fd3..5b2662649b 100644 --- a/src/dawn/wire/BUILD.gn +++ b/src/dawn/wire/BUILD.gn @@ -65,6 +65,8 @@ dawn_component("wire") { "ChunkedCommandHandler.h", "ChunkedCommandSerializer.cpp", "ChunkedCommandSerializer.h", + "ObjectHandle.cpp", + "ObjectHandle.h", "SupportedFeatures.cpp", "SupportedFeatures.h", "Wire.cpp", diff --git a/src/dawn/wire/CMakeLists.txt b/src/dawn/wire/CMakeLists.txt index e389b43c9b..9a79484878 100644 --- a/src/dawn/wire/CMakeLists.txt +++ b/src/dawn/wire/CMakeLists.txt @@ -38,6 +38,8 @@ target_sources(dawn_wire PRIVATE "ChunkedCommandHandler.h" "ChunkedCommandSerializer.cpp" "ChunkedCommandSerializer.h" + "ObjectHandle.cpp" + "ObjectHandle.h" "SupportedFeatures.cpp" "SupportedFeatures.h" "Wire.cpp" diff --git a/src/dawn/wire/ObjectHandle.cpp b/src/dawn/wire/ObjectHandle.cpp new file mode 100644 index 0000000000..92fea02f5d --- /dev/null +++ b/src/dawn/wire/ObjectHandle.cpp @@ -0,0 +1,45 @@ +// Copyright 2022 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. + +#include "dawn/wire/ObjectHandle.h" + +namespace dawn::wire { + +ObjectHandle::ObjectHandle() = default; +ObjectHandle::ObjectHandle(ObjectId id, ObjectGeneration generation) + : id(id), generation(generation) {} + +ObjectHandle::ObjectHandle(const volatile ObjectHandle& rhs) + : id(rhs.id), generation(rhs.generation) {} +ObjectHandle& ObjectHandle::operator=(const volatile ObjectHandle& rhs) { + id = rhs.id; + generation = rhs.generation; + return *this; +} + + +ObjectHandle::ObjectHandle(const ObjectHandle& rhs) = default; +ObjectHandle& ObjectHandle::operator=(const ObjectHandle& rhs) = default; + +ObjectHandle& ObjectHandle::AssignFrom(const ObjectHandle& rhs) { + id = rhs.id; + generation = rhs.generation; + return *this; +} +ObjectHandle& ObjectHandle::AssignFrom(const volatile ObjectHandle& rhs) { + id = rhs.id; + generation = rhs.generation; + return *this; +} +} // namespace dawn::wire diff --git a/src/dawn/wire/ObjectHandle.h b/src/dawn/wire/ObjectHandle.h new file mode 100644 index 0000000000..3e6cf64e7c --- /dev/null +++ b/src/dawn/wire/ObjectHandle.h @@ -0,0 +1,49 @@ +// Copyright 2022 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 DAWN_WIRE_OBJECTHANDLE_H_ +#define DAWN_WIRE_OBJECTHANDLE_H_ + +#include + +namespace dawn::wire { + +using ObjectId = uint32_t; +using ObjectGeneration = uint32_t; +struct ObjectHandle { + ObjectId id; + ObjectGeneration generation; + + ObjectHandle(); + ObjectHandle(ObjectId id, ObjectGeneration generation); + + explicit ObjectHandle(const volatile ObjectHandle& rhs); + ObjectHandle& operator=(const volatile ObjectHandle& rhs); + + ObjectHandle(const ObjectHandle& rhs); + ObjectHandle& operator=(const ObjectHandle& rhs); + + // MSVC has a bug where it thinks the volatile copy assignment is a duplicate. + // Workaround this by forwarding to a different function AssignFrom. + template + ObjectHandle& operator=(const T& rhs) { + return AssignFrom(rhs); + } + ObjectHandle& AssignFrom(const ObjectHandle& rhs); + ObjectHandle& AssignFrom(const volatile ObjectHandle& rhs); +}; + +} // namespace dawn::wire + +#endif // DAWN_WIRE_OBJECTHANDLE_H_ diff --git a/src/dawn/wire/client/ObjectBase.h b/src/dawn/wire/client/ObjectBase.h index 26a6acb875..589b08c0a8 100644 --- a/src/dawn/wire/client/ObjectBase.h +++ b/src/dawn/wire/client/ObjectBase.h @@ -19,6 +19,7 @@ #include "dawn/common/LinkedList.h" #include "dawn/wire/ObjectType_autogen.h" +#include "dawn/wire/ObjectHandle.h" namespace dawn::wire::client { @@ -26,7 +27,7 @@ class Client; struct ObjectBaseParams { Client* client; - uint32_t id; + ObjectId id; }; // All objects on the client side have: @@ -42,7 +43,7 @@ struct ObjectBase : public LinkNode { Client* const client; uint32_t refcount; - const uint32_t id; + const ObjectId id; }; } // namespace dawn::wire::client