2019-05-24 15:57:50 +01:00
|
|
|
/*
|
2024-11-28 06:36:17 +00:00
|
|
|
* Copyright (c) 2017-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.hpp
|
|
|
|
|
*
|
|
|
|
|
* @brief Contains the class definition for a headless swapchain.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2025-11-20 13:55:45 +00:00
|
|
|
extern "C" {
|
2019-05-24 15:57:50 +01:00
|
|
|
#include <vulkan/vk_icd.h>
|
2025-11-20 13:55:45 +00:00
|
|
|
}
|
2024-11-28 06:36:17 +00:00
|
|
|
|
2019-05-24 15:57:50 +01:00
|
|
|
#include <wsi/swapchain_base.hpp>
|
|
|
|
|
|
|
|
|
|
namespace wsi
|
|
|
|
|
{
|
|
|
|
|
namespace headless
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @brief Headless swapchain class.
|
|
|
|
|
*
|
|
|
|
|
* This class is mostly empty, because all the swapchain stuff is handled by the swapchain class,
|
|
|
|
|
* which we inherit. This class only provides a way to create an image and page-flip ops.
|
|
|
|
|
*/
|
|
|
|
|
class swapchain : public wsi::swapchain_base
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator);
|
|
|
|
|
|
|
|
|
|
~swapchain();
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
/**
|
|
|
|
|
* @brief Platform specific init
|
|
|
|
|
*/
|
2021-10-14 15:45:34 +00:00
|
|
|
VkResult init_platform(VkDevice device, const VkSwapchainCreateInfoKHR *swapchain_create_info,
|
2024-04-12 14:52:39 +02:00
|
|
|
bool &use_presentation_thread) override;
|
2019-05-24 15:57:50 +01:00
|
|
|
|
2021-09-23 15:35:51 +01:00
|
|
|
/**
|
2025-11-20 13:55:45 +00:00
|
|
|
* @brief Initalize backend specific image factory.
|
2024-04-25 15:07:47 +01:00
|
|
|
*
|
2025-11-20 13:55:45 +00:00
|
|
|
* @param swapchain_create_info Swapchain create info.
|
|
|
|
|
* @return Vulkan result code.
|
2024-04-25 15:07:47 +01:00
|
|
|
*/
|
2025-11-20 13:55:45 +00:00
|
|
|
VkResult init_image_factory(const VkSwapchainCreateInfoKHR &swapchain_create_info);
|
2024-04-25 15:07:47 +01:00
|
|
|
|
|
|
|
|
/**
|
2025-11-20 13:55:45 +00:00
|
|
|
* @brief Allocates and binds a new swapchain image.
|
2021-09-23 15:35:51 +01:00
|
|
|
*
|
2025-11-20 13:55:45 +00:00
|
|
|
* @param swapchain_image Swapchain image.
|
2019-05-24 15:57:50 +01:00
|
|
|
*
|
2025-11-20 13:55:45 +00:00
|
|
|
* @return Returns VK_SUCCESS on success, otherwise an appropriate error code.
|
2019-05-24 15:57:50 +01:00
|
|
|
*/
|
2025-11-20 13:55:45 +00:00
|
|
|
VkResult allocate_and_bind_swapchain_image(swapchain_image &image) override;
|
2019-05-24 15:57:50 +01:00
|
|
|
|
|
|
|
|
/**
|
2024-08-22 16:45:28 +01:00
|
|
|
* @brief Method to present and image
|
2019-05-24 15:57:50 +01:00
|
|
|
*
|
2024-08-22 16:45:28 +01:00
|
|
|
* It sends the next image for presentation to the presentation engine.
|
2019-05-24 15:57:50 +01:00
|
|
|
*
|
2024-08-22 16:45:28 +01:00
|
|
|
* @param pending_present Information on the pending present request.
|
2019-05-24 15:57:50 +01:00
|
|
|
*/
|
2024-08-22 16:45:28 +01:00
|
|
|
void present_image(const pending_present_request &pending_present) override;
|
2019-05-24 15:57:50 +01:00
|
|
|
|
|
|
|
|
/**
|
2025-11-20 13:55:45 +00:00
|
|
|
* @brief Get the image factory used for creating swapchain images.
|
2019-05-24 15:57:50 +01:00
|
|
|
*
|
2025-11-20 13:55:45 +00:00
|
|
|
* @return Swapchain image factory.
|
2019-05-24 15:57:50 +01:00
|
|
|
*/
|
2025-11-20 13:55:45 +00:00
|
|
|
swapchain_image_factory &get_image_factory() override;
|
2025-11-04 12:20:24 +00:00
|
|
|
|
2025-11-20 13:55:45 +00:00
|
|
|
private:
|
2021-09-23 15:35:51 +01:00
|
|
|
/**
|
2025-11-20 13:55:45 +00:00
|
|
|
* @brief Adds required extensions to the extension list of the swapchain
|
2021-09-23 15:35:51 +01:00
|
|
|
*
|
2025-11-20 13:55:45 +00:00
|
|
|
* @param device Vulkan device
|
|
|
|
|
* @param swapchain_create_info Swapchain create info
|
|
|
|
|
* @return VK_SUCCESS on success, other result codes on failure
|
2021-09-23 15:35:51 +01:00
|
|
|
*/
|
2025-11-20 13:55:45 +00:00
|
|
|
VkResult add_required_extensions(VkDevice device, const VkSwapchainCreateInfoKHR *swapchain_create_info) override;
|
2021-10-27 15:47:08 +01:00
|
|
|
|
2025-03-26 13:18:02 +00:00
|
|
|
/**
|
2025-11-20 13:55:45 +00:00
|
|
|
* @brief Create the image creator with required extensions.
|
2025-03-26 13:18:02 +00:00
|
|
|
*
|
2025-11-20 13:55:45 +00:00
|
|
|
* @param swapchain_create_info VkSwapchainCreateInfoKHR passed by the application.
|
|
|
|
|
* @return If error occurred, returns VkResult, vulkan_image_handle_creator handle otherwise.
|
2025-03-26 13:18:02 +00:00
|
|
|
*/
|
2025-11-20 13:55:45 +00:00
|
|
|
std::variant<VkResult, util::unique_ptr<vulkan_image_handle_creator>> create_image_creator(
|
|
|
|
|
const VkSwapchainCreateInfoKHR &swapchain_create_info);
|
2025-03-26 13:18:02 +00:00
|
|
|
|
2024-11-28 06:36:17 +00:00
|
|
|
/**
|
2025-11-20 13:55:45 +00:00
|
|
|
* @brief Image factory that is used to create swapchain images.
|
2024-11-28 06:36:17 +00:00
|
|
|
*/
|
2025-11-20 13:55:45 +00:00
|
|
|
swapchain_image_factory m_image_factory;
|
2019-05-24 15:57:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} /* namespace headless */
|
|
|
|
|
} /* namespace wsi */
|