-
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
Defer decisions about RasterCache actions until after Preroll is complete #31892
Defer decisions about RasterCache actions until after Preroll is complete #31892
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
d6e6fa0
to
36d70fd
Compare
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.
One thing I like about this mechanism is that it essentially breaks the caching out into a separate pass as per flutter/flutter#91923
I think the mechanism should be much simpler as explained in the review comments. Also, it would be nice to include picture and display caching in the list of cacheable items.
Finally, we could prune the dead cache entries (see the SweepOneCache method) before we add new ones in the caching pass. This would require the preroll items to "touch" or "mark" their existing cache items as having been seen so we don't de-cache anything used in the current frame. This advanced pruning could be a follow on PR, or it could be rolled into this mechanism.
36d70fd
to
3ea7e25
Compare
@flar hey bro, According your suggest I have change the |
@flar @JsouLiang |
Fine... |
1658c1a
to
3d0731a
Compare
3d0731a
to
9b054f5
Compare
9b054f5
to
5b927b4
Compare
flow/layers/layer.h
Outdated
SkRect cull_rect; | ||
SkColorSpace* color_space; | ||
|
||
bool surface_needs_readback; |
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.
Generally this value is only used during Preroll and will not be needed in the caching methods. You can delete this field and just provide a dummy value when creating the Context used when processing the caching queue.
5b927b4
to
aefa7c6
Compare
463110e
to
fe86bd1
Compare
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.
First, I'm not entirely happy with the way the classes break down and inherit methods. I originally suggested creating a CacheableLayer type of class so that only the exact layers that want to perform caching would inherit from it and none of the methods to implement the caching mechanism would exist in Layer or ContainerLayer, but that doesn't seem to be the way that this is going. Every ContainerLayer implements CacheableLayer whether or not its sub class wants to consider caching, and only a portipon of them actually try to cache themselves or their children. If this subclass can't isolate the cacheable methods out of Layer and ContainerLayer, then let's just get rid of it.
Second, we are seeing an issue with the opacity inheritance flags. These were originally implemented as part of Preroll and the children would indicate their ability to inherit the opacity based on a few conditions:
- They were planning to do their own saveLayer in the Paint method and so they could add the opacity as an attribute to the saveLayer "for free" to avoid OpacityLayer having to do its own saveLayer
- They were planning to just drawImage an image to the screen so they could add the opacity to the SkPaint used in the call to drawImage. This applied mainly to TextureLayer and the Picture/DisplayListLayers in the case where they were being drawn from the cache.
- Some layers could pass the opacity through to their child(ren) since their function involved no rendering at all (Transform/ClipLayers).
- Finally some DisplayList objects could inherit the opacity even if they weren't cached.
Most of those cases can be statically determined during preroll except for one - whether or not a Picture or DisplayList is cached. We now don't really know that until after Preroll is done.
In most cases you set it after ShouldBeCached which is a far cry from when it actually should be set. ShouldBeCached simply says that the Picture or DisplayList is eligible based on a static assessment, but there is still a countdown before caching it. It used to be set only after the countdown of pre-cache draws was exceeded and then the picture/DL was cached. You are setting the flag way prematurely (3 entire frames prematurely).
Even if it "ShouldBeCached" and the countdown happens and this is the frame where it gets into the cache, it may not end up being cached because we only cache a maximum of N items per frame and this one may be beyond that limit, or we could simply fail to cache it because it exceeded the maximum allocation size for a texture - we won't know until the cache evaluation phase for much of that.
fe86bd1
to
d728981
Compare
@flar Hi bro, according to your suggestion, I change the |
0c52ffe
to
0e2f476
Compare
3cb79e4
to
9b68847
Compare
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
@ColdPaleLight @dnfield any final review comments? |
The corresponding benchmark to demonstrate the elimination of the "double caching" issue is in the framework tree and collecting data. Depending on how busy the trees are, it will hopefully collect a good dozen or so results before this PR can be rolled in. |
context->raster_cached_entries->push_back(this); | ||
cache_state_ = CacheState::kCurrent; | ||
} | ||
return; |
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.
nit: remove it
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 with nit
I would really like to see the captures in the two places that are using That said, It doesn't have to block landing this change and it'd be fine to follow on in a separate PR. |
My other review comments were less important nits or appear to have been addressed. |
Good point. flutter/flutter#106892 |
// if the rect is intersect we will get the entry access_count to confirm if | ||
// it great than the threshold. Otherwise we only increase the entry | ||
// access_count. | ||
if (context->cull_rect.intersect(bounds)) { |
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.
Shouldn't this be "intersects"? Is this a bug? I'm curious why it never showed up anywhere. Perhaps because we don't use this cull_rect for much during preroll?
AutoGatherLayers
(from knopp) to collection the Layer which need to RasterCachelevel
property which mean the layer level in the LayerTree, when we have collection the need RasterCache layer frompreroll
method and the we will Raster Cache Layer according thelevel
that mean we will do Raster Cache layer from top to bottom .RasterCache(PrerollContext*, matrix)
method the layer not do raster cache if the ancestor layer has raster cacheTODO:
RasterCacheableEntry
need to differentiate:Layer
,DisplayList
,SkPicture