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