Skip to content

mosure/bevy_burn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

bevy_burn πŸ•ŠοΈπŸ”₯

GitHub License crates.io

bevy burn data bridge plugin

features

  • bevy texture -> burn tensor
  • burn tensor -> bevy texture

usage

burn -> bevy gpu example

cargo run --bin gpu_interop

use bevy::prelude::*;
use bevy::{
    asset::RenderAssetUsages,
    render::render_resource::*,
};
use burn_core::tensor::Int;
use burn_wgpu::Wgpu as BurnWgpu;
use bevy_burn::*;

type BB = BurnWgpu<f32, i32>;

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(BevyBurnBridgePlugin::<BB>::default())
        .add_systems(Startup, setup)
        .run();
}

fn setup(
    mut cmds: Commands,
    mut images: ResMut<Assets<Image>>,
) {
    let size = Extent3d {
        width: 256,
        height: 256,
        depth_or_array_layers: 1,
    };
    let mut img = Image::new_fill(
        size,
        TextureDimension::D2,
        &[0; 16],
        TextureFormat::Rgba32Float,
        RenderAssetUsages::RENDER_WORLD,
    );
    img.texture_descriptor.usage |= TextureUsages::COPY_SRC
        | TextureUsages::COPY_DST
        | TextureUsages::TEXTURE_BINDING
        | TextureUsages::STORAGE_BINDING;
    let handle = images.add(img);

    let h = size.height as usize;
    let w = size.width as usize;
    let dev = Default::default();
    let xs = burn_core::tensor::Tensor::<BB, 1, Int>::arange(0..(w * h * 4) as i64, &dev)
        .float()
        .div_scalar((w * h * 4) as f32);
    let rgba = xs.reshape([h, w, 4]);

    cmds.spawn((
        ImageNode {
            image: handle.clone(),
            ..default()
        },
        BevyBurnHandle::<BB> {
            bevy_image: handle,
            tensor: rgba,
            upload: true,
            direction: BindingDirection::BurnToBevy,
            xfer: TransferKind::Gpu,
        },
    ));

    cmds.spawn(Camera2d);
}

compatible versions

bevy_burn bevy burn
0.4 0.17 0.19
0.3 0.17-dev* 0.18

*wgpu version must match

license

licensed under either of

at your option.

analytics

alt

About

bevy burn data bridge πŸ•ŠοΈπŸ”₯

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Languages