Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/frontends/lavapipe/lvp_wsi.c
4565 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
24
#include "lvp_wsi.h"
25
26
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
27
lvp_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
28
{
29
LVP_FROM_HANDLE(lvp_physical_device, pdevice, physicalDevice);
30
PFN_vkVoidFunction func;
31
32
func = vk_instance_dispatch_table_get(&pdevice->vk.instance->dispatch_table, pName);
33
if (func != NULL)
34
return func;
35
36
func = vk_physical_device_dispatch_table_get(&pdevice->vk.dispatch_table, pName);
37
if (func != NULL)
38
return func;
39
40
return vk_device_dispatch_table_get(&vk_device_trampolines, pName);
41
}
42
43
VkResult
44
lvp_init_wsi(struct lvp_physical_device *physical_device)
45
{
46
return wsi_device_init(&physical_device->wsi_device,
47
lvp_physical_device_to_handle(physical_device),
48
lvp_wsi_proc_addr,
49
&physical_device->vk.instance->alloc,
50
-1, NULL, true);
51
}
52
53
void
54
lvp_finish_wsi(struct lvp_physical_device *physical_device)
55
{
56
wsi_device_finish(&physical_device->wsi_device,
57
&physical_device->vk.instance->alloc);
58
}
59
60
VKAPI_ATTR void VKAPI_CALL lvp_DestroySurfaceKHR(
61
VkInstance _instance,
62
VkSurfaceKHR _surface,
63
const VkAllocationCallbacks* pAllocator)
64
{
65
LVP_FROM_HANDLE(lvp_instance, instance, _instance);
66
ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
67
68
vk_free2(&instance->vk.alloc, pAllocator, surface);
69
}
70
71
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceSupportKHR(
72
VkPhysicalDevice physicalDevice,
73
uint32_t queueFamilyIndex,
74
VkSurfaceKHR surface,
75
VkBool32* pSupported)
76
{
77
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
78
79
return wsi_common_get_surface_support(&device->wsi_device,
80
queueFamilyIndex,
81
surface,
82
pSupported);
83
}
84
85
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceCapabilitiesKHR(
86
VkPhysicalDevice physicalDevice,
87
VkSurfaceKHR surface,
88
VkSurfaceCapabilitiesKHR* pSurfaceCapabilities)
89
{
90
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
91
92
return wsi_common_get_surface_capabilities(&device->wsi_device,
93
surface,
94
pSurfaceCapabilities);
95
}
96
97
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceCapabilities2KHR(
98
VkPhysicalDevice physicalDevice,
99
const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
100
VkSurfaceCapabilities2KHR* pSurfaceCapabilities)
101
{
102
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
103
104
return wsi_common_get_surface_capabilities2(&device->wsi_device,
105
pSurfaceInfo,
106
pSurfaceCapabilities);
107
}
108
109
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceCapabilities2EXT(
110
VkPhysicalDevice physicalDevice,
111
VkSurfaceKHR surface,
112
VkSurfaceCapabilities2EXT* pSurfaceCapabilities)
113
{
114
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
115
116
return wsi_common_get_surface_capabilities2ext(&device->wsi_device,
117
surface,
118
pSurfaceCapabilities);
119
}
120
121
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceFormatsKHR(
122
VkPhysicalDevice physicalDevice,
123
VkSurfaceKHR surface,
124
uint32_t* pSurfaceFormatCount,
125
VkSurfaceFormatKHR* pSurfaceFormats)
126
{
127
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
128
return wsi_common_get_surface_formats(&device->wsi_device,
129
surface,
130
pSurfaceFormatCount,
131
pSurfaceFormats);
132
}
133
134
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfaceFormats2KHR(
135
VkPhysicalDevice physicalDevice,
136
const VkPhysicalDeviceSurfaceInfo2KHR* pSurfaceInfo,
137
uint32_t* pSurfaceFormatCount,
138
VkSurfaceFormat2KHR* pSurfaceFormats)
139
{
140
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
141
142
return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo,
143
pSurfaceFormatCount, pSurfaceFormats);
144
}
145
146
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDeviceSurfacePresentModesKHR(
147
VkPhysicalDevice physicalDevice,
148
VkSurfaceKHR surface,
149
uint32_t* pPresentModeCount,
150
VkPresentModeKHR* pPresentModes)
151
{
152
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
153
154
return wsi_common_get_surface_present_modes(&device->wsi_device,
155
surface,
156
pPresentModeCount,
157
pPresentModes);
158
}
159
160
VKAPI_ATTR VkResult VKAPI_CALL lvp_CreateSwapchainKHR(
161
VkDevice _device,
162
const VkSwapchainCreateInfoKHR* pCreateInfo,
163
const VkAllocationCallbacks* pAllocator,
164
VkSwapchainKHR* pSwapchain)
165
{
166
LVP_FROM_HANDLE(lvp_device, device, _device);
167
const VkAllocationCallbacks *alloc;
168
if (pAllocator)
169
alloc = pAllocator;
170
else
171
alloc = &device->vk.alloc;
172
173
return wsi_common_create_swapchain(&device->physical_device->wsi_device,
174
lvp_device_to_handle(device),
175
pCreateInfo,
176
alloc,
177
pSwapchain);
178
}
179
180
VKAPI_ATTR void VKAPI_CALL lvp_DestroySwapchainKHR(
181
VkDevice _device,
182
VkSwapchainKHR swapchain,
183
const VkAllocationCallbacks* pAllocator)
184
{
185
LVP_FROM_HANDLE(lvp_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 lvp_GetSwapchainImagesKHR(
197
VkDevice device,
198
VkSwapchainKHR swapchain,
199
uint32_t* pSwapchainImageCount,
200
VkImage* pSwapchainImages)
201
{
202
return wsi_common_get_images(swapchain,
203
pSwapchainImageCount,
204
pSwapchainImages);
205
}
206
207
VKAPI_ATTR VkResult VKAPI_CALL lvp_AcquireNextImageKHR(
208
VkDevice device,
209
VkSwapchainKHR swapchain,
210
uint64_t timeout,
211
VkSemaphore semaphore,
212
VkFence fence,
213
uint32_t* pImageIndex)
214
{
215
VkAcquireNextImageInfoKHR acquire_info = {
216
.sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,
217
.swapchain = swapchain,
218
.timeout = timeout,
219
.semaphore = semaphore,
220
.fence = fence,
221
.deviceMask = 0,
222
};
223
224
return lvp_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);
225
}
226
227
VKAPI_ATTR VkResult VKAPI_CALL lvp_AcquireNextImage2KHR(
228
VkDevice _device,
229
const VkAcquireNextImageInfoKHR* pAcquireInfo,
230
uint32_t* pImageIndex)
231
{
232
LVP_FROM_HANDLE(lvp_device, device, _device);
233
struct lvp_physical_device *pdevice = device->physical_device;
234
235
VkResult result = wsi_common_acquire_next_image2(&pdevice->wsi_device,
236
_device,
237
pAcquireInfo,
238
pImageIndex);
239
240
LVP_FROM_HANDLE(lvp_fence, fence, pAcquireInfo->fence);
241
242
if (fence && (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR)) {
243
fence->signaled = true;
244
}
245
return result;
246
}
247
248
VKAPI_ATTR VkResult VKAPI_CALL lvp_QueuePresentKHR(
249
VkQueue _queue,
250
const VkPresentInfoKHR* pPresentInfo)
251
{
252
LVP_FROM_HANDLE(lvp_queue, queue, _queue);
253
return wsi_common_queue_present(&queue->device->physical_device->wsi_device,
254
lvp_device_to_handle(queue->device),
255
_queue, 0,
256
pPresentInfo);
257
}
258
259
260
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetDeviceGroupPresentCapabilitiesKHR(
261
VkDevice device,
262
VkDeviceGroupPresentCapabilitiesKHR* pCapabilities)
263
{
264
memset(pCapabilities->presentMask, 0,
265
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
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetDeviceGroupSurfacePresentModesKHR(
273
VkDevice device,
274
VkSurfaceKHR surface,
275
VkDeviceGroupPresentModeFlagsKHR* pModes)
276
{
277
*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
278
279
return VK_SUCCESS;
280
}
281
282
VKAPI_ATTR VkResult VKAPI_CALL lvp_GetPhysicalDevicePresentRectanglesKHR(
283
VkPhysicalDevice physicalDevice,
284
VkSurfaceKHR surface,
285
uint32_t* pRectCount,
286
VkRect2D* pRects)
287
{
288
LVP_FROM_HANDLE(lvp_physical_device, device, physicalDevice);
289
290
return wsi_common_get_present_rectangles(&device->wsi_device,
291
surface,
292
pRectCount, pRects);
293
}
294
295