dawn/node: Work around NodeJS brokenness with printing long strings.
Attempting to print a long string can cause output to go missing. Split long strings up into 4k chunks. Change-Id: Ibcb07459bd8fb4a1a11b6f8db41c8378274a6d09 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95940 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
af13cc714b
commit
1604ae5b97
|
@ -41,6 +41,53 @@ namespace wgpu::binding {
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Returns a string representation of the WGPULoggingType
|
||||||
|
const char* str(WGPULoggingType ty) {
|
||||||
|
switch (ty) {
|
||||||
|
case WGPULoggingType_Verbose:
|
||||||
|
return "verbose";
|
||||||
|
case WGPULoggingType_Info:
|
||||||
|
return "info";
|
||||||
|
case WGPULoggingType_Warning:
|
||||||
|
return "warning";
|
||||||
|
case WGPULoggingType_Error:
|
||||||
|
return "error";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a string representation of the WGPUErrorType
|
||||||
|
const char* str(WGPUErrorType ty) {
|
||||||
|
switch (ty) {
|
||||||
|
case WGPUErrorType_NoError:
|
||||||
|
return "no error";
|
||||||
|
case WGPUErrorType_Validation:
|
||||||
|
return "validation";
|
||||||
|
case WGPUErrorType_OutOfMemory:
|
||||||
|
return "out of memory";
|
||||||
|
case WGPUErrorType_Unknown:
|
||||||
|
return "unknown";
|
||||||
|
case WGPUErrorType_DeviceLost:
|
||||||
|
return "device lost";
|
||||||
|
default:
|
||||||
|
return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// There's something broken with Node when attempting to write more than 65536 bytes to cout.
|
||||||
|
// Split the string up into writes of 4k chunks .
|
||||||
|
// Likely related: https://github.com/nodejs/node/issues/12921
|
||||||
|
void chunkedWrite(const char* msg) {
|
||||||
|
while (true) {
|
||||||
|
auto n = printf("%.4096s", msg);
|
||||||
|
if (n == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
msg += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class DeviceLostInfo : public interop::GPUDeviceLostInfo {
|
class DeviceLostInfo : public interop::GPUDeviceLostInfo {
|
||||||
public:
|
public:
|
||||||
DeviceLostInfo(interop::GPUDeviceLostReason reason, std::string message)
|
DeviceLostInfo(interop::GPUDeviceLostReason reason, std::string message)
|
||||||
|
@ -88,12 +135,14 @@ GPUDevice::GPUDevice(Napi::Env env, wgpu::Device device)
|
||||||
lost_promise_(env, PROMISE_INFO) {
|
lost_promise_(env, PROMISE_INFO) {
|
||||||
device_.SetLoggingCallback(
|
device_.SetLoggingCallback(
|
||||||
[](WGPULoggingType type, char const* message, void* userdata) {
|
[](WGPULoggingType type, char const* message, void* userdata) {
|
||||||
std::cout << type << ": " << message << std::endl;
|
printf("%s:\n", str(type));
|
||||||
|
chunkedWrite(message);
|
||||||
},
|
},
|
||||||
nullptr);
|
nullptr);
|
||||||
device_.SetUncapturedErrorCallback(
|
device_.SetUncapturedErrorCallback(
|
||||||
[](WGPUErrorType type, char const* message, void* userdata) {
|
[](WGPUErrorType type, char const* message, void* userdata) {
|
||||||
std::cout << type << ": " << message << std::endl;
|
printf("%s:\n", str(type));
|
||||||
|
chunkedWrite(message);
|
||||||
},
|
},
|
||||||
nullptr);
|
nullptr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue