Q:

Vulkan: Present to Swapchain from Offscreen Buffer

I'm trying make a deferred renderer in Vulkan so I need to present the resultant image from my deferred rendering framebuffer to the screen, but I don't know exactly how.
My idea is:
Add the image acquired from the swapchain at the end of my framebuffer and add a subpass to render the end result to it.
But, should I create multiple copies of my framebuffer(one copy for every swapchain image), or delete the framebuffer and renderpass and recreate them every frame while setting the last image as the swapchain's image.
Is there other way to do it?
Should I make another set of pipelines, render passes and framebuffers to copy the result to the swapchain's images?
I tried looking at SaschaWillems examples and I think he is doing the double renderpass approach but I wondered if there was another way to do it.

A:

There are multiple options if you want to consider extra copies, but assuming you want to render your final image directly into the swapchain, image, there are two basic options.
First, if you don't want to use multiple subpasses, on each frame you'll use one framebuffer for each pass. The final framebuffer will use the swapchain image for that frame as its color attachment. For each framebuffer, you'll use a different renderpass, since the framebuffer attachment counts/formats/etc. will likely be different. You can create all of the renderpasses and non-swapchain framebuffers up front and reuse them on each frame.
For the swapchain framebuffer, create one for each swapchain image when you first create the swapchain, and then on each frame use the framebuffer that matches the swapchain image for that frame. Try to avoid destroying and recreating objects all the time; instead cache and reuse them -- the reason they're distinct objects is to allow you to amortize the creation cost over many uses. (Single-subpass renderpasses should be cheap to create, but on at least one architecture an framebuffer is expensive to create, and multi-subpass renderpasses can also be expensive on some architectures.)
Secondly, if you want to do the whole thing as a single renderpass with multiple subpasses to take advantage of tile memory on some GPUs, the process is very similar. You'd have a single renderpass, but each subpass corresponds to one of the renderpasses in the first option, and will use similar attachments. Because you have just one renderpass you'll also have just one framebuffer per frame. Since the final subpass will write to the swapchain image, though, you'll need a separate framebuffer object for each swapchain image; all of these framebuffers will be identical except for the swapchain image attachment.

