// Measures the per-frame cost at several canvas sizes, isolating the readback // path from windowing. use dr_gpu::{GpuContext, RenderTarget}; use std::time::Instant; fn main() { env_logger::init(); let ctx = pollster::block_on(GpuContext::new_headless()).unwrap(); println!("adapter: {}\n", ctx.adapter_name()); println!( "{:>12} {:>10} {:>10} {:>8}", "size", "compute", "+readback", "fps" ); for &(w, h) in &[ (840u32, 692u32), (1280, 720), (1920, 1080), (2048, 1152), (3840, 2160), ] { let rt = RenderTarget::new(&ctx, w, h).unwrap(); // warm for i in 0..10 { rt.render(i as f32 * 0.01); let _ = pollster::block_on(rt.read_pixels()); } let n = 40; let t0 = Instant::now(); for i in 0..n { rt.render(i as f32 * 0.01); } ctx.device .poll(wgpu::PollType::wait_indefinitely()) .expect("poll"); let compute = t0.elapsed().as_secs_f64() / n as f64; let t1 = Instant::now(); for i in 0..n { rt.render(i as f32 * 0.01); let _ = pollster::block_on(rt.read_pixels()).unwrap(); } let full = t1.elapsed().as_secs_f64() / n as f64; println!( "{:>5}x{:<6} {:>8.2}ms {:>8.2}ms {:>8.0}", w, h, compute * 1000.0, full * 1000.0, 1.0 / full ); } }