Skip to content
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

wgpu calls createBuffer on an undefined from a worker thread on Wasm #2884

Closed
Tracked by #3674
ghost opened this issue Jul 14, 2022 · 2 comments · Fixed by #3691
Closed
Tracked by #3674

wgpu calls createBuffer on an undefined from a worker thread on Wasm #2884

ghost opened this issue Jul 14, 2022 · 2 comments · Fixed by #3691
Labels
api: webgpu Issues with direct interface with WebGPU type: bug Something isn't working

Comments

@ghost
Copy link

ghost commented Jul 14, 2022

Description
wgpu attempts to execute the createBuffer method on an undefined when running in a worker thread on the target wasm32-unknown-unknown. The instance, adapter, surface, and device were created on the main thread.

Repro steps
A runnable example is here, the source code for which is here; see wasm.rs and core/src/lib.rs. More generic instructions are described below.

  1. Create a new Rust crate targeting wasm32-unknown-unknown.
  2. Export a main function using #[wasm_bindgen].
  3. In main, create a wgpu instance, adapter, device, and surface.
  4. Create a new thread (e.g., using wasm_thread) in which a vertex buffer is created and initialized with the device returned by wgpu.
  5. Observe the error.

Expected vs observed behavior
I expect the vertex buffer creation to be successful, after which render passes would occur, the command queue would be submitted, and the surface frame would ultimately be presented.

Instead, I observe that attempting to create the vertex buffer from a worker thread crashes the Wasm process.

Extra materials
On Microsoft Edge (Chromium-based), I receive the following error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'createBuffer')

On Firefox, I receive the following error:
TypeError: can't access property "createBuffer", getObject(...) is undefined

Platform
Windows 11. wgpu 0.13 (latest minor release). naga 0.9.

@ghost ghost changed the title *wgpu* calls createBuffer on an undefined from a worker thread on Wasm wgpu calls createBuffer on an undefined from a worker thread on Wasm Jul 15, 2022
@codeart1st
Copy link

codeart1st commented Oct 30, 2022

I also run into this issue.

// Send nor Sync. Currently, wasm32 has no threading support so implementing `Send` or `Sync` for a

GPUDevice can be send via postMessage in Javascript, but in rust with wgpu this seems to be not solveable at the moment.

@teoxoy teoxoy added type: bug Something isn't working api: webgpu Issues with direct interface with WebGPU labels Feb 23, 2023
@teoxoy
Copy link
Member

teoxoy commented Feb 23, 2023

Related: #2652 (talks about the GLES backend but the same ideas should apply here too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: webgpu Issues with direct interface with WebGPU type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants