Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I need resources per swapchain image

Tags:

vulkan

I have been following different tutorials and I don't understand why I need resources per swapchain image instead of per frame in flight.

This tutorial: https://vulkan-tutorial.com/Uniform_buffers

has a uniform buffer per swapchain image. Why would I need that if different images are not in flight at the same time? Can I not start rewriting if the previous frame has completed?

Also lunarg tutorial on depth buffers says:

And you need only one for rendering each frame, even if the swapchain has more than one image. This is because you can reuse the same depth buffer while using each image in the swapchain.

This doesn't explain anything, it basically says you can because you can. So why can I reuse the depth buffer but not other resources?

like image 310
Rhu Mage Avatar asked Sep 17 '25 04:09

Rhu Mage


1 Answers

It is to minimize synchronization in the case of the simple Hello Cube app.

Let's say your uniforms change each frame. That means main loop is something like:

  1. Poll (or simulate)
  2. Update (e.g. your uniforms)
  3. Draw
  4. Repeat

If step #2 did not have its own uniform, then it needs to write a uniform previous frame is reading. That means it has to sync with a Fence. That would mean the previous frame is no longer considered "in-flight".

like image 110
krOoze Avatar answered Sep 18 '25 18:09

krOoze