From d4117260039322859d2be0ebe1fe7745aca350ff Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Tue, 30 Jun 2020 18:01:50 +0000 Subject: [PATCH] dawn_wire: Make ApiProcs call into objects directly. This CL modifies code generation so that the generated client procs call the handwritten methods on client objects directly. Previously the flow was: - wgpuBarDoStuff - ClientBarDoStuff - ClientHandwrittenBarDoStuff - client::Bar::DoStuff With this CL the flow is: - wgpuBarDoStuff - ClientBarDoStuff - client::Bar::DoStuff This required adding Buffer creation methods on client::Device instead of calling client::Buffer static methods directly. Bug: dawn:445 Change-Id: I1b332b71ac7a03685afcf8fd0617d3d27da468cf Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24062 Commit-Queue: Corentin Wallez Reviewed-by: Stephen White Reviewed-by: Austin Eng --- .../templates/dawn_wire/client/ApiProcs.cpp | 13 +- src/dawn_wire/BUILD.gn | 1 - src/dawn_wire/CMakeLists.txt | 1 - src/dawn_wire/client/ApiProcs.cpp | 145 ------------------ src/dawn_wire/client/ClientDoers.cpp | 2 +- src/dawn_wire/client/Device.cpp | 15 +- src/dawn_wire/client/Device.h | 14 +- 7 files changed, 33 insertions(+), 158 deletions(-) delete mode 100644 src/dawn_wire/client/ApiProcs.cpp diff --git a/generator/templates/dawn_wire/client/ApiProcs.cpp b/generator/templates/dawn_wire/client/ApiProcs.cpp index a604a7f2a5..00a207f2b2 100644 --- a/generator/templates/dawn_wire/client/ApiProcs.cpp +++ b/generator/templates/dawn_wire/client/ApiProcs.cpp @@ -23,6 +23,7 @@ #include namespace dawn_wire { namespace client { + namespace { //* Outputs an rvalue that's the number of elements a pointer member points to. @@ -176,8 +177,8 @@ namespace dawn_wire { namespace client { } {% endif %} + auto self = reinterpret_cast<{{as_wireType(type)}}>(cSelf); {% if Suffix not in client_handwritten_commands %} - auto self = reinterpret_cast<{{as_wireType(type)}}>(cSelf); Device* device = self->device; {{Suffix}}Cmd cmd; @@ -202,9 +203,9 @@ namespace dawn_wire { namespace client { return reinterpret_cast<{{as_cType(method.return_type.name)}}>(allocation->object.get()); {% endif %} {% else %} - return ClientHandwritten{{Suffix}}(cSelf + return self->{{method.name.CamelCase()}}( {%- for arg in method.arguments -%} - , {{as_varName(arg.name)}} + {%if not loop.first %}, {% endif %} {{as_varName(arg.name)}} {%- endfor -%}); {% endif %} } @@ -235,6 +236,12 @@ namespace dawn_wire { namespace client { {% endif %} {% endfor %} + void ClientDeviceReference(WGPUDevice) { + } + + void ClientDeviceRelease(WGPUDevice) { + } + namespace { WGPUInstance ClientCreateInstance(WGPUInstanceDescriptor const* descriptor) { UNREACHABLE(); diff --git a/src/dawn_wire/BUILD.gn b/src/dawn_wire/BUILD.gn index aa8b0c0ec2..8b33d5c19f 100644 --- a/src/dawn_wire/BUILD.gn +++ b/src/dawn_wire/BUILD.gn @@ -64,7 +64,6 @@ dawn_component("dawn_wire") { "WireDeserializeAllocator.h", "WireServer.cpp", "client/ApiObjects.h", - "client/ApiProcs.cpp", "client/Buffer.cpp", "client/Buffer.h", "client/Client.cpp", diff --git a/src/dawn_wire/CMakeLists.txt b/src/dawn_wire/CMakeLists.txt index 579d46acf1..e7927fa6b5 100644 --- a/src/dawn_wire/CMakeLists.txt +++ b/src/dawn_wire/CMakeLists.txt @@ -30,7 +30,6 @@ target_sources(dawn_wire PRIVATE "WireDeserializeAllocator.h" "WireServer.cpp" "client/ApiObjects.h" - "client/ApiProcs.cpp" "client/Buffer.cpp" "client/Buffer.h" "client/Client.cpp" diff --git a/src/dawn_wire/client/ApiProcs.cpp b/src/dawn_wire/client/ApiProcs.cpp deleted file mode 100644 index db4365b384..0000000000 --- a/src/dawn_wire/client/ApiProcs.cpp +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2019 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/client/ApiObjects.h" -#include "dawn_wire/client/ApiProcs_autogen.h" -#include "dawn_wire/client/Client.h" - -namespace dawn_wire { namespace client { - - void ClientHandwrittenBufferMapReadAsync(WGPUBuffer cBuffer, - WGPUBufferMapReadCallback callback, - void* userdata) { - Buffer* buffer = reinterpret_cast(cBuffer); - buffer->MapReadAsync(callback, userdata); - } - - void ClientHandwrittenBufferMapWriteAsync(WGPUBuffer cBuffer, - WGPUBufferMapWriteCallback callback, - void* userdata) { - Buffer* buffer = reinterpret_cast(cBuffer); - buffer->MapWriteAsync(callback, userdata); - } - - void ClientHandwrittenBufferSetSubData(WGPUBuffer cBuffer, - uint64_t start, - uint64_t count, - const void* data) { - Buffer* buffer = reinterpret_cast(cBuffer); - buffer->SetSubData(start, count, data); - } - - void* ClientHandwrittenBufferGetMappedRange(WGPUBuffer cBuffer) { - Buffer* buffer = reinterpret_cast(cBuffer); - return buffer->GetMappedRange(); - } - - const void* ClientHandwrittenBufferGetConstMappedRange(WGPUBuffer cBuffer) { - Buffer* buffer = reinterpret_cast(cBuffer); - return buffer->GetConstMappedRange(); - } - - void ClientHandwrittenBufferUnmap(WGPUBuffer cBuffer) { - Buffer* buffer = reinterpret_cast(cBuffer); - buffer->Unmap(); - } - - void ClientHandwrittenBufferDestroy(WGPUBuffer cBuffer) { - Buffer* buffer = reinterpret_cast(cBuffer); - buffer->Destroy(); - } - - WGPUBuffer ClientHandwrittenDeviceCreateBuffer(WGPUDevice cDevice, - const WGPUBufferDescriptor* descriptor) { - Device* device = reinterpret_cast(cDevice); - return Buffer::Create(device, descriptor); - } - - WGPUCreateBufferMappedResult ClientHandwrittenDeviceCreateBufferMapped( - WGPUDevice cDevice, - const WGPUBufferDescriptor* descriptor) { - Device* device = reinterpret_cast(cDevice); - return Buffer::CreateMapped(device, descriptor); - } - - void ClientHandwrittenDevicePushErrorScope(WGPUDevice cDevice, WGPUErrorFilter filter) { - Device* device = reinterpret_cast(cDevice); - device->PushErrorScope(filter); - } - - bool ClientHandwrittenDevicePopErrorScope(WGPUDevice cDevice, - WGPUErrorCallback callback, - void* userdata) { - Device* device = reinterpret_cast(cDevice); - return device->RequestPopErrorScope(callback, userdata); - } - - uint64_t ClientHandwrittenFenceGetCompletedValue(WGPUFence cSelf) { - Fence* fence = reinterpret_cast(cSelf); - return fence->GetCompletedValue(); - } - - void ClientHandwrittenFenceOnCompletion(WGPUFence cFence, - uint64_t value, - WGPUFenceOnCompletionCallback callback, - void* userdata) { - Fence* fence = reinterpret_cast(cFence); - fence->OnCompletion(value, callback, userdata); - } - - WGPUFence ClientHandwrittenQueueCreateFence(WGPUQueue cSelf, - WGPUFenceDescriptor const* descriptor) { - Queue* queue = reinterpret_cast(cSelf); - return queue->CreateFence(descriptor); - } - - void ClientHandwrittenQueueSignal(WGPUQueue cQueue, WGPUFence cFence, uint64_t signalValue) { - Queue* queue = reinterpret_cast(cQueue); - queue->Signal(cFence, signalValue); - } - - void ClientHandwrittenQueueWriteBuffer(WGPUQueue cQueue, - WGPUBuffer cBuffer, - uint64_t bufferOffset, - const void* data, - size_t size) { - Queue* queue = reinterpret_cast(cQueue); - queue->WriteBuffer(cBuffer, bufferOffset, data, size); - } - - void ClientDeviceReference(WGPUDevice) { - } - - void ClientDeviceRelease(WGPUDevice) { - } - - WGPUQueue ClientHandwrittenDeviceGetDefaultQueue(WGPUDevice cSelf) { - Device* device = reinterpret_cast(cSelf); - return device->GetDefaultQueue(); - } - - void ClientHandwrittenDeviceSetUncapturedErrorCallback(WGPUDevice cSelf, - WGPUErrorCallback callback, - void* userdata) { - Device* device = reinterpret_cast(cSelf); - device->SetUncapturedErrorCallback(callback, userdata); - } - void ClientHandwrittenDeviceSetDeviceLostCallback(WGPUDevice cSelf, - WGPUDeviceLostCallback callback, - void* userdata) { - Device* device = reinterpret_cast(cSelf); - device->SetDeviceLostCallback(callback, userdata); - } - -}} // namespace dawn_wire::client diff --git a/src/dawn_wire/client/ClientDoers.cpp b/src/dawn_wire/client/ClientDoers.cpp index 55818ba7be..8ec5e5a9fb 100644 --- a/src/dawn_wire/client/ClientDoers.cpp +++ b/src/dawn_wire/client/ClientDoers.cpp @@ -43,7 +43,7 @@ namespace dawn_wire { namespace client { bool Client::DoDevicePopErrorScopeCallback(uint64_t requestSerial, WGPUErrorType errorType, const char* message) { - return mDevice->PopErrorScope(requestSerial, errorType, message); + return mDevice->OnPopErrorScopeCallback(requestSerial, errorType, message); } bool Client::DoBufferMapReadAsyncCallback(Buffer* buffer, diff --git a/src/dawn_wire/client/Device.cpp b/src/dawn_wire/client/Device.cpp index 43361b3e62..64b1b04664 100644 --- a/src/dawn_wire/client/Device.cpp +++ b/src/dawn_wire/client/Device.cpp @@ -91,7 +91,7 @@ namespace dawn_wire { namespace client { mClient->SerializeCommand(cmd); } - bool Device::RequestPopErrorScope(WGPUErrorCallback callback, void* userdata) { + bool Device::PopErrorScope(WGPUErrorCallback callback, void* userdata) { if (mErrorScopeStackSize == 0) { return false; } @@ -111,7 +111,9 @@ namespace dawn_wire { namespace client { return true; } - bool Device::PopErrorScope(uint64_t requestSerial, WGPUErrorType type, const char* message) { + bool Device::OnPopErrorScopeCallback(uint64_t requestSerial, + WGPUErrorType type, + const char* message) { switch (type) { case WGPUErrorType_NoError: case WGPUErrorType_Validation: @@ -135,6 +137,15 @@ namespace dawn_wire { namespace client { return true; } + WGPUBuffer Device::CreateBuffer(const WGPUBufferDescriptor* descriptor) { + return Buffer::Create(this, descriptor); + } + + WGPUCreateBufferMappedResult Device::CreateBufferMapped( + const WGPUBufferDescriptor* descriptor) { + return Buffer::CreateMapped(this, descriptor); + } + WGPUQueue Device::GetDefaultQueue() { mDefaultQueue->refcount++; return reinterpret_cast(mDefaultQueue); diff --git a/src/dawn_wire/client/Device.h b/src/dawn_wire/client/Device.h index 42dff18267..5981124d09 100644 --- a/src/dawn_wire/client/Device.h +++ b/src/dawn_wire/client/Device.h @@ -32,14 +32,18 @@ namespace dawn_wire { namespace client { ~Device(); Client* GetClient(); - void HandleError(WGPUErrorType errorType, const char* message); - void HandleDeviceLost(const char* message); void SetUncapturedErrorCallback(WGPUErrorCallback errorCallback, void* errorUserdata); void SetDeviceLostCallback(WGPUDeviceLostCallback errorCallback, void* errorUserdata); - void PushErrorScope(WGPUErrorFilter filter); - bool RequestPopErrorScope(WGPUErrorCallback callback, void* userdata); - bool PopErrorScope(uint64_t requestSerial, WGPUErrorType type, const char* message); + bool PopErrorScope(WGPUErrorCallback callback, void* userdata); + WGPUBuffer CreateBuffer(const WGPUBufferDescriptor* descriptor); + WGPUCreateBufferMappedResult CreateBufferMapped(const WGPUBufferDescriptor* descriptor); + + void HandleError(WGPUErrorType errorType, const char* message); + void HandleDeviceLost(const char* message); + bool OnPopErrorScopeCallback(uint64_t requestSerial, + WGPUErrorType type, + const char* message); WGPUQueue GetDefaultQueue();