-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Impeller] add mechanism for sharing bdf inputs. #55701
Conversation
This code isn't ready for review yet, but adding @flar and @gaaclarke for high level input. This is the doc that I said I was going to write that I dragged my feet on... |
Also I notice in the video that there is a slight pixel shift when switching modes... |
Currently the transforms are incorrect if the same bdf id is used in different save layers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just reviewed the first half - the front end - on this pass.
One thought - why 64-bit signed integer for ID? Do we anticipate having this many BDFs? An optional value feels more appropriate at the Dart level than a magic value (or declaring that valid IDs must be positive). Making the parameter nullable at the Dart level seems simple. std::optional seems like overkill at the C++ level, but these don't get used all that much compared to all of the other work going on.
FML_UNREACHABLE(); | ||
} | ||
|
||
virtual void saveLayer(const DlRect& bounds, | ||
const SaveLayerOptions& options, | ||
uint32_t total_content_depth, | ||
DlBlendMode max_content_blend_mode, | ||
const DlImageFilter* backdrop = nullptr) { | ||
const DlImageFilter* backdrop = nullptr, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are implementations, aren't they? Do they need the default values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Or all of these virtual
tags?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are not overrides so I think they need the default values. overrides of a virtual method don't need to re-specify them.
display_list/dl_builder.h
Outdated
@@ -51,7 +51,8 @@ class DisplayListBuilder final : public virtual DlCanvas, | |||
// |DlCanvas| | |||
void SaveLayer(const SkRect* bounds, | |||
const DlPaint* paint = nullptr, | |||
const DlImageFilter* backdrop = nullptr) override; | |||
const DlImageFilter* backdrop = nullptr, | |||
int64_t backdrop_id = -1) override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto - default values probably unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, in this case there is a lot of code calling directly to a DlBuilder not through the DlCanvas interface so perhaps it needs them for ease of use. That need would disappear if we did something more like Flutter and Skia and have the Builder simply represent the recording process and provide an actual DlCanvas implementation via a getter rather than via direct implementation...?
display_list/dl_op_receiver.h
Outdated
@@ -143,15 +141,17 @@ class DlOpReceiver { | |||
// layer before further rendering happens. | |||
virtual void saveLayer(const DlRect& bounds, | |||
const SaveLayerOptions options, | |||
const DlImageFilter* backdrop = nullptr) = 0; | |||
const DlImageFilter* backdrop = nullptr, | |||
int64_t backdrop_id = -1) = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This used to be the front end and back end for DLs. Now that it is just the backend I think all default values throughout this interface are obsolete. But, maybe there are a couple of unit tests that still call these directly? I'll watch for this as I de-skiafy...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(The DlOp records used during dispatch shouldn't need any defaults for the calls they make.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed flutter/flutter#156617 to remind me to clean this up.
display_list/skia/dl_sk_canvas.h
Outdated
@@ -32,7 +32,8 @@ class DlSkCanvasAdapter final : public virtual DlCanvas { | |||
void Save() override; | |||
void SaveLayer(const SkRect* bounds, | |||
const DlPaint* paint = nullptr, | |||
const DlImageFilter* backdrop = nullptr) override; | |||
const DlImageFilter* backdrop = nullptr, | |||
int64_t backdrop_id = -1) override; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we use this directly (as in on an instance of this class as opposed to casting it to a DlCanvas where the defaults already exist)? Actually we might in the embedders or other platform code.
Re: the 64 bit integer. Dart ints are 64 bits and signed, so using a smaller int means we'd need to do a runtime check or throw an error (folks could reasonably use Dart max int has an input). We could remove the -1 and make it nullable instead, I need to look into how to pass that through dart::ffi. |
Since we didn't end up writing a design doc, I know we talked about it that one day over gvc but can you write down (or link to someplace where it is already written) why we needed to have users specify this explicitly and we couldn't come up with a heuristic to do this automatically? |
|
Did you consider making the Dart API look like this instead of specifying an integer? This captures a scope more succinctly and doesn't require managing ids. The downside is that it is impossible to mix and match the blur layer across the code (though that makes the code easier to follow). Under the covers you could keep the implementation the same if you wanted. Widget build(BuildContext context) {
return BackdropGroup(
children:[
BackdropFilter(...),
BackdropFilter(...),
]
);
} |
I discussed this a bit with @flar and we both like the idea of separating the Backdrop widget from a backdrop-reading widget. So something like:
But that is all Dart API that would be constructed at the framework layer. The implementation should look almost identical. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was mentioned above but there is actually 2 places we need to make this fix.
@gaaclarke I think the one major unadressed point so far is the manipulation of the backdrop filter raw ptrs. I think the display list stores these as shared_ptrs anyway, so I'm going to lookinto changing the dispatcher. If we do that, I'll do that separately. |
impeller/display_list/canvas.cc
Outdated
!backdrop_data->shared_filter_snapshot.has_value()) { | ||
// TODO(jonahwilliams): compute minimum input hint. | ||
backdrop_data->shared_filter_snapshot = | ||
backdrop_filter_contents->RenderToSnapshot(renderer_, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm realizing that this can result in worse performance even after we've computed the minimum input hint. Imagine 2 blurred rectangles whose corners touch.
Should we maybe just stick to sharing the input? That will always be an improvement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharing the input is a good GPU perfomrnce improvement but removing the filter sharing would discard the vast majority of the CPU overhead for many small filters. I'll show you some numbers tomorrow but even with extra blurring this is still generally faster.
We could also detect how much of the snapshot is used and add a heuristic based on covered %. i do think it would be a bit of an edge case, like someone that adds a single pixel blur to both the top left and bottom right corners, and then opts into (remember this is opt in) backdrop id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a benchmark for this case then so we can quantify the worst case scenario. Something like 2 squares on opposite sides of the screen animating sigma, group versus not group. Maybe we could leave some room outside the union so the minimum input hint change can show up when we implement that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a good idea! will do.
Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change). If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review. |
I modified the backdrop filter blur benchmark application to place a single blur in the top left and in the bottom right corner. This should in theory be the worst possible case for backdrop id. This test was on an iPhone and I made sure to sync after the BDF fix from @gaaclarke and with partial repaint disabled. GPU numbers are performance state medium No backdrop Id: 2.13 ms GPU Time / ~2.5 ms Raster time. Backdrop Id w/ shared filter (current design) 1.55 ms GPU Time / ~2.5 ms Raster time Backdrop id w/ shared input but not shared filter*: 2.0 ms GPU Time / ~2.5 ms Raster time
So for the two small filter case, there really isn't any hit to CPU time. But computing the blur once is still faster than doing it twice, even over a larger area. These numbers will likely be diffrent across devices though. |
Golden file changes are available for triage from new commit, Click here to view. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This comment was marked as outdated.
This comment was marked as outdated.
impeller/display_list/canvas.cc
Outdated
// layer once. | ||
if (backdrop_data->all_filters_equal && | ||
!backdrop_data->shared_filter_snapshot.has_value()) { | ||
// TODO(jonahwilliams): compute minimum input hint. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh forgot to update it, I had filled flutter/flutter#157110
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Introduces a mechanism to allow backdrop filters to 1) share backdrop inputs and 2) fuse filter applications for faster blurs.
This is a proposed solution to flutter/flutter#131568
Implemented:
TBD:
Suggestions: applying a bdf should be a distinct operation from a save layer in the DL builder/dispatcher. The saveLayer implmenentation in the impeller dispatcher is super convoluted because it needs to handle both.
Video
Video starts with normal bdf then I hot reload to specify that the bdfs share inputs/filters. This is running on a pixel 8 pro
Change to the macrobenchmark app is just:
demo.mp4
Requires framework changes in https://github.com/jonahwilliams/flutter/pull/new/backdrop_id