GPU memory: typed discrete check; the status and budget follow a GPU Memory change at once (measure_fit); perf rows P60/P61 for whole-document edits among 150 full-canvas layers under the app's budget

This commit is contained in:
Tanish Manku committed 2026-10-15 21:06:55 -07:00
1 parent 93c8e49954
commit ea8f55f8f9
5 files changed
+127 -6

No files matched your search

+66 -1
View File
@@ -242,6 +242,8 @@ struct Sizes {
big_layer: (u32, u32),
/// Layers in the "150-layer document".
many_layers: usize,
/// The full-canvas layers document (L3): size and layer count.
full_layers: (u32, u32, usize),
/// The 16-bit document (15000 × 10000).
huge16: (u32, u32),
/// The 32-bit document with 20 layers.
@@ -258,6 +260,7 @@ const FULL: Sizes = Sizes {
layered: (5472, 3648),
big_layer: (4243, 2828),
many_layers: 150,
full_layers: (3000, 2000, 150),
huge16: (15000, 10000),
float32: (4000, 3000),
ten_mp: (3872, 2592),
@@ -269,6 +272,7 @@ const QUICK: Sizes = Sizes {
layered: (1600, 1066),
big_layer: (1200, 800),
many_layers: 40,
full_layers: (800, 600, 20),
huge16: (2400, 1600),
float32: (1200, 900),
ten_mp: (1200, 800),
@@ -357,9 +361,10 @@ fn main() {
// A panic in one group (a crash the scenario found) is reported against the row that was
// running, and the other groups still run.
type Group = fn(&mut Bench, &Sizes);
let groups: [(&str, Group); 5] = [
let groups: [(&str, Group); 6] = [
("layered", layered_scenarios),
("many layers", many_layer_scenarios),
("full-canvas layers", full_canvas_layer_scenarios),
("bit depths", depth_scenarios),
("long operations", job_scenarios),
("algorithms", algorithm_scenarios),
@@ -539,6 +544,66 @@ fn layered_scenarios(b: &mut Bench, sz: &Sizes) {
}
/// #209: arrow-key nudge in the 150-layer document; #1771: a new layer there.
/// Layers overhaul L3: edits that redraw the whole document (a layer's opacity, hiding it) with
/// many full-canvas layers, under the app's own GPU memory budget (Memory Usage at its default,
/// the adapter's kind; `gpu_canvas::memory_budget`). Past what the budget holds, each one went to
/// the CPU compositor (2.6 s at 150 layers of 6 MP on a discrete card).
fn full_canvas_layer_scenarios(b: &mut Bench, sz: &Sizes) {
let opacity = "opacity of a layer among many full-canvas layers + refresh";
let hide = "hide a layer among many full-canvas layers + refresh";
if !b.wanted(opacity) && !b.wanted(hide) {
return;
}
b.current = Some(opacity.to_string());
let (w, h, n) = sz.full_layers;
let mut s = Session::new();
let built = (|| -> Res<u64> {
exec(&mut s, "file.new", json!({"width": w, "height": h, "background": "white"}))?;
let mut mid = 0;
for i in 0..n as u32 {
exec(&mut s, "layer.new.layer", json!({"name": format!("full {i}")}))?;
exec(&mut s, "edit.fill", json!({"color": format!("#{:02x}{:02x}80", (i * 37) % 256, (i * 91) % 256), "opacity": 3}))?;
if i % 7 == 3 {
exec(&mut s, "layer.layerStyle.dropShadow", json!({"distance": 6, "size": 8}))?;
}
if i as usize == n / 2 {
mid = active_layer(&s)?;
}
}
Ok(mid)
})();
let mid = match built {
Ok(v) => v,
Err(e) => {
b.errors.push((opacity.to_string(), e));
return;
}
};
if let (Some((g, _)), Some(st)) = (&b.gpu, s.active()) {
let pixels = st.history.pixel_bytes(&st.doc) as u64;
let allowance = u64::from(photocraft_engine::prefs::Performance::default().memory_usage_mb) << 20;
g.set_memory_budget(photocraft_ui_egui::gpu_canvas::memory_budget(
allowance,
pixels,
photocraft_ui_egui::gpu_canvas::physical_memory(),
g.dedicated_memory(),
0,
));
}
let _ = b.refresh(&s, true);
let reps = b.reps;
b.time(opacity, &mut s, reps, true, |b, s, i| {
let t = Instant::now();
exec(s, "layer.setProps", json!({"layer": mid, "opacity": if i % 2 == 0 { 0.5 } else { 1.0 }}))?;
Ok(ms(t) + b.refresh(s, false)?)
});
b.time(hide, &mut s, reps, true, |b, s, i| {
let t = Instant::now();
exec(s, "layer.setProps", json!({"layer": mid, "visible": i % 2 == 1}))?;
Ok(ms(t) + b.refresh(s, false)?)
});
}
fn many_layer_scenarios(b: &mut Bench, sz: &Sizes) {
// Row names stay stable across modes: the layer count is in the mode, not the key.
let name = "nudge 1 px in the many-layer document + refresh".to_string();
+19 -4
View File
@@ -1615,7 +1615,13 @@ fn ensure_gpu(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usize, visible:
grid: None,
});
let present = cache.on_gpu && gpu.has(id.0, size);
if present && cache.revision == revision && cache.preview_key == preview_key {
let current = cache.revision == revision && cache.preview_key == preview_key;
// GPU Memory or Memory Usage changed with nothing to redraw: the new budget, and whether the
// layers fit it, show at once (the status bar's GPU Memory Full).
if present && app.perf.gpu_budget_allowance != budget_allowance(app) {
gpu_budget(app, &gpu, idx, false, visible);
}
if present && current {
// An adjustment preview composited where the view was: catch up where it moved to.
if let Some(r) = crate::adjust_preview::uncovered(app, id, raw_key, visible) {
let r = gpu.refresh(id.0, &doc, Some(r), display.as_deref());
@@ -1680,9 +1686,9 @@ fn ensure_gpu(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usize, visible:
/// structural change, not per brush dab) and whenever either preference changes.
fn gpu_budget(app: &mut PhotocraftApp, gpu: &crate::gpu_canvas::GpuCanvas, idx: usize, partial: bool, visible: DRect) {
gpu.set_focus(Some(visible));
let performance = &app.session.prefs().performance;
let allowance = (u64::from(performance.memory_usage_mb).saturating_mul(1 << 20), u64::from(performance.gpu_memory_mb).saturating_mul(1 << 20));
if partial && app.perf.gpu_budget_allowance == allowance && gpu.memory_budget().is_some() {
let allowance = budget_allowance(app);
let changed = app.perf.gpu_budget_allowance != allowance;
if partial && !changed && gpu.memory_budget().is_some() {
return;
}
let Some(st) = app.session.documents().get(idx) else { return };
@@ -1691,6 +1697,15 @@ fn gpu_budget(app: &mut PhotocraftApp, gpu: &crate::gpu_canvas::GpuCanvas, idx:
gpu.set_memory_budget(budget);
app.perf.gpu_budget_mb = budget >> 20;
app.perf.gpu_budget_allowance = allowance;
if changed && let Some(fit) = gpu.measure_fit(&st.doc) {
app.perf.gpu_layer_fit = Some(fit);
}
}
/// Memory Usage and GPU Memory (Preferences › Performance), in bytes.
fn budget_allowance(app: &PhotocraftApp) -> (u64, u64) {
let performance = &app.session.prefs().performance;
(u64::from(performance.memory_usage_mb).saturating_mul(1 << 20), u64::from(performance.gpu_memory_mb).saturating_mul(1 << 20))
}
/// Live preview for an open filter dialog: run the filter on the proxy and upload it. With
+21
View File
@@ -303,6 +303,27 @@ impl GpuCanvas {
Some((c.resident_bytes(), c.fx_cache_bytes().saturating_add(usize::try_from(c.composite_cache_bytes()).unwrap_or(usize::MAX))))
}
/// Whether the adapter has memory of its own (a discrete card): the document's pixels and
/// History don't share it ([`memory_budget`]).
pub fn dedicated_memory(&self) -> bool {
self.rs.adapter.get_info().device_type == wgpu::DeviceType::DiscreteGpu
}
/// Whether `doc`'s layers fit the budget as it now stands, measured without a refresh (a GPU
/// Memory change shows in the status bar at once). `None` before the compositor exists.
pub fn measure_fit(&self, doc: &photocraft_doc::Document) -> Option<LayerFit> {
let mut r = self.rs.renderer.write();
let res = r.callback_resources.get_mut::<Resources>()?;
let budget = res.compositor_budget;
let comp = res.compositor.as_mut()?;
if let Some(b) = budget {
comp.set_memory_budget(b);
}
let fit = LayerFit { doc: doc.id.0, needed: comp.working_set(doc, doc.bounds()), budget: comp.resident_budget() };
res.layer_fit = Some(fit);
Some(fit)
}
/// Whether the layers of the last full (or large) refresh fit the GPU memory budget, and by
/// how much (`None` before the first one).
pub fn layer_fit(&self) -> Option<LayerFit> {
+3 -1
View File
@@ -6,7 +6,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js
| Area | Done | Partial | Missing | Key numbers |
|---|---:|---:|---:|---|
| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 17 not run, 5 not measurable yet (baseline 2026-10-05) |
| [Performance](#performance) | 3 | 22 | 24 | 58 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 19 not run, 5 not measurable yet (baseline 2026-10-05) |
| [File compatibility](#file-compatibility) | 7 | 14 | 6 | io corpus: oracle ≥ 148/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 249/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 188/256, round trip ≥ 258/256 |
| [Tools](#tools) | 33 | 11 | 0 | |
| [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 26 of 167 (target 0) |
@@ -75,6 +75,8 @@ Baseline: 2026-10-05, commit `f5d2bcb54a`, Apple M4 Pro (48 GB), GPU Apple M4 Pr
| P57 | Chisel bevel size change, 12 MP text paragraph, size 250 (GPU) | track only | – | – | – | – | – | not run | |
| P58 | Chisel bevel size change, 12 MP ellipse, size 8 (CPU) | track only | – | – | – | – | – | not run | |
| P59 | Chisel bevel size change, 12 MP text paragraph, size 8 (CPU) | track only | – | – | – | – | – | not run | |
| P60 | Layer opacity among 150 full-canvas layers, 6 MP (app GPU budget) | ≤ 30 ms p95 | – | – | – | – | – | not run | [#5973](https://github.com/storytold/photocraft/issues/5973) |
| P61 | Hide a layer among 150 full-canvas layers, 6 MP (app GPU budget) | ≤ 30 ms p95 | – | – | – | – | – | not run | [#5973](https://github.com/storytold/photocraft/issues/5973) |
**Not measurable yet** (the code can't do it yet; no number is recorded):
+18
View File
@@ -518,3 +518,21 @@ id = "P59"
title = "Chisel bevel size change, 12 MP text paragraph, size 8 (CPU)"
bench = "bevel_bench"
row = "bevel size change to 8, text (CPU)"
[[scenario]]
id = "P60"
title = "Layer opacity among 150 full-canvas layers, 6 MP (app GPU budget)"
issue = 5973
bench = "perf_scenarios"
row = "opacity of a layer among many full-canvas layers + refresh"
budget_ms = 30
enforce = false # new; no baseline yet
[[scenario]]
id = "P61"
title = "Hide a layer among 150 full-canvas layers, 6 MP (app GPU budget)"
issue = 5973
bench = "perf_scenarios"
row = "hide a layer among many full-canvas layers + refresh"
budget_ms = 30
enforce = false # new; no baseline yet