Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: flush pipelined GPU readback to capture last frame in exports

Cursor Agent9aad0f3df35e
diff --git a/crates/rendering/src/frame_pipeline.rs b/crates/rendering/src/frame_pipeline.rs
index fa811e0c9..13e3c472e 100644
--- a/crates/rendering/src/frame_pipeline.rs
+++ b/crates/rendering/src/frame_pipeline.rs
@@ -461,3 +461,14 @@ pub async fn finish_encoder(
pending.wait(device).await
}
+
+pub async fn flush_pending_readback(
+ session: &mut RenderSession,
+ device: &wgpu::Device,
+) -> Option<Result<RenderedFrame, RenderingError>> {
+ if let Some(pending) = session.pipelined_readback.take_pending() {
+ Some(pending.wait(device).await)
+ } else {
+ None
+ }
+}
diff --git a/crates/rendering/src/lib.rs b/crates/rendering/src/lib.rs
index 7956b0582..6c63d2951 100644
--- a/crates/rendering/src/lib.rs
+++ b/crates/rendering/src/lib.rs
@@ -7,7 +7,7 @@ use composite_frame::CompositeVideoFrameUniforms;
use core::f64;
use cursor_interpolation::{InterpolatedCursorPosition, interpolate_cursor};
use decoder::{AsyncVideoDecoderHandle, spawn_decoder};
-use frame_pipeline::{RenderSession, finish_encoder};
+use frame_pipeline::{RenderSession, finish_encoder, flush_pending_readback};
use futures::FutureExt;
use futures::future::OptionFuture;
use layers::{
@@ -532,6 +532,14 @@ pub async fn render_video_to_channel(
sender.send((frame, current_frame_number)).await?;
}
+ if let Some(Ok(final_frame)) = frame_renderer.flush_pipeline().await {
+ if final_frame.width > 0 && final_frame.height > 0 {
+ sender
+ .send((final_frame, frame_number.saturating_sub(1)))
+ .await?;
+ }
+ }
+
let total_time = start_time.elapsed();
println!(
"Render complete. Processed {frame_number} frames in {:?} seconds",
@@ -1875,6 +1883,14 @@ impl<'a> FrameRenderer<'a> {
Err(last_error.unwrap_or(RenderingError::BufferMapWaitingFailed))
}
+
+ pub async fn flush_pipeline(&mut self) -> Option<Result<RenderedFrame, RenderingError>> {
+ if let Some(session) = &mut self.session {
+ flush_pending_readback(session, &self.constants.device).await
+ } else {
+ None
+ }
+ }
}
pub struct RendererLayers {