From b7e9763e5a8b0c92a084ec432b70b1838e2085c2 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 Feb 2017 16:06:30 -0800 Subject: [PATCH] Update the benchmark --- examples/benchmark.rs | 67 +++++++++++++++++++++++++------------- examples/generate-atlas.rs | 6 ++-- src/glyph_buffer.rs | 6 ++-- 3 files changed, 51 insertions(+), 28 deletions(-) diff --git a/examples/benchmark.rs b/examples/benchmark.rs index 376cc8d6..202c2b2e 100644 --- a/examples/benchmark.rs +++ b/examples/benchmark.rs @@ -28,9 +28,13 @@ use pathfinder::rasterizer::{Rasterizer, RasterizerOptions}; use std::env; use std::os::raw::c_void; +const ATLAS_SIZE: u32 = 2048; const WIDTH: u32 = 512; const HEIGHT: u32 = 384; +const MIN_TIME_PER_SIZE: u64 = 300_000_000; +const MAX_TIME_PER_SIZE: u64 = 3_000_000_000; + fn main() { let mut glfw = glfw::init(glfw::LOG_ERRORS).unwrap(); glfw.window_hint(WindowHint::ContextVersion(3, 3)); @@ -41,7 +45,7 @@ fn main() { let (mut window, _events) = context.expect("Couldn't create a window!"); window.make_current(); gl::load_with(|symbol| window.get_proc_address(symbol) as *const c_void); - let (device_pixel_width, device_pixel_height) = window.get_framebuffer_size(); + let (device_pixel_width, _) = window.get_framebuffer_size(); let instance = Instance::new().unwrap(); let device = instance.create_device().unwrap(); @@ -54,31 +58,50 @@ fn main() { // FIXME(pcwalton) let shelf_height = point_size * 2; - let mut glyph_buffer_builder = GlyphBufferBuilder::new(); - let mut batch_builder = BatchBuilder::new(device_pixel_width as GLuint, shelf_height); - let file = Mmap::open_path(env::args().nth(1).unwrap(), Protection::Read).unwrap(); - let mut glyph_count = 0; - unsafe { - let font = Font::new(file.as_slice()).unwrap(); - let codepoint_ranges = [CodepointRange::new(' ' as u32, '~' as u32)]; - let glyph_ranges = font.cmap.glyph_ranges_for_codepoint_ranges(&codepoint_ranges) - .unwrap(); - for (glyph_index, glyph_id) in glyph_ranges.iter().enumerate() { - glyph_buffer_builder.add_glyph(&font, glyph_id).unwrap(); - batch_builder.add_glyph(&glyph_buffer_builder, - glyph_index as u32, - point_size as f32) - .unwrap(); - glyph_count += 1 + let mut results = vec![]; + let start = time::precise_time_ns(); + let mut last_time = start; + let (mut glyph_buffer_builder, mut batch_builder, mut glyph_count); + let (mut glyph_buffers, mut batch); + loop { + glyph_buffer_builder = GlyphBufferBuilder::new(); + batch_builder = BatchBuilder::new(device_pixel_width as GLuint, shelf_height); + glyph_count = 0; + unsafe { + let font = Font::new(file.as_slice()).unwrap(); + let codepoint_ranges = [CodepointRange::new(' ' as u32, '~' as u32)]; + + let glyph_ranges = font.cmap.glyph_ranges_for_codepoint_ranges(&codepoint_ranges) + .unwrap(); + for (glyph_index, glyph_id) in glyph_ranges.iter().enumerate() { + glyph_buffer_builder.add_glyph(&font, glyph_id).unwrap(); + batch_builder.add_glyph(&glyph_buffer_builder, + glyph_index as u32, + point_size as f32) + .unwrap(); + glyph_count += 1 + } + } + + glyph_buffers = glyph_buffer_builder.create_buffers().unwrap(); + batch = batch_builder.create_batch(&glyph_buffer_builder).unwrap(); + + let end = time::precise_time_ns(); + results.push((end - last_time) as f64); + if end - start > MAX_TIME_PER_SIZE { + break + } + last_time = end } - let glyph_buffers = glyph_buffer_builder.create_buffers().unwrap(); - let batch = batch_builder.create_batch(&glyph_buffer_builder).unwrap(); + stats::winsorize(&mut results, 5.0); + let time_per_glyph = results.mean() / 1_000.0 / glyph_count as f64; + println!("cpu,{}", time_per_glyph); - let atlas_size = Size2D::new(device_pixel_width as GLuint, device_pixel_height as GLuint); + let atlas_size = Size2D::new(ATLAS_SIZE, ATLAS_SIZE); let coverage_buffer = CoverageBuffer::new(&rasterizer.device, &atlas_size).unwrap(); let texture = rasterizer.device @@ -107,8 +130,8 @@ fn main() { results.push(time_per_glyph); let now = time::precise_time_ns(); - if (now - start_time > 300_000_000 && results.median_abs_dev_pct() < 1.0) || - now - start_time > 3_000_000_000 { + if (now - start_time > MIN_TIME_PER_SIZE && results.median_abs_dev_pct() < 1.0) || + now - start_time > MAX_TIME_PER_SIZE { break } } diff --git a/examples/generate-atlas.rs b/examples/generate-atlas.rs index e90dd181..c0eaaaa5 100644 --- a/examples/generate-atlas.rs +++ b/examples/generate-atlas.rs @@ -65,7 +65,7 @@ fn main() { } let glyph_buffers = glyph_buffer_builder.create_buffers().unwrap(); - let batch = batch_builder.create_atlas(&glyph_buffer_builder).unwrap(); + let batch = batch_builder.create_batch(buffer_builder).unwrap(); let atlas_size = Size2D::new(device_pixel_width as GLuint, device_pixel_height as GLuint); let coverage_buffer = CoverageBuffer::new(&rasterizer.device, &atlas_size).unwrap(); @@ -75,11 +75,11 @@ fn main() { .unwrap(); rasterizer.draw_atlas(&Rect::new(Point2D::new(0, 0), atlas_size), - SHELF_HEIGHT, + &batch_builder.atlas, &glyph_buffers, &batch, &coverage_buffer, - &texture).unwrap().wait().unwrap(); + &texture).unwrap(); let draw_context = lord_drawquaad::Context::new(); diff --git a/src/glyph_buffer.rs b/src/glyph_buffer.rs index 8d70d4be..8d4f7861 100644 --- a/src/glyph_buffer.rs +++ b/src/glyph_buffer.rs @@ -162,11 +162,11 @@ impl GlyphDescriptor { #[derive(Copy, Clone, Debug)] #[repr(C)] pub struct Vertex { - x: i16, - y: i16, + pub x: i16, + pub y: i16, /// TODO(pcwalton): Try omitting this and binary search the glyph descriptors in the vertex /// shader. Might or might not help. - glyph_index: u16, + pub glyph_index: u16, } #[derive(Copy, Clone, Debug)]