Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/amd/vulkan/radv_wsi_display.c
7354 views
1
/*
2
* Copyright © 2017 Keith Packard
3
*
4
* Permission to use, copy, modify, distribute, and sell this software and its
5
* documentation for any purpose is hereby granted without fee, provided that
6
* the above copyright notice appear in all copies and that both that copyright
7
* notice and this permission notice appear in supporting documentation, and
8
* that the name of the copyright holders not be used in advertising or
9
* publicity pertaining to distribution of the software without specific,
10
* written prior permission. The copyright holders make no representations
11
* about the suitability of this software for any purpose. It is provided "as
12
* is" without express or implied warranty.
13
*
14
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
20
* OF THIS SOFTWARE.
21
*/
22
23
#include <amdgpu.h>
24
#include <fcntl.h>
25
#include <stdbool.h>
26
#include <string.h>
27
#include <unistd.h>
28
#include <xf86drm.h>
29
#include <xf86drmMode.h>
30
#include "drm-uapi/amdgpu_drm.h"
31
#include "util/debug.h"
32
#include "util/disk_cache.h"
33
#include "util/strtod.h"
34
#include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
35
#include "radv_cs.h"
36
#include "radv_private.h"
37
#include "sid.h"
38
#include "vk_format.h"
39
#include "vk_util.h"
40
#include "wsi_common_display.h"
41
42
#define MM_PER_PIXEL (1.0 / 96.0 * 25.4)
43
44
VkResult
45
radv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,
46
uint32_t *property_count,
47
VkDisplayPropertiesKHR *properties)
48
{
49
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
50
51
return wsi_display_get_physical_device_display_properties(physical_device, &pdevice->wsi_device,
52
property_count, properties);
53
}
54
55
VkResult
56
radv_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physical_device,
57
uint32_t *property_count,
58
VkDisplayProperties2KHR *properties)
59
{
60
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
61
62
return wsi_display_get_physical_device_display_properties2(physical_device, &pdevice->wsi_device,
63
property_count, properties);
64
}
65
66
VkResult
67
radv_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physical_device,
68
uint32_t *property_count,
69
VkDisplayPlanePropertiesKHR *properties)
70
{
71
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
72
73
return wsi_display_get_physical_device_display_plane_properties(
74
physical_device, &pdevice->wsi_device, property_count, properties);
75
}
76
77
VkResult
78
radv_GetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physical_device,
79
uint32_t *property_count,
80
VkDisplayPlaneProperties2KHR *properties)
81
{
82
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
83
84
return wsi_display_get_physical_device_display_plane_properties2(
85
physical_device, &pdevice->wsi_device, property_count, properties);
86
}
87
88
VkResult
89
radv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device, uint32_t plane_index,
90
uint32_t *display_count, VkDisplayKHR *displays)
91
{
92
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
93
94
return wsi_display_get_display_plane_supported_displays(physical_device, &pdevice->wsi_device,
95
plane_index, display_count, displays);
96
}
97
98
VkResult
99
radv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device, VkDisplayKHR display,
100
uint32_t *property_count, VkDisplayModePropertiesKHR *properties)
101
{
102
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
103
104
return wsi_display_get_display_mode_properties(physical_device, &pdevice->wsi_device, display,
105
property_count, properties);
106
}
107
108
VkResult
109
radv_GetDisplayModeProperties2KHR(VkPhysicalDevice physical_device, VkDisplayKHR display,
110
uint32_t *property_count, VkDisplayModeProperties2KHR *properties)
111
{
112
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
113
114
return wsi_display_get_display_mode_properties2(physical_device, &pdevice->wsi_device, display,
115
property_count, properties);
116
}
117
118
VkResult
119
radv_CreateDisplayModeKHR(VkPhysicalDevice physical_device, VkDisplayKHR display,
120
const VkDisplayModeCreateInfoKHR *create_info,
121
const VkAllocationCallbacks *allocator, VkDisplayModeKHR *mode)
122
{
123
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
124
125
return wsi_display_create_display_mode(physical_device, &pdevice->wsi_device, display,
126
create_info, allocator, mode);
127
}
128
129
VkResult
130
radv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device, VkDisplayModeKHR mode_khr,
131
uint32_t plane_index,
132
VkDisplayPlaneCapabilitiesKHR *capabilities)
133
{
134
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
135
136
return wsi_get_display_plane_capabilities(physical_device, &pdevice->wsi_device, mode_khr,
137
plane_index, capabilities);
138
}
139
140
VkResult
141
radv_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physical_device,
142
const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
143
VkDisplayPlaneCapabilities2KHR *capabilities)
144
{
145
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
146
147
return wsi_get_display_plane_capabilities2(physical_device, &pdevice->wsi_device,
148
pDisplayPlaneInfo, capabilities);
149
}
150
151
VkResult
152
radv_CreateDisplayPlaneSurfaceKHR(VkInstance _instance,
153
const VkDisplaySurfaceCreateInfoKHR *create_info,
154
const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)
155
{
156
RADV_FROM_HANDLE(radv_instance, instance, _instance);
157
const VkAllocationCallbacks *alloc;
158
159
if (allocator)
160
alloc = allocator;
161
else
162
alloc = &instance->vk.alloc;
163
164
return wsi_create_display_surface(_instance, alloc, create_info, surface);
165
}
166
167
VkResult
168
radv_ReleaseDisplayEXT(VkPhysicalDevice physical_device, VkDisplayKHR display)
169
{
170
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
171
172
return wsi_release_display(physical_device, &pdevice->wsi_device, display);
173
}
174
175
#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
176
VkResult
177
radv_AcquireXlibDisplayEXT(VkPhysicalDevice physical_device, Display *dpy, VkDisplayKHR display)
178
{
179
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
180
181
return wsi_acquire_xlib_display(physical_device, &pdevice->wsi_device, dpy, display);
182
}
183
184
VkResult
185
radv_GetRandROutputDisplayEXT(VkPhysicalDevice physical_device, Display *dpy, RROutput output,
186
VkDisplayKHR *display)
187
{
188
RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
189
190
return wsi_get_randr_output_display(physical_device, &pdevice->wsi_device, dpy, output, display);
191
}
192
#endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */
193
194
/* VK_EXT_display_control */
195
196
VkResult
197
radv_DisplayPowerControlEXT(VkDevice _device, VkDisplayKHR display,
198
const VkDisplayPowerInfoEXT *display_power_info)
199
{
200
RADV_FROM_HANDLE(radv_device, device, _device);
201
202
return wsi_display_power_control(_device, &device->physical_device->wsi_device, display,
203
display_power_info);
204
}
205
206
VkResult
207
radv_RegisterDeviceEventEXT(VkDevice _device, const VkDeviceEventInfoEXT *device_event_info,
208
const VkAllocationCallbacks *allocator, VkFence *_fence)
209
{
210
RADV_FROM_HANDLE(radv_device, device, _device);
211
VkResult ret;
212
int fd;
213
214
ret = radv_CreateFence(_device,
215
&(VkFenceCreateInfo){
216
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
217
.pNext =
218
&(VkExportFenceCreateInfo){
219
.sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO,
220
.handleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT,
221
},
222
},
223
allocator, _fence);
224
if (ret != VK_SUCCESS)
225
return ret;
226
227
RADV_FROM_HANDLE(radv_fence, fence, *_fence);
228
229
assert(fence->permanent.kind == RADV_FENCE_SYNCOBJ);
230
231
if (device->ws->export_syncobj(device->ws, fence->permanent.syncobj, &fd)) {
232
ret = VK_ERROR_OUT_OF_HOST_MEMORY;
233
} else {
234
ret = wsi_register_device_event(_device, &device->physical_device->wsi_device,
235
device_event_info, allocator, NULL, fd);
236
close(fd);
237
}
238
239
if (ret != VK_SUCCESS)
240
radv_DestroyFence(_device, *_fence, allocator);
241
242
return ret;
243
}
244
245
VkResult
246
radv_RegisterDisplayEventEXT(VkDevice _device, VkDisplayKHR display,
247
const VkDisplayEventInfoEXT *display_event_info,
248
const VkAllocationCallbacks *allocator, VkFence *_fence)
249
{
250
RADV_FROM_HANDLE(radv_device, device, _device);
251
VkResult ret;
252
int fd;
253
254
ret = radv_CreateFence(_device,
255
&(VkFenceCreateInfo){
256
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
257
.pNext =
258
&(VkExportFenceCreateInfo){
259
.sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO,
260
.handleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT,
261
},
262
},
263
allocator, _fence);
264
if (ret != VK_SUCCESS)
265
return ret;
266
267
RADV_FROM_HANDLE(radv_fence, fence, *_fence);
268
269
assert(fence->permanent.kind == RADV_FENCE_SYNCOBJ);
270
271
if (device->ws->export_syncobj(device->ws, fence->permanent.syncobj, &fd)) {
272
ret = VK_ERROR_OUT_OF_HOST_MEMORY;
273
} else {
274
ret = wsi_register_display_event(_device, &device->physical_device->wsi_device, display,
275
display_event_info, allocator, NULL, fd);
276
close(fd);
277
}
278
279
if (ret != VK_SUCCESS)
280
radv_DestroyFence(_device, *_fence, allocator);
281
282
return ret;
283
}
284
285
VkResult
286
radv_GetSwapchainCounterEXT(VkDevice _device, VkSwapchainKHR swapchain,
287
VkSurfaceCounterFlagBitsEXT flag_bits, uint64_t *value)
288
{
289
RADV_FROM_HANDLE(radv_device, device, _device);
290
291
return wsi_get_swapchain_counter(_device, &device->physical_device->wsi_device, swapchain,
292
flag_bits, value);
293
}
294
295
VkResult
296
radv_AcquireDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, VkDisplayKHR display)
297
{
298
RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
299
300
return wsi_acquire_drm_display(physicalDevice, &pdevice->wsi_device, drmFd, display);
301
}
302
303
VkResult radv_GetDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, uint32_t connectorId,
304
VkDisplayKHR* display)
305
{
306
RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
307
308
return wsi_get_drm_display(physicalDevice, &pdevice->wsi_device, drmFd, connectorId, display);
309
}
310
311
312