Skip to content

Optimize mix-blend-mode to avoid readback in most cases. #2844

Open
@gw3583

Description

@gw3583

(brain dump only - needs more detail added)

At the moment we have various hacks in the WR code and shaders to handle the fact that mix-blend-mode must be isolated from other stacking contexts. I think we can modify how we implement mix-blend-mode in a way that removes these hacks and also is an optimization - removing the need for framebuffer readback in most cases.

When we encounter a mix-blend-mode during flattening, we should move the parent stacking context to be a child of the mix-blend-mode picture node. Then, no readback is needed - the parent stacking context will be drawn to an off-screen surface in the correct pass.

A couple of caveats:

  • We still need to do the readback if the parent stacking context is the root (framebuffer). This is rare, and in future we can also track if the root only has a simple background color and avoid the readback in this case too.
  • To get correct blending, we need to ensure that the render task created for the mix-blend-mode is the maximum of the size of the backdrop and child stacking context.

This should allow for a much faster implementation of mix-blend-mode in the majority of cases, by skipping framebuffer readback. It also makes it easier to optimize some of the common cases, where the backdrop is a solid color (either by detecting this, or caching the solid color picture in the texture cache).

Activity

kvark

kvark commented on Jun 26, 2018

@kvark
Member

Sounds reasonable. For the first caveat, can't we introduce an "artificial" full-screen picture just so the readback path is not needed (at the cost of an extra blit/copy)?

gw3583

gw3583 commented on Jun 26, 2018

@gw3583
ContributorAuthor

Yup, that should work.

Gankra

Gankra commented on Jun 26, 2018

@Gankra
Contributor

vague reminder to not introduce a side-channel attack with content-based optimizations on mix-blend-modes/filters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Optimize mix-blend-mode to avoid readback in most cases. · Issue #2844 · servo/webrender