@@ -21,6 +21,8 @@ namespace ZEngine::Hardwares
2121 BufferredFrameCount = buffered_frame_size;
2222 FrameContextPoolSize = BufferredFrameCount * FrameContextPoolSizeFactor;
2323
24+ RenderTimeline = ZPushStructCtorArgs (&Arena, Primitives::Semaphore, Device, true );
25+
2426 Specifications::AttachmentSpecification attachment_specification = {.BindPoint = Specifications::PipelineBindPoint::GRAPHIC};
2527 attachment_specification.ColorsMap .init (&Arena, 2 );
2628 attachment_specification.ColorsMap [0 ] = {};
@@ -334,6 +336,7 @@ namespace ZEngine::Hardwares
334336
335337 wait_semaphores.push (CurrentFrame->Acquired ->GetHandle ());
336338 stage_flags.push (VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT);
339+ wait_values.push (0 );
337340
338341 while (!Device->AsyncGPUOperations .Empty ())
339342 {
@@ -358,16 +361,17 @@ namespace ZEngine::Hardwares
358361 stage_flags.push (val.StageMask );
359362 }
360363
361- QueueView queue = Device->GetQueue (Rendering::QueueType::GRAPHIC_QUEUE);
362- VkSemaphore signal_semaphores[] = {render_complete->GetHandle ()};
363-
364- VkTimelineSemaphoreSubmitInfo timeline_info = {
365- .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
366- .pNext = nullptr ,
367- .waitSemaphoreValueCount = (uint32_t ) wait_values.size (),
368- .pWaitSemaphoreValues = wait_values.data (),
369- .signalSemaphoreValueCount = 0 ,
370- .pSignalSemaphoreValues = nullptr ,
364+ QueueView queue = Device->GetQueue (Rendering::QueueType::GRAPHIC_QUEUE);
365+
366+ uint64_t signal_value = ++RenderTimelineNextValue;
367+ VkSemaphore timeline_signal = RenderTimeline->GetHandle ();
368+ VkTimelineSemaphoreSubmitInfo timeline_info = {
369+ .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
370+ .pNext = nullptr ,
371+ .waitSemaphoreValueCount = (uint32_t ) wait_values.size (),
372+ .pWaitSemaphoreValues = wait_values.data (),
373+ .signalSemaphoreValueCount = 1 ,
374+ .pSignalSemaphoreValues = &signal_value,
371375 };
372376
373377 VkSubmitInfo submit_info = {
@@ -379,7 +383,7 @@ namespace ZEngine::Hardwares
379383 .commandBufferCount = (uint32_t ) buffer.size (),
380384 .pCommandBuffers = buffer.data (),
381385 .signalSemaphoreCount = 1 ,
382- .pSignalSemaphores = signal_semaphores ,
386+ .pSignalSemaphores = &timeline_signal ,
383387 };
384388
385389 auto submit = vkQueueSubmit (queue.Handle , 1 , &(submit_info), CurrentFrame->Fence ->GetHandle ());
@@ -390,11 +394,38 @@ namespace ZEngine::Hardwares
390394 Device->CommandBufferMgr ->ResetEnqueuedBufferIndex ();
391395
392396 CurrentFrame->Fence ->SetState (Rendering::Primitives::FenceState::Submitted);
397+
398+ VkSemaphore timeline_wait = RenderTimeline->GetHandle ();
399+ VkSemaphore binary_semaphores[] = {render_complete->GetHandle ()};
400+
401+ VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_ALL_COMMANDS_BIT;
402+
403+ uint64_t wait_value = signal_value;
404+
405+ VkTimelineSemaphoreSubmitInfo timeline_info2 = {
406+ .sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
407+ .waitSemaphoreValueCount = 1 ,
408+ .pWaitSemaphoreValues = &wait_value,
409+ };
410+
411+ VkSubmitInfo submit2 = {
412+ .sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
413+ .pNext = &timeline_info2,
414+ .waitSemaphoreCount = 1 ,
415+ .pWaitSemaphores = &timeline_wait,
416+ .pWaitDstStageMask = &wait_stage,
417+ .commandBufferCount = 0 ,
418+ .signalSemaphoreCount = 1 ,
419+ .pSignalSemaphores = binary_semaphores,
420+ };
421+
422+ vkQueueSubmit (queue.Handle , 1 , &submit2, VK_NULL_HANDLE);
423+
393424 render_complete->SetState (Rendering::Primitives::SemaphoreState::Submitted);
394425
395426 VkSwapchainKHR swapchains[] = {SwapchainHandle};
396427 uint32_t frames[] = {CurrentFrame->ImageIndex };
397- VkPresentInfoKHR present_info = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .pNext = nullptr , .waitSemaphoreCount = 1 , .pWaitSemaphores = signal_semaphores , .swapchainCount = 1 , .pSwapchains = swapchains, .pImageIndices = frames};
428+ VkPresentInfoKHR present_info = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .pNext = nullptr , .waitSemaphoreCount = 1 , .pWaitSemaphores = binary_semaphores , .swapchainCount = 1 , .pSwapchains = swapchains, .pImageIndices = frames};
398429 VkResult present_result = vkQueuePresentKHR (queue.Handle , &present_info);
399430
400431 CurrentFrame->Acquired ->SetState (Rendering::Primitives::SemaphoreState::Idle);
0 commit comments