Toast Engine
Loading...
Searching...
No Matches
vulkan_pipeline.hpp
1
4
5#pragma once
6
8#include "vulkan_common.hpp"
9
10#include <cstddef>
11#include <optional>
12#include <string>
13#include <vector>
14
15namespace renderer {
16
17class VulkanCore;
18
19class VulkanPipeline {
20public:
21 enum class PipelineType : uint8_t {
22 graphics,
23 compute
24 };
25
26 enum class BlendPreset : uint8_t {
27 none,
28 alpha, // srcAlpha 1-srcAlpha
29 premultiplied, // one 1-srcAlpha
30 additive, // one one
31 multiply, // dstColor zero
32 };
33
34 struct Config {
35 PipelineType pipeline_type = PipelineType::graphics;
36 std::string debug_name;
37
38 vk::Format color_format = vk::Format::eUndefined;
39 std::optional<vk::Format> depth_format;
40 vk::Extent2D extent;
41
42 std::vector<vk::Format> extra_color_formats;
43
44 bool write_extra_color = false;
45
47 bool write_color_alpha = false;
48
49 bool depth_only = false;
50
52 bool depth_fragment = false;
53
55 uint32_t view_mask = 0;
56
57 // TODO move into its own shader class
58 std::vector<std::byte> shader_spirv;
59 std::string vertex_entry = "vertexMain";
61 std::string mesh_entry;
63 std::string task_entry;
66 std::vector<std::byte> task_spirv;
67 std::string fragment_entry = "fragmentMain";
68 std::string compute_entry = "computeMain";
69
70 vk::PipelineLayout pipeline_layout = nullptr;
71
72 std::vector<vk::VertexInputBindingDescription> vertex_bindings;
73 std::vector<vk::VertexInputAttributeDescription> vertex_attributes;
74
75 vk::PrimitiveTopology topology = vk::PrimitiveTopology::eTriangleList;
76
77 vk::CullModeFlags cull_mode = vk::CullModeFlagBits::eBack;
78 vk::FrontFace front_face = vk::FrontFace::eCounterClockwise; // Counter clockwise due to the inverted projection matrix
79
80 bool depth_test = true;
81 bool depth_write = true;
83 vk::CompareOp depth_compare = depth::k_closer;
84
85 float depth_bias_constant = 0.0f;
86 float depth_bias_slope = 0.0f;
87 bool blend_enable = false;
88 BlendPreset blend_preset = BlendPreset::none;
89 };
90
91 VulkanPipeline() = default;
92 explicit VulkanPipeline(const VulkanCore& core, const Config& config);
93 ~VulkanPipeline() = default;
94
95 VulkanPipeline(const VulkanPipeline&) = delete;
96 auto operator=(const VulkanPipeline&) -> VulkanPipeline& = delete;
97 VulkanPipeline(VulkanPipeline&&) = delete;
98 auto operator=(VulkanPipeline&&) -> VulkanPipeline& = delete;
99
100 auto rebuild(const VulkanCore& core, const Config& config) -> void;
101 auto reset() -> void;
102
103 [[nodiscard]]
104 auto isReady() const -> bool {
105 return m_pipeline != nullptr;
106 }
107
108 [[nodiscard]]
109 auto getPipeline() const -> const vk::raii::Pipeline& {
110 return m_pipeline;
111 }
112
113private:
114 std::optional<vk::raii::ShaderModule> m_shader_module;
115 std::optional<vk::raii::ShaderModule> m_task_module;
116 vk::raii::Pipeline m_pipeline = nullptr;
117};
118
119} // namespace renderer
Definition vulkan_core.hpp:48
Definition vulkan_pipeline.hpp:34
std::string task_entry
Only with mesh_entry.
Definition vulkan_pipeline.hpp:63
std::vector< std::byte > task_spirv
Definition vulkan_pipeline.hpp:66
bool write_color_alpha
color_format keeps its destination alpha unless set
Definition vulkan_pipeline.hpp:47
uint32_t view_mask
Must equal every RenderingInfo viewMask. 0 is not multiview and leaves SV_ViewID undefined.
Definition vulkan_pipeline.hpp:55
std::string mesh_entry
Set for a task and mesh pipeline which has no vertex stage or vertex input.
Definition vulkan_pipeline.hpp:61
bool depth_fragment
With depth_only keeps the fragment stage for shaders that write SV_Depth.
Definition vulkan_pipeline.hpp:52
vk::CompareOp depth_compare
Scene convention. Shadow maps set eLess and far plane draws need depth::k_closer_or_equal.
Definition vulkan_pipeline.hpp:83