17ec681f3Smrg/* 27ec681f3Smrg * Copyright © 2021 Collabora Ltd. 37ec681f3Smrg * 47ec681f3Smrg * Derived from tu_wsi.c: 57ec681f3Smrg * Copyright © 2016 Red Hat 67ec681f3Smrg * Copyright © 2015 Intel Corporation 77ec681f3Smrg * 87ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 97ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 107ec681f3Smrg * to deal in the Software without restriction, including without limitation 117ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 127ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 137ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 147ec681f3Smrg * 157ec681f3Smrg * The above copyright notice and this permission notice (including the next 167ec681f3Smrg * paragraph) shall be included in all copies or substantial portions of the 177ec681f3Smrg * Software. 187ec681f3Smrg * 197ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 207ec681f3Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 217ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 227ec681f3Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 237ec681f3Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 247ec681f3Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 257ec681f3Smrg * DEALINGS IN THE SOFTWARE. 267ec681f3Smrg */ 277ec681f3Smrg 287ec681f3Smrg#include "panvk_private.h" 297ec681f3Smrg 307ec681f3Smrg#include "vk_util.h" 317ec681f3Smrg#include "wsi_common.h" 327ec681f3Smrg 337ec681f3Smrgstatic VKAPI_PTR PFN_vkVoidFunction 347ec681f3Smrgpanvk_wsi_proc_addr(VkPhysicalDevice physicalDevice, const char *pName) 357ec681f3Smrg{ 367ec681f3Smrg VK_FROM_HANDLE(panvk_physical_device, pdevice, physicalDevice); 377ec681f3Smrg return vk_instance_get_proc_addr_unchecked(&pdevice->instance->vk, pName); 387ec681f3Smrg} 397ec681f3Smrg 407ec681f3SmrgVkResult 417ec681f3Smrgpanvk_wsi_init(struct panvk_physical_device *physical_device) 427ec681f3Smrg{ 437ec681f3Smrg VkResult result; 447ec681f3Smrg 457ec681f3Smrg result = wsi_device_init(&physical_device->wsi_device, 467ec681f3Smrg panvk_physical_device_to_handle(physical_device), 477ec681f3Smrg panvk_wsi_proc_addr, 487ec681f3Smrg &physical_device->instance->vk.alloc, 497ec681f3Smrg physical_device->master_fd, NULL, 507ec681f3Smrg false); 517ec681f3Smrg if (result != VK_SUCCESS) 527ec681f3Smrg return result; 537ec681f3Smrg 547ec681f3Smrg physical_device->wsi_device.supports_modifiers = false; 557ec681f3Smrg 567ec681f3Smrg physical_device->vk.wsi_device = &physical_device->wsi_device; 577ec681f3Smrg 587ec681f3Smrg return VK_SUCCESS; 597ec681f3Smrg} 607ec681f3Smrg 617ec681f3Smrgvoid 627ec681f3Smrgpanvk_wsi_finish(struct panvk_physical_device *physical_device) 637ec681f3Smrg{ 647ec681f3Smrg physical_device->vk.wsi_device = NULL; 657ec681f3Smrg wsi_device_finish(&physical_device->wsi_device, 667ec681f3Smrg &physical_device->instance->vk.alloc); 677ec681f3Smrg} 687ec681f3Smrg 697ec681f3SmrgVkResult 707ec681f3Smrgpanvk_AcquireNextImage2KHR(VkDevice _device, 717ec681f3Smrg const VkAcquireNextImageInfoKHR *pAcquireInfo, 727ec681f3Smrg uint32_t *pImageIndex) 737ec681f3Smrg{ 747ec681f3Smrg VK_FROM_HANDLE(panvk_device, device, _device); 757ec681f3Smrg VK_FROM_HANDLE(panvk_fence, fence, pAcquireInfo->fence); 767ec681f3Smrg VK_FROM_HANDLE(panvk_semaphore, sem, pAcquireInfo->semaphore); 777ec681f3Smrg struct panvk_physical_device *pdevice = device->physical_device; 787ec681f3Smrg 797ec681f3Smrg VkResult result = 807ec681f3Smrg wsi_common_acquire_next_image2(&pdevice->wsi_device, _device, 817ec681f3Smrg pAcquireInfo, pImageIndex); 827ec681f3Smrg 837ec681f3Smrg /* signal fence/semaphore - image is available immediately */ 847ec681f3Smrg if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) { 857ec681f3Smrg panvk_signal_syncobjs(device, fence ? &fence->syncobj : NULL, 867ec681f3Smrg sem ? &sem->syncobj : NULL); 877ec681f3Smrg } 887ec681f3Smrg 897ec681f3Smrg return result; 907ec681f3Smrg} 91