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
38 #define VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA (VkStructureType)1000001004
39 #define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
41 struct wsi_image_create_info
{
42 VkStructureType sType
;
46 uint32_t modifier_count
;
47 const uint64_t *modifiers
;
50 struct wsi_memory_allocate_info
{
51 VkStructureType sType
;
56 struct wsi_format_modifier_properties
{
58 uint32_t modifier_plane_count
;
61 /* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
62 struct wsi_format_modifier_properties_list
{
63 VkStructureType sType
;
66 uint32_t modifier_count
;
67 struct wsi_format_modifier_properties
*modifier_properties
;
70 /* To be chained into VkSurfaceCapabilities2KHR */
71 struct wsi_surface_supported_counters
{
72 VkStructureType sType
;
75 VkSurfaceCounterFlagsEXT supported_surface_counters
;
81 const struct wsi_device
*wsi_device
;
83 const VkAllocationCallbacks
*alloc
;
84 VkResult (*wait
)(struct wsi_fence
*fence
, uint64_t abs_timeout
);
85 void (*destroy
)(struct wsi_fence
*fence
);
90 struct driOptionCache
;
92 #define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
95 /* Allocator for the instance */
96 VkAllocationCallbacks instance_alloc
;
98 VkPhysicalDevice pdevice
;
99 VkPhysicalDeviceMemoryProperties memory_props
;
100 uint32_t queue_family_count
;
102 VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info
;
104 bool supports_modifiers
;
105 uint32_t maxImageDimension2D
;
106 VkPresentModeKHR override_present_mode
;
108 /* Whether to enable adaptive sync for a swapchain if implemented and
109 * available. Not all window systems might support this. */
110 bool enable_adaptive_sync
;
113 /* Override the minimum number of images on the swapchain.
115 uint32_t override_minImageCount
;
117 /* Forces strict number of image on the swapchain using application
118 * provided VkSwapchainCreateInfoKH::RminImageCount.
120 bool strict_imageCount
;
123 uint64_t (*image_get_modifier
)(VkImage image
);
125 #define WSI_CB(cb) PFN_vk##cb cb
126 WSI_CB(AllocateMemory
);
127 WSI_CB(AllocateCommandBuffers
);
128 WSI_CB(BindBufferMemory
);
129 WSI_CB(BindImageMemory
);
130 WSI_CB(BeginCommandBuffer
);
131 WSI_CB(CmdCopyImageToBuffer
);
132 WSI_CB(CreateBuffer
);
133 WSI_CB(CreateCommandPool
);
136 WSI_CB(DestroyBuffer
);
137 WSI_CB(DestroyCommandPool
);
138 WSI_CB(DestroyFence
);
139 WSI_CB(DestroyImage
);
140 WSI_CB(EndCommandBuffer
);
142 WSI_CB(FreeCommandBuffers
);
143 WSI_CB(GetBufferMemoryRequirements
);
144 WSI_CB(GetImageMemoryRequirements
);
145 WSI_CB(GetImageSubresourceLayout
);
146 WSI_CB(GetMemoryFdKHR
);
147 WSI_CB(GetPhysicalDeviceFormatProperties
);
148 WSI_CB(GetPhysicalDeviceFormatProperties2KHR
);
151 WSI_CB(WaitForFences
);
154 struct wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
157 typedef PFN_vkVoidFunction (VKAPI_PTR
*WSI_FN_GetPhysicalDeviceProcAddr
)(VkPhysicalDevice physicalDevice
, const char* pName
);
160 wsi_device_init(struct wsi_device
*wsi
,
161 VkPhysicalDevice pdevice
,
162 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
,
163 const VkAllocationCallbacks
*alloc
,
165 const struct driOptionCache
*dri_options
);
168 wsi_device_finish(struct wsi_device
*wsi
,
169 const VkAllocationCallbacks
*alloc
);
171 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
173 static inline __VkIcdType * \
174 __VkIcdType ## _from_handle(__VkType _handle) \
176 return (__VkIcdType *)(uintptr_t) _handle; \
179 static inline __VkType \
180 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
182 return (__VkType)(uintptr_t) _obj; \
185 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
186 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
188 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase
, VkSurfaceKHR
)
191 wsi_common_get_surface_support(struct wsi_device
*wsi_device
,
192 uint32_t queueFamilyIndex
,
193 VkSurfaceKHR surface
,
194 VkBool32
* pSupported
);
197 wsi_common_get_surface_capabilities(struct wsi_device
*wsi_device
,
198 VkSurfaceKHR surface
,
199 VkSurfaceCapabilitiesKHR
*pSurfaceCapabilities
);
202 wsi_common_get_surface_capabilities2(struct wsi_device
*wsi_device
,
203 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
204 VkSurfaceCapabilities2KHR
*pSurfaceCapabilities
);
207 wsi_common_get_surface_formats(struct wsi_device
*wsi_device
,
208 VkSurfaceKHR surface
,
209 uint32_t *pSurfaceFormatCount
,
210 VkSurfaceFormatKHR
*pSurfaceFormats
);
213 wsi_common_get_surface_formats2(struct wsi_device
*wsi_device
,
214 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
215 uint32_t *pSurfaceFormatCount
,
216 VkSurfaceFormat2KHR
*pSurfaceFormats
);
219 wsi_common_get_surface_present_modes(struct wsi_device
*wsi_device
,
220 VkSurfaceKHR surface
,
221 uint32_t *pPresentModeCount
,
222 VkPresentModeKHR
*pPresentModes
);
225 wsi_common_get_present_rectangles(struct wsi_device
*wsi
,
226 VkSurfaceKHR surface
,
227 uint32_t* pRectCount
,
231 wsi_common_get_surface_capabilities2ext(
232 struct wsi_device
*wsi_device
,
233 VkSurfaceKHR surface
,
234 VkSurfaceCapabilities2EXT
*pSurfaceCapabilities
);
237 wsi_common_get_images(VkSwapchainKHR _swapchain
,
238 uint32_t *pSwapchainImageCount
,
239 VkImage
*pSwapchainImages
);
242 wsi_common_acquire_next_image2(const struct wsi_device
*wsi
,
244 const VkAcquireNextImageInfoKHR
*pAcquireInfo
,
245 uint32_t *pImageIndex
);
248 wsi_common_create_swapchain(struct wsi_device
*wsi
,
250 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
251 const VkAllocationCallbacks
*pAllocator
,
252 VkSwapchainKHR
*pSwapchain
);
254 wsi_common_destroy_swapchain(VkDevice device
,
255 VkSwapchainKHR swapchain
,
256 const VkAllocationCallbacks
*pAllocator
);
259 wsi_common_queue_present(const struct wsi_device
*wsi
,
262 int queue_family_index
,
263 const VkPresentInfoKHR
*pPresentInfo
);
266 wsi_common_get_current_time(void);