dawn_wire: Remove client/ApiProcs_autogen.h

This header was only used to call DeviceCreateErrorBuffer and
DeviceInjectError that are used in some handwritten client commands.
We remove the need for the header by making these two commands
handwritten.

This also improves readability, previously injecting errors read:

  ClientDeviceInjectError(reinterpret_cast<WGPUDevice>(device),
                           WGPUErrorType_Validation,
                           "Some validation message");

And now reads:

  device->InjectError(WGPUErrorType_Validation, "Some validation message");

Bug: dawn:445

Change-Id: Ie11570aacf3036e13abd174d91670ecb84661226
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24080
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2020-06-30 18:26:30 +00:00 committed by Commit Bot service account
parent d411726003
commit 2f616dd108
11 changed files with 58 additions and 89 deletions

View File

@ -111,7 +111,9 @@
"BufferUnmap",
"DeviceCreateBuffer",
"DeviceCreateBufferMapped",
"DeviceCreateErrorBuffer",
"DeviceGetDefaultQueue",
"DeviceInjectError",
"DevicePushErrorScope",
"QueueCreateFence",
"QueueSignal"

View File

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

View File

@ -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 <algorithm>
@ -23,7 +22,6 @@
#include <vector>
namespace dawn_wire { namespace client {
namespace {
//* Outputs an rvalue that's the number of elements a pointer member points to.
@ -158,8 +156,7 @@ namespace dawn_wire { namespace client {
} while (false);
if (DAWN_UNLIKELY(!sameDevice)) {
ClientDeviceInjectError(reinterpret_cast<WGPUDevice>(device),
WGPUErrorType_Validation,
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
@ -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;

View File

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

View File

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

View File

@ -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<size_t>::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<size_t>::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<WGPUDevice>(device_);
cmd.result = ObjectHandle{allocation->object->id, allocation->generation};
device_->GetClient()->SerializeCommand(cmd);
return reinterpret_cast<WGPUBuffer>(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<size_t>::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<WGPUDevice>(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<size_t>(mSize));
if (readHandle == nullptr) {
ClientDeviceInjectError(reinterpret_cast<WGPUDevice>(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<size_t>::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<WGPUDevice>(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<size_t>(mSize));
if (writeHandle == nullptr) {
ClientDeviceInjectError(reinterpret_cast<WGPUDevice>(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<WGPUDevice>(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<WGPUDevice>(device), WGPUErrorType_Validation,
"Buffer needs to be mapped");
device->InjectError(WGPUErrorType_Validation, "Buffer needs to be mapped");
return nullptr;
}
return mMappedData;

View File

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

View File

@ -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<WGPUDevice>(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<WGPUQueue>(mDefaultQueue);

View File

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

View File

@ -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,7 +46,7 @@ namespace dawn_wire { namespace client {
WGPUFenceOnCompletionCallback callback,
void* userdata) {
if (value > mSignaledValue) {
ClientDeviceInjectError(reinterpret_cast<WGPUDevice>(device), WGPUErrorType_Validation,
device->InjectError(WGPUErrorType_Validation,
"Value greater than fence signaled value");
callback(WGPUFenceCompletionStatus_Error, userdata);
return;

View File

@ -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,14 +36,12 @@ namespace dawn_wire { namespace client {
void Queue::Signal(WGPUFence cFence, uint64_t signalValue) {
Fence* fence = reinterpret_cast<Fence*>(cFence);
if (fence->GetQueue() != this) {
ClientDeviceInjectError(reinterpret_cast<WGPUDevice>(fence->device),
WGPUErrorType_Validation,
device->InjectError(WGPUErrorType_Validation,
"Fence must be signaled on the queue on which it was created.");
return;
}
if (signalValue <= fence->GetSignaledValue()) {
ClientDeviceInjectError(reinterpret_cast<WGPUDevice>(fence->device),
WGPUErrorType_Validation,
device->InjectError(WGPUErrorType_Validation,
"Fence value less than or equal to signaled value");
return;
}