问题
I've known that framebuffer is the final destination of the rendering pipeline and swapchain contains many image. So what is the relation between those two things? Which one is the actual render target? And does the framebuffer later attach the final picture of the current frame on the image view? If so, how will it transfer?
Describing this via paint or diagram would be pleased.
回答1:
VkFramebuffer
+VkRenderPass
defines the render target.Render pass defines which attachment will be written with colors.
VkFramebuffer
defines whichVkImageView
is to be which attachment.VkImageView
defines which part ofVkImage
to use.VkImage
defines whichVkMemory
is used and a format of the texel.
Or maybe in opposite sequence:
VkMemory
is just a sequence of N bytes in memory.VkImage
object adds to it e.g. information about the format (so you can address by texels, not bytes).VkImageView
object helps select part of theVkImage
(like stringView, arrayView or whathaveyou) also can help to match to some incompatible interface (by converting format on the fly).VkFramebuffer
binds aVkImageView
with an attachment.VkRenderpass
defines which attachment will be drawn into
So it's not like you do not use an image. You do, through the Vulkan Framebuffer.
Swapchain image is no different from any other image. Except that the driver is the owner of the image. You can't destroy it directly or allocate it yourself. You just borrow it from the driver for the duration between acquire and present operation.
There's (usually) more of the swapchain images for the purposes of buffering and advance rendering. AFAIK you would need a separate VkFramebuffer
for each image (which is annoying, but more in tune with what actually happens underneath).
(There's definitely a pretty diagram in this. Maybe later...)
回答2:
Probably the best single sentence from the Vulkan spec that describes framebuffers is:
The specific image views that will be used for the attachments, and their dimensions, are specified in VkFramebuffer objects.
Yes, you would need a VkFramebuffer
object for each image in a swapchain, but you generally would need to allocate only one VkMemory
for a depth buffer VkImage
and then add the VkImageView
for that single depth buffer VkImage
to all of your framebuffers.
来源:https://stackoverflow.com/questions/39557141/what-is-the-difference-between-framebuffer-and-image-in-vulkan