Skip to content

Commit 2a9af50

Browse files
authored
Fix Getting WebGPU Context in pthread (#21467)
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.
1 parent c8a1890 commit 2a9af50

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/library_webgpu.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,6 +2431,9 @@ var LibraryWebGPU = {
24312431
var selectorPtr = {{{ makeGetValue('descriptorFromCanvasHTMLSelector', C_STRUCTS.WGPUSurfaceDescriptorFromCanvasHTMLSelector.selector, '*') }}};
24322432
{{{ gpu.makeCheck('selectorPtr') }}}
24332433
var canvas = findCanvasEventTarget(selectorPtr);
2434+
#if OFFSCREENCANVAS_SUPPORT
2435+
if (canvas.offscreenCanvas) canvas = canvas.offscreenCanvas;
2436+
#endif
24342437
var context = canvas.getContext('webgpu');
24352438
#if ASSERTIONS
24362439
assert(context);

test/test_browser.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4689,17 +4689,19 @@ def test_webgl_simple_extensions(self, simple_enable_extensions, webgl_version):
46894689
def test_webgpu_basic_rendering(self, args):
46904690
self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU'] + args)
46914691

4692+
# TODO(#19645): Extend this test to proxied WebGPU when it's re-enabled.
46924693
@requires_graphics_hardware
46934694
@requires_threads
46944695
def test_webgpu_basic_rendering_pthreads(self):
4695-
self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU', '-pthread', '-sPROXY_TO_PTHREAD'])
4696+
self.btest_exit('webgpu_basic_rendering.cpp', args=['-sUSE_WEBGPU', '-pthread', '-sOFFSCREENCANVAS_SUPPORT'])
46964697

46974698
def test_webgpu_get_device(self):
46984699
self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-sASSERTIONS', '--closure=1'])
46994700

4701+
# TODO(#19645): Extend this test to proxied WebGPU when it's re-enabled.
47004702
@requires_threads
47014703
def test_webgpu_get_device_pthreads(self):
4702-
self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-pthread', '-sPROXY_TO_PTHREAD'])
4704+
self.btest_exit('webgpu_get_device.cpp', args=['-sUSE_WEBGPU', '-pthread'])
47034705

47044706
# Tests the feature that shell html page can preallocate the typed array and place it
47054707
# to Module.buffer before loading the script page.

0 commit comments

Comments
 (0)