2019-05-24 15:57:50 +01:00
|
|
|
/*
|
2022-02-28 16:21:06 +00:00
|
|
|
* Copyright (c) 2016-2017, 2019, 2021-2022 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <cassert>
|
2019-11-21 15:23:59 +00:00
|
|
|
#include <wsi/wsi_factory.hpp>
|
|
|
|
|
#include "private_data.hpp"
|
2019-05-24 15:57:50 +01:00
|
|
|
#include "surface_api.hpp"
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
/**
|
|
|
|
|
* @brief Implements vkGetPhysicalDeviceSurfaceCapabilitiesKHR Vulkan entrypoint.
|
|
|
|
|
*/
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
|
|
|
|
|
VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
auto &instance = layer::instance_private_data::get(physicalDevice);
|
|
|
|
|
if (instance.should_layer_handle_surface(physicalDevice, surface))
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2021-07-21 20:19:52 +01:00
|
|
|
wsi::surface_properties *props = wsi::get_surface_properties(instance, surface);
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(props != nullptr);
|
2022-02-28 16:21:06 +00:00
|
|
|
return props->get_surface_capabilities(physicalDevice, pSurfaceCapabilities);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
/* If the layer cannot handle this surface, then necessarily the surface must have been created by the ICDs (or a
|
|
|
|
|
* layer below us.) So it is safe to assume that the ICDs (or layers below us) support VK_KHR_surface and therefore
|
|
|
|
|
* it is safe to can call down. This holds for other entrypoints below.
|
2019-05-24 15:57:50 +01:00
|
|
|
*/
|
2020-06-24 09:36:21 +01:00
|
|
|
return instance.disp.GetPhysicalDeviceSurfaceCapabilitiesKHR(physicalDevice, surface, pSurfaceCapabilities);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Implements vkGetPhysicalDeviceSurfaceFormatsKHR Vulkan entrypoint.
|
|
|
|
|
*/
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
|
|
|
|
|
uint32_t *pSurfaceFormatCount,
|
|
|
|
|
VkSurfaceFormatKHR *pSurfaceFormats) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
auto &instance = layer::instance_private_data::get(physicalDevice);
|
|
|
|
|
if (instance.should_layer_handle_surface(physicalDevice, surface))
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2021-07-21 20:19:52 +01:00
|
|
|
wsi::surface_properties *props = wsi::get_surface_properties(instance, surface);
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(props != nullptr);
|
2022-02-28 16:21:06 +00:00
|
|
|
return props->get_surface_formats(physicalDevice, pSurfaceFormatCount, pSurfaceFormats);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
return instance.disp.GetPhysicalDeviceSurfaceFormatsKHR(physicalDevice, surface, pSurfaceFormatCount,
|
|
|
|
|
pSurfaceFormats);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Implements vkGetPhysicalDeviceSurfacePresentModesKHR Vulkan entrypoint.
|
|
|
|
|
*/
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
|
|
|
|
|
uint32_t *pPresentModeCount,
|
|
|
|
|
VkPresentModeKHR *pPresentModes) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
auto &instance = layer::instance_private_data::get(physicalDevice);
|
|
|
|
|
if (instance.should_layer_handle_surface(physicalDevice, surface))
|
2019-05-24 15:57:50 +01:00
|
|
|
{
|
2021-07-21 20:19:52 +01:00
|
|
|
wsi::surface_properties *props = wsi::get_surface_properties(instance, surface);
|
2020-06-24 09:36:21 +01:00
|
|
|
assert(props != nullptr);
|
|
|
|
|
return props->get_surface_present_modes(physicalDevice, surface, pPresentModeCount, pPresentModes);
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
return instance.disp.GetPhysicalDeviceSurfacePresentModesKHR(physicalDevice, surface, pPresentModeCount,
|
|
|
|
|
pPresentModes);
|
|
|
|
|
}
|
2019-11-21 15:23:59 +00:00
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
/**
|
|
|
|
|
* @brief Implements vkGetPhysicalDeviceSurfaceSupportKHR Vulkan entrypoint.
|
|
|
|
|
*/
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(VkResult)
|
|
|
|
|
wsi_layer_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
|
|
|
|
|
VkSurfaceKHR surface, VkBool32 *pSupported) VWL_API_POST
|
2020-06-24 09:36:21 +01:00
|
|
|
{
|
|
|
|
|
auto &instance = layer::instance_private_data::get(physicalDevice);
|
|
|
|
|
if (instance.should_layer_handle_surface(physicalDevice, surface))
|
|
|
|
|
{
|
|
|
|
|
*pSupported = VK_TRUE;
|
|
|
|
|
return VK_SUCCESS;
|
2019-05-24 15:57:50 +01:00
|
|
|
}
|
|
|
|
|
|
2020-06-24 09:36:21 +01:00
|
|
|
return instance.disp.GetPhysicalDeviceSurfaceSupportKHR(physicalDevice, queueFamilyIndex, surface, pSupported);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 11:25:48 +00:00
|
|
|
VWL_VKAPI_CALL(void)
|
|
|
|
|
wsi_layer_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
|
|
|
|
|
const VkAllocationCallbacks *pAllocator) VWL_API_POST
|
2021-07-21 20:19:52 +01:00
|
|
|
{
|
|
|
|
|
auto &instance_data = layer::instance_private_data::get(instance);
|
|
|
|
|
|
|
|
|
|
instance_data.disp.DestroySurfaceKHR(instance, surface, pAllocator);
|
|
|
|
|
|
|
|
|
|
instance_data.remove_surface(
|
|
|
|
|
surface, util::allocator{ instance_data.get_allocator(), VK_SYSTEM_ALLOCATION_SCOPE_OBJECT, pAllocator });
|
|
|
|
|
}
|