Advertisement

Vulkan render pass interdependencies?

Started by November 14, 2017 01:46 PM
5 comments, last by GuyWithBeard 7 years, 2 months ago

Hi,

In Vulkan you have render passes where you specify which attachments to render to and which to read from, and subpasses within the render pass which can depend on each other. If one subpass needs to finish before another can begin you specify that with a subpass dependency.

In my engine I don't currently use subpasses as the concept of the "render pass" translates roughly to setting a render target and clearing it followed by a number of draw calls in DirectX, while there isn't really any good way to model subpasses in DX. Because of this, in Vulkan, my frame mostly consists of a number of render passes each with one subpass.

My question is, do I have to specify dependencies between the render passes or is that needed only if you have multiple subpasses?

In the Vulkan Programming Guide, chapter 13 it says: "In the example renderpass we set up in Chapter 7, we used a single subpass with no dependencies and a single set of outputs.”, which suggests that you only need dependencies between subpasses, not between render passes. However, the (excellent) tutorials at vulkan-tutorial.com have you creating a subpass dependency to "external subpasses" in the chapter on "Rendering and presentation", under "Subpass dependencies": https://vulkan-tutorial.com/Drawing_a_triangle/Drawing/Rendering_and_presentation even if they are using only one render pass with a single subpass.

So, in short; If I have render pass A, with a single subpass, rendering to an attachment and render pass B, also with a single subpass, rendering to that same attachment, do I have to specify subpass dependencies between the two subpasses of the render passes, in order to make render pass A finish before B can begin, or are they handled implicitly by the fact that they belong to different render passes?

Thanks!

The short answer is that you are likely to have problems and will need to do something to introduce dependencies between render passes.  The longer answer is that this is very driver specific and you might get away with it, at least for a while.  The problem here is that unlike Dx12, Vulkan does do a little driver level work to help you out which you usually want to duplicate in Dx12 yourself anyway.  Basically though, if you issue 10 render passes, the Vulkan driver does not have to heed the order you sent them to the queue unless you have supplied some form of dependency information or explicit synchronization.  Vulkan is allowed to, and probably will, issue the renderpasses out of order, in parallel or completely ass backwards depending on the drivers involved.  Obviously this means that the draw commands associated with each begin/next subpass executes out of order.

When I implemented my wrapper, I ended up duplicating the entire concept of render/sub passes in Dx12, it was the most appropriate solution I could find which would allow me to solve the various issues on the three primary rendering API's I wanted to support.  The primary reason for putting the work into this was exactly the problems you are asking questions about.  At least in my case, when I really dug into and understood the render passes I realized I had basically just been doing exactly the same things except in my rendering code.  By pushing it down to an abstraction it cleaned things up quite a lot and made for a much cleaner API.  Additionally, at a later time, it will make it considerably easier to deal with optimizing for better parallelism and GPU utilization since all the transitions and issuance is in one place that I can get clever with, without having to re-organize large swaths of code.

So, yup, I'd suggest you consider implementing the subpass portion because it has a lot of benefits and solves the problem you are asking about.

Advertisement

Interesting. I wonder if you could force render passes into a specific execution order (ie. the order they are recorded into the command buffer) by using only VK_SUBPASS_EXTERNAL as srcSubpass and dstSubpass.

EDIT: And by that I mean that the vulkan-tutorial.com article seems to suggest that you can refer to a subpass of a previous/subsequent render pass using VK_SUBPASS_EXTERNAL, although I am a bit unsure if that is what it really means.

Of course, it wouldn't be utilizing the GPU to its fullest but it would ensure correct behavior...

BTW, did you manage to hide away all resource barriers and transitions into your render pass system or do you still have to issue barrier/transition commands on your command buffers at the rendering code level?

1 hour ago, GuyWithBeard said:

Interesting. I wonder if you could force render passes into a specific execution order (ie. the order they are recorded into the command buffer) by using only VK_SUBPASS_EXTERNAL as srcSubpass and dstSubpass.

Yes you can.  This was actually the first approach I tried but it is very bad for the GPU in terms that it severely under-utilizes parallelism.  As a quick and dirty 'get it running' solution it is fine though.  If you read that tutorial again you might catch that they talk about there being implicit 'subpasses' in each render pass, it's kinda 'pre' 'your pass' 'post'.  By setting dependencies on those hidden subpasses that is how you can control renderpass to renderpass dependency, or at least ordering.

1 hour ago, GuyWithBeard said:

BTW, did you manage to hide away all resource barriers and transitions into your render pass system or do you still have to issue barrier/transition commands on your command buffers at the rendering code level?

Nope, I still expose quite a bit of that for things not directly within a renderpass since it is common to all three API's, or null op where Metal does some of it for you.  The most specific case is the initial upload of a texture where you still have to do the transition to CPU visible, copy the data, transition to GPU visible copy to GPU only memory.  While I have considered hiding all these items the goal is to keep the adapter as close to the underlying API's as possible and maintain the free threaded externally synchronized model of DX12/Vulkan and to a lesser degree Metal.  Hiding transitions and such would mean building more thread handling and synchronization into that low level than I desire.  This would be detrimental since I'm generating command buffers via 32 threads (Thread ripper is fun) which would really suck if the lowest level adapter was introducing synchronization at the CPU level in order to automate hiding a couple barrier & transition calls.

Long story short, the middle layer 'rendering engine' will probably hide all those details.  I just haven't really bothered much and hand code a lot of it since I'm more focused on game systems than on the rendering right now.

1 hour ago, Hiwas said:

Yes you can. 

Cool, thanks. I am gonna go with that for now because I am in the middle of implementing large feature and now is not the right time to rewrite my render pass system.

This topic is closed to new replies.

Advertisement