radv/gfx10: implement radv_init_dcc_control_reg()
[mesa.git] / src / amd / vulkan / radv_wsi_display.c
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 <stdbool.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include "radv_private.h"
28 #include "radv_cs.h"
29 #include "util/disk_cache.h"
30 #include "util/strtod.h"
31 #include "vk_util.h"
32 #include <xf86drm.h>
33 #include <xf86drmMode.h>
34 #include <amdgpu.h>
35 #include <amdgpu_drm.h>
36 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
37 #include "ac_llvm_util.h"
38 #include "vk_format.h"
39 #include "sid.h"
40 #include "util/debug.h"
41 #include "wsi_common_display.h"
42
43 #define MM_PER_PIXEL (1.0/96.0 * 25.4)
44
45 VkResult
46 radv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,
47 uint32_t *property_count,
48 VkDisplayPropertiesKHR *properties)
49 {
50 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
51
52 return wsi_display_get_physical_device_display_properties(
53 physical_device,
54 &pdevice->wsi_device,
55 property_count,
56 properties);
57 }
58
59 VkResult
60 radv_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physical_device,
61 uint32_t *property_count,
62 VkDisplayProperties2KHR *properties)
63 {
64 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
65
66 return wsi_display_get_physical_device_display_properties2(
67 physical_device,
68 &pdevice->wsi_device,
69 property_count,
70 properties);
71 }
72
73 VkResult
74 radv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
75 VkPhysicalDevice physical_device,
76 uint32_t *property_count,
77 VkDisplayPlanePropertiesKHR *properties)
78 {
79 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
80
81 return wsi_display_get_physical_device_display_plane_properties(
82 physical_device,
83 &pdevice->wsi_device,
84 property_count,
85 properties);
86 }
87
88 VkResult
89 radv_GetPhysicalDeviceDisplayPlaneProperties2KHR(
90 VkPhysicalDevice physical_device,
91 uint32_t *property_count,
92 VkDisplayPlaneProperties2KHR *properties)
93 {
94 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
95
96 return wsi_display_get_physical_device_display_plane_properties2(
97 physical_device,
98 &pdevice->wsi_device,
99 property_count,
100 properties);
101 }
102
103 VkResult
104 radv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device,
105 uint32_t plane_index,
106 uint32_t *display_count,
107 VkDisplayKHR *displays)
108 {
109 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
110
111 return wsi_display_get_display_plane_supported_displays(
112 physical_device,
113 &pdevice->wsi_device,
114 plane_index,
115 display_count,
116 displays);
117 }
118
119
120 VkResult
121 radv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device,
122 VkDisplayKHR display,
123 uint32_t *property_count,
124 VkDisplayModePropertiesKHR *properties)
125 {
126 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
127
128 return wsi_display_get_display_mode_properties(physical_device,
129 &pdevice->wsi_device,
130 display,
131 property_count,
132 properties);
133 }
134
135 VkResult
136 radv_GetDisplayModeProperties2KHR(VkPhysicalDevice physical_device,
137 VkDisplayKHR display,
138 uint32_t *property_count,
139 VkDisplayModeProperties2KHR *properties)
140 {
141 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
142
143 return wsi_display_get_display_mode_properties2(physical_device,
144 &pdevice->wsi_device,
145 display,
146 property_count,
147 properties);
148 }
149
150 VkResult
151 radv_CreateDisplayModeKHR(VkPhysicalDevice physical_device,
152 VkDisplayKHR display,
153 const VkDisplayModeCreateInfoKHR *create_info,
154 const VkAllocationCallbacks *allocator,
155 VkDisplayModeKHR *mode)
156 {
157 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
158
159 return wsi_display_create_display_mode(physical_device,
160 &pdevice->wsi_device,
161 display,
162 create_info,
163 allocator,
164 mode);
165 }
166
167 VkResult
168 radv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device,
169 VkDisplayModeKHR mode_khr,
170 uint32_t plane_index,
171 VkDisplayPlaneCapabilitiesKHR *capabilities)
172 {
173 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
174
175 return wsi_get_display_plane_capabilities(physical_device,
176 &pdevice->wsi_device,
177 mode_khr,
178 plane_index,
179 capabilities);
180 }
181
182 VkResult
183 radv_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physical_device,
184 const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,
185 VkDisplayPlaneCapabilities2KHR *capabilities)
186 {
187 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
188
189 return wsi_get_display_plane_capabilities2(physical_device,
190 &pdevice->wsi_device,
191 pDisplayPlaneInfo,
192 capabilities);
193 }
194
195 VkResult
196 radv_CreateDisplayPlaneSurfaceKHR(
197 VkInstance _instance,
198 const VkDisplaySurfaceCreateInfoKHR *create_info,
199 const VkAllocationCallbacks *allocator,
200 VkSurfaceKHR *surface)
201 {
202 RADV_FROM_HANDLE(radv_instance, instance, _instance);
203 const VkAllocationCallbacks *alloc;
204
205 if (allocator)
206 alloc = allocator;
207 else
208 alloc = &instance->alloc;
209
210 return wsi_create_display_surface(_instance, alloc,
211 create_info, surface);
212 }
213
214 VkResult
215 radv_ReleaseDisplayEXT(VkPhysicalDevice physical_device,
216 VkDisplayKHR display)
217 {
218 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
219
220 return wsi_release_display(physical_device,
221 &pdevice->wsi_device,
222 display);
223 }
224
225 #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
226 VkResult
227 radv_AcquireXlibDisplayEXT(VkPhysicalDevice physical_device,
228 Display *dpy,
229 VkDisplayKHR display)
230 {
231 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
232
233 return wsi_acquire_xlib_display(physical_device,
234 &pdevice->wsi_device,
235 dpy,
236 display);
237 }
238
239 VkResult
240 radv_GetRandROutputDisplayEXT(VkPhysicalDevice physical_device,
241 Display *dpy,
242 RROutput output,
243 VkDisplayKHR *display)
244 {
245 RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);
246
247 return wsi_get_randr_output_display(physical_device,
248 &pdevice->wsi_device,
249 dpy,
250 output,
251 display);
252 }
253 #endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */
254
255 /* VK_EXT_display_control */
256
257 VkResult
258 radv_DisplayPowerControlEXT(VkDevice _device,
259 VkDisplayKHR display,
260 const VkDisplayPowerInfoEXT *display_power_info)
261 {
262 RADV_FROM_HANDLE(radv_device, device, _device);
263
264 return wsi_display_power_control(_device,
265 &device->physical_device->wsi_device,
266 display,
267 display_power_info);
268 }
269
270 VkResult
271 radv_RegisterDeviceEventEXT(VkDevice _device,
272 const VkDeviceEventInfoEXT *device_event_info,
273 const VkAllocationCallbacks *allocator,
274 VkFence *_fence)
275 {
276 RADV_FROM_HANDLE(radv_device, device, _device);
277 struct radv_fence *fence;
278 VkResult ret;
279
280 fence = vk_alloc2(&device->instance->alloc, allocator, sizeof (*fence),
281 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
282 if (!fence)
283 return VK_ERROR_OUT_OF_HOST_MEMORY;
284
285 fence->fence = NULL;
286 fence->syncobj = 0;
287 fence->temp_syncobj = 0;
288
289 ret = wsi_register_device_event(_device,
290 &device->physical_device->wsi_device,
291 device_event_info,
292 allocator,
293 &fence->fence_wsi);
294 if (ret == VK_SUCCESS)
295 *_fence = radv_fence_to_handle(fence);
296 else
297 vk_free2(&device->instance->alloc, allocator, fence);
298 return ret;
299 }
300
301 VkResult
302 radv_RegisterDisplayEventEXT(VkDevice _device,
303 VkDisplayKHR display,
304 const VkDisplayEventInfoEXT *display_event_info,
305 const VkAllocationCallbacks *allocator,
306 VkFence *_fence)
307 {
308 RADV_FROM_HANDLE(radv_device, device, _device);
309
310 struct radv_fence *fence;
311 VkResult ret;
312
313 fence = vk_alloc2(&device->instance->alloc, allocator, sizeof (*fence),
314 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
315 if (!fence)
316 return VK_ERROR_OUT_OF_HOST_MEMORY;
317
318 fence->fence = NULL;
319 fence->syncobj = 0;
320 fence->temp_syncobj = 0;
321
322 ret = wsi_register_display_event(_device,
323 &device->physical_device->wsi_device,
324 display,
325 display_event_info,
326 allocator,
327 &(fence->fence_wsi));
328
329 if (ret == VK_SUCCESS)
330 *_fence = radv_fence_to_handle(fence);
331 else
332 vk_free2(&device->instance->alloc, allocator, fence);
333 return ret;
334 }
335
336 VkResult
337 radv_GetSwapchainCounterEXT(VkDevice _device,
338 VkSwapchainKHR swapchain,
339 VkSurfaceCounterFlagBitsEXT flag_bits,
340 uint64_t *value)
341 {
342 RADV_FROM_HANDLE(radv_device, device, _device);
343
344 return wsi_get_swapchain_counter(_device,
345 &device->physical_device->wsi_device,
346 swapchain,
347 flag_bits,
348 value);
349 }
350