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

[Impeller] Enable depth buffer clipping & Stencil-then-Cover path rendering. #50856

Merged
merged 3 commits into from
Mar 5, 2024

Conversation

EXPECT_TRUE(contains_size(ISize(1000, 1000)))
<< "The root texture wasn't allocated";
EXPECT_TRUE(contains_size(ISize(200, 200)))
<< "The ColorBurned texture wasn't allocated (100x100 scales up 2x)";
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was fragile so I tried to encode its intent better rather than adding more branches.

Copy link
Member

Choose a reason for hiding this comment

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

SGTM

default:
FML_UNREACHABLE();
}
pass.SetPipeline(renderer.GetClipPipeline(options));
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 had to rework this StC logic a bit because it wasn't handling Positions+UVs right. I was inadvertently stenciling with position+UV geometry (bad) and then covering using a position-only rectangle (also bad).

This is fixed now. When we need to use StC, we only generate positions for the stencil prep draw and then draw the cover rectangle with or without UVs 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.

I have a preference towards separating out this rework and the flag-flip of the stencil-then-cover into separate PRs.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I pulled out these changes into this PR: #50900

@chinmaygarde
Copy link
Member

Can you separate just the flag flip into another PR? Otherwise lgtm.

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 #50900 lands. So a lot of this go away with just the flag flip remaining. Thanks!

auto-submit bot pushed a commit that referenced this pull request Feb 23, 2024
The accumulated fixes pulled out of the flag flip PR: #50856

* Also fixes tests to make them resilient to StC being on/off.
* Fix blending for the cover draw.
* Default to depth=1 which is much more reasonable as depth=0 will never draw anything for cover draws. This allows enclosed subpass rendering cases like `Contents::RenderToSnapshot` for filter inputs to work by default and makes mistakes harder.
* Use depth+stencil attachments for `Contents::RenderToSnapshot` subpasses to allow for StC draws.
Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM (but not to CI)

@jonahwilliams
Copy link
Member

The failing test: "Canvas.drawParagraph " IIRC is using Picture.toImage and the Vulkan swiftshader backend, fwiw

@bdero
Copy link
Member Author

bdero commented Feb 24, 2024

There's something funky going on here. On linux_host_engine, Canvas.drawParagraph renders tab as space instead of tofu passed on debug but not profile or release: https://ci.chromium.org/ui/p/flutter/builders/try/Linux%20linux_host_engine/27617/overview

@bdero
Copy link
Member Author

bdero commented Feb 24, 2024

Okay, so it only ever fails when flutter_tester is run with --enable-impeller and --force-multithreading. The --enable-impeller invocation without --force-multithreading doesn't fail.

@bdero
Copy link
Member Author

bdero commented Feb 24, 2024

In total I've seen these tests failing on and off so far:

  • toImage and toImageSync have identical contents
  • Canvas.drawParagraph renders tab as space instead of tofu
  • Canvas preserves perspective data in Matrix4

All of these are doing toImage + toByteData and verifying pixel data.

On macos, I can only repro the toImage and toImageSync have identical contents failure. I ran canvas_test.dart > 100 times without --force-multithreading and it never failed. But when I enable --force-multithreading, it fails around half of the time.

@bdero
Copy link
Member Author

bdero commented Feb 24, 2024

I started dumping the result images before performing the failing ByteData comparison. Formatting the byteData as a PNG drastically reduced the error rate and it took more than 200 runs to collect three failure samples, all of which are identical (MD5 96f4201864c564a731a252100ef6c764):

toImageSync:
toImageSync
toImageSync
toImageSync

toImage:
1
2
3

Close-up in photoshop of the failed toImage result:
image

@bdero
Copy link
Member Author

bdero commented Feb 24, 2024

If I add sleep(const Duration(milliseconds: 300)) just before return (await resultImage.toByteData())! in toImage and toImageSync have identical contents, then Canvas.drawParagraph renders tab as space instead of tofu starts failing every time.

Peculiar! Maybe an underlying allocation is being prematurely freed or reused.

@bdero
Copy link
Member Author

bdero commented Feb 24, 2024

If I disable the DeviceBuffer VMA pool by commenting out these lines the buffers stop getting corrupted:

if (created_buffer_pool_ && desc.storage_mode == StorageMode::kHostVisible) {
allocation_info.pool = staging_buffer_pool_.get().pool;
}

@jonahwilliams
Copy link
Member

I'm not sure how the multi threaded test env. Works, but it's possible that it is breaking some contracts about thread safety of the contexts. You might try backing out Aaron's change to reuse the context objects in the test environment

@jonahwilliams
Copy link
Member

Oh wait, but then that wouldn't explain tester changes.

@jonahwilliams
Copy link
Member

Well if it makes it work, id say delete the VMAPool. But I'm a bit suspicious that something in the flutter tester integration is busted

