Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joatin/wgpu_tokio
Async methods for wgpu using tokio runtime
https://github.com/joatin/wgpu_tokio
async-await rust tokio-rs wgpu
Last synced: about 6 hours ago
JSON representation
Async methods for wgpu using tokio runtime
- Host: GitHub
- URL: https://github.com/joatin/wgpu_tokio
- Owner: Joatin
- License: mit
- Created: 2022-03-11T10:43:27.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-03T22:11:40.000Z (almost 2 years ago)
- Last Synced: 2024-04-17T10:55:52.988Z (7 months ago)
- Topics: async-await, rust, tokio-rs, wgpu
- Language: Rust
- Homepage: https://docs.rs/wgpu_tokio/0.12.5/wgpu_tokio/
- Size: 56.6 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# WGPU Tokio
This crate provide helper traits for working with [wgpu](https://github.com/gfx-rs/wgpu) in an async fashion. This
crate depends on tokio for it's async scheduling.## Why
Using tokio in gamedev brings a lot of benefits. Using multiple threads allows us to utilize the cpu to it's fullest.
And tokios green thread abstraction is cheap and performant.However, straight of calling wgpu's api from the tokio context is not a good idea. Most them will block the code in
order to do some chit-chatting with the gpu, etc. This will block the current worker thread and block other task from
executing while we are waiting for wgpu to finnish.A better solution if to offload this work to a dedicated thread pool and let them run, and then notify tokio once their
finnished.This crate does all of this and puts it inside a nice and tidy trait.
## Usage
Make sure you have the dependencies in place
```toml
[dependencies]
wgpu = "0.12"
wgpu_tokio = "0.12"
```Then in you code make sure you are using the trait
```rust
use wgpu_tokio::DeviceAsyncExt;
```The trait requires that the device is behind and ```Arc```. Then just go ahead and do something.
```rust
async fn do_something(device: Arc) {
let my_buffer = device.create_buffer_async(...).await;
}
```## License
This project is licensed under the [MIT license].
[MIT license]: https://github.com/joatin/wgpu_tokio/blob/main/LICENSE.txt