zbrojny120
zbrojny120

Reputation: 776

At what stage does a pipeline use the framebuffer?

I'm trying to understand when a pipeline starts to use framebuffer attachments in Vulkan. According to the specification, for the graphics primitive shading pipeline, the following stages occur in this order:

VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT
VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT
VK_PIPELINE_STAGE_VERTEX_INPUT_BIT
VK_PIPELINE_STAGE_VERTEX_SHADER_BIT
VK_PIPELINE_STAGE_TESSELLATION_CONTROL_SHADER_BIT
VK_PIPELINE_STAGE_TESSELLATION_EVALUATION_SHADER_BIT
VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT
VK_PIPELINE_STAGE_TRANSFORM_FEEDBACK_BIT_EXT
VK_PIPELINE_STAGE_SHADING_RATE_IMAGE_BIT_NV
VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT

As far as I know, when only one attachment is used (no multi-sampling, just a single colour attachment), the pipe line should start writing to the framebuffer attachment at the rasterisation stage (so around somewhere before VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT). However, according to the specification, this should not happen until VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT stage. So, do pipelines use some intermediate, self-allocated memory to do all the fragment operations, and start writing to a swapchain image only at the COLOR_ATTACHMENT_OUTPUT stage? I only started working with Vulkan about two weeks ago, and I feel like there is some serious flaw in my reasoning, so it would be great if someone could point it out.

Upvotes: 1

Views: 934

Answers (1)

krOoze
krOoze

Reputation: 13246

Pipeline starts to use the color attachment in first subpass that uses it in VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, depth and\or stencil in VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT. This is given by Load Operation (loadOp).

[...] start writing to the framebuffer attachment at the rasterisation stage (so around somewhere before VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT)

Depth would be tested and potentially written there. Color cannot be written there; you do not even know what values to write without fragment shader.

But AIS, first use in render pass instance is the Load Operation, not the actual depth tests and writes.

So, do pipelines use some intermediate, self-allocated memory to do all the fragment operations, and start writing to a swapchain image only at the COLOR_ATTACHMENT_OUTPUT stage?

Pipelines (as in the API abstraction) no; it does not care how the driver does it. As for drivers they might do any number of things. Render Pass is mostly necessitated by tile-based architectures. There, Load Operation is something that actually matches the HW. The attachment may be literally loaded from general purpose memory to "on-chip memory" for processing of the given tile.

Other architectures may operate under the "as-if" principle. Note it is not valid to use attachment in non-attachment uses between Load and Store Op. Also note that the only two available Store operations are allowed to write to the attachment. So, if the driver operates directly on memory of the attachment, it would still be a conformant Vulkan implementation.

following stages occur in this order

I also get the notion that you think this means more than it means.

This is "logical order". This relates to Primitive Order and Rasterization Order. Yes, for a given pixel (x, y) they would happen in order. But that does not mean the driver has to wait on all the pixels before it writes them to memory. So no, with that in mind, you would not necessarily need "some intermediate, self-allocated memory".

Upvotes: 4

Related Questions