dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 1 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "gpu/vulkan/vulkan_implementation.h" |
| 6 | |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 7 | #include "base/bind.h" |
| 8 | #include "gpu/vulkan/vulkan_device_queue.h" |
Vikas Soni | cd499af | 2019-01-29 19:00:11 | [diff] [blame] | 9 | #include "gpu/vulkan/vulkan_function_pointers.h" |
Sergey Ulanov | af257db | 2019-01-28 20:13:52 | [diff] [blame] | 10 | #include "gpu/vulkan/vulkan_instance.h" |
dyen | 5bd6d4f | 2016-03-31 15:25:45 | [diff] [blame] | 11 | |
dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 12 | namespace gpu { |
| 13 | |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 14 | VulkanImplementation::VulkanImplementation() {} |
dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 15 | |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 16 | VulkanImplementation::~VulkanImplementation() {} |
dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 17 | |
Vikas Soni | cd499af | 2019-01-29 19:00:11 | [diff] [blame] | 18 | bool VulkanImplementation::SubmitSignalSemaphore(VkQueue vk_queue, |
| 19 | VkSemaphore vk_semaphore, |
| 20 | VkFence vk_fence) { |
| 21 | // Structure specifying a queue submit operation. |
| 22 | VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; |
| 23 | submit_info.signalSemaphoreCount = 1; |
| 24 | submit_info.pSignalSemaphores = &vk_semaphore; |
| 25 | const unsigned int submit_count = 1; |
| 26 | if (vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) != |
| 27 | VK_SUCCESS) { |
| 28 | return false; |
| 29 | } |
| 30 | return true; |
| 31 | } |
| 32 | |
Peng Huang | fdcb746 | 2019-03-18 17:25:51 | [diff] [blame] | 33 | bool VulkanImplementation::SubmitWaitSemaphores( |
| 34 | VkQueue vk_queue, |
| 35 | const std::vector<VkSemaphore>& vk_semaphores, |
| 36 | VkFence vk_fence) { |
| 37 | DCHECK(!vk_semaphores.empty()); |
Vikas Soni | cd499af | 2019-01-29 19:00:11 | [diff] [blame] | 38 | // Structure specifying a queue submit operation. |
| 39 | VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; |
Peng Huang | fdcb746 | 2019-03-18 17:25:51 | [diff] [blame] | 40 | submit_info.waitSemaphoreCount = vk_semaphores.size(); |
| 41 | submit_info.pWaitSemaphores = vk_semaphores.data(); |
Vikas Soni | cd499af | 2019-01-29 19:00:11 | [diff] [blame] | 42 | const unsigned int submit_count = 1; |
| 43 | if (vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) != |
| 44 | VK_SUCCESS) { |
| 45 | return false; |
| 46 | } |
| 47 | return true; |
| 48 | } |
| 49 | |
Sergey Ulanov | 520fe0e | 2019-04-02 06:02:55 | [diff] [blame^] | 50 | VkSemaphore VulkanImplementation::CreateExternalSemaphore( |
| 51 | VkDevice vk_device, |
| 52 | VkExternalSemaphoreHandleTypeFlags handle_types) { |
| 53 | VkExportSemaphoreCreateInfo export_info = { |
| 54 | VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO}; |
| 55 | export_info.handleTypes = handle_types; |
| 56 | |
| 57 | VkSemaphoreCreateInfo sem_info = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, |
| 58 | &export_info}; |
| 59 | |
| 60 | VkSemaphore semaphore = VK_NULL_HANDLE; |
| 61 | VkResult result = |
| 62 | vkCreateSemaphore(vk_device, &sem_info, nullptr, &semaphore); |
| 63 | |
| 64 | if (result != VK_SUCCESS) { |
| 65 | DLOG(ERROR) << "Failed to create VkSemaphore: " << result; |
| 66 | return VK_NULL_HANDLE; |
| 67 | } |
| 68 | |
| 69 | return semaphore; |
| 70 | } |
| 71 | |
| 72 | std::unique_ptr<VulkanDeviceQueue> CreateVulkanDeviceQueue( |
| 73 | VulkanImplementation* vulkan_implementation, |
| 74 | uint32_t option) { |
| 75 | auto device_queue = std::make_unique<VulkanDeviceQueue>( |
| 76 | vulkan_implementation->GetVulkanInstance()->vk_instance()); |
| 77 | auto callback = base::BindRepeating( |
| 78 | &VulkanImplementation::GetPhysicalDevicePresentationSupport, |
| 79 | base::Unretained(vulkan_implementation)); |
| 80 | std::vector<const char*> required_extensions = |
| 81 | vulkan_implementation->GetRequiredDeviceExtensions(); |
| 82 | if (!device_queue->Initialize(option, std::move(required_extensions), |
| 83 | callback)) { |
| 84 | device_queue->Destroy(); |
| 85 | return nullptr; |
| 86 | } |
| 87 | |
| 88 | return device_queue; |
| 89 | } |
| 90 | |
dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 91 | } // namespace gpu |