Fix swapchain present wait semaphore reuse

VUID-vkQueueSubmit2-semaphore-03868
This commit is contained in:
2025-07-17 21:51:14 +02:00
parent 22e4091419
commit b231d2280e
2 changed files with 16 additions and 9 deletions

5
hk21.todo.txt Normal file
View File

@ -0,0 +1,5 @@
create the image resource & its manager +gpu
recycle fences +gpu
recycle command pools +gpu
recycle frame structures +gpu
use a custom allocator +gpu

View File

@ -16,10 +16,6 @@
#include "hk21/vulkan/loader/loader.hpp" #include "hk21/vulkan/loader/loader.hpp"
#include "hk21/vulkan/sync/sync.hpp" #include "hk21/vulkan/sync/sync.hpp"
// @Todo Make fences recyclable
// @Todo Make command pool recyclable
// @Todo Make frame structure recyclable
#define VK_ALLOCATOR nullptr #define VK_ALLOCATOR nullptr
[[maybe_unused]] static void AslFormat(asl::Formatter& formatter, VkResult res) [[maybe_unused]] static void AslFormat(asl::Formatter& formatter, VkResult res)
@ -356,9 +352,9 @@ class GpuImpl : public Gpu
asl::option<VkSwapchainKHR> m_swapchain; asl::option<VkSwapchainKHR> m_swapchain;
asl::buffer<Image> m_swapchain_images; asl::buffer<Image> m_swapchain_images;
asl::buffer<VkSemaphore> m_swapchain_present_wait_semaphores;
VkSemaphore m_swapchain_image_acquire_semaphore = VK_NULL_HANDLE; VkSemaphore m_swapchain_image_acquire_semaphore = VK_NULL_HANDLE;
VkSemaphore m_queue_complete_semaphore = VK_NULL_HANDLE;
asl::GlobalHeap m_allocator; // @Todo Make this configurable asl::GlobalHeap m_allocator; // @Todo Make this configurable
asl::IntrusiveList<FrameResources> m_in_flight_frames; asl::IntrusiveList<FrameResources> m_in_flight_frames;
@ -380,7 +376,6 @@ public:
, m_device{device} , m_device{device}
, m_queue{queue} , m_queue{queue}
, m_swapchain_image_acquire_semaphore{create_semaphore()} , m_swapchain_image_acquire_semaphore{create_semaphore()}
, m_queue_complete_semaphore{create_semaphore()}
{ {
} }
@ -401,7 +396,11 @@ public:
recycle_resources(); recycle_resources();
destroy_semaphore(m_swapchain_image_acquire_semaphore); destroy_semaphore(m_swapchain_image_acquire_semaphore);
destroy_semaphore(m_queue_complete_semaphore);
for (VkSemaphore semaphore: m_swapchain_present_wait_semaphores)
{
destroy_semaphore(semaphore);
}
if (m_swapchain.has_value()) if (m_swapchain.has_value())
{ {
@ -507,6 +506,7 @@ public:
{ {
m_swapchain_images.resize(count); m_swapchain_images.resize(count);
m_swapchain_present_wait_semaphores.resize(count);
// @Todo Good candidate for temporary allocation // @Todo Good candidate for temporary allocation
asl::buffer<VkImage> images; asl::buffer<VkImage> images;
@ -521,6 +521,7 @@ public:
for (int64_t i = 0; i < count; ++i) for (int64_t i = 0; i < count; ++i)
{ {
m_swapchain_images[i].image = images[i]; m_swapchain_images[i].image = images[i];
m_swapchain_present_wait_semaphores[i] = create_semaphore();
} }
} }
@ -586,6 +587,7 @@ public:
} }
auto& swapchain_image = m_swapchain_images[image_index]; auto& swapchain_image = m_swapchain_images[image_index];
VkSemaphore present_wait_semaphore = m_swapchain_present_wait_semaphores[image_index];
VkCommandPoolCreateInfo command_pool_create_info{ VkCommandPoolCreateInfo command_pool_create_info{
.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
@ -681,7 +683,7 @@ public:
VkSemaphoreSubmitInfo semaphore_signal_submit_info{ VkSemaphoreSubmitInfo semaphore_signal_submit_info{
.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO,
.pNext = nullptr, .pNext = nullptr,
.semaphore = m_queue_complete_semaphore, .semaphore = present_wait_semaphore,
.value = 0, .value = 0,
.stageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, .stageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT,
.deviceIndex = 0, .deviceIndex = 0,
@ -716,7 +718,7 @@ public:
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = nullptr, .pNext = nullptr,
.waitSemaphoreCount = 1, .waitSemaphoreCount = 1,
.pWaitSemaphores = &m_queue_complete_semaphore, .pWaitSemaphores = &present_wait_semaphore,
.swapchainCount = 1, .swapchainCount = 1,
.pSwapchains = &m_swapchain.value(), .pSwapchains = &m_swapchain.value(),
.pImageIndices = &image_index, .pImageIndices = &image_index,