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
40 #define VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA (VkStructureType)1000001006
42 struct wsi_image_create_info
{
43 VkStructureType sType
;
47 uint32_t modifier_count
;
48 const uint64_t *modifiers
;
51 struct wsi_memory_allocate_info
{
52 VkStructureType sType
;
57 struct wsi_format_modifier_properties
{
59 uint32_t modifier_plane_count
;
62 /* Chain in for vkGetPhysicalDeviceFormatProperties2KHR */
63 struct wsi_format_modifier_properties_list
{
64 VkStructureType sType
;
67 uint32_t modifier_count
;
68 struct wsi_format_modifier_properties
*modifier_properties
;
71 /* To be chained into VkSurfaceCapabilities2KHR */
72 struct wsi_surface_supported_counters
{
73 VkStructureType sType
;
76 VkSurfaceCounterFlagsEXT supported_surface_counters
;
80 /* To be chained into VkSubmitInfo */
81 struct wsi_memory_signal_submit_info
{
82 VkStructureType sType
;
84 VkDeviceMemory memory
;
89 const struct wsi_device
*wsi_device
;
91 const VkAllocationCallbacks
*alloc
;
92 VkResult (*wait
)(struct wsi_fence
*fence
, uint64_t abs_timeout
);
93 void (*destroy
)(struct wsi_fence
*fence
);
98 struct driOptionCache
;
100 #define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
103 /* Allocator for the instance */
104 VkAllocationCallbacks instance_alloc
;
106 VkPhysicalDevice pdevice
;
107 VkPhysicalDeviceMemoryProperties memory_props
;
108 uint32_t queue_family_count
;
110 VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info
;
112 bool supports_modifiers
;
113 uint32_t maxImageDimension2D
;
114 VkPresentModeKHR override_present_mode
;
116 /* Whether to enable adaptive sync for a swapchain if implemented and
117 * available. Not all window systems might support this. */
118 bool enable_adaptive_sync
;
121 /* Override the minimum number of images on the swapchain.
123 uint32_t override_minImageCount
;
125 /* Forces strict number of image on the swapchain using application
126 * provided VkSwapchainCreateInfoKH::RminImageCount.
128 bool strict_imageCount
;
131 uint64_t (*image_get_modifier
)(VkImage image
);
133 #define WSI_CB(cb) PFN_vk##cb cb
134 WSI_CB(AllocateMemory
);
135 WSI_CB(AllocateCommandBuffers
);
136 WSI_CB(BindBufferMemory
);
137 WSI_CB(BindImageMemory
);
138 WSI_CB(BeginCommandBuffer
);
139 WSI_CB(CmdCopyImageToBuffer
);
140 WSI_CB(CreateBuffer
);
141 WSI_CB(CreateCommandPool
);
144 WSI_CB(DestroyBuffer
);
145 WSI_CB(DestroyCommandPool
);
146 WSI_CB(DestroyFence
);
147 WSI_CB(DestroyImage
);
148 WSI_CB(EndCommandBuffer
);
150 WSI_CB(FreeCommandBuffers
);
151 WSI_CB(GetBufferMemoryRequirements
);
152 WSI_CB(GetImageMemoryRequirements
);
153 WSI_CB(GetImageSubresourceLayout
);
154 WSI_CB(GetMemoryFdKHR
);
155 WSI_CB(GetPhysicalDeviceFormatProperties
);
156 WSI_CB(GetPhysicalDeviceFormatProperties2KHR
);
159 WSI_CB(WaitForFences
);
162 struct wsi_interface
* wsi
[VK_ICD_WSI_PLATFORM_MAX
];
165 typedef PFN_vkVoidFunction (VKAPI_PTR
*WSI_FN_GetPhysicalDeviceProcAddr
)(VkPhysicalDevice physicalDevice
, const char* pName
);
168 wsi_device_init(struct wsi_device
*wsi
,
169 VkPhysicalDevice pdevice
,
170 WSI_FN_GetPhysicalDeviceProcAddr proc_addr
,
171 const VkAllocationCallbacks
*alloc
,
173 const struct driOptionCache
*dri_options
);
176 wsi_device_finish(struct wsi_device
*wsi
,
177 const VkAllocationCallbacks
*alloc
);
179 #define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
181 static inline __VkIcdType * \
182 __VkIcdType ## _from_handle(__VkType _handle) \
184 return (__VkIcdType *)(uintptr_t) _handle; \
187 static inline __VkType \
188 __VkIcdType ## _to_handle(__VkIcdType *_obj) \
190 return (__VkType)(uintptr_t) _obj; \
193 #define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
194 __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
196 ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase
, VkSurfaceKHR
)
199 wsi_common_get_surface_support(struct wsi_device
*wsi_device
,
200 uint32_t queueFamilyIndex
,
201 VkSurfaceKHR surface
,
202 VkBool32
* pSupported
);
205 wsi_common_get_surface_capabilities(struct wsi_device
*wsi_device
,
206 VkSurfaceKHR surface
,
207 VkSurfaceCapabilitiesKHR
*pSurfaceCapabilities
);
210 wsi_common_get_surface_capabilities2(struct wsi_device
*wsi_device
,
211 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
212 VkSurfaceCapabilities2KHR
*pSurfaceCapabilities
);
215 wsi_common_get_surface_formats(struct wsi_device
*wsi_device
,
216 VkSurfaceKHR surface
,
217 uint32_t *pSurfaceFormatCount
,
218 VkSurfaceFormatKHR
*pSurfaceFormats
);
221 wsi_common_get_surface_formats2(struct wsi_device
*wsi_device
,
222 const VkPhysicalDeviceSurfaceInfo2KHR
*pSurfaceInfo
,
223 uint32_t *pSurfaceFormatCount
,
224 VkSurfaceFormat2KHR
*pSurfaceFormats
);
227 wsi_common_get_surface_present_modes(struct wsi_device
*wsi_device
,
228 VkSurfaceKHR surface
,
229 uint32_t *pPresentModeCount
,
230 VkPresentModeKHR
*pPresentModes
);
233 wsi_common_get_present_rectangles(struct wsi_device
*wsi
,
234 VkSurfaceKHR surface
,
235 uint32_t* pRectCount
,
239 wsi_common_get_surface_capabilities2ext(
240 struct wsi_device
*wsi_device
,
241 VkSurfaceKHR surface
,
242 VkSurfaceCapabilities2EXT
*pSurfaceCapabilities
);
245 wsi_common_get_images(VkSwapchainKHR _swapchain
,
246 uint32_t *pSwapchainImageCount
,
247 VkImage
*pSwapchainImages
);
250 wsi_common_acquire_next_image2(const struct wsi_device
*wsi
,
252 const VkAcquireNextImageInfoKHR
*pAcquireInfo
,
253 uint32_t *pImageIndex
);
256 wsi_common_create_swapchain(struct wsi_device
*wsi
,
258 const VkSwapchainCreateInfoKHR
*pCreateInfo
,
259 const VkAllocationCallbacks
*pAllocator
,
260 VkSwapchainKHR
*pSwapchain
);
262 wsi_common_destroy_swapchain(VkDevice device
,
263 VkSwapchainKHR swapchain
,
264 const VkAllocationCallbacks
*pAllocator
);
267 wsi_common_queue_present(const struct wsi_device
*wsi
,
270 int queue_family_index
,
271 const VkPresentInfoKHR
*pPresentInfo
);
274 wsi_common_get_current_time(void);