6

VkGraphicsPipelineCreateInfo has integer member subpass.

My use case is creating a single pipeline object and use it with multiple subpasses. Each subpass has different color attachment.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
s007
  • 728
  • 6
  • 12

1 Answers1

6

No. A pipeline is always built relative to a specific subpass of a specific render pass. It cannot be used in any other subpass:

The subpass index of the current render pass must be equal to the subpass member of the VkGraphicsPipelineCreateInfo structure specified when creating the VkPipeline currently bound to VK_PIPELINE_BIND_POINT_GRAPHICS.

You will need to create multiple pipelines, one for each subpass you intend to use it with. The pipeline cache should make this efficient for implementations that don't really care much about this.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • 2
    Additionally, wanting to use the same pipeline for multiple subpasses is not typical of the common use cases for subpasses. If you're wanting to do this, it may be a signal that there is a simpler or more efficient way to do what you're trying to do. Generally in multiple-subpass render passes, each subpass is performing a different sub-algorithm of the overall rendering algorithm, so the shaders (and therefore pipelines) will be different. – Jesse Hall Jun 20 '17 at 22:38
  • @NicolBolas However, in 7.2 Render Pass Compatibility (1.1.78) says "graphics pipelines are created based on a specific render pass object. They must only be used with that render pass object, or one compatible with it.". Implying that you _can_ use a pipeline with different render pass. Do you mean that it has to be always (say) subpass 3 of any render pass? – Pablo H Jun 20 '18 at 18:16
  • 1
    @PabloH: Consider how little wiggle-room Section 7.2 gives you for variance. Subpass 3 of a compatible render pass will be using compatible attachments, the exact same subpass state (attachment usages, etc), the same set of dependencies, etc. And yes, pipelines have to be used in the subpass they are defined for. – Nicol Bolas Jun 20 '18 at 18:55