Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 197843d0 authored by Stan Iliev's avatar Stan Iliev
Browse files

Block GPU on dequeue fence only if it has not signalled already

When Vulkan pipeline dequeues next frame at the beginning of
DrawFrame, the dequeue fence has been signalled in most cases.
This CL avoids additional work and saves about 0.3ms per frame.
There is no need to create VkSemaphore and commit an empty command
buffer to the queue if the fence has already signalled.

Bug: 128998567
Test: Ran systrace on SelfieCity and observed better performance
Change-Id: I3532b785fae90308d922a29f1698f5dbcbd79079
parent 3e99fa7a
Loading
Loading
Loading
Loading
+41 −32
Original line number Diff line number Diff line
@@ -439,9 +439,17 @@ Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) {
    LOG_ALWAYS_FATAL_IF(!bufferInfo->dequeued);

    if (bufferInfo->dequeue_fence != -1) {
        struct sync_file_info* finfo = sync_file_info(bufferInfo->dequeue_fence);
        bool isSignalPending = false;
        if (finfo != NULL) {
            isSignalPending = finfo->status != 1;
            sync_file_info_free(finfo);
        }
        if (isSignalPending) {
            int fence_clone = dup(bufferInfo->dequeue_fence);
            if (fence_clone == -1) {
            ALOGE("dup(fence) failed, stalling until signalled: %s (%d)", strerror(errno), errno);
                ALOGE("dup(fence) failed, stalling until signalled: %s (%d)", strerror(errno),
                      errno);
                sync_wait(bufferInfo->dequeue_fence, -1 /* forever */);
            } else {
                VkSemaphoreCreateInfo semaphoreInfo;
@@ -473,6 +481,7 @@ Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) {
                bufferInfo->skSurface->flush();
            }
        }
    }

    int bufferAge = (mSwapBehavior == SwapBehavior::Discard) ? 0 : surface->getCurrentBuffersAge();
    return Frame(surface->logicalWidth(), surface->logicalHeight(), bufferAge);