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 VkDeviceMemory memory
;
57 VkDeviceMemory memory
;
58 VkCommandBuffer
*blit_cmd_buffers
;
68 struct wsi_image_fns
{
69 VkResult (*create_wsi_image
)(VkDevice device_h
,
70 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
71 const VkAllocationCallbacks
*pAllocator
,
72 struct wsi_image
*image_p
);
73 void (*free_wsi_image
)(VkDevice device
,
74 const VkAllocationCallbacks
*pAllocator
,
75 struct wsi_image
*image
);
78 struct wsi_swapchain
{
79 const struct wsi_device
*wsi
;
82 VkAllocationCallbacks alloc
;
83 const struct wsi_image_fns
*image_fns
;
85 VkPresentModeKHR present_mode
;
88 /* Command pools, one per queue family */
89 VkCommandPool
*cmd_pools
;
91 VkResult (*destroy
)(struct wsi_swapchain
*swapchain
,
92 const VkAllocationCallbacks
*pAllocator
);
93 VkResult (*get_images
)(struct wsi_swapchain
*swapchain
,
94 uint32_t *pCount
, VkImage
*pSwapchainImages
);
95 VkResult (*acquire_next_image
)(struct wsi_swapchain
*swap_chain
,
96 uint64_t timeout
, VkSemaphore semaphore
,
97 uint32_t *image_index
);
98 VkResult (*queue_present
)(struct wsi_swapchain
*swap_chain
,
100 uint32_t waitSemaphoreCount
,
101 const VkSemaphore
*pWaitSemaphores
,
102 uint32_t image_index
,
103 const VkPresentRegionKHR
*damage
);
106 struct wsi_interface
{
107 VkResult (*get_support
)(VkIcdSurfaceBase
*surface
,
108 struct wsi_device
*wsi_device
,
109 const VkAllocationCallbacks
*alloc
,
110 uint32_t queueFamilyIndex
,
112 bool can_handle_different_gpu
,
113 VkBool32
* pSupported
);
114 VkResult (*get_capabilities
)(VkIcdSurfaceBase
*surface
,
115 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
);
116 VkResult (*get_capabilities2
)(VkIcdSurfaceBase
*surface
,
117 const void *info_next
,
118 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
);
119 VkResult (*get_formats
)(VkIcdSurfaceBase
*surface
,
120 struct wsi_device
*wsi_device
,
121 uint32_t* pSurfaceFormatCount
,
122 VkSurfaceFormatKHR
* pSurfaceFormats
);
123 VkResult (*get_formats2
)(VkIcdSurfaceBase
*surface
,
124 struct wsi_device
*wsi_device
,
125 const void *info_next
,
126 uint32_t* pSurfaceFormatCount
,
127 VkSurfaceFormat2KHR
* pSurfaceFormats
);
128 VkResult (*get_present_modes
)(VkIcdSurfaceBase
*surface
,
129 uint32_t* pPresentModeCount
,
130 VkPresentModeKHR
* pPresentModes
);
131 VkResult (*create_swapchain
)(VkIcdSurfaceBase
*surface
,
133 struct wsi_device
*wsi_device
,
135 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
136 const VkAllocationCallbacks
* pAllocator
,
137 const struct wsi_image_fns
*image_fns
,
138 struct wsi_swapchain
**swapchain
);
141 #define VK_ICD_WSI_PLATFORM_MAX 5
144 VkPhysicalDeviceMemoryProperties memory_props
;
145 uint32_t queue_family_count
;
147 uint32_t (*queue_get_family_index
)(VkQueue queue
);
149 #define WSI_CB(cb) PFN_vk##cb cb
150 WSI_CB(AllocateMemory
);
151 WSI_CB(AllocateCommandBuffers
);
152 WSI_CB(BindBufferMemory
);
153 WSI_CB(BindImageMemory
);
154 WSI_CB(BeginCommandBuffer
);
155 WSI_CB(CmdCopyImageToBuffer
);
156 WSI_CB(CreateBuffer
);
157 WSI_CB(CreateCommandPool
);
159 WSI_CB(DestroyBuffer
);
160 WSI_CB(DestroyCommandPool
);
161 WSI_CB(DestroyImage
);
162 WSI_CB(EndCommandBuffer
);
164 WSI_CB(FreeCommandBuffers
);
165 WSI_CB(GetBufferMemoryRequirements
);
166 WSI_CB(GetImageMemoryRequirements
);
167 WSI_CB(GetMemoryFdKHR
);
171 struct wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
174 typedef PFN_vkVoidFunction (VKAPI_PTR
*WSI_FN_GetPhysicalDeviceProcAddr
)(VkPhysicalDevice physicalDevice
, const char* pName
);
177 wsi_device_init(struct wsi_device
*wsi
,
178 VkPhysicalDevice pdevice
,
179 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
);
181 #define WSI_CB(cb) PFN_vk##cb cb
182 struct wsi_callbacks
{
183 VkPhysicalDevice (*device_get_physical
)(VkDevice
);
185 WSI_CB(GetDeviceProcAddr
);
186 WSI_CB(GetPhysicalDeviceFormatProperties
);
187 WSI_CB(GetPhysicalDeviceMemoryProperties
);
188 WSI_CB(GetPhysicalDeviceQueueFamilyProperties
);
192 #define WSI_DEFINE_NONDISP_HANDLE_CASTS(__wsi_type, __VkType) \
194 static inline struct __wsi_type * \
195 __wsi_type ## _from_handle(__VkType _handle) \
197 return (struct __wsi_type *)(uintptr_t) _handle; \
200 static inline __VkType \
201 __wsi_type ## _to_handle(struct __wsi_type *_obj) \
203 return (__VkType)(uintptr_t) _obj; \
206 WSI_DEFINE_NONDISP_HANDLE_CASTS(wsi_swapchain
, VkSwapchainKHR
)
208 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
210 static inline __VkIcdType * \
211 __VkIcdType ## _from_handle(__VkType _handle) \
213 return (__VkIcdType *)(uintptr_t) _handle; \
216 static inline __VkType \
217 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
219 return (__VkType)(uintptr_t) _obj; \
222 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
223 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
225 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase
, VkSurfaceKHR
)
227 VkResult
wsi_x11_init_wsi(struct wsi_device
*wsi_device
,
228 const VkAllocationCallbacks
*alloc
);
229 void wsi_x11_finish_wsi(struct wsi_device
*wsi_device
,
230 const VkAllocationCallbacks
*alloc
);
231 VkResult
wsi_wl_init_wsi(struct wsi_device
*wsi_device
,
232 const VkAllocationCallbacks
*alloc
,
233 VkPhysicalDevice physical_device
,
234 const struct wsi_callbacks
*cbs
);
235 void wsi_wl_finish_wsi(struct wsi_device
*wsi_device
,
236 const VkAllocationCallbacks
*alloc
);