From 9446b07cdf2a4cbaddd208aa540f70531e11778d Mon Sep 17 00:00:00 2001 From: mosure Date: Tue, 20 Feb 2024 17:42:28 -0600 Subject: [PATCH 01/24] chore: update vscode workspace --- .vscode/bevy_gaussian_splatting.code-workspace | 13 ------------- .vscode/bevy_interleave.code-workspace | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 .vscode/bevy_gaussian_splatting.code-workspace create mode 100644 .vscode/bevy_interleave.code-workspace diff --git a/.vscode/bevy_gaussian_splatting.code-workspace b/.vscode/bevy_gaussian_splatting.code-workspace deleted file mode 100644 index fbf610a..0000000 --- a/.vscode/bevy_gaussian_splatting.code-workspace +++ /dev/null @@ -1,13 +0,0 @@ -{ - "folders": [ - { - "path": "../" - }, - { - "path": "../../bevy" - } - ], - "settings": { - "liveServer.settings.multiRootWorkspaceName": "bevy_gaussian_splatting" - } -} \ No newline at end of file diff --git a/.vscode/bevy_interleave.code-workspace b/.vscode/bevy_interleave.code-workspace new file mode 100644 index 0000000..5101809 --- /dev/null +++ b/.vscode/bevy_interleave.code-workspace @@ -0,0 +1,18 @@ +{ + "folders": [ + { + "path": ".." + }, + { + "path": "../crates/bevy_interleave_interface" + }, + { + "path": "../crates/bevy_interleave_macros" + } + ], + "settings": { + "rust-analyzer.linkedProjects": [ + "./Cargo.toml" + ] + } +} \ No newline at end of file From 98f68e4aa881441c86ff372732777b9fb954917a Mon Sep 17 00:00:00 2001 From: mosure Date: Thu, 19 Dec 2024 21:32:30 -0600 Subject: [PATCH 02/24] feat: bevy 0.15 --- crates/bevy_interleave_interface/Cargo.toml | 6 +++--- crates/bevy_interleave_interface/src/lib.rs | 14 +++++++++---- .../bevy_interleave_interface/src/texture.rs | 21 ++++++++++++------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index 40f57a7..dcf28d2 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.2.1" +version = "0.3.0" edition = "2021" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,6 +13,6 @@ keywords = [ [dependencies.bevy] -version = "0.13" +version = "0.15" default-features = false -features = ["bevy_asset", "bevy_render"] +features = ["bevy_asset", "bevy_render", "png"] diff --git a/crates/bevy_interleave_interface/src/lib.rs b/crates/bevy_interleave_interface/src/lib.rs index 02565cd..99973f5 100644 --- a/crates/bevy_interleave_interface/src/lib.rs +++ b/crates/bevy_interleave_interface/src/lib.rs @@ -5,6 +5,7 @@ pub mod texture; pub trait PlanarStorage { type PackedType; type PlanarType; + type PlanarTypeHandle: bevy::ecs::component::Component; fn bind_group( &self, @@ -24,14 +25,19 @@ pub trait PlanarStorage { } +pub trait PlanarTextureHandle: bevy::ecs::component::Component { + fn handle(&self) -> &bevy::asset::Handle; +} + pub trait PlanarTexture { type PackedType; - type PlanarType; + type PlanarType: bevy::asset::Asset; + type PlanarTypeHandle: PlanarTextureHandle; fn bind_group( &self, render_device: &bevy::render::renderer::RenderDevice, - gpu_images: &bevy::render::render_asset::RenderAssets, + gpu_images: &bevy::render::render_asset::RenderAssets, layout: &bevy::render::render_resource::BindGroupLayout, ) -> bevy::render::render_resource::BindGroup; @@ -40,11 +46,11 @@ pub trait PlanarTexture { ) -> bevy::render::render_resource::BindGroupLayout; fn prepare( - images: &mut bevy::asset::Assets, + images: &mut bevy::asset::Assets, planar: &Self::PlanarType, ) -> Self; - fn get_asset_handles(&self) -> Vec>; + fn get_asset_handles(&self) -> Vec>; } diff --git a/crates/bevy_interleave_interface/src/texture.rs b/crates/bevy_interleave_interface/src/texture.rs index 2b5299b..4615530 100644 --- a/crates/bevy_interleave_interface/src/texture.rs +++ b/crates/bevy_interleave_interface/src/texture.rs @@ -9,7 +9,10 @@ use bevy::{ }, }; -use crate::PlanarTexture; +use crate::{ + PlanarTexture, + PlanarTextureHandle, +}; pub struct PlanarTexturePlugin { @@ -43,7 +46,7 @@ where } fn finish(&self, app: &mut App) { - if let Ok(render_app) = app.get_sub_app_mut(bevy::render::RenderApp) { + if let Some(render_app) = app.get_sub_app_mut(bevy::render::RenderApp) { render_app.init_resource::>(); } } @@ -80,7 +83,7 @@ fn prepare_textures( clouds: Query< ( Entity, - &Handle, + &R::PlanarTypeHandle, ), Without, >, @@ -90,15 +93,17 @@ where R::PlanarType: Asset, { for (entity, cloud_handle) in clouds.iter() { - if Some(bevy::asset::LoadState::Loading) == asset_server.get_load_state(cloud_handle){ - continue; + if let Some(load_state) = asset_server.get_load_state(cloud_handle.handle()) { + if load_state.is_loading() { + continue; + } } - if cloud_res.get(cloud_handle).is_none() { + if cloud_res.get(cloud_handle.handle()).is_none() { continue; } - let cloud = cloud_res.get(cloud_handle).unwrap(); + let cloud = cloud_res.get(cloud_handle.handle()).unwrap(); let buffers = R::prepare( &mut images, @@ -120,7 +125,7 @@ pub struct PlanarTextureBindGroup( mut commands: Commands, render_device: ResMut, - gpu_images: Res>, + gpu_images: Res>, bind_group_layout: Res>, clouds: Query< ( From 6430d861d6d0fd37ef06c00b49c0047a55463a14 Mon Sep 17 00:00:00 2001 From: mosure Date: Thu, 19 Dec 2024 21:35:37 -0600 Subject: [PATCH 03/24] feat: bevy 0.15 --- Cargo.toml | 10 ++++----- README.md | 2 ++ crates/bevy_interleave_macros/Cargo.toml | 8 +++---- .../src/bindings/storage.rs | 2 ++ .../src/bindings/texture.rs | 12 ++++++----- crates/bevy_interleave_macros/src/planar.rs | 10 +++++++++ examples/app.rs | 2 +- src/lib.rs | 21 +++++++++---------- src/prelude.rs | 7 ++----- 9 files changed, 43 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 753b8c3..dd67d89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,15 +29,15 @@ members = [ [dependencies] -bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.2.1" } -bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.2.1" } -bytemuck = "1.14" +bevy_interleave_interface = { path = "crates/bevy_interleave_interface" } +bevy_interleave_macros = { path = "crates/bevy_interleave_macros" } +bytemuck = "1.20" serde = "1.0" [dependencies.bevy] -version = "0.13" +version = "0.15" default-features = false -features = ["bevy_asset", "bevy_render"] +features = ["bevy_asset", "bevy_render", "png"] [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/README.md b/README.md index 24b0ba0..a44aff9 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ fn interleaved() -> Vec { } fn main() { + // TODO: add unzip implementation for Vec `let planar = interleaved().unzip()` let planar = PlanarMyStruct::from_interleaved(interleaved()); println!("{:?}", planar.field); @@ -114,5 +115,6 @@ fn check_bind_group( | `bevy_interleave` | `bevy` | | :-- | :-- | +| `0.3` | `0.15` | | `0.2` | `0.13` | | `0.1` | `0.12` | diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index f1b0350..22fe26b 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.2.1" +version = "0.3.0" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,7 +13,7 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.2.1" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.3.0" } bytemuck = "1.14" convert_case = "0.6" proc-macro2 = "1.0" @@ -22,9 +22,9 @@ sha1 = "0.10" syn = "2.0" [dependencies.bevy] -version = "0.13" +version = "0.15" default-features = false -features = ["bevy_asset", "bevy_render"] +features = ["bevy_asset", "bevy_render", "png"] [lib] diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index ae1dd91..869a44e 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -19,6 +19,7 @@ pub fn storage_bindings(input: &DeriveInput) -> Result Result Result Result } + quote! { bevy::asset::Handle } }); let bind_group = generate_bind_group_method(name, fields_struct); @@ -66,6 +67,7 @@ pub fn texture_bindings(input: &DeriveInput) -> Result, + gpu_images: &bevy::render::render_asset::RenderAssets, layout: &bevy::render::render_resource::BindGroupLayout, ) -> bevy::render::render_resource::BindGroup { render_device.create_bind_group( @@ -200,7 +202,7 @@ pub fn generate_prepare_method(fields_named: &FieldsNamed) -> quote::__private:: let padded_size = (square * square * depth * format_bpp as u32) as usize; data.resize(padded_size, 0); - let mut #name = bevy::render::texture::Image::new( + let mut #name = bevy::image::Image::new( bevy::render::render_resource::Extent3d { width: square, height: square, @@ -224,7 +226,7 @@ pub fn generate_prepare_method(fields_named: &FieldsNamed) -> quote::__private:: quote! { fn prepare( - images: &mut bevy::asset::Assets, + images: &mut bevy::asset::Assets, planar: &Self::PlanarType, ) -> Self { #(#buffers)* @@ -246,7 +248,7 @@ pub fn generate_get_asset_handles_method(fields_named: &FieldsNamed) -> quote::_ }); quote! { - fn get_asset_handles(&self) -> Vec> { + fn get_asset_handles(&self) -> Vec> { vec![ #(#buffer_names),* ] diff --git a/crates/bevy_interleave_macros/src/planar.rs b/crates/bevy_interleave_macros/src/planar.rs index 96c85d9..73a2c72 100644 --- a/crates/bevy_interleave_macros/src/planar.rs +++ b/crates/bevy_interleave_macros/src/planar.rs @@ -13,6 +13,7 @@ use syn::{ pub fn generate_planar_struct(input: &DeriveInput) -> Result { let name = &input.ident; let planar_name = Ident::new(&format!("Planar{}", name), name.span()); + let planar_handle_name = Ident::new(&format!("Planar{}Handle", name), name.span()); let fields_struct = if let Data::Struct(ref data_struct) = input.data { match data_struct.fields { @@ -55,6 +56,15 @@ pub fn generate_planar_struct(input: &DeriveInput) -> Result); + + impl bevy_interleave_interface::PlanarTextureHandle<#planar_name> for #planar_handle_name { + fn handle(&self) -> &bevy::asset::Handle<#planar_name> { + &self.0 + } + } }; Ok(expanded) diff --git a/examples/app.rs b/examples/app.rs index 7edf4b0..bbe7f0a 100644 --- a/examples/app.rs +++ b/examples/app.rs @@ -32,7 +32,7 @@ fn main() { DefaultPlugins, PlanarPlugin::::default(), PlanarTexturePlugin::::default(), - // TODO: PlanarStoragePlugin::::default(), + // PlanarStoragePlugin::::default(), )); app.run(); diff --git a/src/lib.rs b/src/lib.rs index 229dd01..fd79ce6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,7 +53,7 @@ mod tests { let planar_handle = gaussian_assets.add(planar); - commands.spawn(planar_handle); + commands.spawn(PlanarMyStructHandle(planar_handle)); } #[allow(dead_code)] @@ -74,7 +74,7 @@ mod tests { *frame_count += 1; if *frame_count > 5 { - exit.send(bevy::app::AppExit); + exit.send(bevy::app::AppExit::Success); } } @@ -84,11 +84,10 @@ mod tests { let mut app = App::new(); app.add_plugins(( - DefaultPlugins, - bevy::app::ScheduleRunnerPlugin::run_loop( - std::time::Duration::from_millis(50) - ), - + DefaultPlugins + .set(bevy::app::ScheduleRunnerPlugin::run_loop( + std::time::Duration::from_millis(50) + )), PlanarPlugin::::default(), PlanarTexturePlugin::::default(), )); @@ -101,14 +100,14 @@ mod tests { check_bind_group.in_set(bevy::render::RenderSet::QueueMeshes), ); - render_app.init_resource::(); - let success = render_app.world.resource::(); - let success = success.0.clone(); + let success = TestSuccess(Arc::new(Mutex::new(false))); + let success_arc = success.0.clone(); + render_app.insert_resource(success); app.add_systems(Update, test_timeout); app.run(); - if !*success.lock().unwrap() { + if !*success_arc.lock().unwrap() { panic!("app exit without success flag set - bind group was not found"); } } diff --git a/src/prelude.rs b/src/prelude.rs index 34bab6e..ee4f8ca 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -1,8 +1,5 @@ -pub use bevy::render::{ - render_resource::TextureFormat, - texture::TextureFormatPixelInfo, -}; - +pub use bevy::render::render_resource::TextureFormat; +pub use bevy::image::TextureFormatPixelInfo; pub use crate::interface::{ Planar, From c28757c1d1062631b9cd619af32a0ce6cf5ac1c1 Mon Sep 17 00:00:00 2001 From: mosure Date: Thu, 19 Dec 2024 21:40:22 -0600 Subject: [PATCH 04/24] chore: version bump --- Cargo.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index dd67d89..55722a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.2.1" +version = "0.3.0" edition = "2021" authors = ["mosure "] license = "MIT" @@ -29,8 +29,8 @@ members = [ [dependencies] -bevy_interleave_interface = { path = "crates/bevy_interleave_interface" } -bevy_interleave_macros = { path = "crates/bevy_interleave_macros" } +bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.3" } +bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.3" } bytemuck = "1.20" serde = "1.0" From 778aa8657d75834d1938778a71186b85aeef6945 Mon Sep 17 00:00:00 2001 From: mosure Date: Fri, 27 Dec 2024 22:48:44 -0600 Subject: [PATCH 05/24] feat: storage bindings --- Cargo.toml | 9 +- README.md | 3 +- crates/bevy_interleave_interface/Cargo.toml | 2 +- crates/bevy_interleave_interface/src/lib.rs | 39 +++-- .../bevy_interleave_interface/src/planar.rs | 31 ---- .../bevy_interleave_interface/src/storage.rs | 135 ++++++++++++++++++ .../bevy_interleave_interface/src/texture.rs | 3 +- crates/bevy_interleave_macros/Cargo.toml | 5 +- .../src/bindings/storage.rs | 114 +++++++++------ crates/bevy_interleave_macros/src/planar.rs | 41 +++++- examples/app.rs | 23 +-- src/lib.rs | 46 ++++-- src/prelude.rs | 7 +- 13 files changed, 328 insertions(+), 130 deletions(-) delete mode 100644 crates/bevy_interleave_interface/src/planar.rs create mode 100644 crates/bevy_interleave_interface/src/storage.rs diff --git a/Cargo.toml b/Cargo.toml index 55722a3..6f0b7c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.3.0" +version = "0.4.0" edition = "2021" authors = ["mosure "] license = "MIT" @@ -29,10 +29,11 @@ members = [ [dependencies] -bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.3" } -bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.3" } -bytemuck = "1.20" +bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.4" } +bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.4" } +bytemuck = "1.21" serde = "1.0" +wgpu = "23.0.1" [dependencies.bevy] version = "0.15" diff --git a/README.md b/README.md index a44aff9..177acaf 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![GitHub Issues](https://img.shields.io/github/issues/mosure/bevy_interleave)](https://github.com/mosure/bevy_interleave/issues) [![crates.io](https://img.shields.io/crates/v/bevy_interleave.svg)](https://crates.io/crates/bevy_interleave) -bevy support for e2e packed to planar bind groups +bevy support for e2e packed to planar bind groups (e.g. statically typed meshes) ## minimal example @@ -18,7 +18,6 @@ use bevy_interleave::prelude::*; Planar, ReflectInterleaved, StorageBindings, - TextureBindings, )] pub struct MyStruct { #[texture_format(TextureFormat::R32Sint)] diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index dcf28d2..85fd2b5 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.3.0" +version = "0.4.0" edition = "2021" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_interface/src/lib.rs b/crates/bevy_interleave_interface/src/lib.rs index 99973f5..fe9235a 100644 --- a/crates/bevy_interleave_interface/src/lib.rs +++ b/crates/bevy_interleave_interface/src/lib.rs @@ -1,11 +1,19 @@ -pub mod planar; +pub mod storage; pub mod texture; -pub trait PlanarStorage { +// TODO: this needs to be refactored and better structured +pub trait PlanarHandle +where + Self: bevy::ecs::component::Component, + Self: bevy::render::extract_component::ExtractComponent, + T: bevy::asset::Asset, +{ + fn handle(&self) -> &bevy::asset::Handle; +} + +pub trait GpuPlanarStorage { type PackedType; - type PlanarType; - type PlanarTypeHandle: bevy::ecs::component::Component; fn bind_group( &self, @@ -17,22 +25,23 @@ pub trait PlanarStorage { render_device: &bevy::render::renderer::RenderDevice, read_only: bool, ) -> bevy::render::render_resource::BindGroupLayout; - - fn prepare( - render_device: &bevy::render::renderer::RenderDevice, - planar: &Self::PlanarType, - ) -> Self; } - -pub trait PlanarTextureHandle: bevy::ecs::component::Component { - fn handle(&self) -> &bevy::asset::Handle; +pub trait PlanarStorage { + type PackedType; // Self + type PlanarType: bevy::asset::Asset + bevy::reflect::GetTypeRegistration + bevy::reflect::FromReflect; + type PlanarTypeHandle: PlanarHandle; + type GpuPlanarType: GpuPlanarStorage + bevy::render::render_asset::RenderAsset; } + +// TODO: refactor planar texture to be more like planar storage pub trait PlanarTexture { - type PackedType; + type PackedType; // Self type PlanarType: bevy::asset::Asset; - type PlanarTypeHandle: PlanarTextureHandle; + type PlanarTypeHandle: PlanarHandle; + + // note: planar texture's gpu type utilizes bevy's image render asset fn bind_group( &self, @@ -72,4 +81,6 @@ pub trait Planar { fn to_interleaved(&self) -> Vec; fn from_interleaved(packed: Vec) -> Self where Self: Sized; + + fn subset(&self, indices: &[usize]) -> Self; } diff --git a/crates/bevy_interleave_interface/src/planar.rs b/crates/bevy_interleave_interface/src/planar.rs deleted file mode 100644 index f3f1c45..0000000 --- a/crates/bevy_interleave_interface/src/planar.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::marker::PhantomData; - -use bevy::{ - prelude::*, - reflect::GetTypeRegistration, -}; - -use crate::Planar; - - -pub struct PlanarPlugin { - phantom: PhantomData R>, -} -impl Default for PlanarPlugin { - fn default() -> Self { - Self { - phantom: PhantomData, - } - } -} - -impl Plugin for PlanarPlugin -where - R: Planar + Default + Asset + GetTypeRegistration + Clone + Reflect + FromReflect, -{ - fn build(&self, app: &mut App) { - app.register_type::(); - app.init_asset::(); - app.register_asset_reflect::(); - } -} diff --git a/crates/bevy_interleave_interface/src/storage.rs b/crates/bevy_interleave_interface/src/storage.rs new file mode 100644 index 0000000..4a7cd0f --- /dev/null +++ b/crates/bevy_interleave_interface/src/storage.rs @@ -0,0 +1,135 @@ +use std::marker::PhantomData; + +use bevy::{ + prelude::*, + reflect::GetTypeRegistration, + render::extract_component::ExtractComponentPlugin, +}; + +use crate::{ + GpuPlanarStorage, + PlanarHandle, + PlanarStorage, +}; + + +pub struct PlanarStoragePlugin { + phantom: PhantomData R>, +} +impl Default for PlanarStoragePlugin { + fn default() -> Self { + Self { + phantom: PhantomData, + } + } +} + +impl Plugin for PlanarStoragePlugin +where + R: PlanarStorage + Default + GetTypeRegistration + Clone + Reflect, +{ + fn build(&self, app: &mut App) { + app.register_type::(); + + app.register_type::(); + app.init_asset::(); + app.register_asset_reflect::(); + + app.add_plugins(bevy::render::render_asset::RenderAssetPlugin::::default()); + app.add_plugins(ExtractComponentPlugin::::default()); + + let render_app = app.sub_app_mut(bevy::render::RenderApp); + render_app.add_systems( + bevy::render::Render, + queue_gpu_storage_buffers::.in_set(bevy::render::RenderSet::PrepareBindGroups), + ); + } + + fn finish(&self, app: &mut App) { + if let Some(render_app) = app.get_sub_app_mut(bevy::render::RenderApp) { + render_app.init_resource::>(); + } + } +} + + +#[derive(bevy::prelude::Resource)] +pub struct PlanarStorageLayouts { + pub bind_group_layout: bevy::render::render_resource::BindGroupLayout, + pub phantom: PhantomData R>, +} + +impl +FromWorld for PlanarStorageLayouts { + fn from_world(world: &mut World) -> Self { + let render_device = world.resource::(); + + let read_only = true; + let bind_group_layout = R::GpuPlanarType::bind_group_layout( + render_device, + read_only, + ); + + Self { + bind_group_layout, + phantom: PhantomData, + } + } +} + +#[derive(bevy::prelude::Component, Clone, Debug)] +pub struct PlanarStorageBindGroup { + pub bind_group: bevy::render::render_resource::BindGroup, + pub phantom: PhantomData R>, +} + + +fn queue_gpu_storage_buffers( + mut commands: Commands, + asset_server: Res, + render_device: ResMut, + gpu_planars: Res>, + bind_group_layout: Res>, + clouds: Query< + ( + Entity, + &R::PlanarTypeHandle, + ), + Without>, + >, +) +where + R: PlanarStorage + Default + Clone + Reflect, + R::PlanarType: Asset, +{ + let layout = &bind_group_layout.bind_group_layout; + + info!("queue_gpu_storage_buffers"); + + for (entity, planar_handle,) in clouds.iter() { + info!("handle {:?}", planar_handle.handle()); + + if let Some(load_state) = asset_server.get_load_state(planar_handle.handle()) { + if load_state.is_loading() { + info!("loading"); + continue; + } + } + + if gpu_planars.get(planar_handle.handle()).is_none() { + info!("no gpu planar"); + continue; + } + + let gpu_planar: &::GpuPlanarType = gpu_planars.get(planar_handle.handle()).unwrap(); + let bind_group = gpu_planar.bind_group( + &render_device, + layout, + ); + + commands.entity(entity).insert(PlanarStorageBindGroup:: { + bind_group, + phantom: PhantomData, + }); + } +} diff --git a/crates/bevy_interleave_interface/src/texture.rs b/crates/bevy_interleave_interface/src/texture.rs index 4615530..389f26c 100644 --- a/crates/bevy_interleave_interface/src/texture.rs +++ b/crates/bevy_interleave_interface/src/texture.rs @@ -10,8 +10,8 @@ use bevy::{ }; use crate::{ + PlanarHandle, PlanarTexture, - PlanarTextureHandle, }; @@ -75,6 +75,7 @@ FromWorld for PlanarTextureLayouts { } } + fn prepare_textures( mut commands: Commands, asset_server: Res, diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 22fe26b..74d78e1 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.3.0" +version = "0.4.0" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,13 +13,14 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.3.0" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.4.0" } bytemuck = "1.14" convert_case = "0.6" proc-macro2 = "1.0" quote = "1.0" sha1 = "0.10" syn = "2.0" +wgpu = "23.0.1" [dependencies.bevy] version = "0.15" diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index 869a44e..a0f20ff 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -37,22 +37,85 @@ pub fn storage_bindings(input: &DeriveInput) -> Result; + + fn prepare_asset( + source: Self::SourceAsset, + render_device: &mut bevy::ecs::system::SystemParamItem, + ) -> Result> { + let count = source.len(); + + let draw_indirect_buffer = render_device.create_buffer_with_data(&bevy::render::render_resource::BufferInitDescriptor { + label: Some("draw indirect buffer"), + contents: wgpu::util::DrawIndirectArgs { // TODO: reexport this type + vertex_count: 4, + instance_count: count as u32, + first_vertex: 0, + first_instance: 0, + }.as_bytes(), + usage: bevy::render::render_resource::BufferUsages::INDIRECT + | bevy::render::render_resource::BufferUsages::COPY_DST + | bevy::render::render_resource::BufferUsages::STORAGE + | bevy::render::render_resource::BufferUsages::COPY_SRC, + }); + + #(#buffers)* + + Ok(Self { + count, + draw_indirect_buffer, + + #(#buffer_names),* + }) + } + } + + impl GpuPlanarStorage for #gpu_planar_name { type PackedType = #name; - type PlanarType = #planar_name; - type PlanarTypeHandle = #planar_handle_name; #bind_group #bind_group_layout - #prepare + } + + impl PlanarStorage for #name { + type PackedType = #name; + type PlanarType = #planar_name; + type PlanarTypeHandle = #planar_handle_name; + type GpuPlanarType = #gpu_planar_name; } }; @@ -137,44 +200,3 @@ pub fn generate_bind_group_layout_method(struct_name: &Ident, fields_named: &Fie } } } - - -pub fn generate_prepare_method(fields_named: &FieldsNamed) -> quote::__private::TokenStream { - let buffers = fields_named.named - .iter() - .map(|field| { - let name = field.ident.as_ref().unwrap(); - let buffer_name_string = format!("{}_buffer", name); - - quote! { - let #name = render_device.create_buffer_with_data( - &bevy::render::render_resource::BufferInitDescriptor { - label: Some(#buffer_name_string), - contents: bytemuck::cast_slice(planar.#name.as_slice()), - usage: bevy::render::render_resource::BufferUsages::COPY_DST - | bevy::render::render_resource::BufferUsages::STORAGE, - } - ); - } - }); - - let buffer_names = fields_named.named - .iter() - .map(|field| { - let name = field.ident.as_ref().unwrap(); - quote! { #name } - }); - - quote! { - fn prepare( - render_device: &bevy::render::renderer::RenderDevice, - planar: &Self::PlanarType, - ) -> Self { - #(#buffers)* - - Self { - #(#buffer_names),* - } - } - } -} diff --git a/crates/bevy_interleave_macros/src/planar.rs b/crates/bevy_interleave_macros/src/planar.rs index 73a2c72..636cf28 100644 --- a/crates/bevy_interleave_macros/src/planar.rs +++ b/crates/bevy_interleave_macros/src/planar.rs @@ -33,6 +33,7 @@ pub fn generate_planar_struct(input: &DeriveInput) -> Result Result); - impl bevy_interleave_interface::PlanarTextureHandle<#planar_name> for #planar_handle_name { + impl bevy_interleave_interface::PlanarHandle<#planar_name> for #planar_handle_name { fn handle(&self) -> &bevy::asset::Handle<#planar_name> { &self.0 } @@ -160,3 +162,38 @@ pub fn generate_conversion_methods(struct_name: &Ident, fields_named: &FieldsNam conversion_methods } + + +pub fn generate_subset_method(fields_named: &FieldsNamed) -> proc_macro2::TokenStream { + let mut new_planes_fields = Vec::new(); + let mut push_self_index = Vec::new(); + let mut planes = Vec::new(); + + for field in &fields_named.named { + let name = field.ident.as_ref().unwrap(); + + new_planes_fields.push(quote! { + let mut #name = Vec::with_capacity(indices.len()); + }); + push_self_index.push(quote! { + #name.push(self.#name[index]); + }); + planes.push(quote! { + #name + }); + } + + quote! { + fn subset(&self, indices: &[usize]) -> Self { + #(#new_planes_fields)* + + for &index in indices { + #(#push_self_index)* + } + + Self { + #(#planes),* + } + } + } +} diff --git a/examples/app.rs b/examples/app.rs index bbe7f0a..d8ed190 100644 --- a/examples/app.rs +++ b/examples/app.rs @@ -4,23 +4,26 @@ use bevy_interleave::prelude::*; #[derive( + Clone, Debug, + Default, Planar, + Reflect, ReflectInterleaved, StorageBindings, - TextureBindings, + // TextureBindings, )] pub struct MyStruct { - #[texture_format(TextureFormat::R32Sint)] + // #[texture_format(TextureFormat::R32Sint)] pub field: i32, - #[texture_format(TextureFormat::R32Uint)] + // #[texture_format(TextureFormat::R32Uint)] pub field2: u32, - #[texture_format(TextureFormat::R8Unorm)] + // #[texture_format(TextureFormat::R8Unorm)] pub bool_field: bool, - #[texture_format(TextureFormat::Rgba32Uint)] + // #[texture_format(TextureFormat::Rgba32Uint)] pub array: [u32; 4], } @@ -28,12 +31,10 @@ pub struct MyStruct { fn main() { let mut app = App::new(); - app.add_plugins(( - DefaultPlugins, - PlanarPlugin::::default(), - PlanarTexturePlugin::::default(), - // PlanarStoragePlugin::::default(), - )); + app.add_plugins(DefaultPlugins); + app.add_plugins( + PlanarStoragePlugin::::default(), + ); app.run(); } diff --git a/src/lib.rs b/src/lib.rs index fd79ce6..7d63ace 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,6 +10,7 @@ pub mod macros { +#[allow(dead_code)] mod tests { use std::sync::{Arc, Mutex}; @@ -17,30 +18,32 @@ mod tests { use crate::prelude::*; #[derive( + Clone, Debug, + Default, + Reflect, Planar, ReflectInterleaved, StorageBindings, - TextureBindings, + // TextureBindings, )] pub struct MyStruct { - #[texture_format(TextureFormat::R32Sint)] + // #[texture_format(TextureFormat::R32Sint)] pub field: i32, - #[texture_format(TextureFormat::R32Uint)] + // #[texture_format(TextureFormat::R32Uint)] pub field2: u32, - #[texture_format(TextureFormat::R8Unorm)] + // #[texture_format(TextureFormat::R8Unorm)] pub bool_field: bool, - #[texture_format(TextureFormat::Rgba32Uint)] + // #[texture_format(TextureFormat::Rgba32Uint)] pub array: [u32; 4], } #[derive(Resource, Default)] struct TestSuccess(Arc>); - #[allow(dead_code)] fn setup_planar( mut commands: Commands, mut gaussian_assets: ResMut>, @@ -56,9 +59,18 @@ mod tests { commands.spawn(PlanarMyStructHandle(planar_handle)); } - #[allow(dead_code)] - fn check_bind_group( - bind_group: Query<&PlanarTextureBindGroup::>, + // TODO: require both texture and storage bind groups + // fn check_texture_bind_group( + // bind_group: Query<&PlanarTextureBindGroup::>, + // success: Res, + // ) { + // if bind_group.iter().count() > 0 { + // *success.0.lock().unwrap() = true; + // } + // } + + fn check_storage_bind_group( + bind_group: Query<&PlanarStorageBindGroup::>, success: Res, ) { if bind_group.iter().count() > 0 { @@ -66,7 +78,6 @@ mod tests { } } - #[allow(dead_code)] fn test_timeout( mut exit: EventWriter, mut frame_count: Local, @@ -83,21 +94,26 @@ mod tests { fn texture_bind_group() { let mut app = App::new(); - app.add_plugins(( + app.add_plugins( DefaultPlugins .set(bevy::app::ScheduleRunnerPlugin::run_loop( std::time::Duration::from_millis(50) )), - PlanarPlugin::::default(), - PlanarTexturePlugin::::default(), - )); + ); + app.add_plugins( + PlanarStoragePlugin::::default(), + // PlanarTexturePlugin::::default(), + ); app.add_systems(Startup, setup_planar); let render_app = app.sub_app_mut(bevy::render::RenderApp); render_app.add_systems( bevy::render::Render, - check_bind_group.in_set(bevy::render::RenderSet::QueueMeshes), + ( + check_storage_bind_group.in_set(bevy::render::RenderSet::QueueMeshes), + // check_texture_bind_group.in_set(bevy::render::RenderSet::QueueMeshes) + ), ); let success = TestSuccess(Arc::new(Mutex::new(false))); diff --git a/src/prelude.rs b/src/prelude.rs index ee4f8ca..ddb98bc 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -2,10 +2,15 @@ pub use bevy::render::render_resource::TextureFormat; pub use bevy::image::TextureFormatPixelInfo; pub use crate::interface::{ + GpuPlanarStorage, Planar, PlanarStorage, PlanarTexture, - planar::PlanarPlugin, + storage::{ + PlanarStorageBindGroup, + PlanarStorageLayouts, + PlanarStoragePlugin, + }, texture::{ PlanarTextureBindGroup, PlanarTextureLayouts, From 0be9557604b3888f56a622007a8762827904ed77 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 12:26:24 -0600 Subject: [PATCH 06/24] fix: crate access + test separation --- Cargo.toml | 4 + crates/bevy_interleave_macros/Cargo.toml | 2 +- crates/bevy_interleave_macros/src/planar.rs | 2 +- src/lib.rs | 121 -------------------- test/lib.rs | 115 +++++++++++++++++++ 5 files changed, 121 insertions(+), 123 deletions(-) create mode 100644 test/lib.rs diff --git a/Cargo.toml b/Cargo.toml index 6f0b7c0..957ccd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -78,3 +78,7 @@ codegen-units = 1 [lib] path = "src/lib.rs" + +[[test]] +name = "lib" +path = "test/lib.rs" diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 74d78e1..942e3e3 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.4.0" +version = "0.4.1" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_macros/src/planar.rs b/crates/bevy_interleave_macros/src/planar.rs index 636cf28..837670d 100644 --- a/crates/bevy_interleave_macros/src/planar.rs +++ b/crates/bevy_interleave_macros/src/planar.rs @@ -62,7 +62,7 @@ pub fn generate_planar_struct(input: &DeriveInput) -> Result); - impl bevy_interleave_interface::PlanarHandle<#planar_name> for #planar_handle_name { + impl bevy_interleave::interface::PlanarHandle<#planar_name> for #planar_handle_name { fn handle(&self) -> &bevy::asset::Handle<#planar_name> { &self.0 } diff --git a/src/lib.rs b/src/lib.rs index 7d63ace..5817e50 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,124 +7,3 @@ pub mod interface { pub mod macros { pub use bevy_interleave_macros::*; } - - - -#[allow(dead_code)] -mod tests { - use std::sync::{Arc, Mutex}; - - use bevy::prelude::*; - use crate::prelude::*; - - #[derive( - Clone, - Debug, - Default, - Reflect, - Planar, - ReflectInterleaved, - StorageBindings, - // TextureBindings, - )] - pub struct MyStruct { - // #[texture_format(TextureFormat::R32Sint)] - pub field: i32, - - // #[texture_format(TextureFormat::R32Uint)] - pub field2: u32, - - // #[texture_format(TextureFormat::R8Unorm)] - pub bool_field: bool, - - // #[texture_format(TextureFormat::Rgba32Uint)] - pub array: [u32; 4], - } - - #[derive(Resource, Default)] - struct TestSuccess(Arc>); - - fn setup_planar( - mut commands: Commands, - mut gaussian_assets: ResMut>, - ) { - let planar = PlanarMyStruct::from_interleaved(vec![ - MyStruct { field: 0, field2: 1_u32, bool_field: true, array: [0, 1, 2, 3] }, - MyStruct { field: 2, field2: 3_u32, bool_field: false, array: [4, 5, 6, 7] }, - MyStruct { field: 4, field2: 5_u32, bool_field: true, array: [8, 9, 10, 11] }, - ]); - - let planar_handle = gaussian_assets.add(planar); - - commands.spawn(PlanarMyStructHandle(planar_handle)); - } - - // TODO: require both texture and storage bind groups - // fn check_texture_bind_group( - // bind_group: Query<&PlanarTextureBindGroup::>, - // success: Res, - // ) { - // if bind_group.iter().count() > 0 { - // *success.0.lock().unwrap() = true; - // } - // } - - fn check_storage_bind_group( - bind_group: Query<&PlanarStorageBindGroup::>, - success: Res, - ) { - if bind_group.iter().count() > 0 { - *success.0.lock().unwrap() = true; - } - } - - fn test_timeout( - mut exit: EventWriter, - mut frame_count: Local, - ) { - *frame_count += 1; - - if *frame_count > 5 { - exit.send(bevy::app::AppExit::Success); - } - } - - - #[test] - fn texture_bind_group() { - let mut app = App::new(); - - app.add_plugins( - DefaultPlugins - .set(bevy::app::ScheduleRunnerPlugin::run_loop( - std::time::Duration::from_millis(50) - )), - ); - app.add_plugins( - PlanarStoragePlugin::::default(), - // PlanarTexturePlugin::::default(), - ); - - app.add_systems(Startup, setup_planar); - - let render_app = app.sub_app_mut(bevy::render::RenderApp); - render_app.add_systems( - bevy::render::Render, - ( - check_storage_bind_group.in_set(bevy::render::RenderSet::QueueMeshes), - // check_texture_bind_group.in_set(bevy::render::RenderSet::QueueMeshes) - ), - ); - - let success = TestSuccess(Arc::new(Mutex::new(false))); - let success_arc = success.0.clone(); - render_app.insert_resource(success); - - app.add_systems(Update, test_timeout); - app.run(); - - if !*success_arc.lock().unwrap() { - panic!("app exit without success flag set - bind group was not found"); - } - } -} diff --git a/test/lib.rs b/test/lib.rs new file mode 100644 index 0000000..f12dfd7 --- /dev/null +++ b/test/lib.rs @@ -0,0 +1,115 @@ +use std::sync::{Arc, Mutex}; + +use bevy::prelude::*; +use bevy_interleave::prelude::*; + +#[derive( + Clone, + Debug, + Default, + Reflect, + Planar, + ReflectInterleaved, + StorageBindings, + // TextureBindings, +)] +pub struct MyStruct { + // #[texture_format(TextureFormat::R32Sint)] + pub field: i32, + + // #[texture_format(TextureFormat::R32Uint)] + pub field2: u32, + + // #[texture_format(TextureFormat::R8Unorm)] + pub bool_field: bool, + + // #[texture_format(TextureFormat::Rgba32Uint)] + pub array: [u32; 4], +} + +#[derive(Resource, Default)] +struct TestSuccess(Arc>); + +fn setup_planar( + mut commands: Commands, + mut gaussian_assets: ResMut>, +) { + let planar = PlanarMyStruct::from_interleaved(vec![ + MyStruct { field: 0, field2: 1_u32, bool_field: true, array: [0, 1, 2, 3] }, + MyStruct { field: 2, field2: 3_u32, bool_field: false, array: [4, 5, 6, 7] }, + MyStruct { field: 4, field2: 5_u32, bool_field: true, array: [8, 9, 10, 11] }, + ]); + + let planar_handle = gaussian_assets.add(planar); + + commands.spawn(PlanarMyStructHandle(planar_handle)); +} + +// TODO: require both texture and storage bind groups +// fn check_texture_bind_group( +// bind_group: Query<&PlanarTextureBindGroup::>, +// success: Res, +// ) { +// if bind_group.iter().count() > 0 { +// *success.0.lock().unwrap() = true; +// } +// } + +fn check_storage_bind_group( + bind_group: Query<&PlanarStorageBindGroup::>, + success: Res, +) { + if bind_group.iter().count() > 0 { + *success.0.lock().unwrap() = true; + } +} + +fn test_timeout( + mut exit: EventWriter, + mut frame_count: Local, +) { + *frame_count += 1; + + if *frame_count > 5 { + exit.send(bevy::app::AppExit::Success); + } +} + + +#[test] +fn texture_bind_group() { + let mut app = App::new(); + + app.add_plugins( + DefaultPlugins + .set(bevy::app::ScheduleRunnerPlugin::run_loop( + std::time::Duration::from_millis(50) + )), + ); + app.add_plugins( + PlanarStoragePlugin::::default(), + // PlanarTexturePlugin::::default(), + ); + + app.add_systems(Startup, setup_planar); + + let render_app = app.sub_app_mut(bevy::render::RenderApp); + render_app.add_systems( + bevy::render::Render, + ( + check_storage_bind_group.in_set(bevy::render::RenderSet::QueueMeshes), + // check_texture_bind_group.in_set(bevy::render::RenderSet::QueueMeshes) + ), + ); + + let success = TestSuccess(Arc::new(Mutex::new(false))); + let success_arc = success.0.clone(); + render_app.insert_resource(success); + + app.add_systems(Update, test_timeout); + app.run(); + + if !*success_arc.lock().unwrap() { + panic!("app exit without success flag set - bind group was not found"); + } +} From 637497f5d120591982683b32fe55abc89c238bad Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 12:51:23 -0600 Subject: [PATCH 07/24] chore: bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 957ccd3..324fbe0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.4.0" +version = "0.4.1" edition = "2021" authors = ["mosure "] license = "MIT" From 9f1313c411eca7c11ba0d2ad29865237fffcb8c8 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 14:08:31 -0600 Subject: [PATCH 08/24] fix: asset usage --- Cargo.toml | 2 +- crates/bevy_interleave_macros/Cargo.toml | 2 +- crates/bevy_interleave_macros/src/bindings/storage.rs | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 324fbe0..dcf5bbb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.4.1" +version = "0.4.2" edition = "2021" authors = ["mosure "] license = "MIT" diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 942e3e3..17fb570 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.4.1" +version = "0.4.2" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index a0f20ff..3922526 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -102,6 +102,10 @@ pub fn storage_bindings(input: &DeriveInput) -> Result bevy::render::render_asset::RenderAssetUsages { + bevy::render::render_asset::RenderAssetUsages::default() + } } impl GpuPlanarStorage for #gpu_planar_name { From fd7cf192abd94c47b7465b201239942b74afc792 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 14:22:03 -0600 Subject: [PATCH 09/24] fix: prelude PlanarHandle --- Cargo.toml | 2 +- src/prelude.rs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index dcf5bbb..4fba393 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.4.2" +version = "0.4.3" edition = "2021" authors = ["mosure "] license = "MIT" diff --git a/src/prelude.rs b/src/prelude.rs index ddb98bc..e0fa61b 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -4,6 +4,7 @@ pub use bevy::image::TextureFormatPixelInfo; pub use crate::interface::{ GpuPlanarStorage, Planar, + PlanarHandle, PlanarStorage, PlanarTexture, storage::{ From 8fddeed6ed1e4cee8f99290bfc6e4ed706a02f32 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 14:29:09 -0600 Subject: [PATCH 10/24] feat: GpuPlanarType len --- Cargo.toml | 2 +- crates/bevy_interleave_interface/Cargo.toml | 2 +- crates/bevy_interleave_interface/src/lib.rs | 2 ++ crates/bevy_interleave_macros/Cargo.toml | 2 +- crates/bevy_interleave_macros/src/bindings/storage.rs | 4 ++++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4fba393..811adc6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.4.3" +version = "0.5.0" edition = "2021" authors = ["mosure "] license = "MIT" diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index 85fd2b5..46ea462 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.4.0" +version = "0.5.0" edition = "2021" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_interface/src/lib.rs b/crates/bevy_interleave_interface/src/lib.rs index fe9235a..6758430 100644 --- a/crates/bevy_interleave_interface/src/lib.rs +++ b/crates/bevy_interleave_interface/src/lib.rs @@ -15,6 +15,8 @@ where pub trait GpuPlanarStorage { type PackedType; + fn len(&self) -> usize; + fn bind_group( &self, render_device: &bevy::render::renderer::RenderDevice, diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 17fb570..e6ee706 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.4.2" +version = "0.5.0" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index 3922526..051ea97 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -111,6 +111,10 @@ pub fn storage_bindings(input: &DeriveInput) -> Result usize { + self.count + } + #bind_group #bind_group_layout } From 9d94e3d7064ca6512285803ec5baf5640dd581a9 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 14:29:38 -0600 Subject: [PATCH 11/24] chore: bump versions --- Cargo.toml | 4 ++-- crates/bevy_interleave_macros/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 811adc6..fcf778b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,8 @@ members = [ [dependencies] -bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.4" } -bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.4" } +bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.5" } +bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.5" } bytemuck = "1.21" serde = "1.0" wgpu = "23.0.1" diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index e6ee706..5f3ac1e 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -13,7 +13,7 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.4.0" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.5.0" } bytemuck = "1.14" convert_case = "0.6" proc-macro2 = "1.0" From 86ee6dedf1f5f83f585fcddf9b06b6c53e6a6803 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 14:34:48 -0600 Subject: [PATCH 12/24] fix: PlanarTypeHandle Clone --- Cargo.toml | 2 +- crates/bevy_interleave_interface/Cargo.toml | 2 +- crates/bevy_interleave_interface/src/lib.rs | 1 + crates/bevy_interleave_macros/Cargo.toml | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fcf778b..05d8838 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.5.0" +version = "0.5.1" edition = "2021" authors = ["mosure "] license = "MIT" diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index 46ea462..b492715 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.5.0" +version = "0.5.1" edition = "2021" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_interface/src/lib.rs b/crates/bevy_interleave_interface/src/lib.rs index 6758430..65cf7c8 100644 --- a/crates/bevy_interleave_interface/src/lib.rs +++ b/crates/bevy_interleave_interface/src/lib.rs @@ -7,6 +7,7 @@ pub trait PlanarHandle where Self: bevy::ecs::component::Component, Self: bevy::render::extract_component::ExtractComponent, + Self: Clone, T: bevy::asset::Asset, { fn handle(&self) -> &bevy::asset::Handle; diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 5f3ac1e..b44c406 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.5.0" +version = "0.5.1" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,7 +13,7 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.5.0" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.5.1" } bytemuck = "1.14" convert_case = "0.6" proc-macro2 = "1.0" From 5c79f810529364e14849303ffc938ca199c3c8f1 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 23:39:42 -0600 Subject: [PATCH 13/24] fix: bevy_gaussian_splatting alignment --- Cargo.toml | 2 +- README.md | 60 +++++-------------- crates/bevy_interleave_interface/Cargo.toml | 2 +- crates/bevy_interleave_interface/src/lib.rs | 21 ++++++- .../bevy_interleave_interface/src/storage.rs | 6 +- crates/bevy_interleave_macros/Cargo.toml | 2 +- .../src/bindings/storage.rs | 4 ++ 7 files changed, 42 insertions(+), 55 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 05d8838..7c2a957 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.5.1" +version = "0.6.0" edition = "2021" authors = ["mosure "] license = "MIT" diff --git a/README.md b/README.md index 177acaf..d503287 100644 --- a/README.md +++ b/README.md @@ -5,19 +5,28 @@ [![GitHub Issues](https://img.shields.io/github/issues/mosure/bevy_interleave)](https://github.com/mosure/bevy_interleave/issues) [![crates.io](https://img.shields.io/crates/v/bevy_interleave.svg)](https://crates.io/crates/bevy_interleave) -bevy support for e2e packed to planar bind groups (e.g. statically typed meshes) +bevy static bind group api (e.g. statically typed meshes) +## features + +- [x] storage/texture bind group automation +- [x] packed -> planar main world representation /w serialization +- [x] packed -> planar storage/texture GPU representation +- [x] derive macro automation + ## minimal example ```rust use bevy_interleave::prelude::*; + #[derive( Debug, Planar, ReflectInterleaved, StorageBindings, + TextureBindings, )] pub struct MyStruct { #[texture_format(TextureFormat::R32Sint)] @@ -33,17 +42,15 @@ pub struct MyStruct { pub array: [u32; 4], } -fn interleaved() -> Vec { - vec![ + +fn main() { + let interleaved = vec![ MyStruct { field: 0, field2: 1_u32, bool_field: true, array: [0, 1, 2, 3] }, MyStruct { field: 2, field2: 3_u32, bool_field: false, array: [4, 5, 6, 7] }, MyStruct { field: 4, field2: 5_u32, bool_field: true, array: [8, 9, 10, 11] }, ]; -} -fn main() { - // TODO: add unzip implementation for Vec `let planar = interleaved().unzip()` - let planar = PlanarMyStruct::from_interleaved(interleaved()); + let planar = PlanarMyStruct::from_interleaved(interleaved); println!("{:?}", planar.field); println!("{:?}", planar.field2); @@ -62,46 +69,9 @@ fn main() { // Prints: // [4, 4, 1, 16] // ["field", "field2", "bool_field", "array"] - - - let mut app = App::new() - .add_plugins(( - DefaultPlugins, - PlanarPlugin::::default(), - PlanarTexturePlugin::::default(), - )); - - app.sub_app_mut(bevy::render::RenderApp) - .add_systems( - bevy::render::Render, - check_bind_group.in_set(bevy::render::RenderSet::QueueMeshes), - ); - - app.run(); -} - -fn setup_planar_asset( - mut commands: Commands, - mut planar_assets: ResMut>, -) { - let planar = PlanarMyStruct::from_interleaved(interleaved()); - - commands.spawn(planar_assets.add(planar)); -} - -fn check_bind_group( - bind_group: Query<&PlanarTextureBindGroup::>, -) { - // attach bind group to render pipeline - // size: - // 2 x 2 x bpp - // format: - // binding: 0 - texture - R32Sint - depth 1 - // binding: 1 - texture - R32Uint - depth 1 - // binding: 2 - texture - R8Unorm - depth 1 - // binding: 3 - texture - Rgba32Uint - depth 1 } +// TODO: gpu node binding example, see bevy_gaussian_splatting ``` diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index b492715..2604d3e 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.5.1" +version = "0.6.0" edition = "2021" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_interface/src/lib.rs b/crates/bevy_interleave_interface/src/lib.rs index 65cf7c8..f0fdd84 100644 --- a/crates/bevy_interleave_interface/src/lib.rs +++ b/crates/bevy_interleave_interface/src/lib.rs @@ -8,15 +8,23 @@ where Self: bevy::ecs::component::Component, Self: bevy::render::extract_component::ExtractComponent, Self: Clone, + Self: Default, + Self: bevy::reflect::FromReflect, + Self: bevy::reflect::GetTypeRegistration, + Self: bevy::reflect::Reflect, T: bevy::asset::Asset, { fn handle(&self) -> &bevy::asset::Handle; } +// #[cfg(feature = "debug_gpu")] +// pub debug_gpu: PlanarType, +// TODO: when `debug_gpu` feature is enabled, add a function to access the main -> render world copied asset (for ease of test writing) pub trait GpuPlanarStorage { type PackedType; fn len(&self) -> usize; + fn draw_indirect_buffer(&self) -> &bevy::render::render_resource::Buffer; fn bind_group( &self, @@ -30,7 +38,14 @@ pub trait GpuPlanarStorage { ) -> bevy::render::render_resource::BindGroupLayout; } -pub trait PlanarStorage { +pub trait PlanarStorage +where + Self: Default, + Self: Send, + Self: Sync, + Self: bevy::reflect::Reflect, + Self: 'static, +{ type PackedType; // Self type PlanarType: bevy::asset::Asset + bevy::reflect::GetTypeRegistration + bevy::reflect::FromReflect; type PlanarTypeHandle: PlanarHandle; @@ -78,7 +93,9 @@ pub trait Planar { type PackedType; fn get(&self, index: usize) -> Self::PackedType; - fn is_empty(&self) -> bool; + fn is_empty(&self) -> bool { + self.len() == 0 + } fn len(&self) -> usize; fn set(&mut self, index: usize, value: Self::PackedType); fn to_interleaved(&self) -> Vec; diff --git a/crates/bevy_interleave_interface/src/storage.rs b/crates/bevy_interleave_interface/src/storage.rs index 4a7cd0f..63502b1 100644 --- a/crates/bevy_interleave_interface/src/storage.rs +++ b/crates/bevy_interleave_interface/src/storage.rs @@ -32,6 +32,7 @@ where app.register_type::(); app.register_type::(); + app.register_type::(); app.init_asset::(); app.register_asset_reflect::(); @@ -104,20 +105,15 @@ where { let layout = &bind_group_layout.bind_group_layout; - info!("queue_gpu_storage_buffers"); - for (entity, planar_handle,) in clouds.iter() { - info!("handle {:?}", planar_handle.handle()); if let Some(load_state) = asset_server.get_load_state(planar_handle.handle()) { if load_state.is_loading() { - info!("loading"); continue; } } if gpu_planars.get(planar_handle.handle()).is_none() { - info!("no gpu planar"); continue; } diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index b44c406..578ea3f 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.5.1" +version = "0.6.0" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index 051ea97..0f6a9d6 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -115,6 +115,10 @@ pub fn storage_bindings(input: &DeriveInput) -> Result &bevy::render::render_resource::Buffer { + return &self.draw_indirect_buffer; + } + #bind_group #bind_group_layout } From 4b973164046dd3bcb8fc9a423f76626402f8c315 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 23:41:49 -0600 Subject: [PATCH 14/24] fix: bump versions --- crates/bevy_interleave_macros/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 578ea3f..1fa2760 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -13,7 +13,7 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.5.1" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.6.0" } bytemuck = "1.14" convert_case = "0.6" proc-macro2 = "1.0" From 8139aa3bd9e9713e4aed8d68163fa48606ee7536 Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 28 Dec 2024 23:43:35 -0600 Subject: [PATCH 15/24] fix: minimal example --- Cargo.toml | 4 ++-- README.md | 5 +++++ examples/minimal.rs | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 7c2a957..774bf17 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,8 +29,8 @@ members = [ [dependencies] -bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.5" } -bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.5" } +bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.6" } +bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.6" } bytemuck = "1.21" serde = "1.0" wgpu = "23.0.1" diff --git a/README.md b/README.md index d503287..f8d13b4 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,16 @@ bevy static bind group api (e.g. statically typed meshes) ## minimal example ```rust +use bevy::prelude::*; use bevy_interleave::prelude::*; #[derive( + Clone, Debug, + Default, Planar, + Reflect, ReflectInterleaved, StorageBindings, TextureBindings, @@ -71,6 +75,7 @@ fn main() { // ["field", "field2", "bool_field", "array"] } + // TODO: gpu node binding example, see bevy_gaussian_splatting ``` diff --git a/examples/minimal.rs b/examples/minimal.rs index 6a88d96..9bdd58b 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -1,9 +1,13 @@ +use bevy::prelude::*; use bevy_interleave::prelude::*; #[derive( + Clone, Debug, + Default, Planar, + Reflect, ReflectInterleaved, StorageBindings, TextureBindings, From 66f685d08b3f457313e37c07a002579c73e3b8c4 Mon Sep 17 00:00:00 2001 From: mosure Date: Sun, 29 Dec 2024 16:17:55 -0600 Subject: [PATCH 16/24] fix: sync to render world --- Cargo.toml | 2 +- crates/bevy_interleave_interface/Cargo.toml | 2 +- crates/bevy_interleave_interface/src/lib.rs | 1 - crates/bevy_interleave_interface/src/storage.rs | 5 ++--- crates/bevy_interleave_macros/Cargo.toml | 4 ++-- crates/bevy_interleave_macros/src/planar.rs | 3 ++- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 774bf17..e28cce1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.6.0" +version = "0.6.1" edition = "2021" authors = ["mosure "] license = "MIT" diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index 2604d3e..87157a3 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.6.0" +version = "0.6.1" edition = "2021" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_interface/src/lib.rs b/crates/bevy_interleave_interface/src/lib.rs index f0fdd84..4740e18 100644 --- a/crates/bevy_interleave_interface/src/lib.rs +++ b/crates/bevy_interleave_interface/src/lib.rs @@ -6,7 +6,6 @@ pub mod texture; pub trait PlanarHandle where Self: bevy::ecs::component::Component, - Self: bevy::render::extract_component::ExtractComponent, Self: Clone, Self: Default, Self: bevy::reflect::FromReflect, diff --git a/crates/bevy_interleave_interface/src/storage.rs b/crates/bevy_interleave_interface/src/storage.rs index 63502b1..9137830 100644 --- a/crates/bevy_interleave_interface/src/storage.rs +++ b/crates/bevy_interleave_interface/src/storage.rs @@ -3,7 +3,6 @@ use std::marker::PhantomData; use bevy::{ prelude::*, reflect::GetTypeRegistration, - render::extract_component::ExtractComponentPlugin, }; use crate::{ @@ -37,7 +36,7 @@ where app.register_asset_reflect::(); app.add_plugins(bevy::render::render_asset::RenderAssetPlugin::::default()); - app.add_plugins(ExtractComponentPlugin::::default()); + // app.add_plugins(ExtractComponentPlugin::::default()); let render_app = app.sub_app_mut(bevy::render::RenderApp); render_app.add_systems( @@ -93,7 +92,7 @@ fn queue_gpu_storage_buffers( bind_group_layout: Res>, clouds: Query< ( - Entity, + bevy::prelude::Entity, &R::PlanarTypeHandle, ), Without>, diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 1fa2760..237a3ac 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.6.0" +version = "0.6.1" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,7 +13,7 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.6.0" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.6.1" } bytemuck = "1.14" convert_case = "0.6" proc-macro2 = "1.0" diff --git a/crates/bevy_interleave_macros/src/planar.rs b/crates/bevy_interleave_macros/src/planar.rs index 837670d..385b6b1 100644 --- a/crates/bevy_interleave_macros/src/planar.rs +++ b/crates/bevy_interleave_macros/src/planar.rs @@ -59,7 +59,8 @@ pub fn generate_planar_struct(input: &DeriveInput) -> Result); impl bevy_interleave::interface::PlanarHandle<#planar_name> for #planar_handle_name { From 8ae0348f74d1257f6310596886c0eb3f7aff210a Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 11 Jan 2025 11:39:47 -0600 Subject: [PATCH 17/24] feat: GpuPlanar abstraction --- crates/bevy_interleave_interface/src/lib.rs | 91 +++++++++++++------ .../bevy_interleave_interface/src/storage.rs | 25 +++-- .../bevy_interleave_interface/src/texture.rs | 32 ++++--- .../src/bindings/storage.rs | 7 +- .../src/bindings/texture.rs | 56 +++++++++--- examples/minimal.rs | 10 +- src/prelude.rs | 13 +-- 7 files changed, 159 insertions(+), 75 deletions(-) diff --git a/crates/bevy_interleave_interface/src/lib.rs b/crates/bevy_interleave_interface/src/lib.rs index 4740e18..6ae84aa 100644 --- a/crates/bevy_interleave_interface/src/lib.rs +++ b/crates/bevy_interleave_interface/src/lib.rs @@ -1,8 +1,7 @@ pub mod storage; -pub mod texture; +// pub mod texture; -// TODO: this needs to be refactored and better structured pub trait PlanarHandle where Self: bevy::ecs::component::Component, @@ -16,13 +15,47 @@ where fn handle(&self) -> &bevy::asset::Handle; } -// #[cfg(feature = "debug_gpu")] -// pub debug_gpu: PlanarType, -// TODO: when `debug_gpu` feature is enabled, add a function to access the main -> render world copied asset (for ease of test writing) -pub trait GpuPlanarStorage { + +// TODO: migrate to PlanarSync +pub trait PlanarSync +where + Self: Default, + Self: Send, + Self: Sync, + Self: bevy::reflect::Reflect, + Self: 'static, +{ + type PackedType; // Self + type PlanarType: Planar; + type PlanarTypeHandle: PlanarHandle; + type GpuPlanarType: GpuPlanar< + PackedType = Self::PackedType, + PlanarType = Self::PlanarType, + >; +} + + +pub trait GpuPlanar +where + Self: bevy::render::render_asset::RenderAsset, +{ type PackedType; + type PlanarType; + fn is_empty(&self) -> bool { + self.len() == 0 + } fn len(&self) -> usize; +} + +// #[cfg(feature = "debug_gpu")] +// pub debug_gpu: PlanarType, +// TODO: when `debug_gpu` feature is enabled, add a function to access the main -> render world copied asset (for ease of test writing) +pub trait GpuPlanarStorage +where + Self: GpuPlanar, + Self: bevy::render::render_asset::RenderAsset, +{ fn draw_indirect_buffer(&self) -> &bevy::render::render_resource::Buffer; fn bind_group( @@ -37,29 +70,13 @@ pub trait GpuPlanarStorage { ) -> bevy::render::render_resource::BindGroupLayout; } -pub trait PlanarStorage -where - Self: Default, - Self: Send, - Self: Sync, - Self: bevy::reflect::Reflect, - Self: 'static, -{ - type PackedType; // Self - type PlanarType: bevy::asset::Asset + bevy::reflect::GetTypeRegistration + bevy::reflect::FromReflect; - type PlanarTypeHandle: PlanarHandle; - type GpuPlanarType: GpuPlanarStorage + bevy::render::render_asset::RenderAsset; -} -// TODO: refactor planar texture to be more like planar storage -pub trait PlanarTexture { - type PackedType; // Self - type PlanarType: bevy::asset::Asset; - type PlanarTypeHandle: PlanarHandle; - - // note: planar texture's gpu type utilizes bevy's image render asset - +pub trait GpuPlanarTexture +where + Self: GpuPlanar, + Self: bevy::render::render_asset::RenderAsset, +{ fn bind_group( &self, render_device: &bevy::render::renderer::RenderDevice, @@ -71,15 +88,26 @@ pub trait PlanarTexture { render_device: &bevy::render::renderer::RenderDevice, ) -> bevy::render::render_resource::BindGroupLayout; + fn get_asset_handles(&self) -> Vec>; +} + + +// TODO: find a better name, PlanarTexture is implemented on the packed type +pub trait PlanarTexture +where + Self: PlanarSync, +{ + // note: planar texture's gpu type utilizes bevy's image render asset fn prepare( images: &mut bevy::asset::Assets, planar: &Self::PlanarType, - ) -> Self; + ) -> Self::GpuPlanarType; fn get_asset_handles(&self) -> Vec>; } + pub trait ReflectInterleaved { type PackedType; @@ -88,7 +116,12 @@ pub trait ReflectInterleaved { } -pub trait Planar { +pub trait Planar +where + Self: bevy::asset::Asset, + Self: bevy::reflect::GetTypeRegistration, + Self: bevy::reflect::FromReflect, +{ type PackedType; fn get(&self, index: usize) -> Self::PackedType; diff --git a/crates/bevy_interleave_interface/src/storage.rs b/crates/bevy_interleave_interface/src/storage.rs index 9137830..58c02ce 100644 --- a/crates/bevy_interleave_interface/src/storage.rs +++ b/crates/bevy_interleave_interface/src/storage.rs @@ -8,7 +8,7 @@ use bevy::{ use crate::{ GpuPlanarStorage, PlanarHandle, - PlanarStorage, + PlanarSync, }; @@ -25,7 +25,8 @@ impl Default for PlanarStoragePlugin { impl Plugin for PlanarStoragePlugin where - R: PlanarStorage + Default + GetTypeRegistration + Clone + Reflect, + R: PlanarSync + Default + GetTypeRegistration + Clone + Reflect, + R::GpuPlanarType: GpuPlanarStorage, { fn build(&self, app: &mut App) { app.register_type::(); @@ -53,14 +54,21 @@ where } +// TODO: migrate to PlanarLayouts #[derive(bevy::prelude::Resource)] -pub struct PlanarStorageLayouts { +pub struct PlanarStorageLayouts +where + R::GpuPlanarType: GpuPlanarStorage, +{ pub bind_group_layout: bevy::render::render_resource::BindGroupLayout, pub phantom: PhantomData R>, } -impl -FromWorld for PlanarStorageLayouts { +impl +FromWorld for PlanarStorageLayouts +where + R::GpuPlanarType: GpuPlanarStorage, +{ fn from_world(world: &mut World) -> Self { let render_device = world.resource::(); @@ -78,7 +86,7 @@ FromWorld for PlanarStorageLayouts { } #[derive(bevy::prelude::Component, Clone, Debug)] -pub struct PlanarStorageBindGroup { +pub struct PlanarStorageBindGroup { pub bind_group: bevy::render::render_resource::BindGroup, pub phantom: PhantomData R>, } @@ -99,8 +107,9 @@ fn queue_gpu_storage_buffers( >, ) where - R: PlanarStorage + Default + Clone + Reflect, + R: PlanarSync + Default + Clone + Reflect, R::PlanarType: Asset, + R::GpuPlanarType: GpuPlanarStorage, { let layout = &bind_group_layout.bind_group_layout; @@ -116,7 +125,7 @@ where continue; } - let gpu_planar: &::GpuPlanarType = gpu_planars.get(planar_handle.handle()).unwrap(); + let gpu_planar: &::GpuPlanarType = gpu_planars.get(planar_handle.handle()).unwrap(); let bind_group = gpu_planar.bind_group( &render_device, layout, diff --git a/crates/bevy_interleave_interface/src/texture.rs b/crates/bevy_interleave_interface/src/texture.rs index 389f26c..c839def 100644 --- a/crates/bevy_interleave_interface/src/texture.rs +++ b/crates/bevy_interleave_interface/src/texture.rs @@ -10,8 +10,7 @@ use bevy::{ }; use crate::{ - PlanarHandle, - PlanarTexture, + GpuPlanarTexture, PlanarHandle, PlanarTexture }; @@ -30,6 +29,7 @@ impl Plugin for PlanarTexturePlugin where R: PlanarTexture + Default + Component + ExtractComponent + GetTypeRegistration + Clone + Reflect, R::PlanarType: Asset, + R::GpuPlanarType: GpuPlanarTexture, { fn build(&self, app: &mut App) { app.register_type::(); @@ -54,17 +54,24 @@ where #[derive(bevy::prelude::Resource)] -pub struct PlanarTextureLayouts { +pub struct PlanarTextureLayouts +where + R: PlanarTexture + Default + Component + ExtractComponent + GetTypeRegistration + Clone + Reflect, + R::GpuPlanarType: GpuPlanarTexture, +{ pub bind_group_layout: bevy::render::render_resource::BindGroupLayout, pub phantom: PhantomData R>, } -impl -FromWorld for PlanarTextureLayouts { +impl FromWorld for PlanarTextureLayouts +where + R: PlanarTexture + Default + Component + ExtractComponent + GetTypeRegistration + Clone + Reflect, + R::GpuPlanarType: GpuPlanarTexture, +{ fn from_world(world: &mut World) -> Self { let render_device = world.resource::(); - let bind_group_layout = R::bind_group_layout( + let bind_group_layout = R::GpuPlanarType::bind_group_layout( render_device, ); @@ -76,6 +83,7 @@ FromWorld for PlanarTextureLayouts { } +// TODO: utilize asset prepare workflow fn prepare_textures( mut commands: Commands, asset_server: Res, @@ -92,6 +100,7 @@ fn prepare_textures( where R: PlanarTexture + Default + Component + ExtractComponent + GetTypeRegistration + Clone + Reflect, R::PlanarType: Asset, + R::GpuPlanarType: GpuPlanarTexture, { for (entity, cloud_handle) in clouds.iter() { if let Some(load_state) = asset_server.get_load_state(cloud_handle.handle()) { @@ -105,12 +114,12 @@ where } let cloud = cloud_res.get(cloud_handle.handle()).unwrap(); + let buffers = R::prepare(&mut images, cloud); - let buffers = R::prepare( - &mut images, - cloud, - ); - + // TODO: the flow is: + // 1. given a planar asset handle, prepare main world image buffers insert handles into main world + // 2. copy the main world struct directly to gpu world via extract component + // 3. utilize gpu_planar_type to handle both main and gpu world handles commands.entity(entity).insert(buffers); } } @@ -139,6 +148,7 @@ fn queue_gpu_texture_buffers( where R: PlanarTexture + Default + Component + ExtractComponent + GetTypeRegistration + Clone + Reflect, R::PlanarType: Asset, + R::GpuPlanarType: GpuPlanarTexture, { let layout = &bind_group_layout.bind_group_layout; diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index 0f6a9d6..18ade78 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -108,13 +108,16 @@ pub fn storage_bindings(input: &DeriveInput) -> Result usize { self.count } + } + impl GpuPlanarStorage for #gpu_planar_name { fn draw_indirect_buffer(&self) -> &bevy::render::render_resource::Buffer { return &self.draw_indirect_buffer; } @@ -123,7 +126,7 @@ pub fn storage_bindings(input: &DeriveInput) -> Result Result, + ) -> Result> { + let count = source.len(); - type QueryFilter = (); - type Out = Self; + Ok(Self { + count, + + #(#handle_clones),* + }) + } - fn extract_component(texture_buffers: bevy::ecs::query::QueryItem<'_, Self::QueryData>) -> Option { - texture_buffers.clone().into() + fn asset_usage(_: &Self::SourceAsset) -> bevy::render::render_asset::RenderAssetUsages { + bevy::render::render_asset::RenderAssetUsages::default() } } - impl PlanarTexture for #gpu_planar_name { + impl GpuPlanarTexture for #gpu_planar_name { type PackedType = #name; - type PlanarType = #planar_name; - type PlanarTypeHandle = #planar_handle_name; + + fn len(&self) -> usize { + self.count + } #bind_group #bind_group_layout - #prepare #get_asset_handles } + + impl PlanarTexture for #name { + type PackedType = #name; + type PlanarType = #planar_name; + type PlanarTypeHandle = #planar_handle_name; + type GpuPlanarType = #gpu_planar_name; + + #get_asset_handles + #prepare + } }; Ok(expanded) @@ -191,13 +219,13 @@ pub fn generate_prepare_method(fields_named: &FieldsNamed) -> quote::__private:: let field_type = &field.ty; quote! { - let square = (planar.#name.len() as f32).sqrt().ceil() as u32; + let square = (self.#name.len() as f32).sqrt().ceil() as u32; let size = std::mem::size_of::<#field_type>(); let format_bpp = #format.pixel_size(); let depth = (size as f32 / format_bpp as f32).ceil() as u32; - let mut data = bytemuck::cast_slice(planar.#name.as_slice()).to_vec(); + let mut data = bytemuck::cast_slice(self.#name.as_slice()).to_vec(); let padded_size = (square * square * depth * format_bpp as u32) as usize; data.resize(padded_size, 0); @@ -226,8 +254,8 @@ pub fn generate_prepare_method(fields_named: &FieldsNamed) -> quote::__private:: quote! { fn prepare( + &self, images: &mut bevy::asset::Assets, - planar: &Self::PlanarType, ) -> Self { #(#buffers)* diff --git a/examples/minimal.rs b/examples/minimal.rs index 9bdd58b..7a70872 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -10,19 +10,19 @@ use bevy_interleave::prelude::*; Reflect, ReflectInterleaved, StorageBindings, - TextureBindings, + // TextureBindings, )] pub struct MyStruct { - #[texture_format(TextureFormat::R32Sint)] + // #[texture_format(TextureFormat::R32Sint)] pub field: i32, - #[texture_format(TextureFormat::R32Uint)] + // #[texture_format(TextureFormat::R32Uint)] pub field2: u32, - #[texture_format(TextureFormat::R8Unorm)] + // #[texture_format(TextureFormat::R8Unorm)] pub bool_field: bool, - #[texture_format(TextureFormat::Rgba32Uint)] + // #[texture_format(TextureFormat::Rgba32Uint)] pub array: [u32; 4], } diff --git a/src/prelude.rs b/src/prelude.rs index e0fa61b..1ee2a8f 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -2,21 +2,22 @@ pub use bevy::render::render_resource::TextureFormat; pub use bevy::image::TextureFormatPixelInfo; pub use crate::interface::{ + GpuPlanar, GpuPlanarStorage, Planar, PlanarHandle, - PlanarStorage, + PlanarSync, PlanarTexture, storage::{ PlanarStorageBindGroup, PlanarStorageLayouts, PlanarStoragePlugin, }, - texture::{ - PlanarTextureBindGroup, - PlanarTextureLayouts, - PlanarTexturePlugin, - }, + // texture::{ + // PlanarTextureBindGroup, + // PlanarTextureLayouts, + // PlanarTexturePlugin, + // }, ReflectInterleaved, }; From 4a1b42252bf6c796e32b6d4e7c77dc8ec192a7ce Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 3 May 2025 10:23:52 -0500 Subject: [PATCH 18/24] feat: bevy 0.16 --- Cargo.toml | 12 ++++++------ README.md | 1 + crates/bevy_interleave_interface/Cargo.toml | 4 ++-- crates/bevy_interleave_macros/Cargo.toml | 10 +++++----- .../bevy_interleave_macros/src/bindings/storage.rs | 13 +++++++------ .../bevy_interleave_macros/src/bindings/texture.rs | 11 ++++++----- crates/bevy_interleave_macros/src/planar.rs | 4 ++-- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e28cce1..2205b66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.6.1" -edition = "2021" +version = "0.7.0" +edition = "2024" authors = ["mosure "] license = "MIT" keywords = [ @@ -29,14 +29,14 @@ members = [ [dependencies] -bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.6" } -bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.6" } -bytemuck = "1.21" +bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.7" } +bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.7" } +bytemuck = "1.23" serde = "1.0" wgpu = "23.0.1" [dependencies.bevy] -version = "0.15" +version = "0.16" default-features = false features = ["bevy_asset", "bevy_render", "png"] diff --git a/README.md b/README.md index f8d13b4..dfb803e 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ fn main() { | `bevy_interleave` | `bevy` | | :-- | :-- | +| `0.7` | `0.16` | | `0.3` | `0.15` | | `0.2` | `0.13` | | `0.1` | `0.12` | diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index 87157a3..b871e20 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.6.1" +version = "0.7.0" edition = "2021" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,6 +13,6 @@ keywords = [ [dependencies.bevy] -version = "0.15" +version = "0.16" default-features = false features = ["bevy_asset", "bevy_render", "png"] diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 237a3ac..26978ff 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.6.1" +version = "0.7.0" edition = "2021" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,17 +13,17 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.6.1" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.7.0" } bytemuck = "1.14" -convert_case = "0.6" +convert_case = "0.8" proc-macro2 = "1.0" quote = "1.0" sha1 = "0.10" syn = "2.0" -wgpu = "23.0.1" +wgpu = "24" [dependencies.bevy] -version = "0.15" +version = "0.16" default-features = false features = ["bevy_asset", "bevy_render", "png"] diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index 18ade78..2bab6ff 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -17,9 +17,9 @@ use syn::{ pub fn storage_bindings(input: &DeriveInput) -> Result { let name = &input.ident; - let planar_name = Ident::new(&format!("Planar{}", name), name.span()); - let gpu_planar_name = Ident::new(&format!("PlanarStorage{}", name), name.span()); - let planar_handle_name = Ident::new(&format!("Planar{}Handle", name), name.span()); + let planar_name = Ident::new(&format!("Planar{name}"), name.span()); + let gpu_planar_name = Ident::new(&format!("PlanarStorage{name}"), name.span()); + let planar_handle_name = Ident::new(&format!("Planar{name}Handle"), name.span()); let fields_struct = if let Data::Struct(ref data_struct) = input.data { match data_struct.fields { @@ -41,7 +41,7 @@ pub fn storage_bindings(input: &DeriveInput) -> Result Result, render_device: &mut bevy::ecs::system::SystemParamItem, ) -> Result> { let count = source.len(); @@ -140,7 +141,7 @@ pub fn storage_bindings(input: &DeriveInput) -> Result quote::__private::TokenStream { let struct_name_snake = struct_name.to_string().to_case(Case::Snake); - let bind_group_name = format!("storage_{}_bind_group", struct_name_snake); + let bind_group_name = format!("storage_{struct_name_snake}_bind_group"); let bind_group_entries = fields_named.named .iter() @@ -181,7 +182,7 @@ pub fn generate_bind_group_method(struct_name: &Ident, fields_named: &FieldsName pub fn generate_bind_group_layout_method(struct_name: &Ident, fields_named: &FieldsNamed) -> quote::__private::TokenStream { let struct_name_snake = struct_name.to_string().to_case(Case::Snake); - let bind_group_layout_name = format!("storage_{}_bind_group_layout", struct_name_snake); + let bind_group_layout_name = format!("storage_{struct_name_snake}_bind_group_layout"); let bind_group_layout_entries = fields_named.named .iter() diff --git a/crates/bevy_interleave_macros/src/bindings/texture.rs b/crates/bevy_interleave_macros/src/bindings/texture.rs index 48c30ae..189c03a 100644 --- a/crates/bevy_interleave_macros/src/bindings/texture.rs +++ b/crates/bevy_interleave_macros/src/bindings/texture.rs @@ -24,9 +24,9 @@ use syn::{ pub fn texture_bindings(input: &DeriveInput) -> Result { let name = &input.ident; - let planar_name = Ident::new(&format!("Planar{}", name), name.span()); - let gpu_planar_name = Ident::new(&format!("PlanarTexture{}", name), name.span()); - let planar_handle_name = Ident::new(&format!("Planar{}Handle", name), name.span()); + let planar_name = Ident::new(&format!("Planar{name}"), name.span()); + let gpu_planar_name = Ident::new(&format!("PlanarTexture{name}"), name.span()); + let planar_handle_name = Ident::new(&format!("Planar{name}Handle"), name.span()); let fields_struct = if let Data::Struct(ref data_struct) = input.data { match data_struct.fields { @@ -65,6 +65,7 @@ pub fn texture_bindings(input: &DeriveInput) -> Result, _: &mut bevy::ecs::system::SystemParamItem, ) -> Result> { let count = source.len(); @@ -110,7 +111,7 @@ pub fn texture_bindings(input: &DeriveInput) -> Result quote::__private::TokenStream { let struct_name_snake = struct_name.to_string().to_case(Case::Snake); - let bind_group_name = format!("texture_{}_bind_group", struct_name_snake); + let bind_group_name = format!("texture_{struct_name_snake}_bind_group"); let bind_group_entries = fields_named.named .iter() @@ -148,7 +149,7 @@ pub fn generate_bind_group_method(struct_name: &Ident, fields_named: &FieldsName pub fn generate_bind_group_layout_method(struct_name: &Ident, fields_named: &FieldsNamed) -> quote::__private::TokenStream { let struct_name_snake = struct_name.to_string().to_case(Case::Snake); - let bind_group_layout_name = format!("texture_{}_bind_group_layout", struct_name_snake); + let bind_group_layout_name = format!("texture_{struct_name_snake}_bind_group_layout"); let bind_group_layout_entries = fields_named.named .iter() diff --git a/crates/bevy_interleave_macros/src/planar.rs b/crates/bevy_interleave_macros/src/planar.rs index 385b6b1..7ed5c0b 100644 --- a/crates/bevy_interleave_macros/src/planar.rs +++ b/crates/bevy_interleave_macros/src/planar.rs @@ -12,8 +12,8 @@ use syn::{ pub fn generate_planar_struct(input: &DeriveInput) -> Result { let name = &input.ident; - let planar_name = Ident::new(&format!("Planar{}", name), name.span()); - let planar_handle_name = Ident::new(&format!("Planar{}Handle", name), name.span()); + let planar_name = Ident::new(&format!("Planar{name}"), name.span()); + let planar_handle_name = Ident::new(&format!("Planar{name}Handle"), name.span()); let fields_struct = if let Data::Struct(ref data_struct) = input.data { match data_struct.fields { From e8a675d7b6e4106181a35f964d0c229b777c0b1f Mon Sep 17 00:00:00 2001 From: mosure Date: Sat, 3 May 2025 14:38:54 -0500 Subject: [PATCH 19/24] fix: wgpu version --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2205b66..4d6da03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.7.0" +version = "0.7.1" edition = "2024" authors = ["mosure "] license = "MIT" @@ -33,7 +33,7 @@ bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.7" } bytemuck = "1.23" serde = "1.0" -wgpu = "23.0.1" +wgpu = "24" [dependencies.bevy] version = "0.16" From 3e0567d5b8ba56ad45f72997de67e2b2280b9889 Mon Sep 17 00:00:00 2001 From: MiniMinerX <111392588+MiniMinerX@users.noreply.github.com> Date: Thu, 8 May 2025 17:06:26 -0700 Subject: [PATCH 20/24] Dev 0.16 (#20) * fixed tomls * fixed test * try bevy features --- Cargo.toml | 4 ++-- crates/bevy_interleave_interface/Cargo.toml | 8 ++++---- crates/bevy_interleave_macros/Cargo.toml | 8 ++++---- test/lib.rs | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4d6da03..120c08b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,9 +36,9 @@ serde = "1.0" wgpu = "24" [dependencies.bevy] -version = "0.16" +version = "0.16.0" default-features = false -features = ["bevy_asset", "bevy_render", "png"] +features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index b871e20..c24ce57 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave_interface" -version = "0.7.0" -edition = "2021" +version = "0.7.1" +edition = "2024" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" repository = "https://github.com/mosure/bevy_interleave" @@ -13,6 +13,6 @@ keywords = [ [dependencies.bevy] -version = "0.16" +version = "0.16.0" default-features = false -features = ["bevy_asset", "bevy_render", "png"] +features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 26978ff..cca6aba 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave_macros" -version = "0.7.0" -edition = "2021" +version = "0.7.1" +edition = "2024" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" repository = "https://github.com/mosure/bevy_interleave" @@ -23,9 +23,9 @@ syn = "2.0" wgpu = "24" [dependencies.bevy] -version = "0.16" +version = "0.16.0" default-features = false -features = ["bevy_asset", "bevy_render", "png"] +features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] [lib] diff --git a/test/lib.rs b/test/lib.rs index f12dfd7..f4cad4a 100644 --- a/test/lib.rs +++ b/test/lib.rs @@ -71,7 +71,7 @@ fn test_timeout( *frame_count += 1; if *frame_count > 5 { - exit.send(bevy::app::AppExit::Success); + exit.write(bevy::app::AppExit::Success); } } From 7d5bee5ee7c491dd94769e0044608a42c71cfe4b Mon Sep 17 00:00:00 2001 From: mosure Date: Thu, 8 May 2025 20:00:11 -0500 Subject: [PATCH 21/24] fix: tests --- Cargo.toml | 13 ++++++++ .../bevy_interleave_interface/src/storage.rs | 31 ++++++++++++++++++- crates/bevy_interleave_macros/src/planar.rs | 2 +- test/lib.rs | 22 +++++++++---- 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 120c08b..3f91aa1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,19 @@ default-features = false features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] +[dev-dependencies.bevy] +version = "0.16.0" +default-features = false +features = [ + "bevy_asset", + "bevy_render", + "bevy_winit", + "png", + "reflect_documentation", + "reflect_functions", +] + + [target.'cfg(target_arch = "wasm32")'.dependencies] console_error_panic_hook = "0.1" wasm-bindgen = "0.2" diff --git a/crates/bevy_interleave_interface/src/storage.rs b/crates/bevy_interleave_interface/src/storage.rs index 58c02ce..ba91cff 100644 --- a/crates/bevy_interleave_interface/src/storage.rs +++ b/crates/bevy_interleave_interface/src/storage.rs @@ -37,9 +37,13 @@ where app.register_asset_reflect::(); app.add_plugins(bevy::render::render_asset::RenderAssetPlugin::::default()); - // app.add_plugins(ExtractComponentPlugin::::default()); + app.add_plugins(bevy::render::sync_component::SyncComponentPlugin::::default()); let render_app = app.sub_app_mut(bevy::render::RenderApp); + render_app.add_systems( + bevy::render::ExtractSchedule, + extract_planar_handles::, + ); render_app.add_systems( bevy::render::Render, queue_gpu_storage_buffers::.in_set(bevy::render::RenderSet::PrepareBindGroups), @@ -92,6 +96,31 @@ pub struct PlanarStorageBindGroup { } +fn extract_planar_handles( + mut commands: Commands, + mut main_world: ResMut, +) +where + R: PlanarSync + Default + Clone + Reflect, + R::PlanarType: Asset, + R::GpuPlanarType: GpuPlanarStorage, +{ + let mut planar_handles_query = main_world.query::<( + bevy::render::sync_world::RenderEntity, + &R::PlanarTypeHandle, + )>(); + + for ( + entity, + planar_handle + ) in planar_handles_query.iter(&main_world) { + if let Ok(mut entity_commands) = commands.get_entity(entity) { + entity_commands.insert(planar_handle.clone()); + } + } +} + + fn queue_gpu_storage_buffers( mut commands: Commands, asset_server: Res, diff --git a/crates/bevy_interleave_macros/src/planar.rs b/crates/bevy_interleave_macros/src/planar.rs index 7ed5c0b..7ff0326 100644 --- a/crates/bevy_interleave_macros/src/planar.rs +++ b/crates/bevy_interleave_macros/src/planar.rs @@ -60,7 +60,7 @@ pub fn generate_planar_struct(input: &DeriveInput) -> Result); impl bevy_interleave::interface::PlanarHandle<#planar_name> for #planar_handle_name { diff --git a/test/lib.rs b/test/lib.rs index f4cad4a..f55e559 100644 --- a/test/lib.rs +++ b/test/lib.rs @@ -1,8 +1,12 @@ use std::sync::{Arc, Mutex}; -use bevy::prelude::*; +use bevy::{ + prelude::*, + winit::{WakeUp, WinitPlugin}, +}; use bevy_interleave::prelude::*; + #[derive( Clone, Debug, @@ -30,6 +34,7 @@ pub struct MyStruct { #[derive(Resource, Default)] struct TestSuccess(Arc>); + fn setup_planar( mut commands: Commands, mut gaussian_assets: ResMut>, @@ -42,6 +47,7 @@ fn setup_planar( let planar_handle = gaussian_assets.add(planar); + println!("spawned planar with handle: {:?}", planar_handle.clone()); commands.spawn(PlanarMyStructHandle(planar_handle)); } @@ -80,12 +86,16 @@ fn test_timeout( fn texture_bind_group() { let mut app = App::new(); - app.add_plugins( + let mut winit_plugin = WinitPlugin::::default(); + winit_plugin.run_on_any_thread = true; + + app.add_plugins(( DefaultPlugins - .set(bevy::app::ScheduleRunnerPlugin::run_loop( - std::time::Duration::from_millis(50) - )), - ); + .set(winit_plugin), + bevy::app::ScheduleRunnerPlugin::run_loop( + std::time::Duration::from_millis(50) + ), + )); app.add_plugins( PlanarStoragePlugin::::default(), // PlanarTexturePlugin::::default(), From 5fe701318dcd8dbe9d52bdb946e72b87bddec11a Mon Sep 17 00:00:00 2001 From: mosure Date: Thu, 8 May 2025 20:02:43 -0500 Subject: [PATCH 22/24] chore: bump all versions --- Cargo.toml | 6 +++--- crates/bevy_interleave_interface/Cargo.toml | 4 ++-- crates/bevy_interleave_macros/Cargo.toml | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3f91aa1..a46164b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.7.1" +version = "0.7.2" edition = "2024" authors = ["mosure "] license = "MIT" @@ -36,13 +36,13 @@ serde = "1.0" wgpu = "24" [dependencies.bevy] -version = "0.16.0" +version = "0.16" default-features = false features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] [dev-dependencies.bevy] -version = "0.16.0" +version = "0.16" default-features = false features = [ "bevy_asset", diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index c24ce57..c2d3be6 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.7.1" +version = "0.7.2" edition = "2024" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,6 +13,6 @@ keywords = [ [dependencies.bevy] -version = "0.16.0" +version = "0.16" default-features = false features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index cca6aba..484f4d2 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.7.1" +version = "0.7.2" edition = "2024" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,7 +13,7 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.7.0" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.7.2" } bytemuck = "1.14" convert_case = "0.8" proc-macro2 = "1.0" @@ -23,7 +23,7 @@ syn = "2.0" wgpu = "24" [dependencies.bevy] -version = "0.16.0" +version = "0.16" default-features = false features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] From 622b038f9610be92a12fb82e2de0c513643c7c3d Mon Sep 17 00:00:00 2001 From: victor atasie <52110451+cs50victor@users.noreply.github.com> Date: Fri, 3 Oct 2025 09:04:36 -0700 Subject: [PATCH 23/24] chore: bump bevy (#21) * chore: bump version * chore: bump and lint fix * use x.x semver --- Cargo.toml | 4 ++-- crates/bevy_interleave_interface/Cargo.toml | 2 +- crates/bevy_interleave_interface/src/storage.rs | 10 +++++----- crates/bevy_interleave_macros/Cargo.toml | 2 +- crates/bevy_interleave_macros/src/bindings/storage.rs | 5 +++-- crates/bevy_interleave_macros/src/bindings/texture.rs | 5 +++-- test/lib.rs | 5 +++-- 7 files changed, 18 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a46164b..cfb3779 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,13 +36,13 @@ serde = "1.0" wgpu = "24" [dependencies.bevy] -version = "0.16" +version = "0.17" default-features = false features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] [dev-dependencies.bevy] -version = "0.16" +version = "0.17" default-features = false features = [ "bevy_asset", diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index c2d3be6..883b420 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -13,6 +13,6 @@ keywords = [ [dependencies.bevy] -version = "0.16" +version = "0.17" default-features = false features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] diff --git a/crates/bevy_interleave_interface/src/storage.rs b/crates/bevy_interleave_interface/src/storage.rs index ba91cff..2487078 100644 --- a/crates/bevy_interleave_interface/src/storage.rs +++ b/crates/bevy_interleave_interface/src/storage.rs @@ -46,7 +46,7 @@ where ); render_app.add_systems( bevy::render::Render, - queue_gpu_storage_buffers::.in_set(bevy::render::RenderSet::PrepareBindGroups), + queue_gpu_storage_buffers::.in_set(bevy::render::RenderSystems::PrepareBindGroups), ); } @@ -144,10 +144,10 @@ where for (entity, planar_handle,) in clouds.iter() { - if let Some(load_state) = asset_server.get_load_state(planar_handle.handle()) { - if load_state.is_loading() { - continue; - } + if let Some(load_state) = asset_server.get_load_state(planar_handle.handle()) + && load_state.is_loading() + { + continue; } if gpu_planars.get(planar_handle.handle()).is_none() { diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 484f4d2..934ee04 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -23,7 +23,7 @@ syn = "2.0" wgpu = "24" [dependencies.bevy] -version = "0.16" +version = "0.17" default-features = false features = ["bevy_asset", "bevy_render", "png", "reflect_documentation", "reflect_functions"] diff --git a/crates/bevy_interleave_macros/src/bindings/storage.rs b/crates/bevy_interleave_macros/src/bindings/storage.rs index 2bab6ff..b271e0f 100644 --- a/crates/bevy_interleave_macros/src/bindings/storage.rs +++ b/crates/bevy_interleave_macros/src/bindings/storage.rs @@ -77,6 +77,7 @@ pub fn storage_bindings(input: &DeriveInput) -> Result, render_device: &mut bevy::ecs::system::SystemParamItem, + _: Option<&Self>, ) -> Result> { let count = source.len(); @@ -104,8 +105,8 @@ pub fn storage_bindings(input: &DeriveInput) -> Result bevy::render::render_asset::RenderAssetUsages { - bevy::render::render_asset::RenderAssetUsages::default() + fn asset_usage(_: &Self::SourceAsset) -> bevy::asset::RenderAssetUsages { + bevy::asset::RenderAssetUsages::default() } } diff --git a/crates/bevy_interleave_macros/src/bindings/texture.rs b/crates/bevy_interleave_macros/src/bindings/texture.rs index 189c03a..6868372 100644 --- a/crates/bevy_interleave_macros/src/bindings/texture.rs +++ b/crates/bevy_interleave_macros/src/bindings/texture.rs @@ -67,6 +67,7 @@ pub fn texture_bindings(input: &DeriveInput) -> Result, _: &mut bevy::ecs::system::SystemParamItem, + _: Option<&Self>, ) -> Result> { let count = source.len(); @@ -77,8 +78,8 @@ pub fn texture_bindings(input: &DeriveInput) -> Result bevy::render::render_asset::RenderAssetUsages { - bevy::render::render_asset::RenderAssetUsages::default() + fn asset_usage(_: &Self::SourceAsset) -> bevy::asset::RenderAssetUsages { + bevy::asset::RenderAssetUsages::default() } } diff --git a/test/lib.rs b/test/lib.rs index f55e559..2e747f3 100644 --- a/test/lib.rs +++ b/test/lib.rs @@ -71,7 +71,7 @@ fn check_storage_bind_group( } fn test_timeout( - mut exit: EventWriter, + mut exit: MessageWriter, mut frame_count: Local, ) { *frame_count += 1; @@ -83,6 +83,7 @@ fn test_timeout( #[test] +#[cfg_attr(target_os = "macos", ignore = "WinitPlugin cannot run on non-main thread on macOS")] fn texture_bind_group() { let mut app = App::new(); @@ -107,7 +108,7 @@ fn texture_bind_group() { render_app.add_systems( bevy::render::Render, ( - check_storage_bind_group.in_set(bevy::render::RenderSet::QueueMeshes), + check_storage_bind_group.in_set(bevy::render::RenderSystems::QueueMeshes), // check_texture_bind_group.in_set(bevy::render::RenderSet::QueueMeshes) ), ); From 25974be151701591a5bf36b432e5ee43ee923f41 Mon Sep 17 00:00:00 2001 From: mosure Date: Fri, 3 Oct 2025 11:37:57 -0500 Subject: [PATCH 24/24] chore: release 0.8 --- Cargo.toml | 8 ++++---- README.md | 1 + crates/bevy_interleave_interface/Cargo.toml | 2 +- crates/bevy_interleave_macros/Cargo.toml | 6 +++--- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cfb3779..9aa80dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_interleave" description = "bevy support for e2e packed to planar bind groups" -version = "0.7.2" +version = "0.8.0" edition = "2024" authors = ["mosure "] license = "MIT" @@ -29,11 +29,11 @@ members = [ [dependencies] -bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.7" } -bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.7" } +bevy_interleave_interface = { path = "crates/bevy_interleave_interface", version = "0.8" } +bevy_interleave_macros = { path = "crates/bevy_interleave_macros", version = "0.8" } bytemuck = "1.23" serde = "1.0" -wgpu = "24" +wgpu = "26" [dependencies.bevy] version = "0.17" diff --git a/README.md b/README.md index dfb803e..75fb4dc 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ fn main() { | `bevy_interleave` | `bevy` | | :-- | :-- | +| `0.8` | `0.17` | | `0.7` | `0.16` | | `0.3` | `0.15` | | `0.2` | `0.13` | diff --git a/crates/bevy_interleave_interface/Cargo.toml b/crates/bevy_interleave_interface/Cargo.toml index 883b420..8fa6a7e 100644 --- a/crates/bevy_interleave_interface/Cargo.toml +++ b/crates/bevy_interleave_interface/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_interface" -version = "0.7.2" +version = "0.8.0" edition = "2024" description = "interface for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" diff --git a/crates/bevy_interleave_macros/Cargo.toml b/crates/bevy_interleave_macros/Cargo.toml index 934ee04..8034092 100644 --- a/crates/bevy_interleave_macros/Cargo.toml +++ b/crates/bevy_interleave_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bevy_interleave_macros" -version = "0.7.2" +version = "0.8.0" edition = "2024" description = "macros for e2e packed to planar bind groups" homepage = "https://github.com/mosure/bevy_interleave" @@ -13,14 +13,14 @@ keywords = [ [dependencies] -bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.7.2" } +bevy_interleave_interface = { path = "../bevy_interleave_interface", version = "0.8.0" } bytemuck = "1.14" convert_case = "0.8" proc-macro2 = "1.0" quote = "1.0" sha1 = "0.10" syn = "2.0" -wgpu = "24" +wgpu = "26" [dependencies.bevy] version = "0.17"