2 * Copyright © 2017 Keith Packard
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.
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
27 #include "radv_private.h"
29 #include "util/disk_cache.h"
30 #include "util/strtod.h"
33 #include <xf86drmMode.h>
35 #include <amdgpu_drm.h>
36 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
37 #include "vk_format.h"
39 #include "util/debug.h"
40 #include "wsi_common_display.h"
42 #define MM_PER_PIXEL (1.0/96.0 * 25.4)
45 radv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device
,
46 uint32_t *property_count
,
47 VkDisplayPropertiesKHR
*properties
)
49 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
51 return wsi_display_get_physical_device_display_properties(
59 radv_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physical_device
,
60 uint32_t *property_count
,
61 VkDisplayProperties2KHR
*properties
)
63 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
65 return wsi_display_get_physical_device_display_properties2(
73 radv_GetPhysicalDeviceDisplayPlanePropertiesKHR(
74 VkPhysicalDevice physical_device
,
75 uint32_t *property_count
,
76 VkDisplayPlanePropertiesKHR
*properties
)
78 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
80 return wsi_display_get_physical_device_display_plane_properties(
88 radv_GetPhysicalDeviceDisplayPlaneProperties2KHR(
89 VkPhysicalDevice physical_device
,
90 uint32_t *property_count
,
91 VkDisplayPlaneProperties2KHR
*properties
)
93 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
95 return wsi_display_get_physical_device_display_plane_properties2(
103 radv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device
,
104 uint32_t plane_index
,
105 uint32_t *display_count
,
106 VkDisplayKHR
*displays
)
108 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
110 return wsi_display_get_display_plane_supported_displays(
112 &pdevice
->wsi_device
,
120 radv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device
,
121 VkDisplayKHR display
,
122 uint32_t *property_count
,
123 VkDisplayModePropertiesKHR
*properties
)
125 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
127 return wsi_display_get_display_mode_properties(physical_device
,
128 &pdevice
->wsi_device
,
135 radv_GetDisplayModeProperties2KHR(VkPhysicalDevice physical_device
,
136 VkDisplayKHR display
,
137 uint32_t *property_count
,
138 VkDisplayModeProperties2KHR
*properties
)
140 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
142 return wsi_display_get_display_mode_properties2(physical_device
,
143 &pdevice
->wsi_device
,
150 radv_CreateDisplayModeKHR(VkPhysicalDevice physical_device
,
151 VkDisplayKHR display
,
152 const VkDisplayModeCreateInfoKHR
*create_info
,
153 const VkAllocationCallbacks
*allocator
,
154 VkDisplayModeKHR
*mode
)
156 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
158 return wsi_display_create_display_mode(physical_device
,
159 &pdevice
->wsi_device
,
167 radv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device
,
168 VkDisplayModeKHR mode_khr
,
169 uint32_t plane_index
,
170 VkDisplayPlaneCapabilitiesKHR
*capabilities
)
172 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
174 return wsi_get_display_plane_capabilities(physical_device
,
175 &pdevice
->wsi_device
,
182 radv_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physical_device
,
183 const VkDisplayPlaneInfo2KHR
*pDisplayPlaneInfo
,
184 VkDisplayPlaneCapabilities2KHR
*capabilities
)
186 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
188 return wsi_get_display_plane_capabilities2(physical_device
,
189 &pdevice
->wsi_device
,
195 radv_CreateDisplayPlaneSurfaceKHR(
196 VkInstance _instance
,
197 const VkDisplaySurfaceCreateInfoKHR
*create_info
,
198 const VkAllocationCallbacks
*allocator
,
199 VkSurfaceKHR
*surface
)
201 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
202 const VkAllocationCallbacks
*alloc
;
207 alloc
= &instance
->alloc
;
209 return wsi_create_display_surface(_instance
, alloc
,
210 create_info
, surface
);
214 radv_ReleaseDisplayEXT(VkPhysicalDevice physical_device
,
215 VkDisplayKHR display
)
217 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
219 return wsi_release_display(physical_device
,
220 &pdevice
->wsi_device
,
224 #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT
226 radv_AcquireXlibDisplayEXT(VkPhysicalDevice physical_device
,
228 VkDisplayKHR display
)
230 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
232 return wsi_acquire_xlib_display(physical_device
,
233 &pdevice
->wsi_device
,
239 radv_GetRandROutputDisplayEXT(VkPhysicalDevice physical_device
,
242 VkDisplayKHR
*display
)
244 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physical_device
);
246 return wsi_get_randr_output_display(physical_device
,
247 &pdevice
->wsi_device
,
252 #endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */
254 /* VK_EXT_display_control */
257 radv_DisplayPowerControlEXT(VkDevice _device
,
258 VkDisplayKHR display
,
259 const VkDisplayPowerInfoEXT
*display_power_info
)
261 RADV_FROM_HANDLE(radv_device
, device
, _device
);
263 return wsi_display_power_control(_device
,
264 &device
->physical_device
->wsi_device
,
270 radv_RegisterDeviceEventEXT(VkDevice _device
,
271 const VkDeviceEventInfoEXT
*device_event_info
,
272 const VkAllocationCallbacks
*allocator
,
275 RADV_FROM_HANDLE(radv_device
, device
, _device
);
276 struct radv_fence
*fence
;
279 fence
= vk_alloc2(&device
->instance
->alloc
, allocator
, sizeof (*fence
),
280 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
282 return VK_ERROR_OUT_OF_HOST_MEMORY
;
286 fence
->temp_syncobj
= 0;
288 ret
= wsi_register_device_event(_device
,
289 &device
->physical_device
->wsi_device
,
293 if (ret
== VK_SUCCESS
)
294 *_fence
= radv_fence_to_handle(fence
);
296 vk_free2(&device
->instance
->alloc
, allocator
, fence
);
301 radv_RegisterDisplayEventEXT(VkDevice _device
,
302 VkDisplayKHR display
,
303 const VkDisplayEventInfoEXT
*display_event_info
,
304 const VkAllocationCallbacks
*allocator
,
307 RADV_FROM_HANDLE(radv_device
, device
, _device
);
309 struct radv_fence
*fence
;
312 fence
= vk_alloc2(&device
->instance
->alloc
, allocator
, sizeof (*fence
),
313 8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
315 return VK_ERROR_OUT_OF_HOST_MEMORY
;
319 fence
->temp_syncobj
= 0;
321 ret
= wsi_register_display_event(_device
,
322 &device
->physical_device
->wsi_device
,
326 &(fence
->fence_wsi
));
328 if (ret
== VK_SUCCESS
)
329 *_fence
= radv_fence_to_handle(fence
);
331 vk_free2(&device
->instance
->alloc
, allocator
, fence
);
336 radv_GetSwapchainCounterEXT(VkDevice _device
,
337 VkSwapchainKHR swapchain
,
338 VkSurfaceCounterFlagBitsEXT flag_bits
,
341 RADV_FROM_HANDLE(radv_device
, device
, _device
);
343 return wsi_get_swapchain_counter(_device
,
344 &device
->physical_device
->wsi_device
,