Implement the device error callback.

This adds support for "natively defined" API types like callbacks that
will have to be implemented manually for each target language. Also this
splits the concept of "native method" into a set of native methods per
language.

Removes the "Synchronous error" concept that was used to make builders
work in the maybe Monad, this will have to be reinroduced with builder
callbacks.
This commit is contained in:
Corentin Wallez
2017-04-20 14:42:36 -04:00
committed by Corentin Wallez
parent 682a8250b3
commit 4b410a33ca
15 changed files with 219 additions and 55 deletions

View File

@@ -30,11 +30,6 @@
namespace backend {
void RegisterSynchronousErrorCallback(nxtDevice device, ErrorCallback callback, void* userData) {
auto deviceBase = reinterpret_cast<DeviceBase*>(device);
deviceBase->RegisterErrorCallback(callback, userData);
}
// DeviceBase::Caches
// The caches are unordered_sets of pointers with special hash and compare functions
@@ -57,13 +52,13 @@ namespace backend {
void DeviceBase::HandleError(const char* message) {
if (errorCallback) {
errorCallback(message, errorUserData);
errorCallback(message, errorUserdata);
}
}
void DeviceBase::RegisterErrorCallback(ErrorCallback callback, void* userData) {
void DeviceBase::SetErrorCallback(nxt::DeviceErrorCallback callback, nxt::CallbackUserdata userdata) {
this->errorCallback = callback;
this->errorUserData = userData;
this->errorUserdata = userdata;
}
BindGroupLayoutBase* DeviceBase::GetOrCreateBindGroupLayout(const BindGroupLayoutBase* blueprint, BindGroupLayoutBuilder* builder) {

View File

@@ -30,7 +30,7 @@ namespace backend {
~DeviceBase();
void HandleError(const char* message);
void RegisterErrorCallback(ErrorCallback callback, void* userData);
void SetErrorCallback(nxt::DeviceErrorCallback, nxt::CallbackUserdata userdata);
virtual BindGroupBase* CreateBindGroup(BindGroupBuilder* builder) = 0;
virtual BindGroupLayoutBase* CreateBindGroupLayout(BindGroupLayoutBuilder* builder) = 0;
@@ -85,8 +85,8 @@ namespace backend {
struct Caches;
Caches* caches = nullptr;
ErrorCallback errorCallback = nullptr;
void* errorUserData = nullptr;
nxt::DeviceErrorCallback errorCallback = nullptr;
nxt::CallbackUserdata errorUserdata;
};
}

View File

@@ -30,6 +30,8 @@ SetPic(wire_autogen)
add_library(nxt_wire SHARED
${WIRE_DIR}/TerribleCommandBuffer.h
${WIRE_DIR}/WireCmd.cpp
${WIRE_DIR}/WireCmd.h
)
target_link_libraries(nxt_wire wire_autogen)
SetCXX14(nxt_wire)

View File

@@ -33,8 +33,6 @@ namespace wire {
public:
virtual ~CommandHandler() = default;
virtual const uint8_t* HandleCommands(const uint8_t* commands, size_t size) = 0;
virtual void OnSynchronousError() = 0;
};
CommandHandler* NewClientDevice(nxtProcTable* procs, nxtDevice* device, CommandSerializer* serializer);

33
src/wire/WireCmd.cpp Normal file
View File

@@ -0,0 +1,33 @@
// Copyright 2017 The NXT 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 "WireCmd.h"
namespace nxt {
namespace wire {
size_t ReturnDeviceErrorCallbackCmd::GetRequiredSize() const {
return sizeof(*this) + messageStrlen + 1;
}
char* ReturnDeviceErrorCallbackCmd::GetMessage() {
return reinterpret_cast<char*>(this + 1);
}
const char* ReturnDeviceErrorCallbackCmd::GetMessage() const {
return reinterpret_cast<const char*>(this + 1);
}
}
}

View File

@@ -17,4 +17,20 @@
#include "wire/WireCmd_autogen.h"
namespace nxt {
namespace wire {
struct ReturnDeviceErrorCallbackCmd {
wire::ReturnWireCmd commandId = ReturnWireCmd::DeviceErrorCallback;
size_t messageStrlen;
size_t GetRequiredSize() const;
char* GetMessage();
const char* GetMessage() const;
};
}
}
#endif // WIRE_WIRECMD_H_