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 #3735

Merged
merged 11 commits into from Aug 15, 2019
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 1572646 - Detect and optimize picture cache tiles that are solid …

…colors. r=kvark

With this patch, tiles that are covered only by the opaque backdrop
primitive are detected and noted as solid colors.

Solid color tiles save memory and performance, because:
 - No texture slice is allocated as a render target for them.
 - No need to rasterize this tile.
 - Drawing the tile is done with the faster rectangle shader.

This already saves performance and GPU memory on quite a few
real world sites (esp. when running at 4k). However, the main
benefit of this will be once we enable picture caching on
multiple content slices and the UI layer. When this occurs, it's
important to avoid allocating tile buffers for all the solid
rectangle tiles that the UI layer typically contains.

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

[wrupdater] From https://hg.mozilla.org/mozilla-central/rev/96075609026a3816cb7a6dcf9cf3795afe7f82d6
  • Loading branch information
gw3583 authored and moz-gfx committed Aug 13, 2019
commit ff05e03b311e2d3284e654266738a102ea3ae1a9
@@ -14,7 +14,7 @@ use crate::gpu_types::{ClipMaskInstance, SplitCompositeInstance, SnapOffsets};
use crate::gpu_types::{PrimitiveInstanceData, RasterizationSpace, GlyphInstance};
use crate::gpu_types::{PrimitiveHeader, PrimitiveHeaderIndex, TransformPaletteId, TransformPalette};
use crate::internal_types::{FastHashMap, SavedTargetIndex, Swizzle, TextureSource, Filter};
use crate::picture::{Picture3DContext, PictureCompositeMode, PicturePrimitive};
use crate::picture::{Picture3DContext, PictureCompositeMode, PicturePrimitive, TileSurface};
use crate::prim_store::{DeferredResolve, EdgeAaSegmentMask, PrimitiveInstanceKind, PrimitiveVisibilityIndex, PrimitiveVisibilityMask};
use crate::prim_store::{VisibleGradientTile, PrimitiveInstance, PrimitiveOpacity, SegmentInstanceIndex};
use crate::prim_store::{BrushSegment, ClipMaskKind, ClipTaskIndex, VECS_PER_SEGMENT};
@@ -1191,6 +1191,70 @@ impl BatchBuilder {

debug_assert!(tile.is_valid);
let local_tile_rect = LayoutRect::from_untyped(&tile.rect.to_untyped());

// Draw the tile as either a texture image or solid rect.
let surface = tile.surface.as_ref().expect("no tile surface set!");
let (opacity, blend_mode, batch_params, prim_cache_address) = match surface {
TileSurface::Color { color } => {
let batch_params = BrushBatchParameters::shared(
BrushBatchKind::Solid,
BatchTextures::no_texture(),
[get_shader_opacity(1.0), 0, 0, 0],
0,
);

// TODO(gw): Maybe we could retain this GPU cache handle inside
// the tile to avoid pushing per-frame GPU cache blocks.
let gpu_blocks = [
color.premultiplied().into(),
];

let gpu_handle = gpu_cache.push_per_frame_blocks(&gpu_blocks);
let prim_cache_address = gpu_cache.get_address(&gpu_handle);

(
PrimitiveOpacity::opaque(),
BlendMode::None,
batch_params,
prim_cache_address,
)
}
TileSurface::Texture { ref handle, .. } => {
let cache_item = ctx.resource_cache.texture_cache.get(handle);
let uv_rect_address = gpu_cache
.get_address(&cache_item.uv_rect_handle)
.as_int();

let batch_params = BrushBatchParameters::shared(
BrushBatchKind::Image(ImageBufferKind::Texture2DArray),
BatchTextures::color(cache_item.texture_id),
[
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
RasterizationSpace::Local as i32,
get_shader_opacity(1.0),
0,
],
uv_rect_address,
);

if tile.is_opaque || tile_cache.is_opaque() {
(
PrimitiveOpacity::opaque(),
BlendMode::None,
batch_params,
prim_cache_address,
)
} else {
(
PrimitiveOpacity::translucent(),
BlendMode::PremultipliedAlpha,
batch_params,
prim_cache_address,
)
}
}
};

let prim_header = PrimitiveHeader {
local_rect: local_tile_rect,
local_clip_rect: local_tile_clip_rect,
@@ -1199,29 +1263,6 @@ impl BatchBuilder {
transform_id,
};

let (opacity, blend_mode) = if tile.is_opaque || tile_cache.is_opaque() {
(PrimitiveOpacity::opaque(), BlendMode::None)
} else {
(PrimitiveOpacity::translucent(), BlendMode::PremultipliedAlpha)
};

let cache_item = ctx.resource_cache.texture_cache.get(&tile.handle);
let uv_rect_address = gpu_cache
.get_address(&cache_item.uv_rect_handle)
.as_int();
let textures = BatchTextures::color(cache_item.texture_id);
let batch_params = BrushBatchParameters::shared(
BrushBatchKind::Image(ImageBufferKind::Texture2DArray),
textures,
[
ShaderColorMode::Image as i32 | ((AlphaType::PremultipliedAlpha as i32) << 16),
RasterizationSpace::Local as i32,
get_shader_opacity(1.0),
0,
],
uv_rect_address,
);

let prim_header_index = prim_headers.push(
&prim_header,
z_id,
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.