Plumb the server->client wire

This commit is contained in:
Corentin Wallez 2017-05-09 15:34:13 +02:00 committed by Corentin Wallez
parent 7f433a5b52
commit 682a8250b3
6 changed files with 83 additions and 34 deletions

View File

@ -69,6 +69,7 @@ enum class BackendType {
enum class CmdBufType {
None,
Terrible,
//TODO(cwallez@chromium.org) double terrible cmdbuf
};
static BackendType backendType = BackendType::OpenGL;
@ -78,7 +79,9 @@ static BackendBinding* binding = nullptr;
static GLFWwindow* window = nullptr;
static nxt::wire::CommandHandler* wireServer = nullptr;
static nxt::wire::TerribleCommandBuffer* cmdBuf = nullptr;
static nxt::wire::CommandHandler* wireClient = nullptr;
static nxt::wire::TerribleCommandBuffer* c2sBuf = nullptr;
static nxt::wire::TerribleCommandBuffer* s2cBuf = nullptr;
void HandleSynchronousError(const char* errorMessage, void* userData) {
std::cerr << errorMessage << std::endl;
@ -127,12 +130,16 @@ void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
case CmdBufType::Terrible:
{
wireServer = nxt::wire::CreateCommandHandler(backendDevice, backendProcs);
cmdBuf = new nxt::wire::TerribleCommandBuffer(wireServer);
c2sBuf = new nxt::wire::TerribleCommandBuffer();
s2cBuf = new nxt::wire::TerribleCommandBuffer();
wireServer = nxt::wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf);
c2sBuf->SetHandler(wireServer);
nxtDevice clientDevice;
nxtProcTable clientProcs;
nxt::wire::NewClientDevice(&clientProcs, &clientDevice, cmdBuf);
wireClient = nxt::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
s2cBuf->SetHandler(wireClient);
*procs = clientProcs;
*device = nxt::Device::Acquire(clientDevice);
@ -140,6 +147,7 @@ void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
break;
}
//TODO(cwallez@chromium.org) this will disappear
backend::RegisterSynchronousErrorCallback(backendDevice, HandleSynchronousError, wireServer);
}
@ -250,8 +258,9 @@ extern "C" {
}
void SwapBuffers() {
if (cmdBuf) {
cmdBuf->Flush();
if (cmdBufType == CmdBufType::Terrible) {
c2sBuf->Flush();
s2cBuf->Flush();
}
glfwPollEvents();
binding->SwapBuffers();

View File

@ -210,11 +210,33 @@ namespace wire {
return table;
}
class Client : public CommandHandler {
public:
Client(Device* device) : device(device) {
}
void NewClientDevice(nxtProcTable* procs, nxtDevice* device, CommandSerializer* serializer) {
*device = reinterpret_cast<nxtDeviceImpl*>(new client::Device(serializer));
const uint8_t* HandleCommands(const uint8_t* commands, size_t size) override {
// TODO(cwallez@chromium.org): process callbacks
return nullptr;
}
void OnSynchronousError() override {
// TODO(cwallez@chromium.org): this will disappear
}
private:
Device* device = nullptr;
};
}
CommandHandler* NewClientDevice(nxtProcTable* procs, nxtDevice* device, CommandSerializer* serializer) {
auto clientDevice = new client::Device(serializer);
*device = reinterpret_cast<nxtDeviceImpl*>(clientDevice);
*procs = client::GetProcs();
return new client::Client(clientDevice);
}
}

View File

@ -273,16 +273,16 @@ namespace wire {
return true;
}
{% if returns -%}
auto result =
{%- endif -%}
{% if returns %}
auto result ={{" "}}
{%- endif %}
procs.{{as_varName(type.name, method.name)}}(self
{%- for arg in method.arguments -%}
{% if arg.annotation == "value" and arg.type.category != "object" %}
{%- if arg.annotation == "value" and arg.type.category != "object" -%}
, cmd->{{as_varName(arg.name)}}
{% else %}
{%- else -%}
, arg_{{as_varName(arg.name)}}
{% endif %}
{%- endif -%}
{%- endfor -%}
);
@ -335,7 +335,8 @@ namespace wire {
}
CommandHandler* CreateCommandHandler(nxtDevice device, const nxtProcTable& procs) {
CommandHandler* NewServerCommandHandler(nxtDevice device, const nxtProcTable& procs, CommandSerializer* serializer) {
//TODO(cwallez@chromium.org) do something with the serializer
return new server::Server(device, procs);
}

View File

@ -24,8 +24,16 @@ namespace wire {
class TerribleCommandBuffer : public CommandSerializer {
public:
TerribleCommandBuffer() {
}
TerribleCommandBuffer(CommandHandler* handler) : handler(handler) {
}
void SetHandler(CommandHandler* handler) {
this->handler = handler;
}
void* GetCmdSpace(size_t size) {
if (size > sizeof(buffer)) {
return nullptr;
@ -41,6 +49,7 @@ class TerribleCommandBuffer : public CommandSerializer {
return result;
}
void Flush() {
handler->HandleCommands(buffer, offset);
offset = 0;

View File

@ -29,8 +29,6 @@ namespace wire {
virtual void Flush() = 0;
};
void NewClientDevice(nxtProcTable* procs, nxtDevice* device, CommandSerializer* serializer);
class CommandHandler {
public:
virtual ~CommandHandler() = default;
@ -39,7 +37,8 @@ namespace wire {
virtual void OnSynchronousError() = 0;
};
CommandHandler* CreateCommandHandler(nxtDevice device, const nxtProcTable& procs);
CommandHandler* NewClientDevice(nxtProcTable* procs, nxtDevice* device, CommandSerializer* serializer);
CommandHandler* NewServerCommandHandler(nxtDevice device, const nxtProcTable& procs, CommandSerializer* serializer);
}
}

View File

@ -28,27 +28,34 @@ class WireTests : public Test {
nxtDevice mockDevice;
api.GetProcTableAndDevice(&mockProcs, &mockDevice);
wireServer = CreateCommandHandler(mockDevice, mockProcs);
s2cBuf = new TerribleCommandBuffer();
c2sBuf = new TerribleCommandBuffer(wireServer);
cmdBuf = new TerribleCommandBuffer(wireServer);
wireServer = NewServerCommandHandler(mockDevice, mockProcs, s2cBuf);
c2sBuf->SetHandler(wireServer);
nxtDevice clientDevice;
nxtProcTable clientProcs;
NewClientDevice(&clientProcs, &clientDevice, cmdBuf);
wireClient = NewClientDevice(&clientProcs, &device, c2sBuf);
nxtSetProcs(&clientProcs);
device = clientDevice;
s2cBuf->SetHandler(wireClient);
apiDevice = mockDevice;
}
void TearDown() override {
nxtSetProcs(nullptr);
delete wireServer;
delete cmdBuf;
delete wireClient;
delete c2sBuf;
delete s2cBuf;
}
void Flush() {
cmdBuf->Flush();
void FlushClient() {
c2sBuf->Flush();
}
void FlushServer() {
s2cBuf->Flush();
}
MockProcTable api;
@ -57,7 +64,9 @@ class WireTests : public Test {
private:
CommandHandler* wireServer = nullptr;
TerribleCommandBuffer* cmdBuf = nullptr;
CommandHandler* wireClient = nullptr;
TerribleCommandBuffer* s2cBuf = nullptr;
TerribleCommandBuffer* c2sBuf = nullptr;
};
// One call gets forwarded correctly.
@ -68,7 +77,7 @@ TEST_F(WireTests, CallForwarded) {
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
.WillOnce(Return(apiCmdBufBuilder));
Flush();
FlushClient();
}
// Test that calling methods on a new object works as expected.
@ -84,7 +93,7 @@ TEST_F(WireTests, CreateThenCall) {
EXPECT_CALL(api, CommandBufferBuilderGetResult(apiCmdBufBuilder))
.WillOnce(Return(apiCmdBuf));
Flush();
FlushClient();
}
// Test that client reference/release do not call the backend API.
@ -98,7 +107,7 @@ TEST_F(WireTests, RefCountKeptInClient) {
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
.WillOnce(Return(apiCmdBufBuilder));
Flush();
FlushClient();
}
// Test that client reference/release do not call the backend API.
@ -113,7 +122,7 @@ TEST_F(WireTests, ReleaseCalledOnRefCount0) {
EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
Flush();
FlushClient();
}
TEST_F(WireTests, ObjectAsValueArgument) {
@ -139,7 +148,7 @@ TEST_F(WireTests, ObjectAsValueArgument) {
EXPECT_CALL(api, CommandBufferBuilderSetPipeline(apiCmdBufBuilder, apiPipeline));
Flush();
FlushClient();
}
TEST_F(WireTests, OneObjectAsPointerArgument) {
@ -172,7 +181,7 @@ TEST_F(WireTests, OneObjectAsPointerArgument) {
EXPECT_CALL(api, QueueSubmit(apiQueue, 1, Pointee(apiCmdBuf)));
Flush();
FlushClient();
}
// TODO