What is the best practise for conditional rendering?

Hello everyone,

sometimes we don’t want to render everything in the scene for some reason.
Not rendering certain parts is sometimes referred to as conditional rendering.
But I am wondering: What is the best way to do this?

Taking a look at Sascha Willems great example collection, I see the example “conditional renderer” is using device extension VK_EXT_CONDITIONAL_RENDERING_EXTENSION_NAME.
However, it is not beyond impossible that this extension is not present in a system we want to support.

So what other way to do this?
Another option would be to record command buffers without calling the corresponding vkCmdDrawIndexed, so the object which we want to be invisible will not be rendered. A good example would be Sascha Willem’s “gltfscenerendering”.
This solution would work on all systems as it does not require any extensions.
The downside of this is that recording command buffers can be a very resource intensive operation which can take up to several 100 ms(!).

So what do you think about this?
Is there a best practise I’ve been missing so far?

Thank you,

Recording command buffers (CB) shouldn’t take hundreds of milliseconds for most cases, there are engines that record (almost) all of them each frame after all - so I suppose you have a somewhat unusual use case?

Your options depend a bit on if you know something about which objects are likely being toggled for visibility, e.g. if it only is a subset of your scene you could put those objects into a separate CB and only re-record that when visibility changes. Even if you don’t know that in advance you can distribute objects in your scene over multiple CBs and only record those where visibility changes.

VK_EXT_CONDITIONAL_RENDERING is probably most useful for cases where you handle the decision what to render entirely on the GPU - but if you have to support systems that don’t support it anyway, I’d first look at structuring the CB recording differently so that it is fast(er).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.