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

Conversation

@gaaclarke
Copy link
Member

@gaaclarke gaaclarke commented May 17, 2023

fixes flutter/flutter#127058

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • 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.
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt. See testing the engine for instructions on writing and running engine tests.
  • I updated/added relevant documentation (doc comments with ///).
  • I signed the CLA.
  • All existing and new tests are passing.

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

@gaaclarke gaaclarke changed the title Cleanup vk cleanup [Impeller] made other vulkan objects cleanup properly May 17, 2023
@gaaclarke gaaclarke force-pushed the cleanup-vk-cleanup branch from 80422ed to 75db280 Compare May 17, 2023 23:52
@jason-simmons
Copy link
Member

ContextVK::Setup is constructing all of the context objects locally and moving them into the instance's members only if setup is successful.

But I'm wondering whether that is necessary given that Setup is private and is only called by ContextVK::Create. Setup could instead initialize each member directly and ensure that the members used by DeviceHolder are populated before a weak_ptr<DeviceHolder> is given to any other object.

If Setup fails, then Create will discard the incomplete ContextVK and any members that were initialized will be destructed.

@chinmaygarde chinmaygarde changed the title [Impeller] made other vulkan objects cleanup properly [Impeller] Made other vulkan objects cleanup properly. May 18, 2023
@gaaclarke gaaclarke force-pushed the cleanup-vk-cleanup branch from 75db280 to 2e89d03 Compare May 18, 2023 20:32
@gaaclarke
Copy link
Member Author

If Setup fails, then Create will discard the incomplete ContextVK and any members that were initialized will be destructed.

I was just trying to preserve the old logic but I think you are right. I'll get rid of that smart pointer that resets the instance variable before review.

@gaaclarke gaaclarke force-pushed the cleanup-vk-cleanup branch from d9a07d6 to 44b35d1 Compare May 18, 2023 21:44
@gaaclarke
Copy link
Member Author

I'm still running into trouble getting the tests to run on CI. They run fine locally but crash with no warning on CI. I'm trying turning on debug build runs of the tests too to see if they give more information. I'm noticing that the bots are x86, so maybe that is the x-factor that makes the tests crash.

@gaaclarke gaaclarke force-pushed the cleanup-vk-cleanup branch from dce5026 to f7859be Compare May 19, 2023 00:59
@gaaclarke gaaclarke marked this pull request as ready for review May 19, 2023 01:00
@gaaclarke gaaclarke requested a review from jason-simmons May 19, 2023 01:00
vk::UniqueDevice device = std::move(device_result.value);

// Make sure this ivar is set before handing out DeviceHolder references.
device_ = std::move(device_result.value);
Copy link
Member

Choose a reason for hiding this comment

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

Set every ContextVK member as it is created in Setup instead of setting all of the members at the end of the method.

If Setup fails, then this will ensure that the ContextVK destructor deletes the objects in the proper order. In particular, objects tied to the device should be deleted before the device, and the Vulkan instance should be deleted last.

Copy link
Member Author

Choose a reason for hiding this comment

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

Refactor code that doesn't have to do with the change? I'd rather do that as a followup PR if you want.

Copy link
Member

Choose a reason for hiding this comment

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

It's related to this change - in the current version of this PR if Setup exits early it will set device_ in ContextVK but not any other members.

In particular, instance_ is not set by Setup until the end. So if a failure happens during Setup, the instance local to Setup will be destroyed but device_ will not be destroyed until the ContextVK is destructed.

IIUC it's unsafe to call a Vulkan API like vkDestroyDevice if the instance used to create the device has already been destroyed. So I think it would be safest to set all the ContextVK members as they are created and then rely on the ContextVK destructor to delete the context's Vulkan objects in the correct order.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, good observation. That requires that the ivars of the context are in the correct order in the header which at least for the device and instance is the case. It also means the that the order in which the ivars are set in Setup is meaningful. If we space it out across this whole method, it would be easy to get wrong. I'm back to liking the resetter on the stack that I had at first. It makes it easy to verify the order and is the least invasive to what we already have.

I'm just seeing that you are out of office. Let's go over our options when you get back.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thinking about it, if the order of the ivars is wrong, then the order on the stack would be wrong too. So that doesn't solve the problem. I don't think there is a way you can guarantee this code is safe to all failures. Your proposal is better than what it is now though. I'll make the change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Starting to implement it, I don't like it since on line X we initialize an instance variable and line X+100 we use it. It isn't clear that that instance variable has been initialized at X+100. By using values on the stack and initializing them when we create them we can't get them out of order. Let's chat when you get back.

Copy link
Member

Choose a reason for hiding this comment

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

There is no way to make this completely foolproof.

But I think the requirement that a constructor must initialize members before it uses them later is well understood. It will be more familiar to readers of the code than the scoped_reset class and the requirement to call release() on the scoped_reset at the right time.

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 got rid of the special smart pointer and moved resetting the ivar to a std::unique_ptr. I think you'll find that preferable.

But I think the requirement that a constructor must initialize members before it uses them later is well understood.

It's not that it's not understood, it's impossible to verify when looking at the code without scrolling around because the method is so large.

It will be more familiar to readers of the code than the scoped_reset class and the requirement to call release() on the scoped_reset at the right time.

The nice thing is that they don't have the release, the tests will fail. The order of the release isn't super important as long as it remains in the same spot since the chances of errors in that block of code where all the ivars is getting set is practically zero (possibly zero, i didn't look up std::optional::value or std::string::string's signatures).

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks Jason. I have a followup draft PR that will expand the functionality of mock vulkan so that we can assert the behavior when there is an error at setup.

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 give up, I can't make Setup fail because in practice we abort if there is any vulkan error. 🤷


auto sampler_library =
std::shared_ptr<SamplerLibraryVK>(new SamplerLibraryVK(device.get()));
std::shared_ptr<SamplerLibraryVK>(new SamplerLibraryVK(device_.get()));
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 didn't look into it but, I suspect this guy and the FenceWaiterVK may need device holders too.

@gaaclarke gaaclarke requested a review from jason-simmons May 19, 2023 18:29
device_ = std::move(device_result.value);
// This makes sure that the device is deleted at the proper time if there is
// an error.
std::unique_ptr<vk::UniqueDevice, std::function<void(vk::UniqueDevice*)>>
Copy link
Member

Choose a reason for hiding this comment

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

Use fml::ScopedCleanupClosure here

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label May 19, 2023
@auto-submit auto-submit bot merged commit 90b44e3 into flutter:main May 20, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 20, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 20, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 21, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 21, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request May 21, 2023
zanderso pushed a commit to flutter/flutter that referenced this pull request May 22, 2023
…127292)

