Potential unsafe reuse of `renderFinishedSemaphore`

Offen
#533 0 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 16 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
61/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
cpp
Bereich
backend, testing-qa

Rechercherichtung

Read 15_hello_triangle.cpp alongside 16_frames_in_flight.cpp and the linked Vulkan Guide on swapchain semaphore reuse. Check whether the chapter 15 submission and presentation sequence permits reusing the semaphore before presentation has finished waiting on it. Done when the specification or a reproducer establishes whether reuse is safe and, if not, the example’s synchronization is corrected.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

While reading the Rendering and Presentation chapter, I noticed a potential synchronization issue in 15_hello_triangle.cpp.

The example creates a single renderFinishedSemaphore, which is reused for every frame. It is signaled by queue.submit() and waited on by queue.presentKHR().

My concern is that the semaphore might be reused before the previous presentation operation has finished waiting on it.

For example, consider the following sequence:

Frame 0:

  1. The application submits rendering commands for swapchain Image 0, with drawFence and renderFinishedSemaphore.
  2. Once the rendering submission completes, both drawFence and renderFinishedSemaphore are signaled.
  3. The presentation operation waits on renderFinishedSemaphore. However, this wait may not have completed yet.

Frame 1: (assuming Frame 0's presentation wait on renderFinishedSemaphore has not yet completed):

  1. The CPU waits on drawFence. Since Frame 0's rendering has completed, the fence wait can return.
  2. The application acquires another swapchain image, say Image 1, and submits rendering commands for Frame 1.
  3. This submission attempts to signal the same renderFinishedSemaphore again.

The potential issue is that Frame 0's presentation operation may still be waiting on renderFinishedSemaphore when Frame 1 attempts to signal it again.

Since this is a binary semaphore, it must return to the unsignaled state before it can be signaled again. Waiting for drawFence only guarantees that Frame 0's rendering submission has completed, not that its presentation wait has completed.

The Vulkan Guide on Swapchain Semaphore Reuse discusses a similar problem, where a rendering fence does not guarantee that a semaphore used by presentation is safe to reuse.

I also noticed that the next example, 16_frames_in_flight.cpp uses renderFinishedSemaphores[imageIndex], so it doesn't appear to have the same issue.

I haven't reproduced a validation error myself, but I was wondering whether this semaphore reuse in chapter 15 is guaranteed to be safe by the Vulkan specification.

Thanks!

Vorherrschende Sprache
C++
Sterne
444
Forks
145
Ø Merge
12 T. 10 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus KhronosGroup/Vulkan-Tutorial

Alle Issues in KhronosGroup/Vulkan-Tutorial

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.