~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/vulkan/wsi/wsi_common.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 "vk_dispatch_table.h"
31
 
#include <vulkan/vulkan.h>
32
 
#include <vulkan/vk_icd.h>
33
 
 
34
 
#ifdef __cplusplus
35
 
extern "C" {
36
 
#endif
37
 
 
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;
42
 
#endif
43
 
 
44
 
#include <util/list.h>
45
 
 
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.
48
 
 */
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
53
 
 
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.
57
 
 */
58
 
struct wsi_image_create_info {
59
 
    VkStructureType sType;
60
 
    const void *pNext;
61
 
    bool scanout;
62
 
 
63
 
    /* if true, the image is a buffer blit source */
64
 
    bool buffer_blit_src;
65
 
};
66
 
 
67
 
struct wsi_memory_allocate_info {
68
 
    VkStructureType sType;
69
 
    const void *pNext;
70
 
    bool implicit_sync;
71
 
};
72
 
 
73
 
/* To be chained into VkSurfaceCapabilities2KHR */
74
 
struct wsi_surface_supported_counters {
75
 
   VkStructureType sType;
76
 
   const void *pNext;
77
 
 
78
 
   VkSurfaceCounterFlagsEXT supported_surface_counters;
79
 
 
80
 
};
81
 
 
82
 
/* To be chained into VkSubmitInfo */
83
 
struct wsi_memory_signal_submit_info {
84
 
    VkStructureType sType;
85
 
    const void *pNext;
86
 
    VkDeviceMemory memory;
87
 
};
88
 
 
89
 
struct wsi_interface;
90
 
 
91
 
struct driOptionCache;
92
 
 
93
 
#define VK_ICD_WSI_PLATFORM_MAX (VK_ICD_WSI_PLATFORM_DISPLAY + 1)
94
 
 
95
 
struct wsi_device {
96
 
   /* Allocator for the instance */
97
 
   VkAllocationCallbacks instance_alloc;
98
 
 
99
 
   VkPhysicalDevice pdevice;
100
 
   VkPhysicalDeviceMemoryProperties memory_props;
101
 
   uint32_t queue_family_count;
102
 
 
103
 
   VkPhysicalDevicePCIBusInfoPropertiesEXT pci_bus_info;
104
 
 
105
 
   bool supports_modifiers;
106
 
   uint32_t maxImageDimension2D;
107
 
   VkPresentModeKHR override_present_mode;
108
 
   bool force_bgra8_unorm_first;
109
 
 
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;
113
 
 
114
 
   /* List of fences to signal when hotplug event happens. */
115
 
   struct list_head hotplug_fences;
116
 
 
117
 
   struct {
118
 
      /* Override the minimum number of images on the swapchain.
119
 
       * 0 = no override */
120
 
      uint32_t override_minImageCount;
121
 
 
122
 
      /* Forces strict number of image on the swapchain using application
123
 
       * provided VkSwapchainCreateInfoKH::RminImageCount.
124
 
       */
125
 
      bool strict_imageCount;
126
 
 
127
 
      /* Ensures to create at least the number of image specified by the
128
 
       * driver in VkSurfaceCapabilitiesKHR::minImageCount.
129
 
       */
130
 
      bool ensure_minImageCount;
131
 
 
132
 
      /* Wait for fences before submitting buffers to Xwayland. Defaults to
133
 
       * true.
134
 
       */
135
 
      bool xwaylandWaitReady;
136
 
   } x11;
137
 
 
138
 
   bool sw;
139
 
 
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.
144
 
    */
145
 
   bool signal_semaphore_with_memory;
146
 
 
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.
152
 
    */
153
 
   bool signal_fence_with_memory;
154
 
 
155
 
   /*
156
 
    * This sets the ownership for a WSI memory object:
157
 
    *
158
 
    * The ownership is true if and only if the application is allowed to submit
159
 
    * command buffers that reference the buffer.
160
 
    *
161
 
    * This can be used to prune BO lists without too many adverse affects on
162
 
    * implicit sync.
163
 
    *
164
 
    * Side note: care needs to be taken for internally delayed submissions wrt
165
 
    * timeline semaphores.
166
 
    */
167
 
   void (*set_memory_ownership)(VkDevice device,
168
 
                                VkDeviceMemory memory,
169
 
                                VkBool32 ownership);
170
 
 
171
 
   /*
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.
174
 
    */
175
 
   bool (*can_present_on_device)(VkPhysicalDevice pdevice, int fd);
176
 
 
177
 
   /*
178
 
    * A driver can implement this callback to return a special queue to execute
179
 
    * buffer blits.
180
 
    */
181
 
   VkQueue (*get_buffer_blit_queue)(VkDevice device);
182
 
 
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);
193
 
   WSI_CB(CreateFence);
194
 
   WSI_CB(CreateImage);
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);
202
 
   WSI_CB(FreeMemory);
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);
212
 
   WSI_CB(ResetFences);
