Skip to content

Commit de01074

Browse files
committed
[fix] warnings and add documentation around frame acquisition
1 parent 519b149 commit de01074

2 files changed

Lines changed: 44 additions & 36 deletions

File tree

crates/lambda-rs/src/render/mesh.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,7 @@ mod tests {
188188
/// expected vertex + attribute counts.
189189
#[test]
190190
fn mesh_build_from_obj_parses_vertices() {
191-
use std::{
192-
fs,
193-
path::PathBuf,
194-
};
191+
use std::fs;
195192

196193
// Minimal OBJ with one triangle, normals, and texture coordinates.
197194
let obj = r#"
@@ -205,7 +202,7 @@ vn 0.0 0.0 1.0
205202
f 1/1/1 2/2/1 3/3/1
206203
"#;
207204

208-
let mut path = PathBuf::from(std::env::temp_dir());
205+
let mut path = std::env::temp_dir();
209206
path.push("lambda_mesh_test.obj");
210207
fs::write(&path, obj).expect("write temp obj");
211208

crates/lambda-rs/src/render/mod.rs

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -562,41 +562,52 @@ impl RenderContext {
562562
return Ok(());
563563
}
564564

565-
let requires_surface = commands.iter().any(|cmd| match cmd {
566-
RenderCommand::BeginRenderPass { .. } => true,
567-
RenderCommand::BeginRenderPassTo {
568-
destination: RenderDestination::Surface,
569-
..
570-
} => true,
571-
_ => false,
565+
// Determine whether this command list needs access to the presentation
566+
// surface. We only acquire a surface frame when a surface-backed pass is
567+
// requested; offscreen-only command lists can render without a window.
568+
let requires_surface = commands.iter().any(|cmd| {
569+
return matches!(
570+
cmd,
571+
RenderCommand::BeginRenderPass { .. }
572+
| RenderCommand::BeginRenderPassTo {
573+
destination: RenderDestination::Surface,
574+
..
575+
}
576+
);
572577
});
573578

574579
let mut frame = if requires_surface {
575-
Some(
576-
match {
577-
let surface = self.surface.as_mut().ok_or_else(|| {
578-
RenderError::Configuration(
579-
"No surface attached to RenderContext".to_string(),
580-
)
581-
})?;
582-
surface.acquire_frame()
583-
} {
584-
Ok(frame) => frame,
585-
Err(err) => match err {
586-
targets::surface::SurfaceError::Lost
587-
| targets::surface::SurfaceError::Outdated => {
588-
self.reconfigure_surface(self.size)?;
589-
let surface = self.surface.as_mut().ok_or_else(|| {
590-
RenderError::Configuration(
591-
"No surface attached to RenderContext".to_string(),
592-
)
593-
})?;
594-
surface.acquire_frame().map_err(RenderError::Surface)?
595-
}
596-
_ => return Err(RenderError::Surface(err)),
597-
},
580+
// Acquire exactly one surface frame up-front and reuse its `TextureView`
581+
// for all surface-backed render passes in this command list. The acquired
582+
// frame is presented after encoding completes.
583+
//
584+
// If acquisition fails due to surface loss/outdated config, attempt to
585+
// reconfigure the surface to the current context size and retry once.
586+
let acquired = {
587+
let surface = self.surface.as_mut().ok_or_else(|| {
588+
RenderError::Configuration(
589+
"No surface attached to RenderContext".to_string(),
590+
)
591+
})?;
592+
surface.acquire_frame()
593+
};
594+
595+
Some(match acquired {
596+
Ok(frame) => frame,
597+
Err(err) => match err {
598+
targets::surface::SurfaceError::Lost
599+
| targets::surface::SurfaceError::Outdated => {
600+
self.reconfigure_surface(self.size)?;
601+
let surface = self.surface.as_mut().ok_or_else(|| {
602+
RenderError::Configuration(
603+
"No surface attached to RenderContext".to_string(),
604+
)
605+
})?;
606+
surface.acquire_frame().map_err(RenderError::Surface)?
607+
}
608+
_ => return Err(RenderError::Surface(err)),
598609
},
599-
)
610+
})
600611
} else {
601612
None
602613
};

0 commit comments

Comments
 (0)