diff --git a/hk21.todo.txt b/hk21.todo.txt new file mode 100644 index 0000000..3e80186 --- /dev/null +++ b/hk21.todo.txt @@ -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 diff --git a/hk21/game/gpu.cpp b/hk21/game/gpu.cpp index 220b99b..2349635 100644 --- a/hk21/game/gpu.cpp +++ b/hk21/game/gpu.cpp @@ -16,10 +16,6 @@ #include "hk21/vulkan/loader/loader.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 [[maybe_unused]] static void AslFormat(asl::Formatter& formatter, VkResult res) @@ -356,9 +352,9 @@ class GpuImpl : public Gpu asl::option m_swapchain; asl::buffer m_swapchain_images; + asl::buffer m_swapchain_present_wait_semaphores; 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::IntrusiveList m_in_flight_frames; @@ -380,7 +376,6 @@ public: , m_device{device} , m_queue{queue} , m_swapchain_image_acquire_semaphore{create_semaphore()} - , m_queue_complete_semaphore{create_semaphore()} { } @@ -401,7 +396,11 @@ public: recycle_resources(); 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()) { @@ -507,6 +506,7 @@ public: { m_swapchain_images.resize(count); + m_swapchain_present_wait_semaphores.resize(count); // @Todo Good candidate for temporary allocation asl::buffer images; @@ -521,6 +521,7 @@ public: for (int64_t i = 0; i < count; ++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]; + VkSemaphore present_wait_semaphore = m_swapchain_present_wait_semaphores[image_index]; VkCommandPoolCreateInfo command_pool_create_info{ .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO, @@ -681,7 +683,7 @@ public: VkSemaphoreSubmitInfo semaphore_signal_submit_info{ .sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, .pNext = nullptr, - .semaphore = m_queue_complete_semaphore, + .semaphore = present_wait_semaphore, .value = 0, .stageMask = VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, .deviceIndex = 0, @@ -716,7 +718,7 @@ public: .sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .pNext = nullptr, .waitSemaphoreCount = 1, - .pWaitSemaphores = &m_queue_complete_semaphore, + .pWaitSemaphores = &present_wait_semaphore, .swapchainCount = 1, .pSwapchains = &m_swapchain.value(), .pImageIndices = &image_index,