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 | |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 18 | std::unique_ptr<VulkanDeviceQueue> CreateVulkanDeviceQueue( |
| 19 | VulkanImplementation* vulkan_implementation, |
| 20 | uint32_t option) { |
| 21 | auto device_queue = std::make_unique<VulkanDeviceQueue>( |
Sergey Ulanov | af257db | 2019-01-28 20:13:52 | [diff] [blame] | 22 | vulkan_implementation->GetVulkanInstance()->vk_instance()); |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 23 | auto callback = base::BindRepeating( |
| 24 | &VulkanImplementation::GetPhysicalDevicePresentationSupport, |
| 25 | base::Unretained(vulkan_implementation)); |
Michael Spang | 4e46bc2 | 2018-06-21 23:07:51 | [diff] [blame] | 26 | std::vector<const char*> required_extensions = |
| 27 | vulkan_implementation->GetRequiredDeviceExtensions(); |
| 28 | if (!device_queue->Initialize(option, std::move(required_extensions), |
| 29 | callback)) { |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 30 | device_queue->Destroy(); |
| 31 | return nullptr; |
dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 32 | } |
| 33 | |
Michael Spang | 7509e6d | 2018-05-16 17:08:28 | [diff] [blame] | 34 | return device_queue; |
dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 35 | } |
| 36 | |
Vikas Soni | cd499af | 2019-01-29 19:00:11 | [diff] [blame^] | 37 | bool VulkanImplementation::SubmitSignalSemaphore(VkQueue vk_queue, |
| 38 | VkSemaphore vk_semaphore, |
| 39 | VkFence vk_fence) { |
| 40 | // Structure specifying a queue submit operation. |
| 41 | VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; |
| 42 | submit_info.signalSemaphoreCount = 1; |
| 43 | submit_info.pSignalSemaphores = &vk_semaphore; |
| 44 | const unsigned int submit_count = 1; |
| 45 | if (vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) != |
| 46 | VK_SUCCESS) { |
| 47 | return false; |
| 48 | } |
| 49 | return true; |
| 50 | } |
| 51 | |
| 52 | bool VulkanImplementation::SubmitWaitSemaphore(VkQueue vk_queue, |
| 53 | VkSemaphore vk_semaphore, |
| 54 | VkFence vk_fence) { |
| 55 | // Structure specifying a queue submit operation. |
| 56 | VkSubmitInfo submit_info = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; |
| 57 | submit_info.waitSemaphoreCount = 1; |
| 58 | submit_info.pWaitSemaphores = &vk_semaphore; |
| 59 | const unsigned int submit_count = 1; |
| 60 | if (vkQueueSubmit(vk_queue, submit_count, &submit_info, vk_fence) != |
| 61 | VK_SUCCESS) { |
| 62 | return false; |
| 63 | } |
| 64 | return true; |
| 65 | } |
| 66 | |
dyen | 2ce3e05 | 2016-03-09 21:03:49 | [diff] [blame] | 67 | } // namespace gpu |