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

[Impeller] vk::CommandPool resets via ResourceManager #45654

Merged
merged 33 commits into from
Sep 16, 2023

Conversation

matanlurey
Copy link
Contributor

@matanlurey matanlurey commented Sep 11, 2023

Fixes flutter/flutter#133198.

Major changes:

  • CommandPoolVK is now created indirectly through CommandPoolRecyclerVK.
  • Via destructor, CommandPoolVK resets on a background thread via ResourceManager.
  • Removed all of the code trying to reuse/reset individual command buffers (no longer needed).
  • After every frame, the current/active command pool is recycled.

Tests secured.

@matanlurey matanlurey self-assigned this Sep 11, 2023
@matanlurey matanlurey changed the title [Impeller] vk::CommandPool is now reset off-thread using ResourceManager [Impeller] vk::CommandPool resets via ResourceManager Sep 11, 2023
@matanlurey matanlurey marked this pull request as ready for review September 11, 2023 22:35
///
/// A single instance should be created per |ContextVK|.
///
/// Every "frame", a single |CommandPoolResourceVk| is made available for each
Copy link
Member

Choose a reason for hiding this comment

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

Please make a note of the the threading restrictions you've accounted for here. Specifically, the spec says:

Command pools are externally synchronized, meaning that a command pool must not
be used concurrently in multiple threads. That includes use via recording
commands on any command buffers allocated from the pool, as well as
operations that allocate, free, and reset command buffers or the pool itself.

The things I would look for are:

  1. Are the commands in the command pool done executing when recycle is called?
  2. Does the swap and recycle happen in a thread safe manner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ack. I did find a problem (in unit tests) and addressed them. Did you want the docs updated?

Copy link
Member

Choose a reason for hiding this comment

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

It would be good to have at least 1 answered clearly in the docs. 2 is an implementation detail I am fine leaving out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, added!

@matanlurey
Copy link
Contributor Author

I ran into some multi-threading problems with CreateMockVulkanContext, so I'm going to send a patch to @gaaclarke on that first before addressing the comments above (likely tomorrow AM at this point). Thanks!!!

@matanlurey
Copy link
Contributor Author

I found two other sources of bugs (other than code in this PR) blocking and have fixes out:

Once those are both in I'll update to main and address @chinmaygarde's comments/re-run CI.

matanlurey added a commit that referenced this pull request Sep 12, 2023
I started using `CreateMockVulkanContext()` in
#45654, and discovered that it was
not thread-safe. This PR does a little bit of refactoring/TLC to ensure
that functions and buffers can be accessed across threads (like the
_real_ `ContextVK`).

The attached test (_test for a test fixture, hoorah!_) fails
consistently before the changes, and passes after. Note that if you try
testing this with `--gtest_repeat=10000` (at least that's the threshold
for me), it'll fail - that's actually due to
flutter/flutter#134482 which in turn is being
fixed in #45686.

(Unblocks flutter/flutter#133198)

---------

Co-authored-by: gaaclarke <30870216+gaaclarke@users.noreply.github.com>

buffers_to_collect_.clear();
void CommandPoolRecyclerVK::Recycle() {
Copy link
Member

Choose a reason for hiding this comment

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

Seems more like disposal than recycling?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah fair enough. Renamed!

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.

Overall LGTM, though not to CI 😄

///
/// A single instance should be created per |ContextVK|.
///
/// Every "frame", a single |CommandPoolResourceVk| is made available for each
Copy link
Member

Choose a reason for hiding this comment

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

It would be good to have at least 1 answered clearly in the docs. 2 is an implementation detail I am fine leaving out.

@matanlurey matanlurey added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 16, 2023
@auto-submit auto-submit bot merged commit cc79017 into flutter:main Sep 16, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Sep 16, 2023
fluttermirroringbot pushed a commit to flutter/flutter that referenced this pull request Sep 16, 2023
…ions) (#134882)

Manual roll requested by zra@google.com

flutter/engine@4909256...8c2203b

2023-09-16 skia-flutter-autoroll@skia.org Roll Skia from b33e0e6706b0 to 2eaaa5bf7dae (1 revision) (flutter/engine#45926)
2023-09-16 skia-flutter-autoroll@skia.org Roll Skia from a1f8fb54299a to b33e0e6706b0 (1 revision) (flutter/engine#45923)
2023-09-16 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from -_edKGA5GTkDFxVgl... to 3Tb9CQTTiBv1lb673... (flutter/engine#45922)
2023-09-16 skia-flutter-autoroll@skia.org Roll Dart SDK from 029d6d73c860 to a0ca39c63c16 (1 revision) (flutter/engine#45921)
2023-09-16 matanlurey@users.noreply.github.com [Impeller] `vk::CommandPool` resets via `ResourceManager` (flutter/engine#45654)
2023-09-16 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from wWzXsy6kx1sp8Km34... to ZhY53WD7bFJSA3xoO... (flutter/engine#45919)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from wWzXsy6kx1sp to ZhY53WD7bFJS
  fuchsia/sdk/core/mac-amd64 from -_edKGA5GTkD to 3Tb9CQTTiBv1

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 bdero@google.com,rmistry@google.com,zra@google.com 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
@matanlurey matanlurey deleted the impeller-command-pool-vk-recycle branch September 19, 2023 16:44
Mairramer pushed a commit to Mairramer/flutter that referenced this pull request Oct 10, 2023
…ions) (flutter#134882)

Manual roll requested by zra@google.com

flutter/engine@4909256...8c2203b

2023-09-16 skia-flutter-autoroll@skia.org Roll Skia from b33e0e6706b0 to 2eaaa5bf7dae (1 revision) (flutter/engine#45926)
2023-09-16 skia-flutter-autoroll@skia.org Roll Skia from a1f8fb54299a to b33e0e6706b0 (1 revision) (flutter/engine#45923)
2023-09-16 skia-flutter-autoroll@skia.org Roll Fuchsia Mac SDK from -_edKGA5GTkDFxVgl... to 3Tb9CQTTiBv1lb673... (flutter/engine#45922)
2023-09-16 skia-flutter-autoroll@skia.org Roll Dart SDK from 029d6d73c860 to a0ca39c63c16 (1 revision) (flutter/engine#45921)
2023-09-16 matanlurey@users.noreply.github.com [Impeller] `vk::CommandPool` resets via `ResourceManager` (flutter/engine#45654)
2023-09-16 skia-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from wWzXsy6kx1sp8Km34... to ZhY53WD7bFJSA3xoO... (flutter/engine#45919)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from wWzXsy6kx1sp to ZhY53WD7bFJS
  fuchsia/sdk/core/mac-amd64 from -_edKGA5GTkD to 3Tb9CQTTiBv1

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 bdero@google.com,rmistry@google.com,zra@google.com 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://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
harryterkelsen pushed a commit that referenced this pull request Oct 23, 2023
Fixes flutter/flutter#133198.

Major changes:

- `CommandPoolVK` is now created indirectly through `CommandPoolRecyclerVK`.
- Via destructor, `CommandPoolVK` resets on a background thread via `ResourceManager`.
- Removed all of the code trying to reuse/reset individual command buffers (no longer needed).
- After every frame, the current/active command pool is recycled.

---

_Tests secured._
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] Follow CmdPool best practices from ARM documentation.
3 participants