diff options
author | Silas Bartha <[email protected]> | 2024-06-03 21:39:43 -0400 |
---|---|---|
committer | Silas Bartha <[email protected]> | 2024-06-03 21:39:43 -0400 |
commit | ef6c2954156b2b0cf4abfe583d8faaf546f4e7c4 (patch) | |
tree | f5da21c83771023d55036ad94ee52d8db992ffbd | |
parent | 0ac133c0c396c8b75892cb6e43a52ad973046e2d (diff) |
Removed toolchain config
-rw-r--r-- | .cargo/config.toml | 34 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/components.rs | 19 | ||||
-rw-r--r-- | src/lib.rs | 28 | ||||
-rw-r--r-- | src/nodes.rs | 22 | ||||
-rw-r--r-- | src/render_assets.rs | 21 | ||||
-rw-r--r-- | src/systems.rs | 22 |
7 files changed, 74 insertions, 76 deletions
diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index 6563c2a..0000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,34 +0,0 @@ - -# Add the contents of this file to `config.toml` to enable "fast build" configuration. Please read the notes below. - -# NOTE: For maximum performance, build using a nightly compiler -# If you are using rust stable, remove the "-Zshare-generics=y" below. - -[target.x86_64-unknown-linux-gnu] -linker = "clang" -rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"] - -# NOTE: you must install [Mach-O LLD Port](https://lld.llvm.org/MachO/index.html) on mac. you can easily do this by installing llvm which includes lld with the "brew" package manager: -# `brew install llvm` -[target.x86_64-apple-darwin] -rustflags = [ - "-C", - "link-arg=-fuse-ld=/usr/local/opt/llvm/bin/ld64.lld", - "-Zshare-generics=y", -] - -[target.aarch64-apple-darwin] -rustflags = [ - "-C", - "link-arg=-fuse-ld=/opt/homebrew/opt/llvm/bin/ld64.lld", - "-Zshare-generics=y", -] - -[target.x86_64-pc-windows-msvc] -linker = "rust-lld.exe" -rustflags = ["-Zshare-generics=n"] - -# Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only' -# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains. -#[profile.dev] -#debug = 1 @@ -1,6 +1,6 @@ [package] -name = "grex_framebuffer_extract" -version = "0.1.1" +name = "bevy_framebuffer_extract" +version = "0.1.2" edition = "2021" [dependencies] diff --git a/src/components.rs b/src/components.rs index 3179f0c..c1122d0 100644 --- a/src/components.rs +++ b/src/components.rs @@ -1,6 +1,6 @@ -use std::sync::{Mutex, Arc}; +use std::sync::{Arc, Mutex}; -use bevy::{prelude::*, render::extract_component::ExtractComponent, ecs::query::QueryItem}; +use bevy::{ecs::query::QueryItem, prelude::*, render::extract_component::ExtractComponent}; use crate::render_assets::FramebufferExtractSource; @@ -8,20 +8,16 @@ use crate::render_assets::FramebufferExtractSource; pub struct FramebufferExtractDestination(pub Arc<Mutex<Image>>); impl ExtractComponent for FramebufferExtractDestination { - type QueryData = ( - &'static Self, - &'static Handle<FramebufferExtractSource>, - ); + type QueryData = (&'static Self, &'static Handle<FramebufferExtractSource>); type QueryFilter = (); type Out = (Self, Handle<FramebufferExtractSource>); - fn extract_component((destination, source_handle): QueryItem<'_, Self::QueryData>) -> Option<Self::Out> { - Some(( - destination.clone(), - source_handle.clone(), - )) + fn extract_component( + (destination, source_handle): QueryItem<'_, Self::QueryData>, + ) -> Option<Self::Out> { + Some((destination.clone(), source_handle.clone())) } } @@ -30,4 +26,3 @@ pub struct ExtractFramebufferBundle { pub source: Handle<FramebufferExtractSource>, pub dest: FramebufferExtractDestination, } - @@ -1,19 +1,24 @@ -use bevy::{prelude::*, render::{render_asset::RenderAssetPlugin, extract_component::ExtractComponentPlugin, RenderApp, Render, RenderSet, render_graph::RenderGraph, graph::CameraDriverLabel}}; +use bevy::{ + prelude::*, + render::{ + extract_component::ExtractComponentPlugin, graph::CameraDriverLabel, + render_asset::RenderAssetPlugin, render_graph::RenderGraph, Render, RenderApp, RenderSet, + }, +}; use components::FramebufferExtractDestination; -use nodes::{FramebufferExtractNode, FramebufferExtractLabel}; +use nodes::{FramebufferExtractLabel, FramebufferExtractNode}; use render_assets::FramebufferExtractSource; pub mod components; -mod systems; mod nodes; pub mod render_assets; +mod systems; pub struct FramebufferExtractPlugin; impl Plugin for FramebufferExtractPlugin { fn build(&self, app: &mut App) { - app - .register_type::<FramebufferExtractSource>() + app.register_type::<FramebufferExtractSource>() .init_asset::<FramebufferExtractSource>() .register_asset_reflect::<FramebufferExtractSource>() .add_plugins(( @@ -22,13 +27,12 @@ impl Plugin for FramebufferExtractPlugin { )); let render_app = app.sub_app_mut(RenderApp); - render_app - .add_systems( - Render, - systems::extract_framebuffers - .after(RenderSet::Render) - .before(RenderSet::Cleanup), - ); + render_app.add_systems( + Render, + systems::extract_framebuffers + .after(RenderSet::Render) + .before(RenderSet::Cleanup), + ); let mut graph = render_app.world.resource_mut::<RenderGraph>(); graph.add_node(FramebufferExtractLabel, FramebufferExtractNode); graph.add_node_edge(CameraDriverLabel, FramebufferExtractLabel); diff --git a/src/nodes.rs b/src/nodes.rs index d069798..9791ad1 100644 --- a/src/nodes.rs +++ b/src/nodes.rs @@ -1,4 +1,12 @@ -use bevy::{prelude::*, render::{render_graph::{Node, RenderGraphContext, NodeRunError, RenderLabel}, renderer::RenderContext, render_asset::RenderAssets, render_resource::{ImageCopyBuffer, ImageDataLayout}}}; +use bevy::{ + prelude::*, + render::{ + render_asset::RenderAssets, + render_graph::{Node, NodeRunError, RenderGraphContext, RenderLabel}, + render_resource::{ImageCopyBuffer, ImageDataLayout}, + renderer::RenderContext, + }, +}; use crate::render_assets::FramebufferExtractSource; @@ -15,9 +23,15 @@ impl Node for FramebufferExtractNode { render_context: &mut RenderContext, world: &World, ) -> Result<(), NodeRunError> { - for (_, source) in world.resource::<RenderAssets<FramebufferExtractSource>>().iter() { - let Some(gpu_image) = world.resource::<RenderAssets<Image>>().get(&source.source_handle) else { - return Ok(()) + for (_, source) in world + .resource::<RenderAssets<FramebufferExtractSource>>() + .iter() + { + let Some(gpu_image) = world + .resource::<RenderAssets<Image>>() + .get(&source.source_handle) + else { + return Ok(()); }; render_context.command_encoder().copy_texture_to_buffer( diff --git a/src/render_assets.rs b/src/render_assets.rs index 1615e01..0e2cd4d 100644 --- a/src/render_assets.rs +++ b/src/render_assets.rs @@ -1,4 +1,12 @@ -use bevy::{prelude::*, render::{render_asset::{RenderAsset, RenderAssets, RenderAssetUsages, PrepareAssetError}, render_resource::{Buffer, Extent3d, BufferUsages, BufferDescriptor, TextureFormat}, renderer::RenderDevice}, ecs::system::{lifetimeless::SRes, SystemParamItem}}; +use bevy::{ + ecs::system::{lifetimeless::SRes, SystemParamItem}, + prelude::*, + render::{ + render_asset::{PrepareAssetError, RenderAsset, RenderAssetUsages, RenderAssets}, + render_resource::{Buffer, BufferDescriptor, BufferUsages, Extent3d, TextureFormat}, + renderer::RenderDevice, + }, +}; pub struct GpuFramebufferExtractSource { pub buffer: Buffer, @@ -24,19 +32,20 @@ impl RenderAsset for FramebufferExtractSource { self, (device, images): &mut SystemParamItem<Self::Param>, ) -> Result<Self::PreparedAsset, PrepareAssetError<Self>> { - let Some(gpu_image) = images.get(&self.0) else { warn!("Failed to get GPU image"); - return Err(PrepareAssetError::RetryNextUpdate(self)) + return Err(PrepareAssetError::RetryNextUpdate(self)); }; let size = gpu_image.texture.size(); let format = gpu_image.texture_format; - let bytes_per_row = (size.width / format.block_dimensions().0) * format.block_copy_size(None).unwrap(); - let padded_bytes_per_row = RenderDevice::align_copy_bytes_per_row(bytes_per_row as usize) as u32; + let bytes_per_row = + (size.width / format.block_dimensions().0) * format.block_copy_size(None).unwrap(); + let padded_bytes_per_row = + RenderDevice::align_copy_bytes_per_row(bytes_per_row as usize) as u32; Ok(GpuFramebufferExtractSource { - buffer: device.create_buffer(&BufferDescriptor { + buffer: device.create_buffer(&BufferDescriptor { label: Some("framebuffer_extract_buffer"), size: (size.height * padded_bytes_per_row) as u64, usage: BufferUsages::COPY_DST | BufferUsages::MAP_READ, diff --git a/src/systems.rs b/src/systems.rs index 244b82f..74f8dc8 100644 --- a/src/systems.rs +++ b/src/systems.rs @@ -1,11 +1,21 @@ -use bevy::{prelude::*, render::{render_asset::{RenderAssets, RenderAssetUsages}, renderer::RenderDevice, render_resource::{MapMode, Maintain, Extent3d, TextureDimension}}}; +use bevy::{ + prelude::*, + render::{ + render_asset::{RenderAssetUsages, RenderAssets}, + render_resource::{Extent3d, Maintain, MapMode, TextureDimension}, + renderer::RenderDevice, + }, +}; use pollster::FutureExt; -use crate::{render_assets::FramebufferExtractSource, components::FramebufferExtractDestination}; +use crate::{components::FramebufferExtractDestination, render_assets::FramebufferExtractSource}; pub fn extract_framebuffers( - mut extract_bundles: Query<(&Handle<FramebufferExtractSource>, &mut FramebufferExtractDestination)>, + mut extract_bundles: Query<( + &Handle<FramebufferExtractSource>, + &mut FramebufferExtractDestination, + )>, sources: Res<RenderAssets<FramebufferExtractSource>>, device: Res<RenderDevice>, ) { @@ -25,7 +35,7 @@ pub fn extract_framebuffers( device.poll(Maintain::Wait); rx.block_on().unwrap().unwrap(); } - + slice.get_mapped_range().to_vec() }; @@ -39,7 +49,8 @@ pub fn extract_framebuffers( std::thread::spawn(move || { if bytes_per_row != padded_bytes_per_row { - let mut unpadded_bytes = Vec::<u8>::with_capacity(source_size.height as usize * bytes_per_row); + let mut unpadded_bytes = + Vec::<u8>::with_capacity(source_size.height as usize * bytes_per_row); for padded_row in image_bytes.chunks(padded_bytes_per_row) { unpadded_bytes.extend_from_slice(&padded_row[..bytes_per_row]); } @@ -59,5 +70,4 @@ pub fn extract_framebuffers( ); }); } - } |