mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 16:55:40 +00:00
Bug 1642629 - Preallocate CompositeStateDescriptor vectors. r=kvark
Vector reallocations in CompositeState::push_surface are taking about 2% of total frame building time before this patch. There was an effort at preallocating some with constant values but I suspect these constants haven't been updated along with picture cachign heuristics. Differential Revision: https://phabricator.services.mozilla.com/D80195
This commit is contained in:
parent
cf618044db
commit
440726b308
@ -13,6 +13,7 @@ use crate::picture::{ImageDependency, ResolvedSurfaceTexture, TileCacheInstance,
|
||||
use crate::prim_store::DeferredResolve;
|
||||
use crate::renderer::ImageBufferKind;
|
||||
use crate::resource_cache::{ImageRequest, ResourceCache};
|
||||
use crate::util::Preallocator;
|
||||
use std::{ops, u64};
|
||||
|
||||
/*
|
||||
@ -340,7 +341,49 @@ impl CompositeDescriptor {
|
||||
/// Construct an empty descriptor.
|
||||
pub fn empty() -> Self {
|
||||
CompositeDescriptor {
|
||||
surfaces: Vec::with_capacity(8),
|
||||
surfaces: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CompositeStatePreallocator {
|
||||
opaque_tiles: Preallocator,
|
||||
alpha_tiles: Preallocator,
|
||||
clear_tiles: Preallocator,
|
||||
external_surfaces: Preallocator,
|
||||
occluders: Preallocator,
|
||||
descriptor_surfaces: Preallocator,
|
||||
}
|
||||
|
||||
impl CompositeStatePreallocator {
|
||||
pub fn record(&mut self, state: &CompositeState) {
|
||||
self.opaque_tiles.record_vec(&state.opaque_tiles);
|
||||
self.alpha_tiles.record_vec(&state.alpha_tiles);
|
||||
self.clear_tiles.record_vec(&state.clear_tiles);
|
||||
self.external_surfaces.record_vec(&state.external_surfaces);
|
||||
self.occluders.record_vec(&state.occluders);
|
||||
self.descriptor_surfaces.record_vec(&state.descriptor.surfaces);
|
||||
}
|
||||
|
||||
pub fn preallocate(&self, state: &mut CompositeState) {
|
||||
self.opaque_tiles.preallocate_vec(&mut state.opaque_tiles);
|
||||
self.alpha_tiles.preallocate_vec(&mut state.alpha_tiles);
|
||||
self.clear_tiles.preallocate_vec(&mut state.clear_tiles);
|
||||
self.external_surfaces.preallocate_vec(&mut state.external_surfaces);
|
||||
self.occluders.preallocate_vec(&mut state.occluders);
|
||||
self.descriptor_surfaces.preallocate_vec(&mut state.descriptor.surfaces);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CompositeStatePreallocator {
|
||||
fn default() -> Self {
|
||||
CompositeStatePreallocator {
|
||||
opaque_tiles: Preallocator::new(40),
|
||||
alpha_tiles: Preallocator::new(16),
|
||||
clear_tiles: Preallocator::new(0),
|
||||
external_surfaces: Preallocator::new(0),
|
||||
occluders: Preallocator::new(16),
|
||||
descriptor_surfaces: Preallocator::new(8),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -400,15 +443,15 @@ impl CompositeState {
|
||||
}
|
||||
|
||||
CompositeState {
|
||||
opaque_tiles: Vec::with_capacity(40),
|
||||
alpha_tiles: Vec::with_capacity(16),
|
||||
opaque_tiles: Vec::new(),
|
||||
alpha_tiles: Vec::new(),
|
||||
clear_tiles: Vec::new(),
|
||||
z_generator: ZBufferIdGenerator::new(0, max_depth_ids),
|
||||
dirty_rects_are_valid: true,
|
||||
compositor_kind,
|
||||
picture_caching_is_enabled,
|
||||
global_device_pixel_scale,
|
||||
occluders: Vec::with_capacity(16),
|
||||
occluders: Vec::new(),
|
||||
descriptor: CompositeDescriptor::empty(),
|
||||
external_surfaces: Vec::new(),
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ use api::units::*;
|
||||
use crate::batch::{BatchBuilder, AlphaBatchBuilder, AlphaBatchContainer};
|
||||
use crate::clip::{ClipStore, ClipChainStack};
|
||||
use crate::spatial_tree::{SpatialTree, ROOT_SPATIAL_NODE_INDEX, SpatialNodeIndex};
|
||||
use crate::composite::{CompositorKind, CompositeState};
|
||||
use crate::composite::{CompositorKind, CompositeState, CompositeStatePreallocator};
|
||||
use crate::debug_render::DebugItem;
|
||||
use crate::gpu_cache::{GpuCache, GpuCacheHandle};
|
||||
use crate::gpu_types::{PrimitiveHeaders, TransformPalette, UvRectKind, ZBufferIdGenerator};
|
||||
@ -163,6 +163,8 @@ pub struct FrameBuilder {
|
||||
pub globals: FrameGlobalResources,
|
||||
#[cfg_attr(feature = "capture", serde(skip))]
|
||||
prim_headers_prealloc: Preallocator,
|
||||
#[cfg_attr(feature = "capture", serde(skip))]
|
||||
composite_state_prealloc: CompositeStatePreallocator,
|
||||
}
|
||||
|
||||
pub struct FrameBuildingContext<'a> {
|
||||
@ -236,7 +238,8 @@ impl FrameBuilder {
|
||||
FrameBuilder {
|
||||
pending_retained_tiles: RetainedTiles::new(),
|
||||
globals: FrameGlobalResources::empty(),
|
||||
prim_headers_prealloc: Preallocator::new(0)
|
||||
prim_headers_prealloc: Preallocator::new(0),
|
||||
composite_state_prealloc: CompositeStatePreallocator::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -582,6 +585,8 @@ impl FrameBuilder {
|
||||
scene.config.max_depth_ids,
|
||||
);
|
||||
|
||||
self.composite_state_prealloc.preallocate(&mut composite_state);
|
||||
|
||||
let main_render_task_id = self.build_layer_screen_rects_and_cull_layers(
|
||||
scene,
|
||||
screen_world_rect,
|
||||
@ -672,6 +677,7 @@ impl FrameBuilder {
|
||||
resource_cache.end_frame(&mut resource_profile.texture_cache);
|
||||
|
||||
self.prim_headers_prealloc.record_vec(&mut prim_headers.headers_int);
|
||||
self.composite_state_prealloc.record(&composite_state);
|
||||
|
||||
Frame {
|
||||
content_origin: scene.output_rect.origin,
|
||||
|
Loading…
Reference in New Issue
Block a user