blob: 35abc57fbe5799c8b85aa17ca65fd8c3a6e205a2 [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
Derek Sollenbergera19b71a2019-02-15 16:36:30 -050019#include <android/sync.h>
Alec Mouri6db59a62019-08-02 17:05:26 -070020#include <EGL/egl.h>
21#include <EGL/eglext.h>
Stan Iliev305e13a2018-11-13 11:14:48 -050022
Greg Danielcd558522016-11-17 13:31:40 -050023#include "Properties.h"
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050024#include "RenderThread.h"
Greg Daniel45ec62b2017-01-04 14:27:00 -050025#include "renderstate/RenderState.h"
Ben Wagnereec27d52017-01-11 15:32:07 -050026#include "utils/FatVector.h"
John Reck322b8ab2019-03-14 13:15:28 -070027#include "utils/TraceUtils.h"
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050028
Derek Sollenbergera19b71a2019-02-15 16:36:30 -050029#include <GrBackendSemaphore.h>
Greg Danielac2d2322017-07-12 11:30:15 -040030#include <GrBackendSurface.h>
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050031#include <GrContext.h>
32#include <GrTypes.h>
Greg Daniela227dbb2018-08-20 09:19:48 -040033#include <vk/GrVkExtensions.h>
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050034#include <vk/GrVkTypes.h>
35
36namespace android {
37namespace uirenderer {
38namespace renderthread {
39
Bo Liu7b8c1eb2019-01-08 20:17:55 -080040static void free_features_extensions_structs(const VkPhysicalDeviceFeatures2& features) {
41 // All Vulkan structs that could be part of the features chain will start with the
42 // structure type followed by the pNext pointer. We cast to the CommonVulkanHeader
43 // so we can get access to the pNext for the next struct.
44 struct CommonVulkanHeader {
45 VkStructureType sType;
John Reck0fa0cbc2019-04-05 16:57:46 -070046 void* pNext;
Bo Liu7b8c1eb2019-01-08 20:17:55 -080047 };
48
49 void* pNext = features.pNext;
50 while (pNext) {
51 void* current = pNext;
52 pNext = static_cast<CommonVulkanHeader*>(current)->pNext;
53 free(current);
54 }
55}
56
Greg Daniel2ff202712018-06-14 11:50:10 -040057#define GET_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(VK_NULL_HANDLE, "vk" #F)
58#define GET_INST_PROC(F) m##F = (PFN_vk##F)vkGetInstanceProcAddr(mInstance, "vk" #F)
59#define GET_DEV_PROC(F) m##F = (PFN_vk##F)vkGetDeviceProcAddr(mDevice, "vk" #F)
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050060
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050061void VulkanManager::destroy() {
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050062 if (VK_NULL_HANDLE != mCommandPool) {
Greg Daniel2ff202712018-06-14 11:50:10 -040063 mDestroyCommandPool(mDevice, mCommandPool, nullptr);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050064 mCommandPool = VK_NULL_HANDLE;
65 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050066
Greg Daniel2ff202712018-06-14 11:50:10 -040067 if (mDevice != VK_NULL_HANDLE) {
68 mDeviceWaitIdle(mDevice);
69 mDestroyDevice(mDevice, nullptr);
John Reck1bcacfd2017-11-03 10:12:19 -070070 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050071
Greg Daniel2ff202712018-06-14 11:50:10 -040072 if (mInstance != VK_NULL_HANDLE) {
73 mDestroyInstance(mInstance, nullptr);
74 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050075
Greg Daniel2ff202712018-06-14 11:50:10 -040076 mGraphicsQueue = VK_NULL_HANDLE;
77 mPresentQueue = VK_NULL_HANDLE;
78 mDevice = VK_NULL_HANDLE;
79 mPhysicalDevice = VK_NULL_HANDLE;
80 mInstance = VK_NULL_HANDLE;
Roman Kiryanov74ace839e2019-03-07 18:22:19 -080081 mInstanceExtensionsOwner.clear();
Bo Liu7b8c1eb2019-01-08 20:17:55 -080082 mInstanceExtensions.clear();
Roman Kiryanov74ace839e2019-03-07 18:22:19 -080083 mDeviceExtensionsOwner.clear();
Bo Liu7b8c1eb2019-01-08 20:17:55 -080084 mDeviceExtensions.clear();
85 free_features_extensions_structs(mPhysicalDeviceFeatures2);
86 mPhysicalDeviceFeatures2 = {};
Greg Daniel2ff202712018-06-14 11:50:10 -040087}
Derek Sollenberger0e3cba32016-11-09 11:58:36 -050088
Stan Iliev90276c82019-02-03 18:01:02 -050089void VulkanManager::setupDevice(GrVkExtensions& grExtensions, VkPhysicalDeviceFeatures2& features) {
Greg Daniel2ff202712018-06-14 11:50:10 -040090 VkResult err;
91
92 constexpr VkApplicationInfo app_info = {
John Reck0fa0cbc2019-04-05 16:57:46 -070093 VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType
94 nullptr, // pNext
95 "android framework", // pApplicationName
96 0, // applicationVersion
97 "android framework", // pEngineName
98 0, // engineVerison
99 mAPIVersion, // apiVersion
Greg Daniel2ff202712018-06-14 11:50:10 -0400100 };
101
Greg Daniel2ff202712018-06-14 11:50:10 -0400102 {
103 GET_PROC(EnumerateInstanceExtensionProperties);
104
105 uint32_t extensionCount = 0;
106 err = mEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
Stan Iliev90276c82019-02-03 18:01:02 -0500107 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800108 mInstanceExtensionsOwner.resize(extensionCount);
109 err = mEnumerateInstanceExtensionProperties(nullptr, &extensionCount,
110 mInstanceExtensionsOwner.data());
Stan Iliev90276c82019-02-03 18:01:02 -0500111 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Greg Daniel2ff202712018-06-14 11:50:10 -0400112 bool hasKHRSurfaceExtension = false;
113 bool hasKHRAndroidSurfaceExtension = false;
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800114 for (const VkExtensionProperties& extension : mInstanceExtensionsOwner) {
115 mInstanceExtensions.push_back(extension.extensionName);
116 if (!strcmp(extension.extensionName, VK_KHR_SURFACE_EXTENSION_NAME)) {
Greg Daniel2ff202712018-06-14 11:50:10 -0400117 hasKHRSurfaceExtension = true;
118 }
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800119 if (!strcmp(extension.extensionName, VK_KHR_ANDROID_SURFACE_EXTENSION_NAME)) {
Greg Daniel2ff202712018-06-14 11:50:10 -0400120 hasKHRAndroidSurfaceExtension = true;
121 }
122 }
Stan Iliev90276c82019-02-03 18:01:02 -0500123 LOG_ALWAYS_FATAL_IF(!hasKHRSurfaceExtension || !hasKHRAndroidSurfaceExtension);
Greg Daniel2ff202712018-06-14 11:50:10 -0400124 }
125
126 const VkInstanceCreateInfo instance_create = {
John Reck0fa0cbc2019-04-05 16:57:46 -0700127 VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, // sType
128 nullptr, // pNext
129 0, // flags
130 &app_info, // pApplicationInfo
131 0, // enabledLayerNameCount
132 nullptr, // ppEnabledLayerNames
133 (uint32_t)mInstanceExtensions.size(), // enabledExtensionNameCount
134 mInstanceExtensions.data(), // ppEnabledExtensionNames
Greg Daniel2ff202712018-06-14 11:50:10 -0400135 };
136
137 GET_PROC(CreateInstance);
138 err = mCreateInstance(&instance_create, nullptr, &mInstance);
Stan Iliev90276c82019-02-03 18:01:02 -0500139 LOG_ALWAYS_FATAL_IF(err < 0);
Greg Daniel2ff202712018-06-14 11:50:10 -0400140
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700141 GET_INST_PROC(CreateDevice);
Greg Daniel2ff202712018-06-14 11:50:10 -0400142 GET_INST_PROC(DestroyInstance);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700143 GET_INST_PROC(EnumerateDeviceExtensionProperties);
Greg Daniel2ff202712018-06-14 11:50:10 -0400144 GET_INST_PROC(EnumeratePhysicalDevices);
Greg Daniela227dbb2018-08-20 09:19:48 -0400145 GET_INST_PROC(GetPhysicalDeviceFeatures2);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500146 GET_INST_PROC(GetPhysicalDeviceImageFormatProperties2);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700147 GET_INST_PROC(GetPhysicalDeviceProperties);
148 GET_INST_PROC(GetPhysicalDeviceQueueFamilyProperties);
Greg Daniel2ff202712018-06-14 11:50:10 -0400149
150 uint32_t gpuCount;
Stan Iliev90276c82019-02-03 18:01:02 -0500151 LOG_ALWAYS_FATAL_IF(mEnumeratePhysicalDevices(mInstance, &gpuCount, nullptr));
152 LOG_ALWAYS_FATAL_IF(!gpuCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400153 // Just returning the first physical device instead of getting the whole array. Since there
154 // should only be one device on android.
155 gpuCount = 1;
156 err = mEnumeratePhysicalDevices(mInstance, &gpuCount, &mPhysicalDevice);
157 // VK_INCOMPLETE is returned when the count we provide is less than the total device count.
Stan Iliev90276c82019-02-03 18:01:02 -0500158 LOG_ALWAYS_FATAL_IF(err && VK_INCOMPLETE != err);
Greg Daniel2ff202712018-06-14 11:50:10 -0400159
Greg Daniel96259622018-10-01 14:42:56 -0400160 VkPhysicalDeviceProperties physDeviceProperties;
161 mGetPhysicalDeviceProperties(mPhysicalDevice, &physDeviceProperties);
Stan Iliev90276c82019-02-03 18:01:02 -0500162 LOG_ALWAYS_FATAL_IF(physDeviceProperties.apiVersion < VK_MAKE_VERSION(1, 1, 0));
Stan Ilievbf99c442019-03-29 11:09:11 -0400163 mDriverVersion = physDeviceProperties.driverVersion;
Greg Daniel96259622018-10-01 14:42:56 -0400164
Greg Daniel2ff202712018-06-14 11:50:10 -0400165 // query to get the initial queue props size
166 uint32_t queueCount;
167 mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, nullptr);
Stan Iliev90276c82019-02-03 18:01:02 -0500168 LOG_ALWAYS_FATAL_IF(!queueCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400169
170 // now get the actual queue props
171 std::unique_ptr<VkQueueFamilyProperties[]> queueProps(new VkQueueFamilyProperties[queueCount]);
172 mGetPhysicalDeviceQueueFamilyProperties(mPhysicalDevice, &queueCount, queueProps.get());
173
174 // iterate to find the graphics queue
175 mGraphicsQueueIndex = queueCount;
176 for (uint32_t i = 0; i < queueCount; i++) {
177 if (queueProps[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) {
178 mGraphicsQueueIndex = i;
179 break;
180 }
181 }
Stan Iliev90276c82019-02-03 18:01:02 -0500182 LOG_ALWAYS_FATAL_IF(mGraphicsQueueIndex == queueCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400183
184 // All physical devices and queue families on Android must be capable of
185 // presentation with any native window. So just use the first one.
186 mPresentQueueIndex = 0;
187
Greg Daniel2ff202712018-06-14 11:50:10 -0400188 {
189 uint32_t extensionCount = 0;
190 err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount,
John Reck0fa0cbc2019-04-05 16:57:46 -0700191 nullptr);
Stan Iliev90276c82019-02-03 18:01:02 -0500192 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800193 mDeviceExtensionsOwner.resize(extensionCount);
Greg Daniel2ff202712018-06-14 11:50:10 -0400194 err = mEnumerateDeviceExtensionProperties(mPhysicalDevice, nullptr, &extensionCount,
John Reck0fa0cbc2019-04-05 16:57:46 -0700195 mDeviceExtensionsOwner.data());
Stan Iliev90276c82019-02-03 18:01:02 -0500196 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err);
Greg Daniel2ff202712018-06-14 11:50:10 -0400197 bool hasKHRSwapchainExtension = false;
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800198 for (const VkExtensionProperties& extension : mDeviceExtensionsOwner) {
199 mDeviceExtensions.push_back(extension.extensionName);
200 if (!strcmp(extension.extensionName, VK_KHR_SWAPCHAIN_EXTENSION_NAME)) {
Greg Daniel2ff202712018-06-14 11:50:10 -0400201 hasKHRSwapchainExtension = true;
202 }
203 }
Stan Iliev90276c82019-02-03 18:01:02 -0500204 LOG_ALWAYS_FATAL_IF(!hasKHRSwapchainExtension);
Greg Daniel2ff202712018-06-14 11:50:10 -0400205 }
206
John Reck0fa0cbc2019-04-05 16:57:46 -0700207 auto getProc = [](const char* proc_name, VkInstance instance, VkDevice device) {
Greg Daniela227dbb2018-08-20 09:19:48 -0400208 if (device != VK_NULL_HANDLE) {
209 return vkGetDeviceProcAddr(device, proc_name);
210 }
211 return vkGetInstanceProcAddr(instance, proc_name);
212 };
Roman Kiryanov74ace839e2019-03-07 18:22:19 -0800213
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800214 grExtensions.init(getProc, mInstance, mPhysicalDevice, mInstanceExtensions.size(),
John Reck0fa0cbc2019-04-05 16:57:46 -0700215 mInstanceExtensions.data(), mDeviceExtensions.size(),
216 mDeviceExtensions.data());
Greg Daniela227dbb2018-08-20 09:19:48 -0400217
Stan Iliev90276c82019-02-03 18:01:02 -0500218 LOG_ALWAYS_FATAL_IF(!grExtensions.hasExtension(VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME, 1));
Greg Daniel26e0dca2018-09-18 10:33:19 -0400219
Greg Daniela227dbb2018-08-20 09:19:48 -0400220 memset(&features, 0, sizeof(VkPhysicalDeviceFeatures2));
221 features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
222 features.pNext = nullptr;
223
224 // Setup all extension feature structs we may want to use.
225 void** tailPNext = &features.pNext;
226
227 if (grExtensions.hasExtension(VK_EXT_BLEND_OPERATION_ADVANCED_EXTENSION_NAME, 2)) {
228 VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT* blend;
John Reck0fa0cbc2019-04-05 16:57:46 -0700229 blend = (VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT*)malloc(
Greg Daniela227dbb2018-08-20 09:19:48 -0400230 sizeof(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT));
231 LOG_ALWAYS_FATAL_IF(!blend);
232 blend->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT;
233 blend->pNext = nullptr;
234 *tailPNext = blend;
235 tailPNext = &blend->pNext;
236 }
237
Greg Daniel05036172018-11-28 17:08:04 -0500238 VkPhysicalDeviceSamplerYcbcrConversionFeatures* ycbcrFeature;
John Reck0fa0cbc2019-04-05 16:57:46 -0700239 ycbcrFeature = (VkPhysicalDeviceSamplerYcbcrConversionFeatures*)malloc(
Greg Daniel05036172018-11-28 17:08:04 -0500240 sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeatures));
241 LOG_ALWAYS_FATAL_IF(!ycbcrFeature);
242 ycbcrFeature->sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES;
243 ycbcrFeature->pNext = nullptr;
244 *tailPNext = ycbcrFeature;
245 tailPNext = &ycbcrFeature->pNext;
246
Greg Daniela227dbb2018-08-20 09:19:48 -0400247 // query to get the physical device features
248 mGetPhysicalDeviceFeatures2(mPhysicalDevice, &features);
Greg Daniel2ff202712018-06-14 11:50:10 -0400249 // this looks like it would slow things down,
250 // and we can't depend on it on all platforms
Greg Daniela227dbb2018-08-20 09:19:48 -0400251 features.features.robustBufferAccess = VK_FALSE;
Greg Daniel2ff202712018-06-14 11:50:10 -0400252
John Reck0fa0cbc2019-04-05 16:57:46 -0700253 float queuePriorities[1] = {0.0};
Greg Daniel2ff202712018-06-14 11:50:10 -0400254
Stan Iliev7e733362019-02-28 13:16:36 -0500255 void* queueNextPtr = nullptr;
256
257 VkDeviceQueueGlobalPriorityCreateInfoEXT queuePriorityCreateInfo;
258
John Reck0fa0cbc2019-04-05 16:57:46 -0700259 if (Properties::contextPriority != 0 &&
260 grExtensions.hasExtension(VK_EXT_GLOBAL_PRIORITY_EXTENSION_NAME, 2)) {
Stan Iliev7e733362019-02-28 13:16:36 -0500261 memset(&queuePriorityCreateInfo, 0, sizeof(VkDeviceQueueGlobalPriorityCreateInfoEXT));
262 queuePriorityCreateInfo.sType =
John Reck0fa0cbc2019-04-05 16:57:46 -0700263 VK_STRUCTURE_TYPE_DEVICE_QUEUE_GLOBAL_PRIORITY_CREATE_INFO_EXT;
Stan Iliev7e733362019-02-28 13:16:36 -0500264 queuePriorityCreateInfo.pNext = nullptr;
265 switch (Properties::contextPriority) {
266 case EGL_CONTEXT_PRIORITY_LOW_IMG:
267 queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_LOW_EXT;
268 break;
269 case EGL_CONTEXT_PRIORITY_MEDIUM_IMG:
270 queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_MEDIUM_EXT;
271 break;
272 case EGL_CONTEXT_PRIORITY_HIGH_IMG:
273 queuePriorityCreateInfo.globalPriority = VK_QUEUE_GLOBAL_PRIORITY_HIGH_EXT;
274 break;
275 default:
276 LOG_ALWAYS_FATAL("Unsupported context priority");
John Reck0fa0cbc2019-04-05 16:57:46 -0700277 }
278 queueNextPtr = &queuePriorityCreateInfo;
Stan Iliev7e733362019-02-28 13:16:36 -0500279 }
280
Greg Daniel2ff202712018-06-14 11:50:10 -0400281 const VkDeviceQueueCreateInfo queueInfo[2] = {
John Reck0fa0cbc2019-04-05 16:57:46 -0700282 {
283 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
284 queueNextPtr, // pNext
285 0, // VkDeviceQueueCreateFlags
286 mGraphicsQueueIndex, // queueFamilyIndex
287 1, // queueCount
288 queuePriorities, // pQueuePriorities
289 },
290 {
291 VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, // sType
292 queueNextPtr, // pNext
293 0, // VkDeviceQueueCreateFlags
294 mPresentQueueIndex, // queueFamilyIndex
295 1, // queueCount
296 queuePriorities, // pQueuePriorities
297 }};
Greg Daniel2ff202712018-06-14 11:50:10 -0400298 uint32_t queueInfoCount = (mPresentQueueIndex != mGraphicsQueueIndex) ? 2 : 1;
299
300 const VkDeviceCreateInfo deviceInfo = {
John Reck0fa0cbc2019-04-05 16:57:46 -0700301 VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, // sType
302 &features, // pNext
303 0, // VkDeviceCreateFlags
304 queueInfoCount, // queueCreateInfoCount
305 queueInfo, // pQueueCreateInfos
306 0, // layerCount
307 nullptr, // ppEnabledLayerNames
308 (uint32_t)mDeviceExtensions.size(), // extensionCount
309 mDeviceExtensions.data(), // ppEnabledExtensionNames
310 nullptr, // ppEnabledFeatures
Greg Daniel2ff202712018-06-14 11:50:10 -0400311 };
312
Stan Iliev90276c82019-02-03 18:01:02 -0500313 LOG_ALWAYS_FATAL_IF(mCreateDevice(mPhysicalDevice, &deviceInfo, nullptr, &mDevice));
Greg Daniel2ff202712018-06-14 11:50:10 -0400314
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500315 GET_DEV_PROC(AllocateCommandBuffers);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500316 GET_DEV_PROC(BeginCommandBuffer);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500317 GET_DEV_PROC(CmdPipelineBarrier);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700318 GET_DEV_PROC(CreateCommandPool);
319 GET_DEV_PROC(CreateFence);
320 GET_DEV_PROC(CreateSemaphore);
321 GET_DEV_PROC(DestroyCommandPool);
322 GET_DEV_PROC(DestroyDevice);
323 GET_DEV_PROC(DestroyFence);
324 GET_DEV_PROC(DestroySemaphore);
325 GET_DEV_PROC(DeviceWaitIdle);
326 GET_DEV_PROC(EndCommandBuffer);
327 GET_DEV_PROC(FreeCommandBuffers);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500328 GET_DEV_PROC(GetDeviceQueue);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700329 GET_DEV_PROC(GetSemaphoreFdKHR);
330 GET_DEV_PROC(ImportSemaphoreFdKHR);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500331 GET_DEV_PROC(QueueSubmit);
332 GET_DEV_PROC(QueueWaitIdle);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700333 GET_DEV_PROC(ResetCommandBuffer);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500334 GET_DEV_PROC(ResetFences);
Yiwei Zhang0b9f0b82019-08-15 11:33:59 -0700335 GET_DEV_PROC(WaitForFences);
Greg Daniel2ff202712018-06-14 11:50:10 -0400336}
337
338void VulkanManager::initialize() {
339 if (mDevice != VK_NULL_HANDLE) {
340 return;
341 }
342
Greg Daniela227dbb2018-08-20 09:19:48 -0400343 GET_PROC(EnumerateInstanceVersion);
Greg Danieleaf310e2019-01-28 16:10:32 -0500344 uint32_t instanceVersion;
345 LOG_ALWAYS_FATAL_IF(mEnumerateInstanceVersion(&instanceVersion));
346 LOG_ALWAYS_FATAL_IF(instanceVersion < VK_MAKE_VERSION(1, 1, 0));
Greg Daniela227dbb2018-08-20 09:19:48 -0400347
Stan Iliev981afe72019-02-13 14:24:33 -0500348 this->setupDevice(mExtensions, mPhysicalDeviceFeatures2);
Greg Daniel2ff202712018-06-14 11:50:10 -0400349
350 mGetDeviceQueue(mDevice, mGraphicsQueueIndex, 0, &mGraphicsQueue);
351
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500352 // create the command pool for the command buffers
353 if (VK_NULL_HANDLE == mCommandPool) {
354 VkCommandPoolCreateInfo commandPoolInfo;
355 memset(&commandPoolInfo, 0, sizeof(VkCommandPoolCreateInfo));
356 commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
357 // this needs to be on the render queue
Greg Daniel2ff202712018-06-14 11:50:10 -0400358 commandPoolInfo.queueFamilyIndex = mGraphicsQueueIndex;
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500359 commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
John Reck0fa0cbc2019-04-05 16:57:46 -0700360 SkDEBUGCODE(VkResult res =)
361 mCreateCommandPool(mDevice, &commandPoolInfo, nullptr, &mCommandPool);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500362 SkASSERT(VK_SUCCESS == res);
363 }
Greg Daniel26e0dca2018-09-18 10:33:19 -0400364 LOG_ALWAYS_FATAL_IF(mCommandPool == VK_NULL_HANDLE);
365
Greg Daniel2ff202712018-06-14 11:50:10 -0400366 mGetDeviceQueue(mDevice, mPresentQueueIndex, 0, &mPresentQueue);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500367
Greg Danielcd558522016-11-17 13:31:40 -0500368 if (Properties::enablePartialUpdates && Properties::useBufferAge) {
369 mSwapBehavior = SwapBehavior::BufferAge;
370 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500371}
372
Stan Iliev898123b2019-02-14 14:57:44 -0500373sk_sp<GrContext> VulkanManager::createContext(const GrContextOptions& options) {
John Reck0fa0cbc2019-04-05 16:57:46 -0700374 auto getProc = [](const char* proc_name, VkInstance instance, VkDevice device) {
Stan Iliev981afe72019-02-13 14:24:33 -0500375 if (device != VK_NULL_HANDLE) {
376 return vkGetDeviceProcAddr(device, proc_name);
377 }
378 return vkGetInstanceProcAddr(instance, proc_name);
379 };
380
381 GrVkBackendContext backendContext;
382 backendContext.fInstance = mInstance;
383 backendContext.fPhysicalDevice = mPhysicalDevice;
384 backendContext.fDevice = mDevice;
385 backendContext.fQueue = mGraphicsQueue;
386 backendContext.fGraphicsQueueIndex = mGraphicsQueueIndex;
387 backendContext.fMaxAPIVersion = mAPIVersion;
388 backendContext.fVkExtensions = &mExtensions;
389 backendContext.fDeviceFeatures2 = &mPhysicalDeviceFeatures2;
390 backendContext.fGetProc = std::move(getProc);
391
392 return GrContext::MakeVulkan(backendContext, options);
393}
394
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800395VkFunctorInitParams VulkanManager::getVkFunctorInitParams() const {
396 return VkFunctorInitParams{
397 .instance = mInstance,
398 .physical_device = mPhysicalDevice,
399 .device = mDevice,
400 .queue = mGraphicsQueue,
401 .graphics_queue_index = mGraphicsQueueIndex,
Greg Danieleaf310e2019-01-28 16:10:32 -0500402 .api_version = mAPIVersion,
Bo Liu7b8c1eb2019-01-08 20:17:55 -0800403 .enabled_instance_extension_names = mInstanceExtensions.data(),
404 .enabled_instance_extension_names_length =
405 static_cast<uint32_t>(mInstanceExtensions.size()),
406 .enabled_device_extension_names = mDeviceExtensions.data(),
407 .enabled_device_extension_names_length =
408 static_cast<uint32_t>(mDeviceExtensions.size()),
409 .device_features_2 = &mPhysicalDeviceFeatures2,
410 };
411}
412
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500413Frame VulkanManager::dequeueNextBuffer(VulkanSurface* surface) {
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500414 VulkanSurface::NativeBufferInfo* bufferInfo = surface->dequeueNativeBuffer();
415
416 if (bufferInfo == nullptr) {
417 ALOGE("VulkanSurface::dequeueNativeBuffer called with an invalid surface!");
418 return Frame(-1, -1, 0);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500419 }
420
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500421 LOG_ALWAYS_FATAL_IF(!bufferInfo->dequeued);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500422
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500423 if (bufferInfo->dequeue_fence != -1) {
Stan Iliev197843d2019-03-21 11:34:15 -0400424 struct sync_file_info* finfo = sync_file_info(bufferInfo->dequeue_fence);
425 bool isSignalPending = false;
426 if (finfo != NULL) {
427 isSignalPending = finfo->status != 1;
428 sync_file_info_free(finfo);
429 }
430 if (isSignalPending) {
431 int fence_clone = dup(bufferInfo->dequeue_fence);
432 if (fence_clone == -1) {
433 ALOGE("dup(fence) failed, stalling until signalled: %s (%d)", strerror(errno),
434 errno);
435 sync_wait(bufferInfo->dequeue_fence, -1 /* forever */);
436 } else {
437 VkSemaphoreCreateInfo semaphoreInfo;
438 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
439 semaphoreInfo.pNext = nullptr;
440 semaphoreInfo.flags = 0;
441 VkSemaphore semaphore;
442 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
443 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err, "Failed to create import semaphore, err: %d",
444 err);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500445
Stan Iliev197843d2019-03-21 11:34:15 -0400446 VkImportSemaphoreFdInfoKHR importInfo;
447 importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
448 importInfo.pNext = nullptr;
449 importInfo.semaphore = semaphore;
450 importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT;
451 importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
452 importInfo.fd = fence_clone;
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500453
Stan Iliev197843d2019-03-21 11:34:15 -0400454 err = mImportSemaphoreFdKHR(mDevice, &importInfo);
455 LOG_ALWAYS_FATAL_IF(VK_SUCCESS != err, "Failed to import semaphore, err: %d", err);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500456
Stan Iliev197843d2019-03-21 11:34:15 -0400457 GrBackendSemaphore backendSemaphore;
458 backendSemaphore.initVulkan(semaphore);
459 bufferInfo->skSurface->wait(1, &backendSemaphore);
460 // The following flush blocks the GPU immediately instead of waiting for other
461 // drawing ops. It seems dequeue_fence is not respected otherwise.
John Reck0fa0cbc2019-04-05 16:57:46 -0700462 // TODO: remove the flush after finding why backendSemaphore is not working.
Stan Iliev197843d2019-03-21 11:34:15 -0400463 bufferInfo->skSurface->flush();
464 }
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500465 }
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500466 }
467
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500468 int bufferAge = (mSwapBehavior == SwapBehavior::Discard) ? 0 : surface->getCurrentBuffersAge();
469 return Frame(surface->logicalWidth(), surface->logicalHeight(), bufferAge);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500470}
471
Greg Danield92a9b12019-04-23 10:11:04 -0400472struct DestroySemaphoreInfo {
473 PFN_vkDestroySemaphore mDestroyFunction;
474 VkDevice mDevice;
475 VkSemaphore mSemaphore;
Greg Danielfd429392019-05-09 15:44:56 -0400476 // We need to make sure we don't delete the VkSemaphore until it is done being used by both Skia
477 // (including by the GPU) and inside the VulkanManager. So we always start with two refs, one
478 // owned by Skia and one owned by the VulkanManager. The refs are decremented each time
479 // destroy_semaphore is called with this object. Skia will call destroy_semaphore once it is
480 // done with the semaphore and the GPU has finished work on the semaphore. The VulkanManager
481 // calls destroy_semaphore after sending the semaphore to Skia and exporting it if need be.
482 int mRefs = 2;
Greg Danield92a9b12019-04-23 10:11:04 -0400483
484 DestroySemaphoreInfo(PFN_vkDestroySemaphore destroyFunction, VkDevice device,
485 VkSemaphore semaphore)
486 : mDestroyFunction(destroyFunction), mDevice(device), mSemaphore(semaphore) {}
487};
488
489static void destroy_semaphore(void* context) {
490 DestroySemaphoreInfo* info = reinterpret_cast<DestroySemaphoreInfo*>(context);
Greg Danielfd429392019-05-09 15:44:56 -0400491 --info->mRefs;
492 if (!info->mRefs) {
493 info->mDestroyFunction(info->mDevice, info->mSemaphore, nullptr);
494 delete info;
495 }
Greg Danield92a9b12019-04-23 10:11:04 -0400496}
497
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500498void VulkanManager::swapBuffers(VulkanSurface* surface, const SkRect& dirtyRect) {
499 if (CC_UNLIKELY(Properties::waitForGpuCompletion)) {
500 ATRACE_NAME("Finishing GPU work");
501 mDeviceWaitIdle(mDevice);
Stan Iliev305e13a2018-11-13 11:14:48 -0500502 }
503
Stan Ilievbc5f06b2019-03-26 15:14:34 -0400504 VulkanSurface::NativeBufferInfo* bufferInfo = surface->getCurrentBufferInfo();
505 if (!bufferInfo) {
506 // If VulkanSurface::dequeueNativeBuffer failed earlier, then swapBuffers is a no-op.
507 return;
508 }
509
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500510 VkExportSemaphoreCreateInfo exportInfo;
511 exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO;
512 exportInfo.pNext = nullptr;
513 exportInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500514
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500515 VkSemaphoreCreateInfo semaphoreInfo;
516 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
517 semaphoreInfo.pNext = &exportInfo;
518 semaphoreInfo.flags = 0;
519 VkSemaphore semaphore;
520 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
521 ALOGE_IF(VK_SUCCESS != err, "VulkanManager::swapBuffers(): Failed to create semaphore");
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500522
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500523 GrBackendSemaphore backendSemaphore;
524 backendSemaphore.initVulkan(semaphore);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500525
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500526 int fenceFd = -1;
Greg Danield92a9b12019-04-23 10:11:04 -0400527 DestroySemaphoreInfo* destroyInfo = new DestroySemaphoreInfo(mDestroySemaphore, mDevice,
528 semaphore);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500529 GrSemaphoresSubmitted submitted =
530 bufferInfo->skSurface->flush(SkSurface::BackendSurfaceAccess::kPresent,
Greg Danield92a9b12019-04-23 10:11:04 -0400531 kNone_GrFlushFlags, 1, &backendSemaphore,
532 destroy_semaphore, destroyInfo);
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500533 if (submitted == GrSemaphoresSubmitted::kYes) {
534 VkSemaphoreGetFdInfoKHR getFdInfo;
535 getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR;
536 getFdInfo.pNext = nullptr;
537 getFdInfo.semaphore = semaphore;
538 getFdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500539
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500540 err = mGetSemaphoreFdKHR(mDevice, &getFdInfo, &fenceFd);
541 ALOGE_IF(VK_SUCCESS != err, "VulkanManager::swapBuffers(): Failed to get semaphore Fd");
542 } else {
543 ALOGE("VulkanManager::swapBuffers(): Semaphore submission failed");
544 mQueueWaitIdle(mGraphicsQueue);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500545 }
Greg Danielfd429392019-05-09 15:44:56 -0400546 destroy_semaphore(destroyInfo);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500547
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500548 surface->presentCurrentBuffer(dirtyRect, fenceFd);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500549}
550
551void VulkanManager::destroySurface(VulkanSurface* surface) {
552 // Make sure all submit commands have finished before starting to destroy objects.
553 if (VK_NULL_HANDLE != mPresentQueue) {
554 mQueueWaitIdle(mPresentQueue);
555 }
Greg Daniel2ff202712018-06-14 11:50:10 -0400556 mDeviceWaitIdle(mDevice);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500557
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500558 delete surface;
559}
560
Stan Iliev987a80c02018-12-04 10:07:21 -0500561VulkanSurface* VulkanManager::createSurface(ANativeWindow* window, ColorMode colorMode,
Peiyong Lin3bff1352018-12-11 07:56:07 -0800562 sk_sp<SkColorSpace> surfaceColorSpace,
John Reck0fa0cbc2019-04-05 16:57:46 -0700563 SkColorType surfaceColorType, GrContext* grContext,
564 uint32_t extraBuffers) {
Stan Iliev981afe72019-02-13 14:24:33 -0500565 LOG_ALWAYS_FATAL_IF(!hasVkContext(), "Not initialized");
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500566 if (!window) {
567 return nullptr;
568 }
569
Derek Sollenbergera19b71a2019-02-15 16:36:30 -0500570 return VulkanSurface::Create(window, colorMode, surfaceColorType, surfaceColorSpace, grContext,
John Reck0fa0cbc2019-04-05 16:57:46 -0700571 *this, extraBuffers);
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500572}
573
Greg Danield92a9b12019-04-23 10:11:04 -0400574status_t VulkanManager::fenceWait(sp<Fence>& fence, GrContext* grContext) {
Greg Daniel26e0dca2018-09-18 10:33:19 -0400575 if (!hasVkContext()) {
576 ALOGE("VulkanManager::fenceWait: VkDevice not initialized");
577 return INVALID_OPERATION;
578 }
579
Stan Iliev7a081272018-10-26 17:54:18 -0400580 // Block GPU on the fence.
581 int fenceFd = fence->dup();
582 if (fenceFd == -1) {
583 ALOGE("VulkanManager::fenceWait: error dup'ing fence fd: %d", errno);
584 return -errno;
Stan Iliev564ca3e2018-09-04 22:00:00 +0000585 }
Stan Iliev7a081272018-10-26 17:54:18 -0400586
587 VkSemaphoreCreateInfo semaphoreInfo;
588 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
589 semaphoreInfo.pNext = nullptr;
590 semaphoreInfo.flags = 0;
591 VkSemaphore semaphore;
592 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
593 if (VK_SUCCESS != err) {
594 ALOGE("Failed to create import semaphore, err: %d", err);
595 return UNKNOWN_ERROR;
596 }
597 VkImportSemaphoreFdInfoKHR importInfo;
598 importInfo.sType = VK_STRUCTURE_TYPE_IMPORT_SEMAPHORE_FD_INFO_KHR;
599 importInfo.pNext = nullptr;
600 importInfo.semaphore = semaphore;
601 importInfo.flags = VK_SEMAPHORE_IMPORT_TEMPORARY_BIT;
602 importInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
603 importInfo.fd = fenceFd;
604
605 err = mImportSemaphoreFdKHR(mDevice, &importInfo);
606 if (VK_SUCCESS != err) {
Greg Danield92a9b12019-04-23 10:11:04 -0400607 mDestroySemaphore(mDevice, semaphore, nullptr);
Stan Iliev7a081272018-10-26 17:54:18 -0400608 ALOGE("Failed to import semaphore, err: %d", err);
609 return UNKNOWN_ERROR;
610 }
611
Greg Danield92a9b12019-04-23 10:11:04 -0400612 GrBackendSemaphore beSemaphore;
613 beSemaphore.initVulkan(semaphore);
Stan Iliev7a081272018-10-26 17:54:18 -0400614
Greg Danield92a9b12019-04-23 10:11:04 -0400615 // Skia takes ownership of the semaphore and will delete it once the wait has finished.
616 grContext->wait(1, &beSemaphore);
617 grContext->flush();
Stan Iliev7a081272018-10-26 17:54:18 -0400618
Stan Iliev564ca3e2018-09-04 22:00:00 +0000619 return OK;
620}
621
Greg Danield92a9b12019-04-23 10:11:04 -0400622status_t VulkanManager::createReleaseFence(sp<Fence>& nativeFence, GrContext* grContext) {
Greg Daniel26e0dca2018-09-18 10:33:19 -0400623 if (!hasVkContext()) {
624 ALOGE("VulkanManager::createReleaseFence: VkDevice not initialized");
625 return INVALID_OPERATION;
626 }
627
Greg Daniel26e0dca2018-09-18 10:33:19 -0400628 VkExportSemaphoreCreateInfo exportInfo;
629 exportInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO;
630 exportInfo.pNext = nullptr;
631 exportInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
632
633 VkSemaphoreCreateInfo semaphoreInfo;
634 semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
635 semaphoreInfo.pNext = &exportInfo;
636 semaphoreInfo.flags = 0;
637 VkSemaphore semaphore;
638 VkResult err = mCreateSemaphore(mDevice, &semaphoreInfo, nullptr, &semaphore);
639 if (VK_SUCCESS != err) {
640 ALOGE("VulkanManager::createReleaseFence: Failed to create semaphore");
641 return INVALID_OPERATION;
642 }
643
Greg Danield92a9b12019-04-23 10:11:04 -0400644 GrBackendSemaphore backendSemaphore;
645 backendSemaphore.initVulkan(semaphore);
Greg Daniel26e0dca2018-09-18 10:33:19 -0400646
Greg Danield92a9b12019-04-23 10:11:04 -0400647 DestroySemaphoreInfo* destroyInfo = new DestroySemaphoreInfo(mDestroySemaphore, mDevice,
648 semaphore);
Greg Danielfd429392019-05-09 15:44:56 -0400649 // Even if Skia fails to submit the semaphore, it will still call the destroy_semaphore callback
650 // which will remove its ref to the semaphore. The VulkanManager must still release its ref,
651 // when it is done with the semaphore.
Greg Danield92a9b12019-04-23 10:11:04 -0400652 GrSemaphoresSubmitted submitted =
653 grContext->flush(kNone_GrFlushFlags, 1, &backendSemaphore,
654 destroy_semaphore, destroyInfo);
Greg Daniel26e0dca2018-09-18 10:33:19 -0400655
Greg Danield92a9b12019-04-23 10:11:04 -0400656 if (submitted == GrSemaphoresSubmitted::kNo) {
657 ALOGE("VulkanManager::createReleaseFence: Failed to submit semaphore");
Greg Danielfd429392019-05-09 15:44:56 -0400658 destroy_semaphore(destroyInfo);
Greg Danield92a9b12019-04-23 10:11:04 -0400659 return INVALID_OPERATION;
660 }
Greg Daniel26e0dca2018-09-18 10:33:19 -0400661
662 VkSemaphoreGetFdInfoKHR getFdInfo;
663 getFdInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR;
664 getFdInfo.pNext = nullptr;
665 getFdInfo.semaphore = semaphore;
666 getFdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT;
667
668 int fenceFd = 0;
669
670 err = mGetSemaphoreFdKHR(mDevice, &getFdInfo, &fenceFd);
Greg Danielfd429392019-05-09 15:44:56 -0400671 destroy_semaphore(destroyInfo);
Greg Daniel26e0dca2018-09-18 10:33:19 -0400672 if (VK_SUCCESS != err) {
673 ALOGE("VulkanManager::createReleaseFence: Failed to get semaphore Fd");
674 return INVALID_OPERATION;
675 }
676 nativeFence = new Fence(fenceFd);
677
Stan Iliev564ca3e2018-09-04 22:00:00 +0000678 return OK;
679}
680
Derek Sollenberger0e3cba32016-11-09 11:58:36 -0500681} /* namespace renderthread */
682} /* namespace uirenderer */
683} /* namespace android */