vulkan/wsi/x11: add support to detect if we can support rendering (v3)
[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 "util/vk_alloc.h"
30 #include <vulkan/vulkan.h>
31 #include <vulkan/vk_icd.h>
32
33 struct wsi_device;
34 struct wsi_image_fns {
35 VkResult (*create_wsi_image)(VkDevice device_h,
36 const VkSwapchainCreateInfoKHR *pCreateInfo,
37 const VkAllocationCallbacks *pAllocator,
38 VkImage *image_p,
39 VkDeviceMemory *memory_p,
40 uint32_t *size_p,
41 uint32_t *offset_p,
42 uint32_t *row_pitch_p,
43 int *fd_p);
44 void (*free_wsi_image)(VkDevice device,
45 const VkAllocationCallbacks *pAllocator,
46 VkImage image_h,
47 VkDeviceMemory memory_h);
48 };
49
50 struct wsi_swapchain {
51
52 VkDevice device;
53 VkAllocationCallbacks alloc;
54 const struct wsi_image_fns *image_fns;
55 VkFence fences[3];
56 VkPresentModeKHR present_mode;
57
58 VkResult (*destroy)(struct wsi_swapchain *swapchain,
59 const VkAllocationCallbacks *pAllocator);
60 VkResult (*get_images)(struct wsi_swapchain *swapchain,
61 uint32_t *pCount, VkImage *pSwapchainImages);
62 VkResult (*acquire_next_image)(struct wsi_swapchain *swap_chain,
63 uint64_t timeout, VkSemaphore semaphore,
64 uint32_t *image_index);
65 VkResult (*queue_present)(struct wsi_swapchain *swap_chain,
66 uint32_t image_index);
67 };
68
69 struct wsi_interface {
70 VkResult (*get_support)(VkIcdSurfaceBase *surface,
71 struct wsi_device *wsi_device,
72 const VkAllocationCallbacks *alloc,
73 uint32_t queueFamilyIndex,
74 int local_fd,
75 VkBool32* pSupported);
76 VkResult (*get_capabilities)(VkIcdSurfaceBase *surface,
77 VkSurfaceCapabilitiesKHR* pSurfaceCapabilities);
78 VkResult (*get_formats)(VkIcdSurfaceBase *surface,
79 struct wsi_device *wsi_device,
80 uint32_t* pSurfaceFormatCount,
81 VkSurfaceFormatKHR* pSurfaceFormats);
82 VkResult (*get_present_modes)(VkIcdSurfaceBase *surface,
83 uint32_t* pPresentModeCount,
84 VkPresentModeKHR* pPresentModes);
85 VkResult (*create_swapchain)(VkIcdSurfaceBase *surface,
86 VkDevice device,
87 struct wsi_device *wsi_device,
88 const VkSwapchainCreateInfoKHR* pCreateInfo,
89 const VkAllocationCallbacks* pAllocator,
90 const struct wsi_image_fns *image_fns,
91 struct wsi_swapchain **swapchain);
92 };
93
94 #define VK_ICD_WSI_PLATFORM_MAX 5
95
96 struct wsi_device {
97 struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
98 };
99
100 struct wsi_callbacks {
101 void (*get_phys_device_format_properties)(VkPhysicalDevice physicalDevice,
102 VkFormat format,
103 VkFormatProperties *pFormatProperties);
104 };
105
106 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
107 \
108 static inline struct __wsi_type * \
109 __wsi_type ## _from_handle(__VkType _handle) \
110 { \
111 return (struct __wsi_type *)(uintptr_t) _handle; \
112 } \
113 \
114 static inline __VkType \
115 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
116 { \
117 return (__VkType)(uintptr_t) _obj; \
118 }
119
120 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain, VkSwapchainKHR)
121
122 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
123 \
124 static inline __VkIcdType * \
125 __VkIcdType ## _from_handle(__VkType _handle) \
126 { \
127 return (__VkIcdType *)(uintptr_t) _handle; \
128 } \
129 \
130 static inline __VkType \
131 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
132 { \
133 return (__VkType)(uintptr_t) _obj; \
134 }
135
136 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
137 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
138
139 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
140
141 VkResult wsi_x11_init_wsi(struct wsi_device *wsi_device,
142 const VkAllocationCallbacks *alloc);
143 void wsi_x11_finish_wsi(struct wsi_device *wsi_device,
144 const VkAllocationCallbacks *alloc);
145 VkResult wsi_wl_init_wsi(struct wsi_device *wsi_device,
146 const VkAllocationCallbacks *alloc,
147 VkPhysicalDevice physical_device,
148 const struct wsi_callbacks *cbs);
149 void wsi_wl_finish_wsi(struct wsi_device *wsi_device,
150 const VkAllocationCallbacks *alloc);
151
152
153 #endif