Improve ray tracing by gathering only on change

This commit is contained in:
Michael Huebner 2025-03-24 13:21:22 +01:00
parent 52d540e210
commit fcf246b2cb
5 changed files with 65 additions and 44 deletions

View file

@ -22,6 +22,7 @@ pub trait RenderingFrontEnd {
// scene rendering // scene rendering
fn process( fn process(
&mut self, &mut self,
changed: bool,
content: Vec<&EntityObject>, content: Vec<&EntityObject>,
buffer_recorder: &mut CommandBufferRecorder<'_>, buffer_recorder: &mut CommandBufferRecorder<'_>,
images: &TargetMode<Vec<Arc<Image>>>, images: &TargetMode<Vec<Arc<Image>>>,

View file

@ -406,6 +406,7 @@ impl RenderingFrontEnd for Rasterizer {
fn process( fn process(
&mut self, &mut self,
_changed: bool,
content: Vec<&EntityObject>, content: Vec<&EntityObject>,
buffer_recorder: &mut CommandBufferRecorder<'_>, buffer_recorder: &mut CommandBufferRecorder<'_>,
_images: &TargetMode<Vec<Arc<Image>>>, _images: &TargetMode<Vec<Arc<Image>>>,

View file

@ -680,6 +680,7 @@ impl RenderingFrontEnd for TraditionalRasterizer {
fn process( fn process(
&mut self, &mut self,
_changed: bool,
content: Vec<&EntityObject>, content: Vec<&EntityObject>,
buffer_recorder: &mut CommandBufferRecorder<'_>, buffer_recorder: &mut CommandBufferRecorder<'_>,
_images: &TargetMode<Vec<Arc<Image>>>, _images: &TargetMode<Vec<Arc<Image>>>,

View file

@ -65,6 +65,8 @@ where
width: u32, width: u32,
height: u32, height: u32,
vertex_count: u64,
renderer: T, renderer: T,
} }
@ -147,6 +149,8 @@ where
width, width,
height, height,
vertex_count: 0,
}) })
} }
@ -601,6 +605,7 @@ where
// scene rendering // scene rendering
fn process( fn process(
&mut self, &mut self,
changed: bool,
content: Vec<&EntityObject>, content: Vec<&EntityObject>,
buffer_recorder: &mut CommandBufferRecorder<'_>, buffer_recorder: &mut CommandBufferRecorder<'_>,
images: &TargetMode<Vec<Arc<Image>>>, images: &TargetMode<Vec<Arc<Image>>>,
@ -614,10 +619,12 @@ where
self.renderer.invalidate(); self.renderer.invalidate();
self.animator.invalidate(); self.animator.invalidate();
if changed {
let mut recompile = false;
// gather textures and materials from all objects // gather textures and materials from all objects
let (textures, materials, vertex_count) = Self::gather_descriptor_buffers(&content)?; let (textures, materials, vertex_count) = Self::gather_descriptor_buffers(&content)?;
self.vertex_count = vertex_count;
let mut recompile = false;
// update material descriptor // update material descriptor
if !materials.is_empty() { if !materials.is_empty() {
@ -628,8 +635,10 @@ where
self.max_material_count *= 2; self.max_material_count *= 2;
} }
self.material_desc_set = self.material_desc_set = Self::create_material_descriptor_set(
Self::create_material_descriptor_set(&self.device, self.max_material_count)?; &self.device,
self.max_material_count,
)?;
recompile = true; recompile = true;
} }
@ -666,13 +675,17 @@ where
&self.light_info_desc_set, &self.light_info_desc_set,
])?; ])?;
} }
}
let index = *indices.mono(); let index = *indices.mono();
if let Some(scene_buffer) = if let Some(scene_buffer) = self.animator.animate(
self.animator &content,
.animate(&content, vertex_count, buffer_recorder, index, &self.view)? self.vertex_count,
{ buffer_recorder,
index,
&self.view,
)? {
self.scene_desc_set self.scene_desc_set
.update(&[DescriptorWrite::storage_buffers(0, &[scene_buffer])])?; .update(&[DescriptorWrite::storage_buffers(0, &[scene_buffer])])?;
} }

View file

@ -463,8 +463,13 @@ impl TScene for Scene {
#[cfg(feature = "timings")] #[cfg(feature = "timings")]
let before = Instant::now(); let before = Instant::now();
self.renderer self.renderer.process(
.process(content, buffer_recorder, images, indices)?; world.had_entity_changes(),
content,
buffer_recorder,
images,
indices,
)?;
#[cfg(feature = "timings")] #[cfg(feature = "timings")]
self.timings self.timings