Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
kmamal committed Dec 1, 2023
1 parent d401b43 commit 0b19689
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Dependencies](https://img.shields.io/librariesio/release/npm/@kmamal/gpu)](https://libraries.io/npm/@kmamal%2Fgpu)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

> BEWARE: The [WebGPU specification](https://gpuweb.github.io/gpuweb/) is still a work-in-progress and could change any time.
> WARNING: The [WebGPU specification](https://gpuweb.github.io/gpuweb/) is still a work-in-progress.
WebGPU for Node.js via [Google Dawn](https://dawn.googlesource.com/dawn/+/refs/heads/main/src/dawn/node/).
Allows you to use WebGPU without a browser.
Expand All @@ -14,4 +14,6 @@ It should work on Linux, Mac, and Windows. Prebuilt binaries are available for x

## Instructions

Check the [examples](https://github.com/kmamal/gpu/tree/master/examples) for how to use this package. You can use both [compute](https://github.com/kmamal/gpu/tree/master/examples/00-compute) and [render](https://github.com/kmamal/gpu/tree/master/examples/01-render) pipelines. For render pipelines, you can either render the result to a buffer and save it as an image, or you can use [@kmamal/sdl](https://github.com/kmamal/node-sdl#readme) to render directly to a window as in [this example](https://github.com/kmamal/gpu/tree/master/examples/02-window).
Check the [examples](https://github.com/kmamal/gpu/tree/master/examples) for how to use this package.
You can use both [compute](https://github.com/kmamal/gpu/tree/master/examples/00-compute) and [render](https://github.com/kmamal/gpu/tree/master/examples/01-render) pipelines.
For render pipelines, you can either render the result to a buffer and save it as an image, or you can use [@kmamal/sdl](https://github.com/kmamal/node-sdl#readme) to render directly to a window as in [this example](https://github.com/kmamal/gpu/tree/master/examples/02-window).
25 changes: 12 additions & 13 deletions dawn.patch
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ index e0fe9b77..2342910c 100644
"${PROJECT_SOURCE_DIR}"
"${NODE_ADDON_API_DIR}"
diff --git a/src/dawn/node/Module.cpp b/src/dawn/node/Module.cpp
index 1061c8b6..27a9702a 100644
index 1061c8b6..463df3e5 100644
--- a/src/dawn/node/Module.cpp
+++ b/src/dawn/node/Module.cpp
@@ -34,7 +34,11 @@
Expand Down Expand Up @@ -120,7 +120,7 @@ index 1061c8b6..27a9702a 100644

std::tuple<std::vector<std::string>> args;
auto res = wgpu::interop::FromJS(info, args);
@@ -70,7 +79,181 @@ Napi::Value CreateGPU(const Napi::CallbackInfo& info) {
@@ -70,7 +79,180 @@ Napi::Value CreateGPU(const Napi::CallbackInfo& info) {
}

// Construct a wgpu::interop::GPU interface, implemented by wgpu::bindings::GPU.
Expand All @@ -130,19 +130,19 @@ index 1061c8b6..27a9702a 100644
+ return wgpu::interop::GPU::Bind(env, std::move(gpu));
+}
+
+bool should_abort;
+std::string error;
+
+Napi::Value Refresh(const Napi::CallbackInfo& info) {
+ const Napi::Env& env = info.Env();
+ should_abort = false;
+ error = "";
+ procs.instanceProcessEvents(_instance);
+ return Napi::Boolean::New(env, should_abort);
+ return error.empty() ? env.Undefined() : Napi::String::New(env, error);
+}
+
+void DeviceErrorCallback(WGPUErrorType errorType, const char* message, void*) {
+ if (should_abort) { return; }
+ if (!error.empty()) { return; }
+
+ const char* errorTypeName = "";
+ std::string errorTypeName;
+ switch (errorType) {
+ case WGPUErrorType_Validation:
+ errorTypeName = "Validation";
Expand All @@ -159,19 +159,18 @@ index 1061c8b6..27a9702a 100644
+ default:
+ return;
+ }
+ std::cerr << "WebGPU unhandled error: " << errorTypeName << " error: " << message;
+
+ should_abort = true;
+ error = "WebGPU unhandled error: " + errorTypeName + " error: " + message;
+}
+
+void DeviceLostCallback(WGPUDeviceLostReason reason, const char* message, void*) {
+ if (should_abort) { return; }
+ if (!error.empty()) { return; }
+
+ std::cerr << "WebGPU Device lost: " << message;
+}
+
+void DeviceLogCallback(WGPULoggingType type, const char* message, void*) {
+ if (should_abort) { return; }
+ if (!error.empty()) { return; }
+
+ std::cerr << "WebGPU Device log: " << message;
+}
Expand Down Expand Up @@ -303,7 +302,7 @@ index 1061c8b6..27a9702a 100644
}

#ifdef DAWN_EMIT_COVERAGE
@@ -106,7 +289,8 @@ struct Coverage {
@@ -106,7 +288,8 @@ struct Coverage {
// object.
NAPI_MODULE_EXPORT Napi::Object Initialize(Napi::Env env, Napi::Object exports) {
// Set all the Dawn procedure function pointers.
Expand All @@ -313,7 +312,7 @@ index 1061c8b6..27a9702a 100644

// Register all the interop types
exports.Set(Napi::String::New(env, "globals"), wgpu::interop::Initialize(env));
@@ -114,6 +298,10 @@ NAPI_MODULE_EXPORT Napi::Object Initialize(Napi::Env env, Napi::Object exports)
@@ -114,6 +297,10 @@ NAPI_MODULE_EXPORT Napi::Object Initialize(Napi::Env env, Napi::Object exports)
// Export function that creates and returns the wgpu::interop::GPU interface
exports.Set(Napi::String::New(env, "create"), Napi::Function::New<CreateGPU>(env));

Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const {
} = require('../dist/dawn.node')

setInterval(() => {
const shouldAbort = _refresh()
if (shouldAbort) { process.exit(1) }
const error = _refresh()
if (error) { throw new Error(error) }
}, 100).unref()

module.exports = {
Expand Down

0 comments on commit 0b19689

Please sign in to comment.