-
Notifications
You must be signed in to change notification settings - Fork 130
Fix minor VVL warnings #94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -110,6 +110,7 @@ void PlatformUtilVulkan::GetRefreshRates(VkPhysicalDevice physical_device, | |
| uint32_t queue_family_index, | ||
| std::vector<DisplayManager::DisplaySwapInterval> & | ||
| swap_intervals) { | ||
| swap_intervals.clear(); | ||
| SwappyVk_setQueueFamilyIndex(device, queue, queue_family_index); | ||
|
|
||
| uint64_t refresh_duration = 0; | ||
|
|
@@ -228,6 +229,7 @@ std::vector<const char *> PlatformUtilVulkan::GetRequiredInstanceExtensions( | |
| instance_extensions.push_back(VK_KHR_ANDROID_SURFACE_EXTENSION_NAME); | ||
| if (enable_validation_layers) { | ||
| instance_extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); | ||
| instance_extensions.push_back(VK_EXT_VALIDATION_FEATURES_EXTENSION_NAME); | ||
| } | ||
| // Request the physical device properties 2 extension on 1.0, is core from | ||
| // 1.1+ | ||
|
|
@@ -240,6 +242,7 @@ std::vector<const char *> PlatformUtilVulkan::GetRequiredInstanceExtensions( | |
|
|
||
| void PlatformUtilVulkan::GetScreenResolutions(const VkSurfaceCapabilitiesKHR &capabilities, | ||
| std::vector<DisplayManager::DisplayResolution> &display_resolutions) { | ||
| display_resolutions.clear(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the |
||
| const bool rotated = (capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR || | ||
| capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR); | ||
| const int32_t display_width = capabilities.currentExtent.width; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,11 +133,6 @@ void GraphicsAPIVulkan::QueryCapabilities() { | |
| if (vk_surface_ != VK_NULL_HANDLE) { | ||
| vk_physical_device_ = GetPhysicalDevice(); | ||
| if (vk_physical_device_ != VK_NULL_HANDLE) { | ||
| QuerySurfaceCapabilities(); | ||
| QueryDeviceCapabilities(vk_physical_device_); | ||
| VulkanAPIUtils::GetDisplayFormats(vk_physical_device_, vk_surface_, display_formats_); | ||
| PlatformUtilVulkan::GetScreenResolutions(surface_capabilities_, display_resolutions_); | ||
|
|
||
| QueueFamilyIndices queue_indices = VulkanAPIUtils::FindQueueFamilies( | ||
| vk_physical_device_, vk_surface_); | ||
| if (CreateDevice(true, queue_indices)) { | ||
|
|
@@ -607,7 +602,7 @@ DisplayManager::SwapchainFrameHandle GraphicsAPIVulkan::GetCurrentSwapchainFrame | |
| DisplayManager::SwapchainFrameHandle GraphicsAPIVulkan::PresentCurrentSwapchainFrame() { | ||
| if (swapchain_acquired_current_frame_image_) { | ||
| VkSemaphore wait_semaphores[] = | ||
| {frame_render_completion_semaphore_[swapchain_info_.swapchain_current_frame_index_]}; | ||
| {frame_render_completion_semaphore_[swapchain_info_.swapchain_current_image_index_]}; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
|
|
||
| VkPresentInfoKHR present_info{}; | ||
| present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; | ||
|
|
@@ -649,9 +644,6 @@ DisplayManager::SwapchainFrameHandle GraphicsAPIVulkan::PresentCurrentSwapchainF | |
| swapchain_info_.swapchain_current_frame_index_ = | ||
| (swapchain_info_.swapchain_current_frame_index_ + 1) % | ||
| swapchain_info_.swapchain_frame_count_; | ||
| swapchain_info_.swapchain_current_depth_stencil_frame_index_ = | ||
| (swapchain_info_.swapchain_current_depth_stencil_frame_index_ + 1) % | ||
| swapchain_info_.swapchain_image_count_; | ||
| } else { | ||
| DebugManager::Log(DebugManager::kLog_Channel_Default, | ||
| DebugManager::kLog_Level_Error, | ||
|
|
@@ -705,6 +697,9 @@ bool GraphicsAPIVulkan::GetSwapchainFrameResourcesVk( | |
| "vkAcquireNextImageKHR failed: %d", result); | ||
| return false; | ||
| } | ||
| // TODO: this could just be the number of in-flight frames, but since they | ||
| // are now transient they shouldn't have memoery overhead (at least on mobile) | ||
| swapchain_info_.swapchain_current_depth_stencil_frame_index_ = swapchain_info_.swapchain_current_image_index_; | ||
|
Comment on lines
+700
to
+702
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The TODO comment here is helpful for future optimization. Assigning |
||
| swapchain_acquired_current_frame_image_ = true; | ||
|
|
||
| vkResetFences(vk_device_, 1, | ||
|
|
@@ -716,7 +711,7 @@ bool GraphicsAPIVulkan::GetSwapchainFrameResourcesVk( | |
| frame_resources.image_available = | ||
| swapchain_image_semaphore_[swapchain_info_.swapchain_current_frame_index_]; | ||
| frame_resources.render_complete = | ||
| frame_render_completion_semaphore_[swapchain_info_.swapchain_current_frame_index_]; | ||
| frame_render_completion_semaphore_[swapchain_info_.swapchain_current_image_index_]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| frame_resources.swapchain_color_image_view = | ||
| swapchain_info_.swapchain_image_views_[swapchain_info_.swapchain_current_image_index_]; | ||
| frame_resources.swapchain_depth_stencil_image_view = | ||
|
|
@@ -839,6 +834,13 @@ bool GraphicsAPIVulkan::CreateDevice(bool is_preflight_check, | |
| vkCreateDebugUtilsMessengerEXT(vk_instance_, &messenger_create_info, nullptr, | ||
| &debug_messenger_); | ||
| } | ||
|
|
||
| if (vk_device_ != VK_NULL_HANDLE) { | ||
| QuerySurfaceCapabilities(); | ||
| QueryDeviceCapabilities(vk_physical_device_); | ||
| VulkanAPIUtils::GetDisplayFormats(vk_physical_device_, vk_surface_, display_formats_); | ||
| PlatformUtilVulkan::GetScreenResolutions(surface_capabilities_, display_resolutions_); | ||
| } | ||
|
Comment on lines
+838
to
+843
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving the surface and device capability queries to after |
||
| return (vk_device_ != VK_NULL_HANDLE); | ||
| } | ||
|
|
||
|
|
@@ -885,6 +887,16 @@ void GraphicsAPIVulkan::CreateInstance(bool is_preflight_check) { | |
| PlatformUtilVulkan::InitMessengerCreateInfo(messenger_create_info); | ||
| messenger_create_info.pfnUserCallback = messengerCallback; | ||
| create_info.pNext = &messenger_create_info; | ||
| VkValidationFeaturesEXT features = {}; | ||
| VkValidationFeatureEnableEXT enables[] = { | ||
| // Best practices is a little spammy from Swappy at the moment | ||
| // VK_VALIDATION_FEATURE_ENABLE_BEST_PRACTICES_EXT, | ||
| VK_VALIDATION_FEATURE_ENABLE_SYNCHRONIZATION_VALIDATION_EXT | ||
| }; | ||
| features.sType = VK_STRUCTURE_TYPE_VALIDATION_FEATURES_EXT; | ||
| features.enabledValidationFeatureCount = sizeof(enables) / sizeof(enables[0]); | ||
| features.pEnabledValidationFeatures = enables; | ||
| messenger_create_info.pNext = &features; | ||
| } else { | ||
| create_info.enabledLayerCount = 0; | ||
| create_info.ppEnabledLayerNames = nullptr; | ||
|
|
@@ -1061,13 +1073,16 @@ void GraphicsAPIVulkan::CreateSwapchainImages() { | |
| ds_image_info.format = swapchain_info_.swapchain_depth_stencil_format_; | ||
| ds_image_info.tiling = VK_IMAGE_TILING_OPTIMAL; | ||
| ds_image_info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; | ||
| ds_image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT; | ||
| ds_image_info.usage = VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | | ||
| VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT; | ||
|
Comment on lines
+1076
to
+1077
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ds_image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE; | ||
| ds_image_info.samples = VK_SAMPLE_COUNT_1_BIT; | ||
| ds_image_info.flags = 0; | ||
|
|
||
| VmaAllocationCreateInfo ds_image_alloc_create_info = {}; | ||
| ds_image_alloc_create_info.usage = VMA_MEMORY_USAGE_AUTO; | ||
| // Depth-stencil images paired with a swapchain will be don't care for store | ||
| // so they can be lazily allocated | ||
| ds_image_alloc_create_info.usage = VMA_MEMORY_USAGE_GPU_LAZILY_ALLOCATED; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing VMA usage to |
||
|
|
||
| VulkanAPIUtils::CheckVkResult( | ||
| vmaCreateImage(allocator_, &ds_image_info, | ||
|
|
@@ -1122,8 +1137,8 @@ void GraphicsAPIVulkan::DestroySwapchainImages() { | |
| void GraphicsAPIVulkan::CreateSynchronizationObjects() { | ||
| const size_t in_flight_frame_count = DisplayManager::GetInstance().GetDisplayBufferMode(); | ||
| in_flight_frame_fence_.resize(in_flight_frame_count); | ||
| frame_render_completion_semaphore_.resize(in_flight_frame_count); | ||
| swapchain_image_semaphore_.resize(in_flight_frame_count); | ||
| frame_render_completion_semaphore_.resize(swapchain_info_.swapchain_image_count_); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resizing |
||
|
|
||
| VkSemaphoreCreateInfo semaphore_info{}; | ||
| semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; | ||
|
|
@@ -1132,11 +1147,13 @@ void GraphicsAPIVulkan::CreateSynchronizationObjects() { | |
| fence_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; | ||
| fence_info.flags = VK_FENCE_CREATE_SIGNALED_BIT; | ||
|
|
||
| for (size_t i = 0; i < in_flight_frame_count; ++i) { | ||
| for (size_t i = 0; i < swapchain_info_.swapchain_image_count_; ++i) { | ||
| VulkanAPIUtils::CheckVkResult(vkCreateSemaphore(vk_device_, &semaphore_info, nullptr, | ||
| &frame_render_completion_semaphore_[i]), | ||
| "vkCreateSemaphore"); | ||
| } | ||
|
Comment on lines
+1150
to
+1154
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| for (size_t i = 0; i < in_flight_frame_count; ++i) { | ||
| VulkanAPIUtils::CheckVkResult(vkCreateSemaphore(vk_device_, &semaphore_info, nullptr, | ||
| &swapchain_image_semaphore_[i]), | ||
| "vkCreateSemaphore"); | ||
|
|
@@ -1148,8 +1165,10 @@ void GraphicsAPIVulkan::CreateSynchronizationObjects() { | |
| } | ||
|
|
||
| void GraphicsAPIVulkan::DestroySynchronizationObjects() { | ||
| for (size_t i = 0; i < in_flight_frame_fence_.size(); ++i) { | ||
| for (size_t i = 0; i < frame_render_completion_semaphore_.size(); ++i) { | ||
| vkDestroySemaphore(vk_device_, frame_render_completion_semaphore_[i], nullptr); | ||
| } | ||
|
Comment on lines
+1168
to
+1170
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| for (size_t i = 0; i < in_flight_frame_fence_.size(); ++i) { | ||
| vkDestroySemaphore(vk_device_, swapchain_image_semaphore_[i], nullptr); | ||
| vkDestroyFence(vk_device_, in_flight_frame_fence_[i], nullptr); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,6 +162,7 @@ void VulkanAPIUtils::GetDepthStencilFormats(VkPhysicalDevice physical_device, | |
|
|
||
| void VulkanAPIUtils::GetDisplayFormats(VkPhysicalDevice physical_device, VkSurfaceKHR surface, | ||
| std::vector<DisplayManager::DisplayFormat> &display_formats) { | ||
| display_formats.clear(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| std::vector<DisplayManager::DisplayFormat> depth_stencil_formats; | ||
| VulkanAPIUtils::GetDepthStencilFormats(physical_device, depth_stencil_formats); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,8 +68,8 @@ RenderPassVk::RenderPassVk(const RenderPassCreationParams& params) | |
| subpass_dependency.dstSubpass = 0; | ||
| subpass_dependency.srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; | ||
| subpass_dependency.srcAccessMask = 0; | ||
| subpass_dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; | ||
| subpass_dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; | ||
| subpass_dependency.dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT; | ||
| subpass_dependency.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; | ||
|
Comment on lines
+71
to
+72
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating |
||
|
|
||
| VkRenderPassCreateInfo render_pass_create_info = | ||
| { VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
swap_intervalsalways expected to be empty when this function is called, or is thisclear()added as a defensive measure? If it's possible forswap_intervalsto contain pre-existing data that should be preserved or handled differently under certain conditions, clearing it unconditionally might hide a logic issue elsewhere. However, if this function is always meant to populate it from a clean state, then thisclear()is good practice to ensure no stale data persists from previous calls, especially if the vector instance is reused.