yes
This commit is contained in:
82
Runtime/Includes/Renderer/Pipelines/Graphics.h
git.filemode.normal_file
82
Runtime/Includes/Renderer/Pipelines/Graphics.h
git.filemode.normal_file
@@ -0,0 +1,82 @@
|
||||
#ifndef __SCOP_GRAPHICS_PIPELINE__
|
||||
#define __SCOP_GRAPHICS_PIPELINE__
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include <kvf.h>
|
||||
|
||||
#include <Graphics/Enums.h>
|
||||
#include <Renderer/Image.h>
|
||||
#include <Utils/NonOwningPtr.h>
|
||||
#include <Renderer/Pipelines/Shader.h>
|
||||
#include <Renderer/Pipelines/Pipeline.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
struct GraphicPipelineDescriptor
|
||||
{
|
||||
std::shared_ptr<Shader> vertex_shader;
|
||||
std::shared_ptr<Shader> fragment_shader;
|
||||
std::vector<NonOwningPtr<Texture>> color_attachments;
|
||||
NonOwningPtr<DepthImage> depth = nullptr;
|
||||
NonOwningPtr<class Renderer> renderer = nullptr;
|
||||
std::string name = {};
|
||||
CullMode culling = CullMode::Front;
|
||||
bool no_vertex_inputs = false;
|
||||
bool depth_test_equal = false;
|
||||
bool clear_color_attachments = true;
|
||||
bool wireframe = false;
|
||||
};
|
||||
|
||||
class GraphicPipeline : public Pipeline
|
||||
{
|
||||
friend class Render2DPass;
|
||||
friend class FinalPass;
|
||||
friend class ForwardPass;
|
||||
friend class PostProcessPass;
|
||||
friend class SkyboxPass;
|
||||
|
||||
public:
|
||||
GraphicPipeline() = default;
|
||||
|
||||
inline void Setup(GraphicPipelineDescriptor descriptor)
|
||||
{
|
||||
if(!descriptor.vertex_shader || !descriptor.fragment_shader)
|
||||
FatalError("Vulkan: invalid shaders");
|
||||
m_description = std::move(descriptor);
|
||||
}
|
||||
|
||||
bool BindPipeline(VkCommandBuffer command_buffer, std::size_t framebuffer_index, std::array<float, 4> clear) noexcept;
|
||||
void EndPipeline(VkCommandBuffer command_buffer) noexcept override;
|
||||
void Destroy() noexcept;
|
||||
|
||||
[[nodiscard]] inline VkPipeline GetPipeline() const override { return m_pipeline; }
|
||||
[[nodiscard]] inline VkPipelineLayout GetPipelineLayout() const override { return m_pipeline_layout; }
|
||||
[[nodiscard]] inline VkPipelineBindPoint GetPipelineBindPoint() const override { return VK_PIPELINE_BIND_POINT_GRAPHICS; }
|
||||
[[nodiscard]] inline bool IsPipelineBound() const noexcept { return s_bound_pipeline == this; }
|
||||
[[nodiscard]] inline GraphicPipelineDescriptor& GetDescription() noexcept { return m_description; }
|
||||
|
||||
inline ~GraphicPipeline() noexcept { Destroy(); }
|
||||
|
||||
private:
|
||||
void Init(GraphicPipelineDescriptor descriptor);
|
||||
void CreateFramebuffers(const std::vector<NonOwningPtr<Texture>>& render_targets, bool clear_attachments);
|
||||
void TransitionAttachments(VkCommandBuffer cmd = VK_NULL_HANDLE);
|
||||
|
||||
// Private override to remove access
|
||||
bool BindPipeline(VkCommandBuffer) noexcept override { return false; };
|
||||
|
||||
private:
|
||||
static inline GraphicPipeline* s_bound_pipeline = nullptr;
|
||||
|
||||
GraphicPipelineDescriptor m_description;
|
||||
std::vector<VkFramebuffer> m_framebuffers;
|
||||
std::vector<VkClearValue> m_clears;
|
||||
VkRenderPass m_renderpass = VK_NULL_HANDLE;
|
||||
VkPipeline m_pipeline = VK_NULL_HANDLE;
|
||||
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
25
Runtime/Includes/Renderer/Pipelines/Pipeline.h
git.filemode.normal_file
25
Runtime/Includes/Renderer/Pipelines/Pipeline.h
git.filemode.normal_file
@@ -0,0 +1,25 @@
|
||||
#ifndef __SCOP_PIPELINE__
|
||||
#define __SCOP_PIPELINE__
|
||||
|
||||
#include <kvf.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
class Pipeline
|
||||
{
|
||||
public:
|
||||
Pipeline() = default;
|
||||
|
||||
inline virtual bool BindPipeline(VkCommandBuffer command_buffer) noexcept { RenderCore::Get().vkCmdBindPipeline(command_buffer, GetPipelineBindPoint(), GetPipeline()); return true; }
|
||||
inline virtual void EndPipeline([[maybe_unused]] VkCommandBuffer command_buffer) noexcept {}
|
||||
|
||||
virtual VkPipeline GetPipeline() const = 0;
|
||||
virtual VkPipelineLayout GetPipelineLayout() const = 0;
|
||||
virtual VkPipelineBindPoint GetPipelineBindPoint() const = 0;
|
||||
|
||||
virtual ~Pipeline() = default;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
123
Runtime/Includes/Renderer/Pipelines/Shader.h
git.filemode.normal_file
123
Runtime/Includes/Renderer/Pipelines/Shader.h
git.filemode.normal_file
@@ -0,0 +1,123 @@
|
||||
#ifndef __SCOP_SHADER__
|
||||
#define __SCOP_SHADER__
|
||||
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <unordered_map>
|
||||
|
||||
#include <kvf.h>
|
||||
|
||||
#include <Maths/Mat4.h>
|
||||
#include <Utils/NonOwningPtr.h>
|
||||
|
||||
namespace Scop
|
||||
{
|
||||
struct ShaderSetLayout
|
||||
{
|
||||
std::unordered_map<int, VkDescriptorType> binds;
|
||||
|
||||
ShaderSetLayout(std::unordered_map<int, VkDescriptorType> b) : binds(std::move(b)) {}
|
||||
|
||||
inline bool operator==(const ShaderSetLayout& rhs) const { return binds == rhs.binds; }
|
||||
};
|
||||
|
||||
struct ShaderPushConstantLayout
|
||||
{
|
||||
std::size_t offset;
|
||||
std::size_t size;
|
||||
|
||||
ShaderPushConstantLayout(std::size_t o, std::size_t s) : offset(o), size(s) {}
|
||||
};
|
||||
|
||||
struct ShaderLayout
|
||||
{
|
||||
std::unordered_map<int, ShaderSetLayout> set_layouts;
|
||||
std::vector<ShaderPushConstantLayout> push_constants;
|
||||
|
||||
ShaderLayout(std::unordered_map<int, ShaderSetLayout> s, std::vector<ShaderPushConstantLayout> pc) : set_layouts(std::move(s)), push_constants(std::move(pc)) {}
|
||||
};
|
||||
|
||||
enum class ShaderType
|
||||
{
|
||||
Vertex,
|
||||
Fragment,
|
||||
Compute
|
||||
};
|
||||
|
||||
struct ShaderPipelineLayoutPart
|
||||
{
|
||||
std::vector<VkPushConstantRange> push_constants;
|
||||
std::vector<VkDescriptorSetLayout> set_layouts;
|
||||
};
|
||||
|
||||
class Shader
|
||||
{
|
||||
public:
|
||||
Shader(const std::vector<std::uint32_t>& bytecode, ShaderType type, ShaderLayout layout, std::string shader_name = {});
|
||||
|
||||
[[nodiscard]] inline const ShaderLayout& GetShaderLayout() const { return m_layout; }
|
||||
[[nodiscard]] inline const std::vector<std::uint32_t>& GetByteCode() const noexcept { return m_bytecode; }
|
||||
[[nodiscard]] inline const ShaderPipelineLayoutPart& GetPipelineLayout() const noexcept { return m_pipeline_layout_part; }
|
||||
[[nodiscard]] inline VkShaderModule GetShaderModule() const noexcept { return m_module; }
|
||||
[[nodiscard]] inline VkShaderStageFlagBits GetShaderStage() const noexcept { return m_stage; }
|
||||
[[nodiscard]] inline NonOwningPtr<class GraphicPipeline> GetGraphicPipelineInUse() const noexcept { return p_pipeline_in_use; }
|
||||
|
||||
inline void SetPipelineInUse(NonOwningPtr<class GraphicPipeline> pipeline) noexcept { p_pipeline_in_use = pipeline; }
|
||||
|
||||
void Destroy();
|
||||
|
||||
~Shader();
|
||||
|
||||
private:
|
||||
void GeneratePipelineLayout(ShaderLayout layout);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
ShaderLayout m_layout;
|
||||
ShaderPipelineLayoutPart m_pipeline_layout_part;
|
||||
std::vector<std::uint32_t> m_bytecode;
|
||||
std::vector<VkDescriptorSetLayout> m_set_layouts;
|
||||
VkShaderStageFlagBits m_stage;
|
||||
VkShaderModule m_module = VK_NULL_HANDLE;
|
||||
NonOwningPtr<class GraphicPipeline> p_pipeline_in_use = nullptr;
|
||||
};
|
||||
|
||||
std::shared_ptr<Shader> LoadShaderFromFile(const std::filesystem::path& filepath, ShaderType type, ShaderLayout layout);
|
||||
|
||||
static const ShaderLayout DefaultForwardVertexShaderLayout(
|
||||
{
|
||||
{ 0,
|
||||
ShaderSetLayout({
|
||||
{ 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER },
|
||||
})
|
||||
}
|
||||
}, { ShaderPushConstantLayout({ 0, sizeof(Mat4f) * 2 }) }
|
||||
);
|
||||
|
||||
static const Scop::ShaderLayout DefaultShaderLayout(
|
||||
{
|
||||
{ 1,
|
||||
Scop::ShaderSetLayout({
|
||||
{ 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER }
|
||||
})
|
||||
}
|
||||
}, {}
|
||||
);
|
||||
|
||||
static const Scop::ShaderLayout PostProcessShaderLayout(
|
||||
{
|
||||
{ 0,
|
||||
Scop::ShaderSetLayout({
|
||||
{ 0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER },
|
||||
{ 1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER },
|
||||
{ 2, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER }
|
||||
})
|
||||
}
|
||||
}, {}
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user