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

[metal] Darwin unified external metal textures #24157

Merged

Conversation

iskakaushik
Copy link
Contributor

No description provided.

@google-cla google-cla bot added the cla: yes label Feb 3, 2021
@iskakaushik iskakaushik marked this pull request as ready for review February 3, 2021 17:52
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

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.

I have a few doubts about the memory management of certain CF objects. Other than that, I only eyeballed the code that was moved which look fine to me.

@@ -7,19 +7,23 @@ assert(is_ios || is_mac)
import("//flutter/common/config.gni")

source_set("graphics") {
cflags_objc = flutter_cflags_objc
cflags_objcc = flutter_cflags_objcc
cflags_objcc = [ "-fobjc-arc" ]
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be in addition to the flutter_cflags_objc? I am not sure what those flags currently are but we are no longer applying them to this target.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that the other targets that enable arc, only had this will verify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created a new high level param for arc targets and unified it.

@@ -33,32 +33,39 @@ - (instancetype)initWithMTLDevice:(id<MTLDevice>)device

if (!_device) {
FML_DLOG(ERROR) << "Could not acquire Metal device.";
[self release];
return nil;
Copy link
Member

Choose a reason for hiding this comment

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

Can we decorate translation units with FLUTTER_ASSERT_ARC and FLUTTER_ASSERT_NON_ARC now that we are mixing the two in the engine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added it to the ARC targets that i've touched.

/**
* Creates an external texture with the specified ID and contents.
*/
- (FlutterDarwinExternalTextureMetal*)externalTextureWithID:(int64_t)textureID
Copy link
Member

Choose a reason for hiding this comment

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

IMO createExternalTexture:withIdentifier: seems more idiomatic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

nil, // cache attributes (nil default)
_device, // metal device
nil, // texture attributes (nil default)
&_textureCache // [out] cache
Copy link
Member

Choose a reason for hiding this comment

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

CoreFoundation objects need to be explicitly released. IIRC, this would leak the texture cache in the dealloc unless __bridge_transfered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was worried about the same. I will try to add a test to see that everything that was allocated gets collected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't able to come up with a way to test de-alloc in a nice way. I audited the code and made sure that are CoreFoundation objects are released and retained as necessary.

textureID:(int64_t)textureID
texture:(NSObject<FlutterTexture>*)texture {
if (self = [super init]) {
_textureCache = textureCache;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this missing a CFRetain and subsequent release in the dealloc? We might end up with a dangling reference otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

if (needsUpdatedTexture) {
CVPixelBufferRef pixelBuffer = [_externalTexture copyPixelBuffer];
if (!pixelBuffer) {
pixelBuffer = std::move(_lastPixelBuffer);
Copy link
Member

Choose a reason for hiding this comment

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

What does std::move with ARC even do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't make sense :-) I've used CVPixelBufferRetain and CVPixelBufferRelease as needed.

@iskakaushik iskakaushik added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Feb 4, 2021
@fluttergithubbot fluttergithubbot merged commit 6a2df7f into flutter:master Feb 4, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 4, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 4, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 5, 2021
zanderso added a commit that referenced this pull request Feb 5, 2021
iskakaushik pushed a commit that referenced this pull request Feb 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 5, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Feb 5, 2021
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Feb 5, 2021
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Feb 5, 2021
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Feb 10, 2021
iskakaushik added a commit to iskakaushik/engine that referenced this pull request Feb 11, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
hjfreyer pushed a commit to hjfreyer/engine that referenced this pull request Mar 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes platform-ios waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants