Removed toolchain config
This commit is contained in:
parent
0ac133c0c3
commit
ef6c295415
@ -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]
|
[package]
|
||||||
name = "grex_framebuffer_extract"
|
name = "bevy_framebuffer_extract"
|
||||||
version = "0.1.1"
|
version = "0.1.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
@ -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;
|
use crate::render_assets::FramebufferExtractSource;
|
||||||
|
|
||||||
@ -8,20 +8,16 @@ use crate::render_assets::FramebufferExtractSource;
|
|||||||
pub struct FramebufferExtractDestination(pub Arc<Mutex<Image>>);
|
pub struct FramebufferExtractDestination(pub Arc<Mutex<Image>>);
|
||||||
|
|
||||||
impl ExtractComponent for FramebufferExtractDestination {
|
impl ExtractComponent for FramebufferExtractDestination {
|
||||||
type QueryData = (
|
type QueryData = (&'static Self, &'static Handle<FramebufferExtractSource>);
|
||||||
&'static Self,
|
|
||||||
&'static Handle<FramebufferExtractSource>,
|
|
||||||
);
|
|
||||||
|
|
||||||
type QueryFilter = ();
|
type QueryFilter = ();
|
||||||
|
|
||||||
type Out = (Self, Handle<FramebufferExtractSource>);
|
type Out = (Self, Handle<FramebufferExtractSource>);
|
||||||
|
|
||||||
fn extract_component((destination, source_handle): QueryItem<'_, Self::QueryData>) -> Option<Self::Out> {
|
fn extract_component(
|
||||||
Some((
|
(destination, source_handle): QueryItem<'_, Self::QueryData>,
|
||||||
destination.clone(),
|
) -> Option<Self::Out> {
|
||||||
source_handle.clone(),
|
Some((destination.clone(), source_handle.clone()))
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,4 +26,3 @@ pub struct ExtractFramebufferBundle {
|
|||||||
pub source: Handle<FramebufferExtractSource>,
|
pub source: Handle<FramebufferExtractSource>,
|
||||||
pub dest: FramebufferExtractDestination,
|
pub dest: FramebufferExtractDestination,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
src/lib.rs
18
src/lib.rs
@ -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 components::FramebufferExtractDestination;
|
||||||
use nodes::{FramebufferExtractNode, FramebufferExtractLabel};
|
use nodes::{FramebufferExtractLabel, FramebufferExtractNode};
|
||||||
use render_assets::FramebufferExtractSource;
|
use render_assets::FramebufferExtractSource;
|
||||||
|
|
||||||
pub mod components;
|
pub mod components;
|
||||||
mod systems;
|
|
||||||
mod nodes;
|
mod nodes;
|
||||||
pub mod render_assets;
|
pub mod render_assets;
|
||||||
|
mod systems;
|
||||||
|
|
||||||
pub struct FramebufferExtractPlugin;
|
pub struct FramebufferExtractPlugin;
|
||||||
|
|
||||||
impl Plugin for FramebufferExtractPlugin {
|
impl Plugin for FramebufferExtractPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app
|
app.register_type::<FramebufferExtractSource>()
|
||||||
.register_type::<FramebufferExtractSource>()
|
|
||||||
.init_asset::<FramebufferExtractSource>()
|
.init_asset::<FramebufferExtractSource>()
|
||||||
.register_asset_reflect::<FramebufferExtractSource>()
|
.register_asset_reflect::<FramebufferExtractSource>()
|
||||||
.add_plugins((
|
.add_plugins((
|
||||||
@ -22,8 +27,7 @@ impl Plugin for FramebufferExtractPlugin {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let render_app = app.sub_app_mut(RenderApp);
|
let render_app = app.sub_app_mut(RenderApp);
|
||||||
render_app
|
render_app.add_systems(
|
||||||
.add_systems(
|
|
||||||
Render,
|
Render,
|
||||||
systems::extract_framebuffers
|
systems::extract_framebuffers
|
||||||
.after(RenderSet::Render)
|
.after(RenderSet::Render)
|
||||||
|
22
src/nodes.rs
22
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;
|
use crate::render_assets::FramebufferExtractSource;
|
||||||
|
|
||||||
@ -15,9 +23,15 @@ impl Node for FramebufferExtractNode {
|
|||||||
render_context: &mut RenderContext,
|
render_context: &mut RenderContext,
|
||||||
world: &World,
|
world: &World,
|
||||||
) -> Result<(), NodeRunError> {
|
) -> Result<(), NodeRunError> {
|
||||||
for (_, source) in world.resource::<RenderAssets<FramebufferExtractSource>>().iter() {
|
for (_, source) in world
|
||||||
let Some(gpu_image) = world.resource::<RenderAssets<Image>>().get(&source.source_handle) else {
|
.resource::<RenderAssets<FramebufferExtractSource>>()
|
||||||
return Ok(())
|
.iter()
|
||||||
|
{
|
||||||
|
let Some(gpu_image) = world
|
||||||
|
.resource::<RenderAssets<Image>>()
|
||||||
|
.get(&source.source_handle)
|
||||||
|
else {
|
||||||
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
render_context.command_encoder().copy_texture_to_buffer(
|
render_context.command_encoder().copy_texture_to_buffer(
|
||||||
|
@ -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 struct GpuFramebufferExtractSource {
|
||||||
pub buffer: Buffer,
|
pub buffer: Buffer,
|
||||||
@ -24,16 +32,17 @@ impl RenderAsset for FramebufferExtractSource {
|
|||||||
self,
|
self,
|
||||||
(device, images): &mut SystemParamItem<Self::Param>,
|
(device, images): &mut SystemParamItem<Self::Param>,
|
||||||
) -> Result<Self::PreparedAsset, PrepareAssetError<Self>> {
|
) -> Result<Self::PreparedAsset, PrepareAssetError<Self>> {
|
||||||
|
|
||||||
let Some(gpu_image) = images.get(&self.0) else {
|
let Some(gpu_image) = images.get(&self.0) else {
|
||||||
warn!("Failed to get GPU image");
|
warn!("Failed to get GPU image");
|
||||||
return Err(PrepareAssetError::RetryNextUpdate(self))
|
return Err(PrepareAssetError::RetryNextUpdate(self));
|
||||||
};
|
};
|
||||||
|
|
||||||
let size = gpu_image.texture.size();
|
let size = gpu_image.texture.size();
|
||||||
let format = gpu_image.texture_format;
|
let format = gpu_image.texture_format;
|
||||||
let bytes_per_row = (size.width / format.block_dimensions().0) * format.block_copy_size(None).unwrap();
|
let bytes_per_row =
|
||||||
let padded_bytes_per_row = RenderDevice::align_copy_bytes_per_row(bytes_per_row as usize) as u32;
|
(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 {
|
Ok(GpuFramebufferExtractSource {
|
||||||
buffer: device.create_buffer(&BufferDescriptor {
|
buffer: device.create_buffer(&BufferDescriptor {
|
||||||
|
@ -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 pollster::FutureExt;
|
||||||
|
|
||||||
use crate::{render_assets::FramebufferExtractSource, components::FramebufferExtractDestination};
|
use crate::{components::FramebufferExtractDestination, render_assets::FramebufferExtractSource};
|
||||||
|
|
||||||
pub fn extract_framebuffers(
|
pub fn extract_framebuffers(
|
||||||
mut extract_bundles: Query<(&Handle<FramebufferExtractSource>, &mut FramebufferExtractDestination)>,
|
mut extract_bundles: Query<(
|
||||||
|
&Handle<FramebufferExtractSource>,
|
||||||
|
&mut FramebufferExtractDestination,
|
||||||
|
)>,
|
||||||
sources: Res<RenderAssets<FramebufferExtractSource>>,
|
sources: Res<RenderAssets<FramebufferExtractSource>>,
|
||||||
device: Res<RenderDevice>,
|
device: Res<RenderDevice>,
|
||||||
) {
|
) {
|
||||||
@ -39,7 +49,8 @@ pub fn extract_framebuffers(
|
|||||||
|
|
||||||
std::thread::spawn(move || {
|
std::thread::spawn(move || {
|
||||||
if bytes_per_row != padded_bytes_per_row {
|
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) {
|
for padded_row in image_bytes.chunks(padded_bytes_per_row) {
|
||||||
unpadded_bytes.extend_from_slice(&padded_row[..bytes_per_row]);
|
unpadded_bytes.extend_from_slice(&padded_row[..bytes_per_row]);
|
||||||
}
|
}
|
||||||
@ -59,5 +70,4 @@ pub fn extract_framebuffers(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user