Skip to content

Commit

Permalink
Fix resize issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaowei-guan committed Sep 14, 2024
1 parent 4b94abb commit 00a9e17
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 104 deletions.
125 changes: 59 additions & 66 deletions flutter/shell/platform/tizen/tizen_renderer_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<VkLayerProperties> 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;
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<VkExtensionProperties> 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<VkExtensionProperties> 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<uint32_t>::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<uint32_t>::max());
}
}
return physical_device_ != VK_NULL_HANDLE;
}
Expand Down Expand Up @@ -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 ||
Expand Down
30 changes: 15 additions & 15 deletions flutter/shell/platform/tizen/tizen_renderer_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VkImage> swapchain_images_;
std::vector<VkCommandBuffer> present_transition_buffers_;
std::vector<const char*> enabled_device_extensions_;
std::vector<const char*> 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

Expand Down
45 changes: 22 additions & 23 deletions flutter/shell/platform/tizen/tizen_window_ecore_wl2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<TizenWindowEcoreWl2*>(data);
if (self->view_delegate_) {
auto* configure_event =
reinterpret_cast<Ecore_Wl2_Event_Window_Configure*>(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<TizenWindowEcoreWl2*>(data);
if (self->view_delegate_) {
auto* configure_event =
reinterpret_cast<Ecore_Wl2_Event_Window_Configure*>(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 {
Expand Down

0 comments on commit 00a9e17

Please sign in to comment.