From f0839adbbda7b6f42a914d13a6b4f83c4e1f92dd Mon Sep 17 00:00:00 2001 From: "Yan,Shaobo" Date: Mon, 4 Mar 2024 16:46:02 +0800 Subject: [PATCH 1/2] Fix Getting WebGPU Context in pthread Failed to run compiled WGPU code clips: wgpu::SurfaceDescriptor surfDesc{}; surfDesc.nextInChain = &canvasDesc; wgpu::Surface surface = instance.CreateSurface(&surfDesc); The reason is that it cannot call getContext from correct canvas object. This PR fixed the problem and add correct build flags for webgpu_basic_rendering test in pthread. --- src/library_webgpu.js | 3 +++ test/test_browser.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/library_webgpu.js b/src/library_webgpu.js index 7cd4884c77df..aa732e35d8a9 100644 --- a/src/library_webgpu.js +++ b/src/library_webgpu.js @@ -2434,6 +2434,9 @@ var LibraryWebGPU = { var selectorPtr = {{{ makeGetValue('descriptorFromCanvasHTMLSelector', C_STRUCTS.WGPUSurfaceDescriptorFromCanvasHTMLSelector.selector, '*') }}}; {{{ gpu.makeCheck('selectorPtr') }}} var canvas = findCanvasEventTarget(selectorPtr); +#if OFFSCREENCANVAS_SUPPORT + if (canvas.offscreenCanvas) canvas = canvas.offscreenCanvas; +#endif var context = canvas.getContext('webgpu'); #if ASSERTIONS assert(context); diff --git a/test/test_browser.py b/test/test_browser.py index 2bd8adb6a711..7e7b592218ce 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4790,14 +4790,14 @@ def test_webgpu_basic_rendering(self, args): @requires_graphics_hardware @requires_threads def test_webgpu_basic_rendering_pthreads(self): - self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU', '-pthread', '-sPROXY_TO_PTHREAD']) + self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU', '-pthread', '-sOFFSCREENCANVAS_SUPPORT']) def test_webgpu_get_device(self): self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-sASSERTIONS', '--closure=1']) @requires_threads def test_webgpu_get_device_pthreads(self): - self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-pthread', '-sPROXY_TO_PTHREAD']) + self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-pthread']) # Tests the feature that shell html page can preallocate the typed array and place it # to Module.buffer before loading the script page. From f89563cd9a554daae636162ba2b57feb1726f0a0 Mon Sep 17 00:00:00 2001 From: Kai Ninomiya Date: Mon, 4 Mar 2024 17:39:39 -0800 Subject: [PATCH 2/2] Add TODOs --- test/test_browser.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_browser.py b/test/test_browser.py index d0dfabfca968..7962199f7699 100644 --- a/test/test_browser.py +++ b/test/test_browser.py @@ -4689,6 +4689,7 @@ def test_webgl_simple_extensions(self, simple_enable_extensions, webgl_version): def test_webgpu_basic_rendering(self, args): self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU'] + args) + # TODO(#19645): Extend this test to proxied WebGPU when it's re-enabled. @requires_graphics_hardware @requires_threads def test_webgpu_basic_rendering_pthreads(self): @@ -4697,6 +4698,7 @@ def test_webgpu_basic_rendering_pthreads(self): def test_webgpu_get_device(self): self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-sASSERTIONS', '--closure=1']) + # TODO(#19645): Extend this test to proxied WebGPU when it's re-enabled. @requires_threads def test_webgpu_get_device_pthreads(self): self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-pthread'])