Files
photocraft/crates/engine/tests/lut_row_cache_purge.rs
T
e59dcc9c44 GPU plan: cache adjustment LUT rows between plans (#11498) (#11539)
* GPU plan: cache adjustment LUT rows between plans (#11498)

adjustment_program rebuilt the Levels/Curves tone tables on every plan
(twice per refresh), about 1-2 ms per Levels layer each time. Keep the
rows of Levels, Curves, Color Balance and Hue/Saturation ranges in a
32-entry most-recently-used cache (photocraft_compose::lut_rows, at
most 32 x 3 x 16 KiB = 1.5 MiB), built outside the lock.

Entries are keyed by a u64 hash of exactly what each row builder reads,
fields destructured in full and floats by bits (-0.0 and 0.0 stay
apart). Hue/Saturation master sliders don't add entries; Hue/Sat ranges
and Color Balance don't depend on depth. Edit > Purge > All drops the
cache, and a filled cache enables it.

Release, per call: Levels 8/16-bit 1.10 -> 0.003-0.018 ms, Curves
0.16 -> 0.018, Color Balance 0.11 -> 0.001-0.015, Hue/Sat ranges
0.05 -> 0.008-0.018. The tables are identical, so rendering is unchanged.

Tests: cached rows match fresh tables bit for bit at 8/16/32-bit, hits
and LRU eviction on a local cache, key coverage, and Purge All
releasing the cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* compose: rustfmt the LUT row cache tests (#11498)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* GPU plan: test that plans read cached LUT rows and that curve points key them (#11498)

Plant rows no builder makes under a fresh key and check the planner returns
them, and check that moving a Curves point changes its key (review on #11539).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* compose: prevent in-flight LUT builds from undoing purge

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: FredApps <FredApps@users.noreply.github.com>
2026-11-06 00:32:49 +01:00

31 lines
1.1 KiB
Rust

//! One integration-test process keeps its global adjustment-table cache isolated from parallel
//! unit tests.
use photocraft_compose::lut_rows::{self, ROW_LEN};
use photocraft_engine::Session;
use serde_json::json;
#[test]
fn purge_all_is_enabled_by_cached_adjustment_tables_and_releases_them() {
let mut session = Session::new();
assert!(!session.is_enabled("edit.purge.all"));
let rows = lut_rows::cached(7, || vec![[0.5; ROW_LEN]; 3]);
let accounted = lut_rows::cache_bytes();
assert_eq!(accounted, 3 * ROW_LEN * 4);
assert!(session.is_enabled("edit.purge.all"), "only the adjustment table cache enables purge");
let result = session.execute("edit.purge.all", json!({})).unwrap();
assert_eq!(result["purged"], json!(["adjustment table cache"]));
assert_eq!(result["bytes"].as_u64(), Some(accounted as u64));
assert_eq!(lut_rows::cache_bytes(), 0);
assert!(!session.is_enabled("edit.purge.all"));
// The next render builds the tables again.
let mut built = false;
let again = lut_rows::cached(7, || {
built = true;
vec![[0.5; ROW_LEN]; 3]
});
assert!(built);
assert_eq!(rows, again);
}