PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge remote-tracking branch 'origin/main' into fix/4017-huge-new-document
David Mann0739ff48c5ab
diff --cc crates/ui-egui/src/gpu_canvas.rsindex 2a360ad14,012bcf801..95d073447--- a/crates/ui-egui/src/gpu_canvas.rs+++ b/crates/ui-egui/src/gpu_canvas.rs@@@ -1618,34 -1776,11 +1776,34 @@@ fn init_buffer(device: &wgpu::Device, limpl DocTextures {/// The texture set for a `size` canvas, or `None` (nothing created) when it doesn't fit- /// the canvas budget.+ /// the canvas budget or the GPU's memory. A set the GPU can't hold (a 3 GP canvas is 16 GB+ /// of textures, #4017) lowers the budget below it, so that canvas and larger ones are drawn+ /// on the CPU canvas instead of the out-of-memory error disabling the GPU for the session.- fn new(device: &wgpu::Device, res: &mut Resources, size: [u32; 2], tile: u32, format: wgpu::TextureFormat) -> Option<Self> {+ fn new(device: &wgpu::Device, res: &Resources, size: [u32; 2], tile: u32, format: wgpu::TextureFormat) -> Option<Self> {- if canvas_texture_bytes(size, tile, texel_bytes(format)) > res.canvas_budget.load(Ordering::Relaxed) {+ let bytes = canvas_texture_bytes(size, tile, texel_bytes(format));- if bytes > res.canvas_budget {++ if bytes > res.canvas_budget.load(Ordering::Relaxed) {return None;}+ let validation = device.push_error_scope(wgpu::ErrorFilter::Validation);+ let memory = device.push_error_scope(wgpu::ErrorFilter::OutOfMemory);+ let set = Self::create(device, res, size, tile, format);+ // Native wgpu reports these synchronously; where they arrive later (WebGPU) none is seen.+ let mut cx = std::task::Context::from_waker(std::task::Waker::noop());+ let mut error = None;+ for pop in [memory.pop(), validation.pop()] {+ if let std::task::Poll::Ready(Some(e)) = std::pin::pin!(pop).poll(&mut cx) {+ error.get_or_insert(e);+ }+ }+ if let Some(e) = error {+ log::warn!("{} MB of canvas textures failed ({e}); larger canvases are drawn on the CPU", bytes >> 20);- res.canvas_budget = res.canvas_budget.min(bytes.saturating_sub(1));++ res.canvas_budget.fetch_min(bytes.saturating_sub(1), Ordering::Relaxed);+ return None;+ }+ Some(set)+ }++ fn create(device: &wgpu::Device, res: &Resources, size: [u32; 2], tile: u32, format: wgpu::TextureFormat) -> Self {let mut tiles = Vec::new();for ty in (0..size[1]).step_by(tile as usize) {for tx in (0..size[0]).step_by(tile as usize) {diff --cc crates/ui-egui/src/gpu_canvas_mip_tests.rsindex b61b77ff1,82e911bae..03b373167--- a/crates/ui-egui/src/gpu_canvas_mip_tests.rs+++ b/crates/ui-egui/src/gpu_canvas_mip_tests.rs@@@ -63,30 -64,6 +64,31 @@@ fn canvas_mips_preserve_opaque_pixels_agpu.rs.renderer.write().callback_resources.get_mut::<Resources>().unwrap().separate_mip_targets = separate;check_mips(&gpu);}+ // On the same device (see the top of the file).+ canvas_textures_the_gpu_refuses_leave_it_working(&gpu);+}++/// #4017: a 3 GP canvas's 16 GB of textures failed with Out of Memory, and the uncaptured error+/// disabled the GPU for the session. A refused set is now caught: nothing is kept, the budget+/// drops below it (that canvas goes to the CPU canvas) and the device stays usable. A texture+/// wider than the device allows is refused the same way, synchronously, on any adapter.+fn canvas_textures_the_gpu_refuses_leave_it_working(gpu: &GpuCanvas) {+ let max = gpu.rs.device.limits().max_texture_dimension_2d;+ let (size, tile) = ([max + 1, 1], max + 1);+ let bytes = canvas_texture_bytes(size, tile, texel_bytes(FORMAT));+ {+ let mut renderer = gpu.rs.renderer.write();+ let res = renderer.callback_resources.get_mut::<Resources>().unwrap();- res.canvas_budget = u64::MAX;++ res.canvas_budget.store(u64::MAX, Ordering::Relaxed);+ assert!(DocTextures::new(&gpu.rs.device, res, size, tile, FORMAT).is_none());- assert!(res.canvas_budget < bytes, "{} >= {bytes}", res.canvas_budget);++ let budget = res.canvas_budget.load(Ordering::Relaxed);++ assert!(budget < bytes, "{budget} >= {bytes}");+ }+ assert!(gpu.health.is_ok(), "{:?}", gpu.fault());+ // Smaller canvases still get GPU textures.+ gpu.upload_buffer_full(3, &Buffer::filled(Rect::from_xywh(0, 0, 64, 64), [0.5, 0.5, 0.5, 1.0]), SampleType::U8);+ assert!(gpu.rs.renderer.read().callback_resources.get::<Resources>().unwrap().docs.contains_key(&3));+ assert!(gpu.health.is_ok(), "{:?}", gpu.fault());}fn check_mips(gpu: &GpuCanvas) {diff --cc docs/scorecard.mdindex ab4619356,377ce8583..3d4d87a68--- a/docs/scorecard.md+++ b/docs/scorecard.md@@@ -6,10 -6,10 +6,10 @@@ Generated by `cargo xtask scorecard` fr| Area | Done | Partial | Missing | Key numbers ||---|---:|---:|---:|---|- | [Performance](#performance) | 3 | 22 | 23 | 57 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 18 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) |++| [Performance](#performance) | 3 | 22 | 25 | 59 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 20 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 166 (target 0) |+ | [Workspace and UI](#workspace-and-ui) | 13 | 6 | 4 | settings that do nothing: 26 of 168 (target 0) || [Type](#type) | 4 | 3 | 2 | || [Automation](#automation) | 5 | 2 | 4 | 631 of 631 menu items live (100.0%) || [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 29 of 29 crates; panic_hunt present |@@@ -75,7 -75,8 +75,9 @@@ Baseline: 2026-10-05, commit `f5d2bcb54| 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 | |- | P61 | File > New 10 x 5 m at 200 ppi (3.1 GP) + first reduced canvas refresh | track only | – | – | – | – | – | not run | [#4017](https://github.com/storytold/photocraft/issues/4017) |+ | 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) |++| P62 | File > New 10 x 5 m at 200 ppi (3.1 GP) + first reduced canvas refresh | track only | – | – | – | – | – | not run | [#4017](https://github.com/storytold/photocraft/issues/4017) |**Not measurable yet** (the code can't do it yet; no number is recorded):diff --cc perf/budgets.tomlindex d02f7d1ce,da47aa050..641c13a74--- a/perf/budgets.toml+++ b/perf/budgets.toml@@@ -519,9 -519,20 +519,27 @@@ title = "Chisel bevel size change, 12 Mbench = "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++++[[scenario]]++id = "P62"+title = "File > New 10 x 5 m at 200 ppi (3.1 GP) + first reduced canvas refresh"+issue = 4017+bench = "perf_scenarios"+row = "new 3 GP document + first reduced canvas refresh"