Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/amd/vulkan/radv_wsi.c
7204 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 DEALINGS
23
* IN THE SOFTWARE.
24
*/
25
26
#include "util/macros.h"
27
#include "radv_meta.h"
28
#include "radv_private.h"
29
#include "vk_util.h"
30
#include "wsi_common.h"
31
32
static PFN_vkVoidFunction
33
radv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
34
{
35
RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
36
return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);
37
}
38
39
static void
40
radv_wsi_set_memory_ownership(VkDevice _device, VkDeviceMemory _mem, VkBool32 ownership)
41
{
42
RADV_FROM_HANDLE(radv_device, device, _device);
43
RADV_FROM_HANDLE(radv_device_memory, mem, _mem);
44
45
if (device->use_global_bo_list) {
46
device->ws->buffer_make_resident(device->ws, mem->bo, ownership);
47
}
48
}
49
50
VkResult
51
radv_init_wsi(struct radv_physical_device *physical_device)
52
{
53
VkResult result =
54
wsi_device_init(&physical_device->wsi_device, radv_physical_device_to_handle(physical_device),
55
radv_wsi_proc_addr, &physical_device->instance->vk.alloc,
56
physical_device->master_fd, &physical_device->instance->dri_options, false);
57
if (result != VK_SUCCESS)
58
return result;
59
60
physical_device->wsi_device.supports_modifiers = physical_device->rad_info.chip_class >= GFX9;
61
physical_device->wsi_device.set_memory_ownership = radv_wsi_set_memory_ownership;
62
return VK_SUCCESS;
63
}
64
65
void
66
radv_finish_wsi(struct radv_physical_device *physical_device)
67
{
68
wsi_device_finish(&physical_device->wsi_device, &physical_device->instance->vk.alloc);
69
}
70
71
void
72
radv_DestroySurfaceKHR(VkInstance _instance, VkSurfaceKHR _surface,
73
const VkAllocationCallbacks *pAllocator)
74
{
75
RADV_FROM_HANDLE(radv_instance, instance, _instance);
76
ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, _surface);
77
78
vk_free2(&instance->vk.alloc, pAllocator, surface);
79
}
80
81
VkResult
82
radv_GetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
83
VkSurfaceKHR surface, VkBool32 *pSupported)
84
{
85
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
86
87
return wsi_common_get_surface_support(&device->wsi_device, queueFamilyIndex, surface,
88
pSupported);
89
}
90
91
VkResult
92
radv_GetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
93
VkSurfaceCapabilitiesKHR *pSurfaceCapabilities)
94
{
95
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
96
97
return wsi_common_get_surface_capabilities(&device->wsi_device, surface, pSurfaceCapabilities);
98
}
99
100
VkResult
101
radv_GetPhysicalDeviceSurfaceCapabilities2KHR(VkPhysicalDevice physicalDevice,
102
const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
103
VkSurfaceCapabilities2KHR *pSurfaceCapabilities)
104
{
105
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
106
107
return wsi_common_get_surface_capabilities2(&device->wsi_device, pSurfaceInfo,
108
pSurfaceCapabilities);
109
}
110
111
VkResult
112
radv_GetPhysicalDeviceSurfaceCapabilities2EXT(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
113
VkSurfaceCapabilities2EXT *pSurfaceCapabilities)
114
{
115
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
116
117
return wsi_common_get_surface_capabilities2ext(&device->wsi_device, surface,
118
pSurfaceCapabilities);
119
}
120
121
VkResult
122
radv_GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
123
uint32_t *pSurfaceFormatCount,
124
VkSurfaceFormatKHR *pSurfaceFormats)
125
{
126
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
127
128
return wsi_common_get_surface_formats(&device->wsi_device, surface, pSurfaceFormatCount,
129
pSurfaceFormats);
130
}
131
132
VkResult
133
radv_GetPhysicalDeviceSurfaceFormats2KHR(VkPhysicalDevice physicalDevice,
134
const VkPhysicalDeviceSurfaceInfo2KHR *pSurfaceInfo,
135
uint32_t *pSurfaceFormatCount,
136
VkSurfaceFormat2KHR *pSurfaceFormats)
137
{
138
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
139
140
return wsi_common_get_surface_formats2(&device->wsi_device, pSurfaceInfo, pSurfaceFormatCount,
141
pSurfaceFormats);
142
}
143
144
VkResult
145
radv_GetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
146
uint32_t *pPresentModeCount,
147
VkPresentModeKHR *pPresentModes)
148
{
149
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
150
151
return wsi_common_get_surface_present_modes(&device->wsi_device, surface, pPresentModeCount,
152
pPresentModes);
153
}
154
155
VkResult
156
radv_CreateSwapchainKHR(VkDevice _device, const VkSwapchainCreateInfoKHR *pCreateInfo,
157
const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain)
158
{
159
RADV_FROM_HANDLE(radv_device, device, _device);
160
const VkAllocationCallbacks *alloc;
161
if (pAllocator)
162
alloc = pAllocator;
163
else
164
alloc = &device->vk.alloc;
165
166
return wsi_common_create_swapchain(&device->physical_device->wsi_device,
167
radv_device_to_handle(device), pCreateInfo, alloc,
168
pSwapchain);
169
}
170
171
void
172
radv_DestroySwapchainKHR(VkDevice _device, VkSwapchainKHR swapchain,
173
const VkAllocationCallbacks *pAllocator)
174
{
175
RADV_FROM_HANDLE(radv_device, device, _device);
176
const VkAllocationCallbacks *alloc;
177
178
if (pAllocator)
179
alloc = pAllocator;
180
else
181
alloc = &device->vk.alloc;
182
183
wsi_common_destroy_swapchain(_device, swapchain, alloc);
184
}
185
186
VkResult
187
radv_GetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapchain,
188
uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages)
189
{
190
return wsi_common_get_images(swapchain, pSwapchainImageCount, pSwapchainImages);
191
}
192
193
VkResult
194
radv_AcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapchain, uint64_t timeout,
195
VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex)
196
{
197
VkAcquireNextImageInfoKHR acquire_info = {
198
.sType = VK_STRUCTURE_TYPE_ACQUIRE_NEXT_IMAGE_INFO_KHR,
199
.swapchain = swapchain,
200
.timeout = timeout,
201
.semaphore = semaphore,
202
.fence = fence,
203
.deviceMask = 0,
204
};
205
206
return radv_AcquireNextImage2KHR(device, &acquire_info, pImageIndex);
207
}
208
209
VkResult
210
radv_AcquireNextImage2KHR(VkDevice _device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
211
uint32_t *pImageIndex)
212
{
213
RADV_FROM_HANDLE(radv_device, device, _device);
214
struct radv_physical_device *pdevice = device->physical_device;
215
RADV_FROM_HANDLE(radv_fence, fence, pAcquireInfo->fence);
216
RADV_FROM_HANDLE(radv_semaphore, semaphore, pAcquireInfo->semaphore);
217
218
VkResult result =
219
wsi_common_acquire_next_image2(&pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
220
221
if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) {
222
if (fence) {
223
struct radv_fence_part *part =
224
fence->temporary.kind != RADV_FENCE_NONE ? &fence->temporary : &fence->permanent;
225
226
device->ws->signal_syncobj(device->ws, part->syncobj, 0);
227
}
228
if (semaphore) {
229
struct radv_semaphore_part *part = semaphore->temporary.kind != RADV_SEMAPHORE_NONE
230
? &semaphore->temporary
231
: &semaphore->permanent;
232
233
switch (part->kind) {
234
case RADV_SEMAPHORE_NONE:
235
/* Do not need to do anything. */
236
break;
237
case RADV_SEMAPHORE_TIMELINE:
238
case RADV_SEMAPHORE_TIMELINE_SYNCOBJ:
239
unreachable("WSI only allows binary semaphores.");
240
case RADV_SEMAPHORE_SYNCOBJ:
241
device->ws->signal_syncobj(device->ws, part->syncobj, 0);
242
break;
243
}
244
}
245
}
246
return result;
247
}
248
249
VkResult
250
radv_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo)
251
{
252
RADV_FROM_HANDLE(radv_queue, queue, _queue);
253
return wsi_common_queue_present(&queue->device->physical_device->wsi_device,
254
radv_device_to_handle(queue->device), _queue,
255
queue->queue_family_index, pPresentInfo);
256
}
257
258
VkResult
259
radv_GetDeviceGroupPresentCapabilitiesKHR(VkDevice device,
260
VkDeviceGroupPresentCapabilitiesKHR *pCapabilities)
261
{
262
memset(pCapabilities->presentMask, 0, sizeof(pCapabilities->presentMask));
263
pCapabilities->presentMask[0] = 0x1;
264
pCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
265
266
return VK_SUCCESS;
267
}
268
269
VkResult
270
radv_GetDeviceGroupSurfacePresentModesKHR(VkDevice device, VkSurfaceKHR surface,
271
VkDeviceGroupPresentModeFlagsKHR *pModes)
272
{
273
*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
274
275
return VK_SUCCESS;
276
}
277
278
VkResult
279
radv_GetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
280
uint32_t *pRectCount, VkRect2D *pRects)
281
{
282
RADV_FROM_HANDLE(radv_physical_device, device, physicalDevice);
283
284
return wsi_common_get_present_rectangles(&device->wsi_device, surface, pRectCount, pRects);
285
}
286
287