What is the difference between framebuffer and image in Vulkan?
Asked Answered
B

2

36

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.

Brigantine answered 18/9, 2016 at 11:27 Comment(2)
"I've known that framebuffer is the final destination of the rendering pipeline" A VkFramebuffer is not the "final destination" for anything. What you render to is defined by your subpasses, which reference images in a VkFramebuffer. But the VkFramebuffer itself doesn't really do anything. It sounds like you're talking more about something like OpenGL's default framebuffer.Nikaniki
Well, maybe I'm just used to OpenGL. So which one collect images? I thought that swapchain collect them. Did I misunderstand something?Brigantine
W
86
  • VkFramebuffer + VkRenderPass defines the render target.

  • Render pass defines which attachment will be written with colors.

  • VkFramebuffer defines which VkImageView is to be which attachment.

  • VkImageView defines which part of VkImage to use.

  • VkImage defines which VkDeviceMemory is used and a format of the texel.


Or maybe in opposite sequence:

  • VkDeviceMemory 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 only part (array or mip) of the VkImage (like stringView, arrayView or whathaveyou does). Also can help to match to some incompatible interface (by type casting format).

  • VkFramebuffer binds a VkImageView 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).

enter image description here

Wolfgram answered 18/9, 2016 at 15:35 Comment(8)
Nice explanation. Provide that pretty diagram also.Scallion
Still waiting on that diagram,Trapshooting
Just to troll ya, I made an attempt at a diagramWolfgram
Where can we learn the meaning of the relationships in the diagram? My best guess is the following: white diamond = contained in, black arrow = is, dashed line = note, line arrow = reference to.Gca
@DavidDiGioia Mostly UML, with a touch of BS. Diamond is aggregation. VkDM is bound to VkI, which is bound to VkIV, which is bound to attachment of VkF, while all the objects still preserve their own independence. Arrow with dot is a pointer\array. Attachments of Render Pass are referenced in Subpass(Description) via array index int. Arrows in the memory part of the diagram are "identity" (i.e. it is the same memory just differently interpreted or addressed).Wolfgram
Thank you, this diagram is tremendously helpful! I am currently getting into Vulkan, but find it hard to sort out the relation between individual entities based on the documentation or tutorials. Some things are actually quite different than they used to be in OpenGL.Aceydeucy
@Wolfgram Thanks! Also what tool did you use to make the diagram? I'm thinking of making diagrams of other concepts in Vulkan because having it laid out visually is tremendously helpful in understanding for me.Gca
@DavidDiGioia This one's from old Visio.Wolfgram
Q
16

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.

Qua answered 19/9, 2016 at 19:55 Comment(1)
Aren't you one of the guys from LunarG? Hey, thanks for taking the time to answer questions from us mere mortals here =)Immune

© 2022 - 2024 — McMap. All rights reserved.