~sircmpwn/xrgears

9a78836d512f9b58deef241bc7813a9a2630f2f2 — Lubosz Sarnecki 4 years ago 2c517d1
vks: renderer: don't store submit info as member.
2 files changed, 38 insertions(+), 42 deletions(-)

M examples/xrgears/xrgears.cpp
M vitamin-k/render/vikRendererVks.hpp
M examples/xrgears/xrgears.cpp => examples/xrgears/xrgears.cpp +9 -9
@@ 620,7 620,7 @@ public:
  void draw() {
    renderer->prepare_frame();

    renderer->submitInfo.commandBufferCount = 1;
    VkSubmitInfo submit_info = renderer->init_render_submit_info();

    if (enableDistortion) {
      // The scene render command buffer has to wait for the offscreen


@@ 637,26 637,26 @@ public:
      // Offscreen rendering

      // Wait for swap chain presentation to finish
      renderer->submitInfo.pWaitSemaphores = &renderer->semaphores.presentComplete;
      submit_info.pWaitSemaphores = &renderer->semaphores.presentComplete;
      // Signal ready with offscreen semaphore
      renderer->submitInfo.pSignalSemaphores = &offscreenSemaphore;
      submit_info.pSignalSemaphores = &offscreenSemaphore;

      // Submit work

      renderer->submitInfo.pCommandBuffers = &offScreenCmdBuffer;
      vik_log_check(vkQueueSubmit(renderer->queue, 1, &renderer->submitInfo, VK_NULL_HANDLE));
      submit_info.pCommandBuffers = &offScreenCmdBuffer;
      vik_log_check(vkQueueSubmit(renderer->queue, 1, &submit_info, VK_NULL_HANDLE));

      // Scene rendering

      // Wait for offscreen semaphore
      renderer->submitInfo.pWaitSemaphores = &offscreenSemaphore;
      submit_info.pWaitSemaphores = &offscreenSemaphore;
      // Signal ready with render complete semaphpre
      renderer->submitInfo.pSignalSemaphores = &renderer->semaphores.renderComplete;
      submit_info.pSignalSemaphores = &renderer->semaphores.renderComplete;
    }

    // Submit to queue
    renderer->submitInfo.pCommandBuffers = &renderer->drawCmdBuffers[renderer->currentBuffer];
    vik_log_check(vkQueueSubmit(renderer->queue, 1, &renderer->submitInfo, VK_NULL_HANDLE));
    submit_info.pCommandBuffers = renderer->get_current_command_buffer();
    vik_log_check(vkQueueSubmit(renderer->queue, 1, &submit_info, VK_NULL_HANDLE));
    renderer->submit_frame();
  }


M vitamin-k/render/vikRendererVks.hpp => vitamin-k/render/vikRendererVks.hpp +29 -33
@@ 31,7 31,7 @@ public:
  VkFormat depthFormat;
  VkCommandPool cmdPool;
  VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
  VkSubmitInfo submitInfo;
  //VkSubmitInfo submitInfo;
  VkDescriptorPool descriptorPool = VK_NULL_HANDLE;
  VkPipelineCache pipelineCache;



@@ 405,16 405,6 @@ public:
    // Ensures that the image is not presented until all commands for the text overlay have been sumbitted and executed
    // Will be inserted after the render complete semaphore if the text overlay is enabled
    vik_log_check(vkCreateSemaphore(device, &semaphoreCreateInfo, nullptr, &semaphores.textOverlayComplete));

    // Set up submit info structure
    // Semaphores will stay the same during application lifetime
    // Command buffer submission info is set by each example
    submitInfo = initializers::submitInfo();
    submitInfo.pWaitDstStageMask = &submitPipelineStages;
    submitInfo.waitSemaphoreCount = 1;
    submitInfo.pWaitSemaphores = &semaphores.presentComplete;
    submitInfo.signalSemaphoreCount = 1;
    submitInfo.pSignalSemaphores = &semaphores.renderComplete;
  }

  void create_command_pool() {


@@ 478,33 468,39 @@ public:
    create_command_buffers();
  }

  void submit_text_overlay() {
  VkSubmitInfo submit_text_overlay() {
    VkSubmitInfo submit_info = init_text_submit_info();
    submit_info.pCommandBuffers = &textOverlay->cmdBuffers[currentBuffer];
    vik_log_check(vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE));
  }

  VkSubmitInfo init_text_submit_info() {
    // Wait for color attachment output to finish before rendering the text overlay
    VkPipelineStageFlags stageFlags = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
    submitInfo.pWaitDstStageMask = &stageFlags;

    // Set semaphores
    // Wait for render complete semaphore
    submitInfo.waitSemaphoreCount = 1;
    submitInfo.pWaitSemaphores = &semaphores.renderComplete;
    // Signal ready with text overlay complete semaphpre
    submitInfo.signalSemaphoreCount = 1;
    submitInfo.pSignalSemaphores = &semaphores.textOverlayComplete;
    VkSubmitInfo submit_info = initializers::submitInfo();
    submit_info.pWaitDstStageMask = &stageFlags;
    submit_info.waitSemaphoreCount = 1;
    submit_info.pWaitSemaphores = &semaphores.renderComplete;
    submit_info.signalSemaphoreCount = 1;
    submit_info.pSignalSemaphores = &semaphores.textOverlayComplete;
    submit_info.commandBufferCount = 1;
    return submit_info;
  }

    // Submit current text overlay command buffer
    submitInfo.commandBufferCount = 1;
    submitInfo.pCommandBuffers = &textOverlay->cmdBuffers[currentBuffer];
    vik_log_check(vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE));
  VkSubmitInfo init_render_submit_info() {
    VkSubmitInfo submit_info = initializers::submitInfo();
    submit_info.pWaitDstStageMask = &submitPipelineStages;
    submit_info.waitSemaphoreCount = 1;
    submit_info.pWaitSemaphores = &semaphores.presentComplete;
    submit_info.signalSemaphoreCount = 1;
    submit_info.pSignalSemaphores = &semaphores.renderComplete;
    submit_info.commandBufferCount = 1;
    return submit_info;
  }

    // Reset stage mask
    submitInfo.pWaitDstStageMask = &submitPipelineStages;
    // Reset wait and signal semaphores for rendering next frame
    // Wait for swap chain presentation to finish
    submitInfo.waitSemaphoreCount = 1;
    submitInfo.pWaitSemaphores = &semaphores.presentComplete;
    // Signal ready with offscreen semaphore
    submitInfo.signalSemaphoreCount = 1;
    submitInfo.pSignalSemaphores = &semaphores.renderComplete;
  VkCommandBuffer* get_current_command_buffer() {
    return &drawCmdBuffers[currentBuffer];
  }

  void create_frame_buffers() {