diff options
author | Lior Dekel <lior.dekel@arm.com> | 2022-07-05 18:08:35 +0300 |
---|---|---|
committer | Lior Dekel <lior.dekel@arm.com> | 2022-07-13 14:14:51 +0000 |
commit | 91583f1af270f19b40d19f9423e98a7f3d745e01 (patch) | |
tree | 943169232e3636b8ba023ae6f285d77c30802f61 | |
parent | 711836af6cf0f82e36cce678d56b5ed3fe875b4a (diff) | |
download | vulkan-wsi-layer-91583f1af270f19b40d19f9423e98a7f3d745e01.tar.gz vulkan-wsi-layer-91583f1af270f19b40d19f9423e98a7f3d745e01.tar.bz2 vulkan-wsi-layer-91583f1af270f19b40d19f9423e98a7f3d745e01.zip |
Create common functions in surface_capabilities class
Signed-off-by: Lior Dekel <lior.dekel@arm.com>
Change-Id: Ia5053b202f4e64fd7a255ede513653a951ab3d41
-rw-r--r-- | wsi/headless/surface_properties.cpp | 51 | ||||
-rw-r--r-- | wsi/surface_properties.cpp | 32 | ||||
-rw-r--r-- | wsi/surface_properties.hpp | 50 | ||||
-rw-r--r-- | wsi/wayland/surface_properties.cpp | 47 |
4 files changed, 87 insertions, 93 deletions
diff --git a/wsi/headless/surface_properties.cpp b/wsi/headless/surface_properties.cpp index d13500e..6530631 100644 --- a/wsi/headless/surface_properties.cpp +++ b/wsi/headless/surface_properties.cpp @@ -57,34 +57,7 @@ surface_properties& surface_properties::get_instance() VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities) { - /* Image count limits */ - surface_capabilities->minImageCount = 1; - surface_capabilities->maxImageCount = MAX_SWAPCHAIN_IMAGE_COUNT; - - /* Surface extents */ - surface_capabilities->currentExtent = { 0xffffffff, 0xffffffff }; - surface_capabilities->minImageExtent = { 1, 1 }; - /* Ask the device for max */ - VkPhysicalDeviceProperties dev_props; - layer::instance_private_data::get(physical_device).disp.GetPhysicalDeviceProperties(physical_device, &dev_props); - - surface_capabilities->maxImageExtent = { dev_props.limits.maxImageDimension2D, - dev_props.limits.maxImageDimension2D }; - surface_capabilities->maxImageArrayLayers = 1; - - /* Surface transforms */ - surface_capabilities->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; - surface_capabilities->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; - - /* Composite alpha */ - surface_capabilities->supportedCompositeAlpha = static_cast<VkCompositeAlphaFlagBitsKHR>( - VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR | - VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR | VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR); - - /* Image usage flags */ - surface_capabilities->supportedUsageFlags = - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; + get_surface_capabilities_common(physical_device, surface_capabilities); return VK_SUCCESS; } @@ -140,29 +113,9 @@ VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical UNUSED(physical_device); UNUSED(surface); - VkResult res = VK_SUCCESS; static const std::array<VkPresentModeKHR, 2> modes = { VK_PRESENT_MODE_FIFO_KHR, VK_PRESENT_MODE_FIFO_RELAXED_KHR }; - assert(present_mode_count != nullptr); - - if (nullptr == present_modes) - { - *present_mode_count = modes.size(); - } - else - { - if (modes.size() > *present_mode_count) - { - res = VK_INCOMPLETE; - } - *present_mode_count = std::min(*present_mode_count, static_cast<uint32_t>(modes.size())); - for (uint32_t i = 0; i < *present_mode_count; ++i) - { - present_modes[i] = modes[i]; - } - } - - return res; + return get_surface_present_modes_common(present_mode_count, present_modes, modes); } VWL_VKAPI_CALL(VkResult) diff --git a/wsi/surface_properties.cpp b/wsi/surface_properties.cpp index 4b9c929..9653a8c 100644 --- a/wsi/surface_properties.cpp +++ b/wsi/surface_properties.cpp @@ -96,4 +96,36 @@ void surface_format_properties::fill_format_properties(VkSurfaceFormat2KHR &surf #endif } +void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities) +{ + /* Image count limits */ + surface_capabilities->minImageCount = 1; + surface_capabilities->maxImageCount = surface_properties::MAX_SWAPCHAIN_IMAGE_COUNT; + + /* Surface extents */ + surface_capabilities->currentExtent = { 0xffffffff, 0xffffffff }; + surface_capabilities->minImageExtent = { 1, 1 }; + /* Ask the device for max */ + VkPhysicalDeviceProperties dev_props; + layer::instance_private_data::get(physical_device).disp.GetPhysicalDeviceProperties(physical_device, &dev_props); + + surface_capabilities->maxImageExtent = { dev_props.limits.maxImageDimension2D, + dev_props.limits.maxImageDimension2D }; + surface_capabilities->maxImageArrayLayers = 1; + + /* Surface transforms */ + surface_capabilities->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + surface_capabilities->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; + + /* Composite alpha */ + surface_capabilities->supportedCompositeAlpha = static_cast<VkCompositeAlphaFlagBitsKHR>( + VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR | + VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR | VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR); + + /* Image usage flags */ + surface_capabilities->supportedUsageFlags = + VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | + VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; +} + } /* namespace wsi */
\ No newline at end of file diff --git a/wsi/surface_properties.hpp b/wsi/surface_properties.hpp index 646c79d..af02b3c 100644 --- a/wsi/surface_properties.hpp +++ b/wsi/surface_properties.hpp @@ -200,5 +200,55 @@ VkResult surface_properties_formats_helper(It begin, It end, uint32_t *surface_f return res; } +/** + * @brief Common function for the get_surface_capabilities. + * + * Initiates the different fields in surface_capabilities struct, also + * according to the physical_device. + * + * @param physical_device Vulkan physical_device. + * @param surface_capabilities address of Vulkan surface capabilities struct. + * + */ +void get_surface_capabilities_common(VkPhysicalDevice physical_device, VkSurfaceCapabilitiesKHR *surface_capabilities); + +/** + * @brief Common function for the get_surface_present_modes. + * + * Preparing the present_modes array for get_surface_present_modes. + * + * @param present_mode_count address of counter for the present modes. + * @param present_modes array of present modes. + * @param modes array of modes + * + * @return VK_SUCCESS on success, VK_INCOMPLETE otherwise. + * + */ +template <std::size_t SIZE> +VkResult get_surface_present_modes_common(uint32_t *present_mode_count, VkPresentModeKHR *present_modes, + const std::array<VkPresentModeKHR, SIZE> &modes) +{ + VkResult res = VK_SUCCESS; + + assert(present_mode_count != nullptr); + + if (nullptr == present_modes) + { + *present_mode_count = modes.size(); + return VK_SUCCESS; + } + + if (modes.size() > *present_mode_count) + { + res = VK_INCOMPLETE; + } + *present_mode_count = std::min(*present_mode_count, static_cast<uint32_t>(modes.size())); + for (uint32_t i = 0; i < *present_mode_count; ++i) + { + present_modes[i] = modes[i]; + } + + return res; +} } /* namespace wsi */ diff --git a/wsi/wayland/surface_properties.cpp b/wsi/wayland/surface_properties.cpp index cd54ddd..a729484 100644 --- a/wsi/wayland/surface_properties.cpp +++ b/wsi/wayland/surface_properties.cpp @@ -71,33 +71,13 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ VkSurfaceCapabilitiesKHR *pSurfaceCapabilities) { /* Image count limits */ + get_surface_capabilities_common(physical_device, pSurfaceCapabilities); pSurfaceCapabilities->minImageCount = 2; - pSurfaceCapabilities->maxImageCount = MAX_SWAPCHAIN_IMAGE_COUNT; - - /* Surface extents */ - pSurfaceCapabilities->currentExtent = { 0xffffffff, 0xffffffff }; - pSurfaceCapabilities->minImageExtent = { 1, 1 }; - - VkPhysicalDeviceProperties dev_props; - layer::instance_private_data::get(physical_device).disp.GetPhysicalDeviceProperties(physical_device, &dev_props); - - pSurfaceCapabilities->maxImageExtent = { dev_props.limits.maxImageDimension2D, - dev_props.limits.maxImageDimension2D }; - pSurfaceCapabilities->maxImageArrayLayers = 1; - - /* Surface transforms */ - pSurfaceCapabilities->supportedTransforms = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; - pSurfaceCapabilities->currentTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; /* Composite alpha */ pSurfaceCapabilities->supportedCompositeAlpha = static_cast<VkCompositeAlphaFlagBitsKHR>( VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR | VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR); - /* Image usage flags */ - pSurfaceCapabilities->supportedUsageFlags = - VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | - VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT; - return VK_SUCCESS; } @@ -235,33 +215,12 @@ VkResult surface_properties::get_surface_present_modes(VkPhysicalDevice physical uint32_t *pPresentModeCount, VkPresentModeKHR *pPresentModes) { - VkResult res = VK_SUCCESS; - - static std::array<const VkPresentModeKHR, 2> modes = { + static const std::array<VkPresentModeKHR, 2> modes = { VK_PRESENT_MODE_FIFO_KHR, VK_PRESENT_MODE_MAILBOX_KHR, }; - assert(pPresentModeCount != nullptr); - - if (nullptr == pPresentModes) - { - *pPresentModeCount = modes.size(); - } - else - { - if (modes.size() > *pPresentModeCount) - { - res = VK_INCOMPLETE; - } - *pPresentModeCount = std::min(*pPresentModeCount, static_cast<uint32_t>(modes.size())); - for (uint32_t i = 0; i < *pPresentModeCount; ++i) - { - pPresentModes[i] = modes[i]; - } - } - - return res; + return get_surface_present_modes_common(pPresentModeCount, pPresentModes, modes); } static const char *required_device_extensions[] = { |