2019-05-24 15:57:50 +01:00
|
|
|
/*
|
2020-06-24 09:36:21 +01:00
|
|
|
* Copyright (c) 2017, 2019, 2021 Arm Limited.
|
2019-05-24 15:57:50 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to
|
|
|
|
|
* deal in the Software without restriction, including without limitation the
|
|
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @file swapchain_api.cpp
|
|
|
|
|
*
|
|
|
|
|
* @brief Contains the Vulkan entrypoints for the swapchain.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <new>
|
|
|
|
|
|
2019-11-21 15:23:59 +00:00
|
|
|
#include <wsi/wsi_factory.hpp>
|
2019-05-24 15:57:50 +01:00
|
|
|
|
|
|
|
|
#include "private_data.hpp"
|
|
|
|
|
#include "swapchain_api.hpp"
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
extern "C" {
|
|
|
|
|
|
|
|
|
|
VKAPI_ATTR VkResult wsi_layer_vkCreateSwapchainKHR(VkDevice device,
|
|
|
|
|
const VkSwapchainCreateInfoKHR *pSwapchainCreateInfo,
|
|
|
|
|
const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain)
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(pSwapchain != nullptr);
|
|
|
|
|
layer::device_private_data &device_data = layer::device_private_data::get(device);
|
|
|
|
|
VkSurfaceKHR surface = pSwapchainCreateInfo->surface;
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
if (!device_data.should_layer_create_swapchain(surface))
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2020-06-24 09:36:21 +01:00
|
|
|
if (!device_data.can_icds_create_swapchain(surface))
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2020-06-24 09:36:21 +01:00
|
|
|
return VK_ERROR_INITIALIZATION_FAILED;
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
2020-06-24 09:36:21 +01:00
|
|
|
return device_data.disp.CreateSwapchainKHR(device_data.device, pSwapchainCreateInfo, pAllocator, pSwapchain);
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
wsi::swapchain_base *sc = wsi::allocate_surface_swapchain(surface, device_data, pAllocator);
|
|
|
|
|
if (sc == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
VkResult result = sc->init(device, pSwapchainCreateInfo);
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
/* Error occured during initialization, need to free allocated memory. */
|
|
|
|
|
wsi::destroy_surface_swapchain(sc, pAllocator);
|
2019-05-24 15:57:50 +01:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
*pSwapchain = reinterpret_cast<VkSwapchainKHR>(sc);
|
|
|
|
|
device_data.add_layer_swapchain(*pSwapchain);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
VKAPI_ATTR void wsi_layer_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapc,
|
|
|
|
|
const VkAllocationCallbacks *pAllocator)
|
|
|
|
|
{
|
|
|
|
|
layer::device_private_data &device_data = layer::device_private_data::get(device);
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
if (!device_data.layer_owns_swapchain(swapc))
|
|
|
|
|
{
|
|
|
|
|
return device_data.disp.DestroySwapchainKHR(device_data.device, swapc, pAllocator);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(swapc != VK_NULL_HANDLE);
|
|
|
|
|
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
|
|
|
|
wsi::destroy_surface_swapchain(sc, pAllocator);
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
VKAPI_ATTR VkResult wsi_layer_vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapc,
|
|
|
|
|
uint32_t *pSwapchainImageCount, VkImage *pSwapchainImages)
|
|
|
|
|
{
|
|
|
|
|
layer::device_private_data &device_data = layer::device_private_data::get(device);
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
if (!device_data.layer_owns_swapchain(swapc))
|
|
|
|
|
{
|
|
|
|
|
return device_data.disp.GetSwapchainImagesKHR(device_data.device, swapc, pSwapchainImageCount, pSwapchainImages);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(pSwapchainImageCount != nullptr);
|
|
|
|
|
assert(swapc != VK_NULL_HANDLE);
|
|
|
|
|
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
|
|
|
|
return sc->get_swapchain_images(pSwapchainImageCount, pSwapchainImages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VKAPI_ATTR VkResult wsi_layer_vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapc, uint64_t timeout,
|
|
|
|
|
VkSemaphore semaphore, VkFence fence, uint32_t *pImageIndex)
|
|
|
|
|
{
|
|
|
|
|
layer::device_private_data &device_data = layer::device_private_data::get(device);
|
|
|
|
|
|
|
|
|
|
if (!device_data.layer_owns_swapchain(swapc))
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2020-06-24 09:36:21 +01:00
|
|
|
return device_data.disp.AcquireNextImageKHR(device_data.device, swapc, timeout, semaphore, fence, pImageIndex);
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(swapc != VK_NULL_HANDLE);
|
|
|
|
|
assert(semaphore != VK_NULL_HANDLE || fence != VK_NULL_HANDLE);
|
|
|
|
|
assert(pImageIndex != nullptr);
|
|
|
|
|
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
|
|
|
|
return sc->acquire_next_image(timeout, semaphore, fence, pImageIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VKAPI_ATTR VkResult wsi_layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo)
|
|
|
|
|
{
|
|
|
|
|
assert(queue != VK_NULL_HANDLE);
|
|
|
|
|
assert(pPresentInfo != nullptr);
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
layer::device_private_data &device_data = layer::device_private_data::get(queue);
|
|
|
|
|
|
|
|
|
|
if (!device_data.layer_owns_all_swapchains(pPresentInfo->pSwapchains, pPresentInfo->swapchainCount))
|
|
|
|
|
{
|
|
|
|
|
return device_data.disp.QueuePresentKHR(queue, pPresentInfo);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
VkResult ret = VK_SUCCESS;
|
|
|
|
|
for (uint32_t i = 0; i < pPresentInfo->swapchainCount; ++i)
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2020-06-24 09:36:21 +01:00
|
|
|
VkSwapchainKHR swapc = pPresentInfo->pSwapchains[i];
|
|
|
|
|
|
|
|
|
|
wsi::swapchain_base *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
|
|
|
|
assert(sc != nullptr);
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
VkResult res = sc->queue_present(queue, pPresentInfo, pPresentInfo->pImageIndices[i]);
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
if (pPresentInfo->pResults != nullptr)
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2020-06-24 09:36:21 +01:00
|
|
|
pPresentInfo->pResults[i] = res;
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
if (res != VK_SUCCESS && ret == VK_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
ret = res;
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-24 15:57:50 +01:00
|
|
|
} /* extern "C" */
|