From 3fca8c60bba1714f128a7e9d297614b3833e75f5 Mon Sep 17 00:00:00 2001 From: rod-salazar <51817379+rod-salazar@users.noreply.github.com> Date: Mon, 16 Nov 2020 16:38:14 -0800 Subject: [PATCH] Remove redundant texture copies in TextureCopyNode (#871) Remove redundant texture syncs in TextureCopyNode --- .../src/render_graph/nodes/texture_copy_node.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs b/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs index 0713e8599df36..61f463eb2d633 100644 --- a/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs +++ b/crates/bevy_render/src/render_graph/nodes/texture_copy_node.rs @@ -6,6 +6,7 @@ use crate::{ use bevy_app::prelude::{EventReader, Events}; use bevy_asset::{AssetEvent, Assets}; use bevy_ecs::{Resources, World}; +use bevy_utils::{AHashExt, HashSet}; #[derive(Default)] pub struct TextureCopyNode { @@ -23,10 +24,15 @@ impl Node for TextureCopyNode { ) { let texture_events = resources.get::>>().unwrap(); let textures = resources.get::>().unwrap(); + let mut copied_textures = HashSet::new(); for event in self.texture_event_reader.iter(&texture_events) { match event { AssetEvent::Created { handle } | AssetEvent::Modified { handle } => { if let Some(texture) = textures.get(handle) { + if copied_textures.contains(&handle.id) { + continue; + } + let texture_descriptor: TextureDescriptor = texture.into(); let width = texture.size.x() as usize; let aligned_width = render_context @@ -67,6 +73,8 @@ impl Node for TextureCopyNode { texture_descriptor.size, ); render_context.resources().remove_buffer(texture_buffer); + + copied_textures.insert(&handle.id); } } AssetEvent::Removed { .. } => {}