Correctly wait in the fragment stage until all semaphores are signaled
authorGeorg Lehmann <dadschoorse@gmail.com>
Wed, 5 Feb 2020 18:06:55 +0000 (18:06 +0000)
committerGeorg Lehmann <dadschoorse@gmail.com>
Thu, 6 Feb 2020 15:16:47 +0000 (15:16 +0000)
This fixes two issues:
- a crash if the application uses more than one semaphore for presenting because the driver expects one stage per semaphore
- the swapchain image could be not ready yet if the semaphores aren't signaled, #946 is possible related

Cc: <mesa-stable@lists.freedesktop.org>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3718>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3718>

src/vulkan/overlay-layer/overlay.cpp

index 6ec2f05826a1b51aea42d23ffffe0275819aef13..36fb96f144498985bf98b1699d94d235c2d69b11 100644 (file)
@@ -1344,18 +1344,26 @@ static struct overlay_draw *render_swapchain_display(struct swapchain_data *data
 
    device_data->vtable.EndCommandBuffer(draw->command_buffer);
 
 
    device_data->vtable.EndCommandBuffer(draw->command_buffer);
 
+   VkPipelineStageFlags *stages_wait = (VkPipelineStageFlags*) malloc(sizeof(VkPipelineStageFlags) * n_wait_semaphores);
+   for (unsigned i = 0; i < n_wait_semaphores; i++)
+   {
+      // wait in the fragment stage until the swapchain image is ready
+      stages_wait[i] = VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
+   }
+   
    VkSubmitInfo submit_info = {};
    VkSubmitInfo submit_info = {};
-   VkPipelineStageFlags stage_wait = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
    submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
    submit_info.commandBufferCount = 1;
    submit_info.pCommandBuffers = &draw->command_buffer;
    submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
    submit_info.commandBufferCount = 1;
    submit_info.pCommandBuffers = &draw->command_buffer;
-   submit_info.pWaitDstStageMask = &stage_wait;
+   submit_info.pWaitDstStageMask = stages_wait;
    submit_info.waitSemaphoreCount = n_wait_semaphores;
    submit_info.pWaitSemaphores = wait_semaphores;
    submit_info.signalSemaphoreCount = 1;
    submit_info.pSignalSemaphores = &draw->semaphore;
 
    device_data->vtable.QueueSubmit(device_data->graphic_queue->queue, 1, &submit_info, draw->fence);
    submit_info.waitSemaphoreCount = n_wait_semaphores;
    submit_info.pWaitSemaphores = wait_semaphores;
    submit_info.signalSemaphoreCount = 1;
    submit_info.pSignalSemaphores = &draw->semaphore;
 
    device_data->vtable.QueueSubmit(device_data->graphic_queue->queue, 1, &submit_info, draw->fence);
+   
+   free(stages_wait);
 
    return draw;
 }
 
    return draw;
 }