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]
|
||||
name = "grex_framebuffer_extract"
|
||||
version = "0.1.1"
|
||||
name = "bevy_framebuffer_extract"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
|
||||
[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;
|
||||
|
||||
@ -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,
|
||||
}
|
||||
|
||||
|
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 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,8 +27,7 @@ impl Plugin for FramebufferExtractPlugin {
|
||||
));
|
||||
|
||||
let render_app = app.sub_app_mut(RenderApp);
|
||||
render_app
|
||||
.add_systems(
|
||||
render_app.add_systems(
|
||||
Render,
|
||||
systems::extract_framebuffers
|
||||
.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;
|
||||
|
||||
@ -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(
|
||||
|
@ -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,16 +32,17 @@ 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 {
|
||||
|
@ -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>,
|
||||
) {
|
||||
@ -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(
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user