Skip to content

Commit

Permalink
[render-graph] Test pipeline wrapper (squash me)
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmNotHanni committed May 13, 2023
1 parent 82a8ae9 commit b6c790f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
5 changes: 3 additions & 2 deletions include/inexor/vulkan-renderer/render_graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "inexor/vulkan-renderer/wrapper/device.hpp"
#include "inexor/vulkan-renderer/wrapper/fence.hpp"
#include "inexor/vulkan-renderer/wrapper/framebuffer.hpp"
#include "inexor/vulkan-renderer/wrapper/pipeline.hpp"
#include "inexor/vulkan-renderer/wrapper/semaphore.hpp"
#include "inexor/vulkan-renderer/wrapper/shader.hpp"
#include "inexor/vulkan-renderer/wrapper/swapchain.hpp"
Expand Down Expand Up @@ -334,7 +335,7 @@ class PhysicalStage : public RenderGraphObject {
friend RenderGraph;

private:
VkPipeline m_pipeline{VK_NULL_HANDLE};
std::unique_ptr<wrapper::GraphicsPipeline> m_pipeline;
VkPipelineLayout m_pipeline_layout{VK_NULL_HANDLE};

protected:
Expand Down Expand Up @@ -408,7 +409,7 @@ class RenderGraph {
/// @brief Adds either a render resource or render stage to the render graph.
/// @return A mutable reference to the just-added resource or stage
template <typename T, typename... Args>
T *add(Args &&...args) {
T *add(Args &&... args) {
auto ptr = std::make_unique<T>(std::forward<Args>(args)...);
if constexpr (std::is_same_v<T, BufferResource>) {
return static_cast<T *>(m_buffer_resources.emplace_back(std::move(ptr)).get());
Expand Down
39 changes: 17 additions & 22 deletions src/vulkan-renderer/render_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ PhysicalImage::~PhysicalImage() {
}

PhysicalStage::~PhysicalStage() {
vkDestroyPipeline(m_device.device(), m_pipeline, nullptr);
vkDestroyPipelineLayout(m_device.device(), m_pipeline_layout, nullptr);
}

Expand Down Expand Up @@ -215,7 +214,7 @@ void RenderGraph::record_command_buffer(const RenderStage *stage, const wrapper:
cmd_buf.bind_vertex_buffers(vertex_buffers);
}

cmd_buf.bind_pipeline(physical.m_pipeline);
cmd_buf.bind_pipeline(physical.m_pipeline->pipeline());
stage->m_on_record(physical, cmd_buf);

if (graphics_stage != nullptr) {
Expand Down Expand Up @@ -396,26 +395,22 @@ void RenderGraph::build_graphics_pipeline(const GraphicsStage *stage, PhysicalGr
.pScissors = &scissor,
});

const auto pipeline_ci = wrapper::make_info<VkGraphicsPipelineCreateInfo>({
.stageCount = static_cast<std::uint32_t>(stage->m_shaders.size()),
.pStages = stage->m_shaders.data(),
.pVertexInputState = &vertex_input,
.pInputAssemblyState = &input_assembly,
.pViewportState = &viewport_state,
.pRasterizationState = &rasterization_state,
.pMultisampleState = &multisample_state,
.pDepthStencilState = &depth_stencil,
.pColorBlendState = &blend_state,
.layout = physical.m_pipeline_layout,
.renderPass = physical.m_render_pass,
});

// TODO: Pipeline caching (basically load the render graph from a file)
if (const auto result =
vkCreateGraphicsPipelines(m_device.device(), nullptr, 1, &pipeline_ci, nullptr, &physical.m_pipeline);
result != VK_SUCCESS) {
throw VulkanException("Error: vkCreateGraphicsPipelines failed for pipeline " + stage->name() + " !", result);
}
physical.m_pipeline = std::make_unique<wrapper::GraphicsPipeline>(
m_device,
wrapper::make_info<VkGraphicsPipelineCreateInfo>({
.stageCount = static_cast<std::uint32_t>(stage->m_shaders.size()),
.pStages = stage->m_shaders.data(),
.pVertexInputState = &vertex_input,
.pInputAssemblyState = &input_assembly,
.pViewportState = &viewport_state,
.pRasterizationState = &rasterization_state,
.pMultisampleState = &multisample_state,
.pDepthStencilState = &depth_stencil,
.pColorBlendState = &blend_state,
.layout = physical.m_pipeline_layout,
.renderPass = physical.m_render_pass,
}),
"graphics pipeline");
}

void RenderGraph::compile(const RenderResource *target) {
Expand Down

0 comments on commit b6c790f

Please sign in to comment.