1790 Commits

Author SHA1 Message Date
Jim Graham
72ea712ff9 [Impeller] Fix size of squares in DrawPoints(PointMode). (flutter/engine#48547)
Fixes: https://github.com/flutter/flutter/issues/138877

The existing golden tests were already showing this bug, but we didn't see it. With this fix the size of the squares should be the same as the circle for the round caps in the DrawPoints playground goldens.

Test exemption request: This fix is covered by existing golden tests.
2023-12-01 17:39:29 +00:00
Jim Graham
391fe82deb [Impeller] Add direct tesselation of circles for DrawCircle and Round end caps (flutter/engine#48103)
Note: The GPU tesselation for drawPoints is disabled in this test PR, but will be re-enabled when I can run some benchmarks to see where a good cutoff exists.

Tessellation for circular or quarter circular paths is now handled by a single tessellator class that provides services for DrawCircle, DrawPoints (round caps), and DrawLines (round caps). Creating a general path is avoided along with the associated overhead of recognizing and using a generic tessellation step.
2023-11-30 20:54:06 +00:00
gaaclarke
4e92f34439 [Impeller] Started expanding the blur clip region (flutter/engine#48535)
fixes https://github.com/flutter/flutter/issues/139317
test: AiksTest.CanRenderClippedBlur

This works by double padding. First it applies the padding to clip
region, then it add a transparent gutter around the snapshot to account
for any of the expanded clip region that was ignored. This is suboptimal
since there maybe a considerable region for which blur is calculated
that is clipped. That can be optimized in the future by adjusting the
UVs in the blur phases to match the clip region.

## screenshot of result
<img width="1026" alt="Screenshot 2023-11-30 at 10 28 14 AM"
src="https://github.com/flutter/engine/assets/30870216/a0c673db-8b7a-465e-a75c-09f19d1b98aa">


## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-11-30 11:26:06 -08:00
Jonah Williams
c1ab864ad5 [Impeller] fix order of operations in SkSL generated texture lookup. (flutter/engine#48488)
Fixes https://github.com/flutter/flutter/issues/139017

When multiplying by the texture size we need to add parens incase the texture argument is actually an expression and not a single value.
2023-11-29 17:01:06 +00:00
Jonah Williams
3b4c5a2cd6 [Impeller] fix descriptor pool recycler test flake. (flutter/engine#48479)
This test worked by 1) releasing an item to be destructed on a background thead 2) adding a second item to this queue with a waitable event.

The idea being you could wait for the event and that would tell you when 1) was complete. Unfortunately these items are released by being placed into a std::vector, which destroyed in _reverse_ order. Somtimes when the test state was queried the work was done and sometimes it wasn't

To fix this, add a second waitable event that guarantees that both the first event and the original event have finished - because we do not add these event until the first is destructed and we do not add items to the destroy list while it is in progress.
2023-11-29 01:31:39 +00:00
Jonah Williams
a91602e3a5 [Impeller] Skip mask blur with 0 sigma. (flutter/engine#48457)
<0 sigma render incorrectly with wide gamut, but these shouldn't produce shadows at all as far as I can tell.

https://github.com/flutter/flutter/issues/138842
2023-11-28 19:13:54 +00:00
Jonah Williams
2b72b0253b [Impeller] match sigma scaling to Skia scaling. (flutter/engine#48434)
The Impeller blur is scaling down about twice as fast as the Skia Blur. Instead adopt their approximate constant values, which results in less shaking as the blur gets bigger.

FYI @gaaclarke
2023-11-28 18:52:57 +00:00
gaaclarke
398c7780f2 [Impeller] implements incorporating the gaussian blur snapshot transform (flutter/engine#48426)
fixes https://github.com/flutter/flutter/issues/139085

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-11-28 10:17:18 -08:00
Jonah Williams
b934c49920 [Impeller] Recycle descriptor sets. (flutter/engine#48343)
Like command pools, descriptor pools can be reset on a background thread and reused to improve CPU efficiency. Unlike command pools, we create one per render pass, so the existing management of the lifecycle is handled via the Tracked objects and we need only adapt the easier parts of the command pool reset.

To make the caching more effective, we change descriptor pool allocation to round up to NPOT. this is so if we have a frame with varying numbers of draws : 33, 42, 16, 45, we still end up recycling and reusing the descriptor pool (its just a bit of extra memory).

Fixes https://github.com/flutter/flutter/issues/134968
2023-11-28 18:06:05 +00:00
Kevin Lubick
92bce6db0e Replace all calls to SkTypeface::Make with SkFontMgr ones (flutter/engine#48319)
Similar to https://github.com/flutter/engine/pull/48179, Flutter needs
to stop depending on the default font manager, which the
`SkTypeface::Make*` calls do implicitly

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [ ] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-11-28 07:08:35 -05:00
Jonah Williams
91b78cc361 [Impeller] Add benchmarks that measure the time it takes to record canvas operations. (flutter/engine#48374)
This benchmark includes things like allocating geometry/contents, path conversions, et cetera. It doesn't include dispatching or GPU work, but should make it easier to see improvements/regressions in the efficiency of this code.
2023-11-28 03:06:53 +00:00
Matan Lurey
92a2b041fb Update HeaderFilterRegex once and for all. (flutter/engine#48145)
Includes a test (`header_filter_regex_test.dart`) that hopefully keeps
us on rails going forward.
2023-11-27 15:30:18 -08:00
gaaclarke
b90cbb6fdc [Impeller] updated gaussian blur tests to use device private textures (flutter/engine#48417)
fixes https://github.com/flutter/flutter/issues/138955

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-11-27 12:51:18 -08:00
Jonah Williams
83d1bc80a1 [Impeller] add explainer for Android CPU profiling. (flutter/engine#48407)
So you don't have to talk to me to figure out how to do this.
2023-11-27 20:41:05 +00:00
Jonah Williams
2753839ce5 [Impeller] revert non-zero tessellation optimization. (flutter/engine#48234)
Forgot about the winding order. partially reverts https://github.com/flutter/engine/pull/46282

See https://github.com/flutter/flutter/issues/138598

Reopens https://github.com/flutter/flutter/issues/135458
2023-11-27 17:26:36 +00:00
Brandon DeRosier
c49cfdc9a9 [Flutter GPU] Texture binding, index binding, attachments, depth state. (flutter/engine#48386)
Now rendering textured 3D models!

* Combined depth+stencil attachment.
* Allow for multiple color attachments.
* Add blend mode configuration.
* Fix uniform ordering for vertex shaders.
* Texture binding and sampling options.
* Index buffer binding.
* Depth configuration.
2023-11-26 19:47:16 -08:00
Jonah Williams
02ba2b7ff2 [Impeller] use spec constant for decal support in morph filter. (flutter/engine#48288)
Don't branch on uniform for decal support in GLES backend.
2023-11-27 03:03:15 +00:00
Jonah Williams
0ba4edc764 [Impeller] OES extension does not apply to regular textures for decal support (flutter/engine#48388)
This extension only implies decal support for OES textures. Remove it from the check for generic decal support.

In practice i think it would be unlikely that a driver supports this and not regular decal, but that would only make the bugs this may cause even harder to track down.
2023-11-27 03:03:13 +00:00
Brandon DeRosier
05f43a96aa [Flutter GPU] Raster encoding. First triangle! (flutter/engine#48314)
First triangle, in the framework! 🎉 

Adds shader libraries, pipelines, command buffers, render passes, etc.

* Light pipelines/shader objects. No optimization yet, pipeline warming
to come.
* "Dynamic" command style. Don't re-send bindings if you don't need to.
Essentially: https://github.com/flutter/flutter/issues/133179
* No need to explicitly encode passes.
* Minimal descriptor usage.
* Nothing is async, except for the optional command buffer completion
callback.

It took a bunch of experimenting to get here, but I think things are
starting to look pretty neat. :)

Todo:
* Land the shader bundle format/remove the testing hacks & fixtures that
piggyback off of the runtime effect system.
* Add remaining calls for blend config, clearing bindings, etc.
* Inconsistent error handling patterns that need cleanup.
* Maybe: Surface exceptions for validation errors.
* Handle the texture usage bitmask more elegantly.
2023-11-24 19:02:58 -08:00
auto-submit[bot]
4f2aeb7e76 Reverts "[Impeller] pass const ref to binding helpers." (flutter/engine#48330)
Reverts flutter/engine#48318
Initiated by: jonahwilliams
This change reverts the following previous change:
Original Description:
No point in passing by value and moving, just pass a const ref through. Trivial performance improvement.

# Before
```cpp
  /// Bind uniform buffer for resource named FragInfo.
  static bool BindFragInfo(ResourceBinder& command, BufferView view) {
    return command.BindResource(ShaderStage::kFragment, kResourceFragInfo, kMetadataFragInfo, std::move(view));
  }

  /// Bind combined image sampler for resource named texture_sampler.
  static bool BindTextureSampler(ResourceBinder& command, std::shared_ptr<const Texture> texture, std::shared_ptr<const Sampler> sampler) {
    return command.BindResource(ShaderStage::kFragment, kResourceTextureSampler, kMetadataTextureSampler, std::move(texture), std::move(sampler));
  }
  ```

# After
```cpp
  /// Bind uniform buffer for resource named FragInfo.
  static bool BindFragInfo(ResourceBinder& command, const BufferView& view) {
    return command.BindResource(ShaderStage::kFragment, kResourceFragInfo, kMetadataFragInfo, view);
  }

  /// Bind combined image sampler for resource named texture_sampler.
  static bool BindTextureSampler(ResourceBinder& command, const std::shared_ptr<const Texture>& texture, const std::shared_ptr<const Sampler>& sampler) {
    return command.BindResource(ShaderStage::kFragment, kResourceTextureSampler, kMetadataTextureSampler, texture, sampler);
  }
  ```
2023-11-22 20:09:17 +00:00
Jonah Williams
c453bac49b [Impeller] cache render target properties on Render Pass. (flutter/engine#48323)
Otherwise we do three hashmap lookups everything we call OptionsFromPass(AndEntity) in a contents.

## Before
16 / 392 = 4%

![image](https://github.com/flutter/engine/assets/8975114/cf02778c-22da-4849-a98a-75bac7536284)

## After
6/ 458 = 1.3%

![image](https://github.com/flutter/engine/assets/8975114/13b58267-a25a-483d-a632-55f505070996)
2023-11-22 19:16:11 +00:00
Jonah Williams
2faace2ef2 [Impeller] pass const ref to binding helpers. (flutter/engine#48318)
No point in passing by value and moving, just pass a const ref through. Trivial performance improvement.

# Before
```cpp
  /// Bind uniform buffer for resource named FragInfo.
  static bool BindFragInfo(ResourceBinder& command, BufferView view) {
    return command.BindResource(ShaderStage::kFragment, kResourceFragInfo, kMetadataFragInfo, std::move(view));
  }

  /// Bind combined image sampler for resource named texture_sampler.
  static bool BindTextureSampler(ResourceBinder& command, std::shared_ptr<const Texture> texture, std::shared_ptr<const Sampler> sampler) {
    return command.BindResource(ShaderStage::kFragment, kResourceTextureSampler, kMetadataTextureSampler, std::move(texture), std::move(sampler));
  }
  ```

# After
```cpp
  /// Bind uniform buffer for resource named FragInfo.
  static bool BindFragInfo(ResourceBinder& command, const BufferView& view) {
    return command.BindResource(ShaderStage::kFragment, kResourceFragInfo, kMetadataFragInfo, view);
  }

  /// Bind combined image sampler for resource named texture_sampler.
  static bool BindTextureSampler(ResourceBinder& command, const std::shared_ptr<const Texture>& texture, const std::shared_ptr<const Sampler>& sampler) {
    return command.BindResource(ShaderStage::kFragment, kResourceTextureSampler, kMetadataTextureSampler, texture, sampler);
  }
  ```
2023-11-22 19:14:15 +00:00
Jonah Williams
811d365669 [Impeller] make host buffer state internally ref counted. (flutter/engine#48303)
std::shared_from_this is actually incredibly slow, and dominates the cost of host buffer allocation at 20x more expensive than the memcpy. We can remove the usage of shared_from_this by making an internal class hold the actual allocation/buffer state instead.

### Before

![image](https://github.com/flutter/engine/assets/8975114/d6cd69c7-de1d-4b05-bd76-1d9a3353e350)

146 ms / 647ms = ~20%
### After

33 ms / 540 ms = ~6%

![image](https://github.com/flutter/engine/assets/8975114/e624dd94-9718-404a-a0f8-b359df9f0109)
2023-11-22 03:24:18 +00:00
Jonah Williams
330c06a4f2 [Impeller] Dont copy the paint until we're sure that the RRect blur optimization will apply. (flutter/engine#48298)
Extremely minor micro optimization. Dont copy the paint too early.

Before

![image](https://github.com/flutter/engine/assets/8975114/b5884e02-25ed-4e53-a6e0-d8d5a6a9a79a)

13/269 = ~5%

After:

![image](https://github.com/flutter/engine/assets/8975114/ac5981bb-40c6-4a38-b24c-46b7ad5399a4)

3/262 = ~1%
2023-11-22 00:24:06 +00:00
Matan Lurey
0b7f44c8c4 Yet more compliance with .clang_tidy, stragglers edition. (flutter/engine#48291)
Based off the
[failures](https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8763786250936903249/+/u/test:_test:_lint_host_debug/stdout)
in https://github.com/flutter/engine/pull/48145.

Nothing particularly interesting.
2023-11-21 13:39:18 -08:00
Jonah Williams
753e9e6ac7 [Impeller] Ensure that overlay surfaces are constructed with wide gamut settings. (flutter/engine#48190)
Fixes https://github.com/flutter/flutter/issues/138373

When constructing overlay layers when there are platform views, make sure the same pixel format and color space as the main view is used.

Add validation to impeller HAL about blitting different pixel formats.
2023-11-21 20:29:05 +00:00
Matan Lurey
b1a29657a9 Make {flow|fml|impeller}/... compatible with .clang_tidy. (flutter/engine#48241)
Another few stragglers.
2023-11-21 18:53:06 +00:00
Jonah Williams
260ec88f60 [Impeller] preallocate command buffer to next power of two of entity list. (flutter/engine#48185)
Commands are massive 500 byte objects, re-allocating this vector while recording them can actually add a substantial amount of overhead to applications with lots of drawing commands. Sizing to npot so that underestimating by a few commands doesn't force us to immediately copy all command objects.

This is still a herustic driven approach. An alternative exact approach would have entities/contents describe how many commands they would add. This may be more important for stencil then cover (depending on how we do it) since some contents would need to create two commands.
2023-11-21 18:12:20 +00:00
gaaclarke
e18e1d286c [Impeller] implements gaussian "blur halo" (flutter/engine#48149)
This makes the blurred item have a halo effect that is rendered outside of the bounds of the original thing that was rendered.

issue: https://github.com/flutter/flutter/issues/131580

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-21 16:47:24 +00:00
Matan Lurey
f0ccf7a9a3 [Impeller] Try replacing *desc with value/is_valid checks. (flutter/engine#48194)
Some discussion here:
https://discord.com/channels/608014603317936148/1175215129135153202.

In short, `*<std::optional>` is [undefined
behavior](https://en.cppreference.com/w/cpp/utility/optional/operator*).
After talking to @bdero we are considering that this should never
happen.

I thought of a few different approaches here, none of them are great.
However given that this class is used quite minimally, this seems to
jive with similar patterns we're using in scene/scene_context.

---

Feel free to push back or suggest alternatives, mostly proposing this to
get brain juices flowing.
2023-11-20 16:43:28 -08:00
Kevin Lubick
0d0d4db144 Replace calls to SkFontMgr::RefDefault (flutter/engine#48179)
Skia is removing this API, so clients must track a default FontMgr if
they want one. See https://issues.skia.org/issues/305780908

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide] and the [C++,
Objective-C, Java style guides].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I added new tests to check the change I am making or feature I am
adding, or the PR is [test-exempt]. See [testing the engine] for
instructions on writing and running engine tests.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I signed the [CLA].
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#overview
[Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene
[test-exempt]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[C++, Objective-C, Java style guides]:
https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
[testing the engine]:
https://github.com/flutter/flutter/wiki/Testing-the-engine
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes
[Discord]: https://github.com/flutter/flutter/wiki/Chat
2023-11-20 07:57:02 -05:00
Matan Lurey
54a0749f76 Make impeller/... compatible with .clang-tidy. (flutter/engine#48155)
I moved [`scene_context.h` to another PR](https://github.com/flutter/engine/pull/48194), and here are the boring remains.
2023-11-18 01:21:48 +00:00
Matan Lurey
65edca6565 Make impeller/aiks/... compatible with .clang-tidy. (flutter/engine#48152) 2023-11-17 23:00:13 +00:00
Matan Lurey
178e3396e3 Make impeller/geometry/... compatible with .clang-tidy. (flutter/engine#48154) 2023-11-17 12:05:40 -08:00
Matan Lurey
c175f20309 Make impeller/{archivist|compiler|core|entity}/... compatible with … (flutter/engine#48153) 2023-11-17 11:58:57 -08:00
gaaclarke
cb70984e12 [Impeller] Unify around "transform" (flutter/engine#48184)
This replaces usage of "xformation" and "transformation".

test-exempt: refactor

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-17 18:03:23 +00:00
Jonah Williams
ea36645542 [Impeller] Cleanups to geometry interfaces. (flutter/engine#48180)
* Removed virtual destructor. We only use Geometry types with std::shared_ptr which remembers the correct dtor, we'd only need the virtual destructor if we were using `free` ourselves.
* Remove std:unique_ptr. We had a mix on unique and shared ptrs, and were even doing some copies/conversions between the two. I made it consistently shared_ptr, I don't see the advantage of unique given that geometries are essentially immutable.
* made geometry classes have more const methods and final.
* Added some asserts on trivial destruction.
2023-11-17 17:05:56 +00:00
Brandon DeRosier
f553fe0023 [Flutter GPU] Add Textures. (flutter/engine#48118) 2023-11-16 22:28:54 -08:00
Brandon DeRosier
f9b113e43c [Impeller] Add support for external GL textures to TiledTextureContents. (flutter/engine#47586) 2023-11-16 16:56:49 -08:00
Jonah Williams
6da29df7ee [Impeller] Clang tidy even more (flutter/engine#48102)
Also removes alot of includes of fml macros, which I know is always safe to remove.
2023-11-16 23:15:00 +00:00
gaaclarke
6f471e9027 [Impeller] Implements gaussian blur that scales down before applying the blur (flutter/engine#47576)
A partial implementation of the new gaussian blur effect.  This should perform enough of the code to start getting some performance numbers.

Known outstanding problems:
  1) The edges of the blur are clipped.   I have notes on how I plan on expanding render space in the PR.
  1) Animating the sigma causes some "jumping around artifacts" resulting from the downsampling (maybe the discrete nature of texture pixel size?)
  1) Coverage hints are ignored.  I think depth tests will make that not much of an issue.
  1) We aren't ping ponging textures yet
  1) The snapshot's transform is ignored.

issue: https://github.com/flutter/flutter/issues/131580

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
2023-11-16 22:34:22 +00:00
Jonah Williams
50edc5f397 [Impeller] store all path point data in single buffer. (flutter/engine#47896)
Path objects are expensive to allocate, create, move, et cetera because of the large number of internal heap allocations performed. This change combines the linear, quad, and cubic buffers into a single point buffer that stores all points/control points inline.

The existing component buffer stores the index to the first point in the buffer, and the type field determines how many points are read.

Benchmarked in https://flutter-engine-perf.skia.org/e/?queries=test%3DBM_Polyline_cubic_polyline%26test%3DBM_Polyline_quad_polyline&selected=commit%3D38035%26name%3D%252Cconfig%253Ddefault%252Ccpu_scaling_enabled%253Dfalse%252Cexecutable%253D_b_s_w_ir_cache_builder_src_out_host_release_geometry_benchmarks%252Clibrary_build_type%253Drelease%252Cmhz_per_cpu%253D2200%252Cnum_cpus%253D8%252Csub_result%253DTotalPointCount%252Ctest%253DBM_Polyline_quad_polyline%252Cunit%253Dns%252C

https://github.com/flutter/flutter/issues/138004
2023-11-16 18:54:12 +00:00
Chinmay Garde
94bb885ead [Impeller] Fix issue where the lock was not re-acquired when the wait exits on CV. (flutter/engine#48104)
Had not used std::adopt_lock before and didn't realize that the unique lock destructor unlocks the mutex even when the mutex is adopted (which I suppose makes sense when you think about it). But I had added the annotations assuming the lock will remain if adopted. Found after a painful round of debugging the "safe" condition variables.
2023-11-16 17:54:05 +00:00
Jonah Williams
a4b4cae1a8 [Impeller] Create a drawable backed TextureMTL. (flutter/engine#48049)
Allow creating a TextureMTL instance that is backend by a CAMetalLayer, which only acquires the drawable (and texture) lazily.

I split TextureMTL into two subclasses, one that has the standard wrapping behavior of a MTLTexture, and the other that holds a drawable. This is part of the foundational work for "removing drawable acquisition latency", as we need to delay aquisition of the drawable texture to a worker thread.

The drawable backed texture is only used in tests for now.

Part of https://github.com/flutter/flutter/issues/138490
2023-11-16 17:50:18 +00:00
Jonah Williams
9af166c5ce [Impeller] add async command submission for blit pass. (flutter/engine#48040)
This is a requirement for the "Remove Drawable Acquisition Latency" Change, but is otherwise a harmless improvement.

---

Submitting a command buffer causes the backend specific encoding logic to run. Metal is unique in that it is fairly easy to move this work into a background thread, allowing the engine to move onto creating the next command buffer. This improves throughput of the engine, at the cost of needing two slightly different APIs. Currently the GLES and Vulkan versions of this method still submit synchronously - for now that is out of scope as doing background work with those APIs has proved more challenging.

See also:
   * https://github.com/flutter/engine/pull/42028
   * https://github.com/flutter/flutter/issues/131698
   
Separately, as a requirement for the design in "Remove Drawable Acquisition Latency", we need to be able to defer drawable acquisition to this background thread. While this almost already works for render passes, it does not work for blit passes today. if the engine renders a backdrop filter, then the final command buffer submitted will be a blit pass that copies an offscreen onto the drawable. Therefore we need to add an async version of the blit submission, so that we have a hook to move the drawable acquisition onto a background thread for metal.

This hadn't been done until now because most blit cmd buffers have 1 or 2 cmds on them so the benefit of moving to a background thread is minimal.

Part of https://github.com/flutter/flutter/issues/138490
2023-11-15 23:22:22 +00:00
Jonah Williams
9978ca06a8 [Impeller] some clang tidies in impeller (flutter/engine#48077)
Usage of Scalar/Vector/Half types is desgned around implicit conversions today: we don't specifically convert to the correct generated header types, since that will depend on the target platform. Instead we rely on implicit conversions to handle this - any mistake there would still lead to a compilation error.
2023-11-15 18:26:53 +00:00
Jonah Williams
ac51782b20 [Impeller] Simplify convex tessellation (flutter/engine#47957)
Removes usage of index buffer and adds zig-zagging triangle strip. Could also be adapted emplace directly into host 
buffer.

Benchmark is https://flutter-engine-perf.skia.org/e/?queries=test%3DBM_Convex_rrect_convex

Umbrella issue: https://github.com/flutter/flutter/issues/138004
2023-11-15 01:43:33 +00:00
Jonah Williams
0ba039231a [Impeller] Add convex tess benchmark. (flutter/engine#47956)
Since most shapes are convex, we should benchmark this too.
2023-11-13 18:16:50 +00:00
Brandon DeRosier
fa96666e03 [Flutter GPU] Add DeviceBuffer. (flutter/engine#47699)
Part of http://flutter.dev/go/impeller-dart

Resolves https://github.com/flutter/flutter/issues/130924.
Resolves https://github.com/flutter/flutter/issues/130925.

Create and upload data to host visible device buffers. Commands should allow for binding either HostBuffers (which eventually resolve to DeviceBuffers) or DeviceBuffers. There's a `Buffer` mixin to allow for expressing this in `BufferView`, but this may end up changing once I actually add Commands and need to solve the puzzle.
2023-11-11 00:56:51 +00:00
Jim Graham
77fcf57543 [Impeller] implement Canvas::DrawLine to tesselate lines directly (flutter/engine#47846)
Impeller implements the DrawLine primitive as DrawPath on a path containing a single line. Benchmarks show that this can cost 30% overhead on apps that use a lot of DrawLine primitives. This PR creates a more direct Entity that can tesselate the geometry of a line directly.

The reduced overhead should help with https://github.com/flutter/flutter/issues/138004

The current code will back off to Path rendering for round caps. When the circle geometry work is finished (https://github.com/flutter/engine/pull/47845) we can come back and implement round caps using the code refactored in that PR.
2023-11-10 22:13:43 +00:00