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
;
54 struct wsi_interface
{
55 VkResult (*get_support
)(VkIcdSurfaceBase
*surface
,
56 struct wsi_device
*wsi_device
,
57 const VkAllocationCallbacks
*alloc
,
58 uint32_t queueFamilyIndex
,
60 bool can_handle_different_gpu
,
61 VkBool32
* pSupported
);
62 VkResult (*get_capabilities
)(VkIcdSurfaceBase
*surface
,
63 VkSurfaceCapabilitiesKHR
* pSurfaceCapabilities
);
64 VkResult (*get_capabilities2
)(VkIcdSurfaceBase
*surface
,
65 const void *info_next
,
66 VkSurfaceCapabilities2KHR
* pSurfaceCapabilities
);
67 VkResult (*get_formats
)(VkIcdSurfaceBase
*surface
,
68 struct wsi_device
*wsi_device
,
69 uint32_t* pSurfaceFormatCount
,
70 VkSurfaceFormatKHR
* pSurfaceFormats
);
71 VkResult (*get_formats2
)(VkIcdSurfaceBase
*surface
,
72 struct wsi_device
*wsi_device
,
73 const void *info_next
,
74 uint32_t* pSurfaceFormatCount
,
75 VkSurfaceFormat2KHR
* pSurfaceFormats
);
76 VkResult (*get_present_modes
)(VkIcdSurfaceBase
*surface
,
77 uint32_t* pPresentModeCount
,
78 VkPresentModeKHR
* pPresentModes
);
79 VkResult (*create_swapchain
)(VkIcdSurfaceBase
*surface
,
81 struct wsi_device
*wsi_device
,
83 const VkSwapchainCreateInfoKHR
* pCreateInfo
,
84 const VkAllocationCallbacks
* pAllocator
,
85 struct wsi_swapchain
**swapchain
);
88 #define VK_ICD_WSI_PLATFORM_MAX 5
91 VkPhysicalDeviceMemoryProperties memory_props
;
92 uint32_t queue_family_count
;
94 uint32_t (*queue_get_family_index
)(VkQueue queue
);
96 #define WSI_CB(cb) PFN_vk##cb cb
97 WSI_CB(AllocateMemory
);
98 WSI_CB(AllocateCommandBuffers
);
99 WSI_CB(BindBufferMemory
);
100 WSI_CB(BindImageMemory
);
101 WSI_CB(BeginCommandBuffer
);
102 WSI_CB(CmdCopyImageToBuffer
);
103 WSI_CB(CreateBuffer
);
104 WSI_CB(CreateCommandPool
);
107 WSI_CB(DestroyBuffer
);
108 WSI_CB(DestroyCommandPool
);
109 WSI_CB(DestroyFence
);
110 WSI_CB(DestroyImage
);
111 WSI_CB(EndCommandBuffer
);
113 WSI_CB(FreeCommandBuffers
);
114 WSI_CB(GetBufferMemoryRequirements
);
115 WSI_CB(GetImageMemoryRequirements
);
116 WSI_CB(GetImageSubresourceLayout
);
117 WSI_CB(GetMemoryFdKHR
);
120 WSI_CB(WaitForFences
);
123 struct wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
126 typedef PFN_vkVoidFunction (VKAPI_PTR
*WSI_FN_GetPhysicalDeviceProcAddr
)(VkPhysicalDevice physicalDevice
, const char* pName
);
129 wsi_device_init(struct wsi_device
*wsi
,
130 VkPhysicalDevice pdevice
,
131 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
);
133 #define WSI_CB(cb) PFN_vk##cb cb
134 struct wsi_callbacks
{
135 VkPhysicalDevice (*device_get_physical
)(VkDevice
);
137 WSI_CB(GetDeviceProcAddr
);
138 WSI_CB(GetPhysicalDeviceFormatProperties
);
139 WSI_CB(GetPhysicalDeviceMemoryProperties
);
140 WSI_CB(GetPhysicalDeviceQueueFamilyProperties
);
144 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
146 static inline __VkIcdType * \
147 __VkIcdType ## _from_handle(__VkType _handle) \
149 return (__VkIcdType *)(uintptr_t) _handle; \
152 static inline __VkType \
153 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
155 return (__VkType)(uintptr_t) _obj; \
158 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
159 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
161 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase
, VkSurfaceKHR
)
163 VkResult
wsi_x11_init_wsi(struct wsi_device
*wsi_device
,
164 const VkAllocationCallbacks
*alloc
);
165 void wsi_x11_finish_wsi(struct wsi_device
*wsi_device
,
166 const VkAllocationCallbacks
*alloc
);
167 VkResult
wsi_wl_init_wsi(struct wsi_device
*wsi_device
,
168 const VkAllocationCallbacks
*alloc
,
169 VkPhysicalDevice physical_device
,
170 const struct wsi_callbacks
*cbs
);
171 void wsi_wl_finish_wsi(struct wsi_device
*wsi_device
,
172 const VkAllocationCallbacks
*alloc
);
175 wsi_common_get_images(VkSwapchainKHR _swapchain
,
176 uint32_t *pSwapchainImageCount
,
177 VkImage
*pSwapchainImages
);
180 wsi_common_acquire_next_image(const struct wsi_device
*wsi
,
182 VkSwapchainKHR swapchain
,
184 VkSemaphore semaphore
,
185 uint32_t *pImageIndex
);
188 wsi_common_create_swapchain(struct wsi_device
*wsi
,
191 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
192 const VkAllocationCallbacks
*pAllocator
,
193 VkSwapchainKHR
*pSwapchain
);
195 wsi_common_destroy_swapchain(VkDevice device
,
196 VkSwapchainKHR swapchain
,
197 const VkAllocationCallbacks
*pAllocator
);
200 wsi_common_queue_present(const struct wsi_device
*wsi
,
203 int queue_family_index
,
204 const VkPresentInfoKHR
*pPresentInfo
);