flutter/engine@aac0919...f0f3fe7

2023-05-21 [email protected] Roll Skia from 7c7dff949a27 to
5b2005e47bf3 (1 revision) (flutter/engine#42199)
2023-05-21 [email protected] Roll Fuchsia Linux SDK from
gQ989rlKAuTJHQR-C... to 88pzkUAkSKsJrNG38... (flutter/engine#42198)
2023-05-21 [email protected] Roll Fuchsia Mac SDK from
868_67npyO8nD_JCx... to JU-dKW3CQIUzhbqWE... (flutter/engine#42197)
2023-05-21 [email protected] Roll Skia from a60bfcb01af9 to
7c7dff949a27 (1 revision) (flutter/engine#42195)
2023-05-20 [email protected] Roll Fuchsia Linux SDK from
c_fRDyBVZX-MwW5fS... to gQ989rlKAuTJHQR-C... (flutter/engine#42194)
2023-05-20 [email protected] Roll Skia from f3e9cb7d37fd to
a60bfcb01af9 (1 revision) (flutter/engine#42193)
2023-05-20 [email protected] Roll Fuchsia Mac SDK from
sfLkc5VBFU6UkljF6... to 868_67npyO8nD_JCx... (flutter/engine#42191)
2023-05-20 [email protected] Move SkSurface::MakeNull to
SkSurfaces::Null (flutter/engine#42158)
2023-05-20 [email protected] Roll Fuchsia Linux SDK from
TWjmvLCOnYAUgAzvT... to c_fRDyBVZX-MwW5fS... (flutter/engine#42189)
2023-05-20 [email protected] Roll Skia from b4a4782cf89d to
f3e9cb7d37fd (1 revision) (flutter/engine#42188)
2023-05-20 [email protected] Roll Fuchsia Mac SDK from
pwdDQgM88sqLmZczj... to sfLkc5VBFU6UkljF6... (flutter/engine#42187)
2023-05-20 [email protected] Roll Skia from 7202b405f061 to
b4a4782cf89d (19 revisions) (flutter/engine#42185)
2023-05-20 [email protected] [Impeller] avoid creating multiple
concurrent message loops for Andorid Vulkan (flutter/engine#42146)
2023-05-20 [email protected] Implement
`ImageFilter`/`ColorFilter`/`MaskFilter` in Skwasm
(flutter/engine#42088)
2023-05-20 [email protected] [Impeller] Made
other vulkan objects cleanup properly. (flutter/engine#42113)
2023-05-19 [email protected] [Impeller] Fix the issue that
'coverage_coords' is incorrectly calculated in
'FillPathGeometry::GetPositionUVBuffer' (flutter/engine#42155)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from TWjmvLCOnYAU to 88pzkUAkSKsJ
  fuchsia/sdk/core/mac-amd64 from pwdDQgM88sqL to JU-dKW3CQIUz

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://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
CaseyHillers pushed a commit to CaseyHillers/flutter that referenced this pull request May 24, 2023
…lutter#127292)

flutter/engine@aac0919...f0f3fe7

2023-05-21 [email protected] Roll Skia from 7c7dff949a27 to
5b2005e47bf3 (1 revision) (flutter/engine#42199)
2023-05-21 [email protected] Roll Fuchsia Linux SDK from
gQ989rlKAuTJHQR-C... to 88pzkUAkSKsJrNG38... (flutter/engine#42198)
2023-05-21 [email protected] Roll Fuchsia Mac SDK from
868_67npyO8nD_JCx... to JU-dKW3CQIUzhbqWE... (flutter/engine#42197)
2023-05-21 [email protected] Roll Skia from a60bfcb01af9 to
7c7dff949a27 (1 revision) (flutter/engine#42195)
2023-05-20 [email protected] Roll Fuchsia Linux SDK from
c_fRDyBVZX-MwW5fS... to gQ989rlKAuTJHQR-C... (flutter/engine#42194)
2023-05-20 [email protected] Roll Skia from f3e9cb7d37fd to
a60bfcb01af9 (1 revision) (flutter/engine#42193)
2023-05-20 [email protected] Roll Fuchsia Mac SDK from
sfLkc5VBFU6UkljF6... to 868_67npyO8nD_JCx... (flutter/engine#42191)
2023-05-20 [email protected] Move SkSurface::MakeNull to
SkSurfaces::Null (flutter/engine#42158)
2023-05-20 [email protected] Roll Fuchsia Linux SDK from
TWjmvLCOnYAUgAzvT... to c_fRDyBVZX-MwW5fS... (flutter/engine#42189)
2023-05-20 [email protected] Roll Skia from b4a4782cf89d to
f3e9cb7d37fd (1 revision) (flutter/engine#42188)
2023-05-20 [email protected] Roll Fuchsia Mac SDK from
pwdDQgM88sqLmZczj... to sfLkc5VBFU6UkljF6... (flutter/engine#42187)
2023-05-20 [email protected] Roll Skia from 7202b405f061 to
b4a4782cf89d (19 revisions) (flutter/engine#42185)
2023-05-20 [email protected] [Impeller] avoid creating multiple
concurrent message loops for Andorid Vulkan (flutter/engine#42146)
2023-05-20 [email protected] Implement
`ImageFilter`/`ColorFilter`/`MaskFilter` in Skwasm
(flutter/engine#42088)
2023-05-20 [email protected] [Impeller] Made
other vulkan objects cleanup properly. (flutter/engine#42113)
2023-05-19 [email protected] [Impeller] Fix the issue that
'coverage_coords' is incorrectly calculated in
'FillPathGeometry::GetPositionUVBuffer' (flutter/engine#42155)

Also rolling transitive DEPS:
  fuchsia/sdk/core/linux-amd64 from TWjmvLCOnYAU to 88pzkUAkSKsJ
  fuchsia/sdk/core/mac-amd64 from pwdDQgM88sqL to JU-dKW3CQIUz

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://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
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] Vulkan unit tests crash in vkDestroyDescriptorSetLayout

3 participants