diff options
author | 2025-03-09 01:28:35 +0100 | |
---|---|---|
committer | 2025-03-09 01:29:36 +0100 | |
commit | 86e8494bfa460bdbf506695f8f4b4f01a9cf5088 (patch) | |
tree | d155a490eeed4f36bb0a78d78801e77b76be84bc | |
parent | f369bc86e2abb12024cb781cdba94bbfa047c800 (diff) | |
download | iced-86e8494bfa460bdbf506695f8f4b4f01a9cf5088.tar.gz iced-86e8494bfa460bdbf506695f8f4b4f01a9cf5088.tar.bz2 iced-86e8494bfa460bdbf506695f8f4b4f01a9cf5088.zip |
Reuse `wgpu` device in all benchmarks
-rw-r--r-- | benches/wgpu.rs | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/benches/wgpu.rs b/benches/wgpu.rs index de19c4cf..033eb46d 100644 --- a/benches/wgpu.rs +++ b/benches/wgpu.rs @@ -8,44 +8,15 @@ use iced::{ Color, Element, Font, Length, Pixels, Point, Rectangle, Size, Theme, }; use iced_wgpu::Renderer; +use iced_wgpu::wgpu; criterion_main!(benches); criterion_group!(benches, wgpu_benchmark); #[allow(unused_results)] pub fn wgpu_benchmark(c: &mut Criterion) { - c.bench_function("wgpu — canvas (light)", |b| { - benchmark(b, |_| scene(10)); - }); - c.bench_function("wgpu — canvas (heavy)", |b| { - benchmark(b, |_| scene(1_000)); - }); - - c.bench_function("wgpu - layered text (light)", |b| { - benchmark(b, |_| layered_text(10)); - }); - c.bench_function("wgpu - layered text (heavy)", |b| { - benchmark(b, |_| layered_text(1_000)); - }); - - c.bench_function("wgpu - dynamic text (light)", |b| { - benchmark(b, |i| dynamic_text(1_000, i)); - }); - c.bench_function("wgpu - dynamic text (heavy)", |b| { - benchmark(b, |i| dynamic_text(100_000, i)); - }); -} - -fn benchmark<'a>( - bencher: &mut Bencher<'_>, - view: impl Fn(usize) -> Element<'a, (), Theme, Renderer>, -) { use iced_futures::futures::executor; - use iced_wgpu::graphics; - use iced_wgpu::graphics::Antialiasing; use iced_wgpu::wgpu; - use iced_winit::core; - use iced_winit::runtime; let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends: wgpu::Backends::all(), @@ -72,18 +43,53 @@ fn benchmark<'a>( )) .expect("request device"); + c.bench_function("wgpu — canvas (light)", |b| { + benchmark(b, &adapter, &device, &queue, |_| scene(10)); + }); + c.bench_function("wgpu — canvas (heavy)", |b| { + benchmark(b, &adapter, &device, &queue, |_| scene(1_000)); + }); + + c.bench_function("wgpu - layered text (light)", |b| { + benchmark(b, &adapter, &device, &queue, |_| layered_text(10)); + }); + c.bench_function("wgpu - layered text (heavy)", |b| { + benchmark(b, &adapter, &device, &queue, |_| layered_text(1_000)); + }); + + c.bench_function("wgpu - dynamic text (light)", |b| { + benchmark(b, &adapter, &device, &queue, |i| dynamic_text(1_000, i)); + }); + c.bench_function("wgpu - dynamic text (heavy)", |b| { + benchmark(b, &adapter, &device, &queue, |i| dynamic_text(100_000, i)); + }); +} + +fn benchmark<'a>( + bencher: &mut Bencher<'_>, + adapter: &wgpu::Adapter, + device: &wgpu::Device, + queue: &wgpu::Queue, + view: impl Fn(usize) -> Element<'a, (), Theme, Renderer>, +) { + use iced_wgpu::graphics; + use iced_wgpu::graphics::Antialiasing; + use iced_wgpu::wgpu; + use iced_winit::core; + use iced_winit::runtime; + let format = wgpu::TextureFormat::Bgra8UnormSrgb; let mut engine = iced_wgpu::Engine::new( - &adapter, - &device, - &queue, + adapter, + device, + queue, format, Some(Antialiasing::MSAAx4), ); let mut renderer = - Renderer::new(&device, &engine, Font::DEFAULT, Pixels::from(16)); + Renderer::new(device, &engine, Font::DEFAULT, Pixels::from(16)); let viewport = graphics::Viewport::with_physical_size(Size::new(3840, 2160), 2.0); @@ -135,8 +141,8 @@ fn benchmark<'a>( renderer.present::<&str>( &mut engine, - &device, - &queue, + device, + queue, &mut encoder, Some(Color::BLACK), format, @@ -145,7 +151,7 @@ fn benchmark<'a>( &[], ); - let submission = engine.submit(&queue, encoder); + let submission = engine.submit(queue, encoder); let _ = device.poll(wgpu::Maintain::WaitForSubmissionIndex(submission)); i += 1; |