Multithreading support status in wgpu #4814
-
I'm planning to use wgpu-native from C++, and I'm thinking of using multithreaded rendering (generating command buffers, etc), but I don't understand if this is possible with wgpu. The WebGPU specification doesn't talk about threads, but instead specifies timelines, which I'm failing to match with CPU-side threads in the case of wgpu. The wgpu docs don't mention anything about which objects and methods are safe to call from different threads and which aren't. The only mention I've found is in the documentation of the Device, saying
which hints that multithreaded rendering is possible with wgpu. Note that Rust isn't my primary language and I might have somehow completely missed the relevant thread safety info in the docs. Googling "wgpu multithreading" I've found this article which, again, hints that nultithreading is supported by wgpu. My question is: is multithreaded usage supported by wgpu, and if it is, is the exact multi-threaded behavior (which methods/objects are thread-safe, etc) documented somewhere? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
General rule of thumb: if the method takes What this means is, all wgpu types may be used across threads, except command encoders and renderpass encoders. These must be guarded by a mutex if you were to use the same encoder on multiple threads at the same time. You can however use multiple command encoders from different threads. This is actually getting standardized as part of webgpu.h standardization. |
Beta Was this translation helpful? Give feedback.
General rule of thumb: if the method takes
&mut self
in rust, it must not be called at the same time as any other methods on the type. If it takes&self
, it may be called at the same time as any other&self
method.What this means is, all wgpu types may be used across threads, except command encoders and renderpass encoders. These must be guarded by a mutex if you were to use the same encoder on multiple threads at the same time. You can however use multiple command encoders from different threads.
This is actually getting standardized as part of webgpu.h standardization.