| // Copyright 2019 The Chromium Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #include "gpu/vulkan/vulkan_util.h" | |
| #include "gpu/vulkan/vulkan_function_pointers.h" | |
| namespace gpu { | |
| bool SubmitSignalVkSemaphore(VkQueue vk_queue, | |
| VkSemaphore vk_semaphore, | |
| VkFence vk_fence) { | |
| // Structure specifying a queue submit operation. | |
| VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; | |
| submit_info.signalSemaphoreCount = 1; | |
| submit_info.pSignalSemaphores = &vk_semaphore; | |
| const unsigned int submit_count = 1; | |
| return vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) == | |
| VK_SUCCESS; | |
| } | |
| bool SubmitWaitVkSemaphores(VkQueue vk_queue, | |
| const std::vector<VkSemaphore>& vk_semaphores, | |
| VkFence vk_fence) { | |
| DCHECK(!vk_semaphores.empty()); | |
| // Structure specifying a queue submit operation. | |
| VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; | |
| submit_info.waitSemaphoreCount = vk_semaphores.size(); | |
| submit_info.pWaitSemaphores = vk_semaphores.data(); | |
| const unsigned int submit_count = 1; | |
| return vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) == | |
| VK_SUCCESS; | |
| } | |
| bool SubmitWaitVkSemaphore(VkQueue vk_queue, | |
| VkSemaphore vk_semaphore, | |
| VkFence vk_fence) { | |
| return SubmitWaitVkSemaphores(vk_queue, {vk_semaphore}, vk_fence); | |
| } | |
| VkSemaphore CreateExternalVkSemaphore( | |
| VkDevice vk_device, | |
| VkExternalSemaphoreHandleTypeFlags handle_types) { | |
| VkExportSemaphoreCreateInfo export_info = { | |
| VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO}; | |
| export_info.handleTypes = handle_types; | |
| VkSemaphoreCreateInfo sem_info = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, | |
| &export_info}; | |
| VkSemaphore semaphore = VK_NULL_HANDLE; | |
| VkResult result = | |
| vkCreateSemaphore(vk_device, &sem_info, nullptr, &semaphore); | |
| if (result != VK_SUCCESS) { | |
| DLOG(ERROR) << "Failed to create VkSemaphore: " << result; | |
| return VK_NULL_HANDLE; | |
| } | |
| return semaphore; | |
| } | |
| } // namespace gpu |