101e04c3fSmrg/* 201e04c3fSmrg * Copyright © 2016 Red Hat 301e04c3fSmrg * based on intel anv code: 401e04c3fSmrg * Copyright © 2015 Intel Corporation 501e04c3fSmrg * 601e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a 701e04c3fSmrg * copy of this software and associated documentation files (the "Software"), 801e04c3fSmrg * to deal in the Software without restriction, including without limitation 901e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1001e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the 1101e04c3fSmrg * Software is furnished to do so, subject to the following conditions: 1201e04c3fSmrg * 1301e04c3fSmrg * The above copyright notice and this permission notice (including the next 1401e04c3fSmrg * paragraph) shall be included in all copies or substantial portions of the 1501e04c3fSmrg * Software. 1601e04c3fSmrg * 1701e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1801e04c3fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1901e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2001e04c3fSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2101e04c3fSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 2201e04c3fSmrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2301e04c3fSmrg * IN THE SOFTWARE. 2401e04c3fSmrg */ 2501e04c3fSmrg 267ec681f3Smrg#include "util/macros.h" 2701e04c3fSmrg#include "radv_meta.h" 287ec681f3Smrg#include "radv_private.h" 2901e04c3fSmrg#include "vk_util.h" 307ec681f3Smrg#include "wsi_common.h" 3101e04c3fSmrg 3201e04c3fSmrgstatic PFN_vkVoidFunction 3301e04c3fSmrgradv_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) 3401e04c3fSmrg{ 357ec681f3Smrg RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice); 367ec681f3Smrg return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName); 3701e04c3fSmrg} 3801e04c3fSmrg 397ec681f3Smrgstatic void 407ec681f3Smrgradv_wsi_set_memory_ownership(VkDevice _device, VkDeviceMemory _mem, VkBool32 ownership) 4101e04c3fSmrg{ 427ec681f3Smrg RADV_FROM_HANDLE(radv_device, device, _device); 437ec681f3Smrg RADV_FROM_HANDLE(radv_device_memory, mem, _mem); 4401e04c3fSmrg 457ec681f3Smrg if (device->use_global_bo_list) { 467ec681f3Smrg device->ws->buffer_make_resident(device->ws, mem->bo, ownership); 477ec681f3Smrg } 4801e04c3fSmrg} 4901e04c3fSmrg 507ec681f3SmrgVkResult 517ec681f3Smrgradv_init_wsi(struct radv_physical_device *physical_device) 5201e04c3fSmrg{ 537ec681f3Smrg VkResult result = 547ec681f3Smrg wsi_device_init(&physical_device->wsi_device, radv_physical_device_to_handle(physical_device), 557ec681f3Smrg radv_wsi_proc_addr, &physical_device->instance->vk.alloc, 567ec681f3Smrg physical_device->master_fd, &physical_device->instance->dri_options, false); 577ec681f3Smrg if (result != VK_SUCCESS) 587ec681f3Smrg return result; 5901e04c3fSmrg 607ec681f3Smrg physical_device->wsi_device.supports_modifiers = physical_device->rad_info.chip_class >= GFX9; 617ec681f3Smrg physical_device->wsi_device.set_memory_ownership = radv_wsi_set_memory_ownership; 6201e04c3fSmrg 637ec681f3Smrg physical_device->vk.wsi_device = &physical_device->wsi_device; 6401e04c3fSmrg 6501e04c3fSmrg return VK_SUCCESS; 6601e04c3fSmrg} 6701e04c3fSmrg 687ec681f3Smrgvoid 697ec681f3Smrgradv_finish_wsi(struct radv_physical_device *physical_device) 7001e04c3fSmrg{ 717ec681f3Smrg physical_device->vk.wsi_device = NULL; 727ec681f3Smrg wsi_device_finish(&physical_device->wsi_device, &physical_device->instance->vk.alloc); 737ec681f3Smrg} 7401e04c3fSmrg 757ec681f3SmrgVkResult 767ec681f3Smrgradv_AcquireNextImage2KHR(VkDevice _device, const VkAcquireNextImageInfoKHR *pAcquireInfo, 777ec681f3Smrg uint32_t *pImageIndex) 787ec681f3Smrg{ 797ec681f3Smrg RADV_FROM_HANDLE(radv_device, device, _device); 807ec681f3Smrg struct radv_physical_device *pdevice = device->physical_device; 817ec681f3Smrg RADV_FROM_HANDLE(radv_fence, fence, pAcquireInfo->fence); 827ec681f3Smrg RADV_FROM_HANDLE(radv_semaphore, semaphore, pAcquireInfo->semaphore); 837ec681f3Smrg 847ec681f3Smrg VkResult result = 857ec681f3Smrg wsi_common_acquire_next_image2(&pdevice->wsi_device, _device, pAcquireInfo, pImageIndex); 867ec681f3Smrg 877ec681f3Smrg if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) { 887ec681f3Smrg if (fence) { 897ec681f3Smrg struct radv_fence_part *part = 907ec681f3Smrg fence->temporary.kind != RADV_FENCE_NONE ? &fence->temporary : &fence->permanent; 917ec681f3Smrg 927ec681f3Smrg device->ws->signal_syncobj(device->ws, part->syncobj, 0); 937ec681f3Smrg } 947ec681f3Smrg if (semaphore) { 957ec681f3Smrg struct radv_semaphore_part *part = semaphore->temporary.kind != RADV_SEMAPHORE_NONE 967ec681f3Smrg ? &semaphore->temporary 977ec681f3Smrg : &semaphore->permanent; 987ec681f3Smrg 997ec681f3Smrg switch (part->kind) { 1007ec681f3Smrg case RADV_SEMAPHORE_NONE: 1017ec681f3Smrg /* Do not need to do anything. */ 1027ec681f3Smrg break; 1037ec681f3Smrg case RADV_SEMAPHORE_TIMELINE: 1047ec681f3Smrg case RADV_SEMAPHORE_TIMELINE_SYNCOBJ: 1057ec681f3Smrg unreachable("WSI only allows binary semaphores."); 1067ec681f3Smrg case RADV_SEMAPHORE_SYNCOBJ: 1077ec681f3Smrg device->ws->signal_syncobj(device->ws, part->syncobj, 0); 1087ec681f3Smrg break; 1097ec681f3Smrg } 1107ec681f3Smrg } 1117ec681f3Smrg } 1127ec681f3Smrg return result; 11301e04c3fSmrg} 11401e04c3fSmrg 1157ec681f3SmrgVkResult 1167ec681f3Smrgradv_QueuePresentKHR(VkQueue _queue, const VkPresentInfoKHR *pPresentInfo) 11701e04c3fSmrg{ 1187ec681f3Smrg RADV_FROM_HANDLE(radv_queue, queue, _queue); 1197ec681f3Smrg return wsi_common_queue_present(&queue->device->physical_device->wsi_device, 1207ec681f3Smrg radv_device_to_handle(queue->device), _queue, 1217ec681f3Smrg queue->vk.queue_family_index, pPresentInfo); 12201e04c3fSmrg} 123