2

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

1 Answer 1

8

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I want to apply 2 post Effects to my output. The first post effect plays with the rendered output in fragment shader, where as second post effect flips the image. With the first subpass I can achieve the first post effect. For second subpass is there a way to achieve it? If I cannot address the texture can I modify where I can write the color to?
@abhijitjagdale: No. You have to break the render pass. It should be noted that when you did such a trick in OpenGL ES, you pretty much killed your performance doing so. Vulkan doesn't let you get away with thinking that this is a cheap operation.
I think there is an extension that allows You to invert the viewport thus inverting the displayed image. But it is just an extension so it may not be supported on all devices. With the core spec You need to start a new render pass or invert the image using compute shaders.
I was told it's not exactly that rigid. there is some amount of slack around the local pixel, it just depends on the API. Metal tolerates an offset to neighbors IIRC. Provided you dont spill in the next tile I imagine. HLSL has no parameters so it's rigid, but it's a poor front end. And indeed in SPIRV OpImageRead has relative coord params when Dim is SubpassData

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.