Shadowmap real-time update design

I am curious about the best way to update shadow maps in real-time. Since a texture may be in use when it is being rendered to, just like swap chain images, a more sophisticated design is needed than the simple render-to-texture I used for OpenGL shadowmaps.

I can think of two ways to go about this:

  1. Keep a sort of “swap chain” of shadow maps going. Of course we don’t want to double all our texture memory, so it would be best to store out-of-use shadow maps / buffers in a pool and retrieve a free one from the pool when it is needed.

  2. Render to a buffer and then use a vkCmdCopyTexture() call to copy the results to the displayed shadow map.

Performance is my main concern. Any tips on the best approach here? Is there a simpler way?

I’m curious about this as well. My guess is that you’d typically just need the one shadow map (for a given light source) for the same reasons you only need one depth map – regardless of the swapchain size.

  1. Write to the shadow map in a “shadow” subpass.
  2. Read from the shadow map in another subpass. Image layout would need to be suitable for shader reads. Shadow map attachment would be in the preserved list while the shadow map is accessed as a texture.
  3. Other subpasses here if necessary…

At least that was how I was about to attempt this. Would like to hear the approach others are taking.