Skip to content
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

hello_triangle sample references a retired swapchain #1015

Open
yaman-lunarg opened this issue Apr 9, 2024 · 0 comments · May be fixed by #1019
Open

hello_triangle sample references a retired swapchain #1015

yaman-lunarg opened this issue Apr 9, 2024 · 0 comments · May be fixed by #1019

Comments

@yaman-lunarg
Copy link

hello_triangle.cpp references a retired swapchain resulting in a warning on Android:

04-08 21:49:23.966 19681 20951 W vulkan : getting images for non-active swapchain 0xb400007623312000; only dequeued image handles are valid

void HelloTriangle::init_swapchain(Context &context)
{
	VkSurfaceCapabilitiesKHR surface_properties;
	VK_CHECK(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(context.gpu, context.surface, &surface_properties));
...
VkSwapchainCreateInfoKHR info{VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR};
info.surface            = context.surface;
info.minImageCount      = desired_swapchain_images;
info.imageFormat        = format.format;
info.imageColorSpace    = format.colorSpace;
info.imageExtent.width  = swapchain_size.width;
info.imageExtent.height = swapchain_size.height;
info.imageArrayLayers   = 1;
info.imageUsage         = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
info.imageSharingMode   = VK_SHARING_MODE_EXCLUSIVE;
info.preTransform       = pre_transform;
info.compositeAlpha     = composite;
info.presentMode        = swapchain_present_mode;
info.clipped            = true;
info.oldSwapchain       = old_swapchain;

VK_CHECK(vkCreateSwapchainKHR(context.device, &info, nullptr, &context.swapchain));

if (old_swapchain != VK_NULL_HANDLE)
{
	for (VkImageView image_view : context.swapchain_image_views)
	{
		vkDestroyImageView(context.device, image_view, nullptr);
	}

	uint32_t image_count;
	VK_CHECK(vkGetSwapchainImagesKHR(context.device, old_swapchain, &image_count, nullptr));
	for (size_t i = 0; i < image_count; i++)
	{
		teardown_per_frame(context, context.per_frame[i]);
	}

	context.swapchain_image_views.clear();

	vkDestroySwapchainKHR(context.device, old_swapchain, nullptr);
}
...

Vulkan spec states that

Upon calling vkCreateSwapchainKHR with an oldSwapchain that is not VK_NULL_HANDLE, oldSwapchain is retired — even if creation of the new swapchain fails. The new swapchain is created in the non-retired state whether or not oldSwapchain is VK_NULL_HANDLE.

VK_CHECK(vkCreateSwapchainKHR(context.device, &info, nullptr, &context.swapchain)); retires old_swapchain and VK_CHECK(vkGetSwapchainImagesKHR(context.device, old_swapchain, &image_count, nullptr)); references it.

uint32_t image_count;
VK_CHECK(vkGetSwapchainImagesKHR(context.device, old_swapchain, &image_count, nullptr));

should precede
VK_CHECK(vkCreateSwapchainKHR(context.device, &info, nullptr, &context.swapchain));

@yaman-lunarg yaman-lunarg changed the title hello_triangle sample references a retired swpachain hello_triangle sample references a retired swapchain Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant