From 23f510e66afa8b7c8e7ce3e4c50fcdcbcd539671 Mon Sep 17 00:00:00 2001 From: David OK Date: Tue, 12 Dec 2023 20:22:14 +0000 Subject: [PATCH] MAINT: fix runtime warnings to correctly implement dynamic viewport states. --- .../Shakti/Vulkan/hello_vulkan_image/main.cpp | 11 +++++++++-- cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.cpp | 3 +++ cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.hpp | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp b/cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp index 546a707c1..659f6130e 100644 --- a/cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp +++ b/cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp @@ -262,6 +262,11 @@ class VulkanImageRenderer : public kvk::GraphicsBackend auto h = int{}; glfwGetWindowSize(window, &w, &h); + const auto dynamic_viewport_states = std::vector{ + VK_DYNAMIC_STATE_VIEWPORT, // + VK_DYNAMIC_STATE_SCISSOR // + }; + _graphics_pipeline = VulkanImagePipelineBuilder{_device, _render_pass} .vertex_shader_path(vertex_shader_path) @@ -270,6 +275,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend .input_assembly_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) .viewport_sizes(static_cast(w), static_cast(h)) .scissor_sizes(w, h) + .dynamic_states(dynamic_viewport_states) .create(); } @@ -894,7 +900,8 @@ class VulkanImageRenderer : public kvk::GraphicsBackend // if (w < h) // { // const auto s = 2 * std::max(static_cast(w) / _vstream.width(), - // static_cast(h) / _vstream.height()); + // static_cast(h) / + // _vstream.height()); // _mvp.view.scale(s); // } // } @@ -977,7 +984,7 @@ auto main(int argc, char** argv) -> int const auto program_dir_path = fs::absolute(fs::path(argv[0])).parent_path(); const auto video_path = fs::path(argv[1]); - static constexpr auto debug = false; + static constexpr auto debug = true; auto triangle_renderer = VulkanImageRenderer{ window, // app_name, // diff --git a/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.cpp b/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.cpp index 2779a722d..9cb302618 100644 --- a/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.cpp +++ b/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.cpp @@ -181,6 +181,9 @@ auto GraphicsPipeline::Builder::create_graphics_pipeline( pipeline_info.pMultisampleState = &multisampling; pipeline_info.pColorBlendState = &color_blend; + if (!_dynamic_states.empty()) + pipeline_info.pDynamicState = &dynamic_state_info; + pipeline_info.layout = graphics_pipeline.pipeline_layout; pipeline_info.renderPass = render_pass.handle; pipeline_info.subpass = 0; diff --git a/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.hpp b/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.hpp index 5732896c2..77207be98 100644 --- a/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.hpp +++ b/cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.hpp @@ -156,6 +156,19 @@ namespace DO::Kalpana::Vulkan { return *this; } + auto dynamic_states(const std::vector& states) -> Builder& + { + _dynamic_states = states; + dynamic_state_info = {}; + dynamic_state_info.sType = + VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO; + dynamic_state_info.dynamicStateCount = + static_cast(_dynamic_states.size()); + dynamic_state_info.pDynamicStates = _dynamic_states.data(); + + return *this; + } + // Viewport: which portion of the window? // // Here we want to render on the whole window. @@ -253,6 +266,9 @@ namespace DO::Kalpana::Vulkan { std::vector color_blend_attachments; VkPipelineColorBlendStateCreateInfo color_blend; + std::vector _dynamic_states; + VkPipelineDynamicStateCreateInfo dynamic_state_info; + //! @brief Not sure what it is. VkPipelineLayoutCreateInfo pipeline_layout_info;