这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,673 changes: 2,325 additions & 1,348 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bevy_burn"
description = "bevy burn bindings"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = ["mosure <mitchell@mosure.me>"]
license = "MIT"
Expand Down Expand Up @@ -31,14 +31,14 @@ exclude = [


[dependencies]
burn = { version = "0.18", features = ["wgpu"] }
burn-core = { version = "0.18" }
burn-cubecl = { version = "0.18" }
burn-fusion = { version = "0.18" }
burn-wgpu = { version = "0.18" }
burn = { version = "0.19", features = ["wgpu"] }
burn-core = { version = "0.19" }
burn-cubecl = { version = "0.19" }
burn-fusion = { version = "0.19" }
burn-wgpu = { version = "0.19" }
bytemuck = "1.23"
cubecl = { version = "0.6", features = ["std", "wgpu"] }
wgpu = "25.0"
cubecl = { version = "0.8", features = ["std", "wgpu"] }
wgpu = "26.0"


[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand All @@ -48,11 +48,11 @@ wasm-bindgen = "0.2"


[dependencies.bevy]
git = "https://github.com/bevyengine/bevy.git"
rev = "b79b8133c881942a42bb359f998bd8792c48c1bc"
version = "0.17"
default-features = false
features = [
"bevy_asset",
"bevy_camera",
"bevy_core_pipeline",
"bevy_image",
"bevy_log",
Expand All @@ -61,11 +61,13 @@ features = [
"bevy_sprite",
"bevy_text",
"bevy_ui",
"bevy_ui_render",
"bevy_window",
"bevy_winit",
"debug",
"default_font",
"png",
"std",
"tonemapping_luts",
"webgpu",
"x11",
Expand All @@ -87,6 +89,7 @@ features = [

[dev-dependencies]
criterion = { version = "0.7", features = ["html_reports"] }
futures = "0.3"


[profile.dev.package."*"]
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
bevy burn data bridge plugin





## features
- [ ] bevy texture -> burn tensor
- [x] burn tensor -> bevy texture
Expand All @@ -22,9 +19,9 @@ bevy burn data bridge plugin

```rust
use bevy::prelude::*;
use bevy::render::{
render_asset::RenderAssetUsages,
render_resource::*,
use bevy::{
asset::RenderAssetUsages,
render::render_resource::*,
};
use burn_core::tensor::Int;
use burn_wgpu::Wgpu as BurnWgpu;
Expand Down Expand Up @@ -93,6 +90,7 @@ fn setup(

| `bevy_burn` | `bevy` | `burn` |
| :-- | :-- | :-- |
| `0.4` | `0.17` | `0.19` |
| `0.3` | `0.17-dev*` | `0.18` |

> *`wgpu` version must match
Expand Down
109 changes: 33 additions & 76 deletions bench/io.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
use criterion::{
BenchmarkId,
criterion_group,
criterion_main,
Criterion,
Throughput,
};

use bevy::{
prelude::*,
render::{
render_asset::RenderAssetUsages,
render_resource::*,
},
};
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};

use bevy::{asset::RenderAssetUsages, prelude::*, render::render_resource::*};
use burn::tensor::Tensor;
use burn_wgpu::Wgpu;

use bevy_burn::{
BevyBurnBridgePlugin,
BevyBurnHandle,
BindingDirection,
TransferKind,
};

use bevy_burn::{BevyBurnBridgePlugin, BevyBurnHandle, BindingDirection, TransferKind};

type BurnBackend = Wgpu<f32, i32>;


const SIZE: u32 = 512;


fn default_app() -> App {
let mut app = App::new();

Expand All @@ -43,7 +23,6 @@ fn default_app() -> App {
app
}


fn make_image() -> Image {
let mut img = Image::new_fill(
Extent3d {
Expand All @@ -60,32 +39,25 @@ fn make_image() -> Image {
img
}


fn bench_burn_to_bevy_cpu(crit: &mut Criterion) {
let mut app = default_app();

app.add_systems(
Startup,
|
mut cmds: Commands,
mut images: ResMut<Assets<Image>>,
| {
let handle = images.add(make_image());
let tensor = Tensor::<BurnBackend, 3>::zeros([
SIZE as usize,
SIZE as usize,
4,
],
&Default::default(),
);
cmds.spawn(BevyBurnHandle {
bevy_image: handle,
tensor,
upload: true,
direction: BindingDirection::BurnToBevy,
xfer: TransferKind::Cpu,
});
},
|mut cmds: Commands, mut images: ResMut<Assets<Image>>| {
let handle = images.add(make_image());
let tensor = Tensor::<BurnBackend, 3>::zeros(
[SIZE as usize, SIZE as usize, 4],
&Default::default(),
);
cmds.spawn(BevyBurnHandle {
bevy_image: handle,
tensor,
upload: true,
direction: BindingDirection::BurnToBevy,
xfer: TransferKind::Cpu,
});
},
);

app.add_systems(
Expand All @@ -110,32 +82,25 @@ fn bench_burn_to_bevy_cpu(crit: &mut Criterion) {
group.finish();
}


fn bench_bevy_to_burn_cpu(crit: &mut Criterion) {
let mut app = default_app();

app.add_systems(
Startup,
|
mut cmds: Commands,
mut images: ResMut<Assets<Image>>,
| {
let handle = images.add(make_image());
let tensor = Tensor::<BurnBackend, 3>::zeros([
SIZE as usize,
SIZE as usize,
4,
],
&Default::default(),
);
cmds.spawn(BevyBurnHandle {
bevy_image: handle,
tensor,
upload: true,
direction: BindingDirection::BevyToBurn,
xfer: TransferKind::Cpu,
});
},
|mut cmds: Commands, mut images: ResMut<Assets<Image>>| {
let handle = images.add(make_image());
let tensor = Tensor::<BurnBackend, 3>::zeros(
[SIZE as usize, SIZE as usize, 4],
&Default::default(),
);
cmds.spawn(BevyBurnHandle {
bevy_image: handle,
tensor,
upload: true,
direction: BindingDirection::BevyToBurn,
xfer: TransferKind::Cpu,
});
},
);

app.add_systems(
Expand All @@ -160,10 +125,6 @@ fn bench_bevy_to_burn_cpu(crit: &mut Criterion) {
group.finish();
}





// TODO: fix main thread issues for gpu benchmarking/tests
// fn bench_burn_to_bevy_gpu(crit: &mut Criterion) {
// let mut app = default_app();
Expand Down Expand Up @@ -214,7 +175,6 @@ fn bench_bevy_to_burn_cpu(crit: &mut Criterion) {
// group.finish();
// }


// fn bench_bevy_to_burn_gpu(crit: &mut Criterion) {
// let mut app = default_app();

Expand Down Expand Up @@ -264,10 +224,7 @@ fn bench_bevy_to_burn_cpu(crit: &mut Criterion) {
// group.finish();
// }




criterion_group!{
criterion_group! {
name = io_benches;
config = Criterion::default().sample_size(10);
targets = bench_burn_to_bevy_cpu,
Expand Down
81 changes: 41 additions & 40 deletions example/gpu_interop.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#![recursion_limit = "256"]

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

type BB = BurnWgpu<f32, i32>;

Expand All @@ -29,11 +26,7 @@ struct Plasma {
a: Tensor<BB, 2>,
}

fn setup(
mut cmds: Commands,
mut images: ResMut<Assets<Image>>,
burn: Res<BurnDevice>,
) {
fn setup(mut cmds: Commands, mut images: ResMut<Assets<Image>>, burn: Res<BurnDevice>) {
let size = Extent3d {
width: SIZE,
height: SIZE,
Expand Down Expand Up @@ -71,13 +64,25 @@ fn setup(
let x = Tensor::<BB, 2>::zeros([h, 1], &dev) + xs; // [h, w]
let y = ys + Tensor::<BB, 2>::zeros([1, w], &dev); // [h, w]
let a1 = Tensor::<BB, 2>::ones([h, w], &dev);
let boot_r = x.clone().mul_scalar(8.0).sin().mul_scalar(0.5).add_scalar(0.5);
let boot_g = x.clone().add(y.clone())
let boot_r = x
.clone()
.mul_scalar(8.0)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let boot_g = x
.clone()
.add(y.clone())
.mul_scalar(6.0)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let boot_b = y.clone().mul_scalar(8.0).sin().mul_scalar(0.5).add_scalar(0.5);
let boot_b = y
.clone()
.mul_scalar(8.0)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let rgba = Tensor::<BB, 2>::stack(vec![boot_r, boot_g, boot_b, a1.clone()], 2);

cmds.spawn((
Expand All @@ -98,35 +103,31 @@ fn setup(
cmds.spawn(Camera2d);
}


fn animate_plasma(
time: Res<Time>,
mut q: Query<(&Plasma, &mut BevyBurnHandle<BB>)>,
) {
fn animate_plasma(time: Res<Time>, mut q: Query<(&Plasma, &mut BevyBurnHandle<BB>)>) {
let t = time.elapsed_secs();
for (p, mut h) in &mut q {
let r = p.x
.clone()
.mul_scalar(8.0)
.add_scalar(t * 1.00)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let g = p.x
.clone()
.add(p.y.clone())
.mul_scalar(6.0)
.add_scalar(t * 1.37)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let b = p.y
.clone()
.mul_scalar(9.0)
.add_scalar(-t * 0.73)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let r =
p.x.clone()
.mul_scalar(8.0)
.add_scalar(t * 1.00)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let g =
p.x.clone()
.add(p.y.clone())
.mul_scalar(6.0)
.add_scalar(t * 1.37)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let b =
p.y.clone()
.mul_scalar(9.0)
.add_scalar(-t * 0.73)
.sin()
.mul_scalar(0.5)
.add_scalar(0.5);
let rgba = Tensor::<BB, 2>::stack(vec![r, g, b, p.a.clone()], 2);
h.tensor = rgba;
h.upload = true;
Expand Down
Loading
Loading