diff --git a/dawn_wire.json b/dawn_wire.json index 54d8c94b61..87063e0024 100644 --- a/dawn_wire.json +++ b/dawn_wire.json @@ -111,7 +111,9 @@ "BufferUnmap", "DeviceCreateBuffer", "DeviceCreateBufferMapped", + "DeviceCreateErrorBuffer", "DeviceGetDefaultQueue", + "DeviceInjectError", "DevicePushErrorScope", "QueueCreateFence", "QueueSignal" diff --git a/generator/dawn_json_generator.py b/generator/dawn_json_generator.py index 6037aa8fab..119ba6a849 100644 --- a/generator/dawn_json_generator.py +++ b/generator/dawn_json_generator.py @@ -627,7 +627,6 @@ class MultiGeneratorFromDawnJSON(Generator): renders.append(FileRender('dawn_wire/WireCmd.cpp', 'src/dawn_wire/WireCmd_autogen.cpp', wire_params)) renders.append(FileRender('dawn_wire/client/ApiObjects.h', 'src/dawn_wire/client/ApiObjects_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/client/ApiProcs.cpp', 'src/dawn_wire/client/ApiProcs_autogen.cpp', wire_params)) - renders.append(FileRender('dawn_wire/client/ApiProcs.h', 'src/dawn_wire/client/ApiProcs_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/client/ClientBase.h', 'src/dawn_wire/client/ClientBase_autogen.h', wire_params)) renders.append(FileRender('dawn_wire/client/ClientHandlers.cpp', 'src/dawn_wire/client/ClientHandlers_autogen.cpp', wire_params)) renders.append(FileRender('dawn_wire/client/ClientPrototypes.inc', 'src/dawn_wire/client/ClientPrototypes_autogen.inc', wire_params)) diff --git a/generator/templates/dawn_wire/client/ApiProcs.cpp b/generator/templates/dawn_wire/client/ApiProcs.cpp index 00a207f2b2..3edba1a22b 100644 --- a/generator/templates/dawn_wire/client/ApiProcs.cpp +++ b/generator/templates/dawn_wire/client/ApiProcs.cpp @@ -14,7 +14,6 @@ #include "common/Log.h" #include "dawn_wire/client/ApiObjects.h" -#include "dawn_wire/client/ApiProcs_autogen.h" #include "dawn_wire/client/Client.h" #include @@ -23,7 +22,6 @@ #include namespace dawn_wire { namespace client { - namespace { //* Outputs an rvalue that's the number of elements a pointer member points to. @@ -158,9 +156,8 @@ namespace dawn_wire { namespace client { } while (false); if (DAWN_UNLIKELY(!sameDevice)) { - ClientDeviceInjectError(reinterpret_cast(device), - WGPUErrorType_Validation, - "All objects must be from the same device."); + device->InjectError(WGPUErrorType_Validation, + "All objects must be from the same device."); {% if method.return_type.category == "object" %} // Allocate an object without registering it on the server. This is backed by a real allocation on // the client so commands can be sent with it. But because it's not allocated on the server, it will @@ -236,18 +233,18 @@ namespace dawn_wire { namespace client { {% endif %} {% endfor %} - void ClientDeviceReference(WGPUDevice) { - } - - void ClientDeviceRelease(WGPUDevice) { - } - namespace { WGPUInstance ClientCreateInstance(WGPUInstanceDescriptor const* descriptor) { UNREACHABLE(); return nullptr; } + void ClientDeviceReference(WGPUDevice) { + } + + void ClientDeviceRelease(WGPUDevice) { + } + struct ProcEntry { WGPUProc proc; const char* name; diff --git a/generator/templates/dawn_wire/client/ApiProcs.h b/generator/templates/dawn_wire/client/ApiProcs.h deleted file mode 100644 index 2a27c3cc8e..0000000000 --- a/generator/templates/dawn_wire/client/ApiProcs.h +++ /dev/null @@ -1,41 +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. - -#ifndef DAWNWIRE_CLIENT_APIPROCS_AUTOGEN_H_ -#define DAWNWIRE_CLIENT_APIPROCS_AUTOGEN_H_ - -#include - -namespace dawn_wire { namespace client { - - //* Dawn API - {% for type in by_category["object"] %} - {% set cType = as_cType(type.name) %} - {% for method in c_methods(type) %} - {% set Suffix = as_MethodSuffix(type.name, method.name) %} - {% if Suffix in client_handwritten_commands %} - {% set Suffix = "Handwritten" + Suffix %} - {% endif %} - {{as_cType(method.return_type.name)}} Client{{Suffix}}( - {{-cType}} cSelf - {%- for arg in method.arguments -%} - , {{as_annotated_cType(arg)}} - {%- endfor -%} - ); - {% endfor %} - {% endfor %} - -}} // namespace dawn_wire::client - -#endif // DAWNWIRE_CLIENT_APIPROCS_AUTOGEN_H_ diff --git a/src/dawn_wire/BUILD.gn b/src/dawn_wire/BUILD.gn index 8b33d5c19f..9e46342324 100644 --- a/src/dawn_wire/BUILD.gn +++ b/src/dawn_wire/BUILD.gn @@ -37,7 +37,6 @@ dawn_json_generator("dawn_wire_gen") { "src/dawn_wire/WireCmd_autogen.cpp", "src/dawn_wire/client/ApiObjects_autogen.h", "src/dawn_wire/client/ApiProcs_autogen.cpp", - "src/dawn_wire/client/ApiProcs_autogen.h", "src/dawn_wire/client/ClientBase_autogen.h", "src/dawn_wire/client/ClientHandlers_autogen.cpp", "src/dawn_wire/client/ClientPrototypes_autogen.inc", diff --git a/src/dawn_wire/client/Buffer.cpp b/src/dawn_wire/client/Buffer.cpp index 910ffede8b..0b4889e130 100644 --- a/src/dawn_wire/client/Buffer.cpp +++ b/src/dawn_wire/client/Buffer.cpp @@ -14,7 +14,6 @@ #include "dawn_wire/client/Buffer.h" -#include "dawn_wire/client/ApiProcs_autogen.h" #include "dawn_wire/client/Client.h" #include "dawn_wire/client/Device.h" @@ -53,9 +52,8 @@ namespace dawn_wire { namespace client { if ((descriptor->usage & (WGPUBufferUsage_MapRead | WGPUBufferUsage_MapWrite)) != 0 && descriptor->size > std::numeric_limits::max()) { - ClientDeviceInjectError(cDevice, WGPUErrorType_OutOfMemory, - "Buffer is too large for map usage"); - return ClientDeviceCreateErrorBuffer(cDevice); + device_->InjectError(WGPUErrorType_OutOfMemory, "Buffer is too large for map usage"); + return device_->CreateErrorBuffer(); } auto* bufferObjectAndSerial = wireClient->BufferAllocator().New(device_); @@ -86,9 +84,8 @@ namespace dawn_wire { namespace client { // This buffer is too large to be mapped and to make a WriteHandle for. if (descriptor->size > std::numeric_limits::max()) { - ClientDeviceInjectError(cDevice, WGPUErrorType_OutOfMemory, - "Buffer is too large for mapping"); - result.buffer = ClientDeviceCreateErrorBuffer(cDevice); + device_->InjectError(WGPUErrorType_OutOfMemory, "Buffer is too large for mapping"); + result.buffer = device_->CreateErrorBuffer(); return result; } @@ -99,9 +96,8 @@ namespace dawn_wire { namespace client { wireClient->GetMemoryTransferService()->CreateWriteHandle(descriptor->size)); if (writeHandle == nullptr) { - ClientDeviceInjectError(cDevice, WGPUErrorType_OutOfMemory, - "Buffer mapping allocation failed"); - result.buffer = ClientDeviceCreateErrorBuffer(cDevice); + device_->InjectError(WGPUErrorType_OutOfMemory, "Buffer mapping allocation failed"); + result.buffer = device_->CreateErrorBuffer(); return result; } @@ -111,9 +107,8 @@ namespace dawn_wire { namespace client { // |result.data| may be null on error. std::tie(result.data, result.dataLength) = writeHandle->Open(); if (result.data == nullptr) { - ClientDeviceInjectError(cDevice, WGPUErrorType_OutOfMemory, - "Buffer mapping allocation failed"); - result.buffer = ClientDeviceCreateErrorBuffer(cDevice); + device_->InjectError(WGPUErrorType_OutOfMemory, "Buffer mapping allocation failed"); + result.buffer = device_->CreateErrorBuffer(); return result; } @@ -145,6 +140,18 @@ namespace dawn_wire { namespace client { return result; } + // static + WGPUBuffer Buffer::CreateError(Device* device_) { + auto* allocation = device_->GetClient()->BufferAllocator().New(device_); + + DeviceCreateErrorBufferCmd cmd; + cmd.self = reinterpret_cast(device_); + cmd.result = ObjectHandle{allocation->object->id, allocation->generation}; + device_->GetClient()->SerializeCommand(cmd); + + return reinterpret_cast(allocation->object.get()); + } + Buffer::~Buffer() { // Callbacks need to be fired in all cases, as they can handle freeing resources // so we call them with "Unknown" status. @@ -169,8 +176,7 @@ namespace dawn_wire { namespace client { if (mSize > std::numeric_limits::max()) { // On buffer creation, we check that mappable buffers do not exceed this size. // So this buffer must not have mappable usage. Inject a validation error. - ClientDeviceInjectError(reinterpret_cast(device), WGPUErrorType_Validation, - "Buffer needs the correct map usage bit"); + device->InjectError(WGPUErrorType_Validation, "Buffer needs the correct map usage bit"); callback(WGPUBufferMapAsyncStatus_Error, nullptr, 0, userdata); return; } @@ -181,8 +187,7 @@ namespace dawn_wire { namespace client { device->GetClient()->GetMemoryTransferService()->CreateReadHandle( static_cast(mSize)); if (readHandle == nullptr) { - ClientDeviceInjectError(reinterpret_cast(device), WGPUErrorType_OutOfMemory, - "Failed to create buffer mapping"); + device->InjectError(WGPUErrorType_OutOfMemory, "Failed to create buffer mapping"); callback(WGPUBufferMapAsyncStatus_Error, nullptr, 0, userdata); return; } @@ -207,8 +212,7 @@ namespace dawn_wire { namespace client { if (mSize > std::numeric_limits::max()) { // On buffer creation, we check that mappable buffers do not exceed this size. // So this buffer must not have mappable usage. Inject a validation error. - ClientDeviceInjectError(reinterpret_cast(device), WGPUErrorType_Validation, - "Buffer needs the correct map usage bit"); + device->InjectError(WGPUErrorType_Validation, "Buffer needs the correct map usage bit"); callback(WGPUBufferMapAsyncStatus_Error, nullptr, 0, userdata); return; } @@ -219,8 +223,7 @@ namespace dawn_wire { namespace client { device->GetClient()->GetMemoryTransferService()->CreateWriteHandle( static_cast(mSize)); if (writeHandle == nullptr) { - ClientDeviceInjectError(reinterpret_cast(device), WGPUErrorType_OutOfMemory, - "Failed to create buffer mapping"); + device->InjectError(WGPUErrorType_OutOfMemory, "Failed to create buffer mapping"); callback(WGPUBufferMapAsyncStatus_Error, nullptr, 0, userdata); return; } @@ -366,8 +369,7 @@ namespace dawn_wire { namespace client { void* Buffer::GetMappedRange() { if (!IsMappedForWriting()) { - ClientDeviceInjectError(reinterpret_cast(device), WGPUErrorType_Validation, - "Buffer needs to be mapped for writing"); + device->InjectError(WGPUErrorType_Validation, "Buffer needs to be mapped for writing"); return nullptr; } return mMappedData; @@ -375,8 +377,7 @@ namespace dawn_wire { namespace client { const void* Buffer::GetConstMappedRange() { if (!IsMappedForWriting() && !IsMappedForReading()) { - ClientDeviceInjectError(reinterpret_cast(device), WGPUErrorType_Validation, - "Buffer needs to be mapped"); + device->InjectError(WGPUErrorType_Validation, "Buffer needs to be mapped"); return nullptr; } return mMappedData; diff --git a/src/dawn_wire/client/Buffer.h b/src/dawn_wire/client/Buffer.h index 2dd8dd5ae3..a69b054b8d 100644 --- a/src/dawn_wire/client/Buffer.h +++ b/src/dawn_wire/client/Buffer.h @@ -31,6 +31,7 @@ namespace dawn_wire { namespace client { static WGPUBuffer Create(Device* device, const WGPUBufferDescriptor* descriptor); static WGPUCreateBufferMappedResult CreateMapped(Device* device, const WGPUBufferDescriptor* descriptor); + static WGPUBuffer CreateError(Device* device); ~Buffer(); void ClearMapRequests(WGPUBufferMapAsyncStatus status); diff --git a/src/dawn_wire/client/Device.cpp b/src/dawn_wire/client/Device.cpp index 64b1b04664..4df6226e09 100644 --- a/src/dawn_wire/client/Device.cpp +++ b/src/dawn_wire/client/Device.cpp @@ -137,6 +137,14 @@ namespace dawn_wire { namespace client { return true; } + void Device::InjectError(WGPUErrorType type, const char* message) { + DeviceInjectErrorCmd cmd; + cmd.self = reinterpret_cast(this); + cmd.type = type; + cmd.message = message; + mClient->SerializeCommand(cmd); + } + WGPUBuffer Device::CreateBuffer(const WGPUBufferDescriptor* descriptor) { return Buffer::Create(this, descriptor); } @@ -146,6 +154,10 @@ namespace dawn_wire { namespace client { return Buffer::CreateMapped(this, descriptor); } + WGPUBuffer Device::CreateErrorBuffer() { + return Buffer::CreateError(this); + } + 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 5981124d09..2b554e34e8 100644 --- a/src/dawn_wire/client/Device.h +++ b/src/dawn_wire/client/Device.h @@ -34,10 +34,12 @@ namespace dawn_wire { namespace client { Client* GetClient(); void SetUncapturedErrorCallback(WGPUErrorCallback errorCallback, void* errorUserdata); void SetDeviceLostCallback(WGPUDeviceLostCallback errorCallback, void* errorUserdata); + void InjectError(WGPUErrorType type, const char* message); void PushErrorScope(WGPUErrorFilter filter); bool PopErrorScope(WGPUErrorCallback callback, void* userdata); WGPUBuffer CreateBuffer(const WGPUBufferDescriptor* descriptor); WGPUCreateBufferMappedResult CreateBufferMapped(const WGPUBufferDescriptor* descriptor); + WGPUBuffer CreateErrorBuffer(); void HandleError(WGPUErrorType errorType, const char* message); void HandleDeviceLost(const char* message); diff --git a/src/dawn_wire/client/Fence.cpp b/src/dawn_wire/client/Fence.cpp index aa0407cc77..d9e1fa7ed3 100644 --- a/src/dawn_wire/client/Fence.cpp +++ b/src/dawn_wire/client/Fence.cpp @@ -14,7 +14,7 @@ #include "dawn_wire/client/Fence.h" -#include "dawn_wire/client/ApiProcs_autogen.h" +#include "dawn_wire/client/Device.h" namespace dawn_wire { namespace client { @@ -46,8 +46,8 @@ namespace dawn_wire { namespace client { WGPUFenceOnCompletionCallback callback, void* userdata) { if (value > mSignaledValue) { - ClientDeviceInjectError(reinterpret_cast(device), WGPUErrorType_Validation, - "Value greater than fence signaled value"); + device->InjectError(WGPUErrorType_Validation, + "Value greater than fence signaled value"); callback(WGPUFenceCompletionStatus_Error, userdata); return; } diff --git a/src/dawn_wire/client/Queue.cpp b/src/dawn_wire/client/Queue.cpp index fa338f326c..f515f52380 100644 --- a/src/dawn_wire/client/Queue.cpp +++ b/src/dawn_wire/client/Queue.cpp @@ -14,7 +14,6 @@ #include "dawn_wire/client/Queue.h" -#include "dawn_wire/client/ApiProcs_autogen.h" #include "dawn_wire/client/Client.h" #include "dawn_wire/client/Device.h" @@ -37,15 +36,13 @@ namespace dawn_wire { namespace client { void Queue::Signal(WGPUFence cFence, uint64_t signalValue) { Fence* fence = reinterpret_cast(cFence); if (fence->GetQueue() != this) { - ClientDeviceInjectError(reinterpret_cast(fence->device), - WGPUErrorType_Validation, - "Fence must be signaled on the queue on which it was created."); + device->InjectError(WGPUErrorType_Validation, + "Fence must be signaled on the queue on which it was created."); return; } if (signalValue <= fence->GetSignaledValue()) { - ClientDeviceInjectError(reinterpret_cast(fence->device), - WGPUErrorType_Validation, - "Fence value less than or equal to signaled value"); + device->InjectError(WGPUErrorType_Validation, + "Fence value less than or equal to signaled value"); return; }