Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync changes from mozilla-central gfx/wr #3850

Merged
merged 4 commits into from Feb 5, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Bug 1613167 - Enable/Disable rayon in WebRender via pref. r=gw

We need a way to switch it on and off to compare the performance and power usage of various test cases.
The new pref is "webrender.enable-multithreading" and does not require a restart.

Differential Revision: https://phabricator.services.mozilla.com/D61589

[ghsync] From https://hg.mozilla.org/mozilla-central/rev/a9dde10ff4b84810ca804e74caf30e221345d9ed
  • Loading branch information
nical authored and moz-gfx committed Feb 5, 2020
commit a1d3a1cfa8177ef39d88e3515734cf14526b3e21
@@ -160,6 +160,7 @@ impl api::BlobImageHandler for CheckerboardRenderer {
_requests: &[api::BlobImageParams],
) {}

fn enable_multithreading(&mut self, _: bool) {}
fn delete_font(&mut self, _font: api::FontKey) {}
fn delete_font_instance(&mut self, _instance: api::FontInstanceKey) {}
fn clear_namespace(&mut self, _namespace: api::IdNamespace) {}
@@ -108,6 +108,10 @@ impl GlyphRasterizer {
self.request_glyphs_from_backend(font, new_glyphs);
}

pub fn enable_multithreading(&mut self, enable: bool) {
self.enable_multithreading = enable;
}

pub(in super) fn request_glyphs_from_backend(&mut self, font: FontInstance, glyphs: Vec<GlyphKey>) {
let font_contexts = Arc::clone(&self.font_contexts);
let glyph_tx = self.glyph_tx.clone();
@@ -154,7 +158,7 @@ impl GlyphRasterizer {

// if the number of glyphs is small, do it inline to avoid the threading overhead;
// send the result into glyph_tx so downstream code can't tell the difference.
if glyphs.len() < 8 {
if !self.enable_multithreading || glyphs.len() < 8 {
let jobs = glyphs.iter()
.map(|key: &GlyphKey| process_glyph(key, &font_contexts, &font))
.collect();
@@ -880,6 +884,9 @@ pub struct GlyphRasterizer {

#[allow(dead_code)]
next_gpu_glyph_cache_key: GpuGlyphCacheKey,

// Whether to parallelize glyph rasterization with rayon.
enable_multithreading: bool,
}

impl GlyphRasterizer {
@@ -912,6 +919,7 @@ impl GlyphRasterizer {
fonts_to_remove: Vec::new(),
font_instances_to_remove: Vec::new(),
next_gpu_glyph_cache_key: GpuGlyphCacheKey(0),
enable_multithreading: true,
})
}

@@ -1254,6 +1254,10 @@ impl RenderBackend {
// We don't want to forward this message to the renderer.
return RenderBackendStatus::Continue;
}
DebugCommand::EnableMultithreading(enable) => {
self.resource_cache.enable_multithreading(enable);
return RenderBackendStatus::Continue;
}
DebugCommand::SimulateLongSceneBuild(time_ms) => {
self.scene_tx.send(SceneBuilderRequest::SimulateLongSceneBuild(time_ms)).unwrap();
return RenderBackendStatus::Continue;
@@ -2285,6 +2285,7 @@ impl Renderer {
scene_tx.clone()
};

let enable_multithreading = options.enable_multithreading;
thread::Builder::new().name(rb_thread_name.clone()).spawn(move || {
register_thread_with_profiler(rb_thread_name.clone());
if let Some(ref thread_listener) = *thread_listener_for_render_backend {
@@ -2306,13 +2307,15 @@ impl Renderer {

let glyph_cache = GlyphCache::new(max_glyph_cache_size);

let resource_cache = ResourceCache::new(
let mut resource_cache = ResourceCache::new(
texture_cache,
glyph_rasterizer,
glyph_cache,
blob_image_handler,
);

resource_cache.enable_multithreading(enable_multithreading);

let mut backend = RenderBackend::new(
api_rx,
payload_rx_for_backend,
@@ -2874,7 +2877,8 @@ impl Renderer {
DebugCommand::ClearCaches(_)
| DebugCommand::SimulateLongSceneBuild(_)
| DebugCommand::SimulateLongLowPrioritySceneBuild(_)
| DebugCommand::EnableNativeCompositor(_) => {}
| DebugCommand::EnableNativeCompositor(_)
| DebugCommand::EnableMultithreading(_) => {}
DebugCommand::InvalidateGpuCache => {
match self.gpu_cache_texture.bus {
GpuCacheBus::PixelBuffer { ref mut rows, .. } => {
@@ -6222,6 +6226,7 @@ pub struct RendererOptions {
pub scatter_gpu_cache_updates: bool,
pub upload_method: UploadMethod,
pub workers: Option<Arc<ThreadPool>>,
pub enable_multithreading: bool,
pub blob_image_handler: Option<Box<dyn BlobImageHandler>>,
pub recorder: Option<Box<dyn ApiRecordingReceiver>>,
pub thread_listener: Option<Box<dyn ThreadListener + Send + Sync>>,
@@ -6295,6 +6300,7 @@ impl Default for RendererOptions {
// but we are unable to make this decision here, so picking the reasonable medium.
upload_method: UploadMethod::PixelBuffer(VertexUsageHint::Stream),
workers: None,
enable_multithreading: true,
blob_image_handler: None,
recorder: None,
thread_listener: None,
@@ -556,6 +556,13 @@ impl ResourceCache {
self.texture_cache.max_texture_size()
}

pub fn enable_multithreading(&mut self, enable: bool) {
self.glyph_rasterizer.enable_multithreading(enable);
if let Some(ref mut handler) = self.blob_image_handler {
handler.enable_multithreading(enable);
}
}

fn should_tile(limit: i32, descriptor: &ImageDescriptor, data: &CachedImageData) -> bool {
let size_check = descriptor.size.width > limit || descriptor.size.height > limit;
match *data {
@@ -972,6 +972,8 @@ pub enum DebugCommand {
ClearCaches(ClearCache),
/// Enable/disable native compositor usage
EnableNativeCompositor(bool),
/// Enable/disable parallel job execution with rayon.
EnableMultithreading(bool),
/// Invalidate GPU cache, forcing the update from the CPU mirror.
InvalidateGpuCache,
/// Causes the scene builder to pause for a given amount of milliseconds each time it
@@ -409,6 +409,9 @@ pub trait BlobImageHandler: Send {
/// A hook to let the handler clean up any state related a given namespace before the
/// resource cache deletes them.
fn clear_namespace(&mut self, namespace: IdNamespace);

/// Whether to allow rendering blobs on multiple threads.
fn enable_multithreading(&mut self, enable: bool);
}

/// A group of rasterization requests to execute synchronously on the scene builder thread.
@@ -166,6 +166,8 @@ impl BlobImageHandler for CheckerboardRenderer {
fn create_blob_rasterizer(&mut self) -> Box<dyn AsyncBlobImageRasterizer> {
Box::new(Rasterizer { image_cmds: self.image_cmds.clone() })
}

fn enable_multithreading(&mut self, _enable: bool) {}
}

struct Command {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.