-
-
Notifications
You must be signed in to change notification settings - Fork 154
Description
Vulkan lets you mark the depth attachment as readonly, which can enable some optimizations. It's useful if you've already rendered the depth buffer and just want to use it for depth tests, without writing to it during the pass. LOVR could add support for this:
pass:setCanvas({
depth = {
texture = t,
readonly = true
}
})I think in this case the depth clear would be forced to false, and depth write would be forced to false as well, with Pass:setDepthWrite erroring if you try to set it to true.
It gets a little more complicated due to the stencil buffer. Technically you can separately set each "aspect" (depth vs. stencil) as readonly, if you wanted to do some stencil buffer writes/tests during the pass while keeping the depth readonly, or vice versa. Maybe we can have a separate stencilreadonly flag or something...
Another question is whether this would let you sample the depth buffer in a shader. Since you're not writing to it anymore, it should be safe. We could validate that the depth is readonly if you try to send the depth attachment to a shader uniform. I think the code that writes the descriptor would probably still work -- it would use the VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL layout (so it would require both aspects to be readonly, unless you used a texture view or something).
Synchronization would need to be modified to understand that readonly depth attachments are not being written to, only read from.
Related to #869