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>
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.
36 #define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
37 #define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
39 struct wsi_image_create_info
{
40 VkStructureType sType
;
45 struct wsi_memory_allocate_info
{
46 VkStructureType sType
;
53 struct wsi_swapchain
{
54 const struct wsi_device
*wsi
;
57 VkAllocationCallbacks alloc
;
59 VkPresentModeKHR present_mode
;
62 /* Command pools, one per queue family */
63 VkCommandPool
*cmd_pools
;
65 VkResult (*destroy
)(struct wsi_swapchain
*swapchain
,
66 const VkAllocationCallbacks
*pAllocator
);
67 struct wsi_image
*(*get_wsi_image
)(struct wsi_swapchain
*swapchain
,
68 uint32_t image_index
);
69 VkResult (*acquire_next_image
)(struct wsi_swapchain
*swap_chain
,
70 uint64_t timeout
, VkSemaphore semaphore
,
71 uint32_t *image_index
);
72 VkResult (*queue_present
)(struct wsi_swapchain
*swap_chain
,
74 uint32_t waitSemaphoreCount
,
75 const VkSemaphore
*pWaitSemaphores
,
77 const VkPresentRegionKHR
*damage
);
80 struct wsi_interface
{
81 VkResult (*get_support
)(VkIcdSurfaceBase
*surface
,
82 struct wsi_device
*wsi_device
,
83 const VkAllocationCallbacks
*alloc
,
84 uint32_t queueFamilyIndex
,
86 bool can_handle_different_gpu
,
87 VkBool32
* pSupported
);
88 VkResult (*get_capabilities
)(VkIcdSurfaceBase
*surface
,
89 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
);
90 VkResult (*get_capabilities2
)(VkIcdSurfaceBase
*surface
,
91 const void *info_next
,
92 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
);
93 VkResult (*get_formats
)(VkIcdSurfaceBase
*surface
,
94 struct wsi_device
*wsi_device
,
95 uint32_t* pSurfaceFormatCount
,
96 VkSurfaceFormatKHR
* pSurfaceFormats
);
97 VkResult (*get_formats2
)(VkIcdSurfaceBase
*surface
,
98 struct wsi_device
*wsi_device
,
99 const void *info_next
,
100 uint32_t* pSurfaceFormatCount
,
101 VkSurfaceFormat2KHR
* pSurfaceFormats
);
102 VkResult (*get_present_modes
)(VkIcdSurfaceBase
*surface
,
103 uint32_t* pPresentModeCount
,
104 VkPresentModeKHR
* pPresentModes
);
105 VkResult (*create_swapchain
)(VkIcdSurfaceBase
*surface
,
107 struct wsi_device
*wsi_device
,
109 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
110 const VkAllocationCallbacks
* pAllocator
,
111 struct wsi_swapchain
**swapchain
);
114 #define VK_ICD_WSI_PLATFORM_MAX 5
117 VkPhysicalDeviceMemoryProperties memory_props
;
118 uint32_t queue_family_count
;
120 uint32_t (*queue_get_family_index
)(VkQueue queue
);
122 #define WSI_CB(cb) PFN_vk##cb cb
123 WSI_CB(AllocateMemory
);
124 WSI_CB(AllocateCommandBuffers
);
125 WSI_CB(BindBufferMemory
);
126 WSI_CB(BindImageMemory
);
127 WSI_CB(BeginCommandBuffer
);
128 WSI_CB(CmdCopyImageToBuffer
);
129 WSI_CB(CreateBuffer
);
130 WSI_CB(CreateCommandPool
);
133 WSI_CB(DestroyBuffer
);
134 WSI_CB(DestroyCommandPool
);
135 WSI_CB(DestroyFence
);
136 WSI_CB(DestroyImage
);
137 WSI_CB(EndCommandBuffer
);
139 WSI_CB(FreeCommandBuffers
);
140 WSI_CB(GetBufferMemoryRequirements
);
141 WSI_CB(GetImageMemoryRequirements
);
142 WSI_CB(GetImageSubresourceLayout
);
143 WSI_CB(GetMemoryFdKHR
);
146 WSI_CB(WaitForFences
);
149 struct wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
152 typedef PFN_vkVoidFunction (VKAPI_PTR
*WSI_FN_GetPhysicalDeviceProcAddr
)(VkPhysicalDevice physicalDevice
, const char* pName
);
155 wsi_device_init(struct wsi_device
*wsi
,
156 VkPhysicalDevice pdevice
,
157 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
);
159 #define WSI_CB(cb) PFN_vk##cb cb
160 struct wsi_callbacks
{
161 VkPhysicalDevice (*device_get_physical
)(VkDevice
);
163 WSI_CB(GetDeviceProcAddr
);
164 WSI_CB(GetPhysicalDeviceFormatProperties
);
165 WSI_CB(GetPhysicalDeviceMemoryProperties
);
166 WSI_CB(GetPhysicalDeviceQueueFamilyProperties
);
170 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
172 static inline struct __wsi_type * \
173 __wsi_type ## _from_handle(__VkType _handle) \
175 return (struct __wsi_type *)(uintptr_t) _handle; \
178 static inline __VkType \
179 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
181 return (__VkType)(uintptr_t) _obj; \
184 #define WSI_FROM_HANDLE(__wsi_type, __name, __handle) \
185 struct __wsi_type *__name = __wsi_type ## _from_handle(__handle)
187 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain
, VkSwapchainKHR
)
189 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
191 static inline __VkIcdType * \
192 __VkIcdType ## _from_handle(__VkType _handle) \
194 return (__VkIcdType *)(uintptr_t) _handle; \
197 static inline __VkType \
198 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
200 return (__VkType)(uintptr_t) _obj; \
203 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
204 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
206 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase
, VkSurfaceKHR
)
208 VkResult
wsi_x11_init_wsi(struct wsi_device
*wsi_device
,
209 const VkAllocationCallbacks
*alloc
);
210 void wsi_x11_finish_wsi(struct wsi_device
*wsi_device
,
211 const VkAllocationCallbacks
*alloc
);
212 VkResult
wsi_wl_init_wsi(struct wsi_device
*wsi_device
,
213 const VkAllocationCallbacks
*alloc
,
214 VkPhysicalDevice physical_device
,
215 const struct wsi_callbacks
*cbs
);
216 void wsi_wl_finish_wsi(struct wsi_device
*wsi_device
,
217 const VkAllocationCallbacks
*alloc
);
220 wsi_common_get_images(VkSwapchainKHR _swapchain
,
221 uint32_t *pSwapchainImageCount
,
222 VkImage
*pSwapchainImages
);
225 wsi_common_queue_present(const struct wsi_device
*wsi
,
228 int queue_family_index
,
229 const VkPresentInfoKHR
*pPresentInfo
);