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