1 /*
2 * Copyright © 2016 Red Hat
3 * based on intel anv code:
4 * Copyright © 2015 Intel Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * IN THE SOFTWARE.
24 */
25
26 #include "meta/radv_meta.h"
27 #include "util/macros.h"
28 #include "radv_debug.h"
29 #include "radv_private.h"
30 #include "vk_fence.h"
31 #include "vk_semaphore.h"
32 #include "vk_util.h"
33 #include "wsi_common.h"
34
35 static VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
radv_wsi_proc_addr(VkPhysicalDevice physicalDevice,const char * pName)36 radv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName)
37 {
38 RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
39 return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName);
40 }
41
42 static void
radv_wsi_set_memory_ownership(VkDevice _device,VkDeviceMemory _mem,VkBool32 ownership)43 radv_wsi_set_memory_ownership(VkDevice _device, VkDeviceMemory _mem, VkBool32 ownership)
44 {
45 RADV_FROM_HANDLE(radv_device, device, _device);
46 RADV_FROM_HANDLE(radv_device_memory, mem, _mem);
47
48 if (device->use_global_bo_list) {
49 device->ws->buffer_make_resident(device->ws, mem->bo, ownership);
50 }
51 }
52
53 static VkQueue
radv_wsi_get_prime_blit_queue(VkDevice _device)54 radv_wsi_get_prime_blit_queue(VkDevice _device)
55 {
56 RADV_FROM_HANDLE(radv_device, device, _device);
57
58 if (device->private_sdma_queue != VK_NULL_HANDLE)
59 return vk_queue_to_handle(&device->private_sdma_queue->vk);
60
61 if (device->physical_device->rad_info.gfx_level >= GFX9 &&
62 !(device->physical_device->instance->debug_flags & RADV_DEBUG_NO_DMA_BLIT)) {
63
64 device->physical_device->vk_queue_to_radv[device->physical_device->num_queues++] = RADV_QUEUE_TRANSFER;
65 const VkDeviceQueueCreateInfo queue_create = {
66 .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
67 .queueFamilyIndex = device->physical_device->num_queues - 1,
68 .queueCount = 1,
69 };
70
71 device->private_sdma_queue =
72 vk_zalloc(&device->vk.alloc, sizeof(struct radv_queue), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE);
73
74 VkResult result = radv_queue_init(device, device->private_sdma_queue, 0, &queue_create, NULL);
75 if (result == VK_SUCCESS) {
76 return vk_queue_to_handle(&device->private_sdma_queue->vk);
77 } else {
78 vk_free(&device->vk.alloc, device->private_sdma_queue);
79 device->private_sdma_queue = VK_NULL_HANDLE;
80 }
81 }
82 return VK_NULL_HANDLE;
83 }
84
85 VkResult
radv_init_wsi(struct radv_physical_device * physical_device)86 radv_init_wsi(struct radv_physical_device *physical_device)
87 {
88 VkResult result =
89 wsi_device_init(&physical_device->wsi_device, radv_physical_device_to_handle(physical_device), radv_wsi_proc_addr,
90 &physical_device->instance->vk.alloc, physical_device->master_fd,
91 &physical_device->instance->drirc.options, &(struct wsi_device_options){.sw_device = false});
92 if (result != VK_SUCCESS)
93 return result;
94
95 physical_device->wsi_device.supports_modifiers = physical_device->rad_info.gfx_level >= GFX9;
96 physical_device->wsi_device.set_memory_ownership = radv_wsi_set_memory_ownership;
97 physical_device->wsi_device.get_blit_queue = radv_wsi_get_prime_blit_queue;
98
99 wsi_device_setup_syncobj_fd(&physical_device->wsi_device, physical_device->local_fd);
100
101 physical_device->vk.wsi_device = &physical_device->wsi_device;
102
103 return VK_SUCCESS;
104 }
105
106 void
radv_finish_wsi(struct radv_physical_device * physical_device)107 radv_finish_wsi(struct radv_physical_device *physical_device)
108 {
109 physical_device->vk.wsi_device = NULL;
110 wsi_device_finish(&physical_device->wsi_device, &physical_device->instance->vk.alloc);
111 }
112