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_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
39 #define VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA (VkStructureType)1000001006
41 struct wsi_image_create_info
{
42 VkStructureType sType
;
47 struct wsi_memory_allocate_info
{
48 VkStructureType sType
;
53 /* To be chained into VkSurfaceCapabilities2KHR */
54 struct wsi_surface_supported_counters
{
55 VkStructureType sType
;
58 VkSurfaceCounterFlagsEXT supported_surface_counters
;
62 /* To be chained into VkSubmitInfo */
63 struct wsi_memory_signal_submit_info
{
64 VkStructureType sType
;
66 VkDeviceMemory memory
;
71 const struct wsi_device
*wsi_device
;
73 const VkAllocationCallbacks
*alloc
;
74 VkResult (*wait
)(struct wsi_fence
*fence
, uint64_t abs_timeout
);
75 void (*destroy
)(struct wsi_fence
*fence
);
80 struct driOptionCache
;
82 #define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
85 /* Allocator for the instance */
86 VkAllocationCallbacks instance_alloc
;
88 VkPhysicalDevice pdevice
;
89 VkPhysicalDeviceMemoryProperties memory_props
;
90 uint32_t queue_family_count
;
92 VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info
;
94 bool supports_modifiers
;
95 uint32_t maxImageDimension2D
;
96 VkPresentModeKHR override_present_mode
;
97 bool force_bgra8_unorm_first
;
99 /* Whether to enable adaptive sync for a swapchain if implemented and
100 * available. Not all window systems might support this. */
101 bool enable_adaptive_sync
;
104 /* Override the minimum number of images on the swapchain.
106 uint32_t override_minImageCount
;
108 /* Forces strict number of image on the swapchain using application
109 * provided VkSwapchainCreateInfoKH::RminImageCount.
111 bool strict_imageCount
;
114 /* Signals the semaphore such that any wait on the semaphore will wait on
115 * any reads or writes on the give memory object. This is used to
116 * implement the semaphore signal operation in vkAcquireNextImage.
118 void (*signal_semaphore_for_memory
)(VkDevice device
,
119 VkSemaphore semaphore
,
120 VkDeviceMemory memory
);
122 /* Signals the fence such that any wait on the fence will wait on any reads
123 * or writes on the give memory object. This is used to implement the
124 * semaphore signal operation in vkAcquireNextImage.
126 void (*signal_fence_for_memory
)(VkDevice device
,
128 VkDeviceMemory memory
);
130 #define WSI_CB(cb) PFN_vk##cb cb
131 WSI_CB(AllocateMemory
);
132 WSI_CB(AllocateCommandBuffers
);
133 WSI_CB(BindBufferMemory
);
134 WSI_CB(BindImageMemory
);
135 WSI_CB(BeginCommandBuffer
);
136 WSI_CB(CmdCopyImageToBuffer
);
137 WSI_CB(CreateBuffer
);
138 WSI_CB(CreateCommandPool
);
141 WSI_CB(DestroyBuffer
);
142 WSI_CB(DestroyCommandPool
);
143 WSI_CB(DestroyFence
);
144 WSI_CB(DestroyImage
);
145 WSI_CB(EndCommandBuffer
);
147 WSI_CB(FreeCommandBuffers
);
148 WSI_CB(GetBufferMemoryRequirements
);
149 WSI_CB(GetImageDrmFormatModifierPropertiesEXT
);
150 WSI_CB(GetImageMemoryRequirements
);
151 WSI_CB(GetImageSubresourceLayout
);
152 WSI_CB(GetMemoryFdKHR
);
153 WSI_CB(GetPhysicalDeviceFormatProperties
);
154 WSI_CB(GetPhysicalDeviceFormatProperties2KHR
);
155 WSI_CB(GetPhysicalDeviceImageFormatProperties2
);
158 WSI_CB(WaitForFences
);
161 struct wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
164 typedef PFN_vkVoidFunction (VKAPI_PTR
*WSI_FN_GetPhysicalDeviceProcAddr
)(VkPhysicalDevice physicalDevice
, const char* pName
);
167 wsi_device_init(struct wsi_device
*wsi
,
168 VkPhysicalDevice pdevice
,
169 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
,
170 const VkAllocationCallbacks
*alloc
,
172 const struct driOptionCache
*dri_options
);
175 wsi_device_finish(struct wsi_device
*wsi
,
176 const VkAllocationCallbacks
*alloc
);
178 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
180 static inline __VkIcdType * \
181 __VkIcdType ## _from_handle(__VkType _handle) \
183 return (__VkIcdType *)(uintptr_t) _handle; \
186 static inline __VkType \
187 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
189 return (__VkType)(uintptr_t) _obj; \
192 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
193 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
195 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase
, VkSurfaceKHR
)
198 wsi_common_get_surface_support(struct wsi_device
*wsi_device
,
199 uint32_t queueFamilyIndex
,
200 VkSurfaceKHR surface
,
201 VkBool32
* pSupported
);
204 wsi_common_get_surface_capabilities(struct wsi_device
*wsi_device
,
205 VkSurfaceKHR surface
,
206 VkSurfaceCapabilitiesKHR
*pSurfaceCapabilities
);
209 wsi_common_get_surface_capabilities2(struct wsi_device
*wsi_device
,
210 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
211 VkSurfaceCapabilities2KHR
*pSurfaceCapabilities
);
214 wsi_common_get_surface_formats(struct wsi_device
*wsi_device
,
215 VkSurfaceKHR surface
,
216 uint32_t *pSurfaceFormatCount
,
217 VkSurfaceFormatKHR
*pSurfaceFormats
);
220 wsi_common_get_surface_formats2(struct wsi_device
*wsi_device
,
221 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
222 uint32_t *pSurfaceFormatCount
,
223 VkSurfaceFormat2KHR
*pSurfaceFormats
);
226 wsi_common_get_surface_present_modes(struct wsi_device
*wsi_device
,
227 VkSurfaceKHR surface
,
228 uint32_t *pPresentModeCount
,
229 VkPresentModeKHR
*pPresentModes
);
232 wsi_common_get_present_rectangles(struct wsi_device
*wsi
,
233 VkSurfaceKHR surface
,
234 uint32_t* pRectCount
,
238 wsi_common_get_surface_capabilities2ext(
239 struct wsi_device
*wsi_device
,
240 VkSurfaceKHR surface
,
241 VkSurfaceCapabilities2EXT
*pSurfaceCapabilities
);
244 wsi_common_get_images(VkSwapchainKHR _swapchain
,
245 uint32_t *pSwapchainImageCount
,
246 VkImage
*pSwapchainImages
);
249 wsi_common_acquire_next_image2(const struct wsi_device
*wsi
,
251 const VkAcquireNextImageInfoKHR
*pAcquireInfo
,
252 uint32_t *pImageIndex
);
255 wsi_common_create_swapchain(struct wsi_device
*wsi
,
257 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
258 const VkAllocationCallbacks
*pAllocator
,
259 VkSwapchainKHR
*pSwapchain
);
261 wsi_common_destroy_swapchain(VkDevice device
,
262 VkSwapchainKHR swapchain
,
263 const VkAllocationCallbacks
*pAllocator
);
266 wsi_common_queue_present(const struct wsi_device
*wsi
,
269 int queue_family_index
,
270 const VkPresentInfoKHR
*pPresentInfo
);
273 wsi_common_get_current_time(void);