Skip to content

Commit d4717bd

Browse files
authored
[Impeller] Joined obligatory vulkan swapchain submits (flutter#42865)
Every frame we submit to the queue a layout transition and a notify to the `acquire` fence. This joins those together into one `vkQueueSubmit` call. Thus eliminating a fence that was happening after the layout transition. issue flutter#128838 ## testing results from the gallery driver test ``` Before: "average_frame_build_time_millis": 1.379130952380952, "90th_percentile_frame_build_time_millis": 1.965, "99th_percentile_frame_build_time_millis": 20.246, "worst_frame_build_time_millis": 29.578, "missed_frame_build_budget_count": 7, "average_frame_rasterizer_time_millis": 20.447408955223867, "90th_percentile_frame_rasterizer_time_millis": 25.398, "99th_percentile_frame_rasterizer_time_millis": 160.198, "worst_frame_rasterizer_time_millis": 178.042, "missed_frame_rasterizer_budget_count": 122, "frame_count": 336, "frame_rasterizer_count": 335, "new_gen_gc_count": 0, "old_gen_gc_count": 0, "frame_build_times": [ after: "average_frame_build_time_millis": 1.1907232876712324, "90th_percentile_frame_build_time_millis": 1.926, "99th_percentile_frame_build_time_millis": 16.666, "worst_frame_build_time_millis": 27.39, "missed_frame_build_budget_count": 5, "average_frame_rasterizer_time_millis": 15.525100817438704, "90th_percentile_frame_rasterizer_time_millis": 20.116, "99th_percentile_frame_rasterizer_time_millis": 33.835, "worst_frame_rasterizer_time_millis": 56.075, "missed_frame_rasterizer_budget_count": 156, "frame_count": 365, "frame_rasterizer_count": 367, "new_gen_gc_count": 0, "old_gen_gc_count": 0, ``` [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
1 parent fb5fed4 commit d4717bd

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

impeller/renderer/backend/vulkan/swapchain_impl_vk.cc

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct FrameSynchronizer {
1919
vk::UniqueFence acquire;
2020
vk::UniqueSemaphore render_ready;
2121
vk::UniqueSemaphore present_ready;
22+
std::shared_ptr<CommandBuffer> final_cmd_buffer;
2223
bool is_valid = false;
2324

2425
explicit FrameSynchronizer(const vk::Device& device) {
@@ -382,18 +383,18 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
382383
//----------------------------------------------------------------------------
383384
/// Transition the image to color-attachment-optimal.
384385
///
385-
{
386-
auto cmd_buffer = context.CreateCommandBuffer();
387-
if (!cmd_buffer) {
388-
return false;
389-
}
390-
391-
auto vk_cmd_buffer =
392-
CommandBufferVK::Cast(*cmd_buffer).GetEncoder()->GetCommandBuffer();
386+
sync->final_cmd_buffer = context.CreateCommandBuffer();
387+
if (!sync->final_cmd_buffer) {
388+
return false;
389+
}
393390

391+
auto vk_final_cmd_buffer = CommandBufferVK::Cast(*sync->final_cmd_buffer)
392+
.GetEncoder()
393+
->GetCommandBuffer();
394+
{
394395
LayoutTransition transition;
395396
transition.new_layout = vk::ImageLayout::ePresentSrcKHR;
396-
transition.cmd_buffer = vk_cmd_buffer;
397+
transition.cmd_buffer = vk_final_cmd_buffer;
397398
transition.src_access = vk::AccessFlagBits::eColorAttachmentWrite;
398399
transition.src_stage = vk::PipelineStageFlagBits::eColorAttachmentOutput;
399400
transition.dst_access = {};
@@ -403,7 +404,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
403404
return false;
404405
}
405406

406-
if (!cmd_buffer->SubmitCommands()) {
407+
if (vk_final_cmd_buffer.end() != vk::Result::eSuccess) {
407408
return false;
408409
}
409410
}
@@ -418,6 +419,7 @@ bool SwapchainImplVK::Present(const std::shared_ptr<SwapchainImageVK>& image,
418419
submit_info.setWaitDstStageMask(wait_stage);
419420
submit_info.setWaitSemaphores(*sync->render_ready);
420421
submit_info.setSignalSemaphores(*sync->present_ready);
422+
submit_info.setCommandBuffers(vk_final_cmd_buffer);
421423
auto result =
422424
context.GetGraphicsQueue()->Submit(submit_info, *sync->acquire);
423425
if (result != vk::Result::eSuccess) {

0 commit comments

Comments
 (0)