From 2341508e273edb98ddd13081f92cf7bcf3029ed3 Mon Sep 17 00:00:00 2001 From: Nathan Seymour Date: Fri, 22 Nov 2024 12:33:21 -0600 Subject: [PATCH] split pipeline into own component; --- CMakeLists.txt | 6 +- src/calculator/renderer/VulkanPipeline.cpp | 218 +++++++++++++++++ src/calculator/renderer/VulkanPipeline.h | 28 +++ src/calculator/renderer/VulkanRenderer.cpp | 220 +----------------- src/calculator/renderer/VulkanRenderer.h | 18 +- .../shaders/{graph.frag => grid.frag} | 0 .../shaders/{graph.vert => grid.vert} | 0 7 files changed, 266 insertions(+), 224 deletions(-) create mode 100644 src/calculator/renderer/VulkanPipeline.cpp create mode 100644 src/calculator/renderer/VulkanPipeline.h rename src/calculator/resource/shaders/{graph.frag => grid.frag} (100%) rename src/calculator/resource/shaders/{graph.vert => grid.vert} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index accc3ef..0cc55fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,8 @@ qt_add_executable(unlogic-calculator src/calculator/renderer/VulkanVertexBuffer.h src/calculator/resource/shaders/plot.frag src/calculator/resource/shaders/plot.vert + src/calculator/renderer/VulkanPipeline.cpp + src/calculator/renderer/VulkanPipeline.h ) qt_add_shaders(unlogic-calculator "shaders" NOGLSL @@ -93,8 +95,8 @@ qt_add_shaders(unlogic-calculator "shaders" FILES src/calculator/resource/shaders/plot.frag src/calculator/resource/shaders/plot.vert - src/calculator/resource/shaders/graph.frag - src/calculator/resource/shaders/graph.vert + src/calculator/resource/shaders/grid.frag + src/calculator/resource/shaders/grid.vert ) qt_add_resources(unlogic-calculator "fonts" PREFIX "/fonts" diff --git a/src/calculator/renderer/VulkanPipeline.cpp b/src/calculator/renderer/VulkanPipeline.cpp new file mode 100644 index 0000000..dafe66d --- /dev/null +++ b/src/calculator/renderer/VulkanPipeline.cpp @@ -0,0 +1,218 @@ +#include +#include +#include "VulkanPipeline.h" +#include "graphic/ugl/Vertex.h" + +VkShaderModule ui::VulkanPipeline::loadShader(char const *path) +{ + QFile shader_file(path); + if(!shader_file.open(QIODevice::ReadOnly)) + { + throw std::runtime_error("failed to open vertex shader"); + } + + QByteArray shader_data = shader_file.readAll(); + QShader shader = QShader::fromSerialized(shader_data); + QShaderKey shader_key = std::invoke([&]() { + for(auto const &key : shader.availableShaders()) + { + if(key.source() == QShader::Source::SpirvShader) + { + return key; + } + } + + throw std::runtime_error("shader does not contain SPIR-V source"); + }); + QShaderCode shader_code = shader.shader(shader_key); + + VkShaderModuleCreateInfo create_info { + .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, + .codeSize = (std::size_t)shader_code.shader().size(), + .pCode = reinterpret_cast(shader_code.shader().constData()), + }; + + VkShaderModule module; + if(this->dev_->vkCreateShaderModule(this->window_->device(), &create_info, nullptr, &module) != VK_SUCCESS) + { + throw std::runtime_error("failed to compile shader module"); + } + + return module; +} + +ui::VulkanPipeline::VulkanPipeline(QVulkanWindow *window, const char *vert, const char *frag) : window_(window) +{ + this->dev_ = this->window_->vulkanInstance()->deviceFunctions(this->window_->device()); + + VkShaderModule vert_shader = this->loadShader(vert); + VkShaderModule frag_shader = this->loadShader(frag); + + VkPipelineShaderStageCreateInfo vert_shader_stage_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .stage = VK_SHADER_STAGE_VERTEX_BIT, + .module = vert_shader, + .pName = "main", + }; + + VkPipelineShaderStageCreateInfo frag_shader_stage_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, + .stage = VK_SHADER_STAGE_FRAGMENT_BIT, + .module = frag_shader, + .pName = "main", + }; + + std::array shader_stages = {vert_shader_stage_info, frag_shader_stage_info}; + + VkVertexInputBindingDescription vertex_input_binding_description { + .binding = 0, + .stride = sizeof(unlogic::Vertex), + .inputRate = VK_VERTEX_INPUT_RATE_VERTEX, + }; + + std::array vertex_attribute_descriptions = { + VkVertexInputAttributeDescription { + .location = 0, + .binding = 0, + .format = VK_FORMAT_R32G32_SFLOAT, + .offset = offsetof(unlogic::Vertex, position), + }, + VkVertexInputAttributeDescription { + .location = 1, + .binding = 0, + .format = VK_FORMAT_R32G32B32A32_SFLOAT, + .offset = offsetof(unlogic::Vertex, color), + }, + }; + + VkPipelineVertexInputStateCreateInfo vertex_input_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, + .vertexBindingDescriptionCount = 1, + .pVertexBindingDescriptions = &vertex_input_binding_description, + .vertexAttributeDescriptionCount = vertex_attribute_descriptions.size(), + .pVertexAttributeDescriptions = vertex_attribute_descriptions.data(), + }; + + VkPipelineInputAssemblyStateCreateInfo input_assembly_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, + .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, + .primitiveRestartEnable = VK_FALSE, + }; + + std::array dynamic_states = { + VK_DYNAMIC_STATE_VIEWPORT, + VK_DYNAMIC_STATE_SCISSOR, + }; + + VkPipelineDynamicStateCreateInfo dynamic_state_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, + .dynamicStateCount = dynamic_states.size(), + .pDynamicStates = dynamic_states.data(), + }; + + VkPipelineViewportStateCreateInfo viewport_state_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, + .viewportCount = 1, + .scissorCount = 1, + }; + + VkPipelineRasterizationStateCreateInfo rasterization_state_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, + .depthClampEnable = VK_FALSE, + .rasterizerDiscardEnable = VK_FALSE, + .polygonMode = VK_POLYGON_MODE_FILL, + .cullMode = VK_CULL_MODE_BACK_BIT, + .frontFace = VK_FRONT_FACE_CLOCKWISE, + .depthBiasEnable = VK_FALSE, + .depthBiasConstantFactor = 0.f, + .depthBiasClamp = 0.f, + .depthBiasSlopeFactor = 0.f, + .lineWidth = 1.f, + }; + + VkPipelineMultisampleStateCreateInfo multisample_state_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, + .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, + .sampleShadingEnable = VK_FALSE, + .minSampleShading = 1.0f, + .pSampleMask = nullptr, + .alphaToCoverageEnable = VK_FALSE, + .alphaToOneEnable = VK_FALSE, + }; + + VkPipelineColorBlendAttachmentState color_blend_attachment_state { + .blendEnable = VK_FALSE, + .srcColorBlendFactor = VK_BLEND_FACTOR_ONE, + .dstColorBlendFactor = VK_BLEND_FACTOR_ZERO, + .colorBlendOp = VK_BLEND_OP_ADD, + .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE, + .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, + .alphaBlendOp = VK_BLEND_OP_ADD, + .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, + }; + + VkPipelineColorBlendStateCreateInfo color_blend_state_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, + .logicOpEnable = VK_FALSE, + .logicOp = VK_LOGIC_OP_COPY, + .attachmentCount = 1, + .pAttachments = &color_blend_attachment_state, + .blendConstants = { 0.f, 0.f, 0.f, 0.f }, + }; + + VkPipelineLayoutCreateInfo pipeline_layout_info { + .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, + .setLayoutCount = 0, + .pSetLayouts = nullptr, + .pushConstantRangeCount = 0, + .pPushConstantRanges = nullptr, + }; + + if(this->dev_->vkCreatePipelineLayout(this->window_->device(), &pipeline_layout_info, nullptr, &this->pipeline_layout_) != VK_SUCCESS) + { + throw std::runtime_error("failed to create pipeline layout"); + } + + VkGraphicsPipelineCreateInfo pipeline_info { + .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, + .stageCount = shader_stages.size(), + .pStages = shader_stages.data(), + .pVertexInputState = &vertex_input_info, + .pInputAssemblyState = &input_assembly_info, + .pViewportState = &viewport_state_info, + .pRasterizationState = &rasterization_state_info, + .pMultisampleState = &multisample_state_info, + .pDepthStencilState = nullptr, + .pColorBlendState = &color_blend_state_info, + .pDynamicState = &dynamic_state_info, + .layout = this->pipeline_layout_, + .renderPass = this->window_->defaultRenderPass(), + .subpass = 0, + .basePipelineHandle = VK_NULL_HANDLE, + .basePipelineIndex = -1, + }; + + if(this->dev_->vkCreateGraphicsPipelines(this->window_->device(), VK_NULL_HANDLE, 1, &pipeline_info, nullptr, &this->pipeline_) != VK_SUCCESS) + { + throw std::runtime_error("failed to create pipeline"); + } + + this->dev_->vkDestroyShaderModule(this->window_->device(), vert_shader, nullptr); + this->dev_->vkDestroyShaderModule(this->window_->device(), frag_shader, nullptr); +} + +void ui::VulkanPipeline::Destroy() +{ + this->dev_->vkDestroyPipeline(this->window_->device(), this->pipeline_, nullptr); + this->dev_->vkDestroyPipelineLayout(this->window_->device(), this->pipeline_layout_, nullptr); +} + +ui::VulkanPipeline::~VulkanPipeline() +{ + this->Destroy(); +} + +VkPipeline ui::VulkanPipeline::NativeHandle() +{ + return this->pipeline_; +} diff --git a/src/calculator/renderer/VulkanPipeline.h b/src/calculator/renderer/VulkanPipeline.h new file mode 100644 index 0000000..f2db5b4 --- /dev/null +++ b/src/calculator/renderer/VulkanPipeline.h @@ -0,0 +1,28 @@ +#ifndef UNLOGIC_VULKANPIPELINE_H +#define UNLOGIC_VULKANPIPELINE_H + +#include +#include + +namespace ui +{ + class VulkanPipeline + { + QVulkanWindow *window_; + QVulkanDeviceFunctions *dev_; + + VkPipelineLayout pipeline_layout_ = nullptr; + VkPipeline pipeline_ = nullptr; + + public: + VkShaderModule loadShader(char const *path); + VkPipeline NativeHandle(); + + void Destroy(); + + VulkanPipeline(QVulkanWindow *window, char const *vert, char const *frag); + ~VulkanPipeline(); + }; +} + +#endif //UNLOGIC_VULKANPIPELINE_H diff --git a/src/calculator/renderer/VulkanRenderer.cpp b/src/calculator/renderer/VulkanRenderer.cpp index c511bb0..f2557ef 100644 --- a/src/calculator/renderer/VulkanRenderer.cpp +++ b/src/calculator/renderer/VulkanRenderer.cpp @@ -1,176 +1,16 @@ #include -#include -#include #include "VulkanRenderer.h" #include "VulkanWindow.h" #include "graphic/ugl/Vertex.h" using namespace ui; -void VulkanRenderer::createStandardPipeline(VkPipeline &pipeline, VkPipelineLayout &layout, const char *vert_shader_path, const char *frag_shader_path) -{ - VkShaderModule vert_shader = this->loadShader(vert_shader_path); - VkShaderModule frag_shader = this->loadShader(frag_shader_path); - - VkPipelineShaderStageCreateInfo vert_shader_stage_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, - .stage = VK_SHADER_STAGE_VERTEX_BIT, - .module = vert_shader, - .pName = "main", - }; - - VkPipelineShaderStageCreateInfo frag_shader_stage_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO, - .stage = VK_SHADER_STAGE_FRAGMENT_BIT, - .module = frag_shader, - .pName = "main", - }; - - std::array shader_stages = {vert_shader_stage_info, frag_shader_stage_info}; - - VkVertexInputBindingDescription vertex_input_binding_description { - .binding = 0, - .stride = sizeof(unlogic::Vertex), - .inputRate = VK_VERTEX_INPUT_RATE_VERTEX, - }; - - std::array vertex_attribute_descriptions = { - VkVertexInputAttributeDescription { - .location = 0, - .binding = 0, - .format = VK_FORMAT_R32G32_SFLOAT, - .offset = offsetof(unlogic::Vertex, position), - }, - VkVertexInputAttributeDescription { - .location = 1, - .binding = 0, - .format = VK_FORMAT_R32G32B32A32_SFLOAT, - .offset = offsetof(unlogic::Vertex, color), - }, - }; - - VkPipelineVertexInputStateCreateInfo vertex_input_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO, - .vertexBindingDescriptionCount = 1, - .pVertexBindingDescriptions = &vertex_input_binding_description, - .vertexAttributeDescriptionCount = vertex_attribute_descriptions.size(), - .pVertexAttributeDescriptions = vertex_attribute_descriptions.data(), - }; - - VkPipelineInputAssemblyStateCreateInfo input_assembly_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO, - .topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, - .primitiveRestartEnable = VK_FALSE, - }; - - std::array dynamic_states = { - VK_DYNAMIC_STATE_VIEWPORT, - VK_DYNAMIC_STATE_SCISSOR, - }; - - VkPipelineDynamicStateCreateInfo dynamic_state_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO, - .dynamicStateCount = dynamic_states.size(), - .pDynamicStates = dynamic_states.data(), - }; - - VkPipelineViewportStateCreateInfo viewport_state_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO, - .viewportCount = 1, - .scissorCount = 1, - }; - - VkPipelineRasterizationStateCreateInfo rasterization_state_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO, - .depthClampEnable = VK_FALSE, - .rasterizerDiscardEnable = VK_FALSE, - .polygonMode = VK_POLYGON_MODE_FILL, - .cullMode = VK_CULL_MODE_BACK_BIT, - .frontFace = VK_FRONT_FACE_CLOCKWISE, - .depthBiasEnable = VK_FALSE, - .depthBiasConstantFactor = 0.f, - .depthBiasClamp = 0.f, - .depthBiasSlopeFactor = 0.f, - .lineWidth = 1.f, - }; - - VkPipelineMultisampleStateCreateInfo multisample_state_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO, - .rasterizationSamples = VK_SAMPLE_COUNT_1_BIT, - .sampleShadingEnable = VK_FALSE, - .minSampleShading = 1.0f, - .pSampleMask = nullptr, - .alphaToCoverageEnable = VK_FALSE, - .alphaToOneEnable = VK_FALSE, - }; - - VkPipelineColorBlendAttachmentState color_blend_attachment_state { - .blendEnable = VK_FALSE, - .srcColorBlendFactor = VK_BLEND_FACTOR_ONE, - .dstColorBlendFactor = VK_BLEND_FACTOR_ZERO, - .colorBlendOp = VK_BLEND_OP_ADD, - .srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE, - .dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO, - .alphaBlendOp = VK_BLEND_OP_ADD, - .colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT, - }; - - VkPipelineColorBlendStateCreateInfo color_blend_state_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO, - .logicOpEnable = VK_FALSE, - .logicOp = VK_LOGIC_OP_COPY, - .attachmentCount = 1, - .pAttachments = &color_blend_attachment_state, - .blendConstants = { 0.f, 0.f, 0.f, 0.f }, - }; - - VkPipelineLayoutCreateInfo pipeline_layout_info { - .sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO, - .setLayoutCount = 0, - .pSetLayouts = nullptr, - .pushConstantRangeCount = 0, - .pPushConstantRanges = nullptr, - }; - - if(this->dev_->vkCreatePipelineLayout(this->window_->device(), &pipeline_layout_info, nullptr, &layout) != VK_SUCCESS) - { - throw std::runtime_error("failed to create pipeline layout"); - } - - VkGraphicsPipelineCreateInfo pipeline_info { - .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO, - .stageCount = shader_stages.size(), - .pStages = shader_stages.data(), - .pVertexInputState = &vertex_input_info, - .pInputAssemblyState = &input_assembly_info, - .pViewportState = &viewport_state_info, - .pRasterizationState = &rasterization_state_info, - .pMultisampleState = &multisample_state_info, - .pDepthStencilState = nullptr, - .pColorBlendState = &color_blend_state_info, - .pDynamicState = &dynamic_state_info, - .layout = layout, - .renderPass = this->window_->defaultRenderPass(), - .subpass = 0, - .basePipelineHandle = VK_NULL_HANDLE, - .basePipelineIndex = -1, - }; - - if(this->dev_->vkCreateGraphicsPipelines(this->window_->device(), VK_NULL_HANDLE, 1, &pipeline_info, nullptr, &pipeline) != VK_SUCCESS) - { - throw std::runtime_error("failed to create pipeline"); - } - - this->dev_->vkDestroyShaderModule(this->window_->device(), vert_shader, nullptr); - this->dev_->vkDestroyShaderModule(this->window_->device(), frag_shader, nullptr); -} - void VulkanRenderer::initResources() { this->dev_ = this->window_->vulkanInstance()->deviceFunctions(this->window_->device()); - this->createStandardPipeline(this->plot_pipeline_, this->plot_pipeline_layout_, ":/shaders/plot.vert.qsb", ":/shaders/plot.frag.qsb"); - this->createStandardPipeline(this->graph_pipeline_, this->graph_pipeline_layout_, ":/shaders/graph.vert.qsb", ":/shaders/graph.frag.qsb"); + this->grid_pipeline_ = std::make_unique(this->window_, ":/shaders/grid.vert.qsb", ":/shaders/grid.frag.qsb"); + this->plot_pipeline_ = std::make_unique(this->window_, ":/shaders/plot.vert.qsb", ":/shaders/plot.frag.qsb"); std::array corners = { glm::vec2 { -1.f, -1.f }, @@ -178,18 +18,16 @@ void VulkanRenderer::initResources() glm::vec2 { 1.f, 1.f }, glm::vec2 { -1.f, 1.f }, }; - this->gridlines_ = this->window_->scene->Rect(corners, unlogic::Color::Green); + + this->grid_ = this->window_->scene->Rect(corners, unlogic::Color::Green); } void VulkanRenderer::releaseResources() { - this->gridlines_->Release(); + this->grid_->Release(); - this->dev_->vkDestroyPipeline(this->window_->device(), this->plot_pipeline_, nullptr); - this->dev_->vkDestroyPipelineLayout(this->window_->device(), this->plot_pipeline_layout_, nullptr); - - this->dev_->vkDestroyPipeline(this->window_->device(), this->graph_pipeline_, nullptr); - this->dev_->vkDestroyPipelineLayout(this->window_->device(), this->graph_pipeline_layout_, nullptr); + this->grid_pipeline_.reset(); + this->plot_pipeline_.reset(); } void VulkanRenderer::startNextFrame() @@ -252,7 +90,7 @@ void VulkanRenderer::startNextFrame() // Commence drawing scene if(this->window_->scene->draw_gridlines) { - this->drawVertexBuffer(this->gridlines_.get(), this->graph_pipeline_); + this->drawVertexBuffer(this->grid_.get(), *this->grid_pipeline_); } this->dev_->vkCmdEndRenderPass(cmd); @@ -261,48 +99,10 @@ void VulkanRenderer::startNextFrame() this->window_->requestUpdate(); // render continuously, throttled by the presentation rate } -VkShaderModule VulkanRenderer::loadShader(std::string_view path) -{ - QFile shader_file(path.data()); - if(!shader_file.open(QIODevice::ReadOnly)) - { - throw std::runtime_error("failed to open vertex shader"); - } - - QByteArray shader_data = shader_file.readAll(); - QShader shader = QShader::fromSerialized(shader_data); - QShaderKey shader_key = std::invoke([&]() { - for(auto const &key : shader.availableShaders()) - { - if(key.source() == QShader::Source::SpirvShader) - { - return key; - } - } - - throw std::runtime_error("shader does not contain SPIR-V source"); - }); - QShaderCode shader_code = shader.shader(shader_key); - - VkShaderModuleCreateInfo create_info { - .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, - .codeSize = (std::size_t)shader_code.shader().size(), - .pCode = reinterpret_cast(shader_code.shader().constData()), - }; - - VkShaderModule module; - if(this->dev_->vkCreateShaderModule(this->window_->device(), &create_info, nullptr, &module) != VK_SUCCESS) - { - throw std::runtime_error("failed to compile shader module"); - } - - return module; -} - -void VulkanRenderer::drawVertexBuffer(unlogic::VertexBuffer *vertex_buffer, VkPipeline pipeline) +void VulkanRenderer::drawVertexBuffer(unlogic::VertexBuffer *vertex_buffer, VulkanPipeline &pipeline) { VkCommandBuffer cmd = this->window_->currentCommandBuffer(); - this->dev_->vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); + this->dev_->vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.NativeHandle()); std::array buffers = { static_cast(vertex_buffer->GetNativeHandle()) }; constexpr std::array offsets = { 0 }; diff --git a/src/calculator/renderer/VulkanRenderer.h b/src/calculator/renderer/VulkanRenderer.h index b29944d..b9320ac 100644 --- a/src/calculator/renderer/VulkanRenderer.h +++ b/src/calculator/renderer/VulkanRenderer.h @@ -3,6 +3,7 @@ #include #include +#include "VulkanPipeline.h" #include "graphic/VertexBuffer.h" namespace ui @@ -13,28 +14,21 @@ namespace ui { VulkanWindow *window_ = nullptr; - VkPipelineLayout graph_pipeline_layout_; - VkPipeline graph_pipeline_; - - VkPipelineLayout plot_pipeline_layout_; - VkPipeline plot_pipeline_; - QVulkanDeviceFunctions *dev_ = nullptr; - std::unique_ptr gridlines_ = nullptr; + std::unique_ptr grid_pipeline_; + std::unique_ptr plot_pipeline_; - public: - // Vulkan Utils - VkShaderModule loadShader(std::string_view path); - void createStandardPipeline(VkPipeline &pipeline, VkPipelineLayout &layout, char const *vert_shader_path, char const *frag_shader_path); + std::unique_ptr grid_ = nullptr; + public: // Vulkan Commands void initResources() override; void releaseResources() override; void startNextFrame() override; // Draw Commands - void drawVertexBuffer(unlogic::VertexBuffer *vertex_buffer, VkPipeline pipeline); + void drawVertexBuffer(unlogic::VertexBuffer *vertex_buffer, VulkanPipeline &pipeline); VulkanRenderer(VulkanWindow *window) : window_(window) {} }; diff --git a/src/calculator/resource/shaders/graph.frag b/src/calculator/resource/shaders/grid.frag similarity index 100% rename from src/calculator/resource/shaders/graph.frag rename to src/calculator/resource/shaders/grid.frag diff --git a/src/calculator/resource/shaders/graph.vert b/src/calculator/resource/shaders/grid.vert similarity index 100% rename from src/calculator/resource/shaders/graph.vert rename to src/calculator/resource/shaders/grid.vert