2 * Copyright © 2015 Intel Corporation
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:
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
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
30 #include <vulkan/vulkan.h>
31 #include <vulkan/vk_icd.h>
35 VkDeviceMemory memory
;
43 struct wsi_image_fns
{
44 VkResult (*create_wsi_image
)(VkDevice device_h
,
45 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
46 const VkAllocationCallbacks
*pAllocator
,
47 bool needs_linear_copy
,
49 struct wsi_image
*image_p
);
50 void (*free_wsi_image
)(VkDevice device
,
51 const VkAllocationCallbacks
*pAllocator
,
52 struct wsi_image
*image
);
55 struct wsi_swapchain
{
56 const struct wsi_device
*wsi
;
59 VkAllocationCallbacks alloc
;
60 const struct wsi_image_fns
*image_fns
;
62 VkCommandBuffer
*cmd_buffers
;
63 VkCommandPool cmd_pools
[3];
64 VkPresentModeKHR present_mode
;
66 bool needs_linear_copy
;
68 VkResult (*destroy
)(struct wsi_swapchain
*swapchain
,
69 const VkAllocationCallbacks
*pAllocator
);
70 VkResult (*get_images
)(struct wsi_swapchain
*swapchain
,
71 uint32_t *pCount
, VkImage
*pSwapchainImages
);
72 VkResult (*acquire_next_image
)(struct wsi_swapchain
*swap_chain
,
73 uint64_t timeout
, VkSemaphore semaphore
,
74 uint32_t *image_index
);
75 VkResult (*queue_present
)(struct wsi_swapchain
*swap_chain
,
77 const VkPresentRegionKHR
*damage
);
78 void (*get_image_and_linear
)(struct wsi_swapchain
*swapchain
,
81 VkImage
*linear_image
);
84 struct wsi_interface
{
85 VkResult (*get_support
)(VkIcdSurfaceBase
*surface
,
86 struct wsi_device
*wsi_device
,
87 const VkAllocationCallbacks
*alloc
,
88 uint32_t queueFamilyIndex
,
90 bool can_handle_different_gpu
,
91 VkBool32
* pSupported
);
92 VkResult (*get_capabilities
)(VkIcdSurfaceBase
*surface
,
93 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
);
94 VkResult (*get_capabilities2
)(VkIcdSurfaceBase
*surface
,
95 const void *info_next
,
96 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
);
97 VkResult (*get_formats
)(VkIcdSurfaceBase
*surface
,
98 struct wsi_device
*wsi_device
,
99 uint32_t* pSurfaceFormatCount
,
100 VkSurfaceFormatKHR
* pSurfaceFormats
);
101 VkResult (*get_formats2
)(VkIcdSurfaceBase
*surface
,
102 struct wsi_device
*wsi_device
,
103 const void *info_next
,
104 uint32_t* pSurfaceFormatCount
,
105 VkSurfaceFormat2KHR
* pSurfaceFormats
);
106 VkResult (*get_present_modes
)(VkIcdSurfaceBase
*surface
,
107 uint32_t* pPresentModeCount
,
108 VkPresentModeKHR
* pPresentModes
);
109 VkResult (*create_swapchain
)(VkIcdSurfaceBase
*surface
,
111 struct wsi_device
*wsi_device
,
113 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
114 const VkAllocationCallbacks
* pAllocator
,
115 const struct wsi_image_fns
*image_fns
,
116 struct wsi_swapchain
**swapchain
);
119 #define VK_ICD_WSI_PLATFORM_MAX 5
122 struct wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
125 typedef PFN_vkVoidFunction (VKAPI_PTR
*WSI_FN_GetPhysicalDeviceProcAddr
)(VkPhysicalDevice physicalDevice
, const char* pName
);
128 wsi_device_init(struct wsi_device
*wsi
,
129 VkPhysicalDevice pdevice
,
130 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
);
132 #define WSI_CB(cb) PFN_vk##cb cb
133 struct wsi_callbacks
{
134 WSI_CB(GetPhysicalDeviceFormatProperties
);
138 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
140 static inline struct __wsi_type * \
141 __wsi_type ## _from_handle(__VkType _handle) \
143 return (struct __wsi_type *)(uintptr_t) _handle; \
146 static inline __VkType \
147 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
149 return (__VkType)(uintptr_t) _obj; \
152 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain
, VkSwapchainKHR
)
154 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
156 static inline __VkIcdType * \
157 __VkIcdType ## _from_handle(__VkType _handle) \
159 return (__VkIcdType *)(uintptr_t) _handle; \
162 static inline __VkType \
163 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
165 return (__VkType)(uintptr_t) _obj; \
168 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
169 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
171 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase
, VkSurfaceKHR
)
173 VkResult
wsi_x11_init_wsi(struct wsi_device
*wsi_device
,
174 const VkAllocationCallbacks
*alloc
);
175 void wsi_x11_finish_wsi(struct wsi_device
*wsi_device
,
176 const VkAllocationCallbacks
*alloc
);
177 VkResult
wsi_wl_init_wsi(struct wsi_device
*wsi_device
,
178 const VkAllocationCallbacks
*alloc
,
179 VkPhysicalDevice physical_device
,
180 const struct wsi_callbacks
*cbs
);
181 void wsi_wl_finish_wsi(struct wsi_device
*wsi_device
,
182 const VkAllocationCallbacks
*alloc
);