Bug 1564118 - WR don't assume opaque on the lack of a clip task
authorDzmitry Malyshau <dmalyshau@mozilla.com>
Fri, 02 Aug 2019 14:48:46 +0000
changeset 485989 5babcd57c4945d74a0c97548b32bbfc3a45d25be
parent 485988 dd3a15beada7d76d23693d67ad119826f9f05ae9
child 485990 ff0125384d06fefae3ca60435b85a9be0fd9744e
push id91570
push userdmalyshau@mozilla.com
push dateFri, 02 Aug 2019 16:30:31 +0000
treeherderautoland@5babcd57c494 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1564118
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1564118 - WR don't assume opaque on the lack of a clip task those unwrap_or are mostly seen during the batching, where we should asssume that the primitives are not clipped out and just unwrap() accordingly. Differential Revision: https://phabricator.services.mozilla.com/D39940
gfx/wr/webrender/src/batch.rs
--- a/gfx/wr/webrender/src/batch.rs
+++ b/gfx/wr/webrender/src/batch.rs
@@ -715,19 +715,23 @@ impl BatchBuilder {
         }
 
         if transform_kind != TransformedRectKind::AxisAligned {
             batch_features |= BatchFeatures::ANTIALIASING;
         }
 
         let snap_offsets = prim_info.snap_offsets;
         let prim_vis_mask = prim_info.visibility_mask;
