wgpu_tokio

Crates.iowgpu_tokio
lib.rswgpu_tokio
version0.12.6
sourcesrc
created_at2022-03-11 13:12:35.802866
updated_at2022-03-15 09:42:59.67144
descriptionAsync bindings using tokio for wgpu
homepage
repositoryhttps://github.com/Joatin/wgpu_tokio
max_upload_size
id548213
size15,823
Joatin Granlund (Joatin)

documentation

README

WGPU Tokio

This crate provide helper traits for working with 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

[dependencies]
wgpu = "0.12"
wgpu_tokio = "0.12"

Then in you code make sure you are using the trait

use wgpu_tokio::DeviceAsyncExt;

The trait requires that the device is behind and Arc. Then just go ahead and do something.

async fn do_something(device: Arc<Device>) {
    let my_buffer = device.create_buffer_async(...).await;
}

License

This project is licensed under the MIT license.

Commit count: 16

cargo fmt