5 changed files with 138 additions and 10 deletions
@ -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; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
@ -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; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue