Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/vulkan/wsi/wsi_common.h
7237 views
1
/*
2
* Copyright © 2015 Intel Corporation
3
*
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:
10
*
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
13
* Software.
14
*
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
21
* IN THE SOFTWARE.
22
*/
23
#ifndef WSI_COMMON_H
24
#define WSI_COMMON_H
25
26
#include <stdint.h>
27
#include <stdbool.h>
28
29
#include "vk_alloc.h"
30
#include <vulkan/vulkan.h>
31
#include <vulkan/vk_icd.h>
32
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.
35
*/
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
40
41
/* This is always chained to VkImageCreateInfo when a wsi image is created.
42
* It indicates that the image can be transitioned to/from
43
* VK_IMAGE_LAYOUT_PRESENT_SRC_KHR.
44
*/
45
struct wsi_image_create_info {
46
VkStructureType sType;
47
const void *pNext;
48
bool scanout;
49
50
/* If set, the buffer is the prime blit destination and the image is the
51
* source.
52
*/
53
VkBuffer prime_blit_buffer;
54
};
55
56
struct wsi_memory_allocate_info {
57
VkStructureType sType;
58
const void *pNext;
59
bool implicit_sync;
60
};
61
62
/* To be chained into VkSurfaceCapabilities2KHR */
63
struct wsi_surface_supported_counters {
64
VkStructureType sType;
65
const void *pNext;
66
67
VkSurfaceCounterFlagsEXT supported_surface_counters;
68
69
};
70
71
/* To be chained into VkSubmitInfo */
72
struct wsi_memory_signal_submit_info {
73
VkStructureType sType;
74
const void *pNext;
75
VkDeviceMemory memory;
76
};
77
78
struct wsi_fence {
79
VkDevice device;
80
const struct wsi_device *wsi_device;
81
VkDisplayKHR display;
82
const VkAllocationCallbacks *alloc;
83
VkResult (*wait)(struct wsi_fence *fence, uint64_t abs_timeout);
84
void (*destroy)(struct wsi_fence *fence);
85
};
86
87
struct wsi_interface;
88
89
struct driOptionCache;
90
91
#define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
92
93
struct wsi_device {
94
/* Allocator for the instance */
95
VkAllocationCallbacks instance_alloc;
96
97
VkPhysicalDevice pdevice;
98
VkPhysicalDeviceMemoryProperties memory_props;
99
uint32_t queue_family_count;
100
101
VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;
102
103
bool supports_modifiers;
104
uint32_t maxImageDimension2D;
105
VkPresentModeKHR override_present_mode;
106
bool force_bgra8_unorm_first;
107
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;
111
112
struct {
113
/* Override the minimum number of images on the swapchain.
114
* 0 = no override */
115
uint32_t override_minImageCount;
116
117
/* Forces strict number of image on the swapchain using application
118
* provided VkSwapchainCreateInfoKH::RminImageCount.
119
*/
120
bool strict_imageCount;
121
122
/* Ensures to create at least the number of image specified by the
123
* driver in VkSurfaceCapabilitiesKHR::minImageCount.
124
*/
125
bool ensure_minImageCount;
126
} x11;
127
128
bool sw;
129
130
/* Signals the semaphore such that any wait on the semaphore will wait on
131
* any reads or writes on the give memory object. This is used to
132
* implement the semaphore signal operation in vkAcquireNextImage.
133
*/
134
void (*signal_semaphore_for_memory)(VkDevice device,
135
VkSemaphore semaphore,
136
VkDeviceMemory memory);
137
138
/* Signals the fence such that any wait on the fence will wait on any reads
139
* or writes on the give memory object. This is used to implement the
140
* semaphore signal operation in vkAcquireNextImage.
141
*/
142
void (*signal_fence_for_memory)(VkDevice device,
143
VkFence fence,
144
VkDeviceMemory memory);
145
146
/*
147
* This sets the ownership for a WSI memory object:
148
*
149
* The ownership is true if and only if the application is allowed to submit
150
* command buffers that reference the buffer.
151
*
152
* This can be used to prune BO lists without too many adverse affects on
153
* implicit sync.
154
*
155
* Side note: care needs to be taken for internally delayed submissions wrt
156
* timeline semaphores.
157
*/
158
void (*set_memory_ownership)(VkDevice device,
159
VkDeviceMemory memory,
160
VkBool32 ownership);
161
162
/*
163
* If this is set, the WSI device will call it to let the driver backend
164
* decide if it can present images directly on the given device fd.
165
*/
166
bool (*can_present_on_device)(VkPhysicalDevice pdevice, int fd);
167
168
#define WSI_CB(cb) PFN_vk##cb cb
169
WSI_CB(AllocateMemory);
170
WSI_CB(AllocateCommandBuffers);
171
WSI_CB(BindBufferMemory);
172
WSI_CB(BindImageMemory);
173
WSI_CB(BeginCommandBuffer);
174
WSI_CB(CmdCopyImageToBuffer);
175
WSI_CB(CreateBuffer);
176
WSI_CB(CreateCommandPool);
177
WSI_CB(CreateFence);
178
WSI_CB(CreateImage);
179
WSI_CB(DestroyBuffer);
180
WSI_CB(DestroyCommandPool);
181
WSI_CB(DestroyFence);
182
WSI_CB(DestroyImage);
183
WSI_CB(EndCommandBuffer);
184
WSI_CB(FreeMemory);
185
WSI_CB(FreeCommandBuffers);
186
WSI_CB(GetBufferMemoryRequirements);
187
WSI_CB(GetImageDrmFormatModifierPropertiesEXT);
188
WSI_CB(GetImageMemoryRequirements);
189
WSI_CB(GetImageSubresourceLayout);
190
WSI_CB(GetMemoryFdKHR);
191
WSI_CB(GetPhysicalDeviceFormatProperties);
192
WSI_CB(GetPhysicalDeviceFormatProperties2KHR);
193
WSI_CB(GetPhysicalDeviceImageFormatProperties2);
194
WSI_CB(ResetFences);
195
WSI_CB(QueueSubmit);
196
WSI_CB(WaitForFences);
197
WSI_CB(MapMemory);
198
WSI_CB(UnmapMemory);
199
#undef WSI_CB
200
201
struct wsi_interface * wsi[VK_ICD_WSI_PLATFORM_MAX];
202
};
203
204
typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
205
206
VkResult
207
wsi_device_init(struct wsi_device *wsi,
208
VkPhysicalDevice pdevice,
209
WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
210
const VkAllocationCallbacks *alloc,
211
int display_fd,
212
const struct driOptionCache *dri_options,
213
bool sw_device);
214
215
void
216
wsi_device_finish(struct wsi_device *wsi,
217
const VkAllocationCallbacks *alloc);
218
219
#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType) \
220
\
221
static inline __VkIcdType * \
222
__VkIcdType ## _from_handle(__VkType _handle) \
223
{ \
224
return (__VkIcdType *)(uintptr_t) _handle; \
225
} \
226
\
227
static inline __VkType \
228
__VkIcdType ## _to_handle(__VkIcdType *_obj) \
229
{ \
230
return (__VkType)(uintptr_t) _obj; \
231
}
232
233
#define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
234
__VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
235
236
ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
237
238
VkResult
239
wsi_common_get_surface_support(struct wsi_device *wsi_device,
240
uint32_t queueFamilyIndex,
241
VkSurfaceKHR surface,
242
VkBool32* pSupported);
243
244
VkResult
245
wsi_common_get_surface_capabilities(struct wsi_device *wsi_device,
246
VkSurfaceKHR surface,
247
VkSurfaceCapabilitiesKHR *pSurfaceCapabilities);
248
249
VkResult
250
wsi_common_get_surface_capabilities2(struct wsi_device *wsi_device,
251
const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
252
VkSurfaceCapabilities2KHR *pSurfaceCapabilities);
253
254
VkResult
255
wsi_common_get_surface_formats(struct wsi_device *wsi_device,
256
VkSurfaceKHR surface,
257
uint32_t *pSurfaceFormatCount,
258
VkSurfaceFormatKHR *pSurfaceFormats);
259
260
VkResult
261
wsi_common_get_surface_formats2(struct wsi_device *wsi_device,
262
const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
263
uint32_t *pSurfaceFormatCount,
264
VkSurfaceFormat2KHR *pSurfaceFormats);
265
266
VkResult
267
wsi_common_get_surface_present_modes(struct wsi_device *wsi_device,
268
VkSurfaceKHR surface,
269
uint32_t *pPresentModeCount,
270
VkPresentModeKHR *pPresentModes);
271
272
VkResult
273
wsi_common_get_present_rectangles(struct wsi_device *wsi,
274
VkSurfaceKHR surface,
275
uint32_t* pRectCount,
276
VkRect2D* pRects);
277
278
VkResult
279
wsi_common_get_surface_capabilities2ext(
280
struct wsi_device *wsi_device,
281
VkSurfaceKHR surface,
282
VkSurfaceCapabilities2EXT *pSurfaceCapabilities);
283
284
VkResult
285
wsi_common_get_images(VkSwapchainKHR _swapchain,
286
uint32_t *pSwapchainImageCount,
287
VkImage *pSwapchainImages);
288
289
VkResult
290
wsi_common_acquire_next_image2(const struct wsi_device *wsi,
291
VkDevice device,
292
const VkAcquireNextImageInfoKHR *pAcquireInfo,
293
uint32_t *pImageIndex);
294
295
VkResult
296
wsi_common_create_swapchain(struct wsi_device *wsi,
297
VkDevice device,
298
const VkSwapchainCreateInfoKHR *pCreateInfo,
299
const VkAllocationCallbacks *pAllocator,
300
VkSwapchainKHR *pSwapchain);
301
void
302
wsi_common_destroy_swapchain(VkDevice device,
303
VkSwapchainKHR swapchain,
304
const VkAllocationCallbacks *pAllocator);
305
306
VkResult
307
wsi_common_queue_present(const struct wsi_device *wsi,
308
VkDevice device_h,
309
VkQueue queue_h,
310
int queue_family_index,
311
const VkPresentInfoKHR *pPresentInfo);
312
313
uint64_t
314
wsi_common_get_current_time(void);
315
316
#endif
317
318