Plumb the server->client wire
This commit is contained in:
parent
7f433a5b52
commit
682a8250b3
|
@ -69,6 +69,7 @@ enum class BackendType {
|
||||||
enum class CmdBufType {
|
enum class CmdBufType {
|
||||||
None,
|
None,
|
||||||
Terrible,
|
Terrible,
|
||||||
|
//TODO(cwallez@chromium.org) double terrible cmdbuf
|
||||||
};
|
};
|
||||||
|
|
||||||
static BackendType backendType = BackendType::OpenGL;
|
static BackendType backendType = BackendType::OpenGL;
|
||||||
|
@ -78,7 +79,9 @@ static BackendBinding* binding = nullptr;
|
||||||
static GLFWwindow* window = nullptr;
|
static GLFWwindow* window = nullptr;
|
||||||
|
|
||||||
static nxt::wire::CommandHandler* wireServer = 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) {
|
void HandleSynchronousError(const char* errorMessage, void* userData) {
|
||||||
std::cerr << errorMessage << std::endl;
|
std::cerr << errorMessage << std::endl;
|
||||||
|
@ -127,12 +130,16 @@ void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
|
||||||
|
|
||||||
case CmdBufType::Terrible:
|
case CmdBufType::Terrible:
|
||||||
{
|
{
|
||||||
wireServer = nxt::wire::CreateCommandHandler(backendDevice, backendProcs);
|
c2sBuf = new nxt::wire::TerribleCommandBuffer();
|
||||||
cmdBuf = new nxt::wire::TerribleCommandBuffer(wireServer);
|
s2cBuf = new nxt::wire::TerribleCommandBuffer();
|
||||||
|
|
||||||
|
wireServer = nxt::wire::NewServerCommandHandler(backendDevice, backendProcs, s2cBuf);
|
||||||
|
c2sBuf->SetHandler(wireServer);
|
||||||
|
|
||||||
nxtDevice clientDevice;
|
nxtDevice clientDevice;
|
||||||
nxtProcTable clientProcs;
|
nxtProcTable clientProcs;
|
||||||
nxt::wire::NewClientDevice(&clientProcs, &clientDevice, cmdBuf);
|
wireClient = nxt::wire::NewClientDevice(&clientProcs, &clientDevice, c2sBuf);
|
||||||
|
s2cBuf->SetHandler(wireClient);
|
||||||
|
|
||||||
*procs = clientProcs;
|
*procs = clientProcs;
|
||||||
*device = nxt::Device::Acquire(clientDevice);
|
*device = nxt::Device::Acquire(clientDevice);
|
||||||
|
@ -140,6 +147,7 @@ void GetProcTableAndDevice(nxtProcTable* procs, nxt::Device* device) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO(cwallez@chromium.org) this will disappear
|
||||||
backend::RegisterSynchronousErrorCallback(backendDevice, HandleSynchronousError, wireServer);
|
backend::RegisterSynchronousErrorCallback(backendDevice, HandleSynchronousError, wireServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,8 +258,9 @@ extern "C" {
|
||||||
}
|
}
|
||||||
|
|
||||||
void SwapBuffers() {
|
void SwapBuffers() {
|
||||||
if (cmdBuf) {
|
if (cmdBufType == CmdBufType::Terrible) {
|
||||||
cmdBuf->Flush();
|
c2sBuf->Flush();
|
||||||
|
s2cBuf->Flush();
|
||||||
}
|
}
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
binding->SwapBuffers();
|
binding->SwapBuffers();
|
||||||
|
|
|
@ -210,11 +210,33 @@ namespace wire {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Client : public CommandHandler {
|
||||||
|
public:
|
||||||
|
Client(Device* device) : device(device) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NewClientDevice(nxtProcTable* procs, nxtDevice* device, CommandSerializer* serializer) {
|
const uint8_t* HandleCommands(const uint8_t* commands, size_t size) override {
|
||||||
*device = reinterpret_cast<nxtDeviceImpl*>(new client::Device(serializer));
|
// 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();
|
*procs = client::GetProcs();
|
||||||
|
|
||||||
|
return new client::Client(clientDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -273,16 +273,16 @@ namespace wire {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if returns -%}
|
{% if returns %}
|
||||||
auto result =
|
auto result ={{" "}}
|
||||||
{%- endif -%}
|
{%- endif %}
|
||||||
procs.{{as_varName(type.name, method.name)}}(self
|
procs.{{as_varName(type.name, method.name)}}(self
|
||||||
{%- for arg in method.arguments -%}
|
{%- 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)}}
|
, cmd->{{as_varName(arg.name)}}
|
||||||
{% else %}
|
{%- else -%}
|
||||||
, arg_{{as_varName(arg.name)}}
|
, arg_{{as_varName(arg.name)}}
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
{%- endfor -%}
|
{%- 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);
|
return new server::Server(device, procs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,16 @@ namespace wire {
|
||||||
|
|
||||||
class TerribleCommandBuffer : public CommandSerializer {
|
class TerribleCommandBuffer : public CommandSerializer {
|
||||||
public:
|
public:
|
||||||
|
TerribleCommandBuffer() {
|
||||||
|
}
|
||||||
|
|
||||||
TerribleCommandBuffer(CommandHandler* handler) : handler(handler) {
|
TerribleCommandBuffer(CommandHandler* handler) : handler(handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetHandler(CommandHandler* handler) {
|
||||||
|
this->handler = handler;
|
||||||
|
}
|
||||||
|
|
||||||
void* GetCmdSpace(size_t size) {
|
void* GetCmdSpace(size_t size) {
|
||||||
if (size > sizeof(buffer)) {
|
if (size > sizeof(buffer)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -41,6 +49,7 @@ class TerribleCommandBuffer : public CommandSerializer {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flush() {
|
void Flush() {
|
||||||
handler->HandleCommands(buffer, offset);
|
handler->HandleCommands(buffer, offset);
|
||||||
offset = 0;
|
offset = 0;
|
||||||
|
|
|
@ -29,8 +29,6 @@ namespace wire {
|
||||||
virtual void Flush() = 0;
|
virtual void Flush() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
void NewClientDevice(nxtProcTable* procs, nxtDevice* device, CommandSerializer* serializer);
|
|
||||||
|
|
||||||
class CommandHandler {
|
class CommandHandler {
|
||||||
public:
|
public:
|
||||||
virtual ~CommandHandler() = default;
|
virtual ~CommandHandler() = default;
|
||||||
|
@ -39,7 +37,8 @@ namespace wire {
|
||||||
virtual void OnSynchronousError() = 0;
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,27 +28,34 @@ class WireTests : public Test {
|
||||||
nxtDevice mockDevice;
|
nxtDevice mockDevice;
|
||||||
api.GetProcTableAndDevice(&mockProcs, &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;
|
nxtProcTable clientProcs;
|
||||||
NewClientDevice(&clientProcs, &clientDevice, cmdBuf);
|
wireClient = NewClientDevice(&clientProcs, &device, c2sBuf);
|
||||||
|
|
||||||
nxtSetProcs(&clientProcs);
|
nxtSetProcs(&clientProcs);
|
||||||
device = clientDevice;
|
s2cBuf->SetHandler(wireClient);
|
||||||
|
|
||||||
apiDevice = mockDevice;
|
apiDevice = mockDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TearDown() override {
|
void TearDown() override {
|
||||||
nxtSetProcs(nullptr);
|
nxtSetProcs(nullptr);
|
||||||
delete wireServer;
|
delete wireServer;
|
||||||
delete cmdBuf;
|
delete wireClient;
|
||||||
|
delete c2sBuf;
|
||||||
|
delete s2cBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Flush() {
|
void FlushClient() {
|
||||||
cmdBuf->Flush();
|
c2sBuf->Flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlushServer() {
|
||||||
|
s2cBuf->Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
MockProcTable api;
|
MockProcTable api;
|
||||||
|
@ -57,7 +64,9 @@ class WireTests : public Test {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CommandHandler* wireServer = nullptr;
|
CommandHandler* wireServer = nullptr;
|
||||||
TerribleCommandBuffer* cmdBuf = nullptr;
|
CommandHandler* wireClient = nullptr;
|
||||||
|
TerribleCommandBuffer* s2cBuf = nullptr;
|
||||||
|
TerribleCommandBuffer* c2sBuf = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
// One call gets forwarded correctly.
|
// One call gets forwarded correctly.
|
||||||
|
@ -68,7 +77,7 @@ TEST_F(WireTests, CallForwarded) {
|
||||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
.WillOnce(Return(apiCmdBufBuilder));
|
.WillOnce(Return(apiCmdBufBuilder));
|
||||||
|
|
||||||
Flush();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that calling methods on a new object works as expected.
|
// Test that calling methods on a new object works as expected.
|
||||||
|
@ -84,7 +93,7 @@ TEST_F(WireTests, CreateThenCall) {
|
||||||
EXPECT_CALL(api, CommandBufferBuilderGetResult(apiCmdBufBuilder))
|
EXPECT_CALL(api, CommandBufferBuilderGetResult(apiCmdBufBuilder))
|
||||||
.WillOnce(Return(apiCmdBuf));
|
.WillOnce(Return(apiCmdBuf));
|
||||||
|
|
||||||
Flush();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that client reference/release do not call the backend API.
|
// Test that client reference/release do not call the backend API.
|
||||||
|
@ -98,7 +107,7 @@ TEST_F(WireTests, RefCountKeptInClient) {
|
||||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
.WillOnce(Return(apiCmdBufBuilder));
|
.WillOnce(Return(apiCmdBufBuilder));
|
||||||
|
|
||||||
Flush();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that client reference/release do not call the backend API.
|
// Test that client reference/release do not call the backend API.
|
||||||
|
@ -113,7 +122,7 @@ TEST_F(WireTests, ReleaseCalledOnRefCount0) {
|
||||||
|
|
||||||
EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
|
EXPECT_CALL(api, CommandBufferBuilderRelease(apiCmdBufBuilder));
|
||||||
|
|
||||||
Flush();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WireTests, ObjectAsValueArgument) {
|
TEST_F(WireTests, ObjectAsValueArgument) {
|
||||||
|
@ -139,7 +148,7 @@ TEST_F(WireTests, ObjectAsValueArgument) {
|
||||||
|
|
||||||
EXPECT_CALL(api, CommandBufferBuilderSetPipeline(apiCmdBufBuilder, apiPipeline));
|
EXPECT_CALL(api, CommandBufferBuilderSetPipeline(apiCmdBufBuilder, apiPipeline));
|
||||||
|
|
||||||
Flush();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WireTests, OneObjectAsPointerArgument) {
|
TEST_F(WireTests, OneObjectAsPointerArgument) {
|
||||||
|
@ -172,7 +181,7 @@ TEST_F(WireTests, OneObjectAsPointerArgument) {
|
||||||
|
|
||||||
EXPECT_CALL(api, QueueSubmit(apiQueue, 1, Pointee(apiCmdBuf)));
|
EXPECT_CALL(api, QueueSubmit(apiQueue, 1, Pointee(apiCmdBuf)));
|
||||||
|
|
||||||
Flush();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
|
|
Loading…
Reference in New Issue