[Impeller] Don't perform final layout transition on worker thread. (flutter/engine#44510)

This can lead to https://github.com/flutter/flutter/issues/131717 because the raster thread may access the Queue while the worker thread is doing the final layout transition. Moving the final layout transition back to the raster thread should be fine, its really the presentation that we want to run in a background worker.

Fixes https://github.com/flutter/flutter/issues/131717
This commit is contained in:
Jonah Williams
2023-08-09 08:43:52 -07:00
committed by GitHub
parent af50beefbe
commit 31c639e955

View File

@@ -392,65 +392,66 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
}
const auto& context = ContextVK::Cast(*context_strong);
const auto& sync = synchronizers_[current_frame_];
//----------------------------------------------------------------------------
/// Transition the image to color-attachment-optimal.
///
sync->final_cmd_buffer = context.CreateCommandBuffer();
if (!sync->final_cmd_buffer) {
return false;
}
auto vk_final_cmd_buffer = CommandBufferVK::Cast(*sync->final_cmd_buffer)
.GetEncoder()
->GetCommandBuffer();
{
BarrierVK barrier;
barrier.new_layout = vk::ImageLayout::ePresentSrcKHR;
barrier.cmd_buffer = vk_final_cmd_buffer;
barrier.src_access = vk::AccessFlagBits::eColorAttachmentWrite;
barrier.src_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput;
barrier.dst_access = {};
barrier.dst_stage = vk::PipelineStageFlagBits::eBottomOfPipe;
if (!image->SetLayout(barrier)) {
return false;
}
if (vk_final_cmd_buffer.end() != vk::Result::eSuccess) {
return false;
}
}
//----------------------------------------------------------------------------
/// Signal that the presentation semaphore is ready.
///
{
vk::SubmitInfo submit_info;
vk::PipelineStageFlags wait_stage =
vk::PipelineStageFlagBits::eColorAttachmentOutput;
submit_info.setWaitDstStageMask(wait_stage);
submit_info.setWaitSemaphores(*sync->render_ready);
submit_info.setSignalSemaphores(*sync->present_ready);
submit_info.setCommandBuffers(vk_final_cmd_buffer);
auto result =
context.GetGraphicsQueue()->Submit(submit_info, *sync->acquire);
if (result != vk::Result::eSuccess) {
VALIDATION_LOG << "Could not wait on render semaphore: "
<< vk::to_string(result);
return false;
}
}
context.GetConcurrentWorkerTaskRunner()->PostTask(
[&, index, image, current_frame = current_frame_] {
auto context_strong = context_.lock();
if (!context_strong) {
return;
}
const auto& context = ContextVK::Cast(*context_strong);
const auto& sync = synchronizers_[current_frame];
//----------------------------------------------------------------------------
/// Transition the image to color-attachment-optimal.
///
sync->final_cmd_buffer = context.CreateCommandBuffer();
if (!sync->final_cmd_buffer) {
return;
}
auto vk_final_cmd_buffer =
CommandBufferVK::Cast(*sync->final_cmd_buffer)
.GetEncoder()
->GetCommandBuffer();
{
BarrierVK barrier;
barrier.new_layout = vk::ImageLayout::ePresentSrcKHR;
barrier.cmd_buffer = vk_final_cmd_buffer;
barrier.src_access = vk::AccessFlagBits::eColorAttachmentWrite;
barrier.src_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput;
barrier.dst_access = {};
barrier.dst_stage = vk::PipelineStageFlagBits::eBottomOfPipe;
if (!image->SetLayout(barrier)) {
return;
}
if (vk_final_cmd_buffer.end() != vk::Result::eSuccess) {
return;
}
}
//----------------------------------------------------------------------------
/// Signal that the presentation semaphore is ready.
///
{
vk::SubmitInfo submit_info;
vk::PipelineStageFlags wait_stage =
vk::PipelineStageFlagBits::eColorAttachmentOutput;
submit_info.setWaitDstStageMask(wait_stage);
submit_info.setWaitSemaphores(*sync->render_ready);
submit_info.setSignalSemaphores(*sync->present_ready);
submit_info.setCommandBuffers(vk_final_cmd_buffer);
auto result =
context.GetGraphicsQueue()->Submit(submit_info, *sync->acquire);
if (result != vk::Result::eSuccess) {
VALIDATION_LOG << "Could not wait on render semaphore: "
<< vk::to_string(result);
return;
}
}
//----------------------------------------------------------------------------
/// Present the image.
///