Phase 3a-1: lazy fault-in of raster keyframe pixels
Raster keyframes are no longer eagerly decoded at load — `raw_pixels` stays empty and is paged in on demand from the project container, so a big paint project opens instantly and only touched frames hit RAM. - core: `read_packed_media_readonly` (fresh read-only connection, can't conflict with an in-place save) + `RasterStore` (holds the container path; `load_pixels` reads+decodes a keyframe's PNG by id). `load_beam_sqlite` stops eager-decoding and instead marks every raster keyframe `needs_fault_in` (recursively, incl. nested); a freshly-created keyframe stays false (blank-resident, nothing to page). Added `Document::all_layers_mut`. - editor: the canvas records a fault-in request when it needs a paged-out keyframe (empty pixels && needs_fault_in); the App drains the sink at the top of update(), pages the pixels in via the store, clears the flag, and repaints. Store path is set on load and after save. Export faults in synchronously per frame. Cold-scrub still shows a 1-frame gap and the page-in is synchronous; the image proxy (3a-2) and async load (3a-3) remove those next.
This commit is contained in:
@@ -528,6 +528,7 @@ impl ExportOrchestrator {
|
||||
image_cache: &mut ImageCache,
|
||||
video_manager: &Arc<std::sync::Mutex<VideoManager>>,
|
||||
floating_selection: Option<&lightningbeam_core::selection::RasterFloatingSelection>,
|
||||
raster_store: Option<&lightningbeam_core::raster_store::RasterStore>,
|
||||
) -> Result<bool, String> {
|
||||
if self.cancel_flag.load(Ordering::Relaxed) {
|
||||
self.image_state = None;
|
||||
@@ -575,6 +576,7 @@ impl ExportOrchestrator {
|
||||
output_view,
|
||||
floating_selection,
|
||||
state.settings.allow_transparency,
|
||||
raster_store,
|
||||
)?;
|
||||
queue.submit(Some(encoder.finish()));
|
||||
|
||||
@@ -1029,6 +1031,7 @@ impl ExportOrchestrator {
|
||||
renderer: &mut vello::Renderer,
|
||||
image_cache: &mut ImageCache,
|
||||
video_manager: &Arc<std::sync::Mutex<VideoManager>>,
|
||||
raster_store: Option<&lightningbeam_core::raster_store::RasterStore>,
|
||||
) -> Result<bool, String> {
|
||||
use std::time::Instant;
|
||||
|
||||
@@ -1126,6 +1129,7 @@ impl ExportOrchestrator {
|
||||
gpu_resources, &acquired.rgba_texture_view,
|
||||
None, // No floating selection during video export
|
||||
false, // Video export is never transparent
|
||||
raster_store,
|
||||
)?;
|
||||
let render_end = Instant::now();
|
||||
|
||||
|
||||
@@ -1179,6 +1179,39 @@ pub fn render_frame_to_rgba_hdr(
|
||||
///
|
||||
/// # Returns
|
||||
/// Command encoder ready for submission (caller submits via ReadbackPipeline)
|
||||
/// Fault in raster keyframe pixels needed to composite the document at its current
|
||||
/// time, decoding them from the project `.beam` container via `raster_store`.
|
||||
///
|
||||
/// Mutates the document in place: for every raster layer's active keyframe whose
|
||||
/// `raw_pixels` are empty, loads + sets them (and marks `texture_dirty`). A no-op
|
||||
/// when `raster_store` is `None`/unsaved or everything is already resident.
|
||||
fn fault_in_raster_for_frame(
|
||||
document: &mut Document,
|
||||
raster_store: Option<&lightningbeam_core::raster_store::RasterStore>,
|
||||
) {
|
||||
let store = match raster_store {
|
||||
Some(s) if s.has_path() => s,
|
||||
_ => return,
|
||||
};
|
||||
let now = document.current_time;
|
||||
for layer in document.all_layers_mut() {
|
||||
if let lightningbeam_core::layer::AnyLayer::Raster(rl) = layer {
|
||||
// Resolve the active keyframe id at the current time, then fault it in.
|
||||
let kf_id = match rl.keyframe_at(now) {
|
||||
Some(kf) if kf.raw_pixels.is_empty() && kf.needs_fault_in => kf.id,
|
||||
_ => continue,
|
||||
};
|
||||
if let Some(kf) = rl.keyframes.iter_mut().find(|kf| kf.id == kf_id) {
|
||||
if let Some(pixels) = store.load_pixels(kf_id) {
|
||||
kf.raw_pixels = pixels;
|
||||
kf.texture_dirty = true;
|
||||
}
|
||||
kf.needs_fault_in = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_frame_to_gpu_rgba(
|
||||
document: &mut Document,
|
||||
timestamp: f64,
|
||||
@@ -1193,12 +1226,19 @@ pub fn render_frame_to_gpu_rgba(
|
||||
rgba_texture_view: &wgpu::TextureView,
|
||||
floating_selection: Option<&lightningbeam_core::selection::RasterFloatingSelection>,
|
||||
allow_transparency: bool,
|
||||
raster_store: Option<&lightningbeam_core::raster_store::RasterStore>,
|
||||
) -> Result<wgpu::CommandEncoder, String> {
|
||||
use vello::kurbo::Affine;
|
||||
|
||||
// Set document time to the frame timestamp
|
||||
document.current_time = timestamp;
|
||||
|
||||
// Fault in raster keyframe pixels for this frame (Phase 3 paging). Offline
|
||||
// export renders synchronously with no "next frame", so unlike the live canvas
|
||||
// we must page the pixels in here, before compositing. Cheap no-op when every
|
||||
// keyframe is already resident or when the document is unsaved (no store path).
|
||||
fault_in_raster_for_frame(document, raster_store);
|
||||
|
||||
// Scale the document to the export resolution. The core renderer bakes this
|
||||
// base transform into every layer (vector scenes, raster and video layer
|
||||
// transforms), so the whole stage scales up/down to fill the output. When the
|
||||
|
||||
Reference in New Issue
Block a user