Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "VulkanManager.h" |
| 18 | |
Alec Mouri | 6db59a6 | 2019-08-02 17:05:26 -0700 | [diff] [blame] | 19 | #include <EGL/egl.h> |
| 20 | #include <EGL/eglext.h> |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 21 | #include <GrBackendSemaphore.h> |
| 22 | #include <GrBackendSurface.h> |
Adlai Holler | f8c434e | 2020-07-27 11:42:45 -0400 | [diff] [blame] | 23 | #include <GrDirectContext.h> |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 24 | #include <GrTypes.h> |
| 25 | #include <android/sync.h> |
Jagadeesh Pakaravoor | b624af3 | 2020-05-01 00:01:40 +0000 | [diff] [blame] | 26 | #include <ui/FatVector.h> |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 27 | #include <vk/GrVkExtensions.h> |
| 28 | #include <vk/GrVkTypes.h> |
Stan Iliev | 305e13a | 2018-11-13 11:14:48 -0500 | [diff] [blame] | 29 | |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 30 | #include <cstring> |
| 31 | |
rnlee | ce9762b | 2021-05-21 15:40:53 -0700 | [diff] [blame] | 32 | #include <gui/TraceUtils.h> |
Greg Daniel | cd55852 | 2016-11-17 13:31:40 -0500 | [diff] [blame] | 33 | #include "Properties.h" |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 34 | #include "RenderThread.h" |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 35 | #include "pipeline/skia/ShaderCache.h" |
Greg Daniel | 45ec62b | 2017-01-04 14:27:00 -0500 | [diff] [blame] | 36 | #include "renderstate/RenderState.h" |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 37 | |
Leon Scroggins III | 7ccb8a4 | 2021-11-30 14:17:28 -0500 | [diff] [blame] | 38 | #undef LOG_TAG |
| 39 | #define LOG_TAG "VulkanManager" |
| 40 | |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 41 | namespace android { |
| 42 | namespace uirenderer { |
| 43 | namespace renderthread { |
| 44 | |
John Reck | 90b244d | 2023-04-28 15:41:55 -0400 | [diff] [blame] | 45 | static std::array<std::string_view, 19> sEnableExtensions{ |
John Reck | f6067df | 2023-04-11 16:27:51 -0400 | [diff] [blame] | 46 | VK_KHR_BIND_MEMORY_2_EXTENSION_NAME, |
| 47 | VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, |
| 48 | VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME, |
| 49 | VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME, |
| 50 | VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, |
| 51 | VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, |
| 52 | VK_KHR_MAINTENANCE1_EXTENSION_NAME, |
| 53 | VK_KHR_MAINTENANCE2_EXTENSION_NAME, |
| 54 | VK_KHR_MAINTENANCE3_EXTENSION_NAME, |
| 55 | VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME, |
| 56 | VK_KHR_SURFACE_EXTENSION_NAME, |
| 57 | VK_KHR_SWAPCHAIN_EXTENSION_NAME, |
| 58 | VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, |
John Reck | 90b244d | 2023-04-28 15:41:55 -0400 | [diff] [blame] | 59 | VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, |
John Reck | f6067df | 2023-04-11 16:27:51 -0400 | [diff] [blame] | 60 | VK_EXT_IMAGE_DRM_FORMAT_MODIFIER_EXTENSION_NAME, |
| 61 | VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME, |
| 62 | VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME, |
| 63 | VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, |
| 64 | VK_KHR_ANDROID_SURFACE_EXTENSION_NAME, |
| 65 | }; |
| 66 | |
| 67 | static bool shouldEnableExtension(const std::string_view& extension) { |
| 68 | for (const auto& it : sEnableExtensions) { |
| 69 | if (it == extension) { |
| 70 | return true; |
| 71 | } |
| 72 | } |
| 73 | return false; |
| 74 | } |
| 75 | |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 76 | static void free_features_extensions_structs(const VkPhysicalDeviceFeatures2& features) { |
| 77 | // All Vulkan structs that could be part of the features chain will start with the |
| 78 | // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader |
| 79 | // so we can get access to the pNext for the next struct. |
| 80 | struct CommonVulkanHeader { |
| 81 | VkStructureType sType; |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 82 | void* pNext; |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | void* pNext = features.pNext; |
| 86 | while (pNext) { |
| 87 | void* current = pNext; |
| 88 | pNext = static_cast<CommonVulkanHeader*>(current)->pNext; |
| 89 | free(current); |
| 90 | } |
| 91 | } |
| 92 | |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 93 | GrVkGetProc VulkanManager::sSkiaGetProp = [](const char* proc_name, VkInstance instance, |
| 94 | VkDevice device) { |
| 95 | if (device != VK_NULL_HANDLE) { |
| 96 | if (strcmp("vkQueueSubmit", proc_name) == 0) { |
| 97 | return (PFN_vkVoidFunction)VulkanManager::interceptedVkQueueSubmit; |
| 98 | } else if (strcmp("vkQueueWaitIdle", proc_name) == 0) { |
| 99 | return (PFN_vkVoidFunction)VulkanManager::interceptedVkQueueWaitIdle; |
| 100 | } |
| 101 | return vkGetDeviceProcAddr(device, proc_name); |
| 102 | } |
| 103 | return vkGetInstanceProcAddr(instance, proc_name); |
| 104 | }; |
| 105 | |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 106 | #define GET_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(VK_NULL_HANDLE, "vk" #F) |
| 107 | #define GET_INST_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(mInstance, "vk" #F) |
| 108 | #define GET_DEV_PROC(F) m##F = (PFN_vk##F)vkGetDeviceProcAddr(mDevice, "vk" #F) |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 109 | |
John Reck | 9fc3d27 | 2023-05-01 16:33:22 -0400 | [diff] [blame] | 110 | // cache a weakptr to the context to enable a second thread to share the same vulkan state |
| 111 | static wp<VulkanManager> sWeakInstance = nullptr; |
| 112 | static std::mutex sLock; |
Derek Sollenberger | 802fefa | 2020-08-13 16:53:30 -0400 | [diff] [blame] | 113 | |
John Reck | 9fc3d27 | 2023-05-01 16:33:22 -0400 | [diff] [blame] | 114 | sp<VulkanManager> VulkanManager::getInstance() { |
Derek Sollenberger | 802fefa | 2020-08-13 16:53:30 -0400 | [diff] [blame] | 115 | std::lock_guard _lock{sLock}; |
| 116 | sp<VulkanManager> vulkanManager = sWeakInstance.promote(); |
| 117 | if (!vulkanManager.get()) { |
| 118 | vulkanManager = new VulkanManager(); |
| 119 | sWeakInstance = vulkanManager; |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 120 | } |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 121 | |
Derek Sollenberger | 802fefa | 2020-08-13 16:53:30 -0400 | [diff] [blame] | 122 | return vulkanManager; |
| 123 | } |
| 124 | |
John Reck | 9fc3d27 | 2023-05-01 16:33:22 -0400 | [diff] [blame] | 125 | sp<VulkanManager> VulkanManager::peekInstance() { |
| 126 | std::lock_guard _lock{sLock}; |
| 127 | return sWeakInstance.promote(); |
| 128 | } |
| 129 | |
Derek Sollenberger | 802fefa | 2020-08-13 16:53:30 -0400 | [diff] [blame] | 130 | VulkanManager::~VulkanManager() { |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 131 | if (mDevice != VK_NULL_HANDLE) { |
| 132 | mDeviceWaitIdle(mDevice); |
| 133 | mDestroyDevice(mDevice, nullptr); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 134 | } |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 135 | |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 136 | if (mInstance != VK_NULL_HANDLE) { |
| 137 | mDestroyInstance(mInstance, nullptr); |
| 138 | } |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 139 | |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 140 | mGraphicsQueue = VK_NULL_HANDLE; |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 141 | mDevice = VK_NULL_HANDLE; |
| 142 | mPhysicalDevice = VK_NULL_HANDLE; |
| 143 | mInstance = VK_NULL_HANDLE; |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 144 | mInstanceExtensionsOwner.clear(); |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 145 | mInstanceExtensions.clear(); |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 146 | mDeviceExtensionsOwner.clear(); |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 147 | mDeviceExtensions.clear(); |
| 148 | free_features_extensions_structs(mPhysicalDeviceFeatures2); |
| 149 | mPhysicalDeviceFeatures2 = {}; |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 150 | } |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 151 | |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 152 | void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFeatures2& features) { |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 153 | VkResult err; |
| 154 | |
| 155 | constexpr VkApplicationInfo app_info = { |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 156 | VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType |
| 157 | nullptr, // pNext |
| 158 | "android framework", // pApplicationName |
| 159 | 0, // applicationVersion |
| 160 | "android framework", // pEngineName |
| 161 | 0, // engineVerison |
| 162 | mAPIVersion, // apiVersion |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 163 | }; |
| 164 | |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 165 | { |
| 166 | GET_PROC(EnumerateInstanceExtensionProperties); |
| 167 | |
| 168 | uint32_t extensionCount = 0; |
| 169 | err = mEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 170 | LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err); |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 171 | mInstanceExtensionsOwner.resize(extensionCount); |
| 172 | err = mEnumerateInstanceExtensionProperties(nullptr, &extensionCount, |
| 173 | mInstanceExtensionsOwner.data()); |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 174 | LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 175 | bool hasKHRSurfaceExtension = false; |
| 176 | bool hasKHRAndroidSurfaceExtension = false; |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 177 | for (const VkExtensionProperties& extension : mInstanceExtensionsOwner) { |
John Reck | f6067df | 2023-04-11 16:27:51 -0400 | [diff] [blame] | 178 | if (!shouldEnableExtension(extension.extensionName)) { |
| 179 | ALOGV("Not enabling instance extension %s", extension.extensionName); |
| 180 | continue; |
| 181 | } |
| 182 | ALOGV("Enabling instance extension %s", extension.extensionName); |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 183 | mInstanceExtensions.push_back(extension.extensionName); |
| 184 | if (!strcmp(extension.extensionName, VK_KHR_SURFACE_EXTENSION_NAME)) { |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 185 | hasKHRSurfaceExtension = true; |
| 186 | } |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 187 | if (!strcmp(extension.extensionName, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME)) { |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 188 | hasKHRAndroidSurfaceExtension = true; |
| 189 | } |
| 190 | } |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 191 | LOG_ALWAYS_FATAL_IF(!hasKHRSurfaceExtension || !hasKHRAndroidSurfaceExtension); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | const VkInstanceCreateInfo instance_create = { |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 195 | VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType |
| 196 | nullptr, // pNext |
| 197 | 0, // flags |
| 198 | &app_info, // pApplicationInfo |
| 199 | 0, // enabledLayerNameCount |
| 200 | nullptr, // ppEnabledLayerNames |
| 201 | (uint32_t)mInstanceExtensions.size(), // enabledExtensionNameCount |
| 202 | mInstanceExtensions.data(), // ppEnabledExtensionNames |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | GET_PROC(CreateInstance); |
| 206 | err = mCreateInstance(&instance_create, nullptr, &mInstance); |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 207 | LOG_ALWAYS_FATAL_IF(err < 0); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 208 | |
Yiwei Zhang | 0b9f0b8 | 2019-08-15 11:33:59 -0700 | [diff] [blame] | 209 | GET_INST_PROC(CreateDevice); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 210 | GET_INST_PROC(DestroyInstance); |
Yiwei Zhang | 0b9f0b8 | 2019-08-15 11:33:59 -0700 | [diff] [blame] | 211 | GET_INST_PROC(EnumerateDeviceExtensionProperties); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 212 | GET_INST_PROC(EnumeratePhysicalDevices); |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 213 | GET_INST_PROC(GetPhysicalDeviceFeatures2); |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 214 | GET_INST_PROC(GetPhysicalDeviceImageFormatProperties2); |
Yiwei Zhang | 0b9f0b8 | 2019-08-15 11:33:59 -0700 | [diff] [blame] | 215 | GET_INST_PROC(GetPhysicalDeviceProperties); |
| 216 | GET_INST_PROC(GetPhysicalDeviceQueueFamilyProperties); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 217 | |
| 218 | uint32_t gpuCount; |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 219 | LOG_ALWAYS_FATAL_IF(mEnumeratePhysicalDevices(mInstance, &gpuCount, nullptr)); |
| 220 | LOG_ALWAYS_FATAL_IF(!gpuCount); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 221 | // Just returning the first physical device instead of getting the whole array. Since there |
| 222 | // should only be one device on android. |
| 223 | gpuCount = 1; |
| 224 | err = mEnumeratePhysicalDevices(mInstance, &gpuCount, &mPhysicalDevice); |
| 225 | // VK_INCOMPLETE is returned when the count we provide is less than the total device count. |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 226 | LOG_ALWAYS_FATAL_IF(err && VK_INCOMPLETE != err); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 227 | |
Greg Daniel | 9625962 | 2018-10-01 14:42:56 -0400 | [diff] [blame] | 228 | VkPhysicalDeviceProperties physDeviceProperties; |
| 229 | mGetPhysicalDeviceProperties(mPhysicalDevice, &physDeviceProperties); |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 230 | LOG_ALWAYS_FATAL_IF(physDeviceProperties.apiVersion < VK_MAKE_VERSION(1, 1, 0)); |
Stan Iliev | bf99c44 | 2019-03-29 11:09:11 -0400 | [diff] [blame] | 231 | mDriverVersion = physDeviceProperties.driverVersion; |
Greg Daniel | 9625962 | 2018-10-01 14:42:56 -0400 | [diff] [blame] | 232 | |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 233 | // query to get the initial queue props size |
| 234 | uint32_t queueCount; |
| 235 | mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr); |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 236 | LOG_ALWAYS_FATAL_IF(!queueCount); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 237 | |
| 238 | // now get the actual queue props |
| 239 | std::unique_ptr<VkQueueFamilyProperties[]> queueProps(new VkQueueFamilyProperties[queueCount]); |
| 240 | mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, queueProps.get()); |
| 241 | |
| 242 | // iterate to find the graphics queue |
| 243 | mGraphicsQueueIndex = queueCount; |
| 244 | for (uint32_t i = 0; i < queueCount; i++) { |
| 245 | if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) { |
| 246 | mGraphicsQueueIndex = i; |
| 247 | break; |
| 248 | } |
| 249 | } |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 250 | LOG_ALWAYS_FATAL_IF(mGraphicsQueueIndex == queueCount); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 251 | |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 252 | { |
| 253 | uint32_t extensionCount = 0; |
| 254 | err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount, |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 255 | nullptr); |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 256 | LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err); |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 257 | mDeviceExtensionsOwner.resize(extensionCount); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 258 | err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount, |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 259 | mDeviceExtensionsOwner.data()); |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 260 | LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 261 | bool hasKHRSwapchainExtension = false; |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 262 | for (const VkExtensionProperties& extension : mDeviceExtensionsOwner) { |
John Reck | f6067df | 2023-04-11 16:27:51 -0400 | [diff] [blame] | 263 | if (!shouldEnableExtension(extension.extensionName)) { |
| 264 | ALOGV("Not enabling device extension %s", extension.extensionName); |
| 265 | continue; |
| 266 | } |
| 267 | ALOGV("Enabling device extension %s", extension.extensionName); |
Roman Kiryanov | 74ace839e | 2019-03-07 18:22:19 -0800 | [diff] [blame] | 268 | mDeviceExtensions.push_back(extension.extensionName); |
| 269 | if (!strcmp(extension.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) { |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 270 | hasKHRSwapchainExtension = true; |
| 271 | } |
| 272 | } |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 273 | LOG_ALWAYS_FATAL_IF(!hasKHRSwapchainExtension); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 276 | grExtensions.init(sSkiaGetProp, mInstance, mPhysicalDevice, mInstanceExtensions.size(), |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 277 | mInstanceExtensions.data(), mDeviceExtensions.size(), |
| 278 | mDeviceExtensions.data()); |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 279 | |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 280 | LOG_ALWAYS_FATAL_IF(!grExtensions.hasExtension(VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, 1)); |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 281 | |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 282 | memset(&features, 0, sizeof(VkPhysicalDeviceFeatures2)); |
| 283 | features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2; |
| 284 | features.pNext = nullptr; |
| 285 | |
| 286 | // Setup all extension feature structs we may want to use. |
| 287 | void** tailPNext = &features.pNext; |
| 288 | |
| 289 | if (grExtensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2)) { |
| 290 | VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT* blend; |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 291 | blend = (VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT*)malloc( |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 292 | sizeof(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT)); |
| 293 | LOG_ALWAYS_FATAL_IF(!blend); |
| 294 | blend->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT; |
| 295 | blend->pNext = nullptr; |
| 296 | *tailPNext = blend; |
| 297 | tailPNext = &blend->pNext; |
| 298 | } |
| 299 | |
Greg Daniel | 0503617 | 2018-11-28 17:08:04 -0500 | [diff] [blame] | 300 | VkPhysicalDeviceSamplerYcbcrConversionFeatures* ycbcrFeature; |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 301 | ycbcrFeature = (VkPhysicalDeviceSamplerYcbcrConversionFeatures*)malloc( |
Greg Daniel | 0503617 | 2018-11-28 17:08:04 -0500 | [diff] [blame] | 302 | sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures)); |
| 303 | LOG_ALWAYS_FATAL_IF(!ycbcrFeature); |
| 304 | ycbcrFeature->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES; |
| 305 | ycbcrFeature->pNext = nullptr; |
| 306 | *tailPNext = ycbcrFeature; |
| 307 | tailPNext = &ycbcrFeature->pNext; |
| 308 | |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 309 | // query to get the physical device features |
| 310 | mGetPhysicalDeviceFeatures2(mPhysicalDevice, &features); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 311 | // this looks like it would slow things down, |
| 312 | // and we can't depend on it on all platforms |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 313 | features.features.robustBufferAccess = VK_FALSE; |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 314 | |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 315 | float queuePriorities[1] = {0.0}; |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 316 | |
Stan Iliev | 7e73336 | 2019-02-28 13:16:36 -0500 | [diff] [blame] | 317 | void* queueNextPtr = nullptr; |
| 318 | |
| 319 | VkDeviceQueueGlobalPriorityCreateInfoEXT queuePriorityCreateInfo; |
| 320 | |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 321 | if (Properties::contextPriority != 0 && |
| 322 | grExtensions.hasExtension(VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME, 2)) { |
Stan Iliev | 7e73336 | 2019-02-28 13:16:36 -0500 | [diff] [blame] | 323 | memset(&queuePriorityCreateInfo, 0, sizeof(VkDeviceQueueGlobalPriorityCreateInfoEXT)); |
| 324 | queuePriorityCreateInfo.sType = |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 325 | VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT; |
Stan Iliev | 7e73336 | 2019-02-28 13:16:36 -0500 | [diff] [blame] | 326 | queuePriorityCreateInfo.pNext = nullptr; |
| 327 | switch (Properties::contextPriority) { |
| 328 | case EGL_CONTEXT_PRIORITY_LOW_IMG: |
| 329 | queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT; |
| 330 | break; |
| 331 | case EGL_CONTEXT_PRIORITY_MEDIUM_IMG: |
| 332 | queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT; |
| 333 | break; |
| 334 | case EGL_CONTEXT_PRIORITY_HIGH_IMG: |
| 335 | queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT; |
| 336 | break; |
| 337 | default: |
| 338 | LOG_ALWAYS_FATAL("Unsupported context priority"); |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 339 | } |
| 340 | queueNextPtr = &queuePriorityCreateInfo; |
Stan Iliev | 7e73336 | 2019-02-28 13:16:36 -0500 | [diff] [blame] | 341 | } |
| 342 | |
Yiwei Zhang | 276d5fc | 2020-09-03 12:00:00 -0700 | [diff] [blame] | 343 | const VkDeviceQueueCreateInfo queueInfo = { |
| 344 | VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType |
| 345 | queueNextPtr, // pNext |
| 346 | 0, // VkDeviceQueueCreateFlags |
| 347 | mGraphicsQueueIndex, // queueFamilyIndex |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 348 | 1, // queueCount |
Yiwei Zhang | 276d5fc | 2020-09-03 12:00:00 -0700 | [diff] [blame] | 349 | queuePriorities, // pQueuePriorities |
| 350 | }; |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 351 | |
| 352 | const VkDeviceCreateInfo deviceInfo = { |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 353 | VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType |
| 354 | &features, // pNext |
| 355 | 0, // VkDeviceCreateFlags |
Yiwei Zhang | 276d5fc | 2020-09-03 12:00:00 -0700 | [diff] [blame] | 356 | 1, // queueCreateInfoCount |
| 357 | &queueInfo, // pQueueCreateInfos |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 358 | 0, // layerCount |
| 359 | nullptr, // ppEnabledLayerNames |
| 360 | (uint32_t)mDeviceExtensions.size(), // extensionCount |
| 361 | mDeviceExtensions.data(), // ppEnabledExtensionNames |
| 362 | nullptr, // ppEnabledFeatures |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 363 | }; |
| 364 | |
Stan Iliev | 90276c8 | 2019-02-03 18:01:02 -0500 | [diff] [blame] | 365 | LOG_ALWAYS_FATAL_IF(mCreateDevice(mPhysicalDevice, &deviceInfo, nullptr, &mDevice)); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 366 | |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 367 | GET_DEV_PROC(AllocateCommandBuffers); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 368 | GET_DEV_PROC(BeginCommandBuffer); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 369 | GET_DEV_PROC(CmdPipelineBarrier); |
Yiwei Zhang | 0b9f0b8 | 2019-08-15 11:33:59 -0700 | [diff] [blame] | 370 | GET_DEV_PROC(CreateCommandPool); |
| 371 | GET_DEV_PROC(CreateFence); |
| 372 | GET_DEV_PROC(CreateSemaphore); |
| 373 | GET_DEV_PROC(DestroyCommandPool); |
| 374 | GET_DEV_PROC(DestroyDevice); |
| 375 | GET_DEV_PROC(DestroyFence); |
| 376 | GET_DEV_PROC(DestroySemaphore); |
| 377 | GET_DEV_PROC(DeviceWaitIdle); |
| 378 | GET_DEV_PROC(EndCommandBuffer); |
| 379 | GET_DEV_PROC(FreeCommandBuffers); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 380 | GET_DEV_PROC(GetDeviceQueue); |
Yiwei Zhang | 0b9f0b8 | 2019-08-15 11:33:59 -0700 | [diff] [blame] | 381 | GET_DEV_PROC(GetSemaphoreFdKHR); |
| 382 | GET_DEV_PROC(ImportSemaphoreFdKHR); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 383 | GET_DEV_PROC(QueueSubmit); |
| 384 | GET_DEV_PROC(QueueWaitIdle); |
Yiwei Zhang | 0b9f0b8 | 2019-08-15 11:33:59 -0700 | [diff] [blame] | 385 | GET_DEV_PROC(ResetCommandBuffer); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 386 | GET_DEV_PROC(ResetFences); |
Yiwei Zhang | 0b9f0b8 | 2019-08-15 11:33:59 -0700 | [diff] [blame] | 387 | GET_DEV_PROC(WaitForFences); |
Hugues Evrard | b9510a0 | 2021-03-01 14:35:22 +0000 | [diff] [blame] | 388 | GET_DEV_PROC(FrameBoundaryANDROID); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | void VulkanManager::initialize() { |
Greg Daniel | 1d9de71 | 2021-05-14 09:28:34 -0400 | [diff] [blame] | 392 | std::lock_guard _lock{mInitializeLock}; |
| 393 | |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 394 | if (mDevice != VK_NULL_HANDLE) { |
| 395 | return; |
| 396 | } |
| 397 | |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 398 | GET_PROC(EnumerateInstanceVersion); |
Greg Daniel | eaf310e | 2019-01-28 16:10:32 -0500 | [diff] [blame] | 399 | uint32_t instanceVersion; |
| 400 | LOG_ALWAYS_FATAL_IF(mEnumerateInstanceVersion(&instanceVersion)); |
| 401 | LOG_ALWAYS_FATAL_IF(instanceVersion < VK_MAKE_VERSION(1, 1, 0)); |
Greg Daniel | a227dbb | 2018-08-20 09:19:48 -0400 | [diff] [blame] | 402 | |
Stan Iliev | 981afe7 | 2019-02-13 14:24:33 -0500 | [diff] [blame] | 403 | this->setupDevice(mExtensions, mPhysicalDeviceFeatures2); |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 404 | |
| 405 | mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 0, &mGraphicsQueue); |
| 406 | |
Greg Daniel | cd55852 | 2016-11-17 13:31:40 -0500 | [diff] [blame] | 407 | if (Properties::enablePartialUpdates && Properties::useBufferAge) { |
| 408 | mSwapBehavior = SwapBehavior::BufferAge; |
| 409 | } |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 410 | } |
| 411 | |
John Reck | 9fc3d27 | 2023-05-01 16:33:22 -0400 | [diff] [blame] | 412 | static void onGrContextReleased(void* context) { |
| 413 | VulkanManager* manager = (VulkanManager*)context; |
| 414 | manager->decStrong((void*)onGrContextReleased); |
| 415 | } |
Stan Iliev | 981afe7 | 2019-02-13 14:24:33 -0500 | [diff] [blame] | 416 | |
John Reck | 9fc3d27 | 2023-05-01 16:33:22 -0400 | [diff] [blame] | 417 | sk_sp<GrDirectContext> VulkanManager::createContext(GrContextOptions& options, |
| 418 | ContextType contextType) { |
Stan Iliev | 981afe7 | 2019-02-13 14:24:33 -0500 | [diff] [blame] | 419 | GrVkBackendContext backendContext; |
| 420 | backendContext.fInstance = mInstance; |
| 421 | backendContext.fPhysicalDevice = mPhysicalDevice; |
| 422 | backendContext.fDevice = mDevice; |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 423 | backendContext.fQueue = mGraphicsQueue; |
Stan Iliev | 981afe7 | 2019-02-13 14:24:33 -0500 | [diff] [blame] | 424 | backendContext.fGraphicsQueueIndex = mGraphicsQueueIndex; |
| 425 | backendContext.fMaxAPIVersion = mAPIVersion; |
| 426 | backendContext.fVkExtensions = &mExtensions; |
| 427 | backendContext.fDeviceFeatures2 = &mPhysicalDeviceFeatures2; |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 428 | backendContext.fGetProc = sSkiaGetProp; |
Stan Iliev | 981afe7 | 2019-02-13 14:24:33 -0500 | [diff] [blame] | 429 | |
John Reck | 9fc3d27 | 2023-05-01 16:33:22 -0400 | [diff] [blame] | 430 | LOG_ALWAYS_FATAL_IF(options.fContextDeleteProc != nullptr, "Conflicting fContextDeleteProcs!"); |
| 431 | this->incStrong((void*)onGrContextReleased); |
| 432 | options.fContextDeleteContext = this; |
| 433 | options.fContextDeleteProc = onGrContextReleased; |
| 434 | |
Adlai Holler | f8c434e | 2020-07-27 11:42:45 -0400 | [diff] [blame] | 435 | return GrDirectContext::MakeVulkan(backendContext, options); |
Stan Iliev | 981afe7 | 2019-02-13 14:24:33 -0500 | [diff] [blame] | 436 | } |
| 437 | |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 438 | VkFunctorInitParams VulkanManager::getVkFunctorInitParams() const { |
| 439 | return VkFunctorInitParams{ |
| 440 | .instance = mInstance, |
| 441 | .physical_device = mPhysicalDevice, |
| 442 | .device = mDevice, |
| 443 | .queue = mGraphicsQueue, |
| 444 | .graphics_queue_index = mGraphicsQueueIndex, |
Greg Daniel | eaf310e | 2019-01-28 16:10:32 -0500 | [diff] [blame] | 445 | .api_version = mAPIVersion, |
Bo Liu | 7b8c1eb | 2019-01-08 20:17:55 -0800 | [diff] [blame] | 446 | .enabled_instance_extension_names = mInstanceExtensions.data(), |
| 447 | .enabled_instance_extension_names_length = |
| 448 | static_cast<uint32_t>(mInstanceExtensions.size()), |
| 449 | .enabled_device_extension_names = mDeviceExtensions.data(), |
| 450 | .enabled_device_extension_names_length = |
| 451 | static_cast<uint32_t>(mDeviceExtensions.size()), |
| 452 | .device_features_2 = &mPhysicalDeviceFeatures2, |
| 453 | }; |
| 454 | } |
| 455 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 456 | Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) { |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 457 | VulkanSurface::NativeBufferInfo* bufferInfo = surface->dequeueNativeBuffer(); |
| 458 | |
| 459 | if (bufferInfo == nullptr) { |
| 460 | ALOGE("VulkanSurface::dequeueNativeBuffer called with an invalid surface!"); |
| 461 | return Frame(-1, -1, 0); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 462 | } |
| 463 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 464 | LOG_ALWAYS_FATAL_IF(!bufferInfo->dequeued); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 465 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 466 | if (bufferInfo->dequeue_fence != -1) { |
Stan Iliev | 197843d | 2019-03-21 11:34:15 -0400 | [diff] [blame] | 467 | struct sync_file_info* finfo = sync_file_info(bufferInfo->dequeue_fence); |
| 468 | bool isSignalPending = false; |
| 469 | if (finfo != NULL) { |
| 470 | isSignalPending = finfo->status != 1; |
| 471 | sync_file_info_free(finfo); |
| 472 | } |
| 473 | if (isSignalPending) { |
| 474 | int fence_clone = dup(bufferInfo->dequeue_fence); |
| 475 | if (fence_clone == -1) { |
| 476 | ALOGE("dup(fence) failed, stalling until signalled: %s (%d)", strerror(errno), |
| 477 | errno); |
| 478 | sync_wait(bufferInfo->dequeue_fence, -1 /* forever */); |
| 479 | } else { |
| 480 | VkSemaphoreCreateInfo semaphoreInfo; |
| 481 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 482 | semaphoreInfo.pNext = nullptr; |
| 483 | semaphoreInfo.flags = 0; |
| 484 | VkSemaphore semaphore; |
| 485 | VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore); |
Greg Daniel | d667077 | 2021-06-09 12:01:12 -0400 | [diff] [blame] | 486 | if (err != VK_SUCCESS) { |
| 487 | ALOGE("Failed to create import semaphore, err: %d", err); |
| 488 | close(fence_clone); |
| 489 | sync_wait(bufferInfo->dequeue_fence, -1 /* forever */); |
| 490 | } else { |
| 491 | VkImportSemaphoreFdInfoKHR importInfo; |
| 492 | importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR; |
| 493 | importInfo.pNext = nullptr; |
| 494 | importInfo.semaphore = semaphore; |
| 495 | importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT; |
| 496 | importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; |
| 497 | importInfo.fd = fence_clone; |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 498 | |
Greg Daniel | d667077 | 2021-06-09 12:01:12 -0400 | [diff] [blame] | 499 | err = mImportSemaphoreFdKHR(mDevice, &importInfo); |
| 500 | if (err != VK_SUCCESS) { |
| 501 | ALOGE("Failed to import semaphore, err: %d", err); |
| 502 | mDestroySemaphore(mDevice, semaphore, nullptr); |
| 503 | close(fence_clone); |
| 504 | sync_wait(bufferInfo->dequeue_fence, -1 /* forever */); |
| 505 | } else { |
| 506 | GrBackendSemaphore backendSemaphore; |
| 507 | backendSemaphore.initVulkan(semaphore); |
| 508 | // Skia will take ownership of the VkSemaphore and delete it once the wait |
| 509 | // has finished. The VkSemaphore also owns the imported fd, so it will |
| 510 | // close the fd when it is deleted. |
| 511 | bufferInfo->skSurface->wait(1, &backendSemaphore); |
| 512 | // The following flush blocks the GPU immediately instead of waiting for |
| 513 | // other drawing ops. It seems dequeue_fence is not respected otherwise. |
| 514 | // TODO: remove the flush after finding why backendSemaphore is not working. |
| 515 | bufferInfo->skSurface->flushAndSubmit(); |
| 516 | } |
| 517 | } |
Stan Iliev | 197843d | 2019-03-21 11:34:15 -0400 | [diff] [blame] | 518 | } |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 519 | } |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 520 | } |
| 521 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 522 | int bufferAge = (mSwapBehavior == SwapBehavior::Discard) ? 0 : surface->getCurrentBuffersAge(); |
| 523 | return Frame(surface->logicalWidth(), surface->logicalHeight(), bufferAge); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 526 | struct DestroySemaphoreInfo { |
| 527 | PFN_vkDestroySemaphore mDestroyFunction; |
| 528 | VkDevice mDevice; |
| 529 | VkSemaphore mSemaphore; |
Greg Daniel | fd42939 | 2019-05-09 15:44:56 -0400 | [diff] [blame] | 530 | // We need to make sure we don't delete the VkSemaphore until it is done being used by both Skia |
| 531 | // (including by the GPU) and inside the VulkanManager. So we always start with two refs, one |
| 532 | // owned by Skia and one owned by the VulkanManager. The refs are decremented each time |
| 533 | // destroy_semaphore is called with this object. Skia will call destroy_semaphore once it is |
| 534 | // done with the semaphore and the GPU has finished work on the semaphore. The VulkanManager |
| 535 | // calls destroy_semaphore after sending the semaphore to Skia and exporting it if need be. |
| 536 | int mRefs = 2; |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 537 | |
| 538 | DestroySemaphoreInfo(PFN_vkDestroySemaphore destroyFunction, VkDevice device, |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 539 | VkSemaphore semaphore) |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 540 | : mDestroyFunction(destroyFunction), mDevice(device), mSemaphore(semaphore) {} |
| 541 | }; |
| 542 | |
| 543 | static void destroy_semaphore(void* context) { |
| 544 | DestroySemaphoreInfo* info = reinterpret_cast<DestroySemaphoreInfo*>(context); |
Greg Daniel | fd42939 | 2019-05-09 15:44:56 -0400 | [diff] [blame] | 545 | --info->mRefs; |
| 546 | if (!info->mRefs) { |
| 547 | info->mDestroyFunction(info->mDevice, info->mSemaphore, nullptr); |
| 548 | delete info; |
| 549 | } |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 550 | } |
| 551 | |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 552 | nsecs_t VulkanManager::finishFrame(SkSurface* surface) { |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 553 | ATRACE_NAME("Vulkan finish frame"); |
| 554 | ALOGE_IF(mSwapSemaphore != VK_NULL_HANDLE || mDestroySemaphoreContext != nullptr, |
| 555 | "finishFrame already has an outstanding semaphore"); |
Stan Iliev | bc5f06b | 2019-03-26 15:14:34 -0400 | [diff] [blame] | 556 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 557 | VkExportSemaphoreCreateInfo exportInfo; |
| 558 | exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO; |
| 559 | exportInfo.pNext = nullptr; |
| 560 | exportInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 561 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 562 | VkSemaphoreCreateInfo semaphoreInfo; |
| 563 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 564 | semaphoreInfo.pNext = &exportInfo; |
| 565 | semaphoreInfo.flags = 0; |
| 566 | VkSemaphore semaphore; |
| 567 | VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore); |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 568 | ALOGE_IF(VK_SUCCESS != err, "VulkanManager::makeSwapSemaphore(): Failed to create semaphore"); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 569 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 570 | GrBackendSemaphore backendSemaphore; |
| 571 | backendSemaphore.initVulkan(semaphore); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 572 | |
Greg Daniel | c7ad408 | 2020-05-14 15:38:26 -0400 | [diff] [blame] | 573 | GrFlushInfo flushInfo; |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 574 | if (err == VK_SUCCESS) { |
| 575 | mDestroySemaphoreContext = new DestroySemaphoreInfo(mDestroySemaphore, mDevice, semaphore); |
| 576 | flushInfo.fNumSemaphores = 1; |
| 577 | flushInfo.fSignalSemaphores = &backendSemaphore; |
| 578 | flushInfo.fFinishedProc = destroy_semaphore; |
| 579 | flushInfo.fFinishedContext = mDestroySemaphoreContext; |
| 580 | } else { |
| 581 | semaphore = VK_NULL_HANDLE; |
| 582 | } |
| 583 | GrSemaphoresSubmitted submitted = |
| 584 | surface->flush(SkSurface::BackendSurfaceAccess::kPresent, flushInfo); |
| 585 | GrDirectContext* context = GrAsDirectContext(surface->recordingContext()); |
Adlai Holler | 0375fee | 2020-09-15 12:31:22 -0400 | [diff] [blame] | 586 | ALOGE_IF(!context, "Surface is not backed by gpu"); |
| 587 | context->submit(); |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 588 | const nsecs_t submissionTime = systemTime(); |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 589 | if (semaphore != VK_NULL_HANDLE) { |
| 590 | if (submitted == GrSemaphoresSubmitted::kYes) { |
| 591 | mSwapSemaphore = semaphore; |
Hugues Evrard | b9510a0 | 2021-03-01 14:35:22 +0000 | [diff] [blame] | 592 | if (mFrameBoundaryANDROID) { |
| 593 | // retrieve VkImage used as render target |
| 594 | VkImage image = VK_NULL_HANDLE; |
| 595 | GrBackendRenderTarget backendRenderTarget = |
| 596 | surface->getBackendRenderTarget(SkSurface::kFlushRead_BackendHandleAccess); |
| 597 | if (backendRenderTarget.isValid()) { |
| 598 | GrVkImageInfo info; |
| 599 | if (backendRenderTarget.getVkImageInfo(&info)) { |
| 600 | image = info.fImage; |
| 601 | } else { |
| 602 | ALOGE("Frame boundary: backend is not vulkan"); |
| 603 | } |
| 604 | } else { |
| 605 | ALOGE("Frame boundary: invalid backend render target"); |
| 606 | } |
| 607 | // frameBoundaryANDROID needs to know about mSwapSemaphore, but |
| 608 | // it won't wait on it. |
| 609 | mFrameBoundaryANDROID(mDevice, mSwapSemaphore, image); |
| 610 | } |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 611 | } else { |
| 612 | destroy_semaphore(mDestroySemaphoreContext); |
| 613 | mDestroySemaphoreContext = nullptr; |
| 614 | } |
| 615 | } |
| 616 | skiapipeline::ShaderCache::get().onVkFrameFlushed(context); |
Alec Mouri | 3afb397 | 2022-05-27 22:03:11 +0000 | [diff] [blame] | 617 | |
| 618 | return submissionTime; |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect) { |
| 622 | if (CC_UNLIKELY(Properties::waitForGpuCompletion)) { |
| 623 | ATRACE_NAME("Finishing GPU work"); |
| 624 | mDeviceWaitIdle(mDevice); |
| 625 | } |
| 626 | |
| 627 | int fenceFd = -1; |
| 628 | if (mSwapSemaphore != VK_NULL_HANDLE) { |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 629 | VkSemaphoreGetFdInfoKHR getFdInfo; |
| 630 | getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR; |
| 631 | getFdInfo.pNext = nullptr; |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 632 | getFdInfo.semaphore = mSwapSemaphore; |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 633 | getFdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 634 | |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 635 | VkResult err = mGetSemaphoreFdKHR(mDevice, &getFdInfo, &fenceFd); |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 636 | ALOGE_IF(VK_SUCCESS != err, "VulkanManager::swapBuffers(): Failed to get semaphore Fd"); |
| 637 | } else { |
| 638 | ALOGE("VulkanManager::swapBuffers(): Semaphore submission failed"); |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 639 | |
| 640 | std::lock_guard<std::mutex> lock(mGraphicsQueueMutex); |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 641 | mQueueWaitIdle(mGraphicsQueue); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 642 | } |
Greg Daniel | e8dc397 | 2021-07-15 13:38:44 -0400 | [diff] [blame] | 643 | if (mDestroySemaphoreContext) { |
| 644 | destroy_semaphore(mDestroySemaphoreContext); |
| 645 | } |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 646 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 647 | surface->presentCurrentBuffer(dirtyRect, fenceFd); |
Greg Daniel | be2803a | 2021-02-19 18:32:16 -0500 | [diff] [blame] | 648 | mSwapSemaphore = VK_NULL_HANDLE; |
| 649 | mDestroySemaphoreContext = nullptr; |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void VulkanManager::destroySurface(VulkanSurface* surface) { |
| 653 | // Make sure all submit commands have finished before starting to destroy objects. |
Yiwei Zhang | 276d5fc | 2020-09-03 12:00:00 -0700 | [diff] [blame] | 654 | if (VK_NULL_HANDLE != mGraphicsQueue) { |
Alec Mouri | aa3e498 | 2020-12-14 14:47:57 -0800 | [diff] [blame] | 655 | std::lock_guard<std::mutex> lock(mGraphicsQueueMutex); |
Yiwei Zhang | 276d5fc | 2020-09-03 12:00:00 -0700 | [diff] [blame] | 656 | mQueueWaitIdle(mGraphicsQueue); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 657 | } |
Greg Daniel | 2ff20271 | 2018-06-14 11:50:10 -0400 | [diff] [blame] | 658 | mDeviceWaitIdle(mDevice); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 659 | |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 660 | delete surface; |
| 661 | } |
| 662 | |
Adlai Holler | f8c434e | 2020-07-27 11:42:45 -0400 | [diff] [blame] | 663 | VulkanSurface* VulkanManager::createSurface(ANativeWindow* window, |
| 664 | ColorMode colorMode, |
Peiyong Lin | 3bff135 | 2018-12-11 07:56:07 -0800 | [diff] [blame] | 665 | sk_sp<SkColorSpace> surfaceColorSpace, |
Adlai Holler | f8c434e | 2020-07-27 11:42:45 -0400 | [diff] [blame] | 666 | SkColorType surfaceColorType, |
| 667 | GrDirectContext* grContext, |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 668 | uint32_t extraBuffers) { |
Stan Iliev | 981afe7 | 2019-02-13 14:24:33 -0500 | [diff] [blame] | 669 | LOG_ALWAYS_FATAL_IF(!hasVkContext(), "Not initialized"); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 670 | if (!window) { |
| 671 | return nullptr; |
| 672 | } |
| 673 | |
Derek Sollenberger | a19b71a | 2019-02-15 16:36:30 -0500 | [diff] [blame] | 674 | return VulkanSurface::Create(window, colorMode, surfaceColorType, surfaceColorSpace, grContext, |
John Reck | 0fa0cbc | 2019-04-05 16:57:46 -0700 | [diff] [blame] | 675 | *this, extraBuffers); |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 676 | } |
| 677 | |
Adlai Holler | f8c434e | 2020-07-27 11:42:45 -0400 | [diff] [blame] | 678 | status_t VulkanManager::fenceWait(int fence, GrDirectContext* grContext) { |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 679 | if (!hasVkContext()) { |
| 680 | ALOGE("VulkanManager::fenceWait: VkDevice not initialized"); |
| 681 | return INVALID_OPERATION; |
| 682 | } |
| 683 | |
Stan Iliev | 7a08127 | 2018-10-26 17:54:18 -0400 | [diff] [blame] | 684 | // Block GPU on the fence. |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 685 | int fenceFd = ::dup(fence); |
Stan Iliev | 7a08127 | 2018-10-26 17:54:18 -0400 | [diff] [blame] | 686 | if (fenceFd == -1) { |
| 687 | ALOGE("VulkanManager::fenceWait: error dup'ing fence fd: %d", errno); |
| 688 | return -errno; |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 689 | } |
Stan Iliev | 7a08127 | 2018-10-26 17:54:18 -0400 | [diff] [blame] | 690 | |
| 691 | VkSemaphoreCreateInfo semaphoreInfo; |
| 692 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 693 | semaphoreInfo.pNext = nullptr; |
| 694 | semaphoreInfo.flags = 0; |
| 695 | VkSemaphore semaphore; |
| 696 | VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore); |
| 697 | if (VK_SUCCESS != err) { |
Greg Daniel | d667077 | 2021-06-09 12:01:12 -0400 | [diff] [blame] | 698 | close(fenceFd); |
Stan Iliev | 7a08127 | 2018-10-26 17:54:18 -0400 | [diff] [blame] | 699 | ALOGE("Failed to create import semaphore, err: %d", err); |
| 700 | return UNKNOWN_ERROR; |
| 701 | } |
| 702 | VkImportSemaphoreFdInfoKHR importInfo; |
| 703 | importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR; |
| 704 | importInfo.pNext = nullptr; |
| 705 | importInfo.semaphore = semaphore; |
| 706 | importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT; |
| 707 | importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; |
| 708 | importInfo.fd = fenceFd; |
| 709 | |
| 710 | err = mImportSemaphoreFdKHR(mDevice, &importInfo); |
| 711 | if (VK_SUCCESS != err) { |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 712 | mDestroySemaphore(mDevice, semaphore, nullptr); |
Greg Daniel | d667077 | 2021-06-09 12:01:12 -0400 | [diff] [blame] | 713 | close(fenceFd); |
Stan Iliev | 7a08127 | 2018-10-26 17:54:18 -0400 | [diff] [blame] | 714 | ALOGE("Failed to import semaphore, err: %d", err); |
| 715 | return UNKNOWN_ERROR; |
| 716 | } |
| 717 | |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 718 | GrBackendSemaphore beSemaphore; |
| 719 | beSemaphore.initVulkan(semaphore); |
Stan Iliev | 7a08127 | 2018-10-26 17:54:18 -0400 | [diff] [blame] | 720 | |
Greg Daniel | d667077 | 2021-06-09 12:01:12 -0400 | [diff] [blame] | 721 | // Skia will take ownership of the VkSemaphore and delete it once the wait has finished. The |
| 722 | // VkSemaphore also owns the imported fd, so it will close the fd when it is deleted. |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 723 | grContext->wait(1, &beSemaphore); |
Greg Daniel | c7ad408 | 2020-05-14 15:38:26 -0400 | [diff] [blame] | 724 | grContext->flushAndSubmit(); |
Stan Iliev | 7a08127 | 2018-10-26 17:54:18 -0400 | [diff] [blame] | 725 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 726 | return OK; |
| 727 | } |
| 728 | |
Adlai Holler | f8c434e | 2020-07-27 11:42:45 -0400 | [diff] [blame] | 729 | status_t VulkanManager::createReleaseFence(int* nativeFence, GrDirectContext* grContext) { |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 730 | *nativeFence = -1; |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 731 | if (!hasVkContext()) { |
| 732 | ALOGE("VulkanManager::createReleaseFence: VkDevice not initialized"); |
| 733 | return INVALID_OPERATION; |
| 734 | } |
| 735 | |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 736 | VkExportSemaphoreCreateInfo exportInfo; |
| 737 | exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO; |
| 738 | exportInfo.pNext = nullptr; |
| 739 | exportInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; |
| 740 | |
| 741 | VkSemaphoreCreateInfo semaphoreInfo; |
| 742 | semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; |
| 743 | semaphoreInfo.pNext = &exportInfo; |
| 744 | semaphoreInfo.flags = 0; |
| 745 | VkSemaphore semaphore; |
| 746 | VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore); |
| 747 | if (VK_SUCCESS != err) { |
| 748 | ALOGE("VulkanManager::createReleaseFence: Failed to create semaphore"); |
| 749 | return INVALID_OPERATION; |
| 750 | } |
| 751 | |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 752 | GrBackendSemaphore backendSemaphore; |
| 753 | backendSemaphore.initVulkan(semaphore); |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 754 | |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 755 | DestroySemaphoreInfo* destroyInfo = |
| 756 | new DestroySemaphoreInfo(mDestroySemaphore, mDevice, semaphore); |
Greg Daniel | fd42939 | 2019-05-09 15:44:56 -0400 | [diff] [blame] | 757 | // Even if Skia fails to submit the semaphore, it will still call the destroy_semaphore callback |
| 758 | // which will remove its ref to the semaphore. The VulkanManager must still release its ref, |
| 759 | // when it is done with the semaphore. |
Greg Daniel | c7ad408 | 2020-05-14 15:38:26 -0400 | [diff] [blame] | 760 | GrFlushInfo flushInfo; |
| 761 | flushInfo.fNumSemaphores = 1; |
| 762 | flushInfo.fSignalSemaphores = &backendSemaphore; |
| 763 | flushInfo.fFinishedProc = destroy_semaphore; |
| 764 | flushInfo.fFinishedContext = destroyInfo; |
| 765 | GrSemaphoresSubmitted submitted = grContext->flush(flushInfo); |
| 766 | grContext->submit(); |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 767 | |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 768 | if (submitted == GrSemaphoresSubmitted::kNo) { |
| 769 | ALOGE("VulkanManager::createReleaseFence: Failed to submit semaphore"); |
Greg Daniel | fd42939 | 2019-05-09 15:44:56 -0400 | [diff] [blame] | 770 | destroy_semaphore(destroyInfo); |
Greg Daniel | d92a9b1 | 2019-04-23 10:11:04 -0400 | [diff] [blame] | 771 | return INVALID_OPERATION; |
| 772 | } |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 773 | |
| 774 | VkSemaphoreGetFdInfoKHR getFdInfo; |
| 775 | getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR; |
| 776 | getFdInfo.pNext = nullptr; |
| 777 | getFdInfo.semaphore = semaphore; |
| 778 | getFdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT; |
| 779 | |
| 780 | int fenceFd = 0; |
| 781 | |
| 782 | err = mGetSemaphoreFdKHR(mDevice, &getFdInfo, &fenceFd); |
Greg Daniel | fd42939 | 2019-05-09 15:44:56 -0400 | [diff] [blame] | 783 | destroy_semaphore(destroyInfo); |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 784 | if (VK_SUCCESS != err) { |
| 785 | ALOGE("VulkanManager::createReleaseFence: Failed to get semaphore Fd"); |
| 786 | return INVALID_OPERATION; |
| 787 | } |
Stan Iliev | aaa9e83 | 2019-09-17 14:07:23 -0400 | [diff] [blame] | 788 | *nativeFence = fenceFd; |
Greg Daniel | 26e0dca | 2018-09-18 10:33:19 -0400 | [diff] [blame] | 789 | |
Stan Iliev | 564ca3e | 2018-09-04 22:00:00 +0000 | [diff] [blame] | 790 | return OK; |
| 791 | } |
| 792 | |
Derek Sollenberger | 0e3cba3 | 2016-11-09 11:58:36 -0500 | [diff] [blame] | 793 | } /* namespace renderthread */ |
| 794 | } /* namespace uirenderer */ |
| 795 | } /* namespace android */ |