Path: blob/21.2-virgl/src/amd/vulkan/radv_wsi_display.c
7354 views
/*1* Copyright © 2017 Keith Packard2*3* Permission to use, copy, modify, distribute, and sell this software and its4* documentation for any purpose is hereby granted without fee, provided that5* the above copyright notice appear in all copies and that both that copyright6* notice and this permission notice appear in supporting documentation, and7* that the name of the copyright holders not be used in advertising or8* publicity pertaining to distribution of the software without specific,9* written prior permission. The copyright holders make no representations10* about the suitability of this software for any purpose. It is provided "as11* is" without express or implied warranty.12*13* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,14* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO15* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR16* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,17* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER18* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE19* OF THIS SOFTWARE.20*/2122#include <amdgpu.h>23#include <fcntl.h>24#include <stdbool.h>25#include <string.h>26#include <unistd.h>27#include <xf86drm.h>28#include <xf86drmMode.h>29#include "drm-uapi/amdgpu_drm.h"30#include "util/debug.h"31#include "util/disk_cache.h"32#include "util/strtod.h"33#include "winsys/amdgpu/radv_amdgpu_winsys_public.h"34#include "radv_cs.h"35#include "radv_private.h"36#include "sid.h"37#include "vk_format.h"38#include "vk_util.h"39#include "wsi_common_display.h"4041#define MM_PER_PIXEL (1.0 / 96.0 * 25.4)4243VkResult44radv_GetPhysicalDeviceDisplayPropertiesKHR(VkPhysicalDevice physical_device,45uint32_t *property_count,46VkDisplayPropertiesKHR *properties)47{48RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);4950return wsi_display_get_physical_device_display_properties(physical_device, &pdevice->wsi_device,51property_count, properties);52}5354VkResult55radv_GetPhysicalDeviceDisplayProperties2KHR(VkPhysicalDevice physical_device,56uint32_t *property_count,57VkDisplayProperties2KHR *properties)58{59RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);6061return wsi_display_get_physical_device_display_properties2(physical_device, &pdevice->wsi_device,62property_count, properties);63}6465VkResult66radv_GetPhysicalDeviceDisplayPlanePropertiesKHR(VkPhysicalDevice physical_device,67uint32_t *property_count,68VkDisplayPlanePropertiesKHR *properties)69{70RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);7172return wsi_display_get_physical_device_display_plane_properties(73physical_device, &pdevice->wsi_device, property_count, properties);74}7576VkResult77radv_GetPhysicalDeviceDisplayPlaneProperties2KHR(VkPhysicalDevice physical_device,78uint32_t *property_count,79VkDisplayPlaneProperties2KHR *properties)80{81RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);8283return wsi_display_get_physical_device_display_plane_properties2(84physical_device, &pdevice->wsi_device, property_count, properties);85}8687VkResult88radv_GetDisplayPlaneSupportedDisplaysKHR(VkPhysicalDevice physical_device, uint32_t plane_index,89uint32_t *display_count, VkDisplayKHR *displays)90{91RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);9293return wsi_display_get_display_plane_supported_displays(physical_device, &pdevice->wsi_device,94plane_index, display_count, displays);95}9697VkResult98radv_GetDisplayModePropertiesKHR(VkPhysicalDevice physical_device, VkDisplayKHR display,99uint32_t *property_count, VkDisplayModePropertiesKHR *properties)100{101RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);102103return wsi_display_get_display_mode_properties(physical_device, &pdevice->wsi_device, display,104property_count, properties);105}106107VkResult108radv_GetDisplayModeProperties2KHR(VkPhysicalDevice physical_device, VkDisplayKHR display,109uint32_t *property_count, VkDisplayModeProperties2KHR *properties)110{111RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);112113return wsi_display_get_display_mode_properties2(physical_device, &pdevice->wsi_device, display,114property_count, properties);115}116117VkResult118radv_CreateDisplayModeKHR(VkPhysicalDevice physical_device, VkDisplayKHR display,119const VkDisplayModeCreateInfoKHR *create_info,120const VkAllocationCallbacks *allocator, VkDisplayModeKHR *mode)121{122RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);123124return wsi_display_create_display_mode(physical_device, &pdevice->wsi_device, display,125create_info, allocator, mode);126}127128VkResult129radv_GetDisplayPlaneCapabilitiesKHR(VkPhysicalDevice physical_device, VkDisplayModeKHR mode_khr,130uint32_t plane_index,131VkDisplayPlaneCapabilitiesKHR *capabilities)132{133RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);134135return wsi_get_display_plane_capabilities(physical_device, &pdevice->wsi_device, mode_khr,136plane_index, capabilities);137}138139VkResult140radv_GetDisplayPlaneCapabilities2KHR(VkPhysicalDevice physical_device,141const VkDisplayPlaneInfo2KHR *pDisplayPlaneInfo,142VkDisplayPlaneCapabilities2KHR *capabilities)143{144RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);145146return wsi_get_display_plane_capabilities2(physical_device, &pdevice->wsi_device,147pDisplayPlaneInfo, capabilities);148}149150VkResult151radv_CreateDisplayPlaneSurfaceKHR(VkInstance _instance,152const VkDisplaySurfaceCreateInfoKHR *create_info,153const VkAllocationCallbacks *allocator, VkSurfaceKHR *surface)154{155RADV_FROM_HANDLE(radv_instance, instance, _instance);156const VkAllocationCallbacks *alloc;157158if (allocator)159alloc = allocator;160else161alloc = &instance->vk.alloc;162163return wsi_create_display_surface(_instance, alloc, create_info, surface);164}165166VkResult167radv_ReleaseDisplayEXT(VkPhysicalDevice physical_device, VkDisplayKHR display)168{169RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);170171return wsi_release_display(physical_device, &pdevice->wsi_device, display);172}173174#ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT175VkResult176radv_AcquireXlibDisplayEXT(VkPhysicalDevice physical_device, Display *dpy, VkDisplayKHR display)177{178RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);179180return wsi_acquire_xlib_display(physical_device, &pdevice->wsi_device, dpy, display);181}182183VkResult184radv_GetRandROutputDisplayEXT(VkPhysicalDevice physical_device, Display *dpy, RROutput output,185VkDisplayKHR *display)186{187RADV_FROM_HANDLE(radv_physical_device, pdevice, physical_device);188189return wsi_get_randr_output_display(physical_device, &pdevice->wsi_device, dpy, output, display);190}191#endif /* VK_USE_PLATFORM_XLIB_XRANDR_EXT */192193/* VK_EXT_display_control */194195VkResult196radv_DisplayPowerControlEXT(VkDevice _device, VkDisplayKHR display,197const VkDisplayPowerInfoEXT *display_power_info)198{199RADV_FROM_HANDLE(radv_device, device, _device);200201return wsi_display_power_control(_device, &device->physical_device->wsi_device, display,202display_power_info);203}204205VkResult206radv_RegisterDeviceEventEXT(VkDevice _device, const VkDeviceEventInfoEXT *device_event_info,207const VkAllocationCallbacks *allocator, VkFence *_fence)208{209RADV_FROM_HANDLE(radv_device, device, _device);210VkResult ret;211int fd;212213ret = radv_CreateFence(_device,214&(VkFenceCreateInfo){215.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,216.pNext =217&(VkExportFenceCreateInfo){218.sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO,219.handleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT,220},221},222allocator, _fence);223if (ret != VK_SUCCESS)224return ret;225226RADV_FROM_HANDLE(radv_fence, fence, *_fence);227228assert(fence->permanent.kind == RADV_FENCE_SYNCOBJ);229230if (device->ws->export_syncobj(device->ws, fence->permanent.syncobj, &fd)) {231ret = VK_ERROR_OUT_OF_HOST_MEMORY;232} else {233ret = wsi_register_device_event(_device, &device->physical_device->wsi_device,234device_event_info, allocator, NULL, fd);235close(fd);236}237238if (ret != VK_SUCCESS)239radv_DestroyFence(_device, *_fence, allocator);240241return ret;242}243244VkResult245radv_RegisterDisplayEventEXT(VkDevice _device, VkDisplayKHR display,246const VkDisplayEventInfoEXT *display_event_info,247const VkAllocationCallbacks *allocator, VkFence *_fence)248{249RADV_FROM_HANDLE(radv_device, device, _device);250VkResult ret;251int fd;252253ret = radv_CreateFence(_device,254&(VkFenceCreateInfo){255.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,256.pNext =257&(VkExportFenceCreateInfo){258.sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO,259.handleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT,260},261},262allocator, _fence);263if (ret != VK_SUCCESS)264return ret;265266RADV_FROM_HANDLE(radv_fence, fence, *_fence);267268assert(fence->permanent.kind == RADV_FENCE_SYNCOBJ);269270if (device->ws->export_syncobj(device->ws, fence->permanent.syncobj, &fd)) {271ret = VK_ERROR_OUT_OF_HOST_MEMORY;272} else {273ret = wsi_register_display_event(_device, &device->physical_device->wsi_device, display,274display_event_info, allocator, NULL, fd);275close(fd);276}277278if (ret != VK_SUCCESS)279radv_DestroyFence(_device, *_fence, allocator);280281return ret;282}283284VkResult285radv_GetSwapchainCounterEXT(VkDevice _device, VkSwapchainKHR swapchain,286VkSurfaceCounterFlagBitsEXT flag_bits, uint64_t *value)287{288RADV_FROM_HANDLE(radv_device, device, _device);289290return wsi_get_swapchain_counter(_device, &device->physical_device->wsi_device, swapchain,291flag_bits, value);292}293294VkResult295radv_AcquireDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, VkDisplayKHR display)296{297RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);298299return wsi_acquire_drm_display(physicalDevice, &pdevice->wsi_device, drmFd, display);300}301302VkResult radv_GetDrmDisplayEXT(VkPhysicalDevice physicalDevice, int32_t drmFd, uint32_t connectorId,303VkDisplayKHR* display)304{305RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);306307return wsi_get_drm_display(physicalDevice, &pdevice->wsi_device, drmFd, connectorId, display);308}309310311312