From 54d0b27e4a4afab2d2a2b17b466ef16c8453beed Mon Sep 17 00:00:00 2001 From: Stephen Saunders Date: Mon, 1 Aug 2022 19:05:37 -0400 Subject: [PATCH] Fix ImGui overlay and add extension dependencies for dynamicrendering example --- base/VulkanUIOverlay.cpp | 15 ++++++++++++++- base/VulkanUIOverlay.h | 4 ++-- base/vulkanexamplebase.cpp | 2 +- examples/dynamicrendering/dynamicrendering.cpp | 6 ++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/base/VulkanUIOverlay.cpp b/base/VulkanUIOverlay.cpp index 96a6307b..df25273f 100644 --- a/base/VulkanUIOverlay.cpp +++ b/base/VulkanUIOverlay.cpp @@ -217,7 +217,7 @@ namespace vks } /** Prepare a separate pipeline for the UI overlay rendering decoupled from the main application */ - void UIOverlay::preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass) + void UIOverlay::preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass, const VkFormat colorFormat, const VkFormat depthFormat) { // Pipeline layout // Push constants for UI rendering parameters @@ -276,6 +276,19 @@ namespace vks pipelineCreateInfo.stageCount = static_cast(shaders.size()); pipelineCreateInfo.pStages = shaders.data(); pipelineCreateInfo.subpass = subpass; + +#if defined(VK_KHR_dynamic_rendering) + // SRS - if we are using dynamic rendering (i.e. renderPass null), must define color, depth and stencil attachments at pipeline create time + VkPipelineRenderingCreateInfo pipelineRenderingCreateInfo = {}; + if (renderPass == VK_NULL_HANDLE) { + pipelineRenderingCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO; + pipelineRenderingCreateInfo.colorAttachmentCount = 1; + pipelineRenderingCreateInfo.pColorAttachmentFormats = &colorFormat; + pipelineRenderingCreateInfo.depthAttachmentFormat = depthFormat; + pipelineRenderingCreateInfo.stencilAttachmentFormat = depthFormat; + pipelineCreateInfo.pNext = &pipelineRenderingCreateInfo; + } +#endif // Vertex bindings an attributes based on ImGui vertex definition std::vector vertexInputBindings = { diff --git a/base/VulkanUIOverlay.h b/base/VulkanUIOverlay.h index 7d45179b..aa222363 100644 --- a/base/VulkanUIOverlay.h +++ b/base/VulkanUIOverlay.h @@ -69,7 +69,7 @@ namespace vks UIOverlay(); ~UIOverlay(); - void preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass); + void preparePipeline(const VkPipelineCache pipelineCache, const VkRenderPass renderPass, const VkFormat colorFormat, const VkFormat depthFormat); void prepareResources(); bool update(); @@ -89,4 +89,4 @@ namespace vks bool button(const char* caption); void text(const char* formatstr, ...); }; -} \ No newline at end of file +} diff --git a/base/vulkanexamplebase.cpp b/base/vulkanexamplebase.cpp index 38d20b77..6d6b7d1b 100644 --- a/base/vulkanexamplebase.cpp +++ b/base/vulkanexamplebase.cpp @@ -217,7 +217,7 @@ void VulkanExampleBase::prepare() loadShader(getShadersPath() + "base/uioverlay.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT), }; UIOverlay.prepareResources(); - UIOverlay.preparePipeline(pipelineCache, renderPass); + UIOverlay.preparePipeline(pipelineCache, renderPass, swapChain.colorFormat, depthFormat); } } diff --git a/examples/dynamicrendering/dynamicrendering.cpp b/examples/dynamicrendering/dynamicrendering.cpp index 5c5712c6..36e3600d 100644 --- a/examples/dynamicrendering/dynamicrendering.cpp +++ b/examples/dynamicrendering/dynamicrendering.cpp @@ -42,6 +42,10 @@ public: camera.setPerspective(60.0f, (float)width / (float)height, 0.1f, 256.0f); enabledInstanceExtensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME); + enabledDeviceExtensions.push_back(VK_KHR_MAINTENANCE2_EXTENSION_NAME); + enabledDeviceExtensions.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME); + enabledDeviceExtensions.push_back(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME); + enabledDeviceExtensions.push_back(VK_KHR_DEPTH_STENCIL_RESOLVE_EXTENSION_NAME); enabledDeviceExtensions.push_back(VK_KHR_DYNAMIC_RENDERING_EXTENSION_NAME); } @@ -157,6 +161,8 @@ public: vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); model.draw(drawCmdBuffers[i], vkglTF::RenderFlags::BindImages, pipelineLayout); + + drawUI(drawCmdBuffers[i]); // End dynamic rendering vkCmdEndRenderingKHR(drawCmdBuffers[i]);