diff options
-rw-r--r-- | layer/swapchain_api.cpp | 2 | ||||
-rw-r--r-- | wsi/headless/swapchain.cpp | 60 | ||||
-rw-r--r-- | wsi/headless/swapchain.hpp | 19 | ||||
-rw-r--r-- | wsi/swapchain_base.cpp | 15 | ||||
-rw-r--r-- | wsi/swapchain_base.hpp | 15 | ||||
-rw-r--r-- | wsi/wayland/swapchain.cpp | 20 | ||||
-rw-r--r-- | wsi/wayland/swapchain.hpp | 22 |
7 files changed, 44 insertions, 109 deletions
diff --git a/layer/swapchain_api.cpp b/layer/swapchain_api.cpp index e9c428a..47cd6f1 100644 --- a/layer/swapchain_api.cpp +++ b/layer/swapchain_api.cpp @@ -348,7 +348,7 @@ wsi_layer_vkCreateImage(VkDevice device, const VkImageCreateInfo *pCreateInfo, c } auto sc = reinterpret_cast<wsi::swapchain_base *>(image_sc_create_info->swapchain); - return sc->create_aliased_image_handle(pCreateInfo, pImage); + return sc->create_aliased_image_handle(pImage); } VWL_VKAPI_CALL(VkResult) diff --git a/wsi/headless/swapchain.cpp b/wsi/headless/swapchain.cpp index 0d1ef54..d64d48b 100644 --- a/wsi/headless/swapchain.cpp +++ b/wsi/headless/swapchain.cpp @@ -49,7 +49,9 @@ struct image_data swapchain::swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator) : wsi::swapchain_base(dev_data, pAllocator) - , m_image_create_info() +#if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN + , m_image_compression_control{} +#endif { } @@ -59,42 +61,6 @@ swapchain::~swapchain() teardown(); } -#if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN -VkImageCompressionControlEXT swapchain::construct_image_compression_control() -{ - VkImageCompressionControlEXT compression_control = {}; - compression_control.sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT; - compression_control.compressionControlPlaneCount = m_image_compression_control.compression_control_plane_count; - compression_control.flags = m_image_compression_control.flags; - compression_control.pFixedRateFlags = m_image_compression_control.fixed_rate_flags.data(); - return compression_control; -} -#endif - -VkResult swapchain::create_aliased_image_handle(const VkImageCreateInfo *image_create_info, VkImage *image) -{ -#if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - VkImageCompressionControlEXT compression_control; - if (m_device_data.is_swapchain_compression_control_enabled()) - { - compression_control = construct_image_compression_control(); - compression_control.pNext = m_image_create_info.pNext; - m_image_create_info.pNext = &compression_control; - } -#endif - - VkResult res = m_device_data.disp.CreateImage(m_device, &m_image_create_info, get_allocation_callbacks(), image); - -#if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - if (m_device_data.is_swapchain_compression_control_enabled()) - { - /* Restore pNext pointer of m_image_create_info as compression_control will be garbage after this function exits */ - m_image_create_info.pNext = compression_control.pNext; - } -#endif - return res; -} - VkResult swapchain::create_and_bind_swapchain_image(VkImageCreateInfo image_create, wsi::swapchain_image &image) { VkResult res = VK_SUCCESS; @@ -102,22 +68,20 @@ VkResult swapchain::create_and_bind_swapchain_image(VkImageCreateInfo image_crea m_image_create_info = image_create; #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - VkImageCompressionControlEXT compression_control; if (m_device_data.is_swapchain_compression_control_enabled()) { - compression_control = construct_image_compression_control(); - compression_control.pNext = m_image_create_info.pNext; - m_image_create_info.pNext = &compression_control; + /* Initialize compression control */ + m_image_compression_control.sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT; + m_image_compression_control.compressionControlPlaneCount = + m_image_compression_control_params.compression_control_plane_count; + m_image_compression_control.flags = m_image_compression_control_params.flags; + m_image_compression_control.pFixedRateFlags = m_image_compression_control_params.fixed_rate_flags.data(); + m_image_compression_control.pNext = m_image_create_info.pNext; + + m_image_create_info.pNext = &m_image_compression_control; } #endif res = m_device_data.disp.CreateImage(m_device, &m_image_create_info, get_allocation_callbacks(), &image.image); -#if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - if (m_device_data.is_swapchain_compression_control_enabled()) - { - /* Restore pNext pointer of m_image_create_info as compression_control will be garbage after this function exits */ - m_image_create_info.pNext = compression_control.pNext; - } -#endif if (res != VK_SUCCESS) { return res; diff --git a/wsi/headless/swapchain.hpp b/wsi/headless/swapchain.hpp index f851174..dd7d8e8 100644 --- a/wsi/headless/swapchain.hpp +++ b/wsi/headless/swapchain.hpp @@ -64,18 +64,6 @@ protected: }; /** - * @brief Creates a VkImage handle. - * - * @param image_create_info Data to be used to create the image. - * @param[out] image Handle to the image. - * - * @return If image creation is successful returns VK_SUCCESS, otherwise - * will return VK_ERROR_OUT_OF_DEVICE_MEMORY or VK_ERROR_OUT_OF_HOST_MEMORY - * depending on the error that occured. - */ - VkResult create_aliased_image_handle(const VkImageCreateInfo *image_create_info, VkImage *image) override; - - /** * @brief Creates and binds a new swapchain image. * * @param image_create_info Data to be used to create the image. @@ -123,13 +111,8 @@ protected: private: #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - VkImageCompressionControlEXT construct_image_compression_control(); + VkImageCompressionControlEXT m_image_compression_control; #endif - - /** - * @brief Image creation info used for all swapchain images. - */ - VkImageCreateInfo m_image_create_info; }; } /* namespace headless */ diff --git a/wsi/swapchain_base.cpp b/wsi/swapchain_base.cpp index 6292d3d..1d72c25 100644 --- a/wsi/swapchain_base.cpp +++ b/wsi/swapchain_base.cpp @@ -186,8 +186,9 @@ swapchain_base::swapchain_base(layer::device_private_data &dev_data, const VkAll , m_device(VK_NULL_HANDLE) , m_queue(VK_NULL_HANDLE) #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - , m_image_compression_control({VK_IMAGE_COMPRESSION_DEFAULT_EXT, 0}) + , m_image_compression_control_params({VK_IMAGE_COMPRESSION_DEFAULT_EXT, 0}) #endif + , m_image_create_info() , m_image_acquire_lock() , m_error_state(VK_NOT_READY) , m_started_presenting(false) @@ -210,11 +211,12 @@ VkResult swapchain_base::init(VkDevice device, const VkSwapchainCreateInfoKHR *s VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT, swapchain_create_info->pNext); if (m_device_data.is_swapchain_compression_control_enabled() && image_compression_control != nullptr) { - m_image_compression_control.compression_control_plane_count = image_compression_control->compressionControlPlaneCount; - m_image_compression_control.flags = image_compression_control->flags; + m_image_compression_control_params.compression_control_plane_count = + image_compression_control->compressionControlPlaneCount; + m_image_compression_control_params.flags = image_compression_control->flags; for (uint32_t i = 0; i < image_compression_control->compressionControlPlaneCount; i++) { - m_image_compression_control.fixed_rate_flags[i] = image_compression_control->pFixedRateFlags[i]; + m_image_compression_control_params.fixed_rate_flags[i] = image_compression_control->pFixedRateFlags[i]; } } #endif @@ -537,6 +539,11 @@ VkResult swapchain_base::get_swapchain_images(uint32_t *swapchain_image_count, V } } +VkResult swapchain_base::create_aliased_image_handle(VkImage *image) +{ + return m_device_data.disp.CreateImage(m_device, &m_image_create_info, get_allocation_callbacks(), image); +} + VkResult swapchain_base::notify_presentation_engine(uint32_t image_index) { const std::lock_guard<std::recursive_mutex> lock(m_image_status_mutex); diff --git a/wsi/swapchain_base.hpp b/wsi/swapchain_base.hpp index ca4c754..c79c7b7 100644 --- a/wsi/swapchain_base.hpp +++ b/wsi/swapchain_base.hpp @@ -67,7 +67,7 @@ struct swapchain_image constexpr uint32_t MAX_PLANES = 4; #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN -struct image_compression_control +struct image_compression_control_params { VkImageCompressionFlagsEXT flags; uint32_t compression_control_plane_count; @@ -165,16 +165,16 @@ public: * * It is used to bind images to memory from the swapchain. It is called if a * VkImageSwapchainCreateInfoKHR struct has been provided in the vkCreateImage - * function. + * function. All images created by the swapchain will use the same VkImageCreateInfo, + * initialized in create_and_bind_swapchain_image(). * - * @param image_create_info Data to be used to create the image. * @param[out] image Handle to the image. * * @return If image creation is successful returns VK_SUCCESS, otherwise * will return VK_ERROR_OUT_OF_DEVICE_MEMORY or VK_ERROR_OUT_OF_HOST_MEMORY * depending on the error that occured. */ - virtual VkResult create_aliased_image_handle(const VkImageCreateInfo *image_create_info, VkImage *image) = 0; + VkResult create_aliased_image_handle(VkImage *image); /** * @brief Bind image to a swapchain @@ -312,10 +312,15 @@ protected: * @brief Describes the image compression the swapchain will use * */ - image_compression_control m_image_compression_control; + image_compression_control_params m_image_compression_control_params; #endif /** + * @brief Image creation info used for all swapchain images. + */ + VkImageCreateInfo m_image_create_info; + + /** * @brief Return the VkAllocationCallbacks passed in this object constructor. */ const VkAllocationCallbacks *get_allocation_callbacks() diff --git a/wsi/wayland/swapchain.cpp b/wsi/wayland/swapchain.cpp index 4046df5..4067ff9 100644 --- a/wsi/wayland/swapchain.cpp +++ b/wsi/wayland/swapchain.cpp @@ -79,9 +79,9 @@ swapchain::swapchain(layer::device_private_data &dev_data, const VkAllocationCal , m_wsi_surface(&wsi_surface) , m_buffer_queue(nullptr) , m_wsi_allocator(nullptr) - , m_image_creation_parameters({}, {}, m_allocator, {}, {}) + , m_image_creation_parameters({}, m_allocator, {}, {}) { - m_image_creation_parameters.m_image_create_info.format = VK_FORMAT_UNDEFINED; + m_image_create_info.format = VK_FORMAT_UNDEFINED; } swapchain::~swapchain() @@ -294,9 +294,10 @@ VkResult swapchain::get_surface_compatible_formats(const VkImageCreateInfo &info #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN VkImageCompressionControlEXT compression_control = {}; compression_control.sType = VK_STRUCTURE_TYPE_IMAGE_COMPRESSION_CONTROL_EXT; - compression_control.flags = m_image_compression_control.flags; - compression_control.compressionControlPlaneCount = m_image_compression_control.compression_control_plane_count; - compression_control.pFixedRateFlags = m_image_compression_control.fixed_rate_flags.data(); + compression_control.flags = m_image_compression_control_params.flags; + compression_control.compressionControlPlaneCount = + m_image_compression_control_params.compression_control_plane_count; + compression_control.pFixedRateFlags = m_image_compression_control_params.fixed_rate_flags.data(); if (m_device_data.is_swapchain_compression_control_enabled()) { @@ -352,12 +353,6 @@ VkResult swapchain::get_surface_compatible_formats(const VkImageCreateInfo &info return VK_SUCCESS; } -VkResult swapchain::create_aliased_image_handle(const VkImageCreateInfo *image_create_info, VkImage *image) -{ - return m_device_data.disp.CreateImage(m_device, &m_image_creation_parameters.m_image_create_info, - get_allocation_callbacks(), image); -} - VkResult swapchain::allocate_wsialloc(VkImageCreateInfo &image_create_info, wayland_image_data &image_data, util::vector<wsialloc_format> &importable_formats, wsialloc_format *allocated_format) @@ -366,7 +361,7 @@ VkResult swapchain::allocate_wsialloc(VkImageCreateInfo &image_create_info, wayl uint64_t allocation_flags = is_protected_memory ? WSIALLOC_ALLOCATE_PROTECTED : 0; #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN - if (m_image_compression_control.flags & VK_IMAGE_COMPRESSION_FIXED_RATE_EXPLICIT_EXT) + if (m_image_compression_control_params.flags & VK_IMAGE_COMPRESSION_FIXED_RATE_EXPLICIT_EXT) { allocation_flags |= WSIALLOC_ALLOCATE_HIGHEST_FIXED_RATE_COMPRESSION; } @@ -402,7 +397,6 @@ VkResult swapchain::allocate_image(VkImageCreateInfo &image_create_info, wayland bool is_disjoint = false; util::vector<wsialloc_format> importable_formats(util::allocator(m_allocator, VK_SYSTEM_ALLOCATION_SCOPE_COMMAND)); - auto &m_image_create_info = m_image_creation_parameters.m_image_create_info; auto &m_allocated_format = m_image_creation_parameters.m_allocated_format; if (m_image_create_info.format != VK_FORMAT_UNDEFINED) { diff --git a/wsi/wayland/swapchain.hpp b/wsi/wayland/swapchain.hpp index 381e9c4..99d9d7f 100644 --- a/wsi/wayland/swapchain.hpp +++ b/wsi/wayland/swapchain.hpp @@ -45,17 +45,15 @@ namespace wayland struct image_creation_parameters { - VkImageCreateInfo m_image_create_info; wsialloc_format m_allocated_format; util::vector<VkSubresourceLayout> m_image_layout; VkExternalMemoryImageCreateInfoKHR m_external_info; VkImageDrmFormatModifierExplicitCreateInfoEXT m_drm_mod_info; - image_creation_parameters(VkImageCreateInfo image_create_info, wsialloc_format allocated_format, + image_creation_parameters(wsialloc_format allocated_format, util::allocator allocator, VkExternalMemoryImageCreateInfoKHR external_info, VkImageDrmFormatModifierExplicitCreateInfoEXT drm_mod_info) - : m_image_create_info(image_create_info) - , m_allocated_format(allocated_format) + : m_allocated_format(allocated_format) , m_image_layout(allocator) , m_external_info(external_info) , m_drm_mod_info(drm_mod_info) @@ -82,22 +80,6 @@ protected: bool &use_presentation_thread) override; /** - * @brief Creates a VkImage handle. - * - * The image_create_info argument is ignored in favour of m_image_create_info. This is because in - * order to guarantee a VkImage can be bound to any swapchain index, all swapchain images must - * be created with the same creation parameters. - * - * @param image_create_info Data to be used to create the image. - * @param[out] image Handle to the image. - * - * @return If image creation is successful returns VK_SUCCESS, otherwise - * will return VK_ERROR_OUT_OF_DEVICE_MEMORY or VK_ERROR_OUT_OF_HOST_MEMORY - * depending on the error that occured. - */ - VkResult create_aliased_image_handle(const VkImageCreateInfo *image_create_info, VkImage *image) override; - - /** * @brief Creates and binds a new swapchain image. * * @param image_create_info Data to be used to create the image. |