+        let clip_task_address = ctx.get_prim_clip_task_address(
+            prim_info.clip_task_index,
+            render_tasks,
+        );
 
         if is_chased {
-            println!("\tbatch {:?} with bound {:?}", prim_rect, bounding_rect);
+            println!("\tbatch {:?} with bound {:?} and clip task {:?}", prim_rect, bounding_rect, clip_task_address);
         }
 
         if !bounding_rect.is_empty() {
             debug_assert_eq!(prim_info.clip_chain.pic_spatial_node_index, surface_spatial_node_index,
                 "The primitive's bounding box is specified in a different coordinate system from the current batch!");
         }
 
         match prim_instance.kind {
@@ -757,29 +761,24 @@ impl BatchBuilder {
                 );
 
                 let batch_key = BatchKey {
                     blend_mode: BlendMode::PremultipliedDestOut,
                     kind: BatchKind::Brush(BrushBatchKind::Solid),
                     textures: BatchTextures::no_texture(),
                 };
 
-                let clip_task_address = ctx.get_prim_clip_task_address(
-                    prim_info.clip_task_index,
-                    render_tasks,
-                ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                 self.add_brush_instance_to_batches(
                     batch_key,
                     batch_features,
                     bounding_rect,
                     z_id,
                     INVALID_SEGMENT_INDEX,
                     EdgeAaSegmentMask::all(),
-                    clip_task_address,
+                    clip_task_address.unwrap(),
                     BrushFlags::PERSPECTIVE_INTERPOLATION,
                     prim_header_index,
                     0,
                     prim_vis_mask,
                 );
             }
             PrimitiveInstanceKind::NormalBorder { data_handle, ref cache_handles, .. } => {
                 let prim_data = &ctx.data_stores.normal_border[data_handle];
@@ -869,35 +868,30 @@ impl BatchBuilder {
                 let prim_header = PrimitiveHeader {
                     local_rect: prim_rect,
                     local_clip_rect: prim_info.combined_local_clip_rect,
                     snap_offsets,
                     specific_prim_address: prim_cache_address,
                     transform_id,
                 };
 
-                let clip_task_address = ctx.get_prim_clip_task_address(
-                    prim_info.clip_task_index,
-                    render_tasks,
-                ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                 let glyph_keys = &ctx.scratch.glyph_keys[run.glyph_keys_range];
                 let rasterization_space = match run.raster_space {
                     RasterSpace::Screen => RasterizationSpace::Screen,
                     RasterSpace::Local(..) => RasterizationSpace::Local,
                 };
                 let raster_scale = run.raster_space.local_scale().unwrap_or(1.0).max(0.001);
                 let prim_header_index = prim_headers.push(
                     &prim_header,
                     z_id,
                     [
                         (run.reference_frame_relative_offset.x * 256.0) as i32,
                         (run.reference_frame_relative_offset.y * 256.0) as i32,
                         (raster_scale * 65535.0).round() as i32,
-                        clip_task_address.0 as i32,
+                        clip_task_address.unwrap().0 as i32,
                     ],
                 );
                 let base_instance = GlyphInstance::new(
                     prim_header_index,
                 );
                 let batchers = &mut self.batchers;
 
                 ctx.resource_cache.fetch_glyphs(
@@ -1056,29 +1050,24 @@ impl BatchBuilder {
                 );
 
                 let batch_key = BatchKey {
                     blend_mode,
                     kind: BatchKind::Brush(batch_kind),
                     textures,
                 };
 
-                let clip_task_address = ctx.get_prim_clip_task_address(
-                    prim_info.clip_task_index,
-                    render_tasks,
-                ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                 self.add_brush_instance_to_batches(
                     batch_key,
                     batch_features,
                     bounding_rect,
                     z_id,
                     INVALID_SEGMENT_INDEX,
                     EdgeAaSegmentMask::all(),
-                    clip_task_address,
+                    clip_task_address.unwrap(),
                     BrushFlags::PERSPECTIVE_INTERPOLATION,
                     prim_header_index,
                     segment_user_data,
                     prim_vis_mask,
                 );
             }
             PrimitiveInstanceKind::Picture { pic_index, segment_instance_index, .. } => {
                 let picture = &ctx.prim_store.pictures[pic_index.0];
@@ -1102,20 +1091,20 @@ impl BatchBuilder {
 
                             let child_pic_index = match child_prim_instance.kind {
                                 PrimitiveInstanceKind::Picture { pic_index, .. } => pic_index,
                                 _ => unreachable!(),
                             };
                             let pic = &ctx.prim_store.pictures[child_pic_index.0];
 
                             // Get clip task, if set, for the picture primitive.
-                            let clip_task_address = ctx.get_prim_clip_task_address(
+                            let child_clip_task_address = ctx.get_prim_clip_task_address(
                                 child_prim_info.clip_task_index,
                                 render_tasks,
-                            ).unwrap_or(OPAQUE_TASK_ADDRESS);
+                            );
 
                             let prim_header = PrimitiveHeader {
                                 local_rect: pic.snapped_local_rect,
                                 local_clip_rect: child_prim_info.combined_local_clip_rect,
                                 snap_offsets,
                                 specific_prim_address: GpuCacheAddress::INVALID,
                                 transform_id: transforms
                                     .get_id(
@@ -1140,17 +1129,17 @@ impl BatchBuilder {
                             // Need a new z-id for each child preserve-3d context added
                             // by this inner loop.
                             let z_id = z_generator.next();
 
                             let prim_header_index = prim_headers.push(&prim_header, z_id, [
                                 uv_rect_address.as_int(),
                                 if raster_config.establishes_raster_root { 1 } else { 0 },
                                 0,
-                                clip_task_address.0 as i32,
+                                child_clip_task_address.unwrap().0 as i32,
                             ]);
 
                             let key = BatchKey::new(
                                 BatchKind::SplitComposite,
                                 BlendMode::PremultipliedAlpha,
                                 BatchTextures::no_texture(),
                             );
 
@@ -1176,21 +1165,16 @@ impl BatchBuilder {
                         // If the child picture was rendered in local space, we can safely
                         // interpolate the UV coordinates with perspective correction.
                         let brush_flags = if raster_config.establishes_raster_root {
                             BrushFlags::PERSPECTIVE_INTERPOLATION
                         } else {
                             BrushFlags::empty()
                         };
 
-                        let clip_task_address = ctx.get_prim_clip_task_address(
-                            prim_info.clip_task_index,
-                            render_tasks,
-                        ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                         let surface = &ctx.surfaces[raster_config.surface_index.0];
                         let surface_task = surface.render_tasks.map(|s| s.root);
 
                         match raster_config.composite_mode {
                             PictureCompositeMode::TileCache { .. } => {
                                 let tile_cache = picture.tile_cache.as_ref().unwrap();
 
                                 let tile_clip_rect = match tile_cache.local_rect.intersection(&tile_cache.local_clip_rect) {
@@ -1286,17 +1270,17 @@ impl BatchBuilder {
 
                                         self.add_brush_instance_to_batches(
                                             key,
                                             batch_features,
                                             bounding_rect,
                                             z_id,
                                             INVALID_SEGMENT_INDEX,
                                             EdgeAaSegmentMask::empty(),
-                                            clip_task_address,
+                                            clip_task_address.unwrap(),
                                             brush_flags,
                                             prim_header_index,
                                             uv_rect_address.as_int(),
                                             prim_vis_mask,
                                         );
                                     }
                                     Filter::DropShadows(shadows) => {
                                         // Draw an instance per shadow first, following by the content.
@@ -1362,17 +1346,17 @@ impl BatchBuilder {
 
                                             self.add_brush_instance_to_batches(
                                                 shadow_key,
                                                 batch_features,
                                                 bounding_rect,
                                                 z_id,
                                                 INVALID_SEGMENT_INDEX,
                                                 EdgeAaSegmentMask::empty(),
-                                                clip_task_address,
+                                                clip_task_address.unwrap(),
                                                 brush_flags,
                                                 shadow_prim_header_index,
                                                 shadow_uv_rect_address,
                                                 prim_vis_mask,
                                             );
                                         }
                                         let z_id_content = z_generator.next();
 
@@ -1385,17 +1369,17 @@ impl BatchBuilder {
 
                                         self.add_brush_instance_to_batches(
                                             content_key,
                                             batch_features,
                                             bounding_rect,
                                             z_id_content,
                                             INVALID_SEGMENT_INDEX,
                                             EdgeAaSegmentMask::empty(),
-                                            clip_task_address,
+                                            clip_task_address.unwrap(),
                                             brush_flags,
                                             content_prim_header_index,
                                             content_uv_rect_address,
                                             prim_vis_mask,
                                         );
                                     }
                                     _ => {
                                         let filter_mode = match filter {
@@ -1466,17 +1450,17 @@ impl BatchBuilder {
 
                                         self.add_brush_instance_to_batches(
                                             key,
                                             batch_features,
                                             bounding_rect,
                                             z_id,
                                             INVALID_SEGMENT_INDEX,
                                             EdgeAaSegmentMask::empty(),
-                                            clip_task_address,
+                                            clip_task_address.unwrap(),
                                             brush_flags,
                                             prim_header_index,
                                             0,
                                             prim_vis_mask,
                                         );
                                     }
                                 }
                             }
@@ -1513,17 +1497,17 @@ impl BatchBuilder {
 
                                 self.add_brush_instance_to_batches(
                                     key,
                                     batch_features,
                                     bounding_rect,
                                     z_id,
                                     INVALID_SEGMENT_INDEX,
                                     EdgeAaSegmentMask::empty(),
-                                    clip_task_address,
+                                    clip_task_address.unwrap(),
                                     brush_flags,
                                     prim_header_index,
                                     0,
                                     prim_vis_mask,
                                 );
                             }
                             PictureCompositeMode::MixBlend(mode) if ctx.use_advanced_blending => {
                                 let (uv_rect_address, textures) = render_tasks.resolve_surface(
@@ -1546,17 +1530,17 @@ impl BatchBuilder {
 
                                 self.add_brush_instance_to_batches(
                                     key,
                                     batch_features,
                                     bounding_rect,
                                     z_id,
                                     INVALID_SEGMENT_INDEX,
                                     EdgeAaSegmentMask::empty(),
-                                    clip_task_address,
+                                    clip_task_address.unwrap(),
                                     brush_flags,
                                     prim_header_index,
                                     uv_rect_address.as_int(),
                                     prim_vis_mask,
                                 );
                             }
                             PictureCompositeMode::MixBlend(mode) => {
                                 let cache_task_id = surface_task.expect("bug: surface must be allocated by now");
@@ -1589,17 +1573,17 @@ impl BatchBuilder {
 
                                 self.add_brush_instance_to_batches(
                                     key,
                                     batch_features,
                                     bounding_rect,
                                     z_id,
                                     INVALID_SEGMENT_INDEX,
                                     EdgeAaSegmentMask::empty(),
-                                    clip_task_address,
+                                    clip_task_address.unwrap(),
                                     brush_flags,
                                     prim_header_index,
                                     0,
                                     prim_vis_mask,
                                 );
                             }
                             PictureCompositeMode::Blit(_) => {
                                 let cache_task_id = surface_task.expect("bug: surface must be allocated by now");
@@ -1692,17 +1676,17 @@ impl BatchBuilder {
 
                                 self.add_brush_instance_to_batches(
                                     key,
                                     batch_features,
                                     bounding_rect,
                                     z_id,
                                     INVALID_SEGMENT_INDEX,
                                     EdgeAaSegmentMask::empty(),
-                                    clip_task_address,
+                                    clip_task_address.unwrap(),
                                     brush_flags,
                                     prim_header_index,
                                     uv_rect_address.as_int(),
                                     prim_vis_mask,
                                 );
                             }
                         }
                     }
@@ -2071,21 +2055,16 @@ impl BatchBuilder {
                         prim_info.clip_task_index,
                         prim_vis_mask,
                         ctx,
                     );
                 } else {
                     const VECS_PER_SPECIFIC_BRUSH: usize = 3;
                     let max_tiles_per_header = (MAX_VERTEX_TEXTURE_WIDTH - VECS_PER_SPECIFIC_BRUSH) / VECS_PER_SEGMENT;
 
-                    let clip_task_address = ctx.get_prim_clip_task_address(
-                        prim_info.clip_task_index,
-                        render_tasks,
-                    ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                     // use temporary block storage since we don't know the number of visible tiles beforehand
                     let mut gpu_blocks = Vec::<GpuBlockData>::new();
                     for chunk in image_instance.visible_tiles.chunks(max_tiles_per_header) {
                         gpu_blocks.clear();
                         gpu_blocks.push(PremultipliedColorF::WHITE.into()); //color
                         gpu_blocks.push(PremultipliedColorF::WHITE.into()); //bg color
                         gpu_blocks.push([-1.0, 0.0, 0.0, 0.0].into()); //stretch size
                         // negative first value makes the shader code ignore it and use the local size instead
@@ -2119,17 +2098,17 @@ impl BatchBuilder {
                                 };
                                 self.add_brush_instance_to_batches(
                                     batch_key,
                                     batch_features,
                                     bounding_rect,
                                     z_id,
                                     i as i32,
                                     tile.edge_flags,
-                                    clip_task_address,
+                                    clip_task_address.unwrap(),
                                     BrushFlags::SEGMENT_RELATIVE | BrushFlags::PERSPECTIVE_INTERPOLATION,
                                     prim_header_index,
                                     uv_rect_address.as_int(),
                                     prim_vis_mask,
                                 );
                             }
                         }
                     }
@@ -2185,29 +2164,24 @@ impl BatchBuilder {
                     );
 
                     let batch_key = BatchKey {
                         blend_mode: non_segmented_blend_mode,
                         kind: BatchKind::Brush(batch_kind),
                         textures,
                     };
 
-                    let clip_task_address = ctx.get_prim_clip_task_address(
-                        prim_info.clip_task_index,
-                        render_tasks,
-                    ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                     self.add_brush_instance_to_batches(
                         batch_key,
                         batch_features,
                         bounding_rect,
                         z_id,
                         INVALID_SEGMENT_INDEX,
                         EdgeAaSegmentMask::all(),
-                        clip_task_address,
+                        clip_task_address.unwrap(),
                         BrushFlags::PERSPECTIVE_INTERPOLATION,
                         prim_header_index,
                         segment_user_data,
                         prim_vis_mask,
                     );
                 } else if gradient.visible_tiles_range.is_empty() {
                     let batch_params = BrushBatchParameters::shared(
                         BrushBatchKind::LinearGradient,
@@ -2249,28 +2223,23 @@ impl BatchBuilder {
                         z_id,
                         prim_info.clip_task_index,
                         prim_vis_mask,
                         ctx,
                     );
                 } else {
                     let visible_tiles = &ctx.scratch.gradient_tiles[gradient.visible_tiles_range];
 
-                    let clip_task_address = ctx.get_prim_clip_task_address(
-                        prim_info.clip_task_index,
-                        render_tasks,
-                    ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                     self.add_gradient_tiles(
                         visible_tiles,
                         &prim_data.stops_handle,
                         BrushBatchKind::LinearGradient,
                         specified_blend_mode,
                         bounding_rect,
-                        clip_task_address,
+                        clip_task_address.unwrap(),
                         gpu_cache,
                         &prim_header,
                         prim_headers,
                         z_id,
                         prim_vis_mask,
                     );
                 }
             }
@@ -2336,28 +2305,23 @@ impl BatchBuilder {
                         z_id,
                         prim_info.clip_task_index,
                         prim_vis_mask,
                         ctx,
                     );
                 } else {
                     let visible_tiles = &ctx.scratch.gradient_tiles[*visible_tiles_range];
 
-                    let clip_task_address = ctx.get_prim_clip_task_address(
-                        prim_info.clip_task_index,
-                        render_tasks,
-                    ).unwrap_or(OPAQUE_TASK_ADDRESS);
-
                     self.add_gradient_tiles(
                         visible_tiles,
                         &prim_data.stops_handle,
                         BrushBatchKind::RadialGradient,
                         specified_blend_mode,
                         bounding_rect,
-                        clip_task_address,
+                        clip_task_address.unwrap(),
                         gpu_cache,
                         &prim_header,
                         prim_headers,
                         z_id,
                         prim_vis_mask,
                     );
                 }
             }
@@ -2502,17 +2466,17 @@ impl BatchBuilder {
                 let batch_key = BatchKey {
                     blend_mode: non_segmented_blend_mode,
                     kind: BatchKind::Brush(params.batch_kind),
                     textures: segment_data.textures,
                 };
                 let clip_task_address = ctx.get_prim_clip_task_address(
                     clip_task_index,
                     render_tasks,
-                ).unwrap_or(OPAQUE_TASK_ADDRESS);
+                ).unwrap();
                 self.add_brush_instance_to_batches(
                     batch_key,
                     features,
                     bounding_rect,
                     z_id,
                     INVALID_SEGMENT_INDEX,
                     EdgeAaSegmentMask::all(),
                     clip_task_address,