1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright © 2016 Red Hat 3bf215546Sopenharmony_ci * SPDX-License-Identifier: MIT 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * based on intel anv code: 6bf215546Sopenharmony_ci * Copyright © 2015 Intel Corporation 7bf215546Sopenharmony_ci */ 8bf215546Sopenharmony_ci 9bf215546Sopenharmony_ci#include "tu_wsi.h" 10bf215546Sopenharmony_ci 11bf215546Sopenharmony_ci#include "vk_util.h" 12bf215546Sopenharmony_ci#include "wsi_common_drm.h" 13bf215546Sopenharmony_ci#include "drm-uapi/drm_fourcc.h" 14bf215546Sopenharmony_ci 15bf215546Sopenharmony_ci#include "tu_device.h" 16bf215546Sopenharmony_ci 17bf215546Sopenharmony_cistatic VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL 18bf215546Sopenharmony_citu_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) 19bf215546Sopenharmony_ci{ 20bf215546Sopenharmony_ci TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice); 21bf215546Sopenharmony_ci return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName); 22bf215546Sopenharmony_ci} 23bf215546Sopenharmony_ci 24bf215546Sopenharmony_cistatic bool 25bf215546Sopenharmony_citu_wsi_can_present_on_device(VkPhysicalDevice physicalDevice, int fd) 26bf215546Sopenharmony_ci{ 27bf215546Sopenharmony_ci TU_FROM_HANDLE(tu_physical_device, pdevice, physicalDevice); 28bf215546Sopenharmony_ci 29bf215546Sopenharmony_ci return wsi_common_drm_devices_equal(fd, pdevice->local_fd); 30bf215546Sopenharmony_ci} 31bf215546Sopenharmony_ci 32bf215546Sopenharmony_ciVkResult 33bf215546Sopenharmony_citu_wsi_init(struct tu_physical_device *physical_device) 34bf215546Sopenharmony_ci{ 35bf215546Sopenharmony_ci VkResult result; 36bf215546Sopenharmony_ci 37bf215546Sopenharmony_ci result = wsi_device_init(&physical_device->wsi_device, 38bf215546Sopenharmony_ci tu_physical_device_to_handle(physical_device), 39bf215546Sopenharmony_ci tu_wsi_proc_addr, 40bf215546Sopenharmony_ci &physical_device->instance->vk.alloc, 41bf215546Sopenharmony_ci physical_device->master_fd, 42bf215546Sopenharmony_ci &physical_device->instance->dri_options, 43bf215546Sopenharmony_ci false); 44bf215546Sopenharmony_ci if (result != VK_SUCCESS) 45bf215546Sopenharmony_ci return result; 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ci physical_device->wsi_device.supports_modifiers = true; 48bf215546Sopenharmony_ci physical_device->wsi_device.can_present_on_device = 49bf215546Sopenharmony_ci tu_wsi_can_present_on_device; 50bf215546Sopenharmony_ci 51bf215546Sopenharmony_ci physical_device->vk.wsi_device = &physical_device->wsi_device; 52bf215546Sopenharmony_ci 53bf215546Sopenharmony_ci return VK_SUCCESS; 54bf215546Sopenharmony_ci} 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_civoid 57bf215546Sopenharmony_citu_wsi_finish(struct tu_physical_device *physical_device) 58bf215546Sopenharmony_ci{ 59bf215546Sopenharmony_ci physical_device->vk.wsi_device = NULL; 60bf215546Sopenharmony_ci wsi_device_finish(&physical_device->wsi_device, 61bf215546Sopenharmony_ci &physical_device->instance->vk.alloc); 62bf215546Sopenharmony_ci} 63