@@ -37,9 +37,15 @@ SurfaceTextureExternalTextureVKImpeller::
3737SurfaceTextureExternalTextureVKImpeller::
3838 ~SurfaceTextureExternalTextureVKImpeller () = default ;
3939
40- static bool SetTextureLayoutSync (const ContextVK& context,
41- const TextureSourceVK* texture,
42- vk::ImageLayout layout) {
40+ enum class LayoutUpdateMode {
41+ kSync ,
42+ kAsync ,
43+ };
44+
45+ static bool SetTextureLayout (const ContextVK& context,
46+ const TextureSourceVK* texture,
47+ vk::ImageLayout layout,
48+ LayoutUpdateMode mode) {
4349 TRACE_EVENT0 (" flutter" , __FUNCTION__);
4450 if (!texture) {
4551 return true ;
@@ -76,24 +82,32 @@ static bool SetTextureLayoutSync(const ContextVK& context,
7682
7783 // There is no need to track the fence in the encoder since we are going to do
7884 // a sync wait for completion.
79- auto fence = context.GetDevice ().createFenceUnique (vk::FenceCreateFlags{});
80- if (fence.result != impeller::vk::Result::eSuccess) {
81- VALIDATION_LOG << " Could not create fence." ;
82- return false ;
85+ vk::UniqueFence fence;
86+
87+ if (mode == LayoutUpdateMode::kSync ) {
88+ auto fence_pair =
89+ context.GetDevice ().createFenceUnique (vk::FenceCreateFlags{});
90+ if (fence_pair.result != impeller::vk::Result::eSuccess) {
91+ VALIDATION_LOG << " Could not create fence." ;
92+ return false ;
93+ }
94+ fence = std::move (fence_pair.value );
8395 }
8496
85- if (context.GetGraphicsQueue ()->Submit (submit_info, fence.value . get ()) !=
97+ if (context.GetGraphicsQueue ()->Submit (submit_info, fence.get ()) !=
8698 impeller::vk::Result::eSuccess) {
8799 VALIDATION_LOG << " Could not submit layout transition fence." ;
88100 return false ;
89101 }
90102
91103 using namespace std ::chrono_literals;
92104
93- if (context.GetDevice ().waitForFences (
94- fence.value .get (), VK_TRUE,
95- std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count ()) !=
96- impeller::vk::Result::eSuccess) {
105+ if (fence &&
106+ context.GetDevice ().waitForFences (
107+ fence.get (), //
108+ VK_TRUE, //
109+ std::chrono::duration_cast<std::chrono::nanoseconds>(1s).count () //
110+ ) != impeller::vk::Result::eSuccess) {
97111 VALIDATION_LOG << " Could not perform sync wait on fence." ;
98112 return false ;
99113 }
@@ -130,8 +144,9 @@ void SurfaceTextureExternalTextureVKImpeller::ProcessFrame(
130144 Attach (src_gl_texture);
131145 Update ();
132146
133- SetTextureLayoutSync (context_vk, dst_texture.get (),
134- vk::ImageLayout::eColorAttachmentOptimal);
147+ SetTextureLayout (context_vk, dst_texture.get (),
148+ vk::ImageLayout::eColorAttachmentOptimal,
149+ LayoutUpdateMode::kSync );
135150
136151 SkM44 transformation (GetCurrentUVTransformation ());
137152 impeller::Matrix uv_transformation;
@@ -146,8 +161,9 @@ void SurfaceTextureExternalTextureVKImpeller::ProcessFrame(
146161 VALIDATION_LOG << " Texture copy failed." ;
147162 }
148163
149- SetTextureLayoutSync (context_vk, dst_texture.get (),
150- vk::ImageLayout::eShaderReadOnlyOptimal);
164+ SetTextureLayout (context_vk, dst_texture.get (),
165+ vk::ImageLayout::eShaderReadOnlyOptimal,
166+ LayoutUpdateMode::kAsync );
151167
152168 glDeleteTextures (1u , &src_gl_texture);
153169
0 commit comments