diff --git a/src/library_html5.js b/src/library_html5.js
index 8ddee1757bd11..8efccf627165f 100644
--- a/src/library_html5.js
+++ b/src/library_html5.js
@@ -2598,6 +2598,16 @@ var LibraryJSEvents = {
WebGPU.initManagers();
return WebGPU.mgrDevice.create(Module['preinitializedWebGPUDevice']);
},
+
+ emscripten_webgpu_get_current_texture__sig: 'i',
+ emscripten_webgpu_get_current_texture: 'emscripten_webgpu_do_get_current_texture',
+ emscripten_webgpu_do_get_current_texture__deps: ['$WebGPU'],
+ emscripten_webgpu_do_get_current_texture: function() {
+ var swapchain = Module['preinitializedWebGPUSwapChain'];
+ assert(swapchain);
+ WebGPU.initManagers();
+ return WebGPU.mgrTexture.create(swapchain.getCurrentTexture());
+ },
#endif
#if USE_PTHREADS
diff --git a/src/library_webgpu.js b/src/library_webgpu.js
index 0c75f897ec7e6..6e414ec1d8982 100644
--- a/src/library_webgpu.js
+++ b/src/library_webgpu.js
@@ -49,6 +49,8 @@
var LibraryWebGPU = {
$WebGPU: {
initManagers: function() {
+ if (this.mgrDevice) return;
+
function makeManager() {
return {
objects: [undefined],
diff --git a/system/include/emscripten/html5.h b/system/include/emscripten/html5.h
index eba051dd9d841..8dbdd120189b2 100644
--- a/system/include/emscripten/html5.h
+++ b/system/include/emscripten/html5.h
@@ -504,7 +504,9 @@ extern void *emscripten_webgl2_get_proc_address(const char *name);
extern void *emscripten_webgl_get_proc_address(const char *name);
typedef struct DawnDeviceImpl* DawnDevice;
+typedef struct DawnTextureImpl* DawnTexture;
extern DawnDevice emscripten_webgpu_get_device();
+extern DawnTexture emscripten_webgpu_get_current_texture();
extern EMSCRIPTEN_RESULT emscripten_set_canvas_element_size(const char *target, int width, int height);
extern EMSCRIPTEN_RESULT emscripten_get_canvas_element_size(const char *target, int *width, int *height);