2019-05-24 15:57:50 +01:00
|
|
|
/*
|
2025-01-15 16:05:05 +00:00
|
|
|
* Copyright (c) 2017, 2019, 2021-2025 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>
|
|
|
|
|
|
|
|
|
|
#include "private_data.hpp"
|
|
|
|
|
#include "swapchain_api.hpp"
|
2024-11-28 06:36:17 +00:00
|
|
|
|
2021-09-23 15:35:51 +01:00
|
|
|
#include <util/helpers.hpp>
|
2024-11-28 06:36:17 +00:00
|
|
|
|
|
|
|
|
#include <wsi/synchronization.hpp>
|
|
|
|
|
#include <wsi/wsi_factory.hpp>
|
|
|
|
|
#include <wsi/extensions/frame_boundary.hpp>
|
2025-01-15 16:05:05 +00:00
|
|
|
#include "util/macros.hpp"
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkCreateSwapchainKHR(VkDevice device, const VkSwapchainCreateInfoKHR *pSwapchainCreateInfo,
|
|
|
|
|
const VkAllocationCallbacks *pAllocator, VkSwapchainKHR *pSwapchain) VWL_API_POST
|
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
|
|
|
|
2021-07-21 20:19:52 +01:00
|
|
|
auto sc = wsi::allocate_surface_swapchain(surface, device_data, pAllocator);
|
2020-06-24 09:36:21 +01:00
|
|
|
if (sc == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2022-11-24 11:24:34 +00:00
|
|
|
TRY_LOG(sc->init(device, pSwapchainCreateInfo), "Failed to initialise swapchain");
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2022-11-24 11:24:34 +00:00
|
|
|
TRY_LOG(device_data.add_layer_swapchain(reinterpret_cast<VkSwapchainKHR>(sc.get())),
|
|
|
|
|
"Failed to associate swapchain with the layer");
|
2021-05-27 13:53:07 +01:00
|
|
|
|
2021-07-21 20:19:52 +01:00
|
|
|
*pSwapchain = reinterpret_cast<VkSwapchainKHR>(sc.release());
|
2022-11-24 11:24:34 +00:00
|
|
|
return VK_SUCCESS;
|
2020-06-24 09:36:21 +01:00
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(void)
|
|
|
|
|
wsi_layer_vkDestroySwapchainKHR(VkDevice device, VkSwapchainKHR swapc,
|
|
|
|
|
const VkAllocationCallbacks *pAllocator) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
layer::device_private_data &device_data = layer::device_private_data::get(device);
|
2025-03-10 13:58:12 +00:00
|
|
|
if (swapc == VK_NULL_HANDLE)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
if (!device_data.layer_owns_swapchain(swapc))
|
|
|
|
|
{
|
2025-03-10 13:58:12 +00:00
|
|
|
device_data.disp.DestroySwapchainKHR(device_data.device, swapc, pAllocator);
|
|
|
|
|
return;
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(swapc != VK_NULL_HANDLE);
|
2023-10-30 15:24:42 +08:00
|
|
|
device_data.remove_layer_swapchain(swapc);
|
|
|
|
|
|
2021-10-07 14:48:44 +01:00
|
|
|
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
2021-05-27 13:53:07 +01:00
|
|
|
wsi::destroy_surface_swapchain(sc, device_data, pAllocator);
|
2020-06-24 09:36:21 +01:00
|
|
|
}
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetSwapchainImagesKHR(VkDevice device, VkSwapchainKHR swapc, uint32_t *pSwapchainImageCount,
|
|
|
|
|
VkImage *pSwapchainImages) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
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);
|
2021-10-07 14:48:44 +01:00
|
|
|
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
2020-06-24 09:36:21 +01:00
|
|
|
return sc->get_swapchain_images(pSwapchainImageCount, pSwapchainImages);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkAcquireNextImageKHR(VkDevice device, VkSwapchainKHR swapc, uint64_t timeout, VkSemaphore semaphore,
|
|
|
|
|
VkFence fence, uint32_t *pImageIndex) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
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);
|
2024-06-26 13:34:16 +01:00
|
|
|
assert(semaphore != VK_NULL_HANDLE || fence != VK_NULL_HANDLE);
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(pImageIndex != nullptr);
|
2021-10-07 14:48:44 +01:00
|
|
|
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
2020-06-24 09:36:21 +01:00
|
|
|
return sc->acquire_next_image(timeout, semaphore, fence, pImageIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-20 15:27:47 +01:00
|
|
|
static VkResult submit_wait_request(VkQueue queue, const VkPresentInfoKHR &present_info,
|
2024-10-01 15:18:22 +00:00
|
|
|
layer::device_private_data &device_data, bool &frame_boundary_event_handled)
|
2021-10-20 15:27:47 +01:00
|
|
|
{
|
|
|
|
|
util::vector<VkSemaphore> swapchain_semaphores{ util::allocator(device_data.get_allocator(),
|
|
|
|
|
VK_SYSTEM_ALLOCATION_SCOPE_COMMAND) };
|
|
|
|
|
if (!swapchain_semaphores.try_resize(present_info.swapchainCount))
|
|
|
|
|
{
|
|
|
|
|
return VK_ERROR_OUT_OF_HOST_MEMORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < present_info.swapchainCount; ++i)
|
|
|
|
|
{
|
|
|
|
|
auto swapchain = reinterpret_cast<wsi::swapchain_base *>(present_info.pSwapchains[i]);
|
|
|
|
|
swapchain_semaphores[i] = swapchain->get_image_present_semaphore(present_info.pImageIndices[i]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-09 16:04:28 +01:00
|
|
|
wsi::queue_submit_semaphores semaphores = { present_info.pWaitSemaphores, present_info.waitSemaphoreCount,
|
|
|
|
|
swapchain_semaphores.data(),
|
|
|
|
|
static_cast<uint32_t>(swapchain_semaphores.size()) };
|
2021-10-20 15:27:47 +01:00
|
|
|
|
2024-10-01 15:18:22 +00:00
|
|
|
void *submission_pnext = nullptr;
|
|
|
|
|
auto frame_boundary = wsi::create_frame_boundary(present_info);
|
|
|
|
|
if (frame_boundary.has_value())
|
|
|
|
|
{
|
|
|
|
|
submission_pnext = &frame_boundary.value();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Notify that we don't want to pass any further frame boundary events */
|
|
|
|
|
frame_boundary_event_handled = submission_pnext != nullptr;
|
|
|
|
|
|
2024-10-10 10:24:36 +01:00
|
|
|
TRY(wsi::sync_queue_submit(device_data, queue, VK_NULL_HANDLE, semaphores, submission_pnext));
|
2021-10-20 15:27:47 +01:00
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkQueuePresentKHR(VkQueue queue, const VkPresentInfoKHR *pPresentInfo) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2021-10-20 15:27:47 +01:00
|
|
|
/* Avoid allocating on the heap when there is only one swapchain. */
|
|
|
|
|
const VkPresentInfoKHR *present_info = pPresentInfo;
|
2024-04-09 16:14:27 +01:00
|
|
|
bool use_image_present_semaphore = false;
|
2024-10-01 15:18:22 +00:00
|
|
|
bool frame_boundary_event_handled = true;
|
2021-10-20 15:27:47 +01:00
|
|
|
if (pPresentInfo->swapchainCount > 1)
|
|
|
|
|
{
|
2024-10-01 15:18:22 +00:00
|
|
|
TRY_LOG_CALL(submit_wait_request(queue, *pPresentInfo, device_data, frame_boundary_event_handled));
|
2024-04-09 16:14:27 +01:00
|
|
|
use_image_present_semaphore = true;
|
2021-10-20 15:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
VkResult ret = VK_SUCCESS;
|
2024-08-22 16:45:28 +01:00
|
|
|
|
2025-09-29 15:11:01 +00:00
|
|
|
const uint64_t *p_present_ids{ nullptr };
|
2025-08-18 09:23:02 +00:00
|
|
|
|
2025-09-29 15:11:01 +00:00
|
|
|
auto *present_id2_ext =
|
|
|
|
|
util::find_extension<VkPresentId2KHR>(VK_STRUCTURE_TYPE_PRESENT_ID_2_KHR, pPresentInfo->pNext);
|
|
|
|
|
if (present_id2_ext != nullptr)
|
2025-08-18 09:23:02 +00:00
|
|
|
{
|
2025-09-29 15:11:01 +00:00
|
|
|
p_present_ids = present_id2_ext->pPresentIds;
|
2025-08-18 09:23:02 +00:00
|
|
|
}
|
2025-09-29 15:11:01 +00:00
|
|
|
else
|
2025-08-18 09:23:02 +00:00
|
|
|
{
|
|
|
|
|
auto *ext = util::find_extension<VkPresentIdKHR>(VK_STRUCTURE_TYPE_PRESENT_ID_KHR, pPresentInfo->pNext);
|
|
|
|
|
if (ext != nullptr)
|
|
|
|
|
{
|
2025-09-29 15:11:01 +00:00
|
|
|
p_present_ids = ext->pPresentIds;
|
|
|
|
|
/* If a VkPresentIdKHR structure is included in the pNext chain, and the presentId feature is not enabled,
|
|
|
|
|
* each presentIds entry in that structure must be NULL */
|
|
|
|
|
if (p_present_ids != nullptr)
|
|
|
|
|
{
|
|
|
|
|
assert(device_data.is_present_id_enabled());
|
|
|
|
|
}
|
2025-08-18 09:23:02 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-09 16:14:27 +01:00
|
|
|
const auto present_fence_info = util::find_extension<VkSwapchainPresentFenceInfoEXT>(
|
|
|
|
|
VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_FENCE_INFO_EXT, present_info->pNext);
|
2024-05-09 09:32:42 +01:00
|
|
|
const auto swapchain_present_mode_info = util::find_extension<VkSwapchainPresentModeInfoEXT>(
|
|
|
|
|
VK_STRUCTURE_TYPE_SWAPCHAIN_PRESENT_MODE_INFO_EXT, present_info->pNext);
|
2024-10-02 17:59:01 +01:00
|
|
|
#if VULKAN_WSI_LAYER_EXPERIMENTAL
|
|
|
|
|
const auto present_timings_info =
|
|
|
|
|
util::find_extension<VkPresentTimingsInfoEXT>(VK_STRUCTURE_TYPE_PRESENT_TIMINGS_INFO_EXT, present_info->pNext);
|
|
|
|
|
if (present_timings_info)
|
|
|
|
|
{
|
|
|
|
|
assert(present_timings_info->swapchainCount == pPresentInfo->swapchainCount);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2020-06-24 09:36:21 +01:00
|
|
|
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];
|
2021-10-07 14:48:44 +01:00
|
|
|
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapc);
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(sc != nullptr);
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2024-08-22 16:45:28 +01:00
|
|
|
uint64_t present_id = 0; /* No present ID by default */
|
2025-08-18 09:23:02 +00:00
|
|
|
|
2025-09-29 15:11:01 +00:00
|
|
|
if (p_present_ids != nullptr)
|
2025-08-18 09:23:02 +00:00
|
|
|
{
|
2025-09-29 15:11:01 +00:00
|
|
|
present_id = p_present_ids[i];
|
|
|
|
|
|
|
|
|
|
/* If a VkPresentId2KHR structure is included in the pNext chain, and the presentId2 feature is not enabled,
|
|
|
|
|
* each presentIds entry in that structure must be zero. */
|
|
|
|
|
if (present_id2_ext && present_id != 0)
|
|
|
|
|
{
|
|
|
|
|
assert(device_data.is_present_id2_enabled());
|
|
|
|
|
}
|
2025-08-18 09:23:02 +00:00
|
|
|
}
|
2024-08-22 16:45:28 +01:00
|
|
|
|
|
|
|
|
wsi::swapchain_presentation_parameters present_params{};
|
2024-05-09 09:32:42 +01:00
|
|
|
present_params.present_fence = (present_fence_info == nullptr) ? VK_NULL_HANDLE : present_fence_info->pFences[i];
|
|
|
|
|
if (swapchain_present_mode_info != nullptr)
|
|
|
|
|
{
|
|
|
|
|
present_params.switch_presentation_mode = true;
|
|
|
|
|
present_params.present_mode = swapchain_present_mode_info->pPresentModes[i];
|
|
|
|
|
}
|
2024-08-22 16:45:28 +01:00
|
|
|
|
|
|
|
|
present_params.pending_present.image_index = pPresentInfo->pImageIndices[i];
|
|
|
|
|
present_params.pending_present.present_id = present_id;
|
|
|
|
|
|
|
|
|
|
present_params.use_image_present_semaphore = use_image_present_semaphore;
|
2024-10-01 15:18:22 +00:00
|
|
|
present_params.handle_present_frame_boundary_event = frame_boundary_event_handled;
|
2024-10-02 17:59:01 +01:00
|
|
|
|
|
|
|
|
#if VULKAN_WSI_LAYER_EXPERIMENTAL
|
|
|
|
|
if (present_timings_info)
|
|
|
|
|
{
|
2024-11-28 06:36:17 +00:00
|
|
|
present_params.m_present_timing_info = present_timings_info->pTimingInfos[i];
|
|
|
|
|
present_params.m_present_timing_info.pNext = nullptr;
|
2024-10-02 17:59:01 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
2024-08-22 16:45:28 +01:00
|
|
|
VkResult res = sc->queue_present(queue, present_info, present_params);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetDeviceGroupPresentCapabilitiesKHR(
|
|
|
|
|
VkDevice device, VkDeviceGroupPresentCapabilitiesKHR *pDeviceGroupPresentCapabilities) VWL_API_POST
|
2021-06-25 11:35:11 +01:00
|
|
|
{
|
2025-01-15 16:05:05 +00:00
|
|
|
UNUSED(device);
|
2021-06-25 11:35:11 +01:00
|
|
|
assert(pDeviceGroupPresentCapabilities != nullptr);
|
|
|
|
|
|
|
|
|
|
pDeviceGroupPresentCapabilities->presentMask[0] = 1;
|
|
|
|
|
pDeviceGroupPresentCapabilities->modes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
|
|
|
|
|
|
|
|
|
|
for (uint32_t i = 1; i < VK_MAX_DEVICE_GROUP_SIZE_KHR; i++)
|
|
|
|
|
{
|
|
|
|
|
pDeviceGroupPresentCapabilities->presentMask[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetDeviceGroupSurfacePresentModesKHR(VkDevice device, VkSurfaceKHR surface,
|
|
|
|
|
VkDeviceGroupPresentModeFlagsKHR *pModes) VWL_API_POST
|
2021-06-25 11:35:11 +01:00
|
|
|
{
|
|
|
|
|
assert(pModes != nullptr);
|
|
|
|
|
|
|
|
|
|
auto &device_data = layer::device_private_data::get(device);
|
|
|
|
|
auto &instance = device_data.instance_data;
|
|
|
|
|
|
|
|
|
|
if (!instance.should_layer_handle_surface(device_data.physical_device, surface))
|
|
|
|
|
{
|
|
|
|
|
return device_data.disp.GetDeviceGroupSurfacePresentModesKHR(device, surface, pModes);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*pModes = VK_DEVICE_GROUP_PRESENT_MODE_LOCAL_BIT_KHR;
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetPhysicalDevicePresentRectanglesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
|
|
|
|
|
uint32_t *pRectCount, VkRect2D *pRects) VWL_API_POST
|
2021-06-25 11:35:11 +01:00
|
|
|
{
|
|
|
|
|
assert(surface);
|
|
|
|
|
assert(pRectCount != nullptr);
|
|
|
|
|
|
|
|
|
|
auto &instance = layer::instance_private_data::get(physicalDevice);
|
|
|
|
|
|
|
|
|
|
if (!instance.should_layer_handle_surface(physicalDevice, surface))
|
|
|
|
|
{
|
|
|
|
|
return instance.disp.GetPhysicalDevicePresentRectanglesKHR(physicalDevice, surface, pRectCount, pRects);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult result;
|
2021-07-21 20:19:52 +01:00
|
|
|
wsi::surface_properties *props = wsi::get_surface_properties(instance, surface);
|
2021-06-25 11:35:11 +01:00
|
|
|
assert(props);
|
|
|
|
|
|
|
|
|
|
if (nullptr == pRects)
|
|
|
|
|
{
|
|
|
|
|
*pRectCount = 1;
|
|
|
|
|
result = VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
else if (0 == *pRectCount)
|
|
|
|
|
{
|
|
|
|
|
result = VK_INCOMPLETE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*pRectCount = 1;
|
|
|
|
|
|
2022-07-04 11:11:51 +01:00
|
|
|
VkSurfaceCapabilitiesKHR surface_caps = {};
|
2022-02-28 16:21:06 +00:00
|
|
|
result = props->get_surface_capabilities(physicalDevice, &surface_caps);
|
2021-06-25 11:35:11 +01:00
|
|
|
|
|
|
|
|
if (result != VK_SUCCESS)
|
|
|
|
|
{
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pRects[0].offset.x = 0;
|
|
|
|
|
pRects[0].offset.y = 0;
|
|
|
|
|
pRects[0].extent = surface_caps.currentExtent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkAcquireNextImage2KHR(VkDevice device, const VkAcquireNextImageInfoKHR *pAcquireInfo,
|
|
|
|
|
uint32_t *pImageIndex) VWL_API_POST
|
2021-06-25 11:35:11 +01:00
|
|
|
{
|
|
|
|
|
assert(pAcquireInfo != VK_NULL_HANDLE);
|
|
|
|
|
assert(pAcquireInfo->swapchain != VK_NULL_HANDLE);
|
|
|
|
|
assert(pAcquireInfo->semaphore != VK_NULL_HANDLE || pAcquireInfo->fence != VK_NULL_HANDLE);
|
|
|
|
|
assert(pImageIndex != nullptr);
|
|
|
|
|
|
|
|
|
|
auto &device_data = layer::device_private_data::get(device);
|
|
|
|
|
|
|
|
|
|
if (!device_data.layer_owns_swapchain(pAcquireInfo->swapchain))
|
|
|
|
|
{
|
|
|
|
|
return device_data.disp.AcquireNextImage2KHR(device, pAcquireInfo, pImageIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-07 14:48:44 +01:00
|
|
|
auto *sc = reinterpret_cast<wsi::swapchain_base *>(pAcquireInfo->swapchain);
|
2021-06-25 11:35:11 +01:00
|
|
|
|
|
|
|
|
return sc->acquire_next_image(pAcquireInfo->timeout, pAcquireInfo->semaphore, pAcquireInfo->fence, pImageIndex);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator,
|
|
|
|
|
VkImage *pImage) VWL_API_POST
|
2021-09-23 15:35:51 +01:00
|
|
|
{
|
|
|
|
|
auto &device_data = layer::device_private_data::get(device);
|
|
|
|
|
|
2021-10-07 14:48:44 +01:00
|
|
|
const auto *image_sc_create_info = util::find_extension<VkImageSwapchainCreateInfoKHR>(
|
|
|
|
|
VK_STRUCTURE_TYPE_IMAGE_SWAPCHAIN_CREATE_INFO_KHR, pCreateInfo->pNext);
|
2021-09-23 15:35:51 +01:00
|
|
|
|
|
|
|
|
if (image_sc_create_info == nullptr || !device_data.layer_owns_swapchain(image_sc_create_info->swapchain))
|
|
|
|
|
{
|
|
|
|
|
return device_data.disp.CreateImage(device_data.device, pCreateInfo, pAllocator, pImage);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto sc = reinterpret_cast<wsi::swapchain_base *>(image_sc_create_info->swapchain);
|
2022-07-04 10:15:14 +01:00
|
|
|
return sc->create_aliased_image_handle(pImage);
|
2021-09-23 15:35:51 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkBindImageMemory2(VkDevice device, uint32_t bindInfoCount,
|
|
|
|
|
const VkBindImageMemoryInfo *pBindInfos) VWL_API_POST
|
2021-09-23 15:35:51 +01:00
|
|
|
{
|
|
|
|
|
auto &device_data = layer::device_private_data::get(device);
|
|
|
|
|
|
2024-02-20 08:37:08 +01:00
|
|
|
VkResult endpoint_result = VK_SUCCESS;
|
|
|
|
|
bool maintenance_6 = device_data.is_device_extension_enabled(VK_KHR_MAINTENANCE_6_EXTENSION_NAME);
|
2021-09-23 15:35:51 +01:00
|
|
|
for (uint32_t i = 0; i < bindInfoCount; i++)
|
|
|
|
|
{
|
2024-02-20 08:37:08 +01:00
|
|
|
VkResult result = VK_SUCCESS;
|
|
|
|
|
std::string_view error_message{};
|
|
|
|
|
|
2021-10-07 14:48:44 +01:00
|
|
|
const auto *bind_sc_info = util::find_extension<VkBindImageMemorySwapchainInfoKHR>(
|
2021-09-23 15:35:51 +01:00
|
|
|
VK_STRUCTURE_TYPE_BIND_IMAGE_MEMORY_SWAPCHAIN_INFO_KHR, pBindInfos[i].pNext);
|
|
|
|
|
|
|
|
|
|
if (bind_sc_info == nullptr || bind_sc_info->swapchain == VK_NULL_HANDLE ||
|
|
|
|
|
!device_data.layer_owns_swapchain(bind_sc_info->swapchain))
|
|
|
|
|
{
|
2024-02-20 08:37:08 +01:00
|
|
|
result = device_data.disp.BindImageMemory2KHR(device, 1, &pBindInfos[i]);
|
|
|
|
|
error_message = "Failed to bind image memory";
|
2021-09-23 15:35:51 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
auto sc = reinterpret_cast<wsi::swapchain_base *>(bind_sc_info->swapchain);
|
2025-11-20 13:55:45 +00:00
|
|
|
|
|
|
|
|
result = sc->bind_swapchain_image(&pBindInfos[i], bind_sc_info);
|
2024-02-20 08:37:08 +01:00
|
|
|
error_message = "Failed to bind an image to the swapchain";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (maintenance_6)
|
|
|
|
|
{
|
|
|
|
|
const auto *bind_status =
|
|
|
|
|
util::find_extension<VkBindMemoryStatusKHR>(VK_STRUCTURE_TYPE_BIND_MEMORY_STATUS_KHR, pBindInfos[i].pNext);
|
|
|
|
|
if (nullptr != bind_status)
|
|
|
|
|
{
|
|
|
|
|
assert(bind_status->pResult != nullptr);
|
|
|
|
|
*bind_status->pResult = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (VK_SUCCESS != result)
|
|
|
|
|
{
|
|
|
|
|
/* VK_KHR_maintenance6 requires that all memory binding operations must be attempted, so the results are stored
|
|
|
|
|
rather than returned early upon failure */
|
|
|
|
|
WSI_LOG_ERROR("%s", error_message.data());
|
|
|
|
|
endpoint_result = result;
|
2021-09-23 15:35:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-02-20 08:37:08 +01:00
|
|
|
return endpoint_result;
|
2021-09-23 15:35:51 +01:00
|
|
|
}
|
2024-04-12 14:52:39 +02:00
|
|
|
|
|
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetSwapchainStatusKHR(VkDevice device, VkSwapchainKHR swapchain) VWL_API_POST
|
|
|
|
|
{
|
|
|
|
|
auto &device_data = layer::device_private_data::get(device);
|
|
|
|
|
|
|
|
|
|
if (!device_data.layer_owns_swapchain(swapchain))
|
|
|
|
|
{
|
|
|
|
|
return device_data.disp.GetSwapchainStatusKHR(device, swapchain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto *sc = reinterpret_cast<wsi::swapchain_base *>(swapchain);
|
|
|
|
|
|
|
|
|
|
return sc->get_swapchain_status();
|
|
|
|
|
}
|