Optimization for fence on queue submit

If there is at least one command buffer, we don't need
to send an additional command buffer to signal the fence.

This restores performance lost due to the cube throttling
change associated with MA-229.

MA-229

Change-Id: If1aaf8952f74fcf6336d4ce898c77acfb528dd66
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index f6821ce..742bc42 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -1178,10 +1178,28 @@
                          pSubmits[i].pCommandBuffers[j]);
          assert(cmd_buffer->level == VK_COMMAND_BUFFER_LEVEL_PRIMARY);
 
+         uint32_t signal_semaphore_count = pSubmits[i].signalSemaphoreCount;
+         anv_semaphore_t* signal_semaphores = (anv_semaphore_t*)pSubmits[i].pSignalSemaphores;
+         anv_semaphore_t semaphore_array_with_fence[signal_semaphore_count + 1];
+
+         if (fence && i == submitCount - 1 && j == pSubmits[i].commandBufferCount - 1) {
+            memcpy(semaphore_array_with_fence, pSubmits[i].pSignalSemaphores,
+                   signal_semaphore_count * sizeof(anv_semaphore_t));
+            semaphore_array_with_fence[signal_semaphore_count] = fence->semaphore;
+            signal_semaphore_count++;
+            signal_semaphores = semaphore_array_with_fence;
+
+            assert(fence->state == ANV_FENCE_STATE_RESET);
+            fence->state = ANV_FENCE_STATE_SUBMITTED;
+            pthread_cond_broadcast(&device->queue_submit);
+
+            // Signal that fence has been handled so we don't execute the extra command buffer below
+            fence = NULL;
+         }
+
          result = anv_cmd_buffer_execbuf(device, cmd_buffer, pSubmits[i].waitSemaphoreCount,
                                          (anv_semaphore_t*)pSubmits[i].pWaitSemaphores,
-                                         pSubmits[i].signalSemaphoreCount,
-                                         (anv_semaphore_t*)pSubmits[i].pSignalSemaphores);
+                                         signal_semaphore_count, signal_semaphores);
          if (result != VK_SUCCESS)
             goto out;
       }