| 1 |
/* |
| 2 |
* Copyright 2024 Valve Corporation |
| 3 |
* Copyright 2024 Alyssa Rosenzweig |
| 4 |
* Copyright 2022-2023 Collabora Ltd. and Red Hat Inc. |
| 5 |
* SPDX-License-Identifier: MIT |
| 6 |
*/ |
| 7 |
#include "hk_wsi.h" |
| 8 |
#include "hk_instance.h" |
| 9 |
#include "wsi_common.h" |
| 10 |
|
| 11 |
#include <xf86drm.h> |
| 12 |
|
| 13 |
static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL |
| 14 |
hk_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) |
| 15 |
{ |
| 16 |
VK_FROM_HANDLE(hk_physical_device, pdev, physicalDevice); |
| 17 |
return vk_instance_get_proc_addr_unchecked(pdev->vk.instance, pName); |
| 18 |
} |
| 19 |
|
| 20 |
static bool |
| 21 |
hk_wsi_can_present_on_device(VkPhysicalDevice physicalDevice, int fd) |
| 22 |
{ |
| 23 |
VK_FROM_HANDLE(hk_physical_device, pdev, physicalDevice); |
| 24 |
if (pdev->dev.is_virtio) { |
| 25 |
return false; |
| 26 |
} |
| 27 |
|
| 28 |
drmDevicePtr device; |
| 29 |
if (drmGetDevice2(fd, 0, &device) != 0) { |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
/* Allow on-device presentation for all non-virtio devices with bus type |
| 34 |
* PLATFORM */ |
| 35 |
bool match = device->bustype == DRM_BUS_PLATFORM; |
| 36 |
|
| 37 |
drmFreeDevice(&device); |
| 38 |
|
| 39 |
return match; |
| 40 |
} |
| 41 |
|
| 42 |
VkResult |
| 43 |
hk_init_wsi(struct hk_physical_device *pdev) |
| 44 |
{ |
| 45 |
VkResult result; |
| 46 |
|
| 47 |
struct wsi_device_options wsi_options = {.sw_device = false}; |
| 48 |
result = wsi_device_init( |
| 49 |
&pdev->wsi_device, hk_physical_device_to_handle(pdev), hk_wsi_proc_addr, |
| 50 |
&pdev->vk.instance->alloc, pdev->master_fd, |
| 51 |
&hk_physical_device_instance(pdev)->dri_options, &wsi_options); |
| 52 |
if (result != VK_SUCCESS) |
| 53 |
return result; |
| 54 |
|
| 55 |
pdev->wsi_device.supports_scanout = false; |
| 56 |
pdev->wsi_device.supports_modifiers = true; |
| 57 |
pdev->wsi_device.can_present_on_device = hk_wsi_can_present_on_device; |
| 58 |
|
| 59 |
pdev->vk.wsi_device = &pdev->wsi_device; |
| 60 |
|
| 61 |
return result; |
| 62 |
} |
| 63 |
|
| 64 |
void |
| 65 |
hk_finish_wsi(struct hk_physical_device *pdev) |
| 66 |
{ |
| 67 |
pdev->vk.wsi_device = NULL; |
| 68 |
wsi_device_finish(&pdev->wsi_device, &pdev->vk.instance->alloc); |
| 69 |
} |