Skip to content

Conversation

@MarijnS95
Copy link
Collaborator

@MarijnS95 MarijnS95 commented Oct 11, 2025

Fixes #917
Closes #941
Closes #979

Caution

The example teaches bad practices when it comes to performance. I have a change in flight that switches them to triple-buffering which inevitably replaces the second commit. We may prefer going that route instead.

examples: Have a unique semaphore per swapchain image

This resolves VUID-vkQueueSubmit-pSignalSemaphores-00067 as explained at https://docs.vulkan.org/guide/latest/swapchain_semaphore_reuse.html.

A unique semaphore should be used per swapchain image, because the presentation engine may still reference and use it before the image index it was used with is returned out of acquire_next_image() again.

Alternatives include waiting for the Fence from presentation in VkSwapchainPresentFenceInfoKHR, added by the VK_EXT_swapchain_maintenance1/VK_KHR_swapchain_maintenance1 extension but this is less performant than just using a unique semaphore per swapchain image.

examples: Wait earlier for command-buffer fence to prevent semaphore reuse

This resolves VUID-vkAcquireNextImageKHR-semaphore-01779 where acquire_next_image() is asked to signal a semaphore that may still be waited on by the currently-running submit.

Since the next submit is reusing the existing command buffer and resources as well it must inevitably wait on a fence from the previous frame/submit, pulling out that fence to wait on it is the most practical approach despite teaching bad/slow practices.

Note that this fence was also used to "reuse" the setup command buffer in the texture sample; this was instead generalized to use another command buffer without waiting for and signaling any fence.

examples: Implement triple-buffering

This removes a per-frame stall and demonstrates how users should utilize Vulkan to keep the GPU fed with rendering work, as long as that work (and corresponding presentation requests) complete before we're getting 3 frames ahead.

Note that this does not implement proper frame throttling, and may render lots of discarded frames.

It is an alternative solution to solving VUID-vkAcquireNextImageKHR-semaphore-01779 by also using a unique Semaphore that we know is no longer waited on via previously waiting on the relevant Fence; although similar in nature to the previous solution.

This resolves `VUID-vkQueueSubmit-pSignalSemaphores-00067` as explained
at https://docs.vulkan.org/guide/latest/swapchain_semaphore_reuse.html

A unique semaphore should be used per swapchain image, because the
presentation engine may still reference and use it before the image
index it was used with is returned out of `acquire_next_image()` again.

Alternatives include waiting for the `Fence` from
presentation in `VkSwapchainPresentFenceInfoKHR`, added by the
`VK_EXT_swapchain_maintenance1`/`VK_KHR_swapchain_maintenance1`
extension but this is less performant than just using a unique semaphore
per swapchain image.
…reuse

This resolves `VUID-vkAcquireNextImageKHR-semaphore-01779` where
`acquire_next_image()` is asked to signal a semaphore that may still be
waited on by the currently-running submit.

Since the next submit is reusing the existing command buffer and
resources as well it must inevitably wait on a fence from the previous
frame/submit, pulling out that fence to wait on it is the most practical
approach despite teaching bad/slow practices.

Note that this fence was also used to "reuse" the setup command
buffer in the `texture` sample; this was instead generalized to use
another command buffer without waiting for and signaling any fence.
@MarijnS95 MarijnS95 requested a review from Ralith October 11, 2025 21:01
Copy link
Collaborator

@Ralith Ralith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triple-buffering sounds nice!

@MarijnS95 MarijnS95 changed the title examples: Fix validation errors related to invalid semaphore reuse examples: Prevent invalid semaphore reuse across frames Oct 12, 2025
@MarijnS95 MarijnS95 requested a review from Ralith October 30, 2025 23:03
This removes a per-frame stall and demonstrates how users should
utilize Vulkan to keep the GPU fed with rendering work, as long as that
work (and corresponding presentation requests) complete before we're
getting 3 frames ahead.

Note that this does not implement proper frame throttling, and may
render lots of discarded frames.

It is an alternative solution to solving
`VUID-vkAcquireNextImageKHR-semaphore-01779` by also using a unique
`Semaphore` that we know is no longer waited on via previously waiting
on the relevant `Fence`; although similar in nature to the previous
solution.
@MarijnS95 MarijnS95 merged commit 96becc8 into master Nov 2, 2025
20 checks passed
@MarijnS95 MarijnS95 deleted the fix-examples branch November 2, 2025 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERROR: VALIDATION on examples

3 participants