-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebGPU: Add a preinitializedWebGPUAdapter and emscripten_get_webgpu_adapter() #21073
Comments
I was actually hoping to remove preinitializedWebGPUDevice once we have:
Though maybe you can evaluate whether this would work for whatever code you're looking at that currently uses preinitializedWebGPUDevice? |
futures-based initialization would work except it has the usual problems of WASM apps that don't want to build with ASYNCIFY, and aren't structured to yield to the event loop. Both of those are true in the code I was looking at. JsValStore works, except for the fact we don't define I'm not sure if emscripten_webgpu_import/export* are really all that useful though because it's generally easier to just use WebGPU.mgrAdapter directly. Maybe the WebGPU.mgr* are not supposed to be exposed though..? Consider: EM_JS(int, get_adapter, (), {
return JsValStore.add(myGlobalObject.propertyWhereISavedTheAdapter);
});
int adapter_handle = get_adapter();
wgpu::Adapter adapter = wgpu::Adapter::Acquire(emscripten_webgpu_import_adapter(adapter_handle));
emscripten_webgpu_release_js_handle(adapter_handle); vs. EM_JS(int, get_adapter, (), {
return WebGPU.mgrAdapter.create(myGlobalObject.propertyWhereISavedTheAdapter);
});
wgpu::Adapter adapter = wgpu::Adapter::Acquire(reinterpret_cast<WGPUAdapter>(get_adapter())); |
WebGPU.mgr* is almost certainly going to change (soon) when we put objects in WASM tables to use with externref. I'm wondering if we can replace JsValStore with a stable API to directly access those tables but I'm not sure exactly what this would look like yet. For EM_JS/EM_ASM I think we can do better somehow with externref, like for example having a wgpu::Adapter overload taking an externref directly (though this would be type unsafe): externref_t jsAdapter = EM_ASM_EXTERNREF({
return myGlobalObject.propertyWhereISavedTheAdapter;
});
wgpu::Adapter adapter{jsAdapter}; // constructor stores the adapter into the table TBD though as this is going to require a lot more externref support than Emscripten currently has (which is none). |
Currently, WebGPU applications can set Module['preinitializedWebGPUDevice'] and use emscripten_get_webgpu_device().
This makes it convenient to get the device into your C++ application, without needing any async in C++.
It would be nice to likewise add
preinitializedWebGPUAdapter
andemscripten_get_webgpu_adapter()
so that applications can easily get the WGPUAdapter and query adapter properties in C++. Otherwise, this information needs to be queried in Javascript and passed into C++ separately.(#21072 is about actually filling those adapter properties with useful information)
@kainino0x
The text was updated successfully, but these errors were encountered: