-
Notifications
You must be signed in to change notification settings - Fork 6k
Allow external texture sources when using the Metal backend. #17154
Allow external texture sources when using the Metal backend. #17154
Conversation
72a015e
to
ead5edd
Compare
e353f09
to
520383c
Compare
As c0deb23 has landed, this is good to go. All existing plugins that composite external textures have been tested to work with the Metal backend without modification. |
This pull request is not suitable for automatic merging in its current state.
|
@@ -36,14 +51,20 @@ class CFRef { | |||
instance_ = instance; | |||
} | |||
|
|||
[[nodiscard]] T Release() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we on C++ 17 everywhere we have to compile? Particularly google3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
@@ -34,6 +35,19 @@ | |||
return; | |||
} | |||
|
|||
CVMetalTextureCacheRef texture_cache_raw = NULL; | |||
auto cv_return = CVMetalTextureCacheCreate(kCFAllocatorDefault, // allocator | |||
NULL, // cache attributes (NULL default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang format doesn't line these up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently not. I don't format code so its got to be clang-format
. I think its because the comments are pushed up against the column limit.
&texture_cache_raw // [out] cache | ||
); | ||
if (cv_return != kCVReturnSuccess) { | ||
FML_LOG(ERROR) << "Could not create Metal texture cache."; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this mean for a Flutter developer? What action should be taken if any?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah. Docs are woefully lacking here, apparently it just documents that when it succeeds it returns this and nothing else... https://developer.apple.com/documentation/corevideo/1456774-cvmetaltexturecachecreate?language=objc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this really be FML_DLOG?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What action should be taken if any?
If I saw that in the a bug report, I'd know immediately where what went wrong and where. If a user filed an error for this with no logs, I probably wouldn't find the cause unless I reproduced the issue and set various breakpoint (if the issue caught my attention at all).
I am on the fence about its use. Probably means I should just get rid of it. Patching.
// External images in this backend have no thread affinity and are not tied to the context in any | ||
// way. Instead, they are tied to the Metal device which is associated with the cache already and | ||
// is consistent throughout the shell run. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exciting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with nit about logging. If a developer can take action on it,w e should clarify what action to take - otherwise we should probably make a DLOG.
This patch moves the responsibility of vending external texture proxies to the client rendering API specific IOS context subclasses. Some key changes in the Metal backend compared to OpenGL. * The Metal backend has a single texture cache for all external textures as opposed to a separate cache for each texture proxy in the OpenGL backend. This use is more desirable as cached entries may be reused by multiple proxies for better cache utilization. This implementation is harder in the OpenGL backend because the cache cannot be created upfront as thread local state is needed to (re)initialize the cache. This update can be made to the OpenGL backend as well but it is unrelated to the primary purpose of this patch. * Attempting to use external textures with the software backend now logs a single message to the console that this feature is only available when using the Metal or OpenGL backend on devices. Previously, an OpenGL texture proxy creation would be attempted and it would fail in an undefined spot internally with a confusing message. * The OpenGL backend seems to conflate rendering size with paint size. This puts the unnecessary limitation that the embedders must provide textures at the size at which they will be rendered. This limitation has been lifted in the Metal backend and should probably be lifted in the OpenGL backend as well (in a later patch). There are opportunities to dry up the implementations of the `IOSExternalTextureMetal` and `IOSExternalTextureGL` but that refactor can be attempted separately. Fixes flutter/flutter#41819
520383c
to
453d6a3
Compare
This is unlikely for anything in these components. I converted everything to DLOG. |
Allow external texture sources when using the Metal backend.
This patch moves the responsibility of vending external texture proxies to the
client rendering API specific IOS context subclasses.
Some key changes in the Metal backend compared to OpenGL.
opposed to a separate cache for each texture proxy in the OpenGL backend. This
use is more desirable as cached entries may be reused by multiple proxies for
better cache utilization. This implementation is harder in the OpenGL backend
because the cache cannot be created upfront as thread local state is needed to
(re)initialize the cache. This update can be made to the OpenGL backend as
well but it is unrelated to the primary purpose of this patch.
single message to the console that this feature is only available when using
the Metal or OpenGL backend on devices. Previously, an OpenGL texture proxy
creation would be attempted and it would fail in an undefined spot internally
with a confusing message.
the unnecessary limitation that the embedders must provide textures at the
size at which they will be rendered. This limitation has been lifted in the
Metal backend and should probably be lifted in the OpenGL backend as well (in
a later patch).
There are opportunities to dry up the implementations of the
IOSExternalTextureMetal
andIOSExternalTextureGL
but that refactor can beattempted separately.
Fixes flutter/flutter#41819