big refactoring ! ci skip

This commit is contained in:
2024-09-02 09:44:42 +02:00
parent d95233e728
commit f65ac577bc
581 changed files with 42971 additions and 99170 deletions

View File

@@ -0,0 +1,57 @@
#ifndef __MLX_GRAPHICS_PIPELINE__
#define __MLX_GRAPHICS_PIPELINE__
#include <Renderer/Image.h>
#include <Utils/NonOwningPtr.h>
#include <Renderer/Pipelines/Shader.h>
#include <Renderer/Pipelines/Pipeline.h>
namespace mlx
{
struct GraphicPipelineDescriptor
{
std::shared_ptr<Shader> vertex_shader;
std::shared_ptr<Shader> fragment_shader;
std::vector<NonOwningPtr<Texture>> color_attachments;
NonOwningPtr<class Renderer> renderer = nullptr;
bool clear_color_attachments = true;
bool no_vertex_inputs = false;
};
class GraphicPipeline : public Pipeline
{
public:
GraphicPipeline() = default;
void Init(const GraphicPipelineDescriptor& 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; }
~GraphicPipeline() = default;
private:
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:
std::vector<NonOwningPtr<Texture>> m_attachments;
std::vector<VkFramebuffer> m_framebuffers;
std::vector<VkClearValue> m_clears;
std::shared_ptr<Shader> p_vertex_shader;
std::shared_ptr<Shader> p_fragment_shader;
VkRenderPass m_renderpass = VK_NULL_HANDLE;
VkPipeline m_pipeline = VK_NULL_HANDLE;
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
NonOwningPtr<class Renderer> p_renderer;
};
}
#endif

View File

@@ -1,36 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Pipeline.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 21:23:52 by maldavid #+# #+# */
/* Updated: 2024/03/28 22:15:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_PIPELINE__
#define __MLX_PIPELINE__
#ifndef __PIPELINE__
#define __PIPELINE__
#include <Renderer/Command/CommandBuffer.h>
#include <Renderer/Vulkan/VulkanPrototypes.h>
namespace mlx
{
class GraphicPipeline
class Pipeline
{
public:
void init(class Renderer& renderer);
void Destroy() noexcept;
Pipeline() = default;
inline void BindPipeline(CommandBuffer& command_buffer) noexcept { vkCmdBindPipeline(command_buffer.Get(), VK_PIPELINE_BIND_POINT_GRAPHICS, m_graphics_pipeline); }
inline virtual bool BindPipeline(VkCommandBuffer command_buffer) noexcept { vkCmdBindPipeline(command_buffer, GetPipelineBindPoint(), GetPipeline()); return true; }
inline virtual void EndPipeline([[maybe_unused]] VkCommandBuffer command_buffer) noexcept {}
inline const VkPipeline& GetPipeline() const noexcept { return m_graphics_pipeline; }
inline const VkPipelineLayout& GetPipelineLayout() const noexcept { return m_pipeline_layout; }
virtual VkPipeline GetPipeline() const = 0;
virtual VkPipelineLayout GetPipelineLayout() const = 0;
virtual VkPipelineBindPoint GetPipelineBindPoint() const = 0;
private:
VkPipeline m_graphics_pipeline = VK_NULL_HANDLE;
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
virtual ~Pipeline() = default;
};
}

68
runtime/Includes/Renderer/Pipelines/Shader.h git.filemode.normal_file
View File

@@ -0,0 +1,68 @@
#ifndef __MLX_SHADER__
#define __MLX_SHADER__
namespace mlx
{
struct ShaderSetLayout
{
std::vector<std::pair<int, VkDescriptorType> > binds;
ShaderSetLayout(std::vector<std::pair<int, VkDescriptorType> > b) : binds(std::move(b)) {}
};
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::vector<std::pair<int, ShaderSetLayout> > set_layouts;
std::vector<ShaderPushConstantLayout> push_constants;
ShaderLayout(std::vector<std::pair<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::uint8_t>& bytecode, ShaderType type, ShaderLayout layout);
[[nodiscard]] inline const ShaderLayout& GetShaderLayout() const { return m_layout; }
[[nodiscard]] inline const std::vector<std::uint8_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; }
~Shader();
private:
void GeneratePipelineLayout(ShaderLayout layout);
private:
ShaderLayout m_layout;
ShaderPipelineLayoutPart m_pipeline_layout_part;
std::vector<std::uint8_t> m_bytecode;
std::vector<VkDescriptorSetLayout> m_set_layouts;
VkShaderStageFlagBits m_stage;
VkShaderModule m_module = VK_NULL_HANDLE;
};
}
#endif