'What is the point of specifying the size of the framebuffer in Vulkan?

When you create a framebuffer to render on in Vulkan you're required to fill in the size of it:

VkFramebufferCreateInfo framebufferInfo{};
framebufferInfo.width = width;
framebufferInfo.height = height;

Obviously the size of the buffer or viewport matters as you're required to write out in NDC which is -1 to 1. Essentially Vulkan needs to map -1 to 1 to 0 to size of the buffer/image. However when we create the pipeline we specify the size of the viewport, and I thought it was this that Vulkan uses in knowing what size it's rendering on. If that's the case what is the point of specifying the size in the framebuffer creation info?



Solution 1:[1]

The framebuffer size defines the available space for the attached images beyond which rendering simply can't happen. If a fragment is generated whose framebuffer space coordinate (generated by the viewport transform) falls outside of the framebuffer area, that fragment is discarded.

Fragments which would be produced by application of any of the primitive rasterization rules described below but which lie outside the framebuffer are not produced, nor are they processed by any later stage of the pipeline, including any of the fragment operations.

Note that viewport state can be dynamic and can change in the middle of a renderpass; framebuffer sizes cannot.

Also note that you don't have to have images attached to a framebuffer at all, or you can have a subpass that has no color or depth attachments. The fragment shader will still be invoked on the basis of the framebuffer size, thus allowing the FS to use side-effects to perform some rasterization-based task.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1