Search code examples
vulkanglsles

Is there a way to address subpassInput in Vulkan?


SubpassInput is implicitly addressed by the fragment shader. I want to address the input with my own texture Coords. Similar to texture(sampler, texCoord)


Solution

  • It is not possible. If You want to sample an image inside a shader, you have (in general) two possibilities:

    1. You can use a descriptor set with a descriptor of type sampled image or combined image sampler. This way You can address it however you like. But images that act as attachments inside a render pass cannot be used for such descriptors inside the same render pass in which they are used as attachments. For this purpose, you need to end a render pass and start another one. In the second render pass, you can use such images and sample them from within shaders.

    2. If you want to use an image as an attachment inside a render pass and if you want to sample such an image inside the same render pass (but in a later subpass), you can only do it using an input attachment descriptor (subpassInput inside shaders). This way you don't need to end the render pass and start another one, but you can only sample location associated with fragment shader's coordinates.

      This restriction comes from the fact that rendering is highly parallel. Some parts of the next subpass may already start being processed before all the operations from the previous subpass are finished (think about tiled renderers). And if you start reading data from an image to which you were rendering in a previous subpass, and if this rendering isn't finished yet for some parts of the image, you may get incorrect values. That's why you can read only from the single location from within the render pass (when using an input attachment).

    Maybe there is an extension that lifts these constraints, but I didn't read about any such extension. Core specification allows only the above two options.