-
-
Notifications
You must be signed in to change notification settings - Fork 28
CreateSwapChain Fix #487
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
base: develop
Are you sure you want to change the base?
CreateSwapChain Fix #487
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 |
|---|---|---|
|
|
@@ -1064,22 +1064,12 @@ namespace ZEngine::Hardwares | |
| SwapchainImageHeight = capabilities.currentExtent.height; | ||
| } | ||
|
|
||
| auto min_image_count = std::clamp(capabilities.minImageCount, capabilities.minImageCount + 1, capabilities.maxImageCount); | ||
| auto min_image_count = std::clamp(capabilities.minImageCount, capabilities.minImageCount, capabilities.maxImageCount == 0 ? capabilities.minImageCount + 1 : capabilities.maxImageCount); | ||
| VkSwapchainCreateInfoKHR swapchain_create_info = { | ||
| .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .pNext = nullptr, .surface = Surface, .minImageCount = min_image_count, .imageFormat = SurfaceFormat.format, .imageColorSpace = SurfaceFormat.colorSpace, .imageExtent = VkExtent2D{.width = SwapchainImageWidth, .height = SwapchainImageHeight}, | ||
| .imageArrayLayers = 1, .imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, .preTransform = capabilities.currentTransform, .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, .presentMode = PresentMode, .clipped = VK_TRUE | ||
| }; | ||
|
|
||
| if (SwapchainImageViews.capacity() <= 0) | ||
| { | ||
| SwapchainImageViews.init(Arena, SwapchainImageCount, SwapchainImageCount); | ||
| } | ||
|
|
||
| if (SwapchainFramebuffers.capacity() <= 0) | ||
| { | ||
| SwapchainFramebuffers.init(Arena, SwapchainImageCount, SwapchainImageCount); | ||
|
Owner
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. Same comment here about the prea-allocate ops before calling the Scratch Arena |
||
| } | ||
|
|
||
| auto scratch = ZGetScratch(Arena); | ||
|
|
||
| Array<uint32_t> family_indice = {}; | ||
|
|
@@ -1099,13 +1089,23 @@ namespace ZEngine::Hardwares | |
| uint32_t image_count = 0; | ||
| ZENGINE_VALIDATE_ASSERT(vkGetSwapchainImagesKHR(LogicalDevice, SwapchainHandle, &image_count, nullptr) == VK_SUCCESS, "Failed to get Images count from Swapchain") | ||
|
|
||
| if (image_count < SwapchainImageCount) | ||
| if (image_count != SwapchainImageCount) | ||
| { | ||
| ZENGINE_CORE_WARN("Max Swapchain image count supported is {}, but requested {}", image_count, SwapchainImageCount); | ||
| SwapchainImageCount = image_count; | ||
| ZENGINE_CORE_WARN("Swapchain image count has changed from {} to {}", SwapchainImageCount, image_count); | ||
| } | ||
|
|
||
| if (SwapchainImageViews.capacity() <= 0) | ||
| { | ||
| SwapchainImageViews.init(Arena, SwapchainImageCount, SwapchainImageCount); | ||
| } | ||
|
|
||
| if (SwapchainFramebuffers.capacity() <= 0) | ||
| { | ||
| SwapchainFramebuffers.init(Arena, SwapchainImageCount, SwapchainImageCount); | ||
| } | ||
|
|
||
|
Comment on lines
+1099
to
+1108
Owner
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. This will lead to a crash, because it's called under the block of Temp Arena and you can't use the allocator ------Arena mem-------|| <-----Temp Arena: Scratch (all allocation here in this zone will be ephemeral)---> || ---Arena mem------
Contributor
Author
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. noted. thanks for the explanation on the allocation. there was an issue on one of the vulkan calls because of the mismatch in the "original" swapchain count and the count after obtaining the image count. I will try and look at it with the allocation in mind.
Owner
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 comment here should provide the right fix -- and helps for more clarity |
||
| Array<VkImage> SwapchainImages = {}; | ||
| SwapchainImages.init(scratch.Arena, SwapchainImageCount, SwapchainImageCount); | ||
| ZENGINE_VALIDATE_ASSERT(vkGetSwapchainImagesKHR(LogicalDevice, SwapchainHandle, &SwapchainImageCount, SwapchainImages.data()) == VK_SUCCESS, "Failed to get VkImages from Swapchain") | ||
|
|
||
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.
init(Arena, count, count)help to pre-allocate (and zero-ed) the needed mem.it's useful here, in this context because, once the Temp Arena below
auto scratch = ZGetScratch(Arena);is called, all operations ( eg :push(...)) will use it and will get cleaned-up after release it.But data in
SwapchainImageViewsandSwapchainFramebuffersneed to be persistent till we close the engine.