Skip to content

Commit fae2270

Browse files
committed
update README
1 parent 13ae393 commit fae2270

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

README.md

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Then in your code
1818
import { create, globals } from 'node-webgpu';
1919

2020
Object.assign(globalThis, globals);
21-
globalThis.navigator = { gpu: create([]) };
21+
const navigator = { gpu: create([]) };
2222

2323
...
2424

@@ -32,7 +32,7 @@ see [example](https://github.com/greggman/node-webgpu/tree/main/example)
3232
You can pass dawn options in `create`
3333

3434
```js
35-
globalThis.navigator = {
35+
const navigator = {
3636
gpu: create([
3737
"enable-dawn-features=allow_unsafe_apis,dump_shaders,disable_symbol_renaming",
3838
]),
@@ -45,8 +45,29 @@ The available options are listed [here](https://dawn.googlesource.com/dawn/+/ref
4545

4646
## Notes
4747

48+
### Lifetime
49+
50+
The `dawn.node` implementation exists as long as the `navigator` variable
51+
in the examples is in scope, or rather, as long as there is a reference to
52+
the object returned by `create`. As such, if you assign it to a global
53+
variable like this
54+
55+
```js
56+
globalThis.navigator = { gpu: create([]) };
57+
```
58+
59+
node will not exit because it's still running GPU code in the background.
60+
You can fix that by removing the reference.
61+
62+
```js
63+
delete globalThis.navigator
64+
```
65+
66+
See: https://issues.chromium.org/issues/387965810
67+
68+
### What to use this for
4869
This package provides a WebGPU implementation it node. That said, if you are making a webpage
49-
and are considering using this for testing, you'd probably be better off using puppeteer. You can
70+
and are considering using this for testing, you'd probably be better off using [puppeteer](https://pptr.dev/). You can
5071
find an example of using puppeteer for testing WebGPU in [this repo](https://github.com/greggman/webgpu-debug-helper).
5172

5273
This package is for WebGPU in node. It provides WebGPU in node. But, it does not not provide integration
@@ -58,9 +79,13 @@ I suspect you could provide many of those with polyfills without changing this r
5879
looked into it.
5980

6081
What you can do is render to textures and then read them back. You can also run compute shaders
61-
and read their results.
82+
and read their results. See the example linked above.
83+
84+
## Bugs / Issue
6285

63-
## Bugs
86+
This repo just publishes `dawn.node` from the dawn project [here](https://dawn.googlesource.com/dawn/+/refs/heads/main/src/dawn/node/).
87+
Bugs related to dawn, WebGPU should be filed in the in the
88+
[chromium issue tracker](https://crbug.com/dawn)
6489

6590
## Updating
6691

example/example.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { PNG } from 'pngjs';
33
import { create, globals } from 'node-webgpu';
44

55
Object.assign(globalThis, globals);
6-
globalThis.navigator = { gpu: create([]) };
6+
const navigator = { gpu: create([]) };
77

88
const adapter = await navigator.gpu?.requestAdapter();
99
const device = await adapter?.requestDevice();
@@ -89,4 +89,4 @@ for (let y = 0; y < texture.height; y++) {
8989
// Write the PNG to a file
9090
fs.writeFileSync('output.png', PNG.sync.write(png, {colorType: 6}));
9191
console.log('PNG file has been saved as output.png');
92-
process.exit(0);
92+

test/test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ mocha.addFile('./test/tests/basic-tests.js');
1111

1212
await mocha.loadFilesAsync();
1313
mocha.run(failures => {
14+
delete globalThis.navigator;
1415
process.exit(failures);
1516
});

0 commit comments

Comments
 (0)