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