|
@@ -233,77 +233,77 @@ static void CleanupVulkan()
|
|
|
|
|
|
static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
|
|
static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
|
|
{
|
|
{
|
|
- VkResult err;
|
|
|
|
|
|
+ VkResult err;
|
|
|
|
|
|
- VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore;
|
|
|
|
- err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
|
|
|
|
- check_vk_result(err);
|
|
|
|
|
|
+ VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore;
|
|
|
|
+ err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
|
|
|
|
+ check_vk_result(err);
|
|
|
|
|
|
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
|
|
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
|
|
{
|
|
{
|
|
- err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
|
|
|
|
- check_vk_result(err);
|
|
|
|
-
|
|
|
|
- err = vkResetFences(g_Device, 1, &fd->Fence);
|
|
|
|
- check_vk_result(err);
|
|
|
|
- }
|
|
|
|
- {
|
|
|
|
- err = vkResetCommandPool(g_Device, fd->CommandPool, 0);
|
|
|
|
- check_vk_result(err);
|
|
|
|
- VkCommandBufferBeginInfo info = {};
|
|
|
|
- info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
|
|
- info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
|
|
|
- err = vkBeginCommandBuffer(fd->CommandBuffer, &info);
|
|
|
|
- check_vk_result(err);
|
|
|
|
- }
|
|
|
|
- {
|
|
|
|
- VkRenderPassBeginInfo info = {};
|
|
|
|
- info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
|
|
|
- info.renderPass = wd->RenderPass;
|
|
|
|
- info.framebuffer = wd->Framebuffer[wd->FrameIndex];
|
|
|
|
- info.renderArea.extent.width = wd->Width;
|
|
|
|
- info.renderArea.extent.height = wd->Height;
|
|
|
|
- info.clearValueCount = 1;
|
|
|
|
- info.pClearValues = &wd->ClearValue;
|
|
|
|
- vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // Record Imgui Draw Data and draw funcs into command buffer
|
|
|
|
- ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
|
|
|
|
-
|
|
|
|
- // Submit command buffer
|
|
|
|
- vkCmdEndRenderPass(fd->CommandBuffer);
|
|
|
|
- {
|
|
|
|
- VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
- VkSubmitInfo info = {};
|
|
|
|
- info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
|
|
- info.waitSemaphoreCount = 1;
|
|
|
|
- info.pWaitSemaphores = &image_acquired_semaphore;
|
|
|
|
- info.pWaitDstStageMask = &wait_stage;
|
|
|
|
- info.commandBufferCount = 1;
|
|
|
|
- info.pCommandBuffers = &fd->CommandBuffer;
|
|
|
|
- info.signalSemaphoreCount = 1;
|
|
|
|
- info.pSignalSemaphores = &fd->RenderCompleteSemaphore;
|
|
|
|
-
|
|
|
|
- err = vkEndCommandBuffer(fd->CommandBuffer);
|
|
|
|
- check_vk_result(err);
|
|
|
|
- err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence);
|
|
|
|
- check_vk_result(err);
|
|
|
|
- }
|
|
|
|
|
|
+ err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
|
|
|
|
+ check_vk_result(err);
|
|
|
|
+
|
|
|
|
+ err = vkResetFences(g_Device, 1, &fd->Fence);
|
|
|
|
+ check_vk_result(err);
|
|
|
|
+ }
|
|
|
|
+ {
|
|
|
|
+ err = vkResetCommandPool(g_Device, fd->CommandPool, 0);
|
|
|
|
+ check_vk_result(err);
|
|
|
|
+ VkCommandBufferBeginInfo info = {};
|
|
|
|
+ info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
|
|
|
+ info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
|
|
|
+ err = vkBeginCommandBuffer(fd->CommandBuffer, &info);
|
|
|
|
+ check_vk_result(err);
|
|
|
|
+ }
|
|
|
|
+ {
|
|
|
|
+ VkRenderPassBeginInfo info = {};
|
|
|
|
+ info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
|
|
|
+ info.renderPass = wd->RenderPass;
|
|
|
|
+ info.framebuffer = wd->Framebuffer[wd->FrameIndex];
|
|
|
|
+ info.renderArea.extent.width = wd->Width;
|
|
|
|
+ info.renderArea.extent.height = wd->Height;
|
|
|
|
+ info.clearValueCount = 1;
|
|
|
|
+ info.pClearValues = &wd->ClearValue;
|
|
|
|
+ vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // Record Imgui Draw Data and draw funcs into command buffer
|
|
|
|
+ ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
|
|
|
|
+
|
|
|
|
+ // Submit command buffer
|
|
|
|
+ vkCmdEndRenderPass(fd->CommandBuffer);
|
|
|
|
+ {
|
|
|
|
+ VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
|
|
|
+ VkSubmitInfo info = {};
|
|
|
|
+ info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
|
|
+ info.waitSemaphoreCount = 1;
|
|
|
|
+ info.pWaitSemaphores = &image_acquired_semaphore;
|
|
|
|
+ info.pWaitDstStageMask = &wait_stage;
|
|
|
|
+ info.commandBufferCount = 1;
|
|
|
|
+ info.pCommandBuffers = &fd->CommandBuffer;
|
|
|
|
+ info.signalSemaphoreCount = 1;
|
|
|
|
+ info.pSignalSemaphores = &fd->RenderCompleteSemaphore;
|
|
|
|
+
|
|
|
|
+ err = vkEndCommandBuffer(fd->CommandBuffer);
|
|
|
|
+ check_vk_result(err);
|
|
|
|
+ err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence);
|
|
|
|
+ check_vk_result(err);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
|
|
static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
|
|
{
|
|
{
|
|
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
|
|
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
|
|
- VkPresentInfoKHR info = {};
|
|
|
|
- info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
|
|
|
- info.waitSemaphoreCount = 1;
|
|
|
|
- info.pWaitSemaphores = &fd->RenderCompleteSemaphore;
|
|
|
|
- info.swapchainCount = 1;
|
|
|
|
- info.pSwapchains = &wd->Swapchain;
|
|
|
|
- info.pImageIndices = &wd->FrameIndex;
|
|
|
|
- VkResult err = vkQueuePresentKHR(g_Queue, &info);
|
|
|
|
- check_vk_result(err);
|
|
|
|
|
|
+ VkPresentInfoKHR info = {};
|
|
|
|
+ info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
|
|
|
+ info.waitSemaphoreCount = 1;
|
|
|
|
+ info.pWaitSemaphores = &fd->RenderCompleteSemaphore;
|
|
|
|
+ info.swapchainCount = 1;
|
|
|
|
+ info.pSwapchains = &wd->Swapchain;
|
|
|
|
+ info.pImageIndices = &wd->FrameIndex;
|
|
|
|
+ VkResult err = vkQueuePresentKHR(g_Queue, &info);
|
|
|
|
+ check_vk_result(err);
|
|
}
|
|
}
|
|
|
|
|
|
static void glfw_error_callback(int error, const char* description)
|
|
static void glfw_error_callback(int error, const char* description)
|
|
@@ -315,12 +315,12 @@ static void glfw_resize_callback(GLFWwindow*, int w, int h)
|
|
{
|
|
{
|
|
g_ResizeWanted = true;
|
|
g_ResizeWanted = true;
|
|
g_ResizeWidth = w;
|
|
g_ResizeWidth = w;
|
|
- g_ResizeHeight = h;
|
|
|
|
|
|
+ g_ResizeHeight = h;
|
|
}
|
|
}
|
|
|
|
|
|
int main(int, char**)
|
|
int main(int, char**)
|
|
{
|
|
{
|
|
- // Setup window
|
|
|
|
|
|
+ // Setup window
|
|
glfwSetErrorCallback(glfw_error_callback);
|
|
glfwSetErrorCallback(glfw_error_callback);
|
|
if (!glfwInit())
|
|
if (!glfwInit())
|
|
return 1;
|
|
return 1;
|
|
@@ -433,11 +433,11 @@ int main(int, char**)
|
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
|
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
|
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
glfwPollEvents();
|
|
glfwPollEvents();
|
|
- if (g_ResizeWanted)
|
|
|
|
- {
|
|
|
|
- ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, g_ResizeWidth, g_ResizeHeight);
|
|
|
|
- g_ResizeWanted = false;
|
|
|
|
- }
|
|
|
|
|
|
+ if (g_ResizeWanted)
|
|
|
|
+ {
|
|
|
|
+ ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, g_ResizeWidth, g_ResizeHeight);
|
|
|
|
+ g_ResizeWanted = false;
|
|
|
|
+ }
|
|
|
|
|
|
// Start the Dear ImGui frame
|
|
// Start the Dear ImGui frame
|
|
ImGui_ImplVulkan_NewFrame();
|
|
ImGui_ImplVulkan_NewFrame();
|
|
@@ -484,7 +484,7 @@ int main(int, char**)
|
|
// Rendering
|
|
// Rendering
|
|
ImGui::Render();
|
|
ImGui::Render();
|
|
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
|
|
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
|
|
- FrameRender(wd);
|
|
|
|
|
|
+ FrameRender(wd);
|
|
|
|
|
|
FramePresent(wd);
|
|
FramePresent(wd);
|
|
}
|
|
}
|