diff --git a/src/Application.cpp b/src/Application.cpp index d00199d..76a42ae 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -436,6 +436,7 @@ Application::Application() Application::~Application() { if (m_renderer) { + m_renderer->device().waitIdle(); for (auto const &mesh : m_test_meshes) { m_renderer->destroy_buffer(mesh->mesh_buffers.index_buffer); m_renderer->destroy_buffer(mesh->mesh_buffers.vertex_buffer); @@ -496,9 +497,24 @@ auto Application::init_skybox_pipeline() -> void }; builder.set_descriptor_set_layouts(descriptor_set_layouts); + VkVertexInputBindingDescription binding {}; + binding.binding = 0; + binding.stride = sizeof(smath::Vec3); + binding.inputRate = VK_VERTEX_INPUT_RATE_VERTEX; + + VkVertexInputAttributeDescription attribute {}; + attribute.location = 0; + attribute.binding = 0; + attribute.format = VK_FORMAT_R32G32B32_SFLOAT; + attribute.offset = 0; + + std::array bindings { binding }; + std::array attributes { attribute }; + m_skybox_pipeline = builder.build_graphics( [&](GraphicsPipelineBuilder &pipeline_builder) -> GraphicsPipelineBuilder & { + pipeline_builder.set_vertex_input(bindings, attributes); return pipeline_builder .set_shaders(skybox_vert_shader.get(), skybox_frag_shader.get()) .set_input_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) @@ -522,9 +538,7 @@ auto Application::binary_directory() const -> std::filesystem::path if (!base_path) { return std::filesystem::current_path(); } - std::filesystem::path base_dir { base_path }; - SDL_free(const_cast(base_path)); - return base_dir; + return std::filesystem::path { base_path }; } auto Application::asset_directory() -> std::filesystem::path diff --git a/src/GraphicsPipelineBuilder.cpp b/src/GraphicsPipelineBuilder.cpp index 8adccff..a841f58 100644 --- a/src/GraphicsPipelineBuilder.cpp +++ b/src/GraphicsPipelineBuilder.cpp @@ -32,6 +32,8 @@ auto GraphicsPipelineBuilder::clear() -> GraphicsPipelineBuilder & m_render_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO; m_shader_stages.clear(); + m_vertex_bindings.clear(); + m_vertex_attributes.clear(); return *this; } @@ -168,6 +170,17 @@ auto GraphicsPipelineBuilder::set_pipeline_layout(VkPipelineLayout layout) return *this; } +auto GraphicsPipelineBuilder::set_vertex_input( + std::span bindings, + std::span attributes) + -> GraphicsPipelineBuilder & +{ + m_vertex_bindings.assign(bindings.begin(), bindings.end()); + m_vertex_attributes.assign(attributes.begin(), attributes.end()); + + return *this; +} + auto GraphicsPipelineBuilder::disable_depth_testing() -> GraphicsPipelineBuilder & { @@ -223,6 +236,12 @@ auto GraphicsPipelineBuilder::build(VkDevice dev) -> VkPipeline VkPipelineVertexInputStateCreateInfo vertex_input_ci {}; vertex_input_ci.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; + vertex_input_ci.vertexBindingDescriptionCount + = static_cast(m_vertex_bindings.size()); + vertex_input_ci.pVertexBindingDescriptions = m_vertex_bindings.data(); + vertex_input_ci.vertexAttributeDescriptionCount + = static_cast(m_vertex_attributes.size()); + vertex_input_ci.pVertexAttributeDescriptions = m_vertex_attributes.data(); VkGraphicsPipelineCreateInfo pipeline_ci {}; pipeline_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; diff --git a/src/GraphicsPipelineBuilder.h b/src/GraphicsPipelineBuilder.h index d788856..c6ed2ad 100644 --- a/src/GraphicsPipelineBuilder.h +++ b/src/GraphicsPipelineBuilder.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -35,6 +36,10 @@ struct GraphicsPipelineBuilder { auto set_depth_format(VkFormat format) -> GraphicsPipelineBuilder &; auto set_pipeline_layout(VkPipelineLayout layout) -> GraphicsPipelineBuilder &; + auto set_vertex_input( + std::span bindings, + std::span attributes) + -> GraphicsPipelineBuilder &; auto disable_depth_testing() -> GraphicsPipelineBuilder &; auto enable_depth_testing(bool depth_write_enable = true, VkCompareOp op = VK_COMPARE_OP_LESS_OR_EQUAL) @@ -52,6 +57,8 @@ private: VkFormat m_color_attachment_format {}; std::vector m_shader_stages {}; + std::vector m_vertex_bindings {}; + std::vector m_vertex_attributes {}; Logger &m_logger; };