@jonahwilliams
Copy link
Member

I'm sort of wondering if there is a problem with the readback implementation in image_encoding_impeller.cc -> ConvertBufferToSkImage.

We blit the render target texture into a device buffer and then readback that device buffer. Potentially the device buffer is getting released too early, or we're missing a memory barrier for the readback. I'm not sure if the fence waiter firing guarantees that the buffer is fully populated.

@jonahwilliams
Copy link
Member

I opened two PRs with adjustments to buffer usage/readback to see if those pass/fail

@jonahwilliams
Copy link
Member

I think the "do everything plus barrier" pr is working but is hitting a GLES exception

@bdero bdero force-pushed the bdero/enable-stc branch from 5777f9b to 6c6d241 Compare March 4, 2024 22:11
@jonahwilliams
Copy link
Member

You gotta stop force pushing!

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM, please land a non-force pushed commit so we can verify gold.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #50856 at sha daef206

@bdero
Copy link
Member Author

bdero commented Mar 4, 2024

please land a non-force pushed commit so we can verify gold.

My understanding is that this bug is limited to the flutter-engine-gold.skia.org interface. The flutter-gold test won't succeed if there are golden differences.

@jonahwilliams
Copy link
Member

these goldens look unexpected. Did you need the change from #51101 ?

@bdero
Copy link
Member Author

bdero commented Mar 4, 2024

Maybe. Let's try just the picture.cc attachment change.

@bdero
Copy link
Member Author

bdero commented Mar 5, 2024

Yup that seems to work. Want to land your patch @jonahwilliams? The brand new blur style is broken with StC so now I'm trying to chase that down now.

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

Changes reported for pull request #50856 at sha 1fb0d41

@bdero
Copy link
Member Author

bdero commented Mar 5, 2024

I think the behavior of Inner and Outer is reversed at ToT and enabling StC/switching to the new clip system is just fixing it:
image

Copy link
Member

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM

@bdero bdero added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 5, 2024
@auto-submit auto-submit bot merged commit 3e9928e into flutter:main Mar 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 5, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Mar 5, 2024
…144607)

flutter/engine@d514a30...17a4b66

2024-03-05 [email protected] Roll Skia from a577399ed6fb to 5839a94bf28b (1 revision) (flutter/engine#51194)
2024-03-05 [email protected] [Impeller] Turn off StC. (flutter/engine#51191)
2024-03-05 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Reland: [macOS] Use CVDisplayLink to drive repaint (#51126)" (flutter/engine#51192)
2024-03-05 [email protected] Roll Skia from 9c62e7b382cf to a577399ed6fb (1 revision) (flutter/engine#51190)
2024-03-05 [email protected] Reland "Remove migration flag and unused header files #50216" (flutter/engine#50259)
2024-03-05 [email protected] Shift git version fetching to tools/gn (flutter/engine#51175)
2024-03-05 [email protected] [fuchsia] Remove now unnecessary diagnostics directory (flutter/engine#51180)
2024-03-05 [email protected] [Impeller] Enable depth buffer clipping & Stencil-then-Cover path rendering. (flutter/engine#50856)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-engine-flutter-autoroll
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
bdero added a commit to bdero/flutter-engine that referenced this pull request Mar 5, 2024
auto-submit bot pushed a commit that referenced this pull request Mar 5, 2024
auto-submit bot added a commit that referenced this pull request Mar 5, 2024
… path rendering. (#51209)" (#51217)

Reverts #51209
Initiated by: bdero
Reason for reverting: Golden breakages on [engine roll](flutter/flutter#144647) https://flutter-gold.skia.org/search?issue=144647&crs=github&patchsets=5&corpus=flutter
Original PR Author: bdero

Reviewed By: {jonahwilliams, chinmaygarde}

This change reverts the following previous change:
Original Description:
Turn the page, wash your hands.

Addresses the following issues:
* flutter/flutter#143077
* flutter/flutter#137714
* flutter/flutter#138460
* flutter/flutter#123671
* flutter/flutter#141961
* flutter/flutter#134432

Previous attempt:
- #50856
    - reverted with #51191
    - fixed with #51198
bdero added a commit to bdero/flutter-engine that referenced this pull request Mar 6, 2024
auto-submit bot pushed a commit that referenced this pull request Mar 6, 2024
…dering. (#51219)

Turn the page, wash your hands.

Addresses the following issues:
* flutter/flutter#143077
* flutter/flutter#137714
* flutter/flutter#138460
* flutter/flutter#123671
* flutter/flutter#141961
* flutter/flutter#134432

Previous attempts:
1. #50856
    - reverted with #51191
    - fixed with #51198
2. #51209
    - reverted with #51217
    - fixed with #51218
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 will affect goldens
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants