Skip to content

Commit

Permalink
MAINT: fix runtime warnings to correctly implement dynamic viewport s…
Browse files Browse the repository at this point in the history
…tates.
  • Loading branch information
oddkiva committed Dec 12, 2023
1 parent b1e4c51 commit 23f510e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cpp/examples/Shakti/Vulkan/hello_vulkan_image/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
auto h = int{};
glfwGetWindowSize(window, &w, &h);

const auto dynamic_viewport_states = std::vector<VkDynamicState>{
VK_DYNAMIC_STATE_VIEWPORT, //
VK_DYNAMIC_STATE_SCISSOR //
};

_graphics_pipeline =
VulkanImagePipelineBuilder{_device, _render_pass}
.vertex_shader_path(vertex_shader_path)
Expand All @@ -270,6 +275,7 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
.input_assembly_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.viewport_sizes(static_cast<float>(w), static_cast<float>(h))
.scissor_sizes(w, h)
.dynamic_states(dynamic_viewport_states)
.create();
}

Expand Down Expand Up @@ -894,7 +900,8 @@ class VulkanImageRenderer : public kvk::GraphicsBackend
// if (w < h)
// {
// const auto s = 2 * std::max(static_cast<float>(w) / _vstream.width(),
// static_cast<float>(h) / _vstream.height());
// static_cast<float>(h) /
// _vstream.height());
// _mvp.view.scale(s);
// }
// }
Expand Down Expand Up @@ -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, //
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions cpp/src/DO/Shakti/Vulkan/GraphicsPipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ namespace DO::Kalpana::Vulkan {
return *this;
}

auto dynamic_states(const std::vector<VkDynamicState>& 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<std::uint32_t>(_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.
Expand Down Expand Up @@ -253,6 +266,9 @@ namespace DO::Kalpana::Vulkan {
std::vector<VkPipelineColorBlendAttachmentState> color_blend_attachments;
VkPipelineColorBlendStateCreateInfo color_blend;

std::vector<VkDynamicState> _dynamic_states;
VkPipelineDynamicStateCreateInfo dynamic_state_info;

//! @brief Not sure what it is.
VkPipelineLayoutCreateInfo pipeline_layout_info;

Expand Down

0 comments on commit 23f510e

Please sign in to comment.