213
 
   WSI_CB(QueueSubmit);
214
 
   WSI_CB(WaitForFences);
215
 
   WSI_CB(MapMemory);
216
 
   WSI_CB(UnmapMemory);
217
 
#undef WSI_CB
218
 
 
219
 
    struct wsi_interface *                  wsi[VK_ICD_WSI_PLATFORM_MAX];
220
 
};
221
 
 
222
 
typedef PFN_vkVoidFunction (VKAPI_PTR *WSI_FN_GetPhysicalDeviceProcAddr)(VkPhysicalDevice physicalDevice, const char* pName);
223
 
 
224
 
VkResult
225
 
wsi_device_init(struct wsi_device *wsi,
226
 
                VkPhysicalDevice pdevice,
227
 
                WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
228
 
                const VkAllocationCallbacks *alloc,
229
 
                int display_fd,
230
 
                const struct driOptionCache *dri_options,
231
 
                bool sw_device);
232
 
 
233
 
void
234
 
wsi_device_finish(struct wsi_device *wsi,
235
 
                  const VkAllocationCallbacks *alloc);
236
 
 
237
 
/* Setup file descriptor to be used with imported sync_fd's in wsi fences. */
238
 
void
239
 
wsi_device_setup_syncobj_fd(struct wsi_device *wsi_device,
240
 
                            int fd);
241
 
 
242
 
#define ICD_DEFINE_NONDISP_HANDLE_CASTS(__VkIcdType, __VkType)             \
243
 
                                                                           \
244
 
   static inline __VkIcdType *                                             \
245
 
   __VkIcdType ## _from_handle(__VkType _handle)                           \
246
 
   {                                                                       \
247
 
      return (__VkIcdType *)(uintptr_t) _handle;                           \
248
 
   }                                                                       \
249
 
                                                                           \
250
 
   static inline __VkType                                                  \
251
 
   __VkIcdType ## _to_handle(__VkIcdType *_obj)                            \
252
 
   {                                                                       \
253
 
      return (__VkType)(uintptr_t) _obj;                                   \
254
 
   }
255
 
 
256
 
#define ICD_FROM_HANDLE(__VkIcdType, __name, __handle) \
257
 
   __VkIcdType *__name = __VkIcdType ## _from_handle(__handle)
258
 
 
259
 
ICD_DEFINE_NONDISP_HANDLE_CASTS(VkIcdSurfaceBase, VkSurfaceKHR)
260
 
 
261
 
VkResult
262
 
wsi_common_get_images(VkSwapchainKHR _swapchain,
263
 
                      uint32_t *pSwapchainImageCount,
264
 
                      VkImage *pSwapchainImages);
265
 
 
266
 
VkImage
267
 
wsi_common_get_image(VkSwapchainKHR _swapchain, uint32_t index);
268
 
 
269
 
VkResult
270
 
wsi_common_acquire_next_image2(const struct wsi_device *wsi,
271
 
                               VkDevice device,
272
 
                               const VkAcquireNextImageInfoKHR *pAcquireInfo,
273
 
                               uint32_t *pImageIndex);
274
 
 
275
 
VkResult
276
 
wsi_common_queue_present(const struct wsi_device *wsi,
277
 
                         VkDevice device_h,
278
 
                         VkQueue queue_h,
279
 
                         int queue_family_index,
280
 
                         const VkPresentInfoKHR *pPresentInfo);
281
 
 
282
 
VkResult
283
 
wsi_common_create_swapchain_image(const struct wsi_device *wsi,
284
 
                                  const VkImageCreateInfo *pCreateInfo,
285
 
                                  VkSwapchainKHR _swapchain,
286
 
                                  VkImage *pImage);
287
 
VkResult
288
 
wsi_common_bind_swapchain_image(const struct wsi_device *wsi,
289
 
                                VkImage vk_image,
290
 
                                VkSwapchainKHR _swapchain,
291
 
                                uint32_t image_idx);
292
 
 
293
 
#ifdef __cplusplus
294
 
}
295
 
#endif
296
 
 
297
 
#endif