1#ifndef LIBSBX_GRAPHICS_PIPELINE_GRAPHICS_PIPELINE_HPP_
2#define LIBSBX_GRAPHICS_PIPELINE_GRAPHICS_PIPELINE_HPP_
8#include <unordered_map>
12#include <vulkan/vulkan.hpp>
14#include <fmt/format.h>
16#include <libsbx/utility/enum.hpp>
18#include <libsbx/graphics/buffers/buffer.hpp>
19#include <libsbx/graphics/buffers/uniform_handler.hpp>
21#include <libsbx/graphics/pipeline/shader.hpp>
22#include <libsbx/graphics/pipeline/pipeline.hpp>
23#include <libsbx/graphics/pipeline/vertex_input_description.hpp>
25#include <libsbx/graphics/descriptor/descriptor.hpp>
26#include <libsbx/graphics/descriptor/descriptor_set.hpp>
28#include <libsbx/graphics/images/image2d.hpp>
30namespace sbx::graphics {
32enum class polygon_mode : std::uint8_t {
33 fill = VK_POLYGON_MODE_FILL,
34 line = VK_POLYGON_MODE_LINE,
35 point = VK_POLYGON_MODE_POINT
38enum class cull_mode : std::uint8_t {
39 none = VK_CULL_MODE_NONE,
40 front = VK_CULL_MODE_FRONT_BIT,
41 back = VK_CULL_MODE_BACK_BIT,
42 front_and_back = VK_CULL_MODE_FRONT_AND_BACK
45enum class front_face : std::uint8_t {
46 counter_clockwise = VK_FRONT_FACE_COUNTER_CLOCKWISE,
47 clockwise = VK_FRONT_FACE_CLOCKWISE
51 std::float_t constant_factor{0.0f};
52 std::float_t clamp{0.0f};
53 std::float_t slope_factor{0.0f};
57 graphics::polygon_mode polygon_mode{polygon_mode::fill};
58 std::float_t line_width{1.0f};
59 graphics::cull_mode cull_mode{cull_mode::back};
60 graphics::front_face front_face{front_face::counter_clockwise};
61 std::optional<graphics::depth_bias>
depth_bias{};
64enum class primitive_topology : std::uint8_t {
65 point_list = VK_PRIMITIVE_TOPOLOGY_POINT_LIST,
66 line_list = VK_PRIMITIVE_TOPOLOGY_LINE_LIST,
67 line_strip = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP,
68 triangle_list = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST,
69 triangle_strip = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP,
70 triangle_fan = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN,
71 line_list_with_adjacency = VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY,
72 line_strip_with_adjacency = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY,
73 triangle_list_with_adjacency = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY,
74 triangle_strip_with_adjacency = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY,
75 patch_list = VK_PRIMITIVE_TOPOLOGY_PATCH_LIST,
79 bool uses_depth{
true};
80 bool uses_transparency{
false};
82 graphics::primitive_topology primitive_topology{graphics::primitive_topology::triangle_list};
83 std::vector<graphics::shader::define> defines{};
86template<vertex Vertex>
91 using vertex_type = Vertex;
97 auto handle()
const noexcept ->
const VkPipeline&
override;
99 auto has_variable_descriptors()
const noexcept ->
bool override {
100 return _has_variable_descriptors;
103 auto descriptor_counts()
const noexcept ->
const std::unordered_map<std::uint32_t, std::uint32_t>&
override {
104 return _descriptor_count_at_binding;
107 auto descriptor_set_layout()
const noexcept ->
const VkDescriptorSetLayout&
override;
109 auto descriptor_pool()
const noexcept ->
const VkDescriptorPool&
override;
111 auto layout()
const noexcept ->
const VkPipelineLayout&
override;
113 auto bind_point()
const noexcept -> VkPipelineBindPoint
override;
120 if (
auto it = _uniform_blocks.find(name); it != _uniform_blocks.end()) {
124 throw std::runtime_error(fmt::format(
"Failed to find descriptor block '{}' in graphics pipeline '{}'", name, _name));
127 auto find_descriptor_binding(
const std::string& name)
const -> std::optional<std::uint32_t>
override {
128 if (
auto it = _descriptor_bindings.find(name); it != _descriptor_bindings.end()) {
135 auto find_descriptor_type_at_binding(std::uint32_t binding)
const -> std::optional<VkDescriptorType>
override {
136 if (
auto it = _descriptor_type_at_binding.find(binding); it != _descriptor_type_at_binding.end()) {
147 auto _get_stage_from_name(
const std::string& name)
const noexcept -> VkShaderStageFlagBits;
149 std::unordered_map<VkShaderStageFlagBits, std::unique_ptr<shader>> _shaders{};
151 std::unordered_map<std::string, shader::uniform> _uniforms{};
152 std::unordered_map<std::string, shader::uniform_block> _uniform_blocks{};
154 std::unordered_map<std::uint32_t, VkDescriptorType> _descriptor_type_at_binding{};
155 std::unordered_map<std::uint32_t, std::uint32_t> _descriptor_count_at_binding{};
157 std::unordered_map<std::string, std::uint32_t> _descriptor_bindings{};
158 std::unordered_map<std::string, std::uint32_t> _descriptor_sizes{};
161 VkPipelineLayout _layout{};
162 VkPipeline _handle{};
163 VkPipelineBindPoint _bind_point{};
164 bool _has_variable_descriptors;
168 VkDescriptorPool _descriptor_pool{};
169 VkDescriptorSetLayout _descriptor_set_layout{};
180 static constexpr auto values = std::array<entry_type, 3u>{
181 entry_type{sbx::graphics::polygon_mode::fill,
"fill"},
182 entry_type{sbx::graphics::polygon_mode::line,
"line"},
183 entry_type{sbx::graphics::polygon_mode::point,
"point"}
188#include <libsbx/graphics/pipeline/graphics_pipeline.ipp>
Definition: graphics_pipeline.hpp:87
Definition: pipeline.hpp:18
Definition: graphics_pipeline.hpp:50
Definition: pipeline.hpp:22
Definition: graphics_pipeline.hpp:78
Definition: graphics_pipeline.hpp:56