vulkan

Render pass compatibility


I read that two attachment references are compatible if they have matching format and sample count, or are both VK_ATTACHMENT_UNUSED or the pointer that would contain the reference is NULL.

What pointer is the spec talking about ?

The actual problem that I am try to solve and the reason that I am asking is that I have a framebuffer with 3 attachments (depth, color0, color1) and two pipelines (a.k.a. shader programs). The first pipeline writes to all 3 attachments of the framebuffer, while the second pipeline writes only to depth and color0.

How I am supposed to define a render pass that is compatible with both pipelines and the framebuffer ?

If I create them with render pass with 3 attachments, then validation layers given me warning that the second pipeline does not write into color1 and that its contents will be undefined. On the other hand if I create that second pipeline with a modified render pass with two attachments, then validation layers throw an error that render passes are incompatible:

Attachment 2 is not compatible with 4294967295: The second is unused while the first is not.. The Vulkan spec states: The current render pass must be compatible with the renderPass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline bound to VK_PIPELINE_BIND_POINT_GRAPHICS

For example in OpenGL I am able to solve this by enabling/disabling required attachments with glDrawBuffers before each shader program.


Solution

  • How I am supposed to define a render pass that is compatible with both pipelines and the framebuffer ?

    A pipeline doesn't have to write to all attachments of a subpass. Just have the pipeline that only writes to one output turn off writes to color1. This is done through the write mask.