Pipeline wrapper.
This commit is contained in:
@@ -321,7 +321,7 @@ void VulkanTutorial::destroy_swapchain_objects() {
|
||||
|
||||
m_framebuffers.clear();
|
||||
|
||||
m_context.destroy_pipeline(m_pipeline);
|
||||
m_pipeline.destroy();
|
||||
m_context.destroy_pipeline_layout(m_pipeline_layout);
|
||||
m_render_pass.destroy();
|
||||
}
|
||||
@@ -544,14 +544,7 @@ void VulkanTutorial::create_graphic_pipeline() {
|
||||
.basePipelineIndex = -1,
|
||||
};
|
||||
|
||||
if(vkCreateGraphicsPipelines(
|
||||
m_context.device(),
|
||||
VK_NULL_HANDLE,
|
||||
1, &pipeline_info,
|
||||
nullptr,
|
||||
&m_pipeline
|
||||
) != VK_SUCCESS)
|
||||
throw std::runtime_error("failed to create graphic pipeline");
|
||||
m_pipeline = vk::Pipeline(m_context, pipeline_info);
|
||||
}
|
||||
|
||||
void VulkanTutorial::create_framebuffers() {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <vk/Framebuffer.h>
|
||||
#include <vk/Semaphore.h>
|
||||
#include <vk/RenderPass.h>
|
||||
#include <vk/Pipeline.h>
|
||||
#include <vk/Buffer.h>
|
||||
#include <vk/Swapchain.h>
|
||||
#include <vk/Context.h>
|
||||
@@ -75,7 +76,7 @@ private:
|
||||
vk::RenderPass m_render_pass;
|
||||
VkDescriptorSetLayout m_descriptor_set_layout = VK_NULL_HANDLE;
|
||||
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
|
||||
VkPipeline m_pipeline = VK_NULL_HANDLE;
|
||||
vk::Pipeline m_pipeline;
|
||||
std::vector<vk::Framebuffer> m_framebuffers;
|
||||
VkCommandPool m_command_pool = VK_NULL_HANDLE;
|
||||
vk::Buffer m_vertex_buffer;
|
||||
|
||||
71
src/vk/Pipeline.cpp
Normal file
71
src/vk/Pipeline.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2022 Simon Boyé
|
||||
|
||||
#include <vk/Pipeline.h>
|
||||
#include <vk/Context.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
||||
namespace vk {
|
||||
|
||||
|
||||
Pipeline::Pipeline() noexcept {
|
||||
}
|
||||
|
||||
Pipeline::Pipeline(Context& context, VkPipeline pipeline)
|
||||
: m_context(&context)
|
||||
, m_pipeline(pipeline)
|
||||
{
|
||||
assert(m_context);
|
||||
assert(m_pipeline != VK_NULL_HANDLE);
|
||||
}
|
||||
|
||||
Pipeline::Pipeline(Context& context, VkGraphicsPipelineCreateInfo create_info)
|
||||
: m_context(&context)
|
||||
{
|
||||
assert(m_context);
|
||||
|
||||
if(vkCreateGraphicsPipelines(
|
||||
m_context->device(),
|
||||
VK_NULL_HANDLE,
|
||||
1, &create_info,
|
||||
nullptr,
|
||||
&m_pipeline
|
||||
) != VK_SUCCESS)
|
||||
throw std::runtime_error("failed to create graphic pipeline");
|
||||
}
|
||||
|
||||
Pipeline::Pipeline(Pipeline&& other) noexcept
|
||||
{
|
||||
swap(*this, other);
|
||||
}
|
||||
|
||||
Pipeline::~Pipeline() noexcept {
|
||||
if(!is_null())
|
||||
destroy();
|
||||
}
|
||||
|
||||
|
||||
Pipeline& Pipeline::operator=(Pipeline&& other) noexcept {
|
||||
swap(*this, other);
|
||||
if(other)
|
||||
other.destroy();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void Pipeline::destroy() noexcept {
|
||||
assert(!is_null());
|
||||
assert(m_context);
|
||||
|
||||
vkDestroyPipeline(
|
||||
m_context->device(),
|
||||
m_pipeline,
|
||||
nullptr
|
||||
);
|
||||
|
||||
m_pipeline = nullptr;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
62
src/vk/Pipeline.h
Normal file
62
src/vk/Pipeline.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// Copyright 2022 Simon Boyé
|
||||
#pragma once
|
||||
|
||||
#include <vk/forward.h>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
|
||||
namespace vk {
|
||||
|
||||
|
||||
class Pipeline {
|
||||
public:
|
||||
Pipeline() noexcept;
|
||||
Pipeline(Context& context, VkPipeline pipeline);
|
||||
Pipeline(Context& context, VkGraphicsPipelineCreateInfo create_info);
|
||||
Pipeline(const Pipeline&) = delete;
|
||||
Pipeline(Pipeline&& other) noexcept;
|
||||
~Pipeline() noexcept;
|
||||
|
||||
Pipeline& operator=(const Pipeline&) = delete;
|
||||
Pipeline& operator=(Pipeline&& other) noexcept;
|
||||
|
||||
explicit inline operator bool() const noexcept {
|
||||
return !is_null();
|
||||
}
|
||||
|
||||
inline bool is_null() const noexcept {
|
||||
return m_pipeline == VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
inline const Context* context() const noexcept {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
inline Context* context() noexcept {
|
||||
return m_context;
|
||||
}
|
||||
|
||||
inline operator VkPipeline() noexcept {
|
||||
return m_pipeline;
|
||||
}
|
||||
|
||||
inline VkPipeline pipeline() noexcept {
|
||||
return m_pipeline;
|
||||
}
|
||||
|
||||
friend inline void swap(Pipeline& pipeline_0, Pipeline& pipeline_1) noexcept {
|
||||
using std::swap;
|
||||
swap(pipeline_0.m_context, pipeline_1.m_context);
|
||||
swap(pipeline_0.m_pipeline, pipeline_1.m_pipeline);
|
||||
}
|
||||
|
||||
void destroy() noexcept;
|
||||
|
||||
private:
|
||||
Context* m_context = nullptr;
|
||||
VkPipeline m_pipeline = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user