Skip to content

[Impeller] Parts of application flickering with blur present on main. #131490

Closed
flutter-team-archive/engine
#44121

Description

@knopp

We have parts of application flickering with blur present when tested on main. Though it's possible that the blur causes the issue indirectly by making the rasterisation taking longer.

flicker-flutter-main.mov

Bistected down to flutter-team-archive/engine@8e6497f.
When reenabling the wait for command buffer the issue resolves.

The commit also causes another problem - when application goes to background while scrolling it crashes with

-[MTLDebugCommandBuffer dealloc]:136: failed assertion `MTLCommandBuffer is in an invalid status when being destroyed; is it being over-released?'

This doesn't happens when waiting until the command buffer gets schedule. cc @jonahwilliams

Originally posted by @knopp in #127173 (comment)

Activity

  1. knopp commented on Jul 28, 2023

    @knopp
    MemberAuthor

    For reference, this is on iPhone 13 Pro.

  2. jonahwilliams commented on Jul 28, 2023

    @jonahwilliams
    Contributor

    Can you share some details of the application? We really need to be able to reproduce this so we can figure out where the problem is occuring.

    My read of how presentation works on iOS supports the current strategy we're using and I none of us have seen this issue, even on applications which have much longer CPU or GPU frame times. It could be that there is some other timing issue, and the waitUntilScheduled is acting like a sleep and causing us to win the race.

  3. knopp commented on Jul 28, 2023

    @knopp
    MemberAuthor

    I'll try to isolate this. One thing I noticed - there are two blurs in the application. I disabled all paths (to rule out tesselator) but the performance is still problematic with impeller (fine with Skia)

    I noticed quite a few allocations when rendering offscreen. This is for one second:

    Screenshot 2023-07-28 at 18 48 08

    For every frame there is one 12MB ImpellerOnScreen Stencil Texture allocated/deallocated and a number of EntityPass Color textures (1.8MB each).

    Is this expected behavior? These per-frame allocations don't happen with Skia. I assume it caches the textures used for offscreen rendering.

  4. bdero commented on Jul 28, 2023

    @bdero
    Member

    When blurs are applied as backdrop filters specifically, we currently need to end the current render pass in order to read from the backdrop and blur it into a smaller offscreen texture. This requires us to store the multisample stencil in addition to the color texture in-between passes in order to retain the clip state.

    The best way forward would be to share a reproduction that demonstrates clearly worse performance than Skia (in a new issue) so that we can take a closer look. There are still potential optimization tricks on the table for backdrop blurs that we could explore depending on how the app is using blurs.

  5. bdero commented on Jul 28, 2023

    @bdero
    Member

    It sounds like you're hitting a worst case scenario with the backdrop filter and we're allocating/storing the fullscreen multisample stencil buffer every frame. I think we can obviously do better there, but it would be best to have a repro of your app to make sure that's the primary pathology of your perf issue.

  6. knopp commented on Jul 28, 2023

    @knopp
    MemberAuthor

    I understand the need for these textures, just expected them to be reused across frames. I'll try to put together minimal reproducible example.

  7. added
    e: impellerImpeller rendering backend issues and features requests
    on Jul 28, 2023
  8. moved this to 🤔 Needs Triage in Impelleron Jul 28, 2023
  9. changed the title [-]Parts of application flickering with blur present on main[/-] [+][Impeller] Parts of application flickering with blur present on main.[/+] on Jul 28, 2023
  10. moved this from 🤔 Needs Triage to ⚙️ In Progress in Impelleron Jul 28, 2023
  11. moved this from ⚙️ In Progress to 🤔 Needs Triage in Impelleron Jul 28, 2023
  12. knopp commented on Jul 28, 2023

    @knopp
    MemberAuthor

    The following code can reproduce (iPhone 13 Pro, profile mode, current main) both the flickering and degraded performance compared to skia:

    import 'dart:ui';
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(const MainApp());
    }
    
    class _Blur extends StatelessWidget {
      const _Blur();
    
      @override
      Widget build(BuildContext context) {
        return ClipRRect(
          child: BackdropFilter(
            blendMode: BlendMode.srcIn,
            filter: ImageFilter.blur(
              sigmaX: Shadow.convertRadiusToSigma(80),
              sigmaY: Shadow.convertRadiusToSigma(80),
            ),
            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 < 4; ++i)
                  Positioned(
                    left: 0,
                    right: 0,
                    top: i * 200,
                    height: 100,
                    child: const _Blur(),
                  ),
              ],
            ),
          ),
        );
      }
    }
    impeller-flicker.mov
  13. jonahwilliams commented on Jul 28, 2023

    @jonahwilliams
    Contributor

    Thanks! I have a few ideas here. Worst comes to worst we can just add back the waitUntilScheduled but I think we should be able to retain having more frames in flight for applications that aren't bottlenecked elsewhere.

  14. moved this from 🤔 Needs Triage to ✅ Done in Impelleron Jul 28, 2023
  15. github-actions commented on Aug 12, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  16. locked as resolved and limited conversation to collaborators on Aug 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    e: impellerImpeller rendering backend issues and features requeststeam-engineOwned by Engine team

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions