diff --git a/crates/gpu/src/readback.rs b/crates/gpu/src/readback.rs index ab2e5f2bc5..ccb144d3bb 100644 --- a/crates/gpu/src/readback.rs +++ b/crates/gpu/src/readback.rs @@ -59,8 +59,13 @@ pub fn render_to_vec_stats( let rect = rect.intersect(&doc.bounds()); // This helper holds every staging buffer and the whole result at once (tests and tools): refuse // a rectangle whose pixel vector alone would pass 4 GiB. Use `render_bands` for larger ones. - if u64::from(rect.width()) * u64::from(rect.height()) > MAX_VEC_READBACK_PIXELS { - return Err(Unsupported(format!("{}x{} is too large to read back in one piece; use render_bands", rect.width(), rect.height()))); + let max_pixels = MAX_VEC_READBACK_PIXELS.min(isize::MAX as u64 / std::mem::size_of::<[f32; 4]>() as u64); + if u64::from(rect.width()) * u64::from(rect.height()) > max_pixels { + return Err(Unsupported(format!( + "{}x{} is too large to read back in one piece; use render_bands (8-bit documents) or the CPU compositor", + rect.width(), + rect.height() + ))); } let mut staging: Vec<(Rect, wgpu::Buffer, u32)> = Vec::new(); let mut bpp = 16u32; diff --git a/crates/gpu/tests/it/bounded_readback.rs b/crates/gpu/tests/it/bounded_readback.rs index 29b94d5048..8c0de0813e 100644 --- a/crates/gpu/tests/it/bounded_readback.rs +++ b/crates/gpu/tests/it/bounded_readback.rs @@ -320,5 +320,5 @@ fn one_piece_readback_refuses_a_canvas_it_cannot_hold() { // 20000 x 20000 px = 6.4 GB of RGBA32F; refused before any buffer is made. let doc = Document::with_background("huge", Size::new(20_000, 20_000), ColorMode::Rgb, SampleType::U8, Color::WHITE); let e = render_to_vec(&mut comp, ctx.device(), ctx.queue(), &doc, doc.bounds()).unwrap_err(); - assert!(e.0.contains("render_bands"), "{}", e.0); + assert!(e.0.contains("too large to read back"), "{}", e.0); } diff --git a/crates/ui-egui/examples/fx_bench.rs b/crates/ui-egui/examples/fx_bench.rs index 6c6b259c00..3569e7e7ff 100644 --- a/crates/ui-egui/examples/fx_bench.rs +++ b/crates/ui-egui/examples/fx_bench.rs @@ -239,7 +239,10 @@ fn main() { let (w, h) = arg(&args, "--size").and_then(|s| s.split_once('x').and_then(|(a, b)| Some((a.parse().ok()?, b.parse().ok()?)))).unwrap_or((7360, 4912)); synthetic(w, h) }; - assert!(fits(&doc), "canvas {}x{} is over {MAX_BENCH_PIXELS} pixels", doc.size.width, doc.size.height); + if !fits(&doc) { + eprintln!("canvas {}x{} is over {MAX_BENCH_PIXELS} pixels", doc.size.width, doc.size.height); + return; + } let full = doc.bounds(); println!("document {}x{} ({} layers)", doc.size.width, doc.size.height, doc.walk().len()); let mut g = gpu();