| 1 |
/* |
| 2 |
* Copyright 2018 Google |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
#pragma once |
| 6 |
#include "util/detect_os.h" |
| 7 |
|
| 8 |
#if DETECT_OS_ANDROID |
| 9 |
#include <hardware/hwvulkan.h> |
| 10 |
#elif DETECT_OS_LINUX |
| 11 |
#include <vulkan/vk_icd.h> |
| 12 |
#endif |
| 13 |
#include <inttypes.h> |
| 14 |
#include <vulkan/vulkan.h> |
| 15 |
|
| 16 |
#include <functional> |
| 17 |
|
| 18 |
#include "VulkanHandles.h" |
| 19 |
|
| 20 |
namespace gfxstream { |
| 21 |
namespace guest { |
| 22 |
class IOStream; |
| 23 |
} // namespace guest |
| 24 |
} // namespace gfxstream |
| 25 |
|
| 26 |
namespace gfxstream { |
| 27 |
namespace vk { |
| 28 |
class VkEncoder; |
| 29 |
struct DescriptorPoolAllocationInfo; |
| 30 |
struct ReifiedDescriptorSet; |
| 31 |
struct DescriptorSetLayoutInfo; |
| 32 |
} // namespace vk |
| 33 |
} // namespace gfxstream |
| 34 |
|
| 35 |
extern "C" { |
| 36 |
|
| 37 |
struct goldfish_vk_object_list { |
| 38 |
void* obj; |
| 39 |
struct goldfish_vk_object_list* next; |
| 40 |
}; |
| 41 |
|
| 42 |
#if DETECT_OS_ANDROID |
| 43 |
#define DECLARE_HWVULKAN_DISPATCH hwvulkan_dispatch_t dispatch; |
| 44 |
#elif DETECT_OS_LINUX |
| 45 |
#define DECLARE_HWVULKAN_DISPATCH VK_LOADER_DATA loaderData; |
| 46 |
#else |
| 47 |
#define DECLARE_HWVULKAN_DISPATCH |
| 48 |
#endif |
| 49 |
|
| 50 |
#define GOLDFISH_VK_DEFINE_DISPATCHABLE_HANDLE_STRUCT(type) \ |
| 51 |
struct goldfish_##type { \ |
| 52 |
DECLARE_HWVULKAN_DISPATCH \ |
| 53 |
uint64_t underlying; \ |
| 54 |
gfxstream::vk::VkEncoder* lastUsedEncoder; \ |
| 55 |
uint32_t sequenceNumber; \ |
| 56 |
gfxstream::vk::VkEncoder* privateEncoder; \ |
| 57 |
gfxstream::guest::IOStream* privateStream; \ |
| 58 |
uint32_t flags; \ |
| 59 |
struct goldfish_vk_object_list* poolObjects; \ |
| 60 |
struct goldfish_vk_object_list* subObjects; \ |
| 61 |
struct goldfish_vk_object_list* superObjects; \ |
| 62 |
void* userPtr; \ |
| 63 |
}; |
| 64 |
|
| 65 |
#define GOLDFISH_VK_DEFINE_TRIVIAL_NON_DISPATCHABLE_HANDLE_STRUCT(type) \ |
| 66 |
struct goldfish_##type { \ |
| 67 |
uint64_t underlying; \ |
| 68 |
struct goldfish_vk_object_list* poolObjects; \ |
| 69 |
struct goldfish_vk_object_list* subObjects; \ |
| 70 |
struct goldfish_vk_object_list* superObjects; \ |
| 71 |
void* userPtr; \ |
| 72 |
}; |
| 73 |
|
| 74 |
#define GOLDFISH_VK_NEW_FROM_HOST_DECL(type) type new_from_host_##type(type); |
| 75 |
|
| 76 |
#define GOLDFISH_VK_AS_GOLDFISH_DECL(type) struct goldfish_##type* as_goldfish_##type(type); |
| 77 |
|
| 78 |
#define GOLDFISH_VK_GET_HOST_DECL(type) type get_host_##type(type); |
| 79 |
|
| 80 |
#define GOLDFISH_VK_DELETE_GOLDFISH_DECL(type) void delete_goldfish_##type(type); |
| 81 |
|
| 82 |
#define GOLDFISH_VK_IDENTITY_DECL(type) type vk_handle_identity_##type(type); |
| 83 |
|
| 84 |
#define GOLDFISH_VK_NEW_FROM_HOST_U64_DECL(type) type new_from_host_u64_##type(uint64_t); |
| 85 |
|
| 86 |
#define GOLDFISH_VK_GET_HOST_U64_DECL(type) uint64_t get_host_u64_##type(type); |
| 87 |
|
| 88 |
GOLDFISH_VK_LIST_AUTODEFINED_STRUCT_DISPATCHABLE_HANDLE_TYPES( |
| 89 |
GOLDFISH_VK_DEFINE_DISPATCHABLE_HANDLE_STRUCT) |
| 90 |
GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_NEW_FROM_HOST_DECL) |
| 91 |
GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_AS_GOLDFISH_DECL) |
| 92 |
GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_GET_HOST_DECL) |
| 93 |
GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_DELETE_GOLDFISH_DECL) |
| 94 |
GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_IDENTITY_DECL) |
| 95 |
GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_NEW_FROM_HOST_U64_DECL) |
| 96 |
GOLDFISH_VK_LIST_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_GET_HOST_U64_DECL) |
| 97 |
|
| 98 |
GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_NEW_FROM_HOST_DECL) |
| 99 |
GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_AS_GOLDFISH_DECL) |
| 100 |
GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_GET_HOST_DECL) |
| 101 |
GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_DELETE_GOLDFISH_DECL) |
| 102 |
GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_IDENTITY_DECL) |
| 103 |
GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_NEW_FROM_HOST_U64_DECL) |
| 104 |
GOLDFISH_VK_LIST_NON_DISPATCHABLE_HANDLE_TYPES(GOLDFISH_VK_GET_HOST_U64_DECL) |
| 105 |
GOLDFISH_VK_LIST_AUTODEFINED_STRUCT_NON_DISPATCHABLE_HANDLE_TYPES( |
| 106 |
GOLDFISH_VK_DEFINE_TRIVIAL_NON_DISPATCHABLE_HANDLE_STRUCT) |
| 107 |
|
| 108 |
struct goldfish_VkDescriptorPool { |
| 109 |
uint64_t underlying; |
| 110 |
gfxstream::vk::DescriptorPoolAllocationInfo* allocInfo; |
| 111 |
}; |
| 112 |
|
| 113 |
struct goldfish_VkDescriptorSet { |
| 114 |
uint64_t underlying; |
| 115 |
gfxstream::vk::ReifiedDescriptorSet* reified; |
| 116 |
}; |
| 117 |
|
| 118 |
struct goldfish_VkDescriptorSetLayout { |
| 119 |
uint64_t underlying; |
| 120 |
gfxstream::vk::DescriptorSetLayoutInfo* layoutInfo; |
| 121 |
}; |
| 122 |
|
| 123 |
struct goldfish_VkCommandBuffer { |
| 124 |
DECLARE_HWVULKAN_DISPATCH |
| 125 |
uint64_t underlying; |
| 126 |
gfxstream::vk::VkEncoder* lastUsedEncoder; |
| 127 |
uint32_t sequenceNumber; |
| 128 |
gfxstream::vk::VkEncoder* privateEncoder; |
| 129 |
gfxstream::guest::IOStream* privateStream; |
| 130 |
uint32_t flags; |
| 131 |
struct goldfish_vk_object_list* poolObjects; |
| 132 |
struct goldfish_vk_object_list* subObjects; |
| 133 |
struct goldfish_vk_object_list* superObjects; |
| 134 |
void* userPtr; |
| 135 |
bool isSecondary; |
| 136 |
VkDevice device; |
| 137 |
}; |
| 138 |
|
| 139 |
} // extern "C" |
| 140 |
|
| 141 |
namespace gfxstream { |
| 142 |
namespace vk { |
| 143 |
|
| 144 |
void appendObject(struct goldfish_vk_object_list** begin, void* val); |
| 145 |
void eraseObject(struct goldfish_vk_object_list** begin, void* val); |
| 146 |
void eraseObjects(struct goldfish_vk_object_list** begin); |
| 147 |
void forAllObjects(struct goldfish_vk_object_list* begin, std::function<void(void*)> func); |
| 148 |
|
| 149 |
} // namespace vk |
| 150 |
} // namespace gfxstream |