#Vulkan. One draw image for 2 frames inflight swapchain

1 messages · Page 1 of 1 (latest)

ruby ravine
#

You could include links and snippets of code to give more context. What parts of the code is your question about exactly?

red cedar
#

ofc, mb, 1 sec

#
struct FrameData {
    VkCommandPool command_pool;
    VkCommandBuffer main_command_buffer;
    VkSemaphore swapchain_semaphore, render_semaphore;
    VkFence render_fence;
    DeletionQueue deletion_queue;
    DescriptorAllocatorGrowable frame_descriptors;
};

AllocatedImage draw_image;
AllocatedImage depth_image;
FrameData frames[FRAME_OVERLAP];
FrameData& getCurrentFrame() { return frames[frame_number % FRAME_OVERLAP]; }

I'v cut some stuff that i think is irrelevant to the frame (like error checking and image transitions)

void draw() {
  vkWaitForFences(device, 1, &getCurrentFrame().render_fence, true, 1000000000);
  vkAcquireNextImageKHR(device, swapchain, 1000000000, getCurrentFrame().swapchain_semaphore, 0, &swapchainImageIndex);
  vkResetFences(device, 1, &getCurrentFrame().render_fence);

  auto cmd = getCurrentFrame().main_command_buffer;
  vkResetCommandBuffer(cmd, 0)

  auto cmdBeginInfo = vkinit::command_buffer_begin_info(
    VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
    VK_CHECK(vkBeginCommandBuffer(cmd, &cmdBeginInfo))

  // does all the render/draw
  draw_geometry(cmd);

  copy_image_to_image(cmd, draw_image.image, _images[swapchainImageIndex], draw_extent, swapchain_extent);
  
  vkEndCommandBuffer(cmd)

  auto waitInfo = semaphore_submit_info(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT_KHR, getCurrentFrame().swapchain_semaphore);
  auto signalInfo = semaphore_submit_info(VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, getCurrentFrame().render_semaphore);
  auto submit = submit_info(&cmdinfo, &signalInfo, &waitInfo);

  // _renderFence will now block until the commands finish
  VK_CHECK(vkQueueSubmit2(graphics_queue, 1, &submit, getCurrentFrame().render_fence));

  // present stuff goes here...

  frame_number++;
}
#

I understand the render_fence that is passed to vkQueueSubmit2, but that should only matter to when we try to draw on the same swapchain (which should only happen ever FRAME_OVERLAP frames, so doesn't really answer my original question

#

Also, draw_geometry is just rendering and pipeline commands (like binding pipeline, drawcalls, setting attachements and descriptor sets, etc)

// only thing relevant to this would be:
VkRenderingAttachmentInfo colorAttachment = attachment_info(draw_image.view, nullptr, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);```