mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-19 08:51:41 +01:00
Tests: trim repeated solves and loops in engine and GPU tests (#15367)
- parity.rs: the two paging tests use a 660x580 document (3x3 pages, one interior cell) instead of 1100x900, and eviction runs 2 rounds; the residency tests that share the large document keep it. 16-bit runs only where the GPU reads the 16-bit upload (one effect stack, Dissolve and pattern cases). The disjoint-damage test paints 2 distinct series of 8 strokes and isolates its layers so strokes capture checkpoints, which makes its bytes assert able to fail. many_layers_submit_inside_one_chunk_paged is removed: its stats equal the whole test's. - Coarse preview: drop an unchecked full-resolution solve; colour tests reuse solves and use Extend where Move only adds an unread fill. - Crop fill eligibility is a unit test on additional_target; the integration test keeps 3 cases. - PSD write oracle: one run with a passing and a failing case instead of two runs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ed02f0cdf5
commit
d4797333de
6 files changed
+180
-94
No files matched your search
@@ -19,27 +19,30 @@ fn edited_psd_roundtrip_is_checked_and_bad_expectations_fail() {
|
||||
.unwrap();
|
||||
assert!(made.status.success(), "{}", String::from_utf8_lossy(&made.stderr));
|
||||
let hash = xtask::sha256::hex(&fs::read(&base).unwrap());
|
||||
let mut recipe = json!({"version":1,"corpus_revision":"synthetic","cases":[{
|
||||
"id":"style", "base":"base.psd", "base_sha256":hash, "target":{"kind":"Type","name":"Oracle"},
|
||||
"commands":[{"command":"type.antiAlias.crisp","params":{}}],
|
||||
"checks":[{"op":"changed_to","path":"/text/antialias","value":"Crisp"},{"op":"unchanged","path":"/text/text"}]
|
||||
}]});
|
||||
// One run with a right and a wrong expectation of the same edit: the runner hashes the CLI,
|
||||
// asks git and makes its output directory once, and still has to report the first case as
|
||||
// passing and the second as failing (and fail itself).
|
||||
let case = |id: &str, value: &str| {
|
||||
json!({
|
||||
"id":id, "base":"base.psd", "base_sha256":hash, "target":{"kind":"Type","name":"Oracle"},
|
||||
"commands":[{"command":"type.antiAlias.crisp","params":{}}],
|
||||
"checks":[{"op":"changed_to","path":"/text/antialias","value":value},{"op":"unchanged","path":"/text/text"}]
|
||||
})
|
||||
};
|
||||
let recipe = json!({"version":1,"corpus_revision":"synthetic","cases":[case("style", "Crisp"), case("wrong", "Sharp")]});
|
||||
let recipe_path = root.join("recipes.json");
|
||||
let src = Path::new(env!("CARGO_MANIFEST_DIR")).join("../..");
|
||||
fs::write(&recipe_path, serde_json::to_vec(&recipe).unwrap()).unwrap();
|
||||
let cli_path = Path::new(&cli).to_str().unwrap();
|
||||
let corpus = root.to_str().unwrap();
|
||||
let recipe_name = recipe_path.to_str().unwrap();
|
||||
let output = root.join("success");
|
||||
let output = root.join("report");
|
||||
let args = [recipe_name, corpus, cli_path, output.to_str().unwrap()];
|
||||
xtask::psd_write_oracle::run(&src, &args).unwrap();
|
||||
assert!(xtask::psd_write_oracle::run(&src, &args).is_err(), "a failing case fails the run");
|
||||
let report: Value = serde_json::from_slice(&fs::read(output.join("report.json")).unwrap()).unwrap();
|
||||
assert_eq!(report["cases"][0]["id"], "style");
|
||||
assert_eq!(report["cases"][0]["status"], "pass");
|
||||
assert_eq!(report["cases"][0]["photoshop"]["opens"], "not_run");
|
||||
recipe["cases"][0]["checks"][0]["value"] = json!("Sharp");
|
||||
fs::write(&recipe_path, serde_json::to_vec(&recipe).unwrap()).unwrap();
|
||||
let bad_output = root.join("failure");
|
||||
assert!(xtask::psd_write_oracle::run(&src, &[recipe_name, corpus, cli_path, bad_output.to_str().unwrap()]).is_err());
|
||||
let bad: Value = serde_json::from_slice(&fs::read(bad_output.join("report.json")).unwrap()).unwrap();
|
||||
assert_eq!(bad["cases"][0]["status"], "fail");
|
||||
assert_eq!(report["cases"][1]["id"], "wrong");
|
||||
assert_eq!(report["cases"][1]["status"], "fail");
|
||||
}
|
||||
@@ -891,7 +891,9 @@ mod tests {
|
||||
let b = got.bounds();
|
||||
let before = s.active().unwrap().doc.layers[0].surface().unwrap().read_region(b);
|
||||
assert!(got.layers[0].surface().unwrap().read_region(b) != before, "the preview moves something");
|
||||
s.execute("paint.contentAwareMove", p).unwrap();
|
||||
// That the command takes this selection too is shown by `preview` above: it runs the
|
||||
// command's own `plan`, which rejects an empty selection, at full resolution. The
|
||||
// command's full-resolution solve is left out: nothing here checked its result.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -115,8 +115,10 @@ fn the_core_fit_shifts_brightness_and_leaves_a_hue_alone() {
|
||||
#[test]
|
||||
fn color_ten_on_green_leaves_the_middle_and_blends_the_edge() {
|
||||
// Selection 120,120 40×40 dragged (140,140) → (600,420). Row y 420 is the middle of the landing.
|
||||
// Color 0 is only read at the landing, which Extend makes as Move does (`run_move` step 1),
|
||||
// without Move's second fill of the old place.
|
||||
let mut kept = green_doc();
|
||||
select_and_move(&mut kept, [120, 120, 40, 40], [460, 280], 0, "move");
|
||||
select_and_move(&mut kept, [120, 120, 40, 40], [460, 280], 0, "extend");
|
||||
let mut fitted = green_doc();
|
||||
select_and_move(&mut fitted, [120, 120, 40, 40], [460, 280], 10, "move");
|
||||
|
||||
@@ -144,9 +146,12 @@ fn color_ten_on_green_leaves_the_middle_and_blends_the_edge() {
|
||||
|
||||
#[test]
|
||||
fn a_brightness_change_shifts_the_middle_only_past_color_five() {
|
||||
// Every check reads the landing, which Move and Extend make with the same code (`run_move`
|
||||
// step 1); Extend skips Move's fill of the old place, which nothing here reads. The drop
|
||||
// straight down below stays a Move.
|
||||
let row = |color: u64| {
|
||||
let mut s = ramp_doc();
|
||||
select_and_move(&mut s, [120, 120, 40, 40], [460, 280], color, "move");
|
||||
select_and_move(&mut s, [120, 120, 40, 40], [460, 280], color, "extend");
|
||||
(levels(&s, 590, 420), levels(&s, 600, 420))
|
||||
};
|
||||
let (light, dark) = row(0);
|
||||
@@ -171,21 +176,23 @@ fn a_brightness_change_shifts_the_middle_only_past_color_five() {
|
||||
|
||||
#[test]
|
||||
fn a_flat_patch_matches_the_new_surroundings_at_color_ten() {
|
||||
let middle = |color: u64, mode: &str| {
|
||||
let moved_with = |color: u64, mode: &str| {
|
||||
let mut s = flat_doc();
|
||||
select_and_move(&mut s, [150, 250, 100, 100], [400, 0], color, mode);
|
||||
levels(&s, 600, 300)
|
||||
s
|
||||
};
|
||||
for mode in ["move", "extend"] {
|
||||
assert_eq!(middle(0, mode), [204, 204, 204], "{mode} color 0 keeps 204");
|
||||
assert_eq!(middle(3, mode), [204, 204, 204], "{mode} color 3 leaves the middle");
|
||||
assert_eq!(middle(10, mode), [51, 51, 51], "{mode} color 10 becomes 51");
|
||||
// Move and Extend land the content with the same code (`run_move` step 1); Move only adds
|
||||
// the fill of the old place, away from the landing. So Colors 0 and 3 run once (Extend, one
|
||||
// fill instead of two), and Color 10 runs in both modes, whose landings are compared pixel
|
||||
// by pixel below.
|
||||
assert_eq!(levels(&moved_with(0, "extend"), 600, 300), [204, 204, 204], "color 0 keeps 204");
|
||||
assert_eq!(levels(&moved_with(3, "extend"), 600, 300), [204, 204, 204], "color 3 leaves the middle");
|
||||
let moved = moved_with(10, "move");
|
||||
let extended = moved_with(10, "extend");
|
||||
for (mode, s) in [("move", &moved), ("extend", &extended)] {
|
||||
assert_eq!(levels(s, 600, 300), [51, 51, 51], "{mode} color 10 becomes 51");
|
||||
}
|
||||
// The landing itself agrees; the old place is the part Move refills and Extend keeps.
|
||||
let mut moved = flat_doc();
|
||||
select_and_move(&mut moved, [150, 250, 100, 100], [400, 0], 10, "move");
|
||||
let mut extended = flat_doc();
|
||||
select_and_move(&mut extended, [150, 250, 100, 100], [400, 0], 10, "extend");
|
||||
for y in [256, 300, 340] {
|
||||
for x in [556, 600, 640] {
|
||||
assert_eq!(levels(&moved, x, y), levels(&extended, x, y), "move and extend agree at {x},{y}");
|
||||
|
||||
@@ -339,4 +339,53 @@ mod tests {
|
||||
assert!(c.covered(6, 0, m, None), "x = 4");
|
||||
assert!(!c.covered(7, 0, m, None), "x = 5");
|
||||
}
|
||||
|
||||
/// The active layer is a second fill target only as a visible, unlocked pixel layer with
|
||||
/// visible, unlocked ancestors: each unmeasured state keeps the Background alone. Every state
|
||||
/// here is a pure function of the layer tree; `crop_content_aware_layers.rs` runs a few of them
|
||||
/// through `image.crop`.
|
||||
#[test]
|
||||
fn only_a_visible_unlocked_active_raster_adds_a_target() {
|
||||
use photocraft_doc::{Layer, LayerContent, TextLayer};
|
||||
let mut s = crate::Session::new();
|
||||
s.execute("file.new", serde_json::json!({"width": 8, "height": 8, "background": "white"})).unwrap();
|
||||
let base = (*s.active().unwrap().doc).clone();
|
||||
let fmt = base.pixel_format();
|
||||
let background = base.background().unwrap().id;
|
||||
// The active layer `layer`, at the root or inside a group that `ancestor` edits.
|
||||
let with = |layer: Layer, ancestor: Option<fn(&mut Layer)>| {
|
||||
let mut d = base.clone();
|
||||
let id = layer.id;
|
||||
match ancestor {
|
||||
None => d.layers.push(layer),
|
||||
Some(edit) => {
|
||||
let mut group = Layer::group("Ancestor", vec![layer]);
|
||||
edit(&mut group);
|
||||
d.layers.push(group);
|
||||
}
|
||||
}
|
||||
(additional_target(&d, Some(id)), id)
|
||||
};
|
||||
let (got, id) = with(Layer::raster("Active", fmt), None);
|
||||
assert_eq!(got, Some(id), "a visible, unlocked raster");
|
||||
let plain_group: fn(&mut Layer) = |_| {};
|
||||
let (got, id) = with(Layer::raster("Active", fmt), Some(plain_group));
|
||||
assert_eq!(got, Some(id), "inside a visible, unlocked group");
|
||||
let text = Layer::new("T", LayerContent::Text(TextLayer { text: "T".into(), ..Default::default() }));
|
||||
assert_eq!(with(text, None).0, None, "a type layer");
|
||||
let mut hidden = Layer::raster("Active", fmt);
|
||||
hidden.visible = false;
|
||||
assert_eq!(with(hidden, None).0, None, "a hidden layer");
|
||||
for lock in ["all", "pixels", "transparency", "position", "artboard"] {
|
||||
let mut locked = Layer::raster("Active", fmt);
|
||||
assert!(locked.locks.set(lock, true));
|
||||
assert_eq!(with(locked, None).0, None, "lock {lock}");
|
||||
}
|
||||
let hidden_group: fn(&mut Layer) = |g| g.visible = false;
|
||||
assert_eq!(with(Layer::raster("Active", fmt), Some(hidden_group)).0, None, "a hidden ancestor");
|
||||
let locked_group: fn(&mut Layer) = |g| assert!(g.locks.set("pixels", true));
|
||||
assert_eq!(with(Layer::raster("Active", fmt), Some(locked_group)).0, None, "a locked ancestor");
|
||||
assert_eq!(additional_target(&base, Some(background)), None, "the Background itself");
|
||||
assert_eq!(additional_target(&base, None), None, "no active layer");
|
||||
}
|
||||
}
|
||||
@@ -236,34 +236,24 @@ fn background_active_is_not_a_second_target() {
|
||||
}
|
||||
|
||||
/// Verifies Background-only fill for ineligible active layers and Delete Cropped Pixels off.
|
||||
/// Which active layers are a second target is a pure function of the layer tree, checked for every
|
||||
/// unmeasured state (type, hidden, each lock, hidden or locked ancestor) by `crop_fill`'s
|
||||
/// `only_a_visible_unlocked_active_raster_adds_a_target`. Through the command, straight and
|
||||
/// turned, run one state the layer itself rules out (type), one an ancestor rules out (a locked
|
||||
/// group) and Delete Cropped Pixels off, its own branch of `fill_uncovered`.
|
||||
#[test]
|
||||
fn unmeasured_active_targets_and_delete_off_keep_the_legacy_target() {
|
||||
for turned in [false, true] {
|
||||
let (x, y) = extension_sample(turned);
|
||||
for case in 0..10 {
|
||||
for (text, locked_group, delete) in [(true, false, true), (false, true, true), (false, false, false)] {
|
||||
let (mut s, ids) = scene(turned);
|
||||
let active = match case {
|
||||
0 => ids.text,
|
||||
1 => ids.hidden,
|
||||
_ => ids.quads,
|
||||
};
|
||||
if (2..7).contains(&case) {
|
||||
s.edit("Lock active", |d, _| {
|
||||
assert!(d.layer_mut(active).unwrap().locks.set(["all", "pixels", "transparency", "position", "artboard"][case - 2], true));
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
if case >= 8 {
|
||||
let active = if text { ids.text } else { ids.quads };
|
||||
if locked_group {
|
||||
s.edit("Group active", |d, _| {
|
||||
let i = d.layers.iter().position(|layer| layer.id == active).unwrap();
|
||||
let child = d.layers.remove(i);
|
||||
let mut group = Layer::group("Ancestor", vec![child]);
|
||||
if case == 8 {
|
||||
group.visible = false;
|
||||
} else {
|
||||
assert!(group.locks.set("pixels", true));
|
||||
}
|
||||
assert!(group.locks.set("pixels", true));
|
||||
d.layers.insert(i, group);
|
||||
Ok(())
|
||||
})
|
||||
@@ -271,9 +261,7 @@ fn unmeasured_active_targets_and_delete_off_keep_the_legacy_target() {
|
||||
}
|
||||
select(&mut s, active);
|
||||
let mut p = frame(turned);
|
||||
if case == 7 {
|
||||
p["deleteCroppedPixels"] = json!(false);
|
||||
}
|
||||
p["deleteCroppedPixels"] = json!(delete);
|
||||
let plain = plain_control(&mut s, &p);
|
||||
crop(&mut s, p, true);
|
||||
pixel(doc(&s), ids.background, x, y, WHITE);
|
||||
|
||||
@@ -474,27 +474,31 @@ fn root_checkpoints_keep_clipping_groups_and_adjustments_whole() {
|
||||
fn disjoint_partial_damages_admit_whole_chunks_not_damage_rects() {
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut doc = base_doc(600, 300);
|
||||
doc.layers.push(noise_layer("middle", PixelFormat::RGBA8, doc.bounds(), 2, 0.2));
|
||||
doc.layers.push(noise_layer("top", PixelFormat::RGBA8, doc.bounds(), 3, 0.2));
|
||||
// Each layer in a pass of its own (`alone`): batched into one run, the stack has no
|
||||
// checkpoint below the top layer, so no render would capture and the byte count could not
|
||||
// grow whatever the admission did.
|
||||
doc.layers.push(alone(noise_layer("middle", PixelFormat::RGBA8, doc.bounds(), 2, 0.2)));
|
||||
doc.layers.push(alone(noise_layer("top", PixelFormat::RGBA8, doc.bounds(), 3, 0.2)));
|
||||
check(&mut g, &doc, "warm");
|
||||
// Each series paints 8 rectangles. The second series' rectangles are all new (7 px across
|
||||
// and 65 px down from the first's) but in the same chunk (the 600 x 300 document is one
|
||||
// chunk at `CHUNK`), so a cache entry per damage rectangle would add 8 entries. (The four
|
||||
// series of 24 this replaces painted the same 24 rectangles every time.)
|
||||
let strokes = |g: &mut Gpu, doc: &Document, pass: i32| {
|
||||
for i in 0..24u32 {
|
||||
let x = 40 + ((i + pass as u32 * 13) % 8) * 60;
|
||||
let y = 30 + (i / 8) * 60;
|
||||
diff_rect(g, doc, Rect::new(x as i32, y as i32, x as i32 + 40, y as i32 + 30), "stroke").unwrap();
|
||||
for i in 0..8 {
|
||||
let (x, y) = (40 + i * 60 + pass * 7, 30 + pass * 65);
|
||||
diff_rect(g, doc, Rect::new(x, y, x + 40, y + 30), "stroke").unwrap();
|
||||
}
|
||||
};
|
||||
for pass in 0..2 {
|
||||
doc.layers[2].opacity = 0.3 + pass as f32 * 0.1;
|
||||
strokes(&mut g, &doc, pass);
|
||||
}
|
||||
// The same grid chunks hold every stroke: no entry-per-rectangle growth between passes.
|
||||
doc.layers[2].opacity = 0.3;
|
||||
strokes(&mut g, &doc, 0);
|
||||
// The same grid chunks hold every stroke: no entry-per-rectangle growth between series.
|
||||
let bytes = g.comp.composite_cache_bytes();
|
||||
assert!(bytes > 0);
|
||||
for pass in 2..4 {
|
||||
doc.layers[2].opacity = 0.3 + pass as f32 * 0.1;
|
||||
strokes(&mut g, &doc, pass);
|
||||
}
|
||||
// 0.6, the last opacity the four series this replaces left, so what follows renders the
|
||||
// same document as before.
|
||||
doc.layers[2].opacity = 0.6;
|
||||
strokes(&mut g, &doc, 1);
|
||||
assert_eq!(g.comp.composite_cache_bytes(), bytes, "partial damages must not add entries");
|
||||
// A full-canvas render still populates the whole chunks, and the top edit afterwards hits.
|
||||
check(&mut g, &doc, "full refresh after strokes");
|
||||
@@ -1425,7 +1429,12 @@ fn small_layers_composite_over_their_bounds() {
|
||||
check(&mut g, &big, "small layers across chunks");
|
||||
}
|
||||
|
||||
fn many_layers_submit_inside_one_chunk_mode(paged: bool) {
|
||||
/// One compositor is enough: at 16 x 12 the document is one page and one chunk under the whole
|
||||
/// texture limit and under [`PAGED_LIMIT`] alike, and both draw it through the same `run_cell`.
|
||||
/// The paged run this replaces reported the same `Stats`, field for field (1202 passes, 2401
|
||||
/// tiles uploaded, 1 flush, 1 chunk, 1 cell).
|
||||
#[test]
|
||||
fn many_layers_submit_inside_one_chunk_whole() {
|
||||
// P12: a refresh recorded every pass of a page cell into one command buffer, and with a few
|
||||
// hundred layers Metal ran out of command buffers (device lost, "pc_compose_uniforms is
|
||||
// invalid"). 1200 layers need well over 1000 passes in the document's only chunk: each is
|
||||
@@ -1443,24 +1452,13 @@ fn many_layers_submit_inside_one_chunk_mode(paged: bool) {
|
||||
d.layers.push(l);
|
||||
}
|
||||
let cpu = photocraft_compose::render(&d, d.bounds());
|
||||
let comp = if paged { &mut g.paged } else { &mut g.comp };
|
||||
let (out, stats) = photocraft_gpu::render_to_vec_stats(comp, &g.device, &g.queue, &d, d.bounds()).unwrap();
|
||||
assert!(worst_diff(&cpu.px, &out).0 <= TOL, "1200 layers, paged={paged}");
|
||||
let (out, stats) = photocraft_gpu::render_to_vec_stats(&mut g.comp, &g.device, &g.queue, &d, d.bounds()).unwrap();
|
||||
assert!(worst_diff(&cpu.px, &out).0 <= TOL, "1200 layers");
|
||||
assert_eq!(stats.layers_batched, 0, "{stats:?}");
|
||||
assert_eq!(stats.chunks, 1);
|
||||
assert!(stats.flushes > 0, "{stats:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_layers_submit_inside_one_chunk_whole() {
|
||||
many_layers_submit_inside_one_chunk_mode(false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn many_layers_submit_inside_one_chunk_paged() {
|
||||
many_layers_submit_inside_one_chunk_mode(true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runs_of_plain_layers_blend_in_one_pass() {
|
||||
// Consecutive plain layers are drawn several to a pass (`fs_layerbatch`). Every layer mode at
|
||||
@@ -1901,8 +1899,19 @@ fn fx_check(g: &mut Gpu, doc: &Document, what: &str) -> photocraft_gpu::Stats {
|
||||
fn layer_effects_every_kind() {
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut failures = Vec::new();
|
||||
// On the GPU a 16-bit document differs only in the layer upload
|
||||
// (`convert::rgb_gray16_to_f16`) and in what that input does to Dissolve's threshold and to
|
||||
// pattern pixels: 16 bits run every Dissolve and pattern case, and the full stack (every kind
|
||||
// at once) for the rest. Every case runs at 8 bits.
|
||||
let depth_sensitive = |fx: &[Effect]| {
|
||||
let text = format!("{fx:?}");
|
||||
text.contains("Dissolve") || text.contains("Pattern")
|
||||
};
|
||||
for depth in [SampleType::U8, SampleType::U16] {
|
||||
for (name, fx) in effect_cases() {
|
||||
if depth == SampleType::U16 && name != "full stack" && !depth_sensitive(&fx) {
|
||||
continue;
|
||||
}
|
||||
let mut d = fx_doc(96, 80, depth);
|
||||
d.patterns.push(checker_pattern());
|
||||
let mut l = blob("fx", d.pixel_format(), 46.0, 40.0, 22.0, [0.9, 0.4, 0.2]);
|
||||
@@ -1985,6 +1994,12 @@ fn exterior_effects_merge_from_the_shape_at_any_fill() {
|
||||
];
|
||||
for depth in [SampleType::U8, SampleType::U16] {
|
||||
for (name, fx) in &stacks {
|
||||
// The merge (`effect_exterior`, `fs_fxmerge`) has no depth branch on the GPU or the
|
||||
// CPU: depth only changes how the layer is uploaded (`convert::rgb_gray16_to_f16`). The
|
||||
// stack with both effects covers that at 16 bits; every stack runs at 8 bits.
|
||||
if depth == SampleType::U16 && *name != "shadow and glow" {
|
||||
continue;
|
||||
}
|
||||
for (opacity, fill, blend) in [
|
||||
(1.0, 1.0, BlendMode::Normal),
|
||||
(0.8, 0.6, BlendMode::Normal),
|
||||
@@ -3083,30 +3098,50 @@ fn unbuildable_pipelines_are_an_error_not_a_panic() {
|
||||
|
||||
/// A document several pages wide under [`PAGED_LIMIT`]: pixel layers crossing page borders (one
|
||||
/// masked, one off-canvas), a big effect layer whose region exceeds the limit (maps built per
|
||||
/// page cell), a type layer with a shadow, an adjustment, a clipped group and a gradient fill.
|
||||
/// page cell), a type layer with a shadow across a border, an adjustment, a clipped group and a
|
||||
/// gradient fill. 1100 x 900 (5 x 4 pages) for the residency and budget tests, whose views and
|
||||
/// ratios are measured on it.
|
||||
fn big_doc() -> Document {
|
||||
let (w, h) = (1100, 900);
|
||||
big_doc_sized(false)
|
||||
}
|
||||
|
||||
/// [`big_doc`] at 660 x 580, 3 x 3 pages, with every layer moved and sized to cross the same
|
||||
/// borders: the middle cell has page borders on all four sides and the four inner page corners,
|
||||
/// so it holds every border and corner case of the larger document at about 40 % of its pixels.
|
||||
fn small_big_doc() -> Document {
|
||||
big_doc_sized(true)
|
||||
}
|
||||
|
||||
fn big_doc_sized(small: bool) -> Document {
|
||||
// Each geometry as (1100 x 900 value, 660 x 580 value).
|
||||
let pick = |large: [i32; 4], reduced: [i32; 4]| {
|
||||
let [x0, y0, x1, y1] = if small { reduced } else { large };
|
||||
Rect::new(x0, y0, x1, y1)
|
||||
};
|
||||
let (w, h) = if small { (660, 580) } else { (1100, 900) };
|
||||
let mut d = fx_doc(w, h, SampleType::U8);
|
||||
// Right over the background: adjustment results round to 8 bits, which would turn sub-LSB
|
||||
// float differences of blends beneath into whole steps.
|
||||
let mut adj = Layer::new("invert", LayerContent::Adjustment(Adjustment::Invert));
|
||||
adj.opacity = 0.6;
|
||||
adj.mask = Some(mask(Rect::new(240, 0, 800, 520), 83, 0.0));
|
||||
adj.mask = Some(mask(pick([240, 0, 800, 520], [240, 0, 560, 520]), 83, 0.0));
|
||||
d.layers.push(adj);
|
||||
let mut top = noise_layer("top", PixelFormat::RGBA8, Rect::new(-30, 200, 700, 820), 81, 0.0);
|
||||
let mut top = noise_layer("top", PixelFormat::RGBA8, pick([-30, 200, 700, 820], [-30, 200, 620, 600]), 81, 0.0);
|
||||
top.blend = BlendMode::Multiply;
|
||||
top.mask = Some(mask(Rect::new(100, 240, 600, 700), 82, 1.0));
|
||||
top.mask = Some(mask(pick([100, 240, 600, 700], [100, 240, 500, 540]), 82, 1.0));
|
||||
d.layers.push(top);
|
||||
let stack = effect_cases().into_iter().find(|(n, _)| *n == "full stack").unwrap().1;
|
||||
let mut big = blob("big", d.pixel_format(), 520.0, 450.0, 330.0, [0.9, 0.4, 0.2]);
|
||||
let (bx, by, br) = if small { (330.0, 290.0, 200.0) } else { (520.0, 450.0, 330.0) };
|
||||
let mut big = blob("big", d.pixel_format(), bx, by, br, [0.9, 0.4, 0.2]);
|
||||
big.effects.items = stack;
|
||||
big.effects.items.push(Effect::OuterGlow(glow(FxPaint::Color(Color::rgb(0.2, 1.0, 0.6)), GlowTechnique::Softer, 40.0, 0.2, GlowSource::Edge)));
|
||||
d.layers.push(big);
|
||||
let mut text = as_text(blob("type", d.pixel_format(), 900.0, 150.0, 90.0, [0.1, 0.2, 0.9]));
|
||||
let (tx, ty, tr) = if small { (560.0, 120.0, 60.0) } else { (900.0, 150.0, 90.0) };
|
||||
let mut text = as_text(blob("type", d.pixel_format(), tx, ty, tr, [0.1, 0.2, 0.9]));
|
||||
text.effects.items = vec![Effect::DropShadow(shadow(BlendMode::Multiply, 0.8, 135.0, 12.0, 20.0, 0.0))];
|
||||
d.layers.push(text);
|
||||
let a = noise_layer("ga", PixelFormat::RGBA8, Rect::new(200, 500, 1000, 880), 84, 0.6);
|
||||
let mut c = noise_layer("gc", PixelFormat::RGBA8, Rect::new(0, 600, 1100, 700), 85, 0.0);
|
||||
let a = noise_layer("ga", PixelFormat::RGBA8, pick([200, 500, 1000, 880], [150, 400, 620, 570]), 84, 0.6);
|
||||
let mut c = noise_layer("gc", PixelFormat::RGBA8, pick([0, 600, 1100, 700], [0, 450, 660, 520]), 85, 0.0);
|
||||
c.clipped = true;
|
||||
c.blend = BlendMode::Screen;
|
||||
let mut grp = Layer::group("g", vec![a, c]);
|
||||
@@ -3124,20 +3159,20 @@ fn big_doc() -> Document {
|
||||
fn documents_larger_than_the_texture_limit() {
|
||||
let _gamma = TEXT_GAMMA.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut d = big_doc();
|
||||
let mut d = small_big_doc();
|
||||
assert!(g.paged.supports(&d).is_ok());
|
||||
// Every pass sees page borders, and effect maps and blurs crossing them.
|
||||
check(&mut g, &d, "big document");
|
||||
let s = photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, d.bounds()).unwrap().1;
|
||||
assert!(s.cells >= 20 && s.chunks == s.cells, "{s:?}");
|
||||
// A viewport off the page grid covers only its cells.
|
||||
let view = Rect::new(300, 330, 790, 610);
|
||||
assert!(s.cells >= 9 && s.chunks == s.cells, "{s:?}");
|
||||
// A viewport off the page grid covers only its cells (3 x 2).
|
||||
let view = Rect::new(200, 230, 530, 430);
|
||||
diff_rect(&mut g, &d, view, "viewport").unwrap_or_else(|e| panic!("{e}"));
|
||||
let s = photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, view).unwrap().1;
|
||||
assert_eq!(s.cells, 6, "{s:?}");
|
||||
// A dab across a page corner on the effect layer, and an edit elsewhere.
|
||||
d.layers[3].surface_mut().unwrap().fill_rect(Rect::new(500, 490, 530, 530), &[0.1, 0.1, 0.9, 1.0]);
|
||||
d.layers[2].surface_mut().unwrap().fill_rect(Rect::new(250, 250, 270, 270), &[0.0, 0.0, 0.0, 0.0]);
|
||||
d.layers[3].surface_mut().unwrap().fill_rect(Rect::new(240, 240, 270, 270), &[0.1, 0.1, 0.9, 1.0]);
|
||||
d.layers[2].surface_mut().unwrap().fill_rect(Rect::new(500, 250, 520, 270), &[0.0, 0.0, 0.0, 0.0]);
|
||||
check(&mut g, &d, "after dabs");
|
||||
let s = photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, d.bounds()).unwrap().1;
|
||||
assert_eq!((s.tiles_uploaded, s.fx_shapes), (0, 0), "nothing changed since the last render: {s:?}");
|
||||
@@ -3147,13 +3182,15 @@ fn documents_larger_than_the_texture_limit() {
|
||||
fn pages_are_evicted_under_the_budget() {
|
||||
let _gamma = TEXT_GAMMA.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(mut g) = gpu() else { return };
|
||||
let mut d = big_doc();
|
||||
let mut d = small_big_doc();
|
||||
check(&mut g, &d, "warm");
|
||||
let all = g.paged.resident_bytes();
|
||||
// A budget of one page: everything but the cell being drawn is evicted as the render goes.
|
||||
let page = u64::from(g.paged.page_size()).pow(2) * 4;
|
||||
g.paged.set_resident_budget(page);
|
||||
for round in 0..3 {
|
||||
// Round 0 evicts from a warm, fully resident state; round 1 brings back pages evicted with
|
||||
// the edits made meanwhile (a third round repeated round 1).
|
||||
for round in 0..2 {
|
||||
let cpu = timed("eviction CPU reference", || photocraft_compose::flatten(&d));
|
||||
let (out, s) =
|
||||
timed("eviction GPU render/readback", || photocraft_gpu::render_to_vec_stats(&mut g.paged, &g.device, &g.queue, &d, d.bounds())).unwrap();
|
||||
|
||||
Reference in new issue
Block a user