Footage cache (#3271): a failed picture doesn't refuse the other channels; the browser plane cap is the footage budget

A remembered failure refused any later request for 'all channels', but those are every channel but the picture's: a picture too large to read left the file's other channels unread. A failure now refuses a request only when it asks for everything the failed one did. The browser's plane cap is 256 MB, the browser's largest footage budget (frames and planes together). A test fails a picture read and then reads the other channels; it fails on the old code.
This commit is contained in:
vangel76 committed 2026-11-08 18:32:44 +01:00
1 parent b0e58fad08
commit 9b3821ff77
3 files changed
+34 -8

No files matched your search

+3 -2
View File
@@ -87,8 +87,9 @@ pub(crate) enum Rgb {
/// about 1 GB lower than 2 GiB, at the same speed.)
pub const CACHE_BUDGET: usize = if cfg!(target_arch = "wasm32") { WEB_CACHE_CAP } else { crate::DEFAULT_BUDGET };
/// The most decoded planes the plane store keeps in the browser, whatever the footage budget.
pub const WEB_CACHE_CAP: usize = 512 << 20;
/// The most decoded planes the plane store keeps in the browser: the browser's largest footage
/// budget (Footage Frame Cache, frames and planes together, `WEB_MEDIA_CACHE` in the engine).
pub const WEB_CACHE_CAP: usize = 256 << 20;
/// The index of an EXR file's bytes and the planes of `ids` (all when `None`). `None` when it is
/// not a readable EXR or the planes need too much memory.
+11 -6
View File
@@ -63,9 +63,14 @@ enum Step {
},
}
/// A request for `want` asks for at least what `failed` asked for.
fn asks_at_least(want: &Want, failed: &Want) -> bool {
want.all || (!failed.all && failed.ids.is_subset(&want.ids))
/// A request for `want` of the file `index` describes asks for at least what `failed` asked for
/// (`all` is every channel but the picture's: it doesn't cover a picture channel asked for by id).
fn asks_at_least(index: &ExrIndex, want: &Want, failed: &Want) -> bool {
if failed.all && !want.all {
return false;
}
let aux = if want.all { index.aux_ids() } else { Vec::new() };
failed.ids.iter().all(|id| want.ids.contains(id) || aux.contains(id))
}
/// Decode `want` for this request alone (kept nowhere), noting the file it read.
@@ -506,7 +511,7 @@ impl PlaneStore {
return Step::Done(Ok(b));
}
// (a failure of the file as it was before: the file changed since, it is read again)
if let Some((_, _, why)) = e.failed.iter().find(|(of, failed, _)| Arc::ptr_eq(of, index) && asks_at_least(want, failed)) {
if let Some((_, _, why)) = e.failed.iter().find(|(of, failed, _)| Arc::ptr_eq(of, index) && asks_at_least(index, want, failed)) {
return Step::Done(Err(why.clone()));
}
if let Some(flight) = e.flight.clone() {
@@ -1092,8 +1097,8 @@ impl effectcraft_render::memory::MemoryHolder for SharedStore {
}
/// The footage budget (Settings ▸ Memory & CPU ▸ Footage Frame Cache): the shared plane store
/// keeps at most this much (in the browser at most [`crate::exr_channels::WEB_CACHE_CAP`]); the
/// footage frames and the planes together stay within it (the memory accountant's
/// keeps at most this much (the browser's budget is at most [`crate::exr_channels::WEB_CACHE_CAP`]);
/// the footage frames and the planes together stay within it (the memory accountant's
/// [`effectcraft_render::memory::FOOTAGE`] group).
pub(crate) fn set_budget(bytes: usize) {
let bytes = if cfg!(target_arch = "wasm32") { bytes.min(crate::exr_channels::WEB_CACHE_CAP) } else { bytes };
+20
View File
@@ -1405,3 +1405,23 @@ fn a_failure_is_forgotten_once_the_file_changes() {
assert!(!Arc::ptr_eq(&old, &new));
assert!(store.get(path, &source, &new, &all, Use::Other).is_ok(), "the new file is read");
}
/// #3271 review: a failed picture request (too large here) doesn't refuse a later request for
/// the other channels: "all channels" is every channel but the picture's, so it doesn't ask for
/// what failed.
#[test]
fn a_failed_picture_leaves_the_other_channels_readable() {
let bytes: Arc<[u8]> =
write(vec![part(None, &[("R", true), ("G", true), ("B", true), ("A", true), ("Z", false)], (8, 8), Compression::ZIP1)], (8, 8)).into();
let path = "/3271-failed-picture.exr";
// (room for three planes: the picture's four don't fit, the depth plane does)
set_cap(path, 3 * 8 * 8 * 4);
let store = PlaneStore::new(CACHE_BUDGET);
let source = ExrSource::Bytes(bytes);
let index = crate::exr_index::get(path, &source).unwrap();
let picture = Want { all: false, ids: index.picture_ids().unwrap().into_iter().collect() };
assert!(matches!(store.get(path, &source, &index, &picture, Use::Other), Err(Refused::TooLarge(_))));
assert!(store.get(path, &source, &index, &picture, Use::Other).is_err(), "remembered");
let rest = store.get(path, &source, &index, &Want { all: true, ids: Default::default() }, Use::Other).expect("the other channels");
assert!(rest.aux.get("Z").is_some());
}