More draw cleanup

main
noah metz 2024-10-29 00:31:22 -06:00
parent c2d46d328b
commit f09b09aff9
1 changed files with 19 additions and 34 deletions

@ -83,26 +83,23 @@ VkResult draw_frame(
frame->transfer_infos[tid].size);
src_offset += frame->transfer_infos[tid].size;
}
VK_RESULT(vkEndCommandBuffer(transfer_commands));
VkPipelineStageFlags wait_stages[] = {VK_PIPELINE_STAGE_TRANSFER_BIT};
VkSemaphore transfer_signals[] = {frame->transfer};
VkSemaphore transfer_waits[] = {frame->frame};
uint64_t transfer_wait_values[] = {frame->frame_index};
VkTimelineSemaphoreSubmitInfo timeline_info = {
.sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
.waitSemaphoreValueCount = sizeof(transfer_wait_values)/sizeof(uint64_t),
.pWaitSemaphoreValues = transfer_wait_values,
.waitSemaphoreValueCount = 1,
.pWaitSemaphoreValues = &frame->frame_index,
};
VkSubmitInfo submit_info = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.commandBufferCount = 1,
.pCommandBuffers = &transfer_commands,
.pSignalSemaphores = transfer_signals,
.signalSemaphoreCount = sizeof(transfer_signals)/sizeof(VkSemaphore),
.pWaitSemaphores = transfer_waits,
.pSignalSemaphores = &frame->transfer,
.signalSemaphoreCount = 1,
.pWaitSemaphores = &frame->frame,
.pWaitDstStageMask = wait_stages,
.waitSemaphoreCount = sizeof(transfer_waits)/sizeof(VkSemaphore),
.waitSemaphoreCount = 1,
.pNext = &timeline_info,
};
VK_RESULT(vkQueueSubmit(context->transfer_queue.handle, 1, &submit_info, VK_NULL_HANDLE));
@ -115,35 +112,30 @@ VkResult draw_frame(
VK_RESULT(vkBeginCommandBuffer(compute_commands, &begin_info));
record_ui_compute(compute_commands, ui, context->current_frame);
VK_RESULT(vkEndCommandBuffer(compute_commands));
VkPipelineStageFlags compute_wait_stages[] = {VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT};
frame->compute_index += 1;
VkSemaphore compute_signals[] = {frame->compute};
uint64_t compute_signal_values[] = {frame->compute_index};
VkSemaphore compute_waits[] = {frame->transfer};
VkPipelineStageFlags compute_wait_stages[] = {VK_PIPELINE_STAGE_TRANSFER_BIT | VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT};
VkTimelineSemaphoreSubmitInfo compute_timeline = {
.sType = VK_STRUCTURE_TYPE_TIMELINE_SEMAPHORE_SUBMIT_INFO,
.signalSemaphoreValueCount = sizeof(compute_signal_values)/sizeof(uint64_t),
.pSignalSemaphoreValues = compute_signal_values,
.signalSemaphoreValueCount = 1,
.pSignalSemaphoreValues = &frame->compute_index,
};
VkSubmitInfo compute_submit = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
.commandBufferCount = 1,
.pCommandBuffers = &compute_commands,
.pSignalSemaphores = compute_signals,
.signalSemaphoreCount = sizeof(compute_signals)/sizeof(VkSemaphore),
.pWaitSemaphores = compute_waits,
.pSignalSemaphores = &frame->compute,
.signalSemaphoreCount = 1,
.pWaitSemaphores = &frame->transfer,
.pWaitDstStageMask = compute_wait_stages,
.waitSemaphoreCount = sizeof(compute_waits)/sizeof(VkSemaphore),
.waitSemaphoreCount = 1,
.pNext = &compute_timeline,
};
VK_RESULT(vkQueueSubmit(context->transfer_queue.handle, 1, &compute_submit, VK_NULL_HANDLE));
}
uint32_t image_index;
result = vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, frame->image, VK_NULL_HANDLE, &image_index);
if(result != VK_SUCCESS) {
return result;
}
VK_RESULT(vkAcquireNextImageKHR(context->device, context->swapchain, UINT64_MAX, frame->image, VK_NULL_HANDLE, &image_index));
VkCommandBuffer command_buffer = context->swapchain_command_buffers[image_index];
VK_RESULT(vkResetCommandBuffer(command_buffer, 0));
@ -178,13 +170,12 @@ VkResult draw_frame(
vkCmdNextSubpass(command_buffer, VK_SUBPASS_CONTENTS_INLINE);
record_ui_draw(command_buffer, ui, time, context->current_frame);
vkCmdEndRenderPass(command_buffer);
VK_RESULT(vkEndCommandBuffer(command_buffer));
frame->frame_index += 1;
VkPipelineStageFlags wait_stages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT};
VkSemaphore wait_semaphores[] = {frame->image, frame->compute};
VkSemaphore signal_semaphores[] = {frame->render, frame->frame};
frame->frame_index += 1;
uint64_t wait_values[] = {0, frame->compute_index};
uint64_t signal_values[] = {0, frame->frame_index};
VkTimelineSemaphoreSubmitInfo timeline_info = {
@ -206,10 +197,7 @@ VkResult draw_frame(
.pNext = &timeline_info,
};
result = vkQueueSubmit(context->graphics_queue.handle, 1, &submit_info, frame->ready);
if(result != VK_SUCCESS) {
return result;
}
VK_RESULT(vkQueueSubmit(context->graphics_queue.handle, 1, &submit_info, frame->ready));
VkPresentInfoKHR present_info = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
@ -221,10 +209,7 @@ VkResult draw_frame(
.pResults = 0,
};
result = vkQueuePresentKHR(context->present_queue.handle, &present_info);
if(result != VK_SUCCESS) {
return result;
}
VK_RESULT(vkQueuePresentKHR(context->present_queue.handle, &present_info));
context->current_frame = (context->current_frame + 1) % MAX_FRAMES_IN_FLIGHT;