| 1 |
/* |
| 2 |
* Copyright © 2022 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* based on intel anv code: |
| 5 |
* Copyright © 2015 Intel Corporation |
| 6 |
* |
| 7 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 |
* of this software and associated documentation files (the "Software"), to deal |
| 9 |
* in the Software without restriction, including without limitation the rights |
| 10 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 |
* copies of the Software, and to permit persons to whom the Software is |
| 12 |
* furnished to do so, subject to the following conditions: |
| 13 |
* |
| 14 |
* The above copyright notice and this permission notice (including the next |
| 15 |
* paragraph) shall be included in all copies or substantial portions of the |
| 16 |
* Software. |
| 17 |
* |
| 18 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 21 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 22 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 23 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 |
* SOFTWARE. |
| 25 |
*/ |
| 26 |
|
| 27 |
#include "pvr_wsi.h" |
| 28 |
|
| 29 |
#include <stdint.h> |
| 30 |
#include <stddef.h> |
| 31 |
#include <stdbool.h> |
| 32 |
#include <vulkan/vulkan.h> |
| 33 |
#include <xf86drm.h> |
| 34 |
|
| 35 |
#include "pvr_device.h" |
| 36 |
#include "pvr_entrypoints.h" |
| 37 |
#include "pvr_instance.h" |
| 38 |
#include "pvr_physical_device.h" |
| 39 |
#include "pvr_queue.h" |
| 40 |
|
| 41 |
#include "util/u_atomic.h" |
| 42 |
#include "vk_object.h" |
| 43 |
#include "vk_instance.h" |
| 44 |
#include "wsi_common.h" |
| 45 |
|
| 46 |
static PFN_vkVoidFunction pvr_wsi_proc_addr(VkPhysicalDevice physicalDevice, |
| 47 |
const char *pName) |
| 48 |
{ |
| 49 |
VK_FROM_HANDLE(pvr_physical_device, pdevice, physicalDevice); |
| 50 |
|
| 51 |
return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName); |
| 52 |
} |
| 53 |
|
| 54 |
static bool pvr_can_present_on_device(VkPhysicalDevice pdevice, int fd) |
| 55 |
{ |
| 56 |
drmDevicePtr device; |
| 57 |
if (drmGetDevice2(fd, 0, &device) != 0) |
| 58 |
return false; |
| 59 |
/* Allow on-device presentation for all devices with bus type PLATFORM. |
| 60 |
* Other device types such as PCI or USB should use the PRIME blit path. */ |
| 61 |
bool match = device->bustype == DRM_BUS_PLATFORM; |
| 62 |
|
| 63 |
drmFreeDevice(&device); |
| 64 |
|
| 65 |
return match; |
| 66 |
} |
| 67 |
|
| 68 |
VkResult pvr_wsi_init(struct pvr_physical_device *pdevice) |
| 69 |
{ |
| 70 |
VkResult result; |
| 71 |
|
| 72 |
result = wsi_device_init(&pdevice->wsi_device, |
| 73 |
pvr_physical_device_to_handle(pdevice), |
| 74 |
pvr_wsi_proc_addr, |
| 75 |
&pdevice->vk.instance->alloc, |
| 76 |
pdevice->ws->display_fd, |
| 77 |
NULL, |
| 78 |
&(struct wsi_device_options){ .sw_device = false }); |
| 79 |
if (result != VK_SUCCESS) |
| 80 |
return result; |
| 81 |
|
| 82 |
pdevice->wsi_device.supports_modifiers = true; |
| 83 |
pdevice->wsi_device.can_present_on_device = pvr_can_present_on_device; |
| 84 |
pdevice->vk.wsi_device = &pdevice->wsi_device; |
| 85 |
|
| 86 |
return VK_SUCCESS; |
| 87 |
} |
| 88 |
|
| 89 |
void pvr_wsi_finish(struct pvr_physical_device *pdevice) |
| 90 |
{ |
| 91 |
pdevice->vk.wsi_device = NULL; |
| 92 |
wsi_device_finish(&pdevice->wsi_device, &pdevice->vk.instance->alloc); |
| 93 |
} |
| 94 |
|
| 95 |
VkResult pvr_QueuePresentKHR(VkQueue _queue, |
| 96 |
const VkPresentInfoKHR *pPresentInfo) |
| 97 |
{ |
| 98 |
VK_FROM_HANDLE(pvr_queue, queue, _queue); |
| 99 |
VkResult result; |
| 100 |
|
| 101 |
result = wsi_common_queue_present(&queue->device->pdevice->wsi_device, |
| 102 |
&queue->vk, |
| 103 |
pPresentInfo); |
| 104 |
if (result != VK_SUCCESS) |
| 105 |
return result; |
| 106 |
|
| 107 |
p_atomic_inc(&queue->device->global_queue_present_count); |
| 108 |
|
| 109 |
return VK_SUCCESS; |
| 110 |
} |