Reuse present semaphores by acquired swapchain image #445

Merged
klimovich008 merged 1 commit from codex/present-semaphores-per-image into main 2026-11-08 16:49:22 +00:00
klimovich008 commented 2026-11-08 02:17:37 +00:00 (Migrated from github.com)

What this fixes

With four swapchain images and three frames in flight, a visible window can reuse a presentation semaphore while the display still needs it. Validation reports VUID-vkQueueSubmit2-semaphore-03868.

Why merge

  • Reuse each semaphore only after its swapchain image is acquired again, following the Vulkan guide.
  • Keep frame fences, acquisition semaphores, queue batching and presentation-mode defaults unchanged.
  • Clean up new resources if image-count queries or semaphore allocation fail.

Change

gpu/vk/vk_internal.h: keep presentation semaphores beside swapchain images.
gpu/vk/vk_main.cpp: allocate them per image and retire them with the existing swapchain.
gpu/vk/vk_replay.cpp: select the acquired image's semaphore for submission and presentation.
tests/test_present_semaphores.py: exercise the actual code with four images, three frame slots, recreation and setup failures.

Tested

  • python -I -B tests/test_present_semaphores.py --cxx clang++ checks reuse and cleanup without Vulkan. Fails on the old code, passes now.
  • RX 9070 XT, Windows: unchanged source reports three errors in 47 seconds; fixed code runs 303 seconds with zero VUIDs, including gameplay, maximize and restore.

Not covered

  • Tested on AMD/Windows only. No game data is included.
  • Existing idle-based swapchain retirement remains; explicit presentation fences during teardown are outside this fix.
## What this fixes With four swapchain images and three frames in flight, a visible window can reuse a presentation semaphore while the display still needs it. Validation reports `VUID-vkQueueSubmit2-semaphore-03868`. ## Why merge - Reuse each semaphore only after its swapchain image is acquired again, following the [Vulkan guide](https://docs.vulkan.org/guide/latest/swapchain_semaphore_reuse.html). - Keep frame fences, acquisition semaphores, queue batching and presentation-mode defaults unchanged. - Clean up new resources if image-count queries or semaphore allocation fail. ## Change `gpu/vk/vk_internal.h`: keep presentation semaphores beside swapchain images. `gpu/vk/vk_main.cpp`: allocate them per image and retire them with the existing swapchain. `gpu/vk/vk_replay.cpp`: select the acquired image's semaphore for submission and presentation. `tests/test_present_semaphores.py`: exercise the actual code with four images, three frame slots, recreation and setup failures. ## Tested - `python -I -B tests/test_present_semaphores.py --cxx clang++` checks reuse and cleanup without Vulkan. Fails on the old code, passes now. - RX 9070 XT, Windows: unchanged source reports three errors in 47 seconds; fixed code runs 303 seconds with zero VUIDs, including gameplay, maximize and restore. ## Not covered - Tested on AMD/Windows only. No game data is included. - Existing idle-based swapchain retirement remains; explicit presentation fences during teardown are outside this fix.
Commenting is not possible because the repository is archived.
No description provided.