Add the user-visible logging interface.

Details:
- Add the logging level type WGPULoggingType, including levels verbose,
info, warning, and error,
- Add the API SetLoggingCallback, which bind the callback to deal with
logging string,
- Add the return command DeviceLoggingCallback and related code,
- Add DeviceBase::EmitLog(WGPULoggingType, const char*) , and
DeviceBase::EmitLog(const char*) use WGPULoggingType_info as default,
to post logging from native or server device to bound callback
via CallbackTaskManager.

BUG: dawn:792
Change-Id: I107b9134ff8567a46fa452509799e10b6862b8d3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/52200
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com>
This commit is contained in:
Zhaoming Jiang
2021-06-04 07:10:56 +00:00
committed by Dawn LUCI CQ
parent 9d911d4957
commit b44000e7af
16 changed files with 221 additions and 16 deletions

View File

@@ -33,10 +33,25 @@ namespace dawn_wire { namespace client {
default:
return false;
}
if (device == nullptr) {
// The device might have been deleted or recreated so this isn't an error.
return true;
}
device->HandleError(errorType, message);
return true;
}
bool Client::DoDeviceLoggingCallback(Device* device,
WGPULoggingType loggingType,
const char* message) {
if (device == nullptr) {
// The device might have been deleted or recreated so this isn't an error.
return true;
}
device->HandleLogging(loggingType, message);
return true;
}
bool Client::DoDeviceLostCallback(Device* device, char const* message) {
if (device == nullptr) {
// The device might have been deleted or recreated so this isn't an error.

View File

@@ -76,6 +76,13 @@ namespace dawn_wire { namespace client {
}
}
void Device::HandleLogging(WGPULoggingType loggingType, const char* message) {
if (mLoggingCallback) {
// Since client always run in single thread, calling the callback directly is safe.
mLoggingCallback(loggingType, message, mLoggingUserdata);
}
}
void Device::HandleDeviceLost(const char* message) {
if (mDeviceLostCallback && !mDidRunLostCallback) {
mDidRunLostCallback = true;
@@ -114,6 +121,11 @@ namespace dawn_wire { namespace client {
mErrorUserdata = errorUserdata;
}
void Device::SetLoggingCallback(WGPULoggingCallback callback, void* userdata) {
mLoggingCallback = callback;
mLoggingUserdata = userdata;
}
void Device::SetDeviceLostCallback(WGPUDeviceLostCallback callback, void* userdata) {
mDeviceLostCallback = callback;
mDeviceLostUserdata = userdata;

View File

@@ -36,6 +36,7 @@ namespace dawn_wire { namespace client {
~Device();
void SetUncapturedErrorCallback(WGPUErrorCallback errorCallback, void* errorUserdata);
void SetLoggingCallback(WGPULoggingCallback errorCallback, void* errorUserdata);
void SetDeviceLostCallback(WGPUDeviceLostCallback errorCallback, void* errorUserdata);
void InjectError(WGPUErrorType type, const char* message);
void PushErrorScope(WGPUErrorFilter filter);
@@ -50,6 +51,7 @@ namespace dawn_wire { namespace client {
void* userdata);
void HandleError(WGPUErrorType errorType, const char* message);
void HandleLogging(WGPULoggingType loggingType, const char* message);
void HandleDeviceLost(const char* message);
bool OnPopErrorScopeCallback(uint64_t requestSerial,
WGPUErrorType type,
@@ -89,9 +91,11 @@ namespace dawn_wire { namespace client {
WGPUErrorCallback mErrorCallback = nullptr;
WGPUDeviceLostCallback mDeviceLostCallback = nullptr;
WGPULoggingCallback mLoggingCallback = nullptr;
bool mDidRunLostCallback = false;
void* mErrorUserdata = nullptr;
void* mDeviceLostUserdata = nullptr;
void* mLoggingUserdata = nullptr;
Queue* mQueue = nullptr;

View File

@@ -133,6 +133,15 @@ namespace dawn_wire { namespace server {
info->server->OnUncapturedError(info->self, type, message);
},
data->info.get());
// Set callback to post warning and other infomation to client.
// Almost the same with UncapturedError.
mProcs.deviceSetLoggingCallback(
device,
[](WGPULoggingType type, const char* message, void* userdata) {
DeviceInfo* info = static_cast<DeviceInfo*>(userdata);
info->server->OnLogging(info->self, type, message);
},
data->info.get());
mProcs.deviceSetDeviceLostCallback(
device,
[](const char* message, void* userdata) {
@@ -156,6 +165,7 @@ namespace dawn_wire { namespace server {
// Un-set the error and lost callbacks since we cannot forward them
// after the server has been destroyed.
mProcs.deviceSetUncapturedErrorCallback(device, nullptr, nullptr);
mProcs.deviceSetLoggingCallback(device, nullptr, nullptr);
mProcs.deviceSetDeviceLostCallback(device, nullptr, nullptr);
}

View File

@@ -200,6 +200,7 @@ namespace dawn_wire { namespace server {
// Error callbacks
void OnUncapturedError(ObjectHandle device, WGPUErrorType type, const char* message);
void OnDeviceLost(ObjectHandle device, const char* message);
void OnLogging(ObjectHandle device, WGPULoggingType type, const char* message);
void OnDevicePopErrorScope(WGPUErrorType type,
const char* message,
ErrorScopeUserdata* userdata);

View File

@@ -67,6 +67,15 @@ namespace dawn_wire { namespace server {
SerializeCommand(cmd);
}
void Server::OnLogging(ObjectHandle device, WGPULoggingType type, const char* message) {
ReturnDeviceLoggingCallbackCmd cmd;
cmd.device = device;
cmd.type = type;
cmd.message = message;
SerializeCommand(cmd);
}
bool Server::DoDevicePopErrorScope(ObjectId deviceId, uint64_t requestSerial) {
auto* device = DeviceObjects().Get(deviceId);
if (device == nullptr) {