sandbox
Loading...
Searching...
No Matches
compute_pipeline.hpp
1#ifndef LIBSBX_GRAPHICS_COMPUTE_PIPELINE_HPP_
2#define LIBSBX_GRAPHICS_COMPUTE_PIPELINE_HPP_
3
4#include <vulkan/vulkan.hpp>
5
6#include <fmt/format.h>
7
8#include <libsbx/math/vector3.hpp>
9
10#include <libsbx/graphics/pipeline/pipeline.hpp>
11
12namespace sbx::graphics {
13
14class compute_pipeline : public pipeline {
15
16public:
17
18 compute_pipeline(const std::filesystem::path& path);
19
20 ~compute_pipeline() override;
21
22 auto handle() const noexcept -> const VkPipeline& override {
23 return _handle;
24 }
25
26 auto has_variable_descriptors() const noexcept -> bool override {
27 return false;
28 }
29
30 auto descriptor_counts() const noexcept -> const std::unordered_map<std::uint32_t, std::uint32_t>& override {
31 return _descriptor_count_at_binding;
32 }
33
34 auto descriptor_set_layout() const noexcept -> const VkDescriptorSetLayout& override {
35 return _descriptor_set_layout;
36 }
37
38 auto descriptor_pool() const noexcept -> const VkDescriptorPool& override {
39 return _descriptor_pool;
40 }
41
42 auto layout() const noexcept -> const VkPipelineLayout& override {
43 return _layout;
44 }
45
46 auto bind_point() const noexcept -> VkPipelineBindPoint override {
47 return _bind_point;
48 }
49
50 auto descriptor_block(const std::string& name) const -> const shader::uniform_block& override {
51 if (auto it = _uniform_blocks.find(name); it != _uniform_blocks.end()) {
52 return it->second;
53 }
54
55 throw std::runtime_error(fmt::format("Failed to find descriptor block '{}' in graphics pipeline '{}'", name, _name));
56 }
57
58 auto find_descriptor_binding(const std::string& name) const -> std::optional<std::uint32_t> override {
59 if (auto it = _descriptor_bindings.find(name); it != _descriptor_bindings.end()) {
60 return it->second;
61 }
62
63 return std::nullopt;
64 }
65
66 auto find_descriptor_type_at_binding(std::uint32_t binding) const -> std::optional<VkDescriptorType> override {
67 if (auto it = _descriptor_type_at_binding.find(binding); it != _descriptor_type_at_binding.end()) {
68 return it->second;
69 }
70
71 return std::nullopt;
72 }
73
74 auto dispatch(command_buffer& command_buffer, const math::vector3u& groups) -> void {
75 vkCmdDispatch(command_buffer, groups.x(), groups.y(), groups.z());
76 }
77
78private:
79
80 auto _get_stage_from_name(const std::string& name) const noexcept -> VkShaderStageFlagBits;
81
82 std::unique_ptr<shader> _shader;
83
84 std::unordered_map<std::string, shader::uniform> _uniforms;
85 std::unordered_map<std::string, shader::uniform_block> _uniform_blocks;
86
87 std::unordered_map<std::uint32_t, VkDescriptorType> _descriptor_type_at_binding;
88 std::unordered_map<std::uint32_t, std::uint32_t> _descriptor_count_at_binding;
89
90 std::unordered_map<std::string, std::uint32_t> _descriptor_bindings;
91 std::unordered_map<std::string, std::uint32_t> _descriptor_sizes;
92
93 std::string _name;
94 VkPipelineLayout _layout;
95 VkPipeline _handle;
96 VkPipelineBindPoint _bind_point;
97
98 VkDescriptorPool _descriptor_pool;
99 VkDescriptorSetLayout _descriptor_set_layout;
100
101}; // class compute_pipeline
102
103} // namespace sbx::graphics
104
105#endif // LIBSBX_GRAPHICS_COMPUTE_PIPELINE_HPP_
Definition: command_buffer.hpp:14
Definition: compute_pipeline.hpp:14
Definition: pipeline.hpp:18
Definition: shader.hpp:116
Definition: vector3.hpp:22