Skip to content

Commit

Permalink
WebGPU: consolidate all object tables, move some impl to "layered" we…
Browse files Browse the repository at this point in the history
…bgpu.cpp

I'm planning to move more implementation code into webgpu.cpp over time.
For example, if we move the refcounts there, then they can be accessed
from multiple threads.

There are modest code size improvements from this change, though I
haven't analyzed which changes had the most impact. I'll try that for
later changes. Comparing by building with -O3 --closure=1 with this
project: https://github.com/kainino0x/webgpu-cross-platform-demo

- Before:
  hello.js:   29241 bytes / 11414 gzipped
  hello.wasm: 20858 bytes /  9563 gzipped
  total:      50099 bytes / 20997 gzipped
- After:
  hello.js:   27883 bytes / 10944 gzipped
  hello.wasm: 20545 bytes /  9373 gzipped
  total:      48428 bytes / 20317 gzipped

I suspect the .wasm code size reduction is due to inlining of Reference
and Release calls that now all go to the same function.
  • Loading branch information
kainino0x committed Dec 6, 2023
1 parent 38ab7c1 commit 210c3fe
Show file tree
Hide file tree
Showing 5 changed files with 381 additions and 401 deletions.
1 change: 0 additions & 1 deletion embuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
'libnoexit',
'sqlite3',
'sqlite3-mt',
'libwebgpu_cpp',
]

# Additional tasks on top of MINIMAL_TASKS that are necessary for PIC testing on
Expand Down
12 changes: 6 additions & 6 deletions src/library_html5_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
return `
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case} = (handle) =>
WebGPU.mgr${CamelCase}.create(JsValStore.get(handle));
WebGPU._tableInsert(JsValStore.get(handle));
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case} = (handle) =>
JsValStore.add(WebGPU.mgr${CamelCase}.get(handle));`
JsValStore.add(WebGPU._tableGet(handle));`
},
};
null;
Expand Down Expand Up @@ -48,17 +48,17 @@ var LibraryHTML5WebGPU = {
emscripten_webgpu_release_js_handle__deps: ['$JsValStore'],
emscripten_webgpu_release_js_handle: (id) => JsValStore.remove(id),

emscripten_webgpu_get_device__deps: ['$WebGPU'],
emscripten_webgpu_get_device__deps: ['$WebGPU', 'emwgpuAddRef'],
emscripten_webgpu_get_device: () => {
#if ASSERTIONS
assert(Module['preinitializedWebGPUDevice']);
#endif
if (WebGPU.preinitializedDeviceId === undefined) {
var device = Module['preinitializedWebGPUDevice'];
var deviceWrapper = { queueId: WebGPU.mgrQueue.create(device["queue"]) };
WebGPU.preinitializedDeviceId = WebGPU.mgrDevice.create(device, deviceWrapper);
var deviceWrapper = { queueId: WebGPU._tableInsert(device["queue"]) };
WebGPU.preinitializedDeviceId = WebGPU._tableInsert(device, deviceWrapper);
}
WebGPU.mgrDevice.reference(WebGPU.preinitializedDeviceId);
_emwgpuAddRef(WebGPU.preinitializedDeviceId);
return WebGPU.preinitializedDeviceId;
},
};
Expand Down
Loading

0 comments on commit 210c3fe

Please sign in to comment.