Skip to content

[Impeller] Reduce render-pass overhead when using wide gamut (iOS) #131567

@knopp

Description

@knopp

Consider the following example:

code
import 'dart:ui';
import 'package:flutter/material.dart';

void main() {
  runApp(const MainApp());
}

const kSigma = 1.0;
const kNumberOfBlurs = 6;

class _Blur extends StatelessWidget {
  const _Blur();

  @override
  Widget build(BuildContext context) {
    return ClipRRect(
      child: BackdropFilter(
        blendMode: BlendMode.srcIn,
        filter: ImageFilter.blur(
          sigmaX: kSigma,
          sigmaY: kSigma,
        ),
        child: Container(
          color: Colors.red.withAlpha(30),
          child: const Text('Blur'),
        ),
      ),
    );
  }
}

class MainApp extends StatelessWidget {
  const MainApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Stack(
          children: [
            ListView.builder(
                itemBuilder: (context, index) {
                  return Container(
                    padding: const EdgeInsets.all(10),
                    child: Text('Item $index'),
                  );
                },
                itemCount: 1000),
            for (var i = 0; i < kNumberOfBlurs; ++i) ...[
              Positioned(
                left: 0,
                right: 0,
                top: i * 150,
                height: 60,
                child: const _Blur(),
              ),
            ]
          ],
        ),
      ),
    );
  }
}
screenshot

Screen Shot 2023-07-30 at 09 49 18

It has 6 blur backdrops with sigma=1 (to focus on render pass overhead and not blur filter performance).

This is the performance on A15 (iPhone 13 Pro) with wide gamut disabled:
Screenshot 2023-07-29 at 16 40 56

and wide gamut enabled:
Screenshot 2023-07-29 at 16 42 13

I tried couple of things to figure out why the regression is so large:

I noticed that there is quite a lot of texture allocation per frame. Caching textures improved the frame time by around 1-1.5ms.

Biggest bottleneck by far seems to be the blits for MSAA backdrop. They take around 80% of frame time.

Disabling MSAA backdrop (reverting back to LoadAction::kLoad + StoreAction::kStoreAndMultisampleResolve/kMultisampleResolve) seems to improve the performance considerably:
Screenshot 2023-07-29 at 22 42 22

cc @gaaclarke, @bdero, @jonahwilliams

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work liste: impellerImpeller rendering backend issues and features requestsengineflutter/engine repository. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions