Reuse wgpu device in all benchmarks
This commit is contained in:
parent
f369bc86e2
commit
86e8494bfa
1 changed files with 43 additions and 37 deletions
|
|
@ -8,44 +8,15 @@ use iced::{
|
||||||
Color, Element, Font, Length, Pixels, Point, Rectangle, Size, Theme,
|
Color, Element, Font, Length, Pixels, Point, Rectangle, Size, Theme,
|
||||||
};
|
};
|
||||||
use iced_wgpu::Renderer;
|
use iced_wgpu::Renderer;
|
||||||
|
use iced_wgpu::wgpu;
|
||||||
|
|
||||||
criterion_main!(benches);
|
criterion_main!(benches);
|
||||||
criterion_group!(benches, wgpu_benchmark);
|
criterion_group!(benches, wgpu_benchmark);
|
||||||
|
|
||||||
#[allow(unused_results)]
|
#[allow(unused_results)]
|
||||||
pub fn wgpu_benchmark(c: &mut Criterion) {
|
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_futures::futures::executor;
|
||||||
use iced_wgpu::graphics;
|
|
||||||
use iced_wgpu::graphics::Antialiasing;
|
|
||||||
use iced_wgpu::wgpu;
|
use iced_wgpu::wgpu;
|
||||||
use iced_winit::core;
|
|
||||||
use iced_winit::runtime;
|
|
||||||
|
|
||||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
backends: wgpu::Backends::all(),
|
backends: wgpu::Backends::all(),
|
||||||
|
|
@ -72,18 +43,53 @@ fn benchmark<'a>(
|
||||||
))
|
))
|
||||||
.expect("request device");
|
.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 format = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||||
|
|
||||||
let mut engine = iced_wgpu::Engine::new(
|
let mut engine = iced_wgpu::Engine::new(
|
||||||
&adapter,
|
adapter,
|
||||||
&device,
|
device,
|
||||||
&queue,
|
queue,
|
||||||
format,
|
format,
|
||||||
Some(Antialiasing::MSAAx4),
|
Some(Antialiasing::MSAAx4),
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut renderer =
|
let mut renderer =
|
||||||
Renderer::new(&device, &engine, Font::DEFAULT, Pixels::from(16));
|
Renderer::new(device, &engine, Font::DEFAULT, Pixels::from(16));
|
||||||
|
|
||||||
let viewport =
|
let viewport =
|
||||||
graphics::Viewport::with_physical_size(Size::new(3840, 2160), 2.0);
|
graphics::Viewport::with_physical_size(Size::new(3840, 2160), 2.0);
|
||||||
|
|
@ -135,8 +141,8 @@ fn benchmark<'a>(
|
||||||
|
|
||||||
renderer.present::<&str>(
|
renderer.present::<&str>(
|
||||||
&mut engine,
|
&mut engine,
|
||||||
&device,
|
device,
|
||||||
&queue,
|
queue,
|
||||||
&mut encoder,
|
&mut encoder,
|
||||||
Some(Color::BLACK),
|
Some(Color::BLACK),
|
||||||
format,
|
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));
|
let _ = device.poll(wgpu::Maintain::WaitForSubmissionIndex(submission));
|
||||||
|
|
||||||
i += 1;
|
i += 1;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue