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.
This commit is contained in:
Corentin Wallez
2018-07-26 15:07:57 +02:00
committed by Corentin Wallez
parent 012c149fd9
commit bdc867713a
18 changed files with 154 additions and 112 deletions

View File

@@ -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
$<TARGET_OBJECTS:dawn_wire_autogen>
${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)

View File

@@ -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 <dawn/dawn.h>
#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_

View File

@@ -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 <cstdint>
#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_

View File

@@ -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_

View File

@@ -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 <iostream>
#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;

View File

@@ -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<BackendType> {
public:
@@ -118,10 +118,10 @@ class DawnTest : public ::testing::TestWithParam<BackendType> {
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

View File

@@ -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 {

View File

@@ -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)

View File

@@ -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

View File

@@ -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 <vector>
#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_