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