Skip to content

Commit

Permalink
[dawn][emscripten] Updates html5 bindings that were missed before.
Browse files Browse the repository at this point in the history
- When I first landed
  https://dawn-review.googlesource.com/c/dawn/+/201758, I forgot
  to update the HTML5 library bindings. This change just catches
  those bindings up.

Change-Id: I99a851df30115e253d32fc110f833f0541b584cc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/203059
Reviewed-by: Austin Eng <[email protected]>
Reviewed-by: Shrek Shao <[email protected]>
Commit-Queue: Loko Kung <[email protected]>
  • Loading branch information
lokokung authored and Dawn LUCI CQ committed Aug 20, 2024
1 parent 03d6a43 commit bc3246b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 31 deletions.
59 changes: 29 additions & 30 deletions third_party/emdawnwebgpu/library_html5_webgpu.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{{{
// Helper functions for code generation
globalThis.html5_gpu = {
makeImportExport: (snake_case, CamelCase) => {
makeImportExport: (snake_case) => {
return `
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case} = (handle) =>
WebGPU.mgr${CamelCase}.create(JsValStore.get(handle));
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case} = (ptr) =>
WebGPU._tableInsert(JsValStore.get(ptr));
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case} = (handle) =>
JsValStore.add(WebGPU.mgr${CamelCase}.get(handle));`
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case} = (ptr) =>
JsValStore.add(WebGPU._tableGet(ptr));`
},
};
null;
Expand Down Expand Up @@ -48,46 +48,45 @@ 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', 'emwgpuTableInsertDevice', 'wgpuDeviceAddRef'],
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);
WebGPU.preinitializedDeviceId = _emwgpuTableInsertDevice(device);
}
WebGPU.mgrDevice.reference(WebGPU.preinitializedDeviceId);
_wgpuDeviceAddRef(WebGPU.preinitializedDeviceId);
return WebGPU.preinitializedDeviceId;
},
};

{{{ html5_gpu.makeImportExport('surface', 'Surface') }}}
{{{ html5_gpu.makeImportExport('swap_chain', 'SwapChain') }}}
{{{ html5_gpu.makeImportExport('surface') }}}
{{{ html5_gpu.makeImportExport('swap_chain') }}}

{{{ html5_gpu.makeImportExport('device', 'Device') }}}
{{{ html5_gpu.makeImportExport('queue', 'Queue') }}}
{{{ html5_gpu.makeImportExport('device') }}}
{{{ html5_gpu.makeImportExport('queue') }}}

{{{ html5_gpu.makeImportExport('command_buffer', 'CommandBuffer') }}}
{{{ html5_gpu.makeImportExport('command_encoder', 'CommandEncoder') }}}
{{{ html5_gpu.makeImportExport('render_pass_encoder', 'RenderPassEncoder') }}}
{{{ html5_gpu.makeImportExport('compute_pass_encoder', 'ComputePassEncoder') }}}
{{{ html5_gpu.makeImportExport('command_buffer') }}}
{{{ html5_gpu.makeImportExport('command_encoder') }}}
{{{ html5_gpu.makeImportExport('render_pass_encoder') }}}
{{{ html5_gpu.makeImportExport('compute_pass_encoder') }}}

{{{ html5_gpu.makeImportExport('bind_group', 'BindGroup') }}}
{{{ html5_gpu.makeImportExport('buffer', 'Buffer') }}}
{{{ html5_gpu.makeImportExport('sampler', 'Sampler') }}}
{{{ html5_gpu.makeImportExport('texture', 'Texture') }}}
{{{ html5_gpu.makeImportExport('texture_view', 'TextureView') }}}
{{{ html5_gpu.makeImportExport('query_set', 'QuerySet') }}}
{{{ html5_gpu.makeImportExport('bind_group') }}}
{{{ html5_gpu.makeImportExport('buffer') }}}
{{{ html5_gpu.makeImportExport('sampler') }}}
{{{ html5_gpu.makeImportExport('texture') }}}
{{{ html5_gpu.makeImportExport('texture_view') }}}
{{{ html5_gpu.makeImportExport('query_set') }}}

{{{ html5_gpu.makeImportExport('bind_group_layout', 'BindGroupLayout') }}}
{{{ html5_gpu.makeImportExport('pipeline_layout', 'PipelineLayout') }}}
{{{ html5_gpu.makeImportExport('render_pipeline', 'RenderPipeline') }}}
{{{ html5_gpu.makeImportExport('compute_pipeline', 'ComputePipeline') }}}
{{{ html5_gpu.makeImportExport('shader_module', 'ShaderModule') }}}
{{{ html5_gpu.makeImportExport('bind_group_layout') }}}
{{{ html5_gpu.makeImportExport('pipeline_layout') }}}
{{{ html5_gpu.makeImportExport('render_pipeline') }}}
{{{ html5_gpu.makeImportExport('compute_pipeline') }}}
{{{ html5_gpu.makeImportExport('shader_module') }}}

{{{ html5_gpu.makeImportExport('render_bundle_encoder', 'RenderBundleEncoder') }}}
{{{ html5_gpu.makeImportExport('render_bundle', 'RenderBundle') }}}
{{{ html5_gpu.makeImportExport('render_bundle_encoder') }}}
{{{ html5_gpu.makeImportExport('render_bundle') }}}

mergeInto(LibraryManager.library, LibraryHTML5WebGPU);
15 changes: 14 additions & 1 deletion third_party/emdawnwebgpu/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,26 @@ var LibraryWebGPU = {
},

// ----------------------------------------------------------------------------
// Definitions for standalone JS emwgpu functions (callable from webgpu.cpp)
// Definitions for standalone JS emwgpu functions (callable from webgpu.cpp and
// library_html5_html.js)
// ----------------------------------------------------------------------------

emwgpuDelete: (id) => {
delete WebGPU._table[id];
},

// Extra helper that allow for directly inserting Devices (and their
// corresponding Queue) that is called from the HTML5 library since there
// isn't access to the C++ in webgpu.cpp there.
emwgpuTableInsertDevice__deps: ['emwgpuCreateDevice', 'emwgpuCreateQueue'],
emwgpuTableInsertDevice: (device) => {
var queuePtr = _emwgpuCreateQueue();
WebGPU._tableInsert(queuePtr, device.queue);
var devicePtr = _emwgpuCreateDevice(queuePtr);
WebGPU._tableInsert(devicePtr, device);
return devicePtr;
},

#if ASYNCIFY
// Returns a FutureID that was resolved, or kNullFutureId if timed out.
emwgpuWaitAny__async: true,
Expand Down

0 comments on commit bc3246b

Please sign in to comment.