| 1 |
/* |
| 2 |
* Copyright 2018 Google |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <vulkan/vulkan.h> |
| 8 |
|
| 9 |
#include <atomic> |
| 10 |
#include <functional> |
| 11 |
#include <memory> |
| 12 |
#include <mutex> |
| 13 |
#include <optional> |
| 14 |
#include <set> |
| 15 |
#include <unordered_map> |
| 16 |
|
| 17 |
#include "CommandBufferStagingStream.h" |
| 18 |
#include "GfxStreamConnectionManager.h" |
| 19 |
#include "HostVisibleMemoryVirtualization.h" |
| 20 |
#include "Sync.h" |
| 21 |
#include "VirtGpu.h" |
| 22 |
#include "VulkanHandleMapping.h" |
| 23 |
#include "VulkanHandles.h" |
| 24 |
#include "goldfish_vk_transform_guest.h" |
| 25 |
#include "util/perf/cpu_trace.h" |
| 26 |
#include "util/detect_os.h" |
| 27 |
#include "vulkan/vulkan_core.h" |
| 28 |
|
| 29 |
/// Use installed headers or locally defined Fuchsia-specific bits |
| 30 |
#ifdef VK_USE_PLATFORM_FUCHSIA |
| 31 |
|
| 32 |
#include <cutils/native_handle.h> |
| 33 |
#include <fidl/fuchsia.hardware.goldfish/cpp/wire.h> |
| 34 |
#include <fidl/fuchsia.sysmem/cpp/wire.h> |
| 35 |
#include <lib/zx/channel.h> |
| 36 |
#include <lib/zx/vmo.h> |
| 37 |
#include <zircon/errors.h> |
| 38 |
#include <zircon/process.h> |
| 39 |
#include <zircon/rights.h> |
| 40 |
#include <zircon/syscalls.h> |
| 41 |
#include <zircon/syscalls/object.h> |
| 42 |
|
| 43 |
#include <optional> |
| 44 |
|
| 45 |
#include "services/service_connector.h" |
| 46 |
|
| 47 |
#ifndef FUCHSIA_NO_TRACE |
| 48 |
#include <lib/trace/event.h> |
| 49 |
#endif |
| 50 |
|
| 51 |
#define GET_STATUS_SAFE(result, member) ((result).ok() ? ((result)->member) : ZX_OK) |
| 52 |
|
| 53 |
struct SetBufferCollectionImageConstraintsResult { |
| 54 |
VkResult result; |
| 55 |
fuchsia_sysmem::wire::BufferCollectionConstraints constraints; |
| 56 |
std::vector<uint32_t> createInfoIndex; |
| 57 |
}; |
| 58 |
|
| 59 |
struct SetBufferCollectionBufferConstraintsResult { |
| 60 |
VkResult result; |
| 61 |
fuchsia_sysmem::wire::BufferCollectionConstraints constraints; |
| 62 |
}; |
| 63 |
|
| 64 |
#else |
| 65 |
|
| 66 |
typedef uint32_t zx_handle_t; |
| 67 |
typedef uint64_t zx_koid_t; |
| 68 |
#define ZX_HANDLE_INVALID ((zx_handle_t)0) |
| 69 |
#define ZX_KOID_INVALID ((zx_koid_t)0) |
| 70 |
#endif // VK_USE_PLATFORM_FUCHSIA |
| 71 |
|
| 72 |
/// Use installed headers or locally defined Android-specific bits |
| 73 |
#ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 74 |
#include "AndroidHardwareBuffer.h" |
| 75 |
#include "gfxstream/guest/GfxStreamGralloc.h" |
| 76 |
#include <android/hardware_buffer.h> |
| 77 |
#endif |
| 78 |
|
| 79 |
#if GFXSTREAM_ENABLE_GUEST_GOLDFISH |
| 80 |
/// Goldfish sync only used for AEMU -- should replace in virtio-gpu when possibe |
| 81 |
#include "gfxstream/guest/goldfish_sync.h" |
| 82 |
#endif |
| 83 |
|
| 84 |
#define vk_filter_struct(__start, __sType) { \ |
| 85 |
auto* curr = reinterpret_cast<VkBaseOutStructure*>(__start); \ |
| 86 |
while (curr != nullptr) { \ |
| 87 |
if (curr->pNext != nullptr && curr->pNext->sType == VK_STRUCTURE_TYPE_##__sType) { \ |
| 88 |
curr->pNext = curr->pNext->pNext; \ |
| 89 |
} \ |
| 90 |
curr = curr->pNext; \ |
| 91 |
} \ |
| 92 |
} \ |
| 93 |
|
| 94 |
// This should be ABI identical with the variant in ResourceTracker.h |
| 95 |
struct GfxStreamVkFeatureInfo { |
| 96 |
bool hasDirectMem; |
| 97 |
bool hasVulkan; |
| 98 |
bool hasDeferredVulkanCommands; |
| 99 |
bool hasVulkanNullOptionalStrings; |
| 100 |
bool hasVulkanCreateResourcesWithRequirements; |
| 101 |
bool hasVulkanIgnoredHandles; |
| 102 |
bool hasVirtioGpuNext; |
| 103 |
bool hasVulkanFreeMemorySync; |
| 104 |
bool hasVirtioGpuNativeSync; |
| 105 |
bool hasVulkanShaderFloat16Int8; |
| 106 |
bool hasVulkanAsyncQueueSubmit; |
| 107 |
bool hasVulkanQueueSubmitWithCommands; |
| 108 |
bool hasVulkanBatchedDescriptorSetUpdate; |
| 109 |
bool hasVulkanAsyncQsri; |
| 110 |
bool hasVulkanAuxCommandMemory; |
| 111 |
bool setupComplete; |
| 112 |
}; |
| 113 |
|
| 114 |
class HostConnection; |
| 115 |
|
| 116 |
namespace gfxstream { |
| 117 |
namespace vk { |
| 118 |
|
| 119 |
class VkEncoder; |
| 120 |
|
| 121 |
class ResourceTracker { |
| 122 |
public: |
| 123 |
ResourceTracker(); |
| 124 |
~ResourceTracker(); |
| 125 |
static ResourceTracker* get(); |
| 126 |
|
| 127 |
VulkanHandleMapping* createMapping(); |
| 128 |
VulkanHandleMapping* destroyMapping(); |
| 129 |
|
| 130 |
using HostConnectionGetFunc = GfxStreamConnectionManager* (*)(); |
| 131 |
using VkEncoderGetFunc = VkEncoder* (*)(GfxStreamConnectionManager*); |
| 132 |
using CleanupCallback = std::function<void()>; |
| 133 |
|
| 134 |
struct ThreadingCallbacks { |
| 135 |
HostConnectionGetFunc hostConnectionGetFunc = nullptr; |
| 136 |
VkEncoderGetFunc vkEncoderGetFunc = nullptr; |
| 137 |
}; |
| 138 |
|
| 139 |
static uint32_t streamFeatureBits; |
| 140 |
static ThreadingCallbacks threadingCallbacks; |
| 141 |
|
| 142 |
#define HANDLE_REGISTER_DECL(type) \ |
| 143 |
void register_##type(type); \ |
| 144 |
void unregister_##type(type); |
| 145 |
|
| 146 |
GOLDFISH_VK_LIST_HANDLE_TYPES(HANDLE_REGISTER_DECL) |
| 147 |
|
| 148 |
VkResult on_vkEnumerateInstanceExtensionProperties(void* context, VkResult input_result, |
| 149 |
const char* pLayerName, |
| 150 |
uint32_t* pPropertyCount, |
| 151 |
VkExtensionProperties* pProperties); |
| 152 |
|
| 153 |
VkResult on_vkEnumerateDeviceExtensionProperties(void* context, VkResult input_result, |
| 154 |
VkPhysicalDevice physicalDevice, |
| 155 |
const char* pLayerName, |
| 156 |
uint32_t* pPropertyCount, |
| 157 |
VkExtensionProperties* pProperties); |
| 158 |
|
| 159 |
VkResult on_vkEnumeratePhysicalDevices(void* context, VkResult input_result, |
| 160 |
VkInstance instance, uint32_t* pPhysicalDeviceCount, |
| 161 |
VkPhysicalDevice* pPhysicalDevices); |
| 162 |
|
| 163 |
void on_vkGetPhysicalDeviceFeatures2(void* context, VkPhysicalDevice physicalDevice, |
| 164 |
VkPhysicalDeviceFeatures2* pFeatures); |
| 165 |
|
| 166 |
void on_vkGetPhysicalDeviceProperties2KHR(void* context, VkPhysicalDevice physicalDevice, |
| 167 |
VkPhysicalDeviceProperties2* pProperties); |
| 168 |
void on_vkGetPhysicalDeviceProperties2(void* context, VkPhysicalDevice physicalDevice, |
| 169 |
VkPhysicalDeviceProperties2* pProperties); |
| 170 |
|
| 171 |
void on_vkGetPhysicalDeviceMemoryProperties( |
| 172 |
void* context, VkPhysicalDevice physicalDevice, |
| 173 |
VkPhysicalDeviceMemoryProperties* pMemoryProperties); |
| 174 |
void on_vkGetPhysicalDeviceMemoryProperties2( |
| 175 |
void* context, VkPhysicalDevice physicalDevice, |
| 176 |
VkPhysicalDeviceMemoryProperties2* pMemoryProperties); |
| 177 |
|
| 178 |
VkResult on_vkCreateInstance(void* context, VkResult input_result, |
| 179 |
const VkInstanceCreateInfo* createInfo, |
| 180 |
const VkAllocationCallbacks* pAllocator, VkInstance* pInstance); |
| 181 |
VkResult on_vkCreateDevice(void* context, VkResult input_result, |
| 182 |
VkPhysicalDevice physicalDevice, |
| 183 |
const VkDeviceCreateInfo* pCreateInfo, |
| 184 |
const VkAllocationCallbacks* pAllocator, VkDevice* pDevice); |
| 185 |
void on_vkDestroyDevice_pre(void* context, VkDevice device, |
| 186 |
const VkAllocationCallbacks* pAllocator); |
| 187 |
|
| 188 |
VkResult on_vkAllocateMemory(void* context, VkResult input_result, VkDevice device, |
| 189 |
const VkMemoryAllocateInfo* pAllocateInfo, |
| 190 |
const VkAllocationCallbacks* pAllocator, VkDeviceMemory* pMemory); |
| 191 |
void on_vkFreeMemory(void* context, VkDevice device, VkDeviceMemory memory, |
| 192 |
const VkAllocationCallbacks* pAllocator); |
| 193 |
|
| 194 |
VkResult on_vkMapMemory(void* context, VkResult input_result, VkDevice device, |
| 195 |
VkDeviceMemory memory, VkDeviceSize offset, VkDeviceSize size, |
| 196 |
VkMemoryMapFlags, void** ppData); |
| 197 |
|
| 198 |
void on_vkUnmapMemory(void* context, VkDevice device, VkDeviceMemory memory); |
| 199 |
|
| 200 |
VkResult on_vkCreateImage(void* context, VkResult input_result, VkDevice device, |
| 201 |
const VkImageCreateInfo* pCreateInfo, |
| 202 |
const VkAllocationCallbacks* pAllocator, VkImage* pImage); |
| 203 |
void on_vkDestroyImage(void* context, VkDevice device, VkImage image, |
| 204 |
const VkAllocationCallbacks* pAllocator); |
| 205 |
|
| 206 |
void on_vkGetImageMemoryRequirements(void* context, VkDevice device, VkImage image, |
| 207 |
VkMemoryRequirements* pMemoryRequirements); |
| 208 |
void on_vkGetImageMemoryRequirements2(void* context, VkDevice device, |
| 209 |
const VkImageMemoryRequirementsInfo2* pInfo, |
| 210 |
VkMemoryRequirements2* pMemoryRequirements); |
| 211 |
VkResult on_vkGetImageDrmFormatModifierPropertiesEXT( |
| 212 |
void* context, VkResult input_result, VkDevice device, VkImage image, |
| 213 |
VkImageDrmFormatModifierPropertiesEXT* pProperties); |
| 214 |
|
| 215 |
VkResult on_vkBindImageMemory(void* context, VkResult input_result, VkDevice device, |
| 216 |
VkImage image, VkDeviceMemory memory, VkDeviceSize memoryOffset); |
| 217 |
VkResult on_vkBindImageMemory2(void* context, VkResult input_result, VkDevice device, |
| 218 |
uint32_t bindingCount, const VkBindImageMemoryInfo* pBindInfos); |
| 219 |
|
| 220 |
VkResult on_vkCreateBuffer(void* context, VkResult input_result, VkDevice device, |
| 221 |
const VkBufferCreateInfo* pCreateInfo, |
| 222 |
const VkAllocationCallbacks* pAllocator, VkBuffer* pBuffer); |
| 223 |
void on_vkDestroyBuffer(void* context, VkDevice device, VkBuffer buffer, |
| 224 |
const VkAllocationCallbacks* pAllocator); |
| 225 |
|
| 226 |
void on_vkGetBufferMemoryRequirements(void* context, VkDevice device, VkBuffer buffer, |
| 227 |
VkMemoryRequirements* pMemoryRequirements); |
| 228 |
void on_vkGetBufferMemoryRequirements2(void* context, VkDevice device, |
| 229 |
const VkBufferMemoryRequirementsInfo2* pInfo, |
| 230 |
VkMemoryRequirements2* pMemoryRequirements); |
| 231 |
|
| 232 |
VkResult on_vkCreateSemaphore(void* context, VkResult, VkDevice device, |
| 233 |
const VkSemaphoreCreateInfo* pCreateInfo, |
| 234 |
const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore); |
| 235 |
void on_vkDestroySemaphore(void* context, VkDevice device, VkSemaphore semaphore, |
| 236 |
const VkAllocationCallbacks* pAllocator); |
| 237 |
VkResult on_vkGetSemaphoreFdKHR(void* context, VkResult, VkDevice device, |
| 238 |
const VkSemaphoreGetFdInfoKHR* pGetFdInfo, int* pFd); |
| 239 |
VkResult on_vkImportSemaphoreFdKHR(void* context, VkResult, VkDevice device, |
| 240 |
const VkImportSemaphoreFdInfoKHR* pImportSemaphoreFdInfo); |
| 241 |
|
| 242 |
VkResult on_vkQueueSubmit(void* context, VkResult input_result, VkQueue queue, |
| 243 |
uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence); |
| 244 |
|
| 245 |
VkResult on_vkQueueSubmit2(void* context, VkResult input_result, VkQueue queue, |
| 246 |
uint32_t submitCount, const VkSubmitInfo2* pSubmits, VkFence fence); |
| 247 |
|
| 248 |
VkResult on_vkQueueWaitIdle(void* context, VkResult input_result, VkQueue queue); |
| 249 |
|
| 250 |
void unwrap_vkCreateImage_pCreateInfo(const VkImageCreateInfo* pCreateInfo, |
| 251 |
VkImageCreateInfo* local_pCreateInfo); |
| 252 |
|
| 253 |
void unwrap_vkAcquireImageANDROID_nativeFenceFd(int fd, int* fd_out); |
| 254 |
|
| 255 |
void unwrap_VkBindImageMemory2_pBindInfos(uint32_t bindInfoCount, |
| 256 |
const VkBindImageMemoryInfo* inputBindInfos, |
| 257 |
VkBindImageMemoryInfo* outputBindInfos); |
| 258 |
|
| 259 |
VkResult on_vkGetMemoryFdKHR(void* context, VkResult input_result, VkDevice device, |
| 260 |
const VkMemoryGetFdInfoKHR* pGetFdInfo, int* pFd); |
| 261 |
VkResult on_vkGetMemoryFdPropertiesKHR(void* context, VkResult input_result, VkDevice device, |
| 262 |
VkExternalMemoryHandleTypeFlagBits handleType, int fd, |
| 263 |
VkMemoryFdPropertiesKHR* pMemoryFdProperties); |
| 264 |
|
| 265 |
#ifdef VK_USE_PLATFORM_FUCHSIA |
| 266 |
VkResult on_vkGetMemoryZirconHandleFUCHSIA(void* context, VkResult input_result, |
| 267 |
VkDevice device, |
| 268 |
const VkMemoryGetZirconHandleInfoFUCHSIA* pInfo, |
| 269 |
uint32_t* pHandle); |
| 270 |
VkResult on_vkGetMemoryZirconHandlePropertiesFUCHSIA( |
| 271 |
void* context, VkResult input_result, VkDevice device, |
| 272 |
VkExternalMemoryHandleTypeFlagBits handleType, uint32_t handle, |
| 273 |
VkMemoryZirconHandlePropertiesFUCHSIA* pProperties); |
| 274 |
VkResult on_vkGetSemaphoreZirconHandleFUCHSIA( |
| 275 |
void* context, VkResult input_result, VkDevice device, |
| 276 |
const VkSemaphoreGetZirconHandleInfoFUCHSIA* pInfo, uint32_t* pHandle); |
| 277 |
VkResult on_vkImportSemaphoreZirconHandleFUCHSIA( |
| 278 |
void* context, VkResult input_result, VkDevice device, |
| 279 |
const VkImportSemaphoreZirconHandleInfoFUCHSIA* pInfo); |
| 280 |
VkResult on_vkCreateBufferCollectionFUCHSIA(void* context, VkResult input_result, |
| 281 |
VkDevice device, |
| 282 |
const VkBufferCollectionCreateInfoFUCHSIA* pInfo, |
| 283 |
const VkAllocationCallbacks* pAllocator, |
| 284 |
VkBufferCollectionFUCHSIA* pCollection); |
| 285 |
void on_vkDestroyBufferCollectionFUCHSIA(void* context, VkResult input_result, VkDevice device, |
| 286 |
VkBufferCollectionFUCHSIA collection, |
| 287 |
const VkAllocationCallbacks* pAllocator); |
| 288 |
VkResult on_vkSetBufferCollectionBufferConstraintsFUCHSIA( |
| 289 |
void* context, VkResult input_result, VkDevice device, VkBufferCollectionFUCHSIA collection, |
| 290 |
const VkBufferConstraintsInfoFUCHSIA* pBufferConstraintsInfo); |
| 291 |
VkResult on_vkSetBufferCollectionImageConstraintsFUCHSIA( |
| 292 |
void* context, VkResult input_result, VkDevice device, VkBufferCollectionFUCHSIA collection, |
| 293 |
const VkImageConstraintsInfoFUCHSIA* pImageConstraintsInfo); |
| 294 |
VkResult on_vkGetBufferCollectionPropertiesFUCHSIA( |
| 295 |
void* context, VkResult input_result, VkDevice device, VkBufferCollectionFUCHSIA collection, |
| 296 |
VkBufferCollectionPropertiesFUCHSIA* pProperties); |
| 297 |
|
| 298 |
VkResult setBufferCollectionImageConstraintsFUCHSIA( |
| 299 |
VkEncoder* enc, VkDevice device, |
| 300 |
fidl::WireSyncClient<fuchsia_sysmem::BufferCollection>* pCollection, |
| 301 |
const VkImageConstraintsInfoFUCHSIA* pImageConstraintsInfo); |
| 302 |
|
| 303 |
VkResult setBufferCollectionBufferConstraintsFUCHSIA( |
| 304 |
fidl::WireSyncClient<fuchsia_sysmem::BufferCollection>* pCollection, |
| 305 |
const VkBufferConstraintsInfoFUCHSIA* pBufferConstraintsInfo); |
| 306 |
|
| 307 |
#endif |
| 308 |
|
| 309 |
#ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 310 |
VkResult on_vkGetAndroidHardwareBufferPropertiesANDROID( |
| 311 |
void* context, VkResult input_result, VkDevice device, const AHardwareBuffer* buffer, |
| 312 |
VkAndroidHardwareBufferPropertiesANDROID* pProperties); |
| 313 |
VkResult on_vkGetMemoryAndroidHardwareBufferANDROID( |
| 314 |
void* context, VkResult input_result, VkDevice device, |
| 315 |
const VkMemoryGetAndroidHardwareBufferInfoANDROID* pInfo, struct AHardwareBuffer** pBuffer); |
| 316 |
#endif |
| 317 |
|
| 318 |
VkResult on_vkCreateSamplerYcbcrConversion( |
| 319 |
void* context, VkResult input_result, VkDevice device, |
| 320 |
const VkSamplerYcbcrConversionCreateInfo* pCreateInfo, |
| 321 |
const VkAllocationCallbacks* pAllocator, VkSamplerYcbcrConversion* pYcbcrConversion); |
| 322 |
void on_vkDestroySamplerYcbcrConversion(void* context, VkDevice device, |
| 323 |
VkSamplerYcbcrConversion ycbcrConversion, |
| 324 |
const VkAllocationCallbacks* pAllocator); |
| 325 |
|
| 326 |
VkResult on_vkCreateSampler(void* context, VkResult input_result, VkDevice device, |
| 327 |
const VkSamplerCreateInfo* pCreateInfo, |
| 328 |
const VkAllocationCallbacks* pAllocator, VkSampler* pSampler); |
| 329 |
|
| 330 |
void on_vkGetPhysicalDeviceExternalFenceProperties( |
| 331 |
void* context, VkPhysicalDevice physicalDevice, |
| 332 |
const VkPhysicalDeviceExternalFenceInfo* pExternalFenceInfo, |
| 333 |
VkExternalFenceProperties* pExternalFenceProperties); |
| 334 |
|
| 335 |
VkResult on_vkCreateFence(void* context, VkResult input_result, VkDevice device, |
| 336 |
const VkFenceCreateInfo* pCreateInfo, |
| 337 |
const VkAllocationCallbacks* pAllocator, VkFence* pFence); |
| 338 |
|
| 339 |
void on_vkDestroyFence(void* context, VkDevice device, VkFence fence, |
| 340 |
const VkAllocationCallbacks* pAllocator); |
| 341 |
|
| 342 |
VkResult on_vkResetFences(void* context, VkResult input_result, VkDevice device, |
| 343 |
uint32_t fenceCount, const VkFence* pFences); |
| 344 |
|
| 345 |
VkResult on_vkImportFenceFdKHR(void* context, VkResult input_result, VkDevice device, |
| 346 |
const VkImportFenceFdInfoKHR* pImportFenceFdInfo); |
| 347 |
|
| 348 |
VkResult on_vkGetFenceFdKHR(void* context, VkResult input_result, VkDevice device, |
| 349 |
const VkFenceGetFdInfoKHR* pGetFdInfo, int* pFd); |
| 350 |
|
| 351 |
VkResult on_vkGetFenceStatus(void* context, VkResult input_result, VkDevice device, |
| 352 |
VkFence fence); |
| 353 |
|
| 354 |
VkResult on_vkWaitForFences(void* context, VkResult input_result, VkDevice device, |
| 355 |
uint32_t fenceCount, const VkFence* pFences, VkBool32 waitAll, |
| 356 |
uint64_t timeout); |
| 357 |
|
| 358 |
VkResult on_vkSetPrivateData(void* context, VkResult input_result, VkDevice device, |
| 359 |
VkObjectType objectType, uint64_t objectHandle, |
| 360 |
VkPrivateDataSlot privateDataSlot, uint64_t data); |
| 361 |
VkResult on_vkSetPrivateDataEXT(void* context, VkResult input_result, VkDevice device, |
| 362 |
VkObjectType objectType, uint64_t objectHandle, |
| 363 |
VkPrivateDataSlot privateDataSlot, uint64_t data); |
| 364 |
|
| 365 |
void on_vkGetPrivateData(void* context, VkDevice device, VkObjectType objectType, |
| 366 |
uint64_t objectHandle, VkPrivateDataSlot privateDataSlot, |
| 367 |
uint64_t* pData); |
| 368 |
void on_vkGetPrivateDataEXT(void* context, VkDevice device, VkObjectType objectType, |
| 369 |
uint64_t objectHandle, VkPrivateDataSlot privateDataSlot, |
| 370 |
uint64_t* pData); |
| 371 |
|
| 372 |
VkResult on_vkCreatePrivateDataSlot(void* context, VkResult input_result, VkDevice device, |
| 373 |
const VkPrivateDataSlotCreateInfo* pCreateInfo, |
| 374 |
const VkAllocationCallbacks* pAllocator, |
| 375 |
VkPrivateDataSlot* pPrivateDataSlot); |
| 376 |
VkResult on_vkCreatePrivateDataSlotEXT(void* context, VkResult input_result, VkDevice device, |
| 377 |
const VkPrivateDataSlotCreateInfo* pCreateInfo, |
| 378 |
const VkAllocationCallbacks* pAllocator, |
| 379 |
VkPrivateDataSlot* pPrivateDataSlot); |
| 380 |
void on_vkDestroyPrivateDataSlot(void* context, VkDevice device, |
| 381 |
VkPrivateDataSlot privateDataSlot, |
| 382 |
const VkAllocationCallbacks* pAllocator); |
| 383 |
void on_vkDestroyPrivateDataSlotEXT(void* context, VkDevice device, |
| 384 |
VkPrivateDataSlot privateDataSlot, |
| 385 |
const VkAllocationCallbacks* pAllocator); |
| 386 |
|
| 387 |
VkResult on_vkCreateDescriptorPool(void* context, VkResult input_result, VkDevice device, |
| 388 |
const VkDescriptorPoolCreateInfo* pCreateInfo, |
| 389 |
const VkAllocationCallbacks* pAllocator, |
| 390 |
VkDescriptorPool* pDescriptorPool); |
| 391 |
|
| 392 |
void on_vkDestroyDescriptorPool(void* context, VkDevice device, VkDescriptorPool descriptorPool, |
| 393 |
const VkAllocationCallbacks* pAllocator); |
| 394 |
|
| 395 |
VkResult on_vkResetDescriptorPool(void* context, VkResult input_result, VkDevice device, |
| 396 |
VkDescriptorPool descriptorPool, |
| 397 |
VkDescriptorPoolResetFlags flags); |
| 398 |
|
| 399 |
VkResult on_vkAllocateDescriptorSets(void* context, VkResult input_result, VkDevice device, |
| 400 |
const VkDescriptorSetAllocateInfo* pAllocateInfo, |
| 401 |
VkDescriptorSet* pDescriptorSets); |
| 402 |
|
| 403 |
VkResult on_vkFreeDescriptorSets(void* context, VkResult input_result, VkDevice device, |
| 404 |
VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, |
| 405 |
const VkDescriptorSet* pDescriptorSets); |
| 406 |
|
| 407 |
VkResult on_vkCreateDescriptorSetLayout(void* context, VkResult input_result, VkDevice device, |
| 408 |
const VkDescriptorSetLayoutCreateInfo* pCreateInfo, |
| 409 |
const VkAllocationCallbacks* pAllocator, |
| 410 |
VkDescriptorSetLayout* pSetLayout); |
| 411 |
|
| 412 |
void on_vkUpdateDescriptorSets(void* context, VkDevice device, uint32_t descriptorWriteCount, |
| 413 |
const VkWriteDescriptorSet* pDescriptorWrites, |
| 414 |
uint32_t descriptorCopyCount, |
| 415 |
const VkCopyDescriptorSet* pDescriptorCopies); |
| 416 |
|
| 417 |
VkResult on_vkMapMemoryIntoAddressSpaceGOOGLE_pre(void* context, VkResult input_result, |
| 418 |
VkDevice device, VkDeviceMemory memory, |
| 419 |
uint64_t* pAddress); |
| 420 |
VkResult on_vkMapMemoryIntoAddressSpaceGOOGLE(void* context, VkResult input_result, |
| 421 |
VkDevice device, VkDeviceMemory memory, |
| 422 |
uint64_t* pAddress); |
| 423 |
|
| 424 |
VkResult on_vkCreateDescriptorUpdateTemplate( |
| 425 |
void* context, VkResult input_result, VkDevice device, |
| 426 |
const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, |
| 427 |
const VkAllocationCallbacks* pAllocator, |
| 428 |
VkDescriptorUpdateTemplate* pDescriptorUpdateTemplate); |
| 429 |
|
| 430 |
void on_vkUpdateDescriptorSetWithTemplate(void* context, VkDevice device, |
| 431 |
VkDescriptorSet descriptorSet, |
| 432 |
VkDescriptorUpdateTemplate descriptorUpdateTemplate, |
| 433 |
const void* pData); |
| 434 |
|
| 435 |
void on_vkGetPhysicalDeviceFormatProperties2(void* context, VkPhysicalDevice physicalDevice, |
| 436 |
VkFormat format, |
| 437 |
VkFormatProperties2* pFormatProperties); |
| 438 |
|
| 439 |
VkResult on_vkGetPhysicalDeviceImageFormatProperties2( |
| 440 |
void* context, VkResult input_result, VkPhysicalDevice physicalDevice, |
| 441 |
const VkPhysicalDeviceImageFormatInfo2* pImageFormatInfo, |
| 442 |
VkImageFormatProperties2* pImageFormatProperties); |
| 443 |
|
| 444 |
void on_vkGetPhysicalDeviceExternalBufferProperties( |
| 445 |
void* context, VkPhysicalDevice physicalDevice, |
| 446 |
const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, |
| 447 |
VkExternalBufferProperties* pExternalBufferProperties); |
| 448 |
|
| 449 |
void on_vkGetPhysicalDeviceExternalSemaphoreProperties( |
| 450 |
void* context, VkPhysicalDevice physicalDevice, |
| 451 |
const VkPhysicalDeviceExternalSemaphoreInfo* pExternalSemaphoreInfo, |
| 452 |
VkExternalSemaphoreProperties* pExternalSemaphoreProperties); |
| 453 |
|
| 454 |
void registerEncoderCleanupCallback(const VkEncoder* encoder, void* handle, |
| 455 |
CleanupCallback callback); |
| 456 |
void unregisterEncoderCleanupCallback(const VkEncoder* encoder, void* handle); |
| 457 |
void onEncoderDeleted(const VkEncoder* encoder); |
| 458 |
|
| 459 |
uint32_t syncEncodersForCommandBuffer(VkCommandBuffer commandBuffer, VkEncoder* current); |
| 460 |
uint32_t syncEncodersForQueue(VkQueue queue, VkEncoder* currentEncoder); |
| 461 |
|
| 462 |
CommandBufferStagingStream::Alloc getAlloc(); |
| 463 |
CommandBufferStagingStream::Free getFree(); |
| 464 |
|
| 465 |
VkResult on_vkBeginCommandBuffer(void* context, VkResult input_result, |
| 466 |
VkCommandBuffer commandBuffer, |
| 467 |
const VkCommandBufferBeginInfo* pBeginInfo); |
| 468 |
VkResult on_vkEndCommandBuffer(void* context, VkResult input_result, |
| 469 |
VkCommandBuffer commandBuffer); |
| 470 |
VkResult on_vkResetCommandBuffer(void* context, VkResult input_result, |
| 471 |
VkCommandBuffer commandBuffer, |
| 472 |
VkCommandBufferResetFlags flags); |
| 473 |
|
| 474 |
VkResult on_vkCreateImageView(void* context, VkResult input_result, VkDevice device, |
| 475 |
const VkImageViewCreateInfo* pCreateInfo, |
| 476 |
const VkAllocationCallbacks* pAllocator, VkImageView* pView); |
| 477 |
|
| 478 |
void on_vkCmdExecuteCommands(void* context, VkCommandBuffer commandBuffer, |
| 479 |
uint32_t commandBufferCount, |
| 480 |
const VkCommandBuffer* pCommandBuffers); |
| 481 |
|
| 482 |
void on_vkCmdBindDescriptorSets(void* context, VkCommandBuffer commandBuffer, |
| 483 |
VkPipelineBindPoint pipelineBindPoint, VkPipelineLayout layout, |
| 484 |
uint32_t firstSet, uint32_t descriptorSetCount, |
| 485 |
const VkDescriptorSet* pDescriptorSets, |
| 486 |
uint32_t dynamicOffsetCount, const uint32_t* pDynamicOffsets); |
| 487 |
|
| 488 |
void on_vkCmdPipelineBarrier( |
| 489 |
void* context, VkCommandBuffer commandBuffer, VkPipelineStageFlags srcStageMask, |
| 490 |
VkPipelineStageFlags dstStageMask, VkDependencyFlags dependencyFlags, |
| 491 |
uint32_t memoryBarrierCount, const VkMemoryBarrier* pMemoryBarriers, |
| 492 |
uint32_t bufferMemoryBarrierCount, const VkBufferMemoryBarrier* pBufferMemoryBarriers, |
| 493 |
uint32_t imageMemoryBarrierCount, const VkImageMemoryBarrier* pImageMemoryBarriers); |
| 494 |
|
| 495 |
void on_vkCmdClearColorImage(void* context, VkCommandBuffer commandBuffer, VkImage image, |
| 496 |
VkImageLayout imageLayout, const VkClearColorValue* pColor, |
| 497 |
uint32_t rangeCount, const VkImageSubresourceRange* pRanges); |
| 498 |
|
| 499 |
void on_vkDestroyDescriptorSetLayout(void* context, VkDevice device, |
| 500 |
VkDescriptorSetLayout descriptorSetLayout, |
| 501 |
const VkAllocationCallbacks* pAllocator); |
| 502 |
|
| 503 |
VkResult on_vkAllocateCommandBuffers(void* context, VkResult input_result, VkDevice device, |
| 504 |
const VkCommandBufferAllocateInfo* pAllocateInfo, |
| 505 |
VkCommandBuffer* pCommandBuffers); |
| 506 |
|
| 507 |
VkResult on_vkQueueSignalReleaseImageANDROID(void* context, VkResult input_result, |
| 508 |
VkQueue queue, uint32_t waitSemaphoreCount, |
| 509 |
const VkSemaphore* pWaitSemaphores, VkImage image, |
| 510 |
int* pNativeFenceFd); |
| 511 |
|
| 512 |
VkResult on_vkCreateGraphicsPipelines(void* context, VkResult input_result, VkDevice device, |
| 513 |
VkPipelineCache pipelineCache, uint32_t createInfoCount, |
| 514 |
const VkGraphicsPipelineCreateInfo* pCreateInfos, |
| 515 |
const VkAllocationCallbacks* pAllocator, |
| 516 |
VkPipeline* pPipelines); |
| 517 |
|
| 518 |
uint8_t* getMappedPointer(VkDeviceMemory memory); |
| 519 |
VkDeviceSize getMappedSize(VkDeviceMemory memory); |
| 520 |
VkDeviceSize getNonCoherentExtendedSize(VkDevice device, VkDeviceSize basicSize) const; |
| 521 |
bool isValidMemoryRange(const VkMappedMemoryRange& range); |
| 522 |
|
| 523 |
void setupFeatures(const struct GfxStreamVkFeatureInfo* features); |
| 524 |
void setupCaps(uint32_t& noRenderControlEnc); |
| 525 |
void setupPlatformHelpers(); |
| 526 |
void setThreadingCallbacks(const ThreadingCallbacks& callbacks); |
| 527 |
bool hostSupportsVulkan() const; |
| 528 |
bool usingDirectMapping() const; |
| 529 |
uint32_t getStreamFeatures() const; |
| 530 |
uint32_t getApiVersionFromInstance(VkInstance instance); |
| 531 |
uint32_t getApiVersionFromDevice(VkDevice device); |
| 532 |
VkDevice getDevice(VkCommandBuffer commandBuffer) const; |
| 533 |
void addToCommandPool(VkCommandPool commandPool, uint32_t commandBufferCount, |
| 534 |
VkCommandBuffer* pCommandBuffers); |
| 535 |
void resetCommandPoolStagingInfo(VkCommandPool commandPool); |
| 536 |
|
| 537 |
#ifdef LINUX_GUEST_BUILD |
| 538 |
// TODO: This information is tracked in |
| 539 |
// gfxstream_vk_physical_device::doImageDrmFormatModifierEmulation, but mesa objects need to be |
| 540 |
// combined with gfxstream objects |
| 541 |
bool doImageDrmFormatModifierEmulation(VkPhysicalDevice physicalDevice); |
| 542 |
#endif |
| 543 |
|
| 544 |
#ifdef __GNUC__ |
| 545 |
#define ALWAYS_INLINE_GFXSTREAM |
| 546 |
#elif |
| 547 |
#define ALWAYS_INLINE_GFXSTREAM __attribute__((always_inline)) |
| 548 |
#endif |
| 549 |
|
| 550 |
static VkEncoder* getCommandBufferEncoder(VkCommandBuffer commandBuffer); |
| 551 |
static VkEncoder* getQueueEncoder(VkQueue queue); |
| 552 |
static VkEncoder* getThreadLocalEncoder(); |
| 553 |
|
| 554 |
static void setSeqnoPtr(uint32_t* seqnoptr); |
| 555 |
static ALWAYS_INLINE_GFXSTREAM uint32_t nextSeqno(); |
| 556 |
static ALWAYS_INLINE_GFXSTREAM uint32_t getSeqno(); |
| 557 |
|
| 558 |
// Transforms |
| 559 |
void deviceMemoryTransform_tohost(VkDeviceMemory* memory, uint32_t memoryCount, |
| 560 |
VkDeviceSize* offset, uint32_t offsetCount, |
| 561 |
VkDeviceSize* size, uint32_t sizeCount, uint32_t* typeIndex, |
| 562 |
uint32_t typeIndexCount, uint32_t* typeBits, |
| 563 |
uint32_t typeBitsCount); |
| 564 |
void deviceMemoryTransform_fromhost(VkDeviceMemory* memory, uint32_t memoryCount, |
| 565 |
VkDeviceSize* offset, uint32_t offsetCount, |
| 566 |
VkDeviceSize* size, uint32_t sizeCount, uint32_t* typeIndex, |
| 567 |
uint32_t typeIndexCount, uint32_t* typeBits, |
| 568 |
uint32_t typeBitsCount); |
| 569 |
|
| 570 |
void transformImpl_VkExternalMemoryProperties_fromhost(VkExternalMemoryProperties* pProperties, |
| 571 |
uint32_t); |
| 572 |
void transformImpl_VkExternalMemoryProperties_tohost(VkExternalMemoryProperties* pProperties, |
| 573 |
uint32_t); |
| 574 |
void transformImpl_VkImageCreateInfo_fromhost(const VkImageCreateInfo*, uint32_t); |
| 575 |
void transformImpl_VkImageCreateInfo_tohost(const VkImageCreateInfo*, uint32_t); |
| 576 |
|
| 577 |
#define DEFINE_TRANSFORMED_TYPE_PROTOTYPE(type) \ |
| 578 |
void transformImpl_##type##_tohost(type*, uint32_t); \ |
| 579 |
void transformImpl_##type##_fromhost(type*, uint32_t); |
| 580 |
|
| 581 |
LIST_TRIVIAL_TRANSFORMED_TYPES(DEFINE_TRANSFORMED_TYPE_PROTOTYPE) |
| 582 |
|
| 583 |
private: |
| 584 |
VulkanHandleMapping* mCreateMapping = nullptr; |
| 585 |
VulkanHandleMapping* mDestroyMapping = nullptr; |
| 586 |
|
| 587 |
uint32_t getColorBufferMemoryIndex(void* context, VkDevice device); |
| 588 |
const VkPhysicalDeviceMemoryProperties& getPhysicalDeviceMemoryProperties( |
| 589 |
void* context, VkDevice device, VkPhysicalDevice physicalDevice); |
| 590 |
|
| 591 |
void on_vkGetPhysicalDeviceExternalBufferProperties_common( |
| 592 |
bool isKhr, void* context, VkPhysicalDevice physicalDevice, |
| 593 |
const VkPhysicalDeviceExternalBufferInfo* pExternalBufferInfo, |
| 594 |
VkExternalBufferProperties* pExternalBufferProperties); |
| 595 |
|
| 596 |
template <typename VkSubmitInfoType, typename VkSemaphoreInfoType> |
| 597 |
VkResult on_vkQueueSubmitTemplate(void* context, VkResult input_result, VkQueue queue, |
| 598 |
uint32_t submitCount, const VkSubmitInfoType* pSubmits, |
| 599 |
VkFence fence); |
| 600 |
|
| 601 |
void freeDescriptorSetsIfHostAllocated(VkEncoder* enc, VkDevice device, |
| 602 |
uint32_t descriptorSetCount, |
| 603 |
const VkDescriptorSet* sets); |
| 604 |
void clearDescriptorPoolAndUnregisterDescriptorSets(void* context, VkDevice device, |
| 605 |
VkDescriptorPool pool); |
| 606 |
|
| 607 |
void setDeviceInfo(VkDevice device, VkPhysicalDevice physdev, VkPhysicalDeviceProperties props, |
| 608 |
VkPhysicalDeviceMemoryProperties memProps, uint32_t enabledExtensionCount, |
| 609 |
const char* const* ppEnabledExtensionNames, const void* pNext); |
| 610 |
|
| 611 |
void setDeviceMemoryInfo(VkDevice device, VkDeviceMemory memory, VkDeviceSize allocationSize, |
| 612 |
uint8_t* ptr, uint32_t memoryTypeIndex, void* ahw, bool imported, |
| 613 |
zx_handle_t vmoHandle, VirtGpuResourcePtr blobPtr, int importedFd); |
| 614 |
|
| 615 |
void setImageInfo(VkImage image, VkDevice device, const VkImageCreateInfo* pCreateInfo); |
| 616 |
|
| 617 |
bool supportsDeferredCommands() const; |
| 618 |
bool supportsAsyncQueueSubmit() const; |
| 619 |
bool supportsCreateResourcesWithRequirements() const; |
| 620 |
|
| 621 |
int getHostInstanceExtensionIndex(const std::string& extName) const; |
| 622 |
int getHostDeviceExtensionIndex(const std::string& extName) const; |
| 623 |
|
| 624 |
CoherentMemoryPtr createCoherentMemory(VkDevice device, VkDeviceMemory mem, |
| 625 |
const VkMemoryAllocateInfo& hostAllocationInfo, |
| 626 |
VkEncoder* enc, VkResult& res); |
| 627 |
VkResult allocateCoherentMemory(VkDevice device, const VkMemoryAllocateInfo* pAllocateInfo, |
| 628 |
VkEncoder* enc, VkDeviceMemory* pMemory); |
| 629 |
|
| 630 |
VkResult getCoherentMemory(const VkMemoryAllocateInfo* pAllocateInfo, VkEncoder* enc, |
| 631 |
VkDevice device, VkDeviceMemory* pMemory); |
| 632 |
|
| 633 |
void transformImageMemoryRequirements2ForGuest(VkImage image, VkMemoryRequirements2* reqs2); |
| 634 |
|
| 635 |
void transformBufferMemoryRequirements2ForGuest(VkBuffer buffer, VkMemoryRequirements2* reqs2); |
| 636 |
|
| 637 |
void flushCommandBufferPendingCommandsBottomUp(void* context, VkQueue queue, |
| 638 |
const std::vector<VkCommandBuffer>& workingSet); |
| 639 |
|
| 640 |
template <class VkSubmitInfoType> |
| 641 |
void flushStagingStreams(void* context, VkQueue queue, uint32_t submitCount, |
| 642 |
const VkSubmitInfoType* pSubmits); |
| 643 |
|
| 644 |
VkResult vkQueueSubmitEnc(VkEncoder* enc, VkQueue queue, uint32_t submitCount, |
| 645 |
const VkSubmitInfo* pSubmits, VkFence fence); |
| 646 |
|
| 647 |
VkResult vkQueueSubmitEnc(VkEncoder* enc, VkQueue queue, uint32_t submitCount, |
| 648 |
const VkSubmitInfo2* pSubmits, VkFence fence); |
| 649 |
|
| 650 |
VkResult initDescriptorUpdateTemplateBuffers( |
| 651 |
const VkDescriptorUpdateTemplateCreateInfo* pCreateInfo, |
| 652 |
VkDescriptorUpdateTemplate descriptorUpdateTemplate); |
| 653 |
|
| 654 |
#if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 655 |
VkResult exportSyncFdForQSRILocked(VkImage image, int* fd); |
| 656 |
#endif |
| 657 |
|
| 658 |
void setInstanceInfo(VkInstance instance, uint32_t enabledExtensionCount, |
| 659 |
const char* const* ppEnabledExtensionNames, uint32_t apiVersion); |
| 660 |
|
| 661 |
void resetCommandBufferStagingInfo(VkCommandBuffer commandBuffer, bool alsoResetPrimaries, |
| 662 |
bool alsoClearPendingDescriptorSets); |
| 663 |
|
| 664 |
void resetCommandBufferPendingTopology(VkCommandBuffer commandBuffer); |
| 665 |
|
| 666 |
void clearCommandPool(VkCommandPool commandPool); |
| 667 |
|
| 668 |
void ensureSyncDeviceFd(void); |
| 669 |
|
| 670 |
#if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 671 |
void unwrap_VkNativeBufferANDROID(const VkNativeBufferANDROID* inputNativeInfo, |
| 672 |
VkNativeBufferANDROID* outputNativeInfo); |
| 673 |
|
| 674 |
void unwrap_VkBindImageMemorySwapchainInfoKHR( |
| 675 |
const VkBindImageMemorySwapchainInfoKHR* inputBimsi, |
| 676 |
VkBindImageMemorySwapchainInfoKHR* outputBimsi); |
| 677 |
#endif |
| 678 |
|
| 679 |
#if defined(VK_USE_PLATFORM_FUCHSIA) |
| 680 |
VkResult getBufferCollectionImageCreateInfoIndexLocked( |
| 681 |
VkBufferCollectionFUCHSIA collection, fuchsia_sysmem::wire::BufferCollectionInfo2& info, |
| 682 |
uint32_t* outCreateInfoIndex); |
| 683 |
|
| 684 |
SetBufferCollectionImageConstraintsResult setBufferCollectionImageConstraintsImpl( |
| 685 |
VkEncoder* enc, VkDevice device, |
| 686 |
fidl::WireSyncClient<fuchsia_sysmem::BufferCollection>* pCollection, |
| 687 |
const VkImageConstraintsInfoFUCHSIA* pImageConstraintsInfo); |
| 688 |
|
| 689 |
VkResult setBufferCollectionConstraintsFUCHSIA( |
| 690 |
VkEncoder* enc, VkDevice device, |
| 691 |
fidl::WireSyncClient<fuchsia_sysmem::BufferCollection>* collection, |
| 692 |
const VkImageCreateInfo* pImageInfo); |
| 693 |
#endif |
| 694 |
|
| 695 |
#ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 696 |
uint64_t getAHardwareBufferId(AHardwareBuffer* ahw); |
| 697 |
#endif |
| 698 |
|
| 699 |
void unregister_VkDescriptorSet_locked(VkDescriptorSet set); |
| 700 |
|
| 701 |
#define HANDLE_DEFINE_TRIVIAL_INFO_STRUCT(type) \ |
| 702 |
struct type##_Info { \ |
| 703 |
uint32_t unused; \ |
| 704 |
}; |
| 705 |
GOLDFISH_VK_LIST_TRIVIAL_HANDLE_TYPES(HANDLE_DEFINE_TRIVIAL_INFO_STRUCT) |
| 706 |
|
| 707 |
struct VkInstance_Info { |
| 708 |
uint32_t highestApiVersion; |
| 709 |
// Fodder for vkEnumeratePhysicalDevices. |
| 710 |
std::vector<VkPhysicalDevice> physicalDevices; |
| 711 |
}; |
| 712 |
|
| 713 |
struct VkDevice_Info { |
| 714 |
VkPhysicalDevice physdev; |
| 715 |
VkPhysicalDeviceProperties props; |
| 716 |
VkPhysicalDeviceMemoryProperties memProps; |
| 717 |
uint32_t apiVersion; |
| 718 |
std::vector<std::pair<PFN_vkDeviceMemoryReportCallbackEXT, void*>> |
| 719 |
deviceMemoryReportCallbacks; |
| 720 |
}; |
| 721 |
|
| 722 |
struct VkDeviceMemory_Info { |
| 723 |
bool dedicated = false; |
| 724 |
bool imported = false; |
| 725 |
|
| 726 |
#ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 727 |
AHardwareBuffer* ahw = nullptr; |
| 728 |
#endif |
| 729 |
zx_handle_t vmoHandle = ZX_HANDLE_INVALID; |
| 730 |
VkDevice device; |
| 731 |
|
| 732 |
uint8_t* ptr = nullptr; |
| 733 |
|
| 734 |
uint64_t blobId = 0; |
| 735 |
uint64_t allocationSize = 0; |
| 736 |
uint32_t memoryTypeIndex = 0; |
| 737 |
uint64_t coherentMemorySize = 0; |
| 738 |
uint64_t coherentMemoryOffset = 0; |
| 739 |
|
| 740 |
#if DETECT_OS_ANDROID |
| 741 |
GoldfishAddressSpaceBlockPtr goldfishBlock = nullptr; |
| 742 |
#endif // DETECT_OS_ANDROID |
| 743 |
CoherentMemoryPtr coherentMemory = nullptr; |
| 744 |
VirtGpuResourcePtr blobPtr = nullptr; |
| 745 |
int importedFd = -1; |
| 746 |
}; |
| 747 |
|
| 748 |
struct VkCommandBuffer_Info { |
| 749 |
uint32_t placeholder; |
| 750 |
}; |
| 751 |
|
| 752 |
struct VkQueue_Info { |
| 753 |
uint32_t placeholder; |
| 754 |
}; |
| 755 |
|
| 756 |
// custom guest-side structs for images/buffers because of AHardwareBuffer :(( |
| 757 |
struct VkImage_Info { |
| 758 |
VkDevice device; |
| 759 |
VkImageCreateInfo createInfo; |
| 760 |
bool external = false; |
| 761 |
VkExternalMemoryImageCreateInfo externalCreateInfo; |
| 762 |
VkDeviceMemory currentBacking = VK_NULL_HANDLE; |
| 763 |
VkDeviceSize currentBackingOffset = 0; |
| 764 |
VkDeviceSize currentBackingSize = 0; |
| 765 |
bool baseRequirementsKnown = false; |
| 766 |
VkMemoryRequirements baseRequirements; |
| 767 |
#ifdef VK_USE_PLATFORM_ANDROID_KHR |
| 768 |
bool hasExternalFormat = false; |
| 769 |
unsigned externalFourccFormat = 0; |
| 770 |
std::vector<int> pendingQsriSyncFds; |
| 771 |
bool hasAnb = false; |
| 772 |
#endif |
| 773 |
#ifdef VK_USE_PLATFORM_FUCHSIA |
| 774 |
bool isSysmemBackedMemory = false; |
| 775 |
#endif |
| 776 |
}; |
| 777 |
|
| 778 |
struct VkBuffer_Info { |
| 779 |
VkDevice device; |
| 780 |
VkBufferCreateInfo createInfo; |
| 781 |
bool external = false; |
| 782 |
VkExternalMemoryBufferCreateInfo externalCreateInfo; |
| 783 |
VkDeviceMemory currentBacking = VK_NULL_HANDLE; |
| 784 |
VkDeviceSize currentBackingOffset = 0; |
| 785 |
VkDeviceSize currentBackingSize = 0; |
| 786 |
bool baseRequirementsKnown = false; |
| 787 |
VkMemoryRequirements baseRequirements; |
| 788 |
#ifdef VK_USE_PLATFORM_FUCHSIA |
| 789 |
bool isSysmemBackedMemory = false; |
| 790 |
#endif |
| 791 |
}; |
| 792 |
|
| 793 |
struct VkSemaphore_Info { |
| 794 |
VkDevice device; |
| 795 |
zx_handle_t eventHandle = ZX_HANDLE_INVALID; |
| 796 |
zx_koid_t eventKoid = ZX_KOID_INVALID; |
| 797 |
std::optional<int> syncFd = {}; |
| 798 |
}; |
| 799 |
|
| 800 |
struct VkDescriptorUpdateTemplate_Info { |
| 801 |
uint32_t templateEntryCount = 0; |
| 802 |
VkDescriptorUpdateTemplateEntry* templateEntries; |
| 803 |
|
| 804 |
uint32_t imageInfoCount = 0; |
| 805 |
uint32_t bufferInfoCount = 0; |
| 806 |
uint32_t bufferViewCount = 0; |
| 807 |
uint32_t inlineUniformBlockCount = 0; |
| 808 |
uint32_t* imageInfoIndices; |
| 809 |
uint32_t* bufferInfoIndices; |
| 810 |
uint32_t* bufferViewIndices; |
| 811 |
VkDescriptorImageInfo* imageInfos; |
| 812 |
VkDescriptorBufferInfo* bufferInfos; |
| 813 |
VkBufferView* bufferViews; |
| 814 |
std::vector<uint8_t> inlineUniformBlockBuffer; |
| 815 |
std::vector<uint32_t> inlineUniformBlockBytesPerBlocks; // bytes per uniform block |
| 816 |
}; |
| 817 |
|
| 818 |
struct VkFence_Info { |
| 819 |
VkDevice device; |
| 820 |
bool external = false; |
| 821 |
VkExportFenceCreateInfo exportFenceCreateInfo; |
| 822 |
#if defined(VK_USE_PLATFORM_ANDROID_KHR) || DETECT_OS_LINUX |
| 823 |
// Note: -1 means already signaled. |
| 824 |
std::optional<int> syncFd; |
| 825 |
#endif |
| 826 |
}; |
| 827 |
|
| 828 |
struct VkDescriptorPool_Info { |
| 829 |
uint32_t unused; |
| 830 |
}; |
| 831 |
|
| 832 |
struct VkDescriptorSet_Info { |
| 833 |
uint32_t unused; |
| 834 |
}; |
| 835 |
|
| 836 |
struct VkDescriptorSetLayout_Info { |
| 837 |
uint32_t unused; |
| 838 |
}; |
| 839 |
|
| 840 |
struct VkCommandPool_Info { |
| 841 |
uint32_t unused; |
| 842 |
}; |
| 843 |
|
| 844 |
struct VkSampler_Info { |
| 845 |
uint32_t unused; |
| 846 |
}; |
| 847 |
|
| 848 |
struct VkPrivateDataSlot_Info { |
| 849 |
// We need special handling for device memory and swapchain object types for private data |
| 850 |
// management. For memory, we can use a single handle on the host side, so setting a |
| 851 |
// private data slot for guest handle can also set any other data set previously. |
| 852 |
// For swapchains, we don't actually get create/destroy calls to keep track of object |
| 853 |
// handles to be able to pass the call to the underlying host driver. Rather than handling |
| 854 |
// the 2 cases separately, we handle all the private data management directly here with a |
| 855 |
// single table, so vkSetPrivateData and vkGetPrivateData calls don't need to be encoded for |
| 856 |
// the host. |
| 857 |
typedef std::pair<uint64_t, VkObjectType> PrivateDataKey; |
| 858 |
struct PrivateDataKeyHash { |
| 859 |
template <class T1, class T2> |
| 860 |
std::size_t operator()(const std::pair<T1, T2>& p) const { |
| 861 |
std::size_t h1 = std::hash<T1>{}(p.first); |
| 862 |
std::size_t h2 = std::hash<T2>{}(p.second); |
| 863 |
return h1 ^ h2; |
| 864 |
} |
| 865 |
}; |
| 866 |
|
| 867 |
std::unordered_map<PrivateDataKey, uint64_t, PrivateDataKeyHash> privateDataTable; |
| 868 |
}; |
| 869 |
|
| 870 |
struct VkBufferCollectionFUCHSIA_Info { |
| 871 |
#ifdef VK_USE_PLATFORM_FUCHSIA |
| 872 |
std::optional<fuchsia_sysmem::wire::BufferCollectionConstraints> constraints; |
| 873 |
std::optional<VkBufferCollectionPropertiesFUCHSIA> properties; |
| 874 |
|
| 875 |
// the index of corresponding createInfo for each image format |
| 876 |
// constraints in |constraints|. |
| 877 |
std::vector<uint32_t> createInfoIndex; |
| 878 |
#endif // VK_USE_PLATFORM_FUCHSIA |
| 879 |
}; |
| 880 |
|
| 881 |
VkDescriptorImageInfo filterNonexistentSampler(const VkDescriptorImageInfo& inputInfo); |
| 882 |
|
| 883 |
void emitDeviceMemoryReport(VkDevice_Info info, VkDeviceMemoryReportEventTypeEXT type, |
| 884 |
uint64_t memoryObjectId, VkDeviceSize size, VkObjectType objectType, |
| 885 |
uint64_t objectHandle, uint32_t heapIndex = 0); |
| 886 |
|
| 887 |
void transformImageMemoryRequirementsForGuestLocked(VkImage image, VkMemoryRequirements* reqs); |
| 888 |
CoherentMemoryPtr freeCoherentMemoryLocked(VkDeviceMemory memory, VkDeviceMemory_Info& info); |
| 889 |
|
| 890 |
void EmitGuestAndHostTraceMarker(VkEncoder* encoder); |
| 891 |
|
| 892 |
void sendGuestInfo(VkEncoder* encoder); |
| 893 |
|
| 894 |
std::recursive_mutex mLock; |
| 895 |
|
| 896 |
std::optional<const VkPhysicalDeviceMemoryProperties> mCachedPhysicalDeviceMemoryProps; |
| 897 |
|
| 898 |
struct GfxStreamVkFeatureInfo mFeatureInfo = {}; |
| 899 |
|
| 900 |
#if DETECT_OS_ANDROID |
| 901 |
std::unique_ptr<GoldfishAddressSpaceBlockProvider> mGoldfishAddressSpaceBlockProvider; |
| 902 |
#endif // DETECT_OS_ANDROID |
| 903 |
|
| 904 |
#if defined(VK_USE_PLATFORM_ANDROID_KHR) |
| 905 |
std::unique_ptr<gfxstream::Gralloc> mGralloc = nullptr; |
| 906 |
#endif |
| 907 |
|
| 908 |
std::unique_ptr<gfxstream::SyncHelper> mSyncHelper = nullptr; |
| 909 |
|
| 910 |
struct VirtGpuCaps mCaps = {}; |
| 911 |
std::vector<VkExtensionProperties> mHostInstanceExtensions; |
| 912 |
std::vector<VkExtensionProperties> mHostDeviceExtensions; |
| 913 |
|
| 914 |
// 32 bits only for now, upper bits may be used later. |
| 915 |
std::atomic<uint32_t> mAtomicId = 0; |
| 916 |
#if defined(VK_USE_PLATFORM_ANDROID_KHR) || DETECT_OS_LINUX |
| 917 |
int mSyncDeviceFd = -1; |
| 918 |
#endif |
| 919 |
|
| 920 |
#ifdef VK_USE_PLATFORM_FUCHSIA |
| 921 |
fidl::WireSyncClient<fuchsia_hardware_goldfish::ControlDevice> mControlDevice; |
| 922 |
fidl::WireSyncClient<fuchsia_sysmem::Allocator> mSysmemAllocator; |
| 923 |
#endif |
| 924 |
|
| 925 |
#define HANDLE_REGISTER_DECLARATION(type) std::unordered_map<type, type##_Info> info_##type; |
| 926 |
|
| 927 |
GOLDFISH_VK_LIST_HANDLE_TYPES(HANDLE_REGISTER_DECLARATION) |
| 928 |
|
| 929 |
std::unordered_map<const VkEncoder*, std::unordered_map<void*, CleanupCallback>> |
| 930 |
mEncoderCleanupCallbacks; |
| 931 |
}; |
| 932 |
|
| 933 |
} // namespace vk |
| 934 |
} // namespace gfxstream |