Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Jan 6, 2025
1 parent 13ae393 commit fae2270
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
35 changes: 30 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Then in your code
import { create, globals } from 'node-webgpu';

Object.assign(globalThis, globals);
globalThis.navigator = { gpu: create([]) };
const navigator = { gpu: create([]) };

...

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

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

## Notes

### Lifetime

The `dawn.node` implementation exists as long as the `navigator` variable
in the examples is in scope, or rather, as long as there is a reference to
the object returned by `create`. As such, if you assign it to a global
variable like this

```js
globalThis.navigator = { gpu: create([]) };
```

node will not exit because it's still running GPU code in the background.
You can fix that by removing the reference.

```js
delete globalThis.navigator
```

See: https://issues.chromium.org/issues/387965810

### What to use this for
This package provides a WebGPU implementation it node. That said, if you are making a webpage
and are considering using this for testing, you'd probably be better off using puppeteer. You can
and are considering using this for testing, you'd probably be better off using [puppeteer](https://pptr.dev/). You can
find an example of using puppeteer for testing WebGPU in [this repo](https://github.com/greggman/webgpu-debug-helper).

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

What you can do is render to textures and then read them back. You can also run compute shaders
and read their results.
and read their results. See the example linked above.

## Bugs / Issue

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

## Updating

Expand Down
4 changes: 2 additions & 2 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PNG } from 'pngjs';
import { create, globals } from 'node-webgpu';

Object.assign(globalThis, globals);
globalThis.navigator = { gpu: create([]) };
const navigator = { gpu: create([]) };

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

1 change: 1 addition & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ mocha.addFile('./test/tests/basic-tests.js');

await mocha.loadFilesAsync();
mocha.run(failures => {
delete globalThis.navigator;
process.exit(failures);
});

0 comments on commit fae2270

Please sign in to comment.