blob: 4dbce92ed01c97aba5357fbdfba9ebc14e88b624 [file] [log] [blame]
Derek Sollenberger0e3cba32016-11-09 11:58:36 -05001/*
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 Mouri6db59a62019-08-02 17:05:26 -070019#include <EGL/egl.h>
20#include <EGL/eglext.h>
Stan Ilievaaa9e832019-09-17 14:07:23 -040021#include <GrBackendSemaphore.h>
22#include <GrBackendSurface.h>
Adlai Hollerf8c434e2020-07-27 11:42:45 -040023#include <GrDirectContext.h>
Stan Ilievaaa9e832019-09-17 14:07:23 -040024#include <GrTypes.h>
25#include <android/sync.h>
Jagadeesh Pakaravoorb624af32020-05-01 00:01:40 +000026#include <ui/FatVector.h>
Stan Ilievaaa9e832019-09-17 14:07:23 -040027#include <vk/GrVkExtensions.h>
28#include <vk/GrVkTypes.h>
Stan Iliev305e13a2018-11-13 11:14:48 -050029
Greg Danielcd558522016-11-17 13:31:40 -050030#include "Properties.h"
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050031#include "RenderThread.h"
Greg Daniel45ec62b2017-01-04 14:27:00 -050032#include "renderstate/RenderState.h"
John Reck322b8ab2019-03-14 13:15:28 -070033#include "utils/TraceUtils.h"
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050034
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050035namespace android {
36namespace uirenderer {
37namespace renderthread {
38
Bo Liu7b8c1eb2019-01-08 20:17:55 -080039static void free_features_extensions_structs(const VkPhysicalDeviceFeatures2& features) {
40 // All Vulkan structs that could be part of the features chain will start with the
41 // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader
42 // so we can get access to the pNext for the next struct.
43 struct CommonVulkanHeader {
44 VkStructureType sType;
John Reck0fa0cbc2019-04-05 16:57:46 -070045 void* pNext;
Bo Liu7b8c1eb2019-01-08 20:17:55 -080046 };
47
48 void* pNext = features.pNext;
49 while (pNext) {
50 void* current = pNext;
51 pNext = static_cast<CommonVulkanHeader*>(current)->pNext;
52 free(current);
53 }
54}
55
Greg Daniel2ff202712018-06-14 11:50:10 -040056#define GET_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(VK_NULL_HANDLE, "vk" #F)
57#define GET_INST_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(mInstance, "vk" #F)
58#define GET_DEV_PROC(F) m##F = (PFN_vk##F)vkGetDeviceProcAddr(mDevice, "vk" #F)
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050059
Derek Sollenberger802fefa2020-08-13 16:53:30 -040060sp<VulkanManager> VulkanManager::getInstance() {
61 // cache a weakptr to the context to enable a second thread to share the same vulkan state
62 static wp<VulkanManager> sWeakInstance = nullptr;
63 static std::mutex sLock;
64
65 std::lock_guard _lock{sLock};
66 sp<VulkanManager> vulkanManager = sWeakInstance.promote();
67 if (!vulkanManager.get()) {
68 vulkanManager = new VulkanManager();
69 sWeakInstance = vulkanManager;
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050070 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050071
Derek Sollenberger802fefa2020-08-13 16:53:30 -040072 return vulkanManager;
73}
74
75VulkanManager::~VulkanManager() {
Greg Daniel2ff202712018-06-14 11:50:10 -040076 if (mDevice != VK_NULL_HANDLE) {
77 mDeviceWaitIdle(mDevice);
78 mDestroyDevice(mDevice, nullptr);
John Reck1bcacfd2017-11-03 10:12:19 -070079 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050080
Greg Daniel2ff202712018-06-14 11:50:10 -040081 if (mInstance != VK_NULL_HANDLE) {
82 mDestroyInstance(mInstance, nullptr);
83 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050084
Greg Daniel2ff202712018-06-14 11:50:10 -040085 mGraphicsQueue = VK_NULL_HANDLE;
Derek Sollenberger802fefa2020-08-13 16:53:30 -040086 mAHBUploadQueue = VK_NULL_HANDLE;
Greg Daniel2ff202712018-06-14 11:50:10 -040087 mDevice = VK_NULL_HANDLE;
88 mPhysicalDevice = VK_NULL_HANDLE;
89 mInstance = VK_NULL_HANDLE;
Roman Kiryanov74ace839e2019-03-07 18:22:19 -080090 mInstanceExtensionsOwner.clear();
Bo Liu7b8c1eb2019-01-08 20:17:55 -080091 mInstanceExtensions.clear();
Roman Kiryanov74ace839e2019-03-07 18:22:19 -080092 mDeviceExtensionsOwner.clear();
Bo Liu7b8c1eb2019-01-08 20:17:55 -080093 mDeviceExtensions.clear();
94 free_features_extensions_structs(mPhysicalDeviceFeatures2);
95 mPhysicalDeviceFeatures2 = {};
Greg Daniel2ff202712018-06-14 11:50:10 -040096}
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050097
Stan Iliev90276c82019-02-03 18:01:02 -050098void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFeatures2& features) {
Greg Daniel2ff202712018-06-14 11:50:10 -040099 VkResult err;
100
101 constexpr VkApplicationInfo app_info = {
John Reck0fa0cbc2019-04-05 16:57:46 -0700102 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType
103 nullptr, // pNext
104 "android framework", // pApplicationName
105 0, // applicationVersion
106 "android framework", // pEngineName
107 0, // engineVerison
108 mAPIVersion, // apiVersion
Greg Daniel2ff202712018-06-14 11:50:10 -0400109 };
110
Greg Daniel2ff202712018-06-14 11:50:10 -0400111 {
112 GET_PROC(EnumerateInstanceExtensionProperties);
113
114 uint32_t extensionCount = 0;
115 err = mEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
Stan Iliev90276c82019-02-03 18:01:02 -0500116 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800117 mInstanceExtensionsOwner.resize(extensionCount);
118 err = mEnumerateInstanceExtensionProperties(nullptr, &extensionCount,
119 mInstanceExtensionsOwner.data());
Stan Iliev90276c82019-02-03 18:01:02 -0500120 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Greg Daniel2ff202712018-06-14 11:50:10 -0400121 bool hasKHRSurfaceExtension = false;
122 bool hasKHRAndroidSurfaceExtension = false;
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800123 for (const VkExtensionProperties& extension : mInstanceExtensionsOwner) {
124 mInstanceExtensions.push_back(extension.extensionName);
125 if (!strcmp(extension.extensionName, VK_KHR_SURFACE_EXTENSION_NAME)) {
Greg Daniel2ff202712018-06-14 11:50:10 -0400126 hasKHRSurfaceExtension = true;
127 }
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800128 if (!strcmp(extension.extensionName, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME)) {
Greg Daniel2ff202712018-06-14 11:50:10 -0400129 hasKHRAndroidSurfaceExtension = true;
130 }
131 }
Stan Iliev90276c82019-02-03 18:01:02 -0500132 LOG_ALWAYS_FATAL_IF(!hasKHRSurfaceExtension || !hasKHRAndroidSurfaceExtension);
Greg Daniel2ff202712018-06-14 11:50:10 -0400133 }
134
135 const VkInstanceCreateInfo instance_create = {
John Reck0fa0cbc2019-04-05 16:57:46 -0700136 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType
137 nullptr, // pNext
138 0, // flags
139 &app_info, // pApplicationInfo
140 0, // enabledLayerNameCount
141 nullptr, // ppEnabledLayerNames
142 (uint32_t)mInstanceExtensions.size(), // enabledExtensionNameCount
143 mInstanceExtensions.data(), // ppEnabledExtensionNames
Greg Daniel2ff202712018-06-14 11:50:10 -0400144 };
145
146 GET_PROC(CreateInstance);
147 err = mCreateInstance(&instance_create, nullptr, &mInstance);
Stan Iliev90276c82019-02-03 18:01:02 -0500148 LOG_ALWAYS_FATAL_IF(err < 0);
Greg Daniel2ff202712018-06-14 11:50:10 -0400149
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700150 GET_INST_PROC(CreateDevice);
Greg Daniel2ff202712018-06-14 11:50:10 -0400151 GET_INST_PROC(DestroyInstance);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700152 GET_INST_PROC(EnumerateDeviceExtensionProperties);
Greg Daniel2ff202712018-06-14 11:50:10 -0400153 GET_INST_PROC(EnumeratePhysicalDevices);
Greg Daniela227dbb2018-08-20 09:19:48 -0400154 GET_INST_PROC(GetPhysicalDeviceFeatures2);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500155 GET_INST_PROC(GetPhysicalDeviceImageFormatProperties2);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700156 GET_INST_PROC(GetPhysicalDeviceProperties);
157 GET_INST_PROC(GetPhysicalDeviceQueueFamilyProperties);
Greg Daniel2ff202712018-06-14 11:50:10 -0400158
159 uint32_t gpuCount;
Stan Iliev90276c82019-02-03 18:01:02 -0500160 LOG_ALWAYS_FATAL_IF(mEnumeratePhysicalDevices(mInstance, &gpuCount, nullptr));
161 LOG_ALWAYS_FATAL_IF(!gpuCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400162 // Just returning the first physical device instead of getting the whole array. Since there
163 // should only be one device on android.
164 gpuCount = 1;
165 err = mEnumeratePhysicalDevices(mInstance, &gpuCount, &mPhysicalDevice);
166 // VK_INCOMPLETE is returned when the count we provide is less than the total device count.
Stan Iliev90276c82019-02-03 18:01:02 -0500167 LOG_ALWAYS_FATAL_IF(err && VK_INCOMPLETE != err);
Greg Daniel2ff202712018-06-14 11:50:10 -0400168
Greg Daniel96259622018-10-01 14:42:56 -0400169 VkPhysicalDeviceProperties physDeviceProperties;
170 mGetPhysicalDeviceProperties(mPhysicalDevice, &physDeviceProperties);
Stan Iliev90276c82019-02-03 18:01:02 -0500171 LOG_ALWAYS_FATAL_IF(physDeviceProperties.apiVersion < VK_MAKE_VERSION(1, 1, 0));
Stan Ilievbf99c442019-03-29 11:09:11 -0400172 mDriverVersion = physDeviceProperties.driverVersion;
Greg Daniel96259622018-10-01 14:42:56 -0400173
Greg Daniel2ff202712018-06-14 11:50:10 -0400174 // query to get the initial queue props size
175 uint32_t queueCount;
176 mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr);
Stan Iliev90276c82019-02-03 18:01:02 -0500177 LOG_ALWAYS_FATAL_IF(!queueCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400178
179 // now get the actual queue props
180 std::unique_ptr<VkQueueFamilyProperties[]> queueProps(new VkQueueFamilyProperties[queueCount]);
181 mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, queueProps.get());
182
183 // iterate to find the graphics queue
184 mGraphicsQueueIndex = queueCount;
185 for (uint32_t i = 0; i < queueCount; i++) {
186 if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
187 mGraphicsQueueIndex = i;
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400188 LOG_ALWAYS_FATAL_IF(queueProps[i].queueCount < 2);
Greg Daniel2ff202712018-06-14 11:50:10 -0400189 break;
190 }
191 }
Stan Iliev90276c82019-02-03 18:01:02 -0500192 LOG_ALWAYS_FATAL_IF(mGraphicsQueueIndex == queueCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400193
Greg Daniel2ff202712018-06-14 11:50:10 -0400194 {
195 uint32_t extensionCount = 0;
196 err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount,
John Reck0fa0cbc2019-04-05 16:57:46 -0700197 nullptr);
Stan Iliev90276c82019-02-03 18:01:02 -0500198 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800199 mDeviceExtensionsOwner.resize(extensionCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400200 err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount,
John Reck0fa0cbc2019-04-05 16:57:46 -0700201 mDeviceExtensionsOwner.data());
Stan Iliev90276c82019-02-03 18:01:02 -0500202 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Greg Daniel2ff202712018-06-14 11:50:10 -0400203 bool hasKHRSwapchainExtension = false;
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800204 for (const VkExtensionProperties& extension : mDeviceExtensionsOwner) {
205 mDeviceExtensions.push_back(extension.extensionName);
206 if (!strcmp(extension.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
Greg Daniel2ff202712018-06-14 11:50:10 -0400207 hasKHRSwapchainExtension = true;
208 }
209 }
Stan Iliev90276c82019-02-03 18:01:02 -0500210 LOG_ALWAYS_FATAL_IF(!hasKHRSwapchainExtension);
Greg Daniel2ff202712018-06-14 11:50:10 -0400211 }
212
John Reck0fa0cbc2019-04-05 16:57:46 -0700213 auto getProc = [](const char* proc_name, VkInstance instance, VkDevice device) {
Greg Daniela227dbb2018-08-20 09:19:48 -0400214 if (device != VK_NULL_HANDLE) {
215 return vkGetDeviceProcAddr(device, proc_name);
216 }
217 return vkGetInstanceProcAddr(instance, proc_name);
218 };
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800219
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800220 grExtensions.init(getProc, mInstance, mPhysicalDevice, mInstanceExtensions.size(),
John Reck0fa0cbc2019-04-05 16:57:46 -0700221 mInstanceExtensions.data(), mDeviceExtensions.size(),
222 mDeviceExtensions.data());
Greg Daniela227dbb2018-08-20 09:19:48 -0400223
Stan Iliev90276c82019-02-03 18:01:02 -0500224 LOG_ALWAYS_FATAL_IF(!grExtensions.hasExtension(VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, 1));
Greg Daniel26e0dca2018-09-18 10:33:19 -0400225
Greg Daniela227dbb2018-08-20 09:19:48 -0400226 memset(&features, 0, sizeof(VkPhysicalDeviceFeatures2));
227 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
228 features.pNext = nullptr;
229
230 // Setup all extension feature structs we may want to use.
231 void** tailPNext = &features.pNext;
232
233 if (grExtensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2)) {
234 VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT* blend;
John Reck0fa0cbc2019-04-05 16:57:46 -0700235 blend = (VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT*)malloc(
Greg Daniela227dbb2018-08-20 09:19:48 -0400236 sizeof(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT));
237 LOG_ALWAYS_FATAL_IF(!blend);
238 blend->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT;
239 blend->pNext = nullptr;
240 *tailPNext = blend;
241 tailPNext = &blend->pNext;
242 }
243
Greg Daniel05036172018-11-28 17:08:04 -0500244 VkPhysicalDeviceSamplerYcbcrConversionFeatures* ycbcrFeature;
John Reck0fa0cbc2019-04-05 16:57:46 -0700245 ycbcrFeature = (VkPhysicalDeviceSamplerYcbcrConversionFeatures*)malloc(
Greg Daniel05036172018-11-28 17:08:04 -0500246 sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
247 LOG_ALWAYS_FATAL_IF(!ycbcrFeature);
248 ycbcrFeature->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
249 ycbcrFeature->pNext = nullptr;
250 *tailPNext = ycbcrFeature;
251 tailPNext = &ycbcrFeature->pNext;
252
Greg Daniela227dbb2018-08-20 09:19:48 -0400253 // query to get the physical device features
254 mGetPhysicalDeviceFeatures2(mPhysicalDevice, &features);
Greg Daniel2ff202712018-06-14 11:50:10 -0400255 // this looks like it would slow things down,
256 // and we can't depend on it on all platforms
Greg Daniela227dbb2018-08-20 09:19:48 -0400257 features.features.robustBufferAccess = VK_FALSE;
Greg Daniel2ff202712018-06-14 11:50:10 -0400258
John Reck0fa0cbc2019-04-05 16:57:46 -0700259 float queuePriorities[1] = {0.0};
Greg Daniel2ff202712018-06-14 11:50:10 -0400260
Stan Iliev7e733362019-02-28 13:16:36 -0500261 void* queueNextPtr = nullptr;
262
263 VkDeviceQueueGlobalPriorityCreateInfoEXT queuePriorityCreateInfo;
264
John Reck0fa0cbc2019-04-05 16:57:46 -0700265 if (Properties::contextPriority != 0 &&
266 grExtensions.hasExtension(VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME, 2)) {
Stan Iliev7e733362019-02-28 13:16:36 -0500267 memset(&queuePriorityCreateInfo, 0, sizeof(VkDeviceQueueGlobalPriorityCreateInfoEXT));
268 queuePriorityCreateInfo.sType =
John Reck0fa0cbc2019-04-05 16:57:46 -0700269 VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT;
Stan Iliev7e733362019-02-28 13:16:36 -0500270 queuePriorityCreateInfo.pNext = nullptr;
271 switch (Properties::contextPriority) {
272 case EGL_CONTEXT_PRIORITY_LOW_IMG:
273 queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT;
274 break;
275 case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
276 queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT;
277 break;
278 case EGL_CONTEXT_PRIORITY_HIGH_IMG:
279 queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT;
280 break;
281 default:
282 LOG_ALWAYS_FATAL("Unsupported context priority");
John Reck0fa0cbc2019-04-05 16:57:46 -0700283 }
284 queueNextPtr = &queuePriorityCreateInfo;
Stan Iliev7e733362019-02-28 13:16:36 -0500285 }
286
Yiwei Zhang276d5fc2020-09-03 12:00:00 -0700287 const VkDeviceQueueCreateInfo queueInfo = {
288 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
289 queueNextPtr, // pNext
290 0, // VkDeviceQueueCreateFlags
291 mGraphicsQueueIndex, // queueFamilyIndex
292 2, // queueCount
293 queuePriorities, // pQueuePriorities
294 };
Greg Daniel2ff202712018-06-14 11:50:10 -0400295
296 const VkDeviceCreateInfo deviceInfo = {
John Reck0fa0cbc2019-04-05 16:57:46 -0700297 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
298 &features, // pNext
299 0, // VkDeviceCreateFlags
Yiwei Zhang276d5fc2020-09-03 12:00:00 -0700300 1, // queueCreateInfoCount
301 &queueInfo, // pQueueCreateInfos
John Reck0fa0cbc2019-04-05 16:57:46 -0700302 0, // layerCount
303 nullptr, // ppEnabledLayerNames
304 (uint32_t)mDeviceExtensions.size(), // extensionCount
305 mDeviceExtensions.data(), // ppEnabledExtensionNames
306 nullptr, // ppEnabledFeatures
Greg Daniel2ff202712018-06-14 11:50:10 -0400307 };
308
Stan Iliev90276c82019-02-03 18:01:02 -0500309 LOG_ALWAYS_FATAL_IF(mCreateDevice(mPhysicalDevice, &deviceInfo, nullptr, &mDevice));
Greg Daniel2ff202712018-06-14 11:50:10 -0400310
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500311 GET_DEV_PROC(AllocateCommandBuffers);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500312 GET_DEV_PROC(BeginCommandBuffer);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500313 GET_DEV_PROC(CmdPipelineBarrier);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700314 GET_DEV_PROC(CreateCommandPool);
315 GET_DEV_PROC(CreateFence);
316 GET_DEV_PROC(CreateSemaphore);
317 GET_DEV_PROC(DestroyCommandPool);
318 GET_DEV_PROC(DestroyDevice);
319 GET_DEV_PROC(DestroyFence);
320 GET_DEV_PROC(DestroySemaphore);
321 GET_DEV_PROC(DeviceWaitIdle);
322 GET_DEV_PROC(EndCommandBuffer);
323 GET_DEV_PROC(FreeCommandBuffers);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500324 GET_DEV_PROC(GetDeviceQueue);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700325 GET_DEV_PROC(GetSemaphoreFdKHR);
326 GET_DEV_PROC(ImportSemaphoreFdKHR);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500327 GET_DEV_PROC(QueueSubmit);
328 GET_DEV_PROC(QueueWaitIdle);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700329 GET_DEV_PROC(ResetCommandBuffer);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500330 GET_DEV_PROC(ResetFences);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700331 GET_DEV_PROC(WaitForFences);
Greg Daniel2ff202712018-06-14 11:50:10 -0400332}
333
334void VulkanManager::initialize() {
335 if (mDevice != VK_NULL_HANDLE) {
336 return;
337 }
338
Greg Daniela227dbb2018-08-20 09:19:48 -0400339 GET_PROC(EnumerateInstanceVersion);
Greg Danieleaf310e2019-01-28 16:10:32 -0500340 uint32_t instanceVersion;
341 LOG_ALWAYS_FATAL_IF(mEnumerateInstanceVersion(&instanceVersion));
342 LOG_ALWAYS_FATAL_IF(instanceVersion < VK_MAKE_VERSION(1, 1, 0));
Greg Daniela227dbb2018-08-20 09:19:48 -0400343
Stan Iliev981afe72019-02-13 14:24:33 -0500344 this->setupDevice(mExtensions, mPhysicalDeviceFeatures2);
Greg Daniel2ff202712018-06-14 11:50:10 -0400345
346 mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 0, &mGraphicsQueue);
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400347 mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 1, &mAHBUploadQueue);
Greg Daniel2ff202712018-06-14 11:50:10 -0400348
Greg Danielcd558522016-11-17 13:31:40 -0500349 if (Properties::enablePartialUpdates && Properties::useBufferAge) {
350 mSwapBehavior = SwapBehavior::BufferAge;
351 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500352}
353
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400354sk_sp<GrDirectContext> VulkanManager::createContext(const GrContextOptions& options,
355 ContextType contextType) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700356 auto getProc = [](const char* proc_name, VkInstance instance, VkDevice device) {
Stan Iliev981afe72019-02-13 14:24:33 -0500357 if (device != VK_NULL_HANDLE) {
358 return vkGetDeviceProcAddr(device, proc_name);
359 }
360 return vkGetInstanceProcAddr(instance, proc_name);
361 };
362
363 GrVkBackendContext backendContext;
364 backendContext.fInstance = mInstance;
365 backendContext.fPhysicalDevice = mPhysicalDevice;
366 backendContext.fDevice = mDevice;
Derek Sollenberger802fefa2020-08-13 16:53:30 -0400367 backendContext.fQueue = (contextType == ContextType::kRenderThread) ? mGraphicsQueue
368 : mAHBUploadQueue;
Stan Iliev981afe72019-02-13 14:24:33 -0500369 backendContext.fGraphicsQueueIndex = mGraphicsQueueIndex;
370 backendContext.fMaxAPIVersion = mAPIVersion;
371 backendContext.fVkExtensions = &mExtensions;
372 backendContext.fDeviceFeatures2 = &mPhysicalDeviceFeatures2;
373 backendContext.fGetProc = std::move(getProc);
374
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400375 return GrDirectContext::MakeVulkan(backendContext, options);
Stan Iliev981afe72019-02-13 14:24:33 -0500376}
377
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800378VkFunctorInitParams VulkanManager::getVkFunctorInitParams() const {
379 return VkFunctorInitParams{
380 .instance = mInstance,
381 .physical_device = mPhysicalDevice,
382 .device = mDevice,
383 .queue = mGraphicsQueue,
384 .graphics_queue_index = mGraphicsQueueIndex,
Greg Danieleaf310e2019-01-28 16:10:32 -0500385 .api_version = mAPIVersion,
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800386 .enabled_instance_extension_names = mInstanceExtensions.data(),
387 .enabled_instance_extension_names_length =
388 static_cast<uint32_t>(mInstanceExtensions.size()),
389 .enabled_device_extension_names = mDeviceExtensions.data(),
390 .enabled_device_extension_names_length =
391 static_cast<uint32_t>(mDeviceExtensions.size()),
392 .device_features_2 = &mPhysicalDeviceFeatures2,
393 };
394}
395
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500396Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) {
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500397 VulkanSurface::NativeBufferInfo* bufferInfo = surface->dequeueNativeBuffer();
398
399 if (bufferInfo == nullptr) {
400 ALOGE("VulkanSurface::dequeueNativeBuffer called with an invalid surface!");
401 return Frame(-1, -1, 0);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500402 }
403
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500404 LOG_ALWAYS_FATAL_IF(!bufferInfo->dequeued);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500405
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500406 if (bufferInfo->dequeue_fence != -1) {
Stan Iliev197843d2019-03-21 11:34:15 -0400407 struct sync_file_info* finfo = sync_file_info(bufferInfo->dequeue_fence);
408 bool isSignalPending = false;
409 if (finfo != NULL) {
410 isSignalPending = finfo->status != 1;
411 sync_file_info_free(finfo);
412 }
413 if (isSignalPending) {
414 int fence_clone = dup(bufferInfo->dequeue_fence);
415 if (fence_clone == -1) {
416 ALOGE("dup(fence) failed, stalling until signalled: %s (%d)", strerror(errno),
417 errno);
418 sync_wait(bufferInfo->dequeue_fence, -1 /* forever */);
419 } else {
420 VkSemaphoreCreateInfo semaphoreInfo;
421 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
422 semaphoreInfo.pNext = nullptr;
423 semaphoreInfo.flags = 0;
424 VkSemaphore semaphore;
425 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
426 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err, "Failed to create import semaphore, err: %d",
427 err);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500428
Stan Iliev197843d2019-03-21 11:34:15 -0400429 VkImportSemaphoreFdInfoKHR importInfo;
430 importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
431 importInfo.pNext = nullptr;
432 importInfo.semaphore = semaphore;
433 importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT;
434 importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
435 importInfo.fd = fence_clone;
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500436
Stan Iliev197843d2019-03-21 11:34:15 -0400437 err = mImportSemaphoreFdKHR(mDevice, &importInfo);
438 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err, "Failed to import semaphore, err: %d", err);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500439
Stan Iliev197843d2019-03-21 11:34:15 -0400440 GrBackendSemaphore backendSemaphore;
441 backendSemaphore.initVulkan(semaphore);
442 bufferInfo->skSurface->wait(1, &backendSemaphore);
443 // The following flush blocks the GPU immediately instead of waiting for other
444 // drawing ops. It seems dequeue_fence is not respected otherwise.
John Reck0fa0cbc2019-04-05 16:57:46 -0700445 // TODO: remove the flush after finding why backendSemaphore is not working.
Greg Danielc7ad4082020-05-14 15:38:26 -0400446 bufferInfo->skSurface->flushAndSubmit();
Stan Iliev197843d2019-03-21 11:34:15 -0400447 }
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500448 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500449 }
450
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500451 int bufferAge = (mSwapBehavior == SwapBehavior::Discard) ? 0 : surface->getCurrentBuffersAge();
452 return Frame(surface->logicalWidth(), surface->logicalHeight(), bufferAge);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500453}
454
Greg Danield92a9b12019-04-23 10:11:04 -0400455struct DestroySemaphoreInfo {
456 PFN_vkDestroySemaphore mDestroyFunction;
457 VkDevice mDevice;
458 VkSemaphore mSemaphore;
Greg Danielfd429392019-05-09 15:44:56 -0400459 // We need to make sure we don't delete the VkSemaphore until it is done being used by both Skia
460 // (including by the GPU) and inside the VulkanManager. So we always start with two refs, one
461 // owned by Skia and one owned by the VulkanManager. The refs are decremented each time
462 // destroy_semaphore is called with this object. Skia will call destroy_semaphore once it is
463 // done with the semaphore and the GPU has finished work on the semaphore. The VulkanManager
464 // calls destroy_semaphore after sending the semaphore to Skia and exporting it if need be.
465 int mRefs = 2;
Greg Danield92a9b12019-04-23 10:11:04 -0400466
467 DestroySemaphoreInfo(PFN_vkDestroySemaphore destroyFunction, VkDevice device,
Stan Ilievaaa9e832019-09-17 14:07:23 -0400468 VkSemaphore semaphore)
Greg Danield92a9b12019-04-23 10:11:04 -0400469 : mDestroyFunction(destroyFunction), mDevice(device), mSemaphore(semaphore) {}
470};
471
472static void destroy_semaphore(void* context) {
473 DestroySemaphoreInfo* info = reinterpret_cast<DestroySemaphoreInfo*>(context);
Greg Danielfd429392019-05-09 15:44:56 -0400474 --info->mRefs;
475 if (!info->mRefs) {
476 info->mDestroyFunction(info->mDevice, info->mSemaphore, nullptr);
477 delete info;
478 }
Greg Danield92a9b12019-04-23 10:11:04 -0400479}
480
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500481void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect) {
482 if (CC_UNLIKELY(Properties::waitForGpuCompletion)) {
483 ATRACE_NAME("Finishing GPU work");
484 mDeviceWaitIdle(mDevice);
Stan Iliev305e13a2018-11-13 11:14:48 -0500485 }
486
Stan Ilievbc5f06b2019-03-26 15:14:34 -0400487 VulkanSurface::NativeBufferInfo* bufferInfo = surface->getCurrentBufferInfo();
488 if (!bufferInfo) {
489 // If VulkanSurface::dequeueNativeBuffer failed earlier, then swapBuffers is a no-op.
490 return;
491 }
492
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500493 VkExportSemaphoreCreateInfo exportInfo;
494 exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO;
495 exportInfo.pNext = nullptr;
496 exportInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500497
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500498 VkSemaphoreCreateInfo semaphoreInfo;
499 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
500 semaphoreInfo.pNext = &exportInfo;
501 semaphoreInfo.flags = 0;
502 VkSemaphore semaphore;
503 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
504 ALOGE_IF(VK_SUCCESS != err, "VulkanManager::swapBuffers(): Failed to create semaphore");
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500505
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500506 GrBackendSemaphore backendSemaphore;
507 backendSemaphore.initVulkan(semaphore);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500508
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500509 int fenceFd = -1;
Stan Ilievaaa9e832019-09-17 14:07:23 -0400510 DestroySemaphoreInfo* destroyInfo =
511 new DestroySemaphoreInfo(mDestroySemaphore, mDevice, semaphore);
Greg Danielc7ad4082020-05-14 15:38:26 -0400512 GrFlushInfo flushInfo;
513 flushInfo.fNumSemaphores = 1;
514 flushInfo.fSignalSemaphores = &backendSemaphore;
515 flushInfo.fFinishedProc = destroy_semaphore;
516 flushInfo.fFinishedContext = destroyInfo;
Stan Ilievaaa9e832019-09-17 14:07:23 -0400517 GrSemaphoresSubmitted submitted = bufferInfo->skSurface->flush(
Greg Danielc7ad4082020-05-14 15:38:26 -0400518 SkSurface::BackendSurfaceAccess::kPresent, flushInfo);
519 ALOGE_IF(!bufferInfo->skSurface->getContext(), "Surface is not backed by gpu");
520 bufferInfo->skSurface->getContext()->submit();
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500521 if (submitted == GrSemaphoresSubmitted::kYes) {
522 VkSemaphoreGetFdInfoKHR getFdInfo;
523 getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR;
524 getFdInfo.pNext = nullptr;
525 getFdInfo.semaphore = semaphore;
526 getFdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500527
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500528 err = mGetSemaphoreFdKHR(mDevice, &getFdInfo, &fenceFd);
529 ALOGE_IF(VK_SUCCESS != err, "VulkanManager::swapBuffers(): Failed to get semaphore Fd");
530 } else {
531 ALOGE("VulkanManager::swapBuffers(): Semaphore submission failed");
532 mQueueWaitIdle(mGraphicsQueue);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500533 }
Greg Danielfd429392019-05-09 15:44:56 -0400534 destroy_semaphore(destroyInfo);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500535
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500536 surface->presentCurrentBuffer(dirtyRect, fenceFd);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500537}
538
539void VulkanManager::destroySurface(VulkanSurface* surface) {
540 // Make sure all submit commands have finished before starting to destroy objects.
Yiwei Zhang276d5fc2020-09-03 12:00:00 -0700541 if (VK_NULL_HANDLE != mGraphicsQueue) {
542 mQueueWaitIdle(mGraphicsQueue);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500543 }
Greg Daniel2ff202712018-06-14 11:50:10 -0400544 mDeviceWaitIdle(mDevice);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500545
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500546 delete surface;
547}
548
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400549VulkanSurface* VulkanManager::createSurface(ANativeWindow* window,
550 ColorMode colorMode,
Peiyong Lin3bff1352018-12-11 07:56:07 -0800551 sk_sp<SkColorSpace> surfaceColorSpace,
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400552 SkColorType surfaceColorType,
553 GrDirectContext* grContext,
John Reck0fa0cbc2019-04-05 16:57:46 -0700554 uint32_t extraBuffers) {
Stan Iliev981afe72019-02-13 14:24:33 -0500555 LOG_ALWAYS_FATAL_IF(!hasVkContext(), "Not initialized");
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500556 if (!window) {
557 return nullptr;
558 }
559
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500560 return VulkanSurface::Create(window, colorMode, surfaceColorType, surfaceColorSpace, grContext,
John Reck0fa0cbc2019-04-05 16:57:46 -0700561 *this, extraBuffers);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500562}
563
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400564status_t VulkanManager::fenceWait(int fence, GrDirectContext* grContext) {
Greg Daniel26e0dca2018-09-18 10:33:19 -0400565 if (!hasVkContext()) {
566 ALOGE("VulkanManager::fenceWait: VkDevice not initialized");
567 return INVALID_OPERATION;
568 }
569
Stan Iliev7a081272018-10-26 17:54:18 -0400570 // Block GPU on the fence.
Stan Ilievaaa9e832019-09-17 14:07:23 -0400571 int fenceFd = ::dup(fence);
Stan Iliev7a081272018-10-26 17:54:18 -0400572 if (fenceFd == -1) {
573 ALOGE("VulkanManager::fenceWait: error dup'ing fence fd: %d", errno);
574 return -errno;
Stan Iliev564ca3e2018-09-04 22:00:00 +0000575 }
Stan Iliev7a081272018-10-26 17:54:18 -0400576
577 VkSemaphoreCreateInfo semaphoreInfo;
578 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
579 semaphoreInfo.pNext = nullptr;
580 semaphoreInfo.flags = 0;
581 VkSemaphore semaphore;
582 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
583 if (VK_SUCCESS != err) {
584 ALOGE("Failed to create import semaphore, err: %d", err);
585 return UNKNOWN_ERROR;
586 }
587 VkImportSemaphoreFdInfoKHR importInfo;
588 importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
589 importInfo.pNext = nullptr;
590 importInfo.semaphore = semaphore;
591 importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT;
592 importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
593 importInfo.fd = fenceFd;
594
595 err = mImportSemaphoreFdKHR(mDevice, &importInfo);
596 if (VK_SUCCESS != err) {
Greg Danield92a9b12019-04-23 10:11:04 -0400597 mDestroySemaphore(mDevice, semaphore, nullptr);
Stan Iliev7a081272018-10-26 17:54:18 -0400598 ALOGE("Failed to import semaphore, err: %d", err);
599 return UNKNOWN_ERROR;
600 }
601
Greg Danield92a9b12019-04-23 10:11:04 -0400602 GrBackendSemaphore beSemaphore;
603 beSemaphore.initVulkan(semaphore);
Stan Iliev7a081272018-10-26 17:54:18 -0400604
Greg Danield92a9b12019-04-23 10:11:04 -0400605 // Skia takes ownership of the semaphore and will delete it once the wait has finished.
606 grContext->wait(1, &beSemaphore);
Greg Danielc7ad4082020-05-14 15:38:26 -0400607 grContext->flushAndSubmit();
Stan Iliev7a081272018-10-26 17:54:18 -0400608
Stan Iliev564ca3e2018-09-04 22:00:00 +0000609 return OK;
610}
611
Adlai Hollerf8c434e2020-07-27 11:42:45 -0400612status_t VulkanManager::createReleaseFence(int* nativeFence, GrDirectContext* grContext) {
Stan Ilievaaa9e832019-09-17 14:07:23 -0400613 *nativeFence = -1;
Greg Daniel26e0dca2018-09-18 10:33:19 -0400614 if (!hasVkContext()) {
615 ALOGE("VulkanManager::createReleaseFence: VkDevice not initialized");
616 return INVALID_OPERATION;
617 }
618
Greg Daniel26e0dca2018-09-18 10:33:19 -0400619 VkExportSemaphoreCreateInfo exportInfo;
620 exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO;
621 exportInfo.pNext = nullptr;
622 exportInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
623
624 VkSemaphoreCreateInfo semaphoreInfo;
625 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
626 semaphoreInfo.pNext = &exportInfo;
627 semaphoreInfo.flags = 0;
628 VkSemaphore semaphore;
629 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
630 if (VK_SUCCESS != err) {
631 ALOGE("VulkanManager::createReleaseFence: Failed to create semaphore");
632 return INVALID_OPERATION;
633 }
634
Greg Danield92a9b12019-04-23 10:11:04 -0400635 GrBackendSemaphore backendSemaphore;
636 backendSemaphore.initVulkan(semaphore);
Greg Daniel26e0dca2018-09-18 10:33:19 -0400637
Stan Ilievaaa9e832019-09-17 14:07:23 -0400638 DestroySemaphoreInfo* destroyInfo =
639 new DestroySemaphoreInfo(mDestroySemaphore, mDevice, semaphore);
Greg Danielfd429392019-05-09 15:44:56 -0400640 // Even if Skia fails to submit the semaphore, it will still call the destroy_semaphore callback
641 // which will remove its ref to the semaphore. The VulkanManager must still release its ref,
642 // when it is done with the semaphore.
Greg Danielc7ad4082020-05-14 15:38:26 -0400643 GrFlushInfo flushInfo;
644 flushInfo.fNumSemaphores = 1;
645 flushInfo.fSignalSemaphores = &backendSemaphore;
646 flushInfo.fFinishedProc = destroy_semaphore;
647 flushInfo.fFinishedContext = destroyInfo;
648 GrSemaphoresSubmitted submitted = grContext->flush(flushInfo);
649 grContext->submit();
Greg Daniel26e0dca2018-09-18 10:33:19 -0400650
Greg Danield92a9b12019-04-23 10:11:04 -0400651 if (submitted == GrSemaphoresSubmitted::kNo) {
652 ALOGE("VulkanManager::createReleaseFence: Failed to submit semaphore");
Greg Danielfd429392019-05-09 15:44:56 -0400653 destroy_semaphore(destroyInfo);
Greg Danield92a9b12019-04-23 10:11:04 -0400654 return INVALID_OPERATION;
655 }
Greg Daniel26e0dca2018-09-18 10:33:19 -0400656
657 VkSemaphoreGetFdInfoKHR getFdInfo;
658 getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR;
659 getFdInfo.pNext = nullptr;
660 getFdInfo.semaphore = semaphore;
661 getFdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
662
663 int fenceFd = 0;
664
665 err = mGetSemaphoreFdKHR(mDevice, &getFdInfo, &fenceFd);
Greg Danielfd429392019-05-09 15:44:56 -0400666 destroy_semaphore(destroyInfo);
Greg Daniel26e0dca2018-09-18 10:33:19 -0400667 if (VK_SUCCESS != err) {
668 ALOGE("VulkanManager::createReleaseFence: Failed to get semaphore Fd");
669 return INVALID_OPERATION;
670 }
Stan Ilievaaa9e832019-09-17 14:07:23 -0400671 *nativeFence = fenceFd;
Greg Daniel26e0dca2018-09-18 10:33:19 -0400672
Stan Iliev564ca3e2018-09-04 22:00:00 +0000673 return OK;
674}
675
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500676} /* namespace renderthread */
677} /* namespace uirenderer */
678} /* namespace android */