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
fn process(
&mut self,
changed: bool,
content: Vec<&EntityObject>,
buffer_recorder: &mut CommandBufferRecorder<'_>,
images: &TargetMode<Vec<Arc<Image>>>,

View file

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

View file

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

View file

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

View file

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