Bevy App Compute
Dispatch and run compute shaders on bevy from App World .
Getting Started
Add the following line to your Cargo.toml
[]
= "0.10.1"
Usage
Setup
Make an empty struct and implement ComputeShader
on it. the shader()
fn should point to your shader source code.
You need to derive TypeUuid
as well and assign a unique Uuid.
;
Add the plugin to your app:
use *;
use AppComputePlugin;
And then use the AppCompute
resource to build workers. These workers will let you configure and run some compute shaders from App World!
use *;
use *;
Non blocking computation
You can run your compute shaders without blocking the current system as well. Please be aware that WGPU doesn't support multiple queues, so your submit will be blended in bevy's render queue. This is not ideal.
use *;
use *;
Multiple passes
You can have multiple passes without having to copy data back to the CPU in between:
let worker = app_compute
.worker
.add_uniform
.add_storage
.add_storage
.add_storage
.add_staging_buffer
// Here we run two passes
// add `value` to each element of `output`
.
// multiply each element of `output` by itself
.
.read_staging_buffers
.submit
.map_staging_buffers
.now;
let result = worker.get_data;
let value: & = cast_slice;
println!; // [36.0, 49.0, 64.0, 81.0]
Examples
See examples
Bevy version mapping
Bevy | bevy_app_compute |
---|---|
main | main |
0.10 | 0.10.1 |