Fix some bugs

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2026-01-11 11:43:06 +02:00
parent 46c428b13a
commit 26edfcbe89
3 changed files with 43 additions and 3 deletions

View File

@@ -436,6 +436,7 @@ Application::Application()
Application::~Application() Application::~Application()
{ {
if (m_renderer) { if (m_renderer) {
m_renderer->device().waitIdle();
for (auto const &mesh : m_test_meshes) { for (auto const &mesh : m_test_meshes) {
m_renderer->destroy_buffer(mesh->mesh_buffers.index_buffer); m_renderer->destroy_buffer(mesh->mesh_buffers.index_buffer);
m_renderer->destroy_buffer(mesh->mesh_buffers.vertex_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); 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( m_skybox_pipeline = builder.build_graphics(
[&](GraphicsPipelineBuilder &pipeline_builder) [&](GraphicsPipelineBuilder &pipeline_builder)
-> GraphicsPipelineBuilder & { -> GraphicsPipelineBuilder & {
pipeline_builder.set_vertex_input(bindings, attributes);
return pipeline_builder return pipeline_builder
.set_shaders(skybox_vert_shader.get(), skybox_frag_shader.get()) .set_shaders(skybox_vert_shader.get(), skybox_frag_shader.get())
.set_input_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST) .set_input_topology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
@@ -522,9 +538,7 @@ auto Application::binary_directory() const -> std::filesystem::path
if (!base_path) { if (!base_path) {
return std::filesystem::current_path(); return std::filesystem::current_path();
} }
std::filesystem::path base_dir { base_path }; return std::filesystem::path { base_path };
SDL_free(const_cast<char *>(base_path));
return base_dir;
} }
auto Application::asset_directory() -> std::filesystem::path auto Application::asset_directory() -> std::filesystem::path

View File

@@ -32,6 +32,8 @@ auto GraphicsPipelineBuilder::clear() -> GraphicsPipelineBuilder &
m_render_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO; m_render_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO;
m_shader_stages.clear(); m_shader_stages.clear();
m_vertex_bindings.clear();
m_vertex_attributes.clear();
return *this; return *this;
} }
@@ -168,6 +170,17 @@ auto GraphicsPipelineBuilder::set_pipeline_layout(VkPipelineLayout layout)
return *this; return *this;
} }
auto GraphicsPipelineBuilder::set_vertex_input(
std::span<VkVertexInputBindingDescription const> bindings,
std::span<VkVertexInputAttributeDescription const> 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() auto GraphicsPipelineBuilder::disable_depth_testing()
-> GraphicsPipelineBuilder & -> GraphicsPipelineBuilder &
{ {
@@ -223,6 +236,12 @@ auto GraphicsPipelineBuilder::build(VkDevice dev) -> VkPipeline
VkPipelineVertexInputStateCreateInfo vertex_input_ci {}; VkPipelineVertexInputStateCreateInfo vertex_input_ci {};
vertex_input_ci.sType vertex_input_ci.sType
= VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO; = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertex_input_ci.vertexBindingDescriptionCount
= static_cast<uint32_t>(m_vertex_bindings.size());
vertex_input_ci.pVertexBindingDescriptions = m_vertex_bindings.data();
vertex_input_ci.vertexAttributeDescriptionCount
= static_cast<uint32_t>(m_vertex_attributes.size());
vertex_input_ci.pVertexAttributeDescriptions = m_vertex_attributes.data();
VkGraphicsPipelineCreateInfo pipeline_ci {}; VkGraphicsPipelineCreateInfo pipeline_ci {};
pipeline_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO; pipeline_ci.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;

View File

@@ -1,5 +1,6 @@
#pragma once #pragma once
#include <span>
#include <vector> #include <vector>
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
@@ -35,6 +36,10 @@ struct GraphicsPipelineBuilder {
auto set_depth_format(VkFormat format) -> GraphicsPipelineBuilder &; auto set_depth_format(VkFormat format) -> GraphicsPipelineBuilder &;
auto set_pipeline_layout(VkPipelineLayout layout) auto set_pipeline_layout(VkPipelineLayout layout)
-> GraphicsPipelineBuilder &; -> GraphicsPipelineBuilder &;
auto set_vertex_input(
std::span<VkVertexInputBindingDescription const> bindings,
std::span<VkVertexInputAttributeDescription const> attributes)
-> GraphicsPipelineBuilder &;
auto disable_depth_testing() -> GraphicsPipelineBuilder &; auto disable_depth_testing() -> GraphicsPipelineBuilder &;
auto enable_depth_testing(bool depth_write_enable = true, auto enable_depth_testing(bool depth_write_enable = true,
VkCompareOp op = VK_COMPARE_OP_LESS_OR_EQUAL) VkCompareOp op = VK_COMPARE_OP_LESS_OR_EQUAL)
@@ -52,6 +57,8 @@ private:
VkFormat m_color_attachment_format {}; VkFormat m_color_attachment_format {};
std::vector<VkPipelineShaderStageCreateInfo> m_shader_stages {}; std::vector<VkPipelineShaderStageCreateInfo> m_shader_stages {};
std::vector<VkVertexInputBindingDescription> m_vertex_bindings {};
std::vector<VkVertexInputAttributeDescription> m_vertex_attributes {};
Logger &m_logger; Logger &m_logger;
}; };