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 "vk_dispatch_table.h"
31
#include <vulkan/vulkan.h>
32
#include <vulkan/vk_icd.h>
38
#ifndef WSI_ENTRYPOINTS_H
39
extern const struct vk_instance_entrypoint_table wsi_instance_entrypoints;
40
extern const struct vk_physical_device_entrypoint_table wsi_physical_device_entrypoints;
41
extern const struct vk_device_entrypoint_table wsi_device_entrypoints;
44
#include <util/list.h>
46
/* This is guaranteed to not collide with anything because it's in the
47
* VK_KHR_swapchain namespace but not actually used by the extension.
49
#define VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA (VkStructureType)1000001002
50
#define VK_STRUCTURE_TYPE_WSI_MEMORY_ALLOCATE_INFO_MESA (VkStructureType)1000001003
51
#define VK_STRUCTURE_TYPE_WSI_SURFACE_SUPPORTED_COUNTERS_MESA (VkStructureType)1000001005
52
#define VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA (VkStructureType)1000001006
54
/* This is always chained to VkImageCreateInfo when a wsi image is created.
55
* It indicates that the image can be transitioned to/from
56
* VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
58
struct wsi_image_create_info {
59
VkStructureType sType;
63
/* if true, the image is a buffer blit source */
67
struct wsi_memory_allocate_info {
68
VkStructureType sType;
73
/* To be chained into VkSurfaceCapabilities2KHR */
74
struct wsi_surface_supported_counters {
75
VkStructureType sType;
78
VkSurfaceCounterFlagsEXT supported_surface_counters;
82
/* To be chained into VkSubmitInfo */
83
struct wsi_memory_signal_submit_info {
84
VkStructureType sType;
86
VkDeviceMemory memory;
91
struct driOptionCache;
93
#define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
96
/* Allocator for the instance */
97
VkAllocationCallbacks instance_alloc;
99
VkPhysicalDevice pdevice;
100
VkPhysicalDeviceMemoryProperties memory_props;
101
uint32_t queue_family_count;
103
VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;
105
bool supports_modifiers;
106
uint32_t maxImageDimension2D;
107
VkPresentModeKHR override_present_mode;
108
bool force_bgra8_unorm_first;
110
/* Whether to enable adaptive sync for a swapchain if implemented and
111
* available. Not all window systems might support this. */
112
bool enable_adaptive_sync;
114
/* List of fences to signal when hotplug event happens. */
115
struct list_head hotplug_fences;
118
/* Override the minimum number of images on the swapchain.
120
uint32_t override_minImageCount;
122
/* Forces strict number of image on the swapchain using application
123
* provided VkSwapchainCreateInfoKH::RminImageCount.
125
bool strict_imageCount;
127
/* Ensures to create at least the number of image specified by the
128
* driver in VkSurfaceCapabilitiesKHR::minImageCount.
130
bool ensure_minImageCount;
132
/* Wait for fences before submitting buffers to Xwayland. Defaults to
135
bool xwaylandWaitReady;
140
/* Signals the semaphore such that any wait on the semaphore will wait on
141
* any reads or writes on the give memory object. This is used to
142
* implement the semaphore signal operation in vkAcquireNextImage. This
143
* requires the driver to implement vk_device::create_sync_for_memory.
145
bool signal_semaphore_with_memory;
147
/* Signals the fence such that any wait on the fence will wait on any reads
148
* or writes on the give memory object. This is used to implement the
149
* semaphore signal operation in vkAcquireNextImage. This requires the
150
* driver to implement vk_device::create_sync_for_memory. The resulting
151
* vk_sync must support CPU waits.
153
bool signal_fence_with_memory;
156
* This sets the ownership for a WSI memory object:
158
* The ownership is true if and only if the application is allowed to submit
159
* command buffers that reference the buffer.
161
* This can be used to prune BO lists without too many adverse affects on
164
* Side note: care needs to be taken for internally delayed submissions wrt
165
* timeline semaphores.
167
void (*set_memory_ownership)(VkDevice device,
168
VkDeviceMemory memory,
172
* If this is set, the WSI device will call it to let the driver backend
173
* decide if it can present images directly on the given device fd.
175
bool (*can_present_on_device)(VkPhysicalDevice pdevice, int fd);
178
* A driver can implement this callback to return a special queue to execute
181
VkQueue (*get_buffer_blit_queue)(VkDevice device);
183
#define WSI_CB(cb) PFN_vk##cb cb
184
WSI_CB(AllocateMemory);
185
WSI_CB(AllocateCommandBuffers);
186
WSI_CB(BindBufferMemory);
187
WSI_CB(BindImageMemory);
188
WSI_CB(BeginCommandBuffer);
189
WSI_CB(CmdPipelineBarrier);
190
WSI_CB(CmdCopyImageToBuffer);
191
WSI_CB(CreateBuffer);
192
WSI_CB(CreateCommandPool);
195
WSI_CB(CreateSemaphore);
196
WSI_CB(DestroyBuffer);
197
WSI_CB(DestroyCommandPool);
198
WSI_CB(DestroyFence);
199
WSI_CB(DestroyImage);
200
WSI_CB(DestroySemaphore);
201
WSI_CB(EndCommandBuffer);
203
WSI_CB(FreeCommandBuffers);
204
WSI_CB(GetBufferMemoryRequirements);
205
WSI_CB(GetImageDrmFormatModifierPropertiesEXT);
206
WSI_CB(GetImageMemoryRequirements);
207
WSI_CB(GetImageSubresourceLayout);
208
WSI_CB(GetMemoryFdKHR);
209
WSI_CB(GetPhysicalDeviceFormatProperties);
210
WSI_CB(GetPhysicalDeviceFormatProperties2KHR);
211
WSI_CB(GetPhysicalDeviceImageFormatProperties2);
214
WSI_CB(WaitForFences);
219
struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
222
typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
225
wsi_device_init(struct wsi_device *wsi,
226
VkPhysicalDevice pdevice,
227
WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
228
const VkAllocationCallbacks *alloc,
230
const struct driOptionCache *dri_options,
234
wsi_device_finish(struct wsi_device *wsi,
235
const VkAllocationCallbacks *alloc);
237
/* Setup file descriptor to be used with imported sync_fd's in wsi fences. */
239
wsi_device_setup_syncobj_fd(struct wsi_device *wsi_device,
242
#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
244
static inline __VkIcdType * \
245
__VkIcdType ## _from_handle(__VkType _handle) \
247
return (__VkIcdType *)(uintptr_t) _handle; \
250
static inline __VkType \
251
__VkIcdType ## _to_handle(__VkIcdType *_obj) \
253
return (__VkType)(uintptr_t) _obj; \
256
#define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
257
__VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
259
ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
262
wsi_common_get_images(VkSwapchainKHR _swapchain,
263
uint32_t *pSwapchainImageCount,
264
VkImage *pSwapchainImages);
267
wsi_common_get_image(VkSwapchainKHR _swapchain, uint32_t index);
270
wsi_common_acquire_next_image2(const struct wsi_device *wsi,
272
const VkAcquireNextImageInfoKHR *pAcquireInfo,
273
uint32_t *pImageIndex);
276
wsi_common_queue_present(const struct wsi_device *wsi,
279
int queue_family_index,
280
const VkPresentInfoKHR *pPresentInfo);
283
wsi_common_create_swapchain_image(const struct wsi_device *wsi,
284
const VkImageCreateInfo *pCreateInfo,
285
VkSwapchainKHR _swapchain,
288
wsi_common_bind_swapchain_image(const struct wsi_device *wsi,
290
VkSwapchainKHR _swapchain,