From 9bda572b60817ab97fe2f4b3475abe7c9c985381 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Jan 2016 17:54:14 -0800 Subject: [PATCH 1/2] Don't spin up a thread pool for raster jobs if there aren't any. --- src/resource_cache.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/resource_cache.rs b/src/resource_cache.rs index 0c2750a96c..13cf229d15 100644 --- a/src/resource_cache.rs +++ b/src/resource_cache.rs @@ -358,6 +358,10 @@ fn run_raster_jobs(thread_pool: &mut scoped_threadpool::Pool, font_templates: &HashMap>, device_pixel_ratio: f32, enable_aa: bool) { + if pending_raster_jobs.is_empty() { + return + } + // Run raster jobs in parallel thread_pool.scoped(|scope| { for job in pending_raster_jobs { From b8cf78bedb4985d1870686d1619a2c187a74982c Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 7 Jan 2016 17:54:33 -0800 Subject: [PATCH 2/2] Atomically reference count batches instead of copying them. --- src/batch.rs | 5 +++-- src/frame.rs | 7 +------ src/internal_types.rs | 9 ++------- src/renderer.rs | 24 ++++++++++++------------ 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/src/batch.rs b/src/batch.rs index 4f15e88c01..f2c263fe62 100644 --- a/src/batch.rs +++ b/src/batch.rs @@ -3,6 +3,7 @@ use euclid::{Point2D, Rect, Size2D}; use internal_types::{MAX_RECT, AxisDirection, PackedVertex, PackedVertexForTextureCacheUpdate, Primitive}; use std::sync::atomic::Ordering::SeqCst; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT}; +use std::sync::Arc; use std::u16; use webrender_traits::{ComplexClipRegion}; @@ -236,8 +237,8 @@ impl<'a> BatchBuilder<'a> { } } - pub fn finalize(self) -> Vec { - self.batches + pub fn finalize(self) -> Vec> { + self.batches.into_iter().map(|batch| Arc::new(batch)).collect() } pub fn next_draw_list(&mut self) { diff --git a/src/frame.rs b/src/frame.rs index 756474ef68..6d1f977ffd 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -166,13 +166,8 @@ impl RenderTarget { for batch in &batch_list.batches { batch_info.draw_calls.push(DrawCall { - tile_params: batch.tile_params.clone(), // TODO(gw): Move this instead? - clip_rects: batch.clip_rects.clone(), // Ditto + batch: (*batch).clone(), vertex_buffer_id: vertex_buffer_id, - color_texture_id: batch.color_texture_id, - mask_texture_id: batch.mask_texture_id, - first_vertex: batch.first_vertex, - index_count: batch.index_count, }); } } diff --git a/src/internal_types.rs b/src/internal_types.rs index 719563300b..c5a9025ce1 100644 --- a/src/internal_types.rs +++ b/src/internal_types.rs @@ -325,13 +325,8 @@ pub struct ClearInfo { #[derive(Clone, Debug)] pub struct DrawCall { - pub tile_params: Vec, - pub clip_rects: Vec>, + pub batch: Arc, pub vertex_buffer_id: VertexBufferId, - pub color_texture_id: TextureId, - pub mask_texture_id: TextureId, - pub first_vertex: u32, - pub index_count: u16, } #[derive(Clone, Debug)] @@ -495,7 +490,7 @@ pub enum Primitive { #[derive(Debug)] pub struct BatchList { - pub batches: Vec, + pub batches: Vec>, pub draw_list_group_id: DrawListGroupId, } diff --git a/src/renderer.rs b/src/renderer.rs index e04ec4b574..f7e08b9208 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -971,10 +971,10 @@ impl Renderer { let vao_id = self.vertex_buffers[&draw_call.vertex_buffer_id].vao_id; self.device.bind_vao(vao_id); - if draw_call.tile_params.len() > 0 { + if draw_call.batch.tile_params.len() > 0 { // TODO(gw): Avoid alloc here... let mut floats = Vec::new(); - for vec in &draw_call.tile_params { + for vec in &draw_call.batch.tile_params { floats.push(vec.u0); floats.push(vec.v0); floats.push(vec.u_size); @@ -985,10 +985,10 @@ impl Renderer { &floats); } - if draw_call.clip_rects.len() > 0 { + if draw_call.batch.clip_rects.len() > 0 { // TODO(gw): Avoid alloc here... let mut floats = Vec::new(); - for rect in &draw_call.clip_rects { + for rect in &draw_call.batch.clip_rects { floats.push(rect.origin.x); floats.push(rect.origin.y); floats.push(rect.origin.x + rect.size.width); @@ -999,27 +999,27 @@ impl Renderer { &floats); } - self.device.bind_mask_texture(draw_call.mask_texture_id); - self.device.bind_color_texture(draw_call.color_texture_id); + self.device.bind_mask_texture(draw_call.batch.mask_texture_id); + self.device.bind_color_texture(draw_call.batch.color_texture_id); // TODO(gw): Although a minor cost, this is an extra hashtable lookup for every // draw call, when the batch textures are (almost) always the same. // This could probably be cached or provided elsewhere. - let color_size = self.device - .get_texture_dimensions(draw_call.color_texture_id); - let mask_size = self.device - .get_texture_dimensions(draw_call.mask_texture_id); + let color_size = + self.device.get_texture_dimensions(draw_call.batch.color_texture_id); + let mask_size = + self.device.get_texture_dimensions(draw_call.batch.mask_texture_id); self.device.set_uniform_4f(self.u_atlas_params, color_size.0 as f32, color_size.1 as f32, mask_size.0 as f32, mask_size.1 as f32); - let index_count = draw_call.index_count as i32; + let index_count = draw_call.batch.index_count as i32; self.profile_counters.draw_calls.inc(); - self.device.draw_triangles_u16(draw_call.first_vertex as i32, + self.device.draw_triangles_u16(draw_call.batch.first_vertex as i32, index_count); } }