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