Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 1 | // Copyright (C) 2018 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | #include <hardware/hwvulkan.h> |
| 15 | |
| 16 | #include <log/log.h> |
| 17 | |
| 18 | #include <errno.h> |
| 19 | #include <string.h> |
David Reveman | fc7d2fa | 2019-05-15 22:03:05 -0400 | [diff] [blame] | 20 | #ifdef VK_USE_PLATFORM_FUCHSIA |
Ian McKellar | 4884b52 | 2021-08-31 12:32:43 -0700 | [diff] [blame] | 21 | #include <fidl/fuchsia.logger/cpp/wire.h> |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 22 | #include <lib/syslog/global.h> |
John Bauman | 8153a44 | 2019-10-16 15:41:17 -0700 | [diff] [blame] | 23 | #include <lib/zx/channel.h> |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 24 | #include <lib/zx/socket.h> |
Craig Stout | bd797ab | 2019-11-13 18:07:58 -0800 | [diff] [blame] | 25 | #include <lib/zxio/zxio.h> |
David Reveman | fc7d2fa | 2019-05-15 22:03:05 -0400 | [diff] [blame] | 26 | #include <unistd.h> |
John Bauman | 8153a44 | 2019-10-16 15:41:17 -0700 | [diff] [blame] | 27 | |
Yilong Li | 5a3e369 | 2020-12-01 10:23:29 -0800 | [diff] [blame] | 28 | #include "TraceProviderFuchsia.h" |
John Bauman | 8153a44 | 2019-10-16 15:41:17 -0700 | [diff] [blame] | 29 | #include "services/service_connector.h" |
David Reveman | fc7d2fa | 2019-05-15 22:03:05 -0400 | [diff] [blame] | 30 | #endif |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 31 | |
Lingfeng Yang | e71c642 | 2018-11-01 19:29:49 -0700 | [diff] [blame] | 32 | #include "HostConnection.h" |
Lingfeng Yang | 33b91be | 2021-01-22 17:50:18 -0800 | [diff] [blame] | 33 | #include "ProcessPipe.h" |
Lingfeng Yang | 71b596b | 2018-11-07 18:03:25 -0800 | [diff] [blame] | 34 | #include "ResourceTracker.h" |
Lingfeng Yang | 3af8bd1 | 2018-11-03 12:49:30 -0700 | [diff] [blame] | 35 | #include "VkEncoder.h" |
Lingfeng Yang | 0b81df2 | 2018-11-05 21:40:30 -0800 | [diff] [blame] | 36 | #include "func_table.h" |
| 37 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 38 | // Used when there is no Vulkan support on the host. |
| 39 | // Copied from frameworks/native/vulkan/libvulkan/stubhal.cpp |
| 40 | namespace vkstubhal { |
| 41 | |
David Reveman | 0eac780 | 2019-09-09 22:59:39 -0400 | [diff] [blame] | 42 | [[noreturn]] VKAPI_ATTR void NoOp() { |
| 43 | LOG_ALWAYS_FATAL("invalid stub function called"); |
| 44 | } |
| 45 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 46 | VkResult |
| 47 | EnumerateInstanceExtensionProperties(const char* /*layer_name*/, |
| 48 | uint32_t* count, |
| 49 | VkExtensionProperties* /*properties*/) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 50 | AEMU_SCOPED_TRACE("vkstubhal::EnumerateInstanceExtensionProperties"); |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 51 | *count = 0; |
| 52 | return VK_SUCCESS; |
| 53 | } |
| 54 | |
| 55 | VkResult |
| 56 | EnumerateInstanceLayerProperties(uint32_t* count, |
| 57 | VkLayerProperties* /*properties*/) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 58 | AEMU_SCOPED_TRACE("vkstubhal::EnumerateInstanceLayerProperties"); |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 59 | *count = 0; |
| 60 | return VK_SUCCESS; |
| 61 | } |
| 62 | |
| 63 | VkResult CreateInstance(const VkInstanceCreateInfo* /*create_info*/, |
| 64 | const VkAllocationCallbacks* /*allocator*/, |
| 65 | VkInstance* instance) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 66 | AEMU_SCOPED_TRACE("vkstubhal::CreateInstance"); |
David Reveman | f1ed3a0 | 2019-06-06 23:06:04 -0400 | [diff] [blame] | 67 | auto dispatch = new hwvulkan_dispatch_t; |
| 68 | dispatch->magic = HWVULKAN_DISPATCH_MAGIC; |
| 69 | *instance = reinterpret_cast<VkInstance>(dispatch); |
| 70 | return VK_SUCCESS; |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void DestroyInstance(VkInstance instance, |
| 74 | const VkAllocationCallbacks* /*allocator*/) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 75 | AEMU_SCOPED_TRACE("vkstubhal::DestroyInstance"); |
David Reveman | f1ed3a0 | 2019-06-06 23:06:04 -0400 | [diff] [blame] | 76 | auto dispatch = reinterpret_cast<hwvulkan_dispatch_t*>(instance); |
| 77 | ALOG_ASSERT(dispatch->magic == HWVULKAN_DISPATCH_MAGIC, |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 78 | "DestroyInstance: invalid instance handle"); |
David Reveman | f1ed3a0 | 2019-06-06 23:06:04 -0400 | [diff] [blame] | 79 | delete dispatch; |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | VkResult EnumeratePhysicalDevices(VkInstance /*instance*/, |
| 83 | uint32_t* count, |
| 84 | VkPhysicalDevice* /*gpus*/) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 85 | AEMU_SCOPED_TRACE("vkstubhal::EnumeratePhysicalDevices"); |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 86 | *count = 0; |
| 87 | return VK_SUCCESS; |
| 88 | } |
| 89 | |
David Reveman | 0eac780 | 2019-09-09 22:59:39 -0400 | [diff] [blame] | 90 | VkResult EnumerateInstanceVersion(uint32_t* pApiVersion) { |
| 91 | AEMU_SCOPED_TRACE("vkstubhal::EnumerateInstanceVersion"); |
| 92 | *pApiVersion = VK_API_VERSION_1_0; |
| 93 | return VK_SUCCESS; |
| 94 | } |
| 95 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 96 | VkResult |
| 97 | EnumeratePhysicalDeviceGroups(VkInstance /*instance*/, |
| 98 | uint32_t* count, |
| 99 | VkPhysicalDeviceGroupProperties* /*properties*/) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 100 | AEMU_SCOPED_TRACE("vkstubhal::EnumeratePhysicalDeviceGroups"); |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 101 | *count = 0; |
| 102 | return VK_SUCCESS; |
| 103 | } |
| 104 | |
David Reveman | bb99e44 | 2019-05-27 11:13:32 -0400 | [diff] [blame] | 105 | VkResult |
| 106 | CreateDebugReportCallbackEXT(VkInstance /*instance*/, |
| 107 | const VkDebugReportCallbackCreateInfoEXT* /*pCreateInfo*/, |
| 108 | const VkAllocationCallbacks* /*pAllocator*/, |
David Reveman | f482390 | 2019-09-02 09:19:05 -0400 | [diff] [blame] | 109 | VkDebugReportCallbackEXT* pCallback) |
David Reveman | bb99e44 | 2019-05-27 11:13:32 -0400 | [diff] [blame] | 110 | { |
| 111 | AEMU_SCOPED_TRACE("vkstubhal::CreateDebugReportCallbackEXT"); |
David Reveman | f482390 | 2019-09-02 09:19:05 -0400 | [diff] [blame] | 112 | *pCallback = VK_NULL_HANDLE; |
David Reveman | bb99e44 | 2019-05-27 11:13:32 -0400 | [diff] [blame] | 113 | return VK_SUCCESS; |
| 114 | } |
| 115 | |
| 116 | void |
| 117 | DestroyDebugReportCallbackEXT(VkInstance /*instance*/, |
| 118 | VkDebugReportCallbackEXT /*callback*/, |
| 119 | const VkAllocationCallbacks* /*pAllocator*/) |
| 120 | { |
| 121 | AEMU_SCOPED_TRACE("vkstubhal::DestroyDebugReportCallbackEXT"); |
| 122 | } |
| 123 | |
| 124 | void |
| 125 | DebugReportMessageEXT(VkInstance /*instance*/, |
| 126 | VkDebugReportFlagsEXT /*flags*/, |
| 127 | VkDebugReportObjectTypeEXT /*objectType*/, |
| 128 | uint64_t /*object*/, |
| 129 | size_t /*location*/, |
| 130 | int32_t /*messageCode*/, |
| 131 | const char* /*pLayerPrefix*/, |
| 132 | const char* /*pMessage*/) |
| 133 | { |
| 134 | AEMU_SCOPED_TRACE("vkstubhal::DebugReportMessageEXT"); |
| 135 | } |
| 136 | |
David Reveman | 67eb5e2 | 2019-06-10 20:40:37 -0400 | [diff] [blame] | 137 | VkResult |
| 138 | CreateDebugUtilsMessengerEXT(VkInstance /*instance*/, |
| 139 | const VkDebugUtilsMessengerCreateInfoEXT* /*pCreateInfo*/, |
| 140 | const VkAllocationCallbacks* /*pAllocator*/, |
David Reveman | f482390 | 2019-09-02 09:19:05 -0400 | [diff] [blame] | 141 | VkDebugUtilsMessengerEXT* pMessenger) |
David Reveman | 67eb5e2 | 2019-06-10 20:40:37 -0400 | [diff] [blame] | 142 | { |
| 143 | AEMU_SCOPED_TRACE("vkstubhal::CreateDebugUtilsMessengerEXT"); |
David Reveman | f482390 | 2019-09-02 09:19:05 -0400 | [diff] [blame] | 144 | *pMessenger = VK_NULL_HANDLE; |
David Reveman | 67eb5e2 | 2019-06-10 20:40:37 -0400 | [diff] [blame] | 145 | return VK_SUCCESS; |
| 146 | } |
| 147 | |
| 148 | void |
| 149 | DestroyDebugUtilsMessengerEXT(VkInstance /*instance*/, |
| 150 | VkDebugUtilsMessengerEXT /*messenger*/, |
| 151 | const VkAllocationCallbacks* /*pAllocator*/) |
| 152 | { |
| 153 | AEMU_SCOPED_TRACE("vkstubhal::DestroyDebugUtilsMessengerkEXT"); |
| 154 | } |
| 155 | |
| 156 | void |
| 157 | SubmitDebugUtilsMessageEXT(VkInstance /*instance*/, |
| 158 | VkDebugUtilsMessageSeverityFlagBitsEXT /*messageSeverity*/, |
| 159 | VkDebugUtilsMessageTypeFlagsEXT /*messageTypes*/, |
| 160 | const VkDebugUtilsMessengerCallbackDataEXT* /*pCallbackData*/) |
| 161 | { |
| 162 | AEMU_SCOPED_TRACE("vkstubhal::SubmitDebugUtilsMessageEXT"); |
| 163 | } |
| 164 | |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 165 | #ifdef VK_USE_PLATFORM_FUCHSIA |
| 166 | VkResult |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 167 | GetMemoryZirconHandleFUCHSIA(VkDevice /*device*/, |
| 168 | const VkMemoryGetZirconHandleInfoFUCHSIA* /*pInfo*/, |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 169 | uint32_t* pHandle) { |
David Reveman | 488704f | 2019-03-27 01:29:08 -0400 | [diff] [blame] | 170 | AEMU_SCOPED_TRACE("vkstubhal::GetMemoryZirconHandleFUCHSIA"); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 171 | *pHandle = 0; |
| 172 | return VK_SUCCESS; |
| 173 | } |
| 174 | |
| 175 | VkResult |
David Reveman | 488704f | 2019-03-27 01:29:08 -0400 | [diff] [blame] | 176 | GetMemoryZirconHandlePropertiesFUCHSIA(VkDevice /*device*/, |
| 177 | VkExternalMemoryHandleTypeFlagBits /*handleType*/, |
| 178 | uint32_t /*handle*/, |
| 179 | VkMemoryZirconHandlePropertiesFUCHSIA* /*pProperties*/) { |
| 180 | AEMU_SCOPED_TRACE("vkstubhal::GetMemoryZirconHandlePropertiesFUCHSIA"); |
| 181 | return VK_SUCCESS; |
| 182 | } |
| 183 | |
| 184 | VkResult |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 185 | GetSemaphoreZirconHandleFUCHSIA(VkDevice /*device*/, |
| 186 | const VkSemaphoreGetZirconHandleInfoFUCHSIA* /*pInfo*/, |
| 187 | uint32_t* pHandle) { |
David Reveman | 488704f | 2019-03-27 01:29:08 -0400 | [diff] [blame] | 188 | AEMU_SCOPED_TRACE("vkstubhal::GetSemaphoreZirconHandleFUCHSIA"); |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 189 | *pHandle = 0; |
| 190 | return VK_SUCCESS; |
| 191 | } |
| 192 | |
| 193 | VkResult |
| 194 | ImportSemaphoreZirconHandleFUCHSIA(VkDevice /*device*/, |
| 195 | const VkImportSemaphoreZirconHandleInfoFUCHSIA* /*pInfo*/) { |
David Reveman | 488704f | 2019-03-27 01:29:08 -0400 | [diff] [blame] | 196 | AEMU_SCOPED_TRACE("vkstubhal::ImportSemaphoreZirconHandleFUCHSIA"); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 197 | return VK_SUCCESS; |
| 198 | } |
David Reveman | e10aae2 | 2019-03-17 15:55:45 -0400 | [diff] [blame] | 199 | |
Yilong Li | e12328f | 2022-01-06 03:32:13 -0800 | [diff] [blame] | 200 | VkResult CreateBufferCollectionFUCHSIA( |
| 201 | VkDevice /*device*/, |
| 202 | const VkBufferCollectionCreateInfoFUCHSIA* /*pInfo*/, |
| 203 | const VkAllocationCallbacks* /*pAllocator*/, |
| 204 | VkBufferCollectionFUCHSIA* /*pCollection*/) { |
| 205 | AEMU_SCOPED_TRACE("vkstubhal::CreateBufferCollectionFUCHSIA"); |
| 206 | return VK_SUCCESS; |
| 207 | } |
| 208 | |
| 209 | void DestroyBufferCollectionFUCHSIA( |
| 210 | VkDevice /*device*/, |
| 211 | VkBufferCollectionFUCHSIA /*collection*/, |
| 212 | const VkAllocationCallbacks* /*pAllocator*/) { |
| 213 | AEMU_SCOPED_TRACE("vkstubhal::DestroyBufferCollectionFUCHSIA"); |
| 214 | } |
| 215 | |
| 216 | VkResult SetBufferCollectionImageConstraintsFUCHSIA( |
| 217 | VkDevice /*device*/, |
| 218 | VkBufferCollectionFUCHSIA /*collection*/, |
| 219 | const VkImageConstraintsInfoFUCHSIA* /*pImageConstraintsInfo*/) { |
| 220 | AEMU_SCOPED_TRACE("vkstubhal::SetBufferCollectionImageConstraintsFUCHSIA"); |
| 221 | return VK_SUCCESS; |
| 222 | } |
| 223 | |
| 224 | VkResult SetBufferCollectionBufferConstraintsFUCHSIA( |
| 225 | VkDevice /*device*/, |
| 226 | VkBufferCollectionFUCHSIA /*collection*/, |
| 227 | const VkBufferConstraintsInfoFUCHSIA* /*pBufferConstraintsInfo*/) { |
| 228 | AEMU_SCOPED_TRACE("vkstubhal::SetBufferCollectionBufferConstraintsFUCHSIA"); |
| 229 | return VK_SUCCESS; |
| 230 | } |
| 231 | |
| 232 | VkResult GetBufferCollectionPropertiesFUCHSIA( |
| 233 | VkDevice /*device*/, |
| 234 | VkBufferCollectionFUCHSIA /*collection*/, |
| 235 | VkBufferCollectionPropertiesFUCHSIA* /*pProperties*/) { |
| 236 | AEMU_SCOPED_TRACE("vkstubhal::GetBufferCollectionPropertiesFUCHSIA"); |
| 237 | return VK_SUCCESS; |
| 238 | } |
| 239 | |
Yilong Li | aac34f9 | 2021-06-30 14:41:48 -0700 | [diff] [blame] | 240 | VkResult CreateBufferCollectionFUCHSIAX( |
| 241 | VkDevice /*device*/, |
| 242 | const VkBufferCollectionCreateInfoFUCHSIAX* /*pInfo*/, |
| 243 | const VkAllocationCallbacks* /*pAllocator*/, |
| 244 | VkBufferCollectionFUCHSIAX* /*pCollection*/) { |
| 245 | AEMU_SCOPED_TRACE("vkstubhal::CreateBufferCollectionFUCHSIAX"); |
| 246 | return VK_SUCCESS; |
| 247 | } |
| 248 | |
| 249 | void DestroyBufferCollectionFUCHSIAX( |
| 250 | VkDevice /*device*/, |
| 251 | VkBufferCollectionFUCHSIAX /*collection*/, |
| 252 | const VkAllocationCallbacks* /*pAllocator*/) { |
| 253 | AEMU_SCOPED_TRACE("vkstubhal::DestroyBufferCollectionFUCHSIAX"); |
| 254 | } |
| 255 | |
| 256 | VkResult SetBufferCollectionConstraintsFUCHSIAX( |
| 257 | VkDevice /*device*/, |
| 258 | VkBufferCollectionFUCHSIAX /*collection*/, |
| 259 | const VkImageCreateInfo* /*pImageInfo*/) { |
| 260 | AEMU_SCOPED_TRACE("vkstubhal::SetBufferCollectionConstraintsFUCHSIAX"); |
| 261 | return VK_SUCCESS; |
| 262 | } |
| 263 | |
| 264 | VkResult SetBufferCollectionImageConstraintsFUCHSIAX( |
| 265 | VkDevice /*device*/, |
| 266 | VkBufferCollectionFUCHSIAX /*collection*/, |
| 267 | const VkImageConstraintsInfoFUCHSIAX* /*pImageConstraintsInfo*/) { |
| 268 | AEMU_SCOPED_TRACE("vkstubhal::SetBufferCollectionImageConstraintsFUCHSIAX"); |
| 269 | return VK_SUCCESS; |
| 270 | } |
| 271 | |
| 272 | VkResult SetBufferCollectionBufferConstraintsFUCHSIAX( |
| 273 | VkDevice /*device*/, |
| 274 | VkBufferCollectionFUCHSIAX /*collection*/, |
| 275 | const VkBufferConstraintsInfoFUCHSIAX* /*pBufferConstraintsInfo*/) { |
| 276 | AEMU_SCOPED_TRACE( |
| 277 | "vkstubhal::SetBufferCollectionBufferConstraintsFUCHSIAX"); |
| 278 | return VK_SUCCESS; |
| 279 | } |
| 280 | |
| 281 | VkResult GetBufferCollectionPropertiesFUCHSIAX( |
| 282 | VkDevice /*device*/, |
| 283 | VkBufferCollectionFUCHSIAX /*collection*/, |
| 284 | VkBufferCollectionPropertiesFUCHSIAX* /*pProperties*/) { |
| 285 | AEMU_SCOPED_TRACE("vkstubhal::GetBufferCollectionPropertiesFUCHSIAX"); |
| 286 | return VK_SUCCESS; |
| 287 | } |
| 288 | |
| 289 | VkResult GetBufferCollectionProperties2FUCHSIAX( |
| 290 | VkDevice /*device*/, |
| 291 | VkBufferCollectionFUCHSIAX /*collection*/, |
| 292 | VkBufferCollectionProperties2FUCHSIAX* /*pProperties*/) { |
| 293 | AEMU_SCOPED_TRACE("vkstubhal::GetBufferCollectionProperties2FUCHSIAX"); |
| 294 | return VK_SUCCESS; |
| 295 | } |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 296 | #endif |
| 297 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 298 | PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, |
| 299 | const char* name) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 300 | AEMU_SCOPED_TRACE("vkstubhal::GetInstanceProcAddr"); |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 301 | if (strcmp(name, "vkCreateInstance") == 0) |
| 302 | return reinterpret_cast<PFN_vkVoidFunction>(CreateInstance); |
| 303 | if (strcmp(name, "vkDestroyInstance") == 0) |
| 304 | return reinterpret_cast<PFN_vkVoidFunction>(DestroyInstance); |
| 305 | if (strcmp(name, "vkEnumerateInstanceExtensionProperties") == 0) |
| 306 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 307 | EnumerateInstanceExtensionProperties); |
| 308 | if (strcmp(name, "vkEnumeratePhysicalDevices") == 0) |
| 309 | return reinterpret_cast<PFN_vkVoidFunction>(EnumeratePhysicalDevices); |
David Reveman | 0eac780 | 2019-09-09 22:59:39 -0400 | [diff] [blame] | 310 | if (strcmp(name, "vkEnumerateInstanceVersion") == 0) |
| 311 | return reinterpret_cast<PFN_vkVoidFunction>(EnumerateInstanceVersion); |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 312 | if (strcmp(name, "vkEnumeratePhysicalDeviceGroups") == 0) |
| 313 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 314 | EnumeratePhysicalDeviceGroups); |
David Reveman | a65a771 | 2019-05-25 14:07:28 -0400 | [diff] [blame] | 315 | if (strcmp(name, "vkEnumeratePhysicalDeviceGroupsKHR") == 0) |
| 316 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 317 | EnumeratePhysicalDeviceGroups); |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 318 | if (strcmp(name, "vkGetInstanceProcAddr") == 0) |
| 319 | return reinterpret_cast<PFN_vkVoidFunction>(GetInstanceProcAddr); |
David Reveman | bb99e44 | 2019-05-27 11:13:32 -0400 | [diff] [blame] | 320 | if (strcmp(name, "vkCreateDebugReportCallbackEXT") == 0) |
| 321 | return reinterpret_cast<PFN_vkVoidFunction>(CreateDebugReportCallbackEXT); |
| 322 | if (strcmp(name, "vkDestroyDebugReportCallbackEXT") == 0) |
| 323 | return reinterpret_cast<PFN_vkVoidFunction>(DestroyDebugReportCallbackEXT); |
| 324 | if (strcmp(name, "vkDebugReportMessageEXT") == 0) |
| 325 | return reinterpret_cast<PFN_vkVoidFunction>(DebugReportMessageEXT); |
David Reveman | 67eb5e2 | 2019-06-10 20:40:37 -0400 | [diff] [blame] | 326 | if (strcmp(name, "vkCreateDebugUtilsMessengerEXT") == 0) |
| 327 | return reinterpret_cast<PFN_vkVoidFunction>(CreateDebugUtilsMessengerEXT); |
| 328 | if (strcmp(name, "vkDestroyDebugUtilsMessengerEXT") == 0) |
| 329 | return reinterpret_cast<PFN_vkVoidFunction>(DestroyDebugUtilsMessengerEXT); |
| 330 | if (strcmp(name, "vkSubmitDebugUtilsMessageEXT") == 0) |
| 331 | return reinterpret_cast<PFN_vkVoidFunction>(SubmitDebugUtilsMessageEXT); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 332 | #ifdef VK_USE_PLATFORM_FUCHSIA |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 333 | if (strcmp(name, "vkGetMemoryZirconHandleFUCHSIA") == 0) |
| 334 | return reinterpret_cast<PFN_vkVoidFunction>(GetMemoryZirconHandleFUCHSIA); |
David Reveman | 488704f | 2019-03-27 01:29:08 -0400 | [diff] [blame] | 335 | if (strcmp(name, "vkGetMemoryZirconHandlePropertiesFUCHSIA") == 0) |
| 336 | return reinterpret_cast<PFN_vkVoidFunction>(GetMemoryZirconHandlePropertiesFUCHSIA); |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 337 | if (strcmp(name, "vkGetSemaphoreZirconHandleFUCHSIA") == 0) |
| 338 | return reinterpret_cast<PFN_vkVoidFunction>(GetSemaphoreZirconHandleFUCHSIA); |
| 339 | if (strcmp(name, "vkImportSemaphoreZirconHandleFUCHSIA") == 0) |
| 340 | return reinterpret_cast<PFN_vkVoidFunction>(ImportSemaphoreZirconHandleFUCHSIA); |
Yilong Li | e12328f | 2022-01-06 03:32:13 -0800 | [diff] [blame] | 341 | if (strcmp(name, "vkCreateBufferCollectionFUCHSIA") == 0) |
| 342 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 343 | CreateBufferCollectionFUCHSIA); |
| 344 | if (strcmp(name, "vkDestroyBufferCollectionFUCHSIA") == 0) |
| 345 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 346 | DestroyBufferCollectionFUCHSIA); |
| 347 | if (strcmp(name, "vkSetBufferCollectionImageConstraintsFUCHSIA") == 0) |
| 348 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 349 | SetBufferCollectionImageConstraintsFUCHSIA); |
| 350 | if (strcmp(name, "vkSetBufferCollectionBufferConstraintsFUCHSIA") == 0) |
| 351 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 352 | SetBufferCollectionBufferConstraintsFUCHSIA); |
| 353 | if (strcmp(name, "vkGetBufferCollectionPropertiesFUCHSIA") == 0) |
| 354 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 355 | GetBufferCollectionPropertiesFUCHSIA); |
Yilong Li | aac34f9 | 2021-06-30 14:41:48 -0700 | [diff] [blame] | 356 | if (strcmp(name, "vkCreateBufferCollectionFUCHSIAX") == 0) |
| 357 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 358 | CreateBufferCollectionFUCHSIAX); |
| 359 | if (strcmp(name, "vkDestroyBufferCollectionFUCHSIAX") == 0) |
| 360 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 361 | DestroyBufferCollectionFUCHSIAX); |
| 362 | if (strcmp(name, "vkSetBufferCollectionConstraintsFUCHSIAX") == 0) |
| 363 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 364 | SetBufferCollectionConstraintsFUCHSIAX); |
| 365 | if (strcmp(name, "vkSetBufferCollectionImageConstraintsFUCHSIAX") == 0) |
| 366 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 367 | SetBufferCollectionImageConstraintsFUCHSIAX); |
| 368 | if (strcmp(name, "vkSetBufferCollectionBufferConstraintsFUCHSIAX") == 0) |
| 369 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 370 | SetBufferCollectionBufferConstraintsFUCHSIAX); |
| 371 | if (strcmp(name, "vkGetBufferCollectionPropertiesFUCHSIAX") == 0) |
| 372 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 373 | GetBufferCollectionPropertiesFUCHSIAX); |
| 374 | if (strcmp(name, "vkGetBufferCollectionProperties2FUCHSIAX") == 0) |
| 375 | return reinterpret_cast<PFN_vkVoidFunction>( |
| 376 | GetBufferCollectionProperties2FUCHSIAX); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 377 | #endif |
David Reveman | 0eac780 | 2019-09-09 22:59:39 -0400 | [diff] [blame] | 378 | // Return NoOp for entrypoints that should never be called. |
| 379 | if (strcmp(name, "vkGetPhysicalDeviceFeatures") == 0 || |
| 380 | strcmp(name, "vkGetPhysicalDeviceProperties") == 0 || |
| 381 | strcmp(name, "vkGetPhysicalDeviceFormatProperties") == 0 || |
| 382 | strcmp(name, "vkGetPhysicalDeviceImageFormatProperties") == 0 || |
| 383 | strcmp(name, "vkGetPhysicalDeviceMemoryProperties") == 0 || |
| 384 | strcmp(name, "vkGetPhysicalDeviceQueueFamilyProperties") == 0 || |
| 385 | strcmp(name, "vkGetDeviceProcAddr") == 0 || |
| 386 | strcmp(name, "vkCreateDevice") == 0 || |
| 387 | strcmp(name, "vkEnumerateDeviceExtensionProperties") == 0 || |
| 388 | strcmp(name, "vkGetPhysicalDeviceSparseImageFormatProperties") == 0 || |
| 389 | strcmp(name, "vkGetPhysicalDeviceFeatures2") == 0 || |
| 390 | strcmp(name, "vkGetPhysicalDeviceProperties2") == 0 || |
| 391 | strcmp(name, "vkGetPhysicalDeviceFormatProperties2") == 0 || |
| 392 | strcmp(name, "vkGetPhysicalDeviceImageFormatProperties2") == 0 || |
| 393 | strcmp(name, "vkGetPhysicalDeviceQueueFamilyProperties2") == 0 || |
| 394 | strcmp(name, "vkGetPhysicalDeviceMemoryProperties2") == 0 || |
| 395 | strcmp(name, "vkGetPhysicalDeviceSparseImageFormatProperties2") == 0 || |
| 396 | strcmp(name, "vkGetPhysicalDeviceExternalBufferProperties") == 0 || |
| 397 | strcmp(name, "vkGetPhysicalDeviceExternalFenceProperties") == 0 || |
| 398 | strcmp(name, "vkGetPhysicalDeviceExternalSemaphoreProperties") == 0) |
| 399 | return reinterpret_cast<PFN_vkVoidFunction>(NoOp); |
| 400 | |
David Reveman | e8b8780 | 2019-08-30 07:58:54 -0400 | [diff] [blame] | 401 | // Per the spec, return NULL for nonexistent entrypoints. |
| 402 | return nullptr; |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | } // namespace vkstubhal |
| 406 | |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 407 | namespace { |
| 408 | |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 409 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 410 | |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 411 | int OpenDevice(const hw_module_t* module, const char* id, hw_device_t** device); |
| 412 | |
| 413 | hw_module_methods_t goldfish_vulkan_module_methods = { |
| 414 | .open = OpenDevice |
| 415 | }; |
| 416 | |
| 417 | extern "C" __attribute__((visibility("default"))) hwvulkan_module_t HAL_MODULE_INFO_SYM = { |
| 418 | .common = { |
| 419 | .tag = HARDWARE_MODULE_TAG, |
| 420 | .module_api_version = HWVULKAN_MODULE_API_VERSION_0_1, |
| 421 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 422 | .id = HWVULKAN_HARDWARE_MODULE_ID, |
| 423 | .name = "Goldfish Vulkan Driver", |
| 424 | .author = "The Android Open Source Project", |
| 425 | .methods = &goldfish_vulkan_module_methods, |
| 426 | }, |
| 427 | }; |
| 428 | |
Lingfeng Yang | 09d0f91 | 2019-02-05 23:17:25 +0000 | [diff] [blame] | 429 | int CloseDevice(struct hw_device_t* /*device*/) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 430 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetInstanceProcAddr"); |
Lingfeng Yang | 09d0f91 | 2019-02-05 23:17:25 +0000 | [diff] [blame] | 431 | // nothing to do - opening a device doesn't allocate any resources |
| 432 | return 0; |
| 433 | } |
| 434 | |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 435 | #endif |
| 436 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 437 | #define VK_HOST_CONNECTION(ret) \ |
Gurchetan Singh | a9f2791 | 2022-02-09 12:56:27 -0800 | [diff] [blame] | 438 | HostConnection *hostCon = HostConnection::getOrCreate(VIRTIO_GPU_CAPSET_GFXSTREAM); \ |
Lingfeng Yang | e71c642 | 2018-11-01 19:29:49 -0700 | [diff] [blame] | 439 | if (!hostCon) { \ |
| 440 | ALOGE("vulkan: Failed to get host connection\n"); \ |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 441 | return ret; \ |
Lingfeng Yang | e71c642 | 2018-11-01 19:29:49 -0700 | [diff] [blame] | 442 | } \ |
| 443 | ExtendedRCEncoderContext *rcEnc = hostCon->rcEncoder(); \ |
| 444 | if (!rcEnc) { \ |
| 445 | ALOGE("vulkan: Failed to get renderControl encoder context\n"); \ |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 446 | return ret; \ |
Lingfeng Yang | 3af8bd1 | 2018-11-03 12:49:30 -0700 | [diff] [blame] | 447 | } \ |
Lingfeng Yang | 34b5cae | 2019-08-21 14:12:19 -0700 | [diff] [blame] | 448 | goldfish_vk::ResourceTracker::ThreadingCallbacks threadingCallbacks = { \ |
Luca Stefani | 28a2e81 | 2020-07-04 17:50:57 +0200 | [diff] [blame] | 449 | [] { \ |
| 450 | auto hostCon = HostConnection::get(); \ |
| 451 | hostCon->rcEncoder(); \ |
| 452 | return hostCon; \ |
| 453 | }, \ |
Lingfeng Yang | cd2d8fe | 2019-08-16 12:21:50 -0700 | [diff] [blame] | 454 | [](HostConnection* hostCon) { return hostCon->vkEncoder(); }, \ |
Lingfeng Yang | 34b5cae | 2019-08-21 14:12:19 -0700 | [diff] [blame] | 455 | }; \ |
| 456 | goldfish_vk::ResourceTracker::get()->setThreadingCallbacks(threadingCallbacks); \ |
Gurchetan Singh | a9f2791 | 2022-02-09 12:56:27 -0800 | [diff] [blame] | 457 | goldfish_vk::ResourceTracker::get()->setupFeatures(rcEnc->featureInfo_const()); \ |
| 458 | goldfish_vk::ResourceTracker::get()->setSeqnoPtr(getSeqnoPtrForProcess()); \ |
Lingfeng Yang | b55ed1c | 2019-06-20 15:57:08 -0700 | [diff] [blame] | 459 | auto hostSupportsVulkan = goldfish_vk::ResourceTracker::get()->hostSupportsVulkan(); \ |
Lingfeng Yang | b1d9010 | 2018-11-29 16:10:36 -0800 | [diff] [blame] | 460 | goldfish_vk::VkEncoder *vkEnc = hostCon->vkEncoder(); \ |
Lingfeng Yang | 3af8bd1 | 2018-11-03 12:49:30 -0700 | [diff] [blame] | 461 | if (!vkEnc) { \ |
| 462 | ALOGE("vulkan: Failed to get Vulkan encoder\n"); \ |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 463 | return ret; \ |
Lingfeng Yang | 3af8bd1 | 2018-11-03 12:49:30 -0700 | [diff] [blame] | 464 | } \ |
Lingfeng Yang | e71c642 | 2018-11-01 19:29:49 -0700 | [diff] [blame] | 465 | |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 466 | VKAPI_ATTR |
| 467 | VkResult EnumerateInstanceExtensionProperties( |
| 468 | const char* layer_name, |
| 469 | uint32_t* count, |
| 470 | VkExtensionProperties* properties) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 471 | AEMU_SCOPED_TRACE("goldfish_vulkan::EnumerateInstanceExtensionProperties"); |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 472 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 473 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 474 | |
| 475 | if (!hostSupportsVulkan) { |
| 476 | return vkstubhal::EnumerateInstanceExtensionProperties(layer_name, count, properties); |
| 477 | } |
Lingfeng Yang | e71c642 | 2018-11-01 19:29:49 -0700 | [diff] [blame] | 478 | |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 479 | if (layer_name) { |
| 480 | ALOGW( |
| 481 | "Driver vkEnumerateInstanceExtensionProperties shouldn't be called " |
| 482 | "with a layer name ('%s')", |
| 483 | layer_name); |
| 484 | } |
| 485 | |
Lingfeng Yang | 154a33c | 2019-01-29 19:06:23 -0800 | [diff] [blame] | 486 | VkResult res = goldfish_vk::ResourceTracker::get()->on_vkEnumerateInstanceExtensionProperties( |
| 487 | vkEnc, VK_SUCCESS, layer_name, count, properties); |
Lingfeng Yang | 7dea7b3 | 2018-12-18 09:49:02 -0800 | [diff] [blame] | 488 | |
Lingfeng Yang | 154a33c | 2019-01-29 19:06:23 -0800 | [diff] [blame] | 489 | return res; |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | VKAPI_ATTR |
| 493 | VkResult CreateInstance(const VkInstanceCreateInfo* create_info, |
| 494 | const VkAllocationCallbacks* allocator, |
| 495 | VkInstance* out_instance) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 496 | AEMU_SCOPED_TRACE("goldfish_vulkan::CreateInstance"); |
| 497 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 498 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 499 | |
| 500 | if (!hostSupportsVulkan) { |
| 501 | return vkstubhal::CreateInstance(create_info, allocator, out_instance); |
| 502 | } |
Lingfeng Yang | d744704 | 2018-10-25 11:09:18 -0700 | [diff] [blame] | 503 | |
Lingfeng Yang | a1d57a5 | 2021-01-08 14:02:14 -0800 | [diff] [blame] | 504 | VkResult res = vkEnc->vkCreateInstance(create_info, nullptr, out_instance, true /* do lock */); |
Lingfeng Yang | 0b81df2 | 2018-11-05 21:40:30 -0800 | [diff] [blame] | 505 | |
| 506 | return res; |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 507 | } |
| 508 | |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 509 | #ifdef VK_USE_PLATFORM_FUCHSIA |
| 510 | VKAPI_ATTR |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 511 | VkResult GetMemoryZirconHandleFUCHSIA( |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 512 | VkDevice device, |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 513 | const VkMemoryGetZirconHandleInfoFUCHSIA* pInfo, |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 514 | uint32_t* pHandle) { |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 515 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetMemoryZirconHandleFUCHSIA"); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 516 | |
| 517 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 518 | |
| 519 | if (!hostSupportsVulkan) { |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 520 | return vkstubhal::GetMemoryZirconHandleFUCHSIA(device, pInfo, pHandle); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | VkResult res = goldfish_vk::ResourceTracker::get()-> |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 524 | on_vkGetMemoryZirconHandleFUCHSIA( |
Lingfeng Yang | f83538d | 2019-03-07 15:07:36 -0800 | [diff] [blame] | 525 | vkEnc, VK_SUCCESS, |
| 526 | device, pInfo, pHandle); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 527 | |
| 528 | return res; |
| 529 | } |
| 530 | |
| 531 | VKAPI_ATTR |
David Reveman | 488704f | 2019-03-27 01:29:08 -0400 | [diff] [blame] | 532 | VkResult GetMemoryZirconHandlePropertiesFUCHSIA( |
| 533 | VkDevice device, |
| 534 | VkExternalMemoryHandleTypeFlagBits handleType, |
| 535 | uint32_t handle, |
| 536 | VkMemoryZirconHandlePropertiesFUCHSIA* pProperties) { |
| 537 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetMemoryZirconHandlePropertiesFUCHSIA"); |
| 538 | |
| 539 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 540 | |
| 541 | if (!hostSupportsVulkan) { |
| 542 | return vkstubhal::GetMemoryZirconHandlePropertiesFUCHSIA( |
| 543 | device, handleType, handle, pProperties); |
| 544 | } |
| 545 | |
| 546 | VkResult res = goldfish_vk::ResourceTracker::get()-> |
| 547 | on_vkGetMemoryZirconHandlePropertiesFUCHSIA( |
| 548 | vkEnc, VK_SUCCESS, device, handleType, handle, pProperties); |
| 549 | |
| 550 | return res; |
| 551 | } |
| 552 | |
| 553 | VKAPI_ATTR |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 554 | VkResult GetSemaphoreZirconHandleFUCHSIA( |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 555 | VkDevice device, |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 556 | const VkSemaphoreGetZirconHandleInfoFUCHSIA* pInfo, |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 557 | uint32_t* pHandle) { |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 558 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetSemaphoreZirconHandleFUCHSIA"); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 559 | |
| 560 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 561 | |
| 562 | if (!hostSupportsVulkan) { |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 563 | return vkstubhal::GetSemaphoreZirconHandleFUCHSIA(device, pInfo, pHandle); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | VkResult res = goldfish_vk::ResourceTracker::get()-> |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 567 | on_vkGetSemaphoreZirconHandleFUCHSIA( |
Lingfeng Yang | f83538d | 2019-03-07 15:07:36 -0800 | [diff] [blame] | 568 | vkEnc, VK_SUCCESS, device, pInfo, pHandle); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 569 | |
| 570 | return res; |
| 571 | } |
| 572 | |
| 573 | VKAPI_ATTR |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 574 | VkResult ImportSemaphoreZirconHandleFUCHSIA( |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 575 | VkDevice device, |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 576 | const VkImportSemaphoreZirconHandleInfoFUCHSIA* pInfo) { |
| 577 | AEMU_SCOPED_TRACE("goldfish_vulkan::ImportSemaphoreZirconHandleFUCHSIA"); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 578 | |
| 579 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 580 | |
| 581 | if (!hostSupportsVulkan) { |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 582 | return vkstubhal::ImportSemaphoreZirconHandleFUCHSIA(device, pInfo); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | VkResult res = goldfish_vk::ResourceTracker::get()-> |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 586 | on_vkImportSemaphoreZirconHandleFUCHSIA( |
Lingfeng Yang | f83538d | 2019-03-07 15:07:36 -0800 | [diff] [blame] | 587 | vkEnc, VK_SUCCESS, device, pInfo); |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 588 | |
| 589 | return res; |
| 590 | } |
David Reveman | e10aae2 | 2019-03-17 15:55:45 -0400 | [diff] [blame] | 591 | |
| 592 | VKAPI_ATTR |
Yilong Li | e12328f | 2022-01-06 03:32:13 -0800 | [diff] [blame] | 593 | VkResult CreateBufferCollectionFUCHSIA( |
| 594 | VkDevice device, |
| 595 | const VkBufferCollectionCreateInfoFUCHSIA* pInfo, |
| 596 | const VkAllocationCallbacks* pAllocator, |
| 597 | VkBufferCollectionFUCHSIA* pCollection) { |
| 598 | AEMU_SCOPED_TRACE("goldfish_vulkan::CreateBufferCollectionFUCHSIA"); |
| 599 | |
| 600 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 601 | |
| 602 | if (!hostSupportsVulkan) { |
| 603 | return vkstubhal::CreateBufferCollectionFUCHSIA( |
| 604 | device, pInfo, pAllocator, pCollection); |
| 605 | } |
| 606 | |
| 607 | VkResult res = |
| 608 | goldfish_vk::ResourceTracker::get()->on_vkCreateBufferCollectionFUCHSIA( |
| 609 | vkEnc, VK_SUCCESS, device, pInfo, pAllocator, pCollection); |
| 610 | |
| 611 | return res; |
| 612 | } |
| 613 | |
| 614 | VKAPI_ATTR |
| 615 | void DestroyBufferCollectionFUCHSIA(VkDevice device, |
| 616 | VkBufferCollectionFUCHSIA collection, |
| 617 | const VkAllocationCallbacks* pAllocator) { |
| 618 | AEMU_SCOPED_TRACE("goldfish_vulkan::DestroyBufferCollectionFUCHSIA"); |
| 619 | |
| 620 | VK_HOST_CONNECTION() |
| 621 | |
| 622 | if (!hostSupportsVulkan) { |
| 623 | vkstubhal::DestroyBufferCollectionFUCHSIA(device, collection, |
| 624 | pAllocator); |
| 625 | return; |
| 626 | } |
| 627 | |
| 628 | goldfish_vk::ResourceTracker::get()->on_vkDestroyBufferCollectionFUCHSIA( |
| 629 | vkEnc, VK_SUCCESS, device, collection, pAllocator); |
| 630 | } |
| 631 | |
| 632 | VKAPI_ATTR |
| 633 | VkResult SetBufferCollectionBufferConstraintsFUCHSIA( |
| 634 | VkDevice device, |
| 635 | VkBufferCollectionFUCHSIA collection, |
| 636 | const VkBufferConstraintsInfoFUCHSIA* pBufferConstraintsInfo) { |
| 637 | AEMU_SCOPED_TRACE( |
| 638 | "goldfish_vulkan::SetBufferCollectionBufferConstraintsFUCHSIA"); |
| 639 | |
| 640 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 641 | |
| 642 | if (!hostSupportsVulkan) { |
| 643 | return vkstubhal::SetBufferCollectionBufferConstraintsFUCHSIA( |
| 644 | device, collection, pBufferConstraintsInfo); |
| 645 | } |
| 646 | |
| 647 | VkResult res = |
| 648 | goldfish_vk::ResourceTracker::get() |
| 649 | ->on_vkSetBufferCollectionBufferConstraintsFUCHSIA( |
| 650 | vkEnc, VK_SUCCESS, device, collection, pBufferConstraintsInfo); |
| 651 | |
| 652 | return res; |
| 653 | } |
| 654 | |
| 655 | VKAPI_ATTR |
| 656 | VkResult SetBufferCollectionImageConstraintsFUCHSIA( |
| 657 | VkDevice device, |
| 658 | VkBufferCollectionFUCHSIA collection, |
| 659 | const VkImageConstraintsInfoFUCHSIA* pImageConstraintsInfo) { |
| 660 | AEMU_SCOPED_TRACE( |
| 661 | "goldfish_vulkan::SetBufferCollectionBufferConstraintsFUCHSIA"); |
| 662 | |
| 663 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 664 | |
| 665 | if (!hostSupportsVulkan) { |
| 666 | return vkstubhal::SetBufferCollectionImageConstraintsFUCHSIA( |
| 667 | device, collection, pImageConstraintsInfo); |
| 668 | } |
| 669 | |
| 670 | VkResult res = |
| 671 | goldfish_vk::ResourceTracker::get() |
| 672 | ->on_vkSetBufferCollectionImageConstraintsFUCHSIA( |
| 673 | vkEnc, VK_SUCCESS, device, collection, pImageConstraintsInfo); |
| 674 | |
| 675 | return res; |
| 676 | } |
| 677 | |
| 678 | VKAPI_ATTR |
| 679 | VkResult GetBufferCollectionPropertiesFUCHSIA( |
| 680 | VkDevice device, |
| 681 | VkBufferCollectionFUCHSIA collection, |
| 682 | VkBufferCollectionPropertiesFUCHSIA* pProperties) { |
| 683 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetBufferCollectionPropertiesFUCHSIA"); |
| 684 | |
| 685 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 686 | |
| 687 | if (!hostSupportsVulkan) { |
| 688 | return vkstubhal::GetBufferCollectionPropertiesFUCHSIA( |
| 689 | device, collection, pProperties); |
| 690 | } |
| 691 | |
| 692 | VkResult res = goldfish_vk::ResourceTracker::get() |
| 693 | ->on_vkGetBufferCollectionPropertiesFUCHSIA( |
| 694 | vkEnc, VK_SUCCESS, device, collection, pProperties); |
| 695 | |
| 696 | return res; |
| 697 | } |
| 698 | |
| 699 | VKAPI_ATTR |
Yilong Li | aac34f9 | 2021-06-30 14:41:48 -0700 | [diff] [blame] | 700 | VkResult CreateBufferCollectionFUCHSIAX( |
| 701 | VkDevice device, |
| 702 | const VkBufferCollectionCreateInfoFUCHSIAX* pInfo, |
| 703 | const VkAllocationCallbacks* pAllocator, |
| 704 | VkBufferCollectionFUCHSIAX* pCollection) { |
| 705 | AEMU_SCOPED_TRACE("goldfish_vulkan::CreateBufferCollectionFUCHSIAX"); |
| 706 | |
| 707 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 708 | |
| 709 | if (!hostSupportsVulkan) { |
| 710 | return vkstubhal::CreateBufferCollectionFUCHSIAX( |
| 711 | device, pInfo, pAllocator, pCollection); |
| 712 | } |
| 713 | |
| 714 | VkResult res = |
| 715 | goldfish_vk::ResourceTracker::get() |
| 716 | ->on_vkCreateBufferCollectionFUCHSIAX( |
| 717 | vkEnc, VK_SUCCESS, device, pInfo, pAllocator, pCollection); |
| 718 | |
| 719 | return res; |
| 720 | } |
| 721 | |
| 722 | VKAPI_ATTR |
| 723 | void DestroyBufferCollectionFUCHSIAX(VkDevice device, |
| 724 | VkBufferCollectionFUCHSIAX collection, |
| 725 | const VkAllocationCallbacks* pAllocator) { |
| 726 | AEMU_SCOPED_TRACE("goldfish_vulkan::DestroyBufferCollectionFUCHSIAX"); |
| 727 | |
| 728 | VK_HOST_CONNECTION() |
| 729 | |
| 730 | if (!hostSupportsVulkan) { |
| 731 | vkstubhal::DestroyBufferCollectionFUCHSIAX(device, collection, |
| 732 | pAllocator); |
| 733 | return; |
| 734 | } |
| 735 | |
| 736 | goldfish_vk::ResourceTracker::get()->on_vkDestroyBufferCollectionFUCHSIAX( |
| 737 | vkEnc, VK_SUCCESS, device, collection, pAllocator); |
| 738 | } |
| 739 | |
| 740 | VKAPI_ATTR |
| 741 | VkResult SetBufferCollectionConstraintsFUCHSIAX( |
| 742 | VkDevice device, |
| 743 | VkBufferCollectionFUCHSIAX collection, |
| 744 | const VkImageCreateInfo* pImageInfo) { |
| 745 | AEMU_SCOPED_TRACE( |
| 746 | "goldfish_vulkan::SetBufferCollectionConstraintsFUCHSIAX"); |
| 747 | |
| 748 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 749 | |
| 750 | if (!hostSupportsVulkan) { |
| 751 | return vkstubhal::SetBufferCollectionConstraintsFUCHSIAX( |
| 752 | device, collection, pImageInfo); |
| 753 | } |
| 754 | |
| 755 | VkResult res = goldfish_vk::ResourceTracker::get() |
| 756 | ->on_vkSetBufferCollectionConstraintsFUCHSIAX( |
| 757 | vkEnc, VK_SUCCESS, device, collection, pImageInfo); |
| 758 | |
| 759 | return res; |
| 760 | } |
| 761 | |
| 762 | VKAPI_ATTR |
| 763 | VkResult SetBufferCollectionBufferConstraintsFUCHSIAX( |
| 764 | VkDevice device, |
| 765 | VkBufferCollectionFUCHSIAX collection, |
| 766 | const VkBufferConstraintsInfoFUCHSIAX* pBufferConstraintsInfo) { |
| 767 | AEMU_SCOPED_TRACE( |
| 768 | "goldfish_vulkan::SetBufferCollectionBufferConstraintsFUCHSIAX"); |
| 769 | |
| 770 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 771 | |
| 772 | if (!hostSupportsVulkan) { |
| 773 | return vkstubhal::SetBufferCollectionBufferConstraintsFUCHSIAX( |
| 774 | device, collection, pBufferConstraintsInfo); |
| 775 | } |
| 776 | |
| 777 | VkResult res = |
| 778 | goldfish_vk::ResourceTracker::get() |
| 779 | ->on_vkSetBufferCollectionBufferConstraintsFUCHSIAX( |
| 780 | vkEnc, VK_SUCCESS, device, collection, pBufferConstraintsInfo); |
| 781 | |
| 782 | return res; |
| 783 | } |
| 784 | |
| 785 | VKAPI_ATTR |
| 786 | VkResult SetBufferCollectionImageConstraintsFUCHSIAX( |
| 787 | VkDevice device, |
| 788 | VkBufferCollectionFUCHSIAX collection, |
| 789 | const VkImageConstraintsInfoFUCHSIAX* pImageConstraintsInfo) { |
| 790 | AEMU_SCOPED_TRACE( |
| 791 | "goldfish_vulkan::SetBufferCollectionBufferConstraintsFUCHSIAX"); |
| 792 | |
| 793 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 794 | |
| 795 | if (!hostSupportsVulkan) { |
| 796 | return vkstubhal::SetBufferCollectionImageConstraintsFUCHSIAX( |
| 797 | device, collection, pImageConstraintsInfo); |
| 798 | } |
| 799 | |
| 800 | VkResult res = |
| 801 | goldfish_vk::ResourceTracker::get() |
| 802 | ->on_vkSetBufferCollectionImageConstraintsFUCHSIAX( |
| 803 | vkEnc, VK_SUCCESS, device, collection, pImageConstraintsInfo); |
| 804 | |
| 805 | return res; |
| 806 | } |
| 807 | |
| 808 | VKAPI_ATTR |
| 809 | VkResult GetBufferCollectionPropertiesFUCHSIAX( |
| 810 | VkDevice device, |
| 811 | VkBufferCollectionFUCHSIAX collection, |
| 812 | VkBufferCollectionPropertiesFUCHSIAX* pProperties) { |
| 813 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetBufferCollectionPropertiesFUCHSIAX"); |
| 814 | |
| 815 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 816 | |
| 817 | if (!hostSupportsVulkan) { |
| 818 | return vkstubhal::GetBufferCollectionPropertiesFUCHSIAX( |
| 819 | device, collection, pProperties); |
| 820 | } |
| 821 | |
| 822 | VkResult res = goldfish_vk::ResourceTracker::get() |
| 823 | ->on_vkGetBufferCollectionPropertiesFUCHSIAX( |
| 824 | vkEnc, VK_SUCCESS, device, collection, pProperties); |
| 825 | |
| 826 | return res; |
| 827 | } |
| 828 | |
| 829 | VKAPI_ATTR |
| 830 | VkResult GetBufferCollectionProperties2FUCHSIAX( |
| 831 | VkDevice device, |
| 832 | VkBufferCollectionFUCHSIAX collection, |
| 833 | VkBufferCollectionProperties2FUCHSIAX* pProperties) { |
| 834 | AEMU_SCOPED_TRACE( |
| 835 | "goldfish_vulkan::GetBufferCollectionProperties2FUCHSIAX"); |
| 836 | |
| 837 | VK_HOST_CONNECTION(VK_ERROR_DEVICE_LOST) |
| 838 | |
| 839 | if (!hostSupportsVulkan) { |
| 840 | return vkstubhal::GetBufferCollectionProperties2FUCHSIAX( |
| 841 | device, collection, pProperties); |
| 842 | } |
| 843 | |
| 844 | VkResult res = goldfish_vk::ResourceTracker::get() |
| 845 | ->on_vkGetBufferCollectionProperties2FUCHSIAX( |
| 846 | vkEnc, VK_SUCCESS, device, collection, pProperties); |
| 847 | |
| 848 | return res; |
| 849 | } |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 850 | #endif |
| 851 | |
Lingfeng Yang | 33b91be | 2021-01-22 17:50:18 -0800 | [diff] [blame] | 852 | uint64_t currGuestTimeNs() { |
| 853 | struct timespec ts; |
| 854 | #ifdef __APPLE__ |
| 855 | clock_gettime(CLOCK_REALTIME, &ts); |
| 856 | #else |
| 857 | clock_gettime(CLOCK_BOOTTIME, &ts); |
| 858 | #endif |
| 859 | uint64_t res = (uint64_t)(ts.tv_sec * 1000000000ULL + ts.tv_nsec); |
| 860 | return res; |
| 861 | } |
| 862 | |
| 863 | struct FrameTracingState { |
| 864 | uint32_t frameNumber = 0; |
| 865 | bool tracingEnabled = false; |
| 866 | void onSwapBuffersSuccessful(ExtendedRCEncoderContext* rcEnc) { |
| 867 | #ifdef GFXSTREAM |
| 868 | bool current = android::base::isTracingEnabled(); |
| 869 | // edge trigger |
| 870 | if (current && !tracingEnabled) { |
| 871 | if (rcEnc->hasHostSideTracing()) { |
| 872 | rcEnc->rcSetTracingForPuid(rcEnc, getPuid(), 1, currGuestTimeNs()); |
| 873 | } |
| 874 | } |
| 875 | if (!current && tracingEnabled) { |
| 876 | if (rcEnc->hasHostSideTracing()) { |
| 877 | rcEnc->rcSetTracingForPuid(rcEnc, getPuid(), 0, currGuestTimeNs()); |
| 878 | } |
| 879 | } |
| 880 | tracingEnabled = current; |
| 881 | #endif |
| 882 | ++frameNumber; |
| 883 | } |
| 884 | }; |
| 885 | |
| 886 | static FrameTracingState sFrameTracingState; |
| 887 | |
| 888 | static PFN_vkVoidFunction sQueueSignalReleaseImageAndroidImpl = 0; |
| 889 | |
| 890 | static VkResult |
| 891 | QueueSignalReleaseImageANDROID( |
| 892 | VkQueue queue, |
| 893 | uint32_t waitSemaphoreCount, |
| 894 | const VkSemaphore* pWaitSemaphores, |
| 895 | VkImage image, |
| 896 | int* pNativeFenceFd) |
| 897 | { |
| 898 | sFrameTracingState.onSwapBuffersSuccessful(HostConnection::get()->rcEncoder()); |
| 899 | ((PFN_vkQueueSignalReleaseImageANDROID)sQueueSignalReleaseImageAndroidImpl)(queue, waitSemaphoreCount, pWaitSemaphores, image, pNativeFenceFd); |
| 900 | return VK_SUCCESS; |
| 901 | } |
| 902 | |
Lingfeng Yang | f0654ff | 2019-02-02 12:21:24 -0800 | [diff] [blame] | 903 | static PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* name) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 904 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetDeviceProcAddr"); |
| 905 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 906 | VK_HOST_CONNECTION(nullptr) |
| 907 | |
| 908 | if (!hostSupportsVulkan) { |
| 909 | return nullptr; |
| 910 | } |
| 911 | |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 912 | #ifdef VK_USE_PLATFORM_FUCHSIA |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 913 | if (!strcmp(name, "vkGetMemoryZirconHandleFUCHSIA")) { |
| 914 | return (PFN_vkVoidFunction)GetMemoryZirconHandleFUCHSIA; |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 915 | } |
David Reveman | 488704f | 2019-03-27 01:29:08 -0400 | [diff] [blame] | 916 | if (!strcmp(name, "vkGetMemoryZirconHandlePropertiesFUCHSIA")) { |
| 917 | return (PFN_vkVoidFunction)GetMemoryZirconHandlePropertiesFUCHSIA; |
| 918 | } |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 919 | if (!strcmp(name, "vkGetSemaphoreZirconHandleFUCHSIA")) { |
| 920 | return (PFN_vkVoidFunction)GetSemaphoreZirconHandleFUCHSIA; |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 921 | } |
David Reveman | ba51ee2 | 2019-03-26 11:22:21 -0400 | [diff] [blame] | 922 | if (!strcmp(name, "vkImportSemaphoreZirconHandleFUCHSIA")) { |
| 923 | return (PFN_vkVoidFunction)ImportSemaphoreZirconHandleFUCHSIA; |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 924 | } |
Yilong Li | e12328f | 2022-01-06 03:32:13 -0800 | [diff] [blame] | 925 | if (!strcmp(name, "vkCreateBufferCollectionFUCHSIA")) { |
| 926 | return (PFN_vkVoidFunction)CreateBufferCollectionFUCHSIA; |
| 927 | } |
| 928 | if (!strcmp(name, "vkDestroyBufferCollectionFUCHSIA")) { |
| 929 | return (PFN_vkVoidFunction)DestroyBufferCollectionFUCHSIA; |
| 930 | } |
| 931 | if (!strcmp(name, "vkSetBufferCollectionImageConstraintsFUCHSIA")) { |
| 932 | return (PFN_vkVoidFunction)SetBufferCollectionImageConstraintsFUCHSIA; |
| 933 | } |
| 934 | if (!strcmp(name, "vkSetBufferCollectionBufferConstraintsFUCHSIA")) { |
| 935 | return (PFN_vkVoidFunction)SetBufferCollectionBufferConstraintsFUCHSIA; |
| 936 | } |
| 937 | if (!strcmp(name, "vkGetBufferCollectionPropertiesFUCHSIA")) { |
| 938 | return (PFN_vkVoidFunction)GetBufferCollectionPropertiesFUCHSIA; |
| 939 | } |
Yilong Li | 818d1a8 | 2021-08-20 17:24:36 -0700 | [diff] [blame] | 940 | if (!strcmp(name, "vkCreateBufferCollectionFUCHSIAX")) { |
| 941 | return (PFN_vkVoidFunction)CreateBufferCollectionFUCHSIAX; |
| 942 | } |
| 943 | if (!strcmp(name, "vkDestroyBufferCollectionFUCHSIAX")) { |
| 944 | return (PFN_vkVoidFunction)DestroyBufferCollectionFUCHSIAX; |
| 945 | } |
| 946 | if (!strcmp(name, "vkSetBufferCollectionConstraintsFUCHSIAX")) { |
| 947 | return (PFN_vkVoidFunction)SetBufferCollectionConstraintsFUCHSIAX; |
| 948 | } |
| 949 | if (!strcmp(name, "vkSetBufferCollectionImageConstraintsFUCHSIAX")) { |
| 950 | return (PFN_vkVoidFunction)SetBufferCollectionImageConstraintsFUCHSIAX; |
| 951 | } |
| 952 | if (!strcmp(name, "vkSetBufferCollectionBufferConstraintsFUCHSIAX")) { |
| 953 | return (PFN_vkVoidFunction)SetBufferCollectionBufferConstraintsFUCHSIAX; |
| 954 | } |
| 955 | if (!strcmp(name, "vkGetBufferCollectionPropertiesFUCHSIAX")) { |
| 956 | return (PFN_vkVoidFunction)GetBufferCollectionPropertiesFUCHSIAX; |
| 957 | } |
| 958 | if (!strcmp(name, "vkGetBufferCollectionProperties2FUCHSIAX")) { |
| 959 | return (PFN_vkVoidFunction)GetBufferCollectionProperties2FUCHSIAX; |
| 960 | } |
David Reveman | 5b7c584 | 2019-02-20 01:06:48 -0500 | [diff] [blame] | 961 | #endif |
Lingfeng Yang | 33b91be | 2021-01-22 17:50:18 -0800 | [diff] [blame] | 962 | if (!strcmp(name, "vkQueueSignalReleaseImageANDROID")) { |
| 963 | if (!sQueueSignalReleaseImageAndroidImpl) { |
| 964 | sQueueSignalReleaseImageAndroidImpl = |
| 965 | (PFN_vkVoidFunction)( |
| 966 | goldfish_vk::goldfish_vulkan_get_device_proc_address(device, "vkQueueSignalReleaseImageANDROID")); |
| 967 | } |
| 968 | return (PFN_vkVoidFunction)QueueSignalReleaseImageANDROID; |
| 969 | } |
Lingfeng Yang | 9d02e10 | 2018-11-10 01:51:46 -0800 | [diff] [blame] | 970 | if (!strcmp(name, "vkGetDeviceProcAddr")) { |
| 971 | return (PFN_vkVoidFunction)(GetDeviceProcAddr); |
| 972 | } |
Lingfeng Yang | f0654ff | 2019-02-02 12:21:24 -0800 | [diff] [blame] | 973 | return (PFN_vkVoidFunction)(goldfish_vk::goldfish_vulkan_get_device_proc_address(device, name)); |
Lingfeng Yang | e30d338 | 2018-11-09 08:24:37 -0800 | [diff] [blame] | 974 | } |
| 975 | |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 976 | VKAPI_ATTR |
| 977 | PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 978 | AEMU_SCOPED_TRACE("goldfish_vulkan::GetInstanceProcAddr"); |
| 979 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 980 | VK_HOST_CONNECTION(nullptr) |
| 981 | |
| 982 | if (!hostSupportsVulkan) { |
| 983 | return vkstubhal::GetInstanceProcAddr(instance, name); |
| 984 | } |
| 985 | |
Lingfeng Yang | 0b81df2 | 2018-11-05 21:40:30 -0800 | [diff] [blame] | 986 | if (!strcmp(name, "vkEnumerateInstanceExtensionProperties")) { |
| 987 | return (PFN_vkVoidFunction)EnumerateInstanceExtensionProperties; |
| 988 | } |
| 989 | if (!strcmp(name, "vkCreateInstance")) { |
| 990 | return (PFN_vkVoidFunction)CreateInstance; |
| 991 | } |
Lingfeng Yang | e30d338 | 2018-11-09 08:24:37 -0800 | [diff] [blame] | 992 | if (!strcmp(name, "vkGetDeviceProcAddr")) { |
| 993 | return (PFN_vkVoidFunction)(GetDeviceProcAddr); |
| 994 | } |
Lingfeng Yang | 33b91be | 2021-01-22 17:50:18 -0800 | [diff] [blame] | 995 | if (!strcmp(name, "vkQueueSignalReleaseImageANDROID")) { |
| 996 | if (!sQueueSignalReleaseImageAndroidImpl) { |
| 997 | sQueueSignalReleaseImageAndroidImpl = |
| 998 | (PFN_vkVoidFunction)( |
| 999 | goldfish_vk::goldfish_vulkan_get_instance_proc_address(instance, "vkQueueSignalReleaseImageANDROID")); |
| 1000 | } |
| 1001 | return (PFN_vkVoidFunction)QueueSignalReleaseImageANDROID; |
| 1002 | } |
Lingfeng Yang | f0654ff | 2019-02-02 12:21:24 -0800 | [diff] [blame] | 1003 | return (PFN_vkVoidFunction)(goldfish_vk::goldfish_vulkan_get_instance_proc_address(instance, name)); |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 1004 | } |
| 1005 | |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1006 | #ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 1007 | |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 1008 | hwvulkan_device_t goldfish_vulkan_device = { |
| 1009 | .common = { |
| 1010 | .tag = HARDWARE_DEVICE_TAG, |
| 1011 | .version = HWVULKAN_DEVICE_API_VERSION_0_1, |
| 1012 | .module = &HAL_MODULE_INFO_SYM.common, |
| 1013 | .close = CloseDevice, |
| 1014 | }, |
| 1015 | .EnumerateInstanceExtensionProperties = EnumerateInstanceExtensionProperties, |
| 1016 | .CreateInstance = CreateInstance, |
| 1017 | .GetInstanceProcAddr = GetInstanceProcAddr, |
| 1018 | }; |
| 1019 | |
| 1020 | int OpenDevice(const hw_module_t* /*module*/, |
| 1021 | const char* id, |
| 1022 | hw_device_t** device) { |
Lingfeng Yang | 42ac179 | 2019-02-22 20:13:44 -0800 | [diff] [blame] | 1023 | AEMU_SCOPED_TRACE("goldfish_vulkan::OpenDevice"); |
| 1024 | |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 1025 | if (strcmp(id, HWVULKAN_DEVICE_0) == 0) { |
| 1026 | *device = &goldfish_vulkan_device.common; |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1027 | goldfish_vk::ResourceTracker::get(); |
| 1028 | return 0; |
| 1029 | } |
| 1030 | return -ENOENT; |
| 1031 | } |
| 1032 | |
Gurchetan Singh | 8fb0642 | 2022-01-13 13:30:24 -0800 | [diff] [blame] | 1033 | #elif VK_USE_PLATFORM_FUCHSIA |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1034 | |
| 1035 | class VulkanDevice { |
| 1036 | public: |
Craig Stout | bd797ab | 2019-11-13 18:07:58 -0800 | [diff] [blame] | 1037 | VulkanDevice() : mHostSupportsGoldfish(IsAccessible(QEMU_PIPE_PATH)) { |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1038 | InitLogger(); |
Yilong Li | 5a3e369 | 2020-12-01 10:23:29 -0800 | [diff] [blame] | 1039 | InitTraceProvider(); |
David Reveman | df8d964 | 2019-04-24 12:13:36 -0400 | [diff] [blame] | 1040 | goldfish_vk::ResourceTracker::get(); |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 1041 | } |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1042 | |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1043 | static void InitLogger(); |
| 1044 | |
Craig Stout | bd797ab | 2019-11-13 18:07:58 -0800 | [diff] [blame] | 1045 | static bool IsAccessible(const char* name) { |
| 1046 | zx_handle_t handle = GetConnectToServiceFunction()(name); |
| 1047 | if (handle == ZX_HANDLE_INVALID) |
| 1048 | return false; |
| 1049 | |
| 1050 | zxio_storage_t io_storage; |
James Robinson | 92cde42 | 2021-06-21 20:41:56 +0000 | [diff] [blame] | 1051 | zx_status_t status = zxio_create(handle, &io_storage); |
Craig Stout | bd797ab | 2019-11-13 18:07:58 -0800 | [diff] [blame] | 1052 | if (status != ZX_OK) |
| 1053 | return false; |
| 1054 | |
James Robinson | 92cde42 | 2021-06-21 20:41:56 +0000 | [diff] [blame] | 1055 | status = zxio_close(&io_storage.io); |
Craig Stout | bd797ab | 2019-11-13 18:07:58 -0800 | [diff] [blame] | 1056 | if (status != ZX_OK) |
| 1057 | return false; |
| 1058 | |
| 1059 | return true; |
| 1060 | } |
| 1061 | |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1062 | static VulkanDevice& GetInstance() { |
| 1063 | static VulkanDevice g_instance; |
| 1064 | return g_instance; |
| 1065 | } |
| 1066 | |
| 1067 | PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name) { |
David Reveman | fc7d2fa | 2019-05-15 22:03:05 -0400 | [diff] [blame] | 1068 | if (!mHostSupportsGoldfish) { |
| 1069 | return vkstubhal::GetInstanceProcAddr(instance, name); |
| 1070 | } |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1071 | return ::GetInstanceProcAddr(instance, name); |
| 1072 | } |
David Reveman | fc7d2fa | 2019-05-15 22:03:05 -0400 | [diff] [blame] | 1073 | |
| 1074 | private: |
Yilong Li | 5a3e369 | 2020-12-01 10:23:29 -0800 | [diff] [blame] | 1075 | void InitTraceProvider(); |
| 1076 | |
| 1077 | TraceProviderFuchsia mTraceProvider; |
David Reveman | fc7d2fa | 2019-05-15 22:03:05 -0400 | [diff] [blame] | 1078 | const bool mHostSupportsGoldfish; |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1079 | }; |
| 1080 | |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1081 | void VulkanDevice::InitLogger() { |
Tamir Duberstein | 7f3c6b0 | 2022-04-27 13:57:28 -0400 | [diff] [blame] | 1082 | auto log_socket = ([] () -> std::optional<zx::socket> { |
Ian McKellar | da00efc | 2021-03-01 20:05:25 +0000 | [diff] [blame] | 1083 | fidl::ClientEnd<fuchsia_logger::LogSink> channel{zx::channel{ |
Yifei Teng | fadb9d9 | 2021-02-11 15:01:55 -0800 | [diff] [blame] | 1084 | GetConnectToServiceFunction()("/svc/fuchsia.logger.LogSink")}}; |
| 1085 | if (!channel.is_valid()) |
| 1086 | return std::nullopt; |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1087 | |
Yifei Teng | fadb9d9 | 2021-02-11 15:01:55 -0800 | [diff] [blame] | 1088 | zx::socket local_socket, remote_socket; |
| 1089 | zx_status_t status = zx::socket::create(ZX_SOCKET_DATAGRAM, &local_socket, &remote_socket); |
| 1090 | if (status != ZX_OK) |
| 1091 | return std::nullopt; |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1092 | |
Yifei Teng | 7cfaef2 | 2021-09-30 18:21:15 -0700 | [diff] [blame] | 1093 | auto result = fidl::WireCall(channel)->Connect(std::move(remote_socket)); |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1094 | |
Yifei Teng | fadb9d9 | 2021-02-11 15:01:55 -0800 | [diff] [blame] | 1095 | if (!result.ok()) |
| 1096 | return std::nullopt; |
| 1097 | |
| 1098 | return local_socket; |
| 1099 | })(); |
Tamir Duberstein | 7f3c6b0 | 2022-04-27 13:57:28 -0400 | [diff] [blame] | 1100 | if (!log_socket) |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1101 | return; |
| 1102 | |
Tamir Duberstein | 7f3c6b0 | 2022-04-27 13:57:28 -0400 | [diff] [blame] | 1103 | fx_logger_config_t config = { |
| 1104 | .min_severity = FX_LOG_INFO, |
| 1105 | .console_fd = -1, |
| 1106 | .log_sink_socket = log_socket->release(), |
| 1107 | .tags = nullptr, |
| 1108 | .num_tags = 0, |
| 1109 | }; |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1110 | |
David Reveman | 91991a2 | 2020-04-10 09:27:54 -0400 | [diff] [blame] | 1111 | fx_log_reconfigure(&config); |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1112 | } |
| 1113 | |
Yilong Li | 5a3e369 | 2020-12-01 10:23:29 -0800 | [diff] [blame] | 1114 | void VulkanDevice::InitTraceProvider() { |
| 1115 | if (!mTraceProvider.Initialize()) { |
| 1116 | ALOGE("Trace provider failed to initialize"); |
| 1117 | } |
| 1118 | } |
| 1119 | |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1120 | extern "C" __attribute__((visibility("default"))) PFN_vkVoidFunction |
| 1121 | vk_icdGetInstanceProcAddr(VkInstance instance, const char* name) { |
| 1122 | return VulkanDevice::GetInstance().GetInstanceProcAddr(instance, name); |
Lingfeng Yang | a89af50 | 2018-10-18 13:46:20 -0700 | [diff] [blame] | 1123 | } |
| 1124 | |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1125 | extern "C" __attribute__((visibility("default"))) VkResult |
| 1126 | vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) { |
| 1127 | *pSupportedVersion = std::min(*pSupportedVersion, 3u); |
| 1128 | return VK_SUCCESS; |
| 1129 | } |
| 1130 | |
Craig Stout | e6b9b41 | 2020-09-30 17:10:14 -0400 | [diff] [blame] | 1131 | typedef VkResult(VKAPI_PTR *PFN_vkOpenInNamespaceAddr)(const char *pName, uint32_t handle); |
John Bauman | 8153a44 | 2019-10-16 15:41:17 -0700 | [diff] [blame] | 1132 | |
| 1133 | namespace { |
| 1134 | |
Craig Stout | e6b9b41 | 2020-09-30 17:10:14 -0400 | [diff] [blame] | 1135 | PFN_vkOpenInNamespaceAddr g_vulkan_connector; |
John Bauman | 8153a44 | 2019-10-16 15:41:17 -0700 | [diff] [blame] | 1136 | |
| 1137 | zx_handle_t LocalConnectToServiceFunction(const char* pName) { |
| 1138 | zx::channel remote_endpoint, local_endpoint; |
| 1139 | zx_status_t status; |
| 1140 | if ((status = zx::channel::create(0, &remote_endpoint, &local_endpoint)) != ZX_OK) { |
| 1141 | ALOGE("zx::channel::create failed: %d", status); |
| 1142 | return ZX_HANDLE_INVALID; |
| 1143 | } |
| 1144 | if ((status = g_vulkan_connector(pName, remote_endpoint.release())) != ZX_OK) { |
| 1145 | ALOGE("vulkan_connector failed: %d", status); |
| 1146 | return ZX_HANDLE_INVALID; |
| 1147 | } |
| 1148 | return local_endpoint.release(); |
| 1149 | } |
Craig Stout | 3d2098f | 2019-11-25 15:36:43 -0800 | [diff] [blame] | 1150 | |
John Bauman | 8153a44 | 2019-10-16 15:41:17 -0700 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | extern "C" __attribute__((visibility("default"))) void |
Craig Stout | e6b9b41 | 2020-09-30 17:10:14 -0400 | [diff] [blame] | 1154 | vk_icdInitializeOpenInNamespaceCallback(PFN_vkOpenInNamespaceAddr callback) { |
John Bauman | 8153a44 | 2019-10-16 15:41:17 -0700 | [diff] [blame] | 1155 | g_vulkan_connector = callback; |
| 1156 | SetConnectToServiceFunction(&LocalConnectToServiceFunction); |
| 1157 | } |
| 1158 | |
Gurchetan Singh | 8fb0642 | 2022-01-13 13:30:24 -0800 | [diff] [blame] | 1159 | #else |
| 1160 | class VulkanDevice { |
| 1161 | public: |
| 1162 | VulkanDevice() { |
| 1163 | goldfish_vk::ResourceTracker::get(); |
| 1164 | } |
| 1165 | |
| 1166 | static VulkanDevice& GetInstance() { |
| 1167 | static VulkanDevice g_instance; |
| 1168 | return g_instance; |
| 1169 | } |
| 1170 | |
| 1171 | PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name) { |
| 1172 | return ::GetInstanceProcAddr(instance, name); |
| 1173 | } |
| 1174 | }; |
| 1175 | |
| 1176 | extern "C" __attribute__((visibility("default"))) PFN_vkVoidFunction |
| 1177 | vk_icdGetInstanceProcAddr(VkInstance instance, const char* name) { |
| 1178 | return VulkanDevice::GetInstance().GetInstanceProcAddr(instance, name); |
| 1179 | } |
| 1180 | |
| 1181 | extern "C" __attribute__((visibility("default"))) VkResult |
| 1182 | vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t* pSupportedVersion) { |
| 1183 | *pSupportedVersion = std::min(*pSupportedVersion, 3u); |
| 1184 | return VK_SUCCESS; |
| 1185 | } |
| 1186 | |
David Reveman | 7beff56 | 2019-04-22 16:50:02 +0200 | [diff] [blame] | 1187 | #endif |
| 1188 | |
Lingfeng Yang | b8a38c7 | 2019-02-02 20:27:54 -0800 | [diff] [blame] | 1189 | } // namespace |