blob: b50635dc8a75de1285e0c7a761083faf14169a5c [file] [log] [blame]
Lingfeng Yang71b596b2018-11-07 18:03:25 -08001// Copyright (C) 2018 The Android Open Source Project
2// Copyright (C) 2018 Google Inc.
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.
Lingfeng Yang71b596b2018-11-07 18:03:25 -080015#pragma once
16
Lingfeng Yang42ac1792019-02-22 20:13:44 -080017#include "android/base/Tracing.h"
18
Lingfeng Yang71b596b2018-11-07 18:03:25 -080019#include <vulkan/vulkan.h>
20
Lingfeng Yang71b596b2018-11-07 18:03:25 -080021#include "VulkanHandleMapping.h"
Lingfeng Yang6ab1b0d2018-11-27 23:36:03 -080022#include "VulkanHandles.h"
Lingfeng Yang256f9252020-07-14 14:27:33 -070023#include <functional>
Lingfeng Yang71b596b2018-11-07 18:03:25 -080024#include <memory>
25
Lingfeng Yang2b1b8cf2019-02-08 09:53:36 -080026#include "goldfish_vk_transform_guest.h"
27
Lingfeng Yang31754632018-12-21 18:24:55 -080028struct EmulatorFeatureInfo;
29
Lingfeng Yang34b5cae2019-08-21 14:12:19 -070030class HostConnection;
31
Lingfeng Yang71b596b2018-11-07 18:03:25 -080032namespace goldfish_vk {
33
Lingfeng Yang39a276e2019-06-17 13:27:22 -070034class VkEncoder;
35
Lingfeng Yang97a06702018-12-24 17:02:43 -080036class ResourceTracker {
Lingfeng Yang71b596b2018-11-07 18:03:25 -080037public:
38 ResourceTracker();
Lingfeng Yangb1d90102018-11-29 16:10:36 -080039 virtual ~ResourceTracker();
Lingfeng Yang71b596b2018-11-07 18:03:25 -080040 static ResourceTracker* get();
Lingfeng Yang40329112021-01-22 18:01:43 -080041
Lingfeng Yang71b596b2018-11-07 18:03:25 -080042 VulkanHandleMapping* createMapping();
43 VulkanHandleMapping* unwrapMapping();
44 VulkanHandleMapping* destroyMapping();
Lingfeng Yang2285df12018-11-17 16:25:11 -080045 VulkanHandleMapping* defaultMapping();
Lingfeng Yang6ab1b0d2018-11-27 23:36:03 -080046
Lingfeng Yang34b5cae2019-08-21 14:12:19 -070047 using HostConnectionGetFunc = HostConnection* (*)();
Lingfeng Yangcd2d8fe2019-08-16 12:21:50 -070048 using VkEncoderGetFunc = VkEncoder* (*)(HostConnection*);
Lingfeng Yang256f9252020-07-14 14:27:33 -070049 using CleanupCallback = std::function<void()>;
Lingfeng Yang34b5cae2019-08-21 14:12:19 -070050
51 struct ThreadingCallbacks {
52 HostConnectionGetFunc hostConnectionGetFunc = 0;
Lingfeng Yangcd2d8fe2019-08-16 12:21:50 -070053 VkEncoderGetFunc vkEncoderGetFunc = 0;
Lingfeng Yang34b5cae2019-08-21 14:12:19 -070054 };
55
Lingfeng Yang40329112021-01-22 18:01:43 -080056 static uint32_t streamFeatureBits;
57 static ThreadingCallbacks threadingCallbacks;
58
Lingfeng Yang6ab1b0d2018-11-27 23:36:03 -080059#define HANDLE_REGISTER_DECL(type) \
60 void register_##type(type); \
61 void unregister_##type(type); \
62
63 GOLDFISH_VK_LIST_HANDLE_TYPES(HANDLE_REGISTER_DECL)
64
Lingfeng Yang154a33c2019-01-29 19:06:23 -080065 VkResult on_vkEnumerateInstanceExtensionProperties(
66 void* context,
67 VkResult input_result,
68 const char* pLayerName,
69 uint32_t* pPropertyCount,
70 VkExtensionProperties* pProperties);
71
Lingfeng Yangdef88ba2018-12-13 12:43:17 -080072 VkResult on_vkEnumerateDeviceExtensionProperties(
73 void* context,
74 VkResult input_result,
75 VkPhysicalDevice physicalDevice,
76 const char* pLayerName,
77 uint32_t* pPropertyCount,
Lingfeng Yang97a06702018-12-24 17:02:43 -080078 VkExtensionProperties* pProperties);
Lingfeng Yang154a33c2019-01-29 19:06:23 -080079
Lingfeng Yangb64ca452019-02-14 22:04:28 -080080 VkResult on_vkEnumeratePhysicalDevices(
81 void* context, VkResult input_result,
82 VkInstance instance, uint32_t* pPhysicalDeviceCount,
83 VkPhysicalDevice* pPhysicalDevices);
84
Yahan Zhou7b99a382022-04-13 15:25:46 -070085 void on_vkGetPhysicalDeviceFeatures2(
86 void* context,
87 VkPhysicalDevice physicalDevice,
88 VkPhysicalDeviceFeatures2* pFeatures);
89 void on_vkGetPhysicalDeviceFeatures2KHR(
90 void* context,
91 VkPhysicalDevice physicalDevice,
92 VkPhysicalDeviceFeatures2* pFeatures);
Yilong Lif3369082020-06-25 03:39:24 -070093 void on_vkGetPhysicalDeviceProperties(
94 void* context,
95 VkPhysicalDevice physicalDevice,
96 VkPhysicalDeviceProperties* pProperties);
97 void on_vkGetPhysicalDeviceProperties2(
98 void* context,
99 VkPhysicalDevice physicalDevice,
100 VkPhysicalDeviceProperties2* pProperties);
101 void on_vkGetPhysicalDeviceProperties2KHR(
102 void* context,
103 VkPhysicalDevice physicalDevice,
104 VkPhysicalDeviceProperties2* pProperties);
105
Lingfeng Yang97a06702018-12-24 17:02:43 -0800106 void on_vkGetPhysicalDeviceMemoryProperties(
107 void* context,
108 VkPhysicalDevice physicalDevice,
109 VkPhysicalDeviceMemoryProperties* pMemoryProperties);
Lingfeng Yang154a33c2019-01-29 19:06:23 -0800110 void on_vkGetPhysicalDeviceMemoryProperties2(
111 void* context,
112 VkPhysicalDevice physicalDevice,
113 VkPhysicalDeviceMemoryProperties2* pMemoryProperties);
114 void on_vkGetPhysicalDeviceMemoryProperties2KHR(
115 void* context,
116 VkPhysicalDevice physicalDevice,
117 VkPhysicalDeviceMemoryProperties2* pMemoryProperties);
Yilong Li366c3662021-04-25 03:38:14 -0700118 void on_vkGetDeviceQueue(void* context,
119 VkDevice device,
120 uint32_t queueFamilyIndex,
121 uint32_t queueIndex,
122 VkQueue* pQueue);
123 void on_vkGetDeviceQueue2(void* context,
124 VkDevice device,
125 const VkDeviceQueueInfo2* pQueueInfo,
126 VkQueue* pQueue);
Lingfeng Yangdef88ba2018-12-13 12:43:17 -0800127
Lingfeng Yangf0654ff2019-02-02 12:21:24 -0800128 VkResult on_vkCreateInstance(
129 void* context,
130 VkResult input_result,
131 const VkInstanceCreateInfo* createInfo,
132 const VkAllocationCallbacks* pAllocator,
133 VkInstance* pInstance);
Lingfeng Yang131d5a42018-11-30 12:00:33 -0800134 VkResult on_vkCreateDevice(
135 void* context,
136 VkResult input_result,
137 VkPhysicalDevice physicalDevice,
138 const VkDeviceCreateInfo* pCreateInfo,
139 const VkAllocationCallbacks* pAllocator,
Lingfeng Yang97a06702018-12-24 17:02:43 -0800140 VkDevice* pDevice);
Lingfeng Yang35e9c6a2018-12-25 17:13:36 -0800141 void on_vkDestroyDevice_pre(
142 void* context,
143 VkDevice device,
144 const VkAllocationCallbacks* pAllocator);
Lingfeng Yang131d5a42018-11-30 12:00:33 -0800145
146 VkResult on_vkAllocateMemory(
147 void* context,
148 VkResult input_result,
149 VkDevice device,
150 const VkMemoryAllocateInfo* pAllocateInfo,
151 const VkAllocationCallbacks* pAllocator,
Lingfeng Yang97a06702018-12-24 17:02:43 -0800152 VkDeviceMemory* pMemory);
Lingfeng Yange9979522018-12-25 14:44:52 -0800153 void on_vkFreeMemory(
154 void* context,
155 VkDevice device,
156 VkDeviceMemory memory,
157 const VkAllocationCallbacks* pAllocator);
Lingfeng Yang131d5a42018-11-30 12:00:33 -0800158
Lingfeng Yangdef88ba2018-12-13 12:43:17 -0800159 VkResult on_vkMapMemory(
160 void* context,
161 VkResult input_result,
162 VkDevice device,
163 VkDeviceMemory memory,
164 VkDeviceSize offset,
165 VkDeviceSize size,
166 VkMemoryMapFlags,
167 void** ppData);
168
169 void on_vkUnmapMemory(
170 void* context,
171 VkDevice device,
Lingfeng Yang97a06702018-12-24 17:02:43 -0800172 VkDeviceMemory memory);
Lingfeng Yangdef88ba2018-12-13 12:43:17 -0800173
Lingfeng Yang4af5f322019-02-14 08:10:28 -0800174 VkResult on_vkCreateImage(
175 void* context, VkResult input_result,
176 VkDevice device, const VkImageCreateInfo *pCreateInfo,
177 const VkAllocationCallbacks *pAllocator,
178 VkImage *pImage);
179 void on_vkDestroyImage(
180 void* context,
181 VkDevice device, VkImage image, const VkAllocationCallbacks *pAllocator);
182
183 void on_vkGetImageMemoryRequirements(
184 void *context, VkDevice device, VkImage image,
185 VkMemoryRequirements *pMemoryRequirements);
186 void on_vkGetImageMemoryRequirements2(
187 void *context, VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
188 VkMemoryRequirements2 *pMemoryRequirements);
189 void on_vkGetImageMemoryRequirements2KHR(
190 void *context, VkDevice device, const VkImageMemoryRequirementsInfo2 *pInfo,
191 VkMemoryRequirements2 *pMemoryRequirements);
192
193 VkResult on_vkBindImageMemory(
194 void* context, VkResult input_result,
195 VkDevice device, VkImage image, VkDeviceMemory memory,
196 VkDeviceSize memoryOffset);
197 VkResult on_vkBindImageMemory2(
198 void* context, VkResult input_result,
199 VkDevice device, uint32_t bindingCount, const VkBindImageMemoryInfo* pBindInfos);
200 VkResult on_vkBindImageMemory2KHR(
201 void* context, VkResult input_result,
202 VkDevice device, uint32_t bindingCount, const VkBindImageMemoryInfo* pBindInfos);
203
204 VkResult on_vkCreateBuffer(
205 void* context, VkResult input_result,
206 VkDevice device, const VkBufferCreateInfo *pCreateInfo,
207 const VkAllocationCallbacks *pAllocator,
208 VkBuffer *pBuffer);
209 void on_vkDestroyBuffer(
210 void* context,
211 VkDevice device, VkBuffer buffer, const VkAllocationCallbacks *pAllocator);
212
213 void on_vkGetBufferMemoryRequirements(
214 void* context, VkDevice device, VkBuffer buffer, VkMemoryRequirements *pMemoryRequirements);
215 void on_vkGetBufferMemoryRequirements2(
216 void* context, VkDevice device, const VkBufferMemoryRequirementsInfo2* pInfo,
217 VkMemoryRequirements2* pMemoryRequirements);
218 void on_vkGetBufferMemoryRequirements2KHR(
219 void* context, VkDevice device, const VkBufferMemoryRequirementsInfo2* pInfo,
220 VkMemoryRequirements2* pMemoryRequirements);
221
222 VkResult on_vkBindBufferMemory(
223 void* context, VkResult input_result,
224 VkDevice device, VkBuffer buffer, VkDeviceMemory memory, VkDeviceSize memoryOffset);
225 VkResult on_vkBindBufferMemory2(
226 void* context, VkResult input_result,
227 VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfo *pBindInfos);
228 VkResult on_vkBindBufferMemory2KHR(
229 void* context, VkResult input_result,
230 VkDevice device, uint32_t bindInfoCount, const VkBindBufferMemoryInfo *pBindInfos);
231
David Reveman5b7c5842019-02-20 01:06:48 -0500232 VkResult on_vkCreateSemaphore(
David Reveman32b110e2019-02-21 13:20:54 -0500233 void* context, VkResult,
234 VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo,
235 const VkAllocationCallbacks* pAllocator,
236 VkSemaphore* pSemaphore);
237 void on_vkDestroySemaphore(
238 void* context,
239 VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks *pAllocator);
Yahan Zhoua499e442019-02-26 16:35:01 -0800240 VkResult on_vkGetSemaphoreFdKHR(
241 void* context, VkResult,
242 VkDevice device,
243 const VkSemaphoreGetFdInfoKHR* pGetFdInfo,
244 int* pFd);
245 VkResult on_vkImportSemaphoreFdKHR(
246 void* context, VkResult,
247 VkDevice device,
248 const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo);
David Reveman32b110e2019-02-21 13:20:54 -0500249
David Reveman24710222019-02-25 02:21:42 -0500250 VkResult on_vkQueueSubmit(
251 void* context, VkResult input_result,
252 VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence);
253
Lingfeng Yangcd2d8fe2019-08-16 12:21:50 -0700254 VkResult on_vkQueueWaitIdle(
255 void* context, VkResult input_result,
256 VkQueue queue);
257
Lingfeng Yangdef88ba2018-12-13 12:43:17 -0800258 void unwrap_VkNativeBufferANDROID(
259 const VkImageCreateInfo* pCreateInfo,
260 VkImageCreateInfo* local_pCreateInfo);
261 void unwrap_vkAcquireImageANDROID_nativeFenceFd(int fd, int* fd_out);
262
David Reveman5b7c5842019-02-20 01:06:48 -0500263#ifdef VK_USE_PLATFORM_FUCHSIA
David Revemanba51ee22019-03-26 11:22:21 -0400264 VkResult on_vkGetMemoryZirconHandleFUCHSIA(
Lingfeng Yang4f3f91f2019-02-28 11:37:21 -0800265 void* context, VkResult input_result,
David Reveman5b7c5842019-02-20 01:06:48 -0500266 VkDevice device,
David Revemanba51ee22019-03-26 11:22:21 -0400267 const VkMemoryGetZirconHandleInfoFUCHSIA* pInfo,
David Reveman5b7c5842019-02-20 01:06:48 -0500268 uint32_t* pHandle);
David Reveman488704f2019-03-27 01:29:08 -0400269 VkResult on_vkGetMemoryZirconHandlePropertiesFUCHSIA(
Lingfeng Yang4f3f91f2019-02-28 11:37:21 -0800270 void* context, VkResult input_result,
271 VkDevice device,
David Reveman488704f2019-03-27 01:29:08 -0400272 VkExternalMemoryHandleTypeFlagBits handleType,
Lingfeng Yang4f3f91f2019-02-28 11:37:21 -0800273 uint32_t handle,
David Reveman488704f2019-03-27 01:29:08 -0400274 VkMemoryZirconHandlePropertiesFUCHSIA* pProperties);
David Revemanba51ee22019-03-26 11:22:21 -0400275 VkResult on_vkGetSemaphoreZirconHandleFUCHSIA(
Lingfeng Yang4f3f91f2019-02-28 11:37:21 -0800276 void* context, VkResult input_result,
David Reveman5b7c5842019-02-20 01:06:48 -0500277 VkDevice device,
David Revemanba51ee22019-03-26 11:22:21 -0400278 const VkSemaphoreGetZirconHandleInfoFUCHSIA* pInfo,
David Reveman5b7c5842019-02-20 01:06:48 -0500279 uint32_t* pHandle);
David Revemanba51ee22019-03-26 11:22:21 -0400280 VkResult on_vkImportSemaphoreZirconHandleFUCHSIA(
Lingfeng Yang4f3f91f2019-02-28 11:37:21 -0800281 void* context, VkResult input_result,
David Reveman5b7c5842019-02-20 01:06:48 -0500282 VkDevice device,
David Revemanba51ee22019-03-26 11:22:21 -0400283 const VkImportSemaphoreZirconHandleInfoFUCHSIA* pInfo);
Yilong Lie12328f2022-01-06 03:32:13 -0800284 VkResult on_vkCreateBufferCollectionFUCHSIA(
285 void* context,
286 VkResult input_result,
287 VkDevice device,
288 const VkBufferCollectionCreateInfoFUCHSIA* pInfo,
289 const VkAllocationCallbacks* pAllocator,
290 VkBufferCollectionFUCHSIA* pCollection);
291 void on_vkDestroyBufferCollectionFUCHSIA(
292 void* context,
293 VkResult input_result,
294 VkDevice device,
295 VkBufferCollectionFUCHSIA collection,
296 const VkAllocationCallbacks* pAllocator);
297 VkResult on_vkSetBufferCollectionBufferConstraintsFUCHSIA(
298 void* context,
299 VkResult input_result,
300 VkDevice device,
301 VkBufferCollectionFUCHSIA collection,
302 const VkBufferConstraintsInfoFUCHSIA* pBufferConstraintsInfo);
303 VkResult on_vkSetBufferCollectionImageConstraintsFUCHSIA(
304 void* context,
305 VkResult input_result,
306 VkDevice device,
307 VkBufferCollectionFUCHSIA collection,
308 const VkImageConstraintsInfoFUCHSIA* pImageConstraintsInfo);
309 VkResult on_vkGetBufferCollectionPropertiesFUCHSIA(
310 void* context,
311 VkResult input_result,
312 VkDevice device,
313 VkBufferCollectionFUCHSIA collection,
314 VkBufferCollectionPropertiesFUCHSIA* pProperties);
Gurchetan Singh4ea5e042022-10-25 16:08:28 +0000315 VkResult on_vkCreateBufferCollectionFUCHSIAX(
316 void* context,
317 VkResult input_result,
318 VkDevice device,
319 const VkBufferCollectionCreateInfoFUCHSIAX* pInfo,
320 const VkAllocationCallbacks* pAllocator,
321 VkBufferCollectionFUCHSIAX* pCollection);
322 void on_vkDestroyBufferCollectionFUCHSIAX(
323 void* context,
324 VkResult input_result,
325 VkDevice device,
326 VkBufferCollectionFUCHSIAX collection,
327 const VkAllocationCallbacks* pAllocator);
328 VkResult on_vkSetBufferCollectionConstraintsFUCHSIAX(
329 void* context,
330 VkResult input_result,
331 VkDevice device,
332 VkBufferCollectionFUCHSIAX collection,
333 const VkImageCreateInfo* pImageInfo);
334 VkResult on_vkSetBufferCollectionBufferConstraintsFUCHSIAX(
335 void* context,
336 VkResult input_result,
337 VkDevice device,
338 VkBufferCollectionFUCHSIAX collection,
339 const VkBufferConstraintsInfoFUCHSIAX* pBufferConstraintsInfo);
340 VkResult on_vkSetBufferCollectionImageConstraintsFUCHSIAX(
341 void* context,
342 VkResult input_result,
343 VkDevice device,
344 VkBufferCollectionFUCHSIAX collection,
345 const VkImageConstraintsInfoFUCHSIAX* pImageConstraintsInfo);
346 VkResult on_vkGetBufferCollectionPropertiesFUCHSIAX(
347 void* context,
348 VkResult input_result,
349 VkDevice device,
350 VkBufferCollectionFUCHSIAX collection,
351 VkBufferCollectionPropertiesFUCHSIAX* pProperties);
352 VkResult on_vkGetBufferCollectionProperties2FUCHSIAX(
353 void* context,
354 VkResult input_result,
355 VkDevice device,
356 VkBufferCollectionFUCHSIAX collection,
357 VkBufferCollectionProperties2FUCHSIAX* pProperties);
David Reveman5b7c5842019-02-20 01:06:48 -0500358#endif
359
Lingfeng Yang4f3f91f2019-02-28 11:37:21 -0800360 VkResult on_vkGetAndroidHardwareBufferPropertiesANDROID(
361 void* context, VkResult input_result,
362 VkDevice device,
363 const AHardwareBuffer* buffer,
364 VkAndroidHardwareBufferPropertiesANDROID* pProperties);
365 VkResult on_vkGetMemoryAndroidHardwareBufferANDROID(
366 void* context, VkResult input_result,
367 VkDevice device,
368 const VkMemoryGetAndroidHardwareBufferInfoANDROID *pInfo,
369 struct AHardwareBuffer** pBuffer);
Lingfeng Yang4f3f91f2019-02-28 11:37:21 -0800370
Lingfeng Yang5c701122019-03-05 08:34:46 -0800371 VkResult on_vkCreateSamplerYcbcrConversion(
372 void* context, VkResult input_result,
373 VkDevice device,
374 const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
375 const VkAllocationCallbacks* pAllocator,
376 VkSamplerYcbcrConversion* pYcbcrConversion);
Roman Kiryanov004f48c2019-06-28 14:59:32 -0700377 void on_vkDestroySamplerYcbcrConversion(
378 void* context,
379 VkDevice device,
380 VkSamplerYcbcrConversion ycbcrConversion,
381 const VkAllocationCallbacks* pAllocator);
Lingfeng Yang5c701122019-03-05 08:34:46 -0800382 VkResult on_vkCreateSamplerYcbcrConversionKHR(
383 void* context, VkResult input_result,
384 VkDevice device,
385 const VkSamplerYcbcrConversionCreateInfo* pCreateInfo,
386 const VkAllocationCallbacks* pAllocator,
387 VkSamplerYcbcrConversion* pYcbcrConversion);
Roman Kiryanov004f48c2019-06-28 14:59:32 -0700388 void on_vkDestroySamplerYcbcrConversionKHR(
389 void* context,
390 VkDevice device,
391 VkSamplerYcbcrConversion ycbcrConversion,
392 const VkAllocationCallbacks* pAllocator);
393
394 VkResult on_vkCreateSampler(
395 void* context, VkResult input_result,
396 VkDevice device,
397 const VkSamplerCreateInfo* pCreateInfo,
398 const VkAllocationCallbacks* pAllocator,
399 VkSampler* pSampler);
Lingfeng Yang5c701122019-03-05 08:34:46 -0800400
Lingfeng Yangcd2d8fe2019-08-16 12:21:50 -0700401 void on_vkGetPhysicalDeviceExternalFenceProperties(
402 void* context,
403 VkPhysicalDevice physicalDevice,
404 const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo,
405 VkExternalFenceProperties* pExternalFenceProperties);
406
407 void on_vkGetPhysicalDeviceExternalFencePropertiesKHR(
408 void* context,
409 VkPhysicalDevice physicalDevice,
410 const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo,
411 VkExternalFenceProperties* pExternalFenceProperties);
412
413 VkResult on_vkCreateFence(
414 void* context,
415 VkResult input_result,
416 VkDevice device,
417 const VkFenceCreateInfo* pCreateInfo,
418 const VkAllocationCallbacks* pAllocator, VkFence* pFence);
419
420 void on_vkDestroyFence(
421 void* context,
422 VkDevice device,
423 VkFence fence,
424 const VkAllocationCallbacks* pAllocator);
425
426 VkResult on_vkResetFences(
427 void* context,
428 VkResult input_result,
429 VkDevice device,
430 uint32_t fenceCount,
431 const VkFence* pFences);
432
433 VkResult on_vkImportFenceFdKHR(
434 void* context,
435 VkResult input_result,
436 VkDevice device,
437 const VkImportFenceFdInfoKHR* pImportFenceFdInfo);
438
439 VkResult on_vkGetFenceFdKHR(
440 void* context,
441 VkResult input_result,
442 VkDevice device,
443 const VkFenceGetFdInfoKHR* pGetFdInfo,
444 int* pFd);
445
446 VkResult on_vkWaitForFences(
447 void* context,
448 VkResult input_result,
449 VkDevice device,
450 uint32_t fenceCount,
451 const VkFence* pFences,
452 VkBool32 waitAll,
453 uint64_t timeout);
454
Lingfeng Yange9e77d52020-03-25 14:01:58 -0700455 VkResult on_vkCreateDescriptorPool(
456 void* context,
457 VkResult input_result,
458 VkDevice device,
459 const VkDescriptorPoolCreateInfo* pCreateInfo,
460 const VkAllocationCallbacks* pAllocator,
461 VkDescriptorPool* pDescriptorPool);
462
463 void on_vkDestroyDescriptorPool(
464 void* context,
465 VkDevice device,
466 VkDescriptorPool descriptorPool,
467 const VkAllocationCallbacks* pAllocator);
468
469 VkResult on_vkResetDescriptorPool(
470 void* context,
471 VkResult input_result,
472 VkDevice device,
473 VkDescriptorPool descriptorPool,
474 VkDescriptorPoolResetFlags flags);
475
476 VkResult on_vkAllocateDescriptorSets(
477 void* context,
478 VkResult input_result,
479 VkDevice device,
480 const VkDescriptorSetAllocateInfo* pAllocateInfo,
481 VkDescriptorSet* pDescriptorSets);
482
483 VkResult on_vkFreeDescriptorSets(
484 void* context,
485 VkResult input_result,
486 VkDevice device,
487 VkDescriptorPool descriptorPool,
488 uint32_t descriptorSetCount,
489 const VkDescriptorSet* pDescriptorSets);
490
Lingfeng Yang03354c72020-03-26 13:00:51 -0700491 VkResult on_vkCreateDescriptorSetLayout(
492 void* context,
493 VkResult input_result,
494 VkDevice device,
495 const VkDescriptorSetLayoutCreateInfo* pCreateInfo,
496 const VkAllocationCallbacks* pAllocator,
497 VkDescriptorSetLayout* pSetLayout);
498
499 void on_vkUpdateDescriptorSets(
500 void* context,
501 VkDevice device,
502 uint32_t descriptorWriteCount,
503 const VkWriteDescriptorSet* pDescriptorWrites,
504 uint32_t descriptorCopyCount,
505 const VkCopyDescriptorSet* pDescriptorCopies);
506
Lingfeng Yang236abc92018-12-21 20:19:33 -0800507 VkResult on_vkMapMemoryIntoAddressSpaceGOOGLE_pre(
508 void* context,
509 VkResult input_result,
510 VkDevice device,
511 VkDeviceMemory memory,
512 uint64_t* pAddress);
513 VkResult on_vkMapMemoryIntoAddressSpaceGOOGLE(
514 void* context,
515 VkResult input_result,
516 VkDevice device,
517 VkDeviceMemory memory,
518 uint64_t* pAddress);
519
Lingfeng Yang05d5ea32019-03-23 00:12:39 -0700520 VkResult on_vkCreateDescriptorUpdateTemplate(
521 void* context, VkResult input_result,
522 VkDevice device,
523 const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo,
524 const VkAllocationCallbacks* pAllocator,
525 VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate);
526
527 VkResult on_vkCreateDescriptorUpdateTemplateKHR(
528 void* context, VkResult input_result,
529 VkDevice device,
530 const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo,
531 const VkAllocationCallbacks* pAllocator,
532 VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate);
533
534 void on_vkUpdateDescriptorSetWithTemplate(
535 void* context,
536 VkDevice device,
537 VkDescriptorSet descriptorSet,
538 VkDescriptorUpdateTemplate descriptorUpdateTemplate,
539 const void* pData);
540
Lingfeng Yange517d1e2019-03-25 18:02:49 -0700541 VkResult on_vkGetPhysicalDeviceImageFormatProperties2(
542 void* context, VkResult input_result,
543 VkPhysicalDevice physicalDevice,
544 const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo,
545 VkImageFormatProperties2* pImageFormatProperties);
546
547 VkResult on_vkGetPhysicalDeviceImageFormatProperties2KHR(
548 void* context, VkResult input_result,
549 VkPhysicalDevice physicalDevice,
550 const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo,
551 VkImageFormatProperties2* pImageFormatProperties);
552
Yilong Lid1c69192021-02-05 02:06:07 -0800553 void on_vkGetPhysicalDeviceExternalSemaphoreProperties(
554 void* context,
555 VkPhysicalDevice physicalDevice,
556 const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo,
557 VkExternalSemaphoreProperties* pExternalSemaphoreProperties);
558
559 void on_vkGetPhysicalDeviceExternalSemaphorePropertiesKHR(
560 void* context,
561 VkPhysicalDevice physicalDevice,
562 const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo,
563 VkExternalSemaphoreProperties* pExternalSemaphoreProperties);
564
Lingfeng Yang256f9252020-07-14 14:27:33 -0700565 void registerEncoderCleanupCallback(const VkEncoder* encoder, void* handle, CleanupCallback callback);
566 void unregisterEncoderCleanupCallback(const VkEncoder* encoder, void* handle);
567 void onEncoderDeleted(const VkEncoder* encoder);
568
Lingfeng Yang39a276e2019-06-17 13:27:22 -0700569 uint32_t syncEncodersForCommandBuffer(VkCommandBuffer commandBuffer, VkEncoder* current);
Lingfeng Yangf89f75d2020-07-09 17:42:33 -0700570 uint32_t syncEncodersForQueue(VkQueue queue, VkEncoder* current);
Lingfeng Yang39a276e2019-06-17 13:27:22 -0700571
Lingfeng Yangc53e7472019-03-27 08:50:55 -0700572 VkResult on_vkBeginCommandBuffer(
573 void* context, VkResult input_result,
574 VkCommandBuffer commandBuffer,
575 const VkCommandBufferBeginInfo* pBeginInfo);
576 VkResult on_vkEndCommandBuffer(
577 void* context, VkResult input_result,
578 VkCommandBuffer commandBuffer);
579 VkResult on_vkResetCommandBuffer(
580 void* context, VkResult input_result,
581 VkCommandBuffer commandBuffer,
582 VkCommandBufferResetFlags flags);
583
Roman Kiryanov6db11e52019-04-26 14:18:14 -0700584 VkResult on_vkCreateImageView(
585 void* context, VkResult input_result,
586 VkDevice device,
587 const VkImageViewCreateInfo* pCreateInfo,
588 const VkAllocationCallbacks* pAllocator,
589 VkImageView* pView);
590
Lingfeng Yang967f9af2021-01-22 17:56:24 -0800591 void on_vkCmdExecuteCommands(
592 void* context,
593 VkCommandBuffer commandBuffer,
594 uint32_t commandBufferCount,
595 const VkCommandBuffer* pCommandBuffers);
596
Lingfeng Yang55676e02021-02-08 08:39:45 -0800597 void on_vkCmdBindDescriptorSets(
598 void* context,
599 VkCommandBuffer commandBuffer,
600 VkPipelineBindPoint pipelineBindPoint,
601 VkPipelineLayout layout,
602 uint32_t firstSet,
603 uint32_t descriptorSetCount,
604 const VkDescriptorSet* pDescriptorSets,
605 uint32_t dynamicOffsetCount,
606 const uint32_t* pDynamicOffsets);
607
608 void on_vkDestroyDescriptorSetLayout(
609 void* context,
610 VkDevice device,
611 VkDescriptorSetLayout descriptorSetLayout,
612 const VkAllocationCallbacks* pAllocator);
613
Lingfeng Yang97f51af2021-04-22 12:24:11 -0700614 VkResult on_vkAllocateCommandBuffers(
615 void* context,
616 VkResult input_result,
617 VkDevice device,
618 const VkCommandBufferAllocateInfo* pAllocateInfo,
619 VkCommandBuffer* pCommandBuffers);
620
Lingfeng Yang084e5342021-07-15 13:06:43 -0700621 VkResult on_vkQueueSignalReleaseImageANDROID(
622 void* context,
623 VkResult input_result,
624 VkQueue queue,
625 uint32_t waitSemaphoreCount,
626 const VkSemaphore* pWaitSemaphores,
627 VkImage image,
628 int* pNativeFenceFd);
629
Yahan Zhou483ac022022-06-13 15:41:11 -0700630 VkResult on_vkCreateGraphicsPipelines(
631 void* context,
632 VkResult input_result,
633 VkDevice device,
634 VkPipelineCache pipelineCache,
635 uint32_t createInfoCount,
636 const VkGraphicsPipelineCreateInfo* pCreateInfos,
637 const VkAllocationCallbacks* pAllocator,
638 VkPipeline* pPipelines);
639
Lingfeng Yangdef88ba2018-12-13 12:43:17 -0800640 uint8_t* getMappedPointer(VkDeviceMemory memory);
641 VkDeviceSize getMappedSize(VkDeviceMemory memory);
Lingfeng Yang6ab1b0d2018-11-27 23:36:03 -0800642 VkDeviceSize getNonCoherentExtendedSize(VkDevice device, VkDeviceSize basicSize) const;
Lingfeng Yangdef88ba2018-12-13 12:43:17 -0800643 bool isValidMemoryRange(const VkMappedMemoryRange& range) const;
Lingfeng Yang31754632018-12-21 18:24:55 -0800644 void setupFeatures(const EmulatorFeatureInfo* features);
Lingfeng Yang34b5cae2019-08-21 14:12:19 -0700645 void setThreadingCallbacks(const ThreadingCallbacks& callbacks);
Lingfeng Yangb8a38c72019-02-02 20:27:54 -0800646 bool hostSupportsVulkan() const;
Lingfeng Yang236abc92018-12-21 20:19:33 -0800647 bool usingDirectMapping() const;
Lingfeng Yangb55ed1c2019-06-20 15:57:08 -0700648 uint32_t getStreamFeatures() const;
Lingfeng Yang2b1b8cf2019-02-08 09:53:36 -0800649 uint32_t getApiVersionFromInstance(VkInstance instance) const;
650 uint32_t getApiVersionFromDevice(VkDevice device) const;
651 bool hasInstanceExtension(VkInstance instance, const std::string& name) const;
652 bool hasDeviceExtension(VkDevice instance, const std::string& name) const;
Yahan Zhou97f37fa2022-04-28 21:57:17 +0000653 VkDevice getDevice(VkCommandBuffer commandBuffer) const;
Lingfeng Yang967f9af2021-01-22 17:56:24 -0800654 void addToCommandPool(VkCommandPool commandPool,
655 uint32_t commandBufferCount,
656 VkCommandBuffer* pCommandBuffers);
657 void resetCommandPoolStagingInfo(VkCommandPool commandPool);
658
Gurchetan Singhb7be3162021-11-04 09:36:15 -0700659#ifdef __GNUC__
660 #define ALWAYS_INLINE
661#elif
662 #define ALWAYS_INLINE __attribute__((always_inline))
663#endif
Lingfeng Yang967f9af2021-01-22 17:56:24 -0800664
665 static VkEncoder* getCommandBufferEncoder(VkCommandBuffer commandBuffer);
666 static VkEncoder* getQueueEncoder(VkQueue queue);
667 static VkEncoder* getThreadLocalEncoder();
Lingfeng Yang2b1b8cf2019-02-08 09:53:36 -0800668
Lingfeng Yangdb616552021-01-22 17:58:02 -0800669 static void setSeqnoPtr(uint32_t* seqnoptr);
Gurchetan Singhb7be3162021-11-04 09:36:15 -0700670 static ALWAYS_INLINE uint32_t nextSeqno();
671 static ALWAYS_INLINE uint32_t getSeqno();
Lingfeng Yangdb616552021-01-22 17:58:02 -0800672
Lingfeng Yang2b1b8cf2019-02-08 09:53:36 -0800673 // Transforms
Lingfeng Yang97a06702018-12-24 17:02:43 -0800674 void deviceMemoryTransform_tohost(
675 VkDeviceMemory* memory, uint32_t memoryCount,
676 VkDeviceSize* offset, uint32_t offsetCount,
677 VkDeviceSize* size, uint32_t sizeCount,
678 uint32_t* typeIndex, uint32_t typeIndexCount,
679 uint32_t* typeBits, uint32_t typeBitsCount);
680 void deviceMemoryTransform_fromhost(
Lingfeng Yang62b23322018-12-24 12:45:47 -0800681 VkDeviceMemory* memory, uint32_t memoryCount,
682 VkDeviceSize* offset, uint32_t offsetCount,
683 VkDeviceSize* size, uint32_t sizeCount,
684 uint32_t* typeIndex, uint32_t typeIndexCount,
685 uint32_t* typeBits, uint32_t typeBitsCount);
Lingfeng Yangdef88ba2018-12-13 12:43:17 -0800686
Yilong Lidbc16d52021-02-04 03:15:21 -0800687 void transformImpl_VkExternalMemoryProperties_fromhost(
688 VkExternalMemoryProperties* pProperties,
689 uint32_t);
690 void transformImpl_VkExternalMemoryProperties_tohost(
691 VkExternalMemoryProperties* pProperties,
692 uint32_t);
Yilong Li353409a2022-01-04 02:37:56 -0800693 void transformImpl_VkImageCreateInfo_fromhost(const VkImageCreateInfo*, uint32_t);
694 void transformImpl_VkImageCreateInfo_tohost(const VkImageCreateInfo*, uint32_t);
Lingfeng Yang4af5f322019-02-14 08:10:28 -0800695
Yilong Lidbc16d52021-02-04 03:15:21 -0800696#define DEFINE_TRANSFORMED_TYPE_PROTOTYPE(type) \
697 void transformImpl_##type##_tohost(type*, uint32_t); \
698 void transformImpl_##type##_fromhost(type*, uint32_t);
Lingfeng Yangf0654ff2019-02-02 12:21:24 -0800699
Yilong Lid1c69192021-02-05 02:06:07 -0800700 LIST_TRIVIAL_TRANSFORMED_TYPES(DEFINE_TRANSFORMED_TYPE_PROTOTYPE)
Yilong Lidbc16d52021-02-04 03:15:21 -0800701
702private:
Lingfeng Yang71b596b2018-11-07 18:03:25 -0800703 class Impl;
704 std::unique_ptr<Impl> mImpl;
705};
Lingfeng Yang71b596b2018-11-07 18:03:25 -0800706
Lingfeng Yangb8a38c72019-02-02 20:27:54 -0800707} // namespace goldfish_vk