From bdc867713a5ad5f1f70c7b46cc2017f3cc479fa6 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Thu, 26 Jul 2018 15:07:57 +0200 Subject: [PATCH] Make dawn_wire a shared library Also moves the TerribleCommandBuffer to utils:: because it isn't part of the implementation of the wire, renames dawn::wire to dawn_wire, moves src/wire to src/dawn_wire and puts the interface of dawn_wire in src/include/dawn_wire. --- CMakeLists.txt | 2 +- examples/SampleUtils.cpp | 18 +++++------ generator/main.py | 12 +++---- .../{wire => dawn_wire}/WireClient.cpp | 20 ++++++------ .../templates/{wire => dawn_wire}/WireCmd.cpp | 12 +++---- .../templates/{wire => dawn_wire}/WireCmd.h | 12 +++---- .../{wire => dawn_wire}/WireServer.cpp | 8 ++--- src/{wire => dawn_wire}/CMakeLists.txt | 24 +++++++------- src/{wire => dawn_wire}/WireCmd.h | 22 ++++++------- src/{wire => include/dawn_wire}/Wire.h | 27 ++++++++-------- src/include/dawn_wire/dawn_wire_export.h | 32 +++++++++++++++++++ src/tests/DawnTest.cpp | 12 +++---- src/tests/DawnTest.h | 14 ++++---- src/tests/unittests/WireTests.cpp | 14 ++++---- src/utils/CMakeLists.txt | 2 ++ src/{wire => utils}/TerribleCommandBuffer.cpp | 11 ++++--- src/{wire => utils}/TerribleCommandBuffer.h | 20 ++++++------ third_party/CMakeLists.txt | 4 +++ 18 files changed, 154 insertions(+), 112 deletions(-) rename generator/templates/{wire => dawn_wire}/WireClient.cpp (98%) rename generator/templates/{wire => dawn_wire}/WireCmd.cpp (98%) rename generator/templates/{wire => dawn_wire}/WireCmd.h (95%) rename generator/templates/{wire => dawn_wire}/WireServer.cpp (99%) rename src/{wire => dawn_wire}/CMakeLists.txt (56%) rename src/{wire => dawn_wire}/WireCmd.h (71%) rename src/{wire => include/dawn_wire}/Wire.h (55%) create mode 100644 src/include/dawn_wire/dawn_wire_export.h rename src/{wire => utils}/TerribleCommandBuffer.cpp (84%) rename src/{wire => utils}/TerribleCommandBuffer.h (64%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 249e974201..4c62310288 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,7 +238,7 @@ add_subdirectory(third_party) add_subdirectory(src/common) add_subdirectory(src/dawn_native) -add_subdirectory(src/wire) +add_subdirectory(src/dawn_wire) add_subdirectory(src/utils) add_subdirectory(src/tests) diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp index 887d5ec13c..0b3c2d6ca1 100644 --- a/examples/SampleUtils.cpp +++ b/examples/SampleUtils.cpp @@ -17,7 +17,7 @@ #include "common/Assert.h" #include "common/Platform.h" #include "utils/BackendBinding.h" -#include "wire/TerribleCommandBuffer.h" +#include "utils/TerribleCommandBuffer.h" #include #include @@ -60,10 +60,10 @@ static utils::BackendBinding* binding = nullptr; static GLFWwindow* window = nullptr; -static dawn::wire::CommandHandler* wireServer = nullptr; -static dawn::wire::CommandHandler* wireClient = nullptr; -static dawn::wire::TerribleCommandBuffer* c2sBuf = nullptr; -static dawn::wire::TerribleCommandBuffer* s2cBuf = nullptr; +static dawn_wire::CommandHandler* wireServer = nullptr; +static dawn_wire::CommandHandler* wireClient = nullptr; +static utils::TerribleCommandBuffer* c2sBuf = nullptr; +static utils::TerribleCommandBuffer* s2cBuf = nullptr; dawn::Device CreateCppDawnDevice() { binding = utils::CreateBinding(backendType); @@ -98,15 +98,15 @@ dawn::Device CreateCppDawnDevice() { case CmdBufType::Terrible: { - c2sBuf = new dawn::wire::TerribleCommandBuffer(); - s2cBuf = new dawn::wire::TerribleCommandBuffer(); + c2sBuf = new utils::TerribleCommandBuffer(); + s2cBuf = new utils::TerribleCommandBuffer(); - wireServer = dawn::wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf); + wireServer = dawn_wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf); c2sBuf->SetHandler(wireServer); dawnDevice clientDevice; dawnProcTable clientProcs; - wireClient = dawn::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf); + wireClient = dawn_wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf); s2cBuf->SetHandler(wireClient); procs = clientProcs; diff --git a/generator/main.py b/generator/main.py index 6202cbc622..737ff10bba 100644 --- a/generator/main.py +++ b/generator/main.py @@ -389,7 +389,7 @@ def debug(text): print(text) def main(): - targets = ['dawn_headers', 'libdawn', 'mock_dawn', 'opengl', 'metal', 'd3d12', 'null', 'wire', "dawn_native_utils"] + targets = ['dawn_headers', 'libdawn', 'mock_dawn', 'opengl', 'metal', 'd3d12', 'null', 'dawn_wire', "dawn_native_utils"] parser = argparse.ArgumentParser( description = 'Generates code for various target for Dawn.', @@ -482,11 +482,11 @@ def main(): renders.append(FileRender('dawn_native/api_structs.h', 'dawn_native/dawn_structs_autogen.h', base_backend_params)) renders.append(FileRender('dawn_native/api_structs.cpp', 'dawn_native/dawn_structs_autogen.cpp', base_backend_params)) - if 'wire' in targets: - renders.append(FileRender('wire/WireCmd.h', 'wire/WireCmd_autogen.h', base_backend_params)) - renders.append(FileRender('wire/WireCmd.cpp', 'wire/WireCmd_autogen.cpp', base_backend_params)) - renders.append(FileRender('wire/WireClient.cpp', 'wire/WireClient.cpp', base_backend_params)) - renders.append(FileRender('wire/WireServer.cpp', 'wire/WireServer.cpp', base_backend_params)) + if 'dawn_wire' in targets: + renders.append(FileRender('dawn_wire/WireCmd.h', 'dawn_wire/WireCmd_autogen.h', base_backend_params)) + renders.append(FileRender('dawn_wire/WireCmd.cpp', 'dawn_wire/WireCmd_autogen.cpp', base_backend_params)) + renders.append(FileRender('dawn_wire/WireClient.cpp', 'dawn_wire/WireClient.cpp', base_backend_params)) + renders.append(FileRender('dawn_wire/WireServer.cpp', 'dawn_wire/WireServer.cpp', base_backend_params)) output_separator = '\n' if args.gn else ';' if args.print_dependencies: diff --git a/generator/templates/wire/WireClient.cpp b/generator/templates/dawn_wire/WireClient.cpp similarity index 98% rename from generator/templates/wire/WireClient.cpp rename to generator/templates/dawn_wire/WireClient.cpp index 9d551738fe..aafed2711a 100644 --- a/generator/templates/wire/WireClient.cpp +++ b/generator/templates/dawn_wire/WireClient.cpp @@ -12,8 +12,8 @@ //* See the License for the specific language governing permissions and //* limitations under the License. -#include "wire/Wire.h" -#include "wire/WireCmd.h" +#include "dawn_wire/Wire.h" +#include "dawn_wire/WireCmd.h" #include "common/Assert.h" @@ -24,7 +24,7 @@ #include #include -namespace dawn { namespace wire { +namespace dawn_wire { //* Client side implementation of the API, will serialize everything to memory to send to the server side. namespace client { @@ -194,7 +194,7 @@ namespace dawn { namespace wire { //* The client wire uses the global Dawn device to store its global data such as the serializer //* and the object id allocators. - class Device : public ObjectBase, public wire::ObjectIdProvider { + class Device : public ObjectBase, public ObjectIdProvider { public: Device(CommandSerializer* serializer) : ObjectBase(this, 1, 1), @@ -247,7 +247,7 @@ namespace dawn { namespace wire { ) { {{as_backendType(type)}} self = reinterpret_cast<{{as_backendType(type)}}>(cSelf); Device* device = self->device; - wire::{{Suffix}}Cmd cmd; + {{Suffix}}Cmd cmd; //* Create the structure going on the wire on the stack and fill it with the value //* arguments so it can compute its size. @@ -306,7 +306,7 @@ namespace dawn { namespace wire { obj->builderCallback.Call(DAWN_BUILDER_ERROR_STATUS_UNKNOWN, "Unknown"); - wire::{{as_MethodSuffix(type.name, Name("destroy"))}}Cmd cmd; + {{as_MethodSuffix(type.name, Name("destroy"))}}Cmd cmd; cmd.objectId = obj->id; auto allocCmd = static_cast(obj->device->GetCmdSpace(sizeof(cmd))); @@ -332,7 +332,7 @@ namespace dawn { namespace wire { request.isWrite = false; buffer->requests[serial] = request; - wire::BufferMapAsyncCmd cmd; + BufferMapAsyncCmd cmd; cmd.bufferId = buffer->id; cmd.requestSerial = serial; cmd.start = start; @@ -354,7 +354,7 @@ namespace dawn { namespace wire { request.isWrite = true; buffer->requests[serial] = request; - wire::BufferMapAsyncCmd cmd; + BufferMapAsyncCmd cmd; cmd.bufferId = buffer->id; cmd.requestSerial = serial; cmd.start = start; @@ -379,7 +379,7 @@ namespace dawn { namespace wire { // If the buffer was mapped for writing, send the update to the data to the server if (buffer->isWriteMapped) { - wire::BufferUpdateMappedDataCmd cmd; + BufferUpdateMappedDataCmd cmd; cmd.bufferId = buffer->id; cmd.dataLength = static_cast(buffer->mappedDataSize); @@ -673,4 +673,4 @@ namespace dawn { namespace wire { return new client::Client(clientDevice); } -}} // namespace dawn::wire +} // namespace dawn_wire diff --git a/generator/templates/wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp similarity index 98% rename from generator/templates/wire/WireCmd.cpp rename to generator/templates/dawn_wire/WireCmd.cpp index 0225ef2477..1ca77ddc0b 100644 --- a/generator/templates/wire/WireCmd.cpp +++ b/generator/templates/dawn_wire/WireCmd.cpp @@ -12,7 +12,7 @@ //* See the License for the specific language governing permissions and //* limitations under the License. -#include "wire/WireCmd.h" +#include "dawn_wire/WireCmd.h" #include "common/Assert.h" @@ -83,7 +83,7 @@ struct {{name}}Transfer { {% if is_method %} //* Start the transfer structure with the command ID, so that casting to WireCmd gives the ID. - wire::{{Return}}WireCmd commandId; + {{Return}}WireCmd commandId; //* Methods always have an implicit "self" argument. ObjectId self; @@ -150,7 +150,7 @@ transfer->resultSerial = record.resultSerial; {% endif %} - transfer->commandId = wire::{{Return}}WireCmd::{{name}}; + transfer->commandId = {{Return}}WireCmd::{{name}}; transfer->self = provider.GetId(record.self); {% endif %} @@ -201,7 +201,7 @@ record->resultSerial = transfer->resultSerial; {% endif %} - ASSERT(transfer->commandId == wire::{{Return}}WireCmd::{{name}}); + ASSERT(transfer->commandId == {{Return}}WireCmd::{{name}}); record->selfId = transfer->self; //* This conversion is done after the copying of result* and selfId: Deserialize @@ -258,7 +258,7 @@ } {% endmacro %} -namespace dawn { namespace wire { +namespace dawn_wire { // Macro to simplify error handling, similar to DAWN_TRY but for DeserializeResult. #define DESERIALIZE_TRY(EXPR) \ @@ -344,4 +344,4 @@ namespace dawn { namespace wire { {% endfor %} {% endfor %} -}} // namespace dawn::wire +} // namespace dawn_wire diff --git a/generator/templates/wire/WireCmd.h b/generator/templates/dawn_wire/WireCmd.h similarity index 95% rename from generator/templates/wire/WireCmd.h rename to generator/templates/dawn_wire/WireCmd.h index 72da4fdcd0..9e451ef191 100644 --- a/generator/templates/wire/WireCmd.h +++ b/generator/templates/dawn_wire/WireCmd.h @@ -12,10 +12,10 @@ //* See the License for the specific language governing permissions and //* limitations under the License. -#ifndef WIRE_WIRECMD_AUTOGEN_H_ -#define WIRE_WIRECMD_AUTOGEN_H_ +#ifndef DAWNWIRE_WIRECMD_AUTOGEN_H_ +#define DAWNWIRE_WIRECMD_AUTOGEN_H_ -namespace dawn { namespace wire { +namespace dawn_wire { using ObjectId = uint32_t; using ObjectSerial = uint32_t; @@ -131,7 +131,7 @@ namespace dawn { namespace wire { //* Command for the server calling a builder status callback. {% for type in by_category["object"] if type.is_builder %} struct Return{{type.name.CamelCase()}}ErrorCallbackCmd { - wire::ReturnWireCmd commandId = ReturnWireCmd::{{type.name.CamelCase()}}ErrorCallback; + ReturnWireCmd commandId = ReturnWireCmd::{{type.name.CamelCase()}}ErrorCallback; ObjectId builtObjectId; ObjectSerial builtObjectSerial; @@ -140,6 +140,6 @@ namespace dawn { namespace wire { }; {% endfor %} -}} // namespace dawn::wire +} // namespace dawn_wire -#endif // WIRE_WIRECMD_AUTOGEN_H_ +#endif // DAWNWIRE_WIRECMD_AUTOGEN_H_ diff --git a/generator/templates/wire/WireServer.cpp b/generator/templates/dawn_wire/WireServer.cpp similarity index 99% rename from generator/templates/wire/WireServer.cpp rename to generator/templates/dawn_wire/WireServer.cpp index 25980d8fcd..77afff0c21 100644 --- a/generator/templates/wire/WireServer.cpp +++ b/generator/templates/dawn_wire/WireServer.cpp @@ -12,8 +12,8 @@ //* See the License for the specific language governing permissions and //* limitations under the License. -#include "wire/Wire.h" -#include "wire/WireCmd.h" +#include "dawn_wire/Wire.h" +#include "dawn_wire/WireCmd.h" #include "common/Assert.h" @@ -22,7 +22,7 @@ #include #include -namespace dawn { namespace wire { +namespace dawn_wire { namespace server { class Server; @@ -626,4 +626,4 @@ namespace dawn { namespace wire { return new server::Server(device, procs, serializer); } -}} // namespace dawn::wire +} // namespace dawn_wire diff --git a/src/wire/CMakeLists.txt b/src/dawn_wire/CMakeLists.txt similarity index 56% rename from src/wire/CMakeLists.txt rename to src/dawn_wire/CMakeLists.txt index 6c99c06a52..4c539727ae 100644 --- a/src/wire/CMakeLists.txt +++ b/src/dawn_wire/CMakeLists.txt @@ -12,24 +12,26 @@ # See the License for the specific language governing permissions and # limitations under the License. -set(WIRE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(DAWN_WIRE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(DAWN_WIRE_INCLUDE_DIR ${INCLUDE_DIR}/dawn_wire) Generate( LIB_NAME dawn_wire_autogen - LIB_TYPE STATIC + LIB_TYPE OBJECT FOLDER "wire" - PRINT_NAME "Wire serialization/deserialization autogenerated files" + PRINT_NAME "dawn_wire autogenerated files" COMMAND_LINE_ARGS ${GENERATOR_COMMON_ARGS} - -T wire - EXTRA_SOURCES - ${WIRE_DIR}/WireCmd.h + -T dawn_wire ) +target_compile_definitions(dawn_wire_autogen PRIVATE DAWN_WIRE_IMPLEMENTATION) -add_library(dawn_wire STATIC - ${WIRE_DIR}/TerribleCommandBuffer.cpp - ${WIRE_DIR}/TerribleCommandBuffer.h - ${WIRE_DIR}/Wire.h +add_library(dawn_wire SHARED + $ + ${DAWN_WIRE_DIR}/WireCmd.h + ${DAWN_WIRE_INCLUDE_DIR}/Wire.h + ${DAWN_WIRE_INCLUDE_DIR}/dawn_wire_export.h ) -target_link_libraries(dawn_wire dawn_wire_autogen dawn_common) +target_link_libraries(dawn_wire dawn_common) +target_compile_definitions(dawn_wire PRIVATE DAWN_WIRE_IMPLEMENTATION) DawnInternalTarget("wire" dawn_wire) diff --git a/src/wire/WireCmd.h b/src/dawn_wire/WireCmd.h similarity index 71% rename from src/wire/WireCmd.h rename to src/dawn_wire/WireCmd.h index 3cb19f12fe..7419cd2f0a 100644 --- a/src/wire/WireCmd.h +++ b/src/dawn_wire/WireCmd.h @@ -12,23 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef WIRE_WIRECMD_H_ -#define WIRE_WIRECMD_H_ +#ifndef DAWNWIRE_WIRECMD_H_ +#define DAWNWIRE_WIRECMD_H_ #include -#include "wire/WireCmd_autogen.h" +#include "dawn_wire/WireCmd_autogen.h" -namespace dawn { namespace wire { +namespace dawn_wire { struct ReturnDeviceErrorCallbackCmd { - wire::ReturnWireCmd commandId = ReturnWireCmd::DeviceErrorCallback; + ReturnWireCmd commandId = ReturnWireCmd::DeviceErrorCallback; size_t messageStrlen; }; struct BufferMapAsyncCmd { - wire::WireCmd commandId = WireCmd::BufferMapAsync; + WireCmd commandId = WireCmd::BufferMapAsync; ObjectId bufferId; ObjectSerial requestSerial; @@ -38,7 +38,7 @@ namespace dawn { namespace wire { }; struct ReturnBufferMapReadAsyncCallbackCmd { - wire::ReturnWireCmd commandId = ReturnWireCmd::BufferMapReadAsyncCallback; + ReturnWireCmd commandId = ReturnWireCmd::BufferMapReadAsyncCallback; ObjectId bufferId; ObjectSerial bufferSerial; @@ -48,7 +48,7 @@ namespace dawn { namespace wire { }; struct ReturnBufferMapWriteAsyncCallbackCmd { - wire::ReturnWireCmd commandId = ReturnWireCmd::BufferMapWriteAsyncCallback; + ReturnWireCmd commandId = ReturnWireCmd::BufferMapWriteAsyncCallback; ObjectId bufferId; ObjectSerial bufferSerial; @@ -57,12 +57,12 @@ namespace dawn { namespace wire { }; struct BufferUpdateMappedDataCmd { - wire::WireCmd commandId = WireCmd::BufferUpdateMappedDataCmd; + WireCmd commandId = WireCmd::BufferUpdateMappedDataCmd; ObjectId bufferId; uint32_t dataLength; }; -}} // namespace dawn::wire +} // namespace dawn_wire -#endif // WIRE_WIRECMD_H_ +#endif // DAWNWIRE_WIRECMD_H_ diff --git a/src/wire/Wire.h b/src/include/dawn_wire/Wire.h similarity index 55% rename from src/wire/Wire.h rename to src/include/dawn_wire/Wire.h index b0aca95c0e..f9cdd6ef0b 100644 --- a/src/wire/Wire.h +++ b/src/include/dawn_wire/Wire.h @@ -12,35 +12,36 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef WIRE_WIRE_H_ -#define WIRE_WIRE_H_ +#ifndef DAWNWIRE_WIRE_H_ +#define DAWNWIRE_WIRE_H_ #include #include "dawn/dawn.h" +#include "dawn_wire/dawn_wire_export.h" -namespace dawn { namespace wire { +namespace dawn_wire { - class CommandSerializer { + class DAWN_WIRE_EXPORT CommandSerializer { public: virtual ~CommandSerializer() = default; virtual void* GetCmdSpace(size_t size) = 0; virtual bool Flush() = 0; }; - class CommandHandler { + class DAWN_WIRE_EXPORT CommandHandler { public: virtual ~CommandHandler() = default; virtual const char* HandleCommands(const char* commands, size_t size) = 0; }; - CommandHandler* NewClientDevice(dawnProcTable* procs, - dawnDevice* device, - CommandSerializer* serializer); - CommandHandler* NewServerCommandHandler(dawnDevice device, - const dawnProcTable& procs, - CommandSerializer* serializer); + DAWN_WIRE_EXPORT CommandHandler* NewClientDevice(dawnProcTable* procs, + dawnDevice* device, + CommandSerializer* serializer); + DAWN_WIRE_EXPORT CommandHandler* NewServerCommandHandler(dawnDevice device, + const dawnProcTable& procs, + CommandSerializer* serializer); -}} // namespace dawn::wire +} // namespace dawn_wire -#endif // WIRE_WIRE_H_ +#endif // DAWNWIRE_WIRE_H_ diff --git a/src/include/dawn_wire/dawn_wire_export.h b/src/include/dawn_wire/dawn_wire_export.h new file mode 100644 index 0000000000..327c58ea43 --- /dev/null +++ b/src/include/dawn_wire/dawn_wire_export.h @@ -0,0 +1,32 @@ +// Copyright 2018 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_EXPORT_H_ +#define DAWNWIRE_EXPORT_H_ + +#if defined(WIN32) +# if defined(DAWN_WIRE_IMPLEMENTATION) +# define DAWN_WIRE_EXPORT __declspec(dllexport) +# else +# define DAWN_WIRE_EXPORT __declspec(dllimport) +# endif +#else +# if defined(DAWN_WIRE_IMPLEMENTATION) +# define DAWN_WIRE_EXPORT __attribute__((visibility("default"))) +# else +# define DAWN_WIRE_EXPORT +# endif +#endif + +#endif // DAWNWIRE_EXPORT_H_ diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index 46646733ec..168a88e14b 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -17,11 +17,11 @@ #include "common/Assert.h" #include "common/Constants.h" #include "common/Math.h" +#include "dawn_wire/Wire.h" #include "utils/BackendBinding.h" #include "utils/DawnHelpers.h" #include "utils/SystemUtils.h" -#include "wire/TerribleCommandBuffer.h" -#include "wire/Wire.h" +#include "utils/TerribleCommandBuffer.h" #include #include "GLFW/glfw3.h" @@ -145,15 +145,15 @@ void DawnTest::SetUp() { dawnProcTable procs; if (gTestUsesWire) { - mC2sBuf = new dawn::wire::TerribleCommandBuffer(); - mS2cBuf = new dawn::wire::TerribleCommandBuffer(); + mC2sBuf = new utils::TerribleCommandBuffer(); + mS2cBuf = new utils::TerribleCommandBuffer(); - mWireServer = dawn::wire::NewServerCommandHandler(backendDevice, backendProcs, mS2cBuf); + mWireServer = dawn_wire::NewServerCommandHandler(backendDevice, backendProcs, mS2cBuf); mC2sBuf->SetHandler(mWireServer); dawnDevice clientDevice; dawnProcTable clientProcs; - mWireClient = dawn::wire::NewClientDevice(&clientProcs, &clientDevice, mC2sBuf); + mWireClient = dawn_wire::NewClientDevice(&clientProcs, &clientDevice, mC2sBuf); mS2cBuf->SetHandler(mWireClient); procs = clientProcs; diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h index f3325ef781..20896f97d0 100644 --- a/src/tests/DawnTest.h +++ b/src/tests/DawnTest.h @@ -66,16 +66,16 @@ std::ostream& operator<<(std::ostream& stream, BackendType backend); namespace utils { class BackendBinding; + class TerribleCommandBuffer; } namespace detail { class Expectation; } -namespace dawn { namespace wire { +namespace dawn_wire { class CommandHandler; - class TerribleCommandBuffer; -}} // namespace dawn::wire +} // namespace dawn_wire class DawnTest : public ::testing::TestWithParam { public: @@ -118,10 +118,10 @@ class DawnTest : public ::testing::TestWithParam { private: // Things used to set up testing through the Wire. - dawn::wire::CommandHandler* mWireServer = nullptr; - dawn::wire::CommandHandler* mWireClient = nullptr; - dawn::wire::TerribleCommandBuffer* mC2sBuf = nullptr; - dawn::wire::TerribleCommandBuffer* mS2cBuf = nullptr; + dawn_wire::CommandHandler* mWireServer = nullptr; + dawn_wire::CommandHandler* mWireClient = nullptr; + utils::TerribleCommandBuffer* mC2sBuf = nullptr; + utils::TerribleCommandBuffer* mS2cBuf = nullptr; void FlushWire(); // MapRead buffers used to get data for the expectations diff --git a/src/tests/unittests/WireTests.cpp b/src/tests/unittests/WireTests.cpp index 382345158e..cd0e889bc3 100644 --- a/src/tests/unittests/WireTests.cpp +++ b/src/tests/unittests/WireTests.cpp @@ -16,11 +16,11 @@ #include "mock/mock_dawn.h" #include "common/Assert.h" -#include "wire/TerribleCommandBuffer.h" -#include "wire/Wire.h" +#include "dawn_wire/Wire.h" +#include "utils/TerribleCommandBuffer.h" using namespace testing; -using namespace dawn::wire; +using namespace dawn_wire; // Definition of a "Lambda predicate matcher" for GMock to allow checking deep structures // are passed correctly by the wire. @@ -138,8 +138,8 @@ class WireTestsBase : public Test { } EXPECT_CALL(api, DeviceTick(_)).Times(AnyNumber()); - mS2cBuf = new TerribleCommandBuffer(); - mC2sBuf = new TerribleCommandBuffer(mWireServer); + mS2cBuf = new utils::TerribleCommandBuffer(); + mC2sBuf = new utils::TerribleCommandBuffer(mWireServer); mWireServer = NewServerCommandHandler(mockDevice, mockProcs, mS2cBuf); mC2sBuf->SetHandler(mWireServer); @@ -181,8 +181,8 @@ class WireTestsBase : public Test { CommandHandler* mWireServer = nullptr; CommandHandler* mWireClient = nullptr; - TerribleCommandBuffer* mS2cBuf = nullptr; - TerribleCommandBuffer* mC2sBuf = nullptr; + utils::TerribleCommandBuffer* mS2cBuf = nullptr; + utils::TerribleCommandBuffer* mC2sBuf = nullptr; }; class WireTests : public WireTestsBase { diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 2c1f2a7876..6e880d29c2 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -21,6 +21,8 @@ list(APPEND UTILS_SOURCES ${UTILS_DIR}/DawnHelpers.h ${UTILS_DIR}/SystemUtils.cpp ${UTILS_DIR}/SystemUtils.h + ${UTILS_DIR}/TerribleCommandBuffer.cpp + ${UTILS_DIR}/TerribleCommandBuffer.h ) if (DAWN_ENABLE_D3D12) diff --git a/src/wire/TerribleCommandBuffer.cpp b/src/utils/TerribleCommandBuffer.cpp similarity index 84% rename from src/wire/TerribleCommandBuffer.cpp rename to src/utils/TerribleCommandBuffer.cpp index 74392a3a9a..77f86ec4b2 100644 --- a/src/wire/TerribleCommandBuffer.cpp +++ b/src/utils/TerribleCommandBuffer.cpp @@ -12,19 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "wire/TerribleCommandBuffer.h" +#include "utils/TerribleCommandBuffer.h" #include "common/Assert.h" -namespace dawn { namespace wire { +namespace utils { TerribleCommandBuffer::TerribleCommandBuffer() { } - TerribleCommandBuffer::TerribleCommandBuffer(CommandHandler* handler) : mHandler(handler) { + TerribleCommandBuffer::TerribleCommandBuffer(dawn_wire::CommandHandler* handler) + : mHandler(handler) { } - void TerribleCommandBuffer::SetHandler(CommandHandler* handler) { + void TerribleCommandBuffer::SetHandler(dawn_wire::CommandHandler* handler) { mHandler = handler; } @@ -56,4 +57,4 @@ namespace dawn { namespace wire { return success; } -}} // namespace dawn::wire +} // namespace utils diff --git a/src/wire/TerribleCommandBuffer.h b/src/utils/TerribleCommandBuffer.h similarity index 64% rename from src/wire/TerribleCommandBuffer.h rename to src/utils/TerribleCommandBuffer.h index 906b19f8c6..b5affc8553 100644 --- a/src/wire/TerribleCommandBuffer.h +++ b/src/utils/TerribleCommandBuffer.h @@ -12,31 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef WIRE_TERRIBLE_COMMAND_BUFFER_H_ -#define WIRE_TERRIBLE_COMMAND_BUFFER_H_ +#ifndef UTILS_TERRIBLE_COMMAND_BUFFER_H_ +#define UTILS_TERRIBLE_COMMAND_BUFFER_H_ #include -#include "wire/Wire.h" +#include "dawn_wire/Wire.h" -namespace dawn { namespace wire { +namespace utils { - class TerribleCommandBuffer : public CommandSerializer { + class TerribleCommandBuffer : public dawn_wire::CommandSerializer { public: TerribleCommandBuffer(); - TerribleCommandBuffer(CommandHandler* handler); + TerribleCommandBuffer(dawn_wire::CommandHandler* handler); - void SetHandler(CommandHandler* handler); + void SetHandler(dawn_wire::CommandHandler* handler); void* GetCmdSpace(size_t size) override; bool Flush() override; private: - CommandHandler* mHandler = nullptr; + dawn_wire::CommandHandler* mHandler = nullptr; size_t mOffset = 0; char mBuffer[10000000]; }; -}} // namespace dawn::wire +} // namespace utils -#endif // WIRE_TERRIBLE_COMMAND_BUFFER_H_ +#endif // UTILS_TERRIBLE_COMMAND_BUFFER_H_ diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index 4d70444c25..3c8d395402 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -40,6 +40,10 @@ set(GLAD_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/glad/include) set(GLAD_INCLUDE_DIR ${GLAD_INCLUDE_DIR} PARENT_SCOPE) target_include_directories(glad SYSTEM PUBLIC ${GLAD_INCLUDE_DIR}) DawnExternalTarget("third_party" glad) +if(APPLE) + # Workaround https://github.com/Dav1dde/glad/issues/158 + set_property(TARGET glad APPEND PROPERTY COMPILE_OPTIONS "-fno-common") +endif() # ShaderC # Prevent SPIRV-Tools from using Werror as it has a warning on MSVC