Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/freedreno/vulkan/tu_wsi.c
4565 views
1
/*
2
* Copyright © 2016 Red Hat
3
* based on intel anv code:
4
* Copyright © 2015 Intel Corporation
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the "Software"),
8
* to deal in the Software without restriction, including without limitation
9
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
* and/or sell copies of the Software, and to permit persons to whom the
11
* Software is furnished to do so, subject to the following conditions:
12
*
13
* The above copyright notice and this permission notice (including the next
14
* paragraph) shall be included in all copies or substantial portions of the
15
* Software.
16
*
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
* DEALINGS IN THE SOFTWARE.
24
*/
25
26
#include "tu_private.h"
27
28
#include "vk_util.h"
29
#include "wsi_common.h"
30
#include "drm-uapi/drm_fourcc.h"
31
32
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
33
tu_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
34
{
35
TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice);
36
return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);
37
}
38
39
VkResult
40
tu_wsi_init(struct tu_physical_device *physical_device)
41
{
42
VkResult result;
43
44
result = wsi_device_init(&physical_device->wsi_device,
45
tu_physical_device_to_handle(physical_device),
46
tu_wsi_proc_addr,
47
&physical_device->instance->vk.alloc,
48
physical_device->master_fd, NULL,
49
false);
50
if (result != VK_SUCCESS)
51
return result;
52
53
physical_device->wsi_device.supports_modifiers = true;
54
55
return VK_SUCCESS;
56
}
57
58
void
59
tu_wsi_finish(struct tu_physical_device *physical_device)
60
{
61
wsi_device_finish(&physical_device->wsi_device,
62
&physical_device->instance->vk.alloc);
63
}
64
65
VKAPI_ATTR void VKAPI_CALL
66
tu_DestroySurfaceKHR(VkInstance _instance,
67
VkSurfaceKHR _surface,
68
const VkAllocationCallbacks *pAllocator)
69
{
70
TU_FROM_HANDLE(tu_instance, instance, _instance);
71
ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
72
73
vk_free2(&instance->vk.alloc, pAllocator, surface);
74
}
75
76
VKAPI_ATTR VkResult VKAPI_CALL
77
tu_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice,
78
uint32_t queueFamilyIndex,
79
VkSurfaceKHR surface,
80
VkBool32 *pSupported)
81
{
82
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
83
84
return wsi_common_get_surface_support(
85
&device->wsi_device, queueFamilyIndex, surface, pSupported);
86
}
87
88
VKAPI_ATTR VkResult VKAPI_CALL
89
tu_GetPhysicalDeviceSurfaceCapabilitiesKHR(
90
VkPhysicalDevice physicalDevice,
91
VkSurfaceKHR surface,
92
VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
93
{
94
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
95
96
return wsi_common_get_surface_capabilities(&device->wsi_device, surface,
97
pSurfaceCapabilities);
98
}
99
100
VKAPI_ATTR VkResult VKAPI_CALL
101
tu_GetPhysicalDeviceSurfaceCapabilities2KHR(
102
VkPhysicalDevice physicalDevice,
103
const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
104
VkSurfaceCapabilities2KHR *pSurfaceCapabilities)
105
{
106
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
107
108
return wsi_common_get_surface_capabilities2(
109
&device->wsi_device, pSurfaceInfo, pSurfaceCapabilities);
110
}
111
112
VKAPI_ATTR VkResult VKAPI_CALL
113
tu_GetPhysicalDeviceSurfaceCapabilities2EXT(
114
VkPhysicalDevice physicalDevice,
115
VkSurfaceKHR surface,
116
VkSurfaceCapabilities2EXT *pSurfaceCapabilities)
117
{
118
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
119
120
return wsi_common_get_surface_capabilities2ext(
121
&device->wsi_device, surface, pSurfaceCapabilities);
122
}
123
124
VKAPI_ATTR VkResult VKAPI_CALL
125
tu_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice,
126
VkSurfaceKHR surface,
127
uint32_t *pSurfaceFormatCount,
128
VkSurfaceFormatKHR *pSurfaceFormats)
129
{
130
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
131
132
return wsi_common_get_surface_formats(
133
&device->wsi_device, surface, pSurfaceFormatCount, pSurfaceFormats);
134
}
135
136
VKAPI_ATTR VkResult VKAPI_CALL
137
tu_GetPhysicalDeviceSurfaceFormats2KHR(
138
VkPhysicalDevice physicalDevice,
139
const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
140
uint32_t *pSurfaceFormatCount,
141
VkSurfaceFormat2KHR *pSurfaceFormats)
142
{
143
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
144
145
return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,
146
pSurfaceFormatCount,
147
pSurfaceFormats);
148
}
149
150
VKAPI_ATTR VkResult VKAPI_CALL
151
tu_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice,
152
VkSurfaceKHR surface,
153
uint32_t *pPresentModeCount,
154
VkPresentModeKHR *pPresentModes)
155
{
156
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
157
158
return wsi_common_get_surface_present_modes(
159
&device->wsi_device, surface, pPresentModeCount, pPresentModes);
160
}
161
162
VKAPI_ATTR VkResult VKAPI_CALL
163
tu_CreateSwapchainKHR(VkDevice _device,
164
const VkSwapchainCreateInfoKHR *pCreateInfo,
165
const VkAllocationCallbacks *pAllocator,
166
VkSwapchainKHR *pSwapchain)
167
{
168
TU_FROM_HANDLE(tu_device, device, _device);
169
const VkAllocationCallbacks *alloc;
170
if (pAllocator)
171
alloc = pAllocator;
172
else
173
alloc = &device->vk.alloc;
174
175
return wsi_common_create_swapchain(&device->physical_device->wsi_device,
176
tu_device_to_handle(device),
177
pCreateInfo, alloc, pSwapchain);
178
}
179
180
VKAPI_ATTR void VKAPI_CALL
181
tu_DestroySwapchainKHR(VkDevice _device,
182
VkSwapchainKHR swapchain,
183
const VkAllocationCallbacks *pAllocator)
184
{
185
TU_FROM_HANDLE(tu_device, device, _device);
186
const VkAllocationCallbacks *alloc;
187
188
if (pAllocator)
189
alloc = pAllocator;
190
else
191
alloc = &device->vk.alloc;
192
193
wsi_common_destroy_swapchain(_device, swapchain, alloc);
194
}
195
196
VKAPI_ATTR VkResult VKAPI_CALL
197
tu_GetSwapchainImagesKHR(VkDevice device,
198
VkSwapchainKHR swapchain,
199
uint32_t *pSwapchainImageCount,
200
VkImage *pSwapchainImages)
201
{
202
return wsi_common_get_images(swapchain, pSwapchainImageCount,
203
pSwapchainImages);
204
}
205
206
VKAPI_ATTR VkResult VKAPI_CALL
207
tu_AcquireNextImageKHR(VkDevice device,
208
VkSwapchainKHR swapchain,
209
uint64_t timeout,
210
VkSemaphore semaphore,
211
VkFence fence,
212
uint32_t *pImageIndex)
213
{
214
VkAcquireNextImageInfoKHR acquire_info = {
215
.sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,
216
.swapchain = swapchain,
217
.timeout = timeout,
218
.semaphore = semaphore,
219
.fence = fence,
220
.deviceMask = 0,
221
};
222
223
return tu_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);
224
}
225
226
VKAPI_ATTR VkResult VKAPI_CALL
227
tu_AcquireNextImage2KHR(VkDevice _device,
228
const VkAcquireNextImageInfoKHR *pAcquireInfo,
229
uint32_t *pImageIndex)
230
{
231
TU_FROM_HANDLE(tu_device, device, _device);
232
TU_FROM_HANDLE(tu_syncobj, fence, pAcquireInfo->fence);
233
TU_FROM_HANDLE(tu_syncobj, semaphore, pAcquireInfo->semaphore);
234
235
struct tu_physical_device *pdevice = device->physical_device;
236
237
VkResult result = wsi_common_acquire_next_image2(
238
&pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
239
240
/* signal fence/semaphore - image is available immediately */
241
tu_signal_fences(device, fence, semaphore);
242
243
return result;
244
}
245
246
VKAPI_ATTR VkResult VKAPI_CALL
247
tu_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
248
{
249
TU_FROM_HANDLE(tu_queue, queue, _queue);
250
return wsi_common_queue_present(
251
&queue->device->physical_device->wsi_device,
252
tu_device_to_handle(queue->device), _queue, queue->queue_family_index,
253
pPresentInfo);
254
}
255
256
VKAPI_ATTR VkResult VKAPI_CALL
257
tu_GetDeviceGroupPresentCapabilitiesKHR(
258
VkDevice device, VkDeviceGroupPresentCapabilitiesKHR *pCapabilities)
259
{
260
memset(pCapabilities->presentMask, 0, sizeof(pCapabilities->presentMask));
261
pCapabilities->presentMask[0] = 0x1;
262
pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
263
264
return VK_SUCCESS;
265
}
266
267
VKAPI_ATTR VkResult VKAPI_CALL
268
tu_GetDeviceGroupSurfacePresentModesKHR(
269
VkDevice device,
270
VkSurfaceKHR surface,
271
VkDeviceGroupPresentModeFlagsKHR *pModes)
272
{
273
*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
274
275
return VK_SUCCESS;
276
}
277
278
VKAPI_ATTR VkResult VKAPI_CALL
279
tu_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice,
280
VkSurfaceKHR surface,
281
uint32_t *pRectCount,
282
VkRect2D *pRects)
283
{
284
TU_FROM_HANDLE(tu_physical_device, device, physicalDevice);
285
286
return wsi_common_get_present_rectangles(&device->wsi_device, surface,
287
pRectCount, pRects);
288
}
289
290