Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Special case color filter in tiled texture. #39445

Merged
merged 13 commits into from
Feb 14, 2023

Conversation

jonahwilliams
Copy link
Member

Fixes flutter/flutter#119874

Currently there are two inefficiencies in the main wonderous carosel page:

  1. We require two pass to tile the texture with opacity, then apply a color filter, these operations should be combined.
  2. The final coverage is used for intermediate render passes, but tilling could be applied at the end.

Fixing these increases the FPS I see from ~90 up to 110. Getting closer!

I first attempt to generalize the passthrough code to handle tiled textures. In summary, this was a huge mess: https://github.com/flutter/engine/compare/main...jonahwilliams:engine:uv_stuff?expand=1

I tried to create a simpler implementation that takes advantage of the fact that the color filters we care about are almost always set on the same paint that is drawing the tiled texture. The tiled texture contents can be responsible for applying color filter in a subpass that is sized to the texture.

@flutter-dashboard

This comment was marked as off-topic.

@jonahwilliams jonahwilliams marked this pull request as draft February 7, 2023 01:59
@jonahwilliams
Copy link
Member Author

TBD how we should test this, texture allocation or whatnot.

@jonahwilliams
Copy link
Member Author

before

before_patch

after

after_patch

@jonahwilliams jonahwilliams marked this pull request as ready for review February 8, 2023 17:27
@chinmaygarde chinmaygarde changed the title [impeller] special case color filter in tiled texture [Impeller] special case color filter in tiled texture. Feb 8, 2023
Comment on lines 48 to 55
uint64_t Allocator::GetAllocatedSize() const {
return allocated_size_;
}

void Allocator::ResetAllocatedSize() {
allocated_size_ = 0;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should add/remove these with some ifdef.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea is that if we do this only in builds for engine unit tests, we could probably track a vector of allocated sizes which make assertions easier

@chinmaygarde chinmaygarde changed the title [Impeller] special case color filter in tiled texture. [Impeller] Special case color filter in tiled texture. Feb 11, 2023
@@ -37,6 +37,15 @@ class Allocator {
///
virtual uint16_t MinimumBytesPerRow(PixelFormat format) const;

// Debug/Profile only functionality for tracking the size of allocations
#if (FLUTTER_RUNTIME_MODE != FLUTTER_RUNTIME_MODE_RELEASE)
const std::vector<ISize>& GetAllocatedSizes() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if you intend to incorporate the allocator instrumentation into this patch. If it helps speeds thing along for this patch, maybe we can back this out and land this patch while working on the instrumentation separately. Your call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think now that I have an idea of how we will test this, I feel more comfortable backing this change out and working on it separately

Copy link
Member

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after backing out the allocator instrumentation is backed out. We discussed that this is would be fixed in a separate patch.

std::shared_ptr<Texture> texture_;
SamplerDescriptor sampler_descriptor_ = {};
Entity::TileMode x_tile_mode_ = Entity::TileMode::kClamp;
Entity::TileMode y_tile_mode_ = Entity::TileMode::kClamp;
std::optional<ColorFilterProc> color_filter_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be good to note why this this is here as a naive implementation (like the one earlier) shouldn't have to care about the filter.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment here and a breadcrumb in paint.cc

@jonahwilliams
Copy link
Member Author

Backed out the allocator change. Will open a new PR with these features later

@jonahwilliams jonahwilliams added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 14, 2023
@auto-submit auto-submit bot merged commit 57e83aa into flutter:main Feb 14, 2023
@jonahwilliams jonahwilliams deleted the tiled_texture_special branch February 14, 2023 19:26
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 15, 2023
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Feb 15, 2023
…120761)

* ab2dec516 Roll Skia from 8de7f68a3661 to 67a8177742e6 (4 revisions) (flutter/engine#39623)

* a7ec1e50f Remove libpng dependency in the APNG decoder (flutter/engine#39622)

* cb5393336 Add more info to malioc_diff.py output (flutter/engine#39625)

* 60c199501 Roll Dart SDK from ea59504416a8 to 22ad11262460 (2 revisions) (flutter/engine#39624)

* b1f76fbb0 [Impeller] Avoid stringstream usage in CreateUniformMemberKey (flutter/engine#39606)

* a85220d2f Fix a flake in EmbedderTest.CompositorRenderTargetsNotRecycledWhenAvoidsCacheSet (flutter/engine#39596)

* 3141b116d [impeller] Refactored backend specific feature checks to capabilities (flutter/engine#39598)

* bf667254f [impellerc] Generate GLSL output for the runtime-stage-gles target (flutter/engine#39602)

* 57e83aa16 [Impeller] Special case color filter in tiled texture. (flutter/engine#39445)

* e1325a9de Roll Skia from 67a8177742e6 to a3fe5233eb10 (9 revisions) (flutter/engine#39627)

* 9f2c4db50 Add app anatomy diagram (flutter/engine#39628)

* e8c14e436 Roll Fuchsia Linux SDK from mWwKhmxRlXNJATVmu... to A15Lg2MzGSkbj33mo... (flutter/engine#39631)

* 9bd50b706 [Impeller] read from framebuffer for advanced blends on iOS. (flutter/engine#39567)

* 66715c928 Fix build output path of the malioc core list (flutter/engine#39629)

* 727500b12 Roll Skia from a3fe5233eb10 to b7508e2f2577 (3 revisions) (flutter/engine#39634)

* f193de9cc [Impeller] Make RenderTarget::CreateOffscreen utilities have a stencil by default (flutter/engine#39636)

* 76b51e33a Roll Skia from b7508e2f2577 to 5974e36ea190 (4 revisions) (flutter/engine#39639)

* aba44ff0b Roll Dart SDK from 22ad11262460 to 1dc26efa3c4c (1 revision) (flutter/engine#39640)

* 657102f87 Roll Fuchsia Mac SDK from EFcCpAxOuQllDqP0F... to jsnm3dngrd9MveHrB... (flutter/engine#39641)

* 44e36c9c0 Roll Skia from 5974e36ea190 to 2a7644cf4bd7 (1 revision) (flutter/engine#39642)
// Image input types will directly set their color filter,
// if any. See `TiledTextureContents.SetColorFilter`.
if (color_source_type == ColorSourceType::kImage) {
return input;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this will break if the filter is set after the color source?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, it's capturing a ref to the paint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can lose this optimization if its making canvas weird. now that we're handling filters better in general its not as necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can lose this optimization if its making canvas weird. now that we're handling filters better in general its not as necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah I think it's alright. Just had to rethink a refactor I'm working on.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
autosubmit Merge PR when tree becomes green via auto submit App e: impeller
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

[Impeller] For images with tiling, attempt applying filters once to the untiled image before tiling.
3 participants