From 00a9e17af52562fca24a3fad659b0f8c97a25ca7 Mon Sep 17 00:00:00 2001 From: Xiaowei Guan Date: Sat, 14 Sep 2024 09:14:58 +0800 Subject: [PATCH] Fix resize issue --- .../platform/tizen/tizen_renderer_vulkan.cc | 125 +++++++++--------- .../platform/tizen/tizen_renderer_vulkan.h | 30 ++--- .../platform/tizen/tizen_window_ecore_wl2.cc | 45 +++---- 3 files changed, 96 insertions(+), 104 deletions(-) diff --git a/flutter/shell/platform/tizen/tizen_renderer_vulkan.cc b/flutter/shell/platform/tizen/tizen_renderer_vulkan.cc index 11a8939..0a0e57f 100644 --- a/flutter/shell/platform/tizen/tizen_renderer_vulkan.cc +++ b/flutter/shell/platform/tizen/tizen_renderer_vulkan.cc @@ -57,37 +57,30 @@ bool TizenRendererVulkan::InitVulkan(TizenViewBase* view) { FT_LOG(Error) << "Failed to create surface"; return false; } - if (!PickPhysicalDevice()) { FT_LOG(Error) << "Filed to pick physical device"; return false; } - if (!CreateLogicalDevice()) { FT_LOG(Error) << "Filed to create logical device"; return false; } - if (!GetDeviceQueue()) { FT_LOG(Error) << "Filed to get device queue"; return false; } - if (!CreateSemaphore()) { FT_LOG(Error) << "Filed to create semaphore"; return false; } - if (!CreateFence()) { FT_LOG(Error) << "Filed to create fence"; return false; } - if (!CreateCommandPool()) { FT_LOG(Error) << "Filed to create command pool"; return false; } - if (!InitializeSwapchain()) { FT_LOG(Error) << "Filed to initialize swapchain"; return false; @@ -231,23 +224,28 @@ void TizenRendererVulkan::SetupDebugMessenger() { bool TizenRendererVulkan::CheckValidationLayerSupport() { uint32_t layer_count; if (vkEnumerateInstanceLayerProperties(&layer_count, nullptr) != VK_SUCCESS) { + FT_LOG(Error) << "Failed to enumerate instance layer properties"; return false; } std::vector available_layers(layer_count); if (vkEnumerateInstanceLayerProperties( &layer_count, available_layers.data()) != VK_SUCCESS) { + FT_LOG(Error) << "Failed to enumerate instance layer properties"; return false; } for (const char* layer_name : validation_layers) { bool layer_found = false; for (const auto& layer_properties : available_layers) { + FT_LOG(Info) << "layer_properties.layerName : " + << layer_properties.layerName; if (strcmp(layer_name, layer_properties.layerName) == 0) { layer_found = true; break; } } if (!layer_found) { + FT_LOG(Error) << "Layer requested is not available"; return false; } } @@ -292,6 +290,8 @@ bool TizenRendererVulkan::PickPhysicalDevice() { return false; } + FT_LOG(Info) << "Enumerating " << gpu_count << " physical device(s)."; + uint32_t selected_score = 0; for (const auto& physical_device : physical_devices) { VkPhysicalDeviceProperties properties; @@ -321,63 +321,63 @@ bool TizenRendererVulkan::PickPhysicalDevice() { surface_present_supported) { graphics_queue_family = i; } - // Skip physical devices that don't have a graphics queue. - if (!graphics_queue_family.has_value()) { - FT_LOG(Info) << "Skipping due to no suitable graphics queues."; - continue; - } + } + // Skip physical devices that don't have a graphics queue. + if (!graphics_queue_family.has_value()) { + FT_LOG(Info) << "Skipping due to no suitable graphics queues."; + continue; + } - // Prefer discrete GPUs. - if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { - score += 1 << 30; - } - uint32_t extension_count; - vkEnumerateDeviceExtensionProperties(physical_device, nullptr, - &extension_count, nullptr); - std::vector available_extensions(extension_count); - vkEnumerateDeviceExtensionProperties(physical_device, nullptr, - &extension_count, - available_extensions.data()); - - bool supports_swapchain = false; - for (const auto& available_extension : available_extensions) { - if (strcmp(VK_KHR_SWAPCHAIN_EXTENSION_NAME, - available_extension.extensionName) == 0) { - supports_swapchain = true; - supported_extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); - } - // The spec requires VK_KHR_portability_subset be enabled whenever it's - // available on a device. It's present on compatibility ICDs like - // MoltenVK. - else if (strcmp("VK_KHR_portability_subset", - available_extension.extensionName) == 0) { - supported_extensions.push_back("VK_KHR_portability_subset"); - } - // Prefer GPUs that support VK_KHR_get_memory_requirements2. - else if (strcmp(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, - available_extension.extensionName) == 0) { - score += 1 << 29; - supported_extensions.push_back( - VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME); - } + // Prefer discrete GPUs. + if (properties.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU) { + score += 1 << 30; + } + uint32_t extension_count; + vkEnumerateDeviceExtensionProperties(physical_device, nullptr, + &extension_count, nullptr); + std::vector available_extensions(extension_count); + vkEnumerateDeviceExtensionProperties(physical_device, nullptr, + &extension_count, + available_extensions.data()); + + bool supports_swapchain = false; + for (const auto& available_extension : available_extensions) { + if (strcmp(VK_KHR_SWAPCHAIN_EXTENSION_NAME, + available_extension.extensionName) == 0) { + supports_swapchain = true; + supported_extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); } - // Skip physical devices that don't have swapchain support. - if (!supports_swapchain) { - FT_LOG(Info) << "Skipping due to lack of swapchain support."; - continue; + // The spec requires VK_KHR_portability_subset be enabled whenever it's + // available on a device. It's present on compatibility ICDs like + // MoltenVK. + else if (strcmp("VK_KHR_portability_subset", + available_extension.extensionName) == 0) { + supported_extensions.push_back("VK_KHR_portability_subset"); } - // Prefer GPUs with larger max texture sizes. - score += properties.limits.maxImageDimension2D; - if (selected_score < score) { - FT_LOG(Info) << "This is the best device so far. Score: " << score; - - selected_score = score; - physical_device_ = physical_device; - enabled_device_extensions_ = supported_extensions; - graphics_queue_family_index_ = graphics_queue_family.value_or( - std::numeric_limits::max()); + // Prefer GPUs that support VK_KHR_get_memory_requirements2. + else if (strcmp(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME, + available_extension.extensionName) == 0) { + score += 1 << 29; + supported_extensions.push_back( + VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME); } } + // Skip physical devices that don't have swapchain support. + if (!supports_swapchain) { + FT_LOG(Info) << "Skipping due to lack of swapchain support."; + continue; + } + // Prefer GPUs with larger max texture sizes. + score += properties.limits.maxImageDimension2D; + if (selected_score < score) { + FT_LOG(Info) << "This is the best device so far. Score: " << score; + + selected_score = score; + physical_device_ = physical_device; + enabled_device_extensions_ = supported_extensions; + graphics_queue_family_index_ = + graphics_queue_family.value_or(std::numeric_limits::max()); + } } return physical_device_ != VK_NULL_HANDLE; } @@ -568,13 +568,6 @@ VkCompositeAlphaFlagBitsKHR TizenRendererVulkan::GetSwapChainCompositeAlpha( } bool TizenRendererVulkan::InitializeSwapchain() { - if (resize_pending_) { - resize_pending_ = false; - vkDestroySwapchainKHR(logical_device_, swapchain_, nullptr); - vkQueueWaitIdle(graphics_queue_); - vkResetCommandPool(logical_device_, swapchain_command_pool_, - VK_COMMAND_POOL_RESET_RELEASE_RESOURCES_BIT); - } uint32_t format_count; if (vkGetPhysicalDeviceSurfaceFormatsKHR( physical_device_, surface_, &format_count, nullptr) != VK_SUCCESS || diff --git a/flutter/shell/platform/tizen/tizen_renderer_vulkan.h b/flutter/shell/platform/tizen/tizen_renderer_vulkan.h index c13dfae..2b5cca6 100644 --- a/flutter/shell/platform/tizen/tizen_renderer_vulkan.h +++ b/flutter/shell/platform/tizen/tizen_renderer_vulkan.h @@ -69,28 +69,28 @@ class TizenRendererVulkan : public TizenRenderer { bool PickPhysicalDevice(); void SetupDebugMessenger(); - bool enable_validation_layers_ = true; + bool enable_validation_layers_ = false; - VkDebugUtilsMessengerEXT debug_messenger_; - VkDevice logical_device_; - VkInstance instance_; - VkPhysicalDevice physical_device_; - VkQueue graphics_queue_; - VkSurfaceKHR surface_; + VkDebugUtilsMessengerEXT debug_messenger_ = VK_NULL_HANDLE; + VkDevice logical_device_ = VK_NULL_HANDLE; + VkInstance instance_ = VK_NULL_HANDLE; + VkPhysicalDevice physical_device_ = VK_NULL_HANDLE; + VkQueue graphics_queue_ = VK_NULL_HANDLE; + VkSurfaceKHR surface_ = VK_NULL_HANDLE; VkSurfaceFormatKHR surface_format_; - VkSemaphore present_transition_semaphore_; - VkFence image_ready_fence_; - VkSwapchainKHR swapchain_; - VkCommandPool swapchain_command_pool_; + VkSemaphore present_transition_semaphore_ = VK_NULL_HANDLE; + VkFence image_ready_fence_ = VK_NULL_HANDLE; + VkSwapchainKHR swapchain_ = VK_NULL_HANDLE; + VkCommandPool swapchain_command_pool_= VK_NULL_HANDLE; std::vector swapchain_images_; std::vector present_transition_buffers_; std::vector enabled_device_extensions_; std::vector enabled_instance_extensions_; - uint32_t graphics_queue_family_index_; - uint32_t last_image_index_; + uint32_t graphics_queue_family_index_ = 0; + uint32_t last_image_index_ = 0; bool resize_pending_ = false; - uint32_t width_; - uint32_t height_; + uint32_t width_ = 0; + uint32_t height_ = 0; }; } // namespace flutter diff --git a/flutter/shell/platform/tizen/tizen_window_ecore_wl2.cc b/flutter/shell/platform/tizen/tizen_window_ecore_wl2.cc index cf78194..5ecf39d 100644 --- a/flutter/shell/platform/tizen/tizen_window_ecore_wl2.cc +++ b/flutter/shell/platform/tizen/tizen_window_ecore_wl2.cc @@ -242,30 +242,29 @@ void TizenWindowEcoreWl2::RegisterEventHandlers() { return ECORE_CALLBACK_PASS_ON; }, this)); - - ecore_event_handlers_.push_back(ecore_event_handler_add( - ECORE_WL2_EVENT_WINDOW_CONFIGURE, - [](void* data, int type, void* event) -> Eina_Bool { - auto* self = static_cast(data); - if (self->view_delegate_) { - auto* configure_event = - reinterpret_cast(event); - if (configure_event->win == self->GetWindowId()) { - ecore_wl2_egl_window_resize_with_rotation( - self->ecore_wl2_egl_window_, configure_event->x, - configure_event->y, configure_event->w, configure_event->h, - self->GetRotation()); - - self->view_delegate_->OnResize( - configure_event->x, configure_event->y, configure_event->w, - configure_event->h); - return ECORE_CALLBACK_DONE; + if (!is_vulkan_) { + ecore_event_handlers_.push_back(ecore_event_handler_add( + ECORE_WL2_EVENT_WINDOW_CONFIGURE, + [](void* data, int type, void* event) -> Eina_Bool { + auto* self = static_cast(data); + if (self->view_delegate_) { + auto* configure_event = + reinterpret_cast(event); + if (configure_event->win == self->GetWindowId()) { + ecore_wl2_egl_window_resize_with_rotation( + self->ecore_wl2_egl_window_, configure_event->x, + configure_event->y, configure_event->w, configure_event->h, + self->GetRotation()); + self->view_delegate_->OnResize( + configure_event->x, configure_event->y, configure_event->w, + configure_event->h); + return ECORE_CALLBACK_DONE; + } } - } - return ECORE_CALLBACK_PASS_ON; - }, - this)); - + return ECORE_CALLBACK_PASS_ON; + }, + this)); + } ecore_event_handlers_.push_back(ecore_event_handler_add( ECORE_EVENT_MOUSE_BUTTON_DOWN, [](void* data, int type, void* event) -> Eina_Bool {