Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/src/lib/libhtml5_webgpu.js
4150 views
1
{{{
2
// Helper functions for code generation
3
const html5_gpu = {
4
makeImportExport: (snake_case, CamelCase) => {
5
return `
6
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
7
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case} = (handle) =>
8
WebGPU.mgr${CamelCase}.create(JsValStore.get(handle));
9
10
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
11
LibraryHTML5WebGPU.emscripten_webgpu_export_${snake_case} = (handle) =>
12
JsValStore.add(WebGPU.mgr${CamelCase}.get(handle));`
13
},
14
};
15
}}}
16
17
18
var LibraryHTML5WebGPU = {
19
$JsValStore: {
20
values: {},
21
next_id: 1,
22
23
add(js_val) {
24
var id;
25
do {
26
id = JsValStore.next_id++;
27
if (JsValStore.next_id > 2147483647) JsValStore.next_id = 1; // Wraparound signed int32.
28
} while (id in JsValStore.values);
29
30
JsValStore.values[id] = js_val;
31
return id;
32
},
33
remove(id) {
34
#if ASSERTIONS
35
assert(id in JsValStore.values);
36
#endif
37
delete JsValStore.values[id];
38
},
39
get(id) {
40
#if ASSERTIONS
41
assert(id === 0 || id in JsValStore.values);
42
#endif
43
return JsValStore.values[id];
44
},
45
},
46
47
emscripten_webgpu_release_js_handle__deps: ['$JsValStore'],
48
emscripten_webgpu_release_js_handle: (id) => JsValStore.remove(id),
49
50
emscripten_webgpu_get_device__deps: ['$WebGPU'],
51
emscripten_webgpu_get_device: () => {
52
#if ASSERTIONS
53
assert(Module['preinitializedWebGPUDevice']);
54
#endif
55
if (WebGPU.preinitializedDeviceId === undefined) {
56
var device = Module['preinitializedWebGPUDevice'];
57
var deviceWrapper = { queueId: WebGPU.mgrQueue.create(device["queue"]) };
58
WebGPU.preinitializedDeviceId = WebGPU.mgrDevice.create(device, deviceWrapper);
59
}
60
WebGPU.mgrDevice.reference(WebGPU.preinitializedDeviceId);
61
return WebGPU.preinitializedDeviceId;
62
},
63
};
64
65
{{{ html5_gpu.makeImportExport('surface', 'Surface') }}}
66
{{{ html5_gpu.makeImportExport('swap_chain', 'SwapChain') }}}
67
68
{{{ html5_gpu.makeImportExport('device', 'Device') }}}
69
{{{ html5_gpu.makeImportExport('queue', 'Queue') }}}
70
71
{{{ html5_gpu.makeImportExport('command_buffer', 'CommandBuffer') }}}
72
{{{ html5_gpu.makeImportExport('command_encoder', 'CommandEncoder') }}}
73
{{{ html5_gpu.makeImportExport('render_pass_encoder', 'RenderPassEncoder') }}}
74
{{{ html5_gpu.makeImportExport('compute_pass_encoder', 'ComputePassEncoder') }}}
75
76
{{{ html5_gpu.makeImportExport('bind_group', 'BindGroup') }}}
77
{{{ html5_gpu.makeImportExport('buffer', 'Buffer') }}}
78
{{{ html5_gpu.makeImportExport('sampler', 'Sampler') }}}
79
{{{ html5_gpu.makeImportExport('texture', 'Texture') }}}
80
{{{ html5_gpu.makeImportExport('texture_view', 'TextureView') }}}
81
{{{ html5_gpu.makeImportExport('query_set', 'QuerySet') }}}
82
83
{{{ html5_gpu.makeImportExport('bind_group_layout', 'BindGroupLayout') }}}
84
{{{ html5_gpu.makeImportExport('pipeline_layout', 'PipelineLayout') }}}
85
{{{ html5_gpu.makeImportExport('render_pipeline', 'RenderPipeline') }}}
86
{{{ html5_gpu.makeImportExport('compute_pipeline', 'ComputePipeline') }}}
87
{{{ html5_gpu.makeImportExport('shader_module', 'ShaderModule') }}}
88
89
{{{ html5_gpu.makeImportExport('render_bundle_encoder', 'RenderBundleEncoder') }}}
90
{{{ html5_gpu.makeImportExport('render_bundle', 'RenderBundle') }}}
91
92
addToLibrary(LibraryHTML5WebGPU);
93
94