61b1de59d7f7edba95419b4cb3035e661849a47a
[mesa.git] / src / vulkan / wsi / wsi_common.h
1 /*
2 * Copyright © 2015 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23 #ifndef WSI_COMMON_H
24 #define WSI_COMMON_H
25
26 #include <stdint.h>
27 #include <stdbool.h>
28
29 #include "vk_alloc.h"
30 #include <vulkan/vulkan.h>
31 #include <vulkan/vk_icd.h>
32
33 /* This is guaranteed to not collide with anything because it's in the
34 * VK_KHR_swapchain namespace but not actually used by the extension.
35 */
36 #define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
37 #define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
38 #define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004
39
40 struct wsi_image_create_info {
41 VkStructureType sType;
42 const void *pNext;
43 bool scanout;
44
45 uint32_t modifier_count;
46 const uint64_t *modifiers;
47 };
48
49 struct wsi_memory_allocate_info {
50 VkStructureType sType;
51 const void *pNext;
52 bool implicit_sync;
53 };
54
55 struct wsi_format_modifier_properties {
56 uint64_t modifier;
57 uint32_t modifier_plane_count;
58 };
59
60 /* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
61 struct wsi_format_modifier_properties_list {
62 VkStructureType sType;
63 const void *pNext;
64
65 uint32_t modifier_count;
66 struct wsi_format_modifier_properties *modifier_properties;
67 };
68
69 struct wsi_interface;
70
71 #define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
72
73 struct wsi_device {
74 VkPhysicalDevice pdevice;
75 VkPhysicalDeviceMemoryProperties memory_props;
76 uint32_t queue_family_count;
77
78 bool supports_modifiers;
79 uint64_t (*image_get_modifier)(VkImage image);
80
81 #define WSI_CB(cb) PFN_vk##cb cb
82 WSI_CB(AllocateMemory);
83 WSI_CB(AllocateCommandBuffers);
84 WSI_CB(BindBufferMemory);
85 WSI_CB(BindImageMemory);
86 WSI_CB(BeginCommandBuffer);
87 WSI_CB(CmdCopyImageToBuffer);
88 WSI_CB(CreateBuffer);
89 WSI_CB(CreateCommandPool);
90 WSI_CB(CreateFence);
91 WSI_CB(CreateImage);
92 WSI_CB(DestroyBuffer);
93 WSI_CB(DestroyCommandPool);
94 WSI_CB(DestroyFence);
95 WSI_CB(DestroyImage);
96 WSI_CB(EndCommandBuffer);
97 WSI_CB(FreeMemory);
98 WSI_CB(FreeCommandBuffers);
99 WSI_CB(GetBufferMemoryRequirements);
100 WSI_CB(GetImageMemoryRequirements);
101 WSI_CB(GetImageSubresourceLayout);
102 WSI_CB(GetMemoryFdKHR);
103 WSI_CB(GetPhysicalDeviceFormatProperties);
104 WSI_CB(GetPhysicalDeviceFormatProperties2KHR);
105 WSI_CB(ResetFences);
106 WSI_CB(QueueSubmit);
107 WSI_CB(WaitForFences);
108 #undef WSI_CB
109
110 struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
111 };
112
113 typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
114
115 VkResult
116 wsi_device_init(struct wsi_device *wsi,
117 VkPhysicalDevice pdevice,
118 WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
119 const VkAllocationCallbacks *alloc,
120 int display_fd);
121
122 void
123 wsi_device_finish(struct wsi_device *wsi,
124 const VkAllocationCallbacks *alloc);
125
126 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
127 \
128 static inline __VkIcdType * \
129 __VkIcdType ## _from_handle(__VkType _handle) \
130 { \
131 return (__VkIcdType *)(uintptr_t) _handle; \
132 } \
133 \
134 static inline __VkType \
135 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
136 { \
137 return (__VkType)(uintptr_t) _obj; \
138 }
139
140 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
141 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
142
143 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
144
145 VkResult
146 wsi_common_get_surface_support(struct wsi_device *wsi_device,
147 int local_fd,
148 uint32_t queueFamilyIndex,
149 VkSurfaceKHR surface,
150 const VkAllocationCallbacks *alloc,
151 VkBool32* pSupported);
152
153 VkResult
154 wsi_common_get_surface_capabilities(struct wsi_device *wsi_device,
155 VkSurfaceKHR surface,
156 VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
157
158 VkResult
159 wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,
160 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
161 VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
162
163 VkResult
164 wsi_common_get_surface_formats(struct wsi_device *wsi_device,
165 VkSurfaceKHR surface,
166 uint32_t *pSurfaceFormatCount,
167 VkSurfaceFormatKHR *pSurfaceFormats);
168
169 VkResult
170 wsi_common_get_surface_formats2(struct wsi_device *wsi_device,
171 const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
172 uint32_t *pSurfaceFormatCount,
173 VkSurfaceFormat2KHR *pSurfaceFormats);
174
175 VkResult
176 wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
177 VkSurfaceKHR surface,
178 uint32_t *pPresentModeCount,
179 VkPresentModeKHR *pPresentModes);
180
181 VkResult
182 wsi_common_get_images(VkSwapchainKHR _swapchain,
183 uint32_t *pSwapchainImageCount,
184 VkImage *pSwapchainImages);
185
186 VkResult
187 wsi_common_acquire_next_image(const struct wsi_device *wsi,
188 VkDevice device,
189 VkSwapchainKHR swapchain,
190 uint64_t timeout,
191 VkSemaphore semaphore,
192 uint32_t *pImageIndex);
193
194 VkResult
195 wsi_common_create_swapchain(struct wsi_device *wsi,
196 VkDevice device,
197 int fd,
198 const VkSwapchainCreateInfoKHR *pCreateInfo,
199 const VkAllocationCallbacks *pAllocator,
200 VkSwapchainKHR *pSwapchain);
201 void
202 wsi_common_destroy_swapchain(VkDevice device,
203 VkSwapchainKHR swapchain,
204 const VkAllocationCallbacks *pAllocator);
205
206 VkResult
207 wsi_common_queue_present(const struct wsi_device *wsi,
208 VkDevice device_h,
209 VkQueue queue_h,
210 int queue_family_index,
211 const VkPresentInfoKHR *pPresentInfo);
212
213 #endif