wren
Vulkan-based game engine
Loading...
Searching...
No Matches
shader.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <map>
5#include <memory>
6#include <string>
7#include <vulkan/vulkan.hpp>
8#include <vulkan/vulkan_enums.hpp>
9#include <vulkan/vulkan_handles.hpp>
10#include <vulkan/vulkan_structs.hpp>
11#include <wren/math/vector.hpp>
12#include <wren/utils/result.hpp>
13
14namespace spv_reflect {
15class ShaderModule;
16}
17
18namespace wren::reflect {
19using spirv_t = std::vector<uint32_t>;
20}
21
22namespace wren::vk {
23
24BOOST_DEFINE_ENUM(ShaderType, Vertex, Fragment);
25
27 public:
28 ShaderModule() = default;
29 ShaderModule(reflect::spirv_t spirv, const ::vk::ShaderModule& module);
30
31 [[nodiscard]] auto module() const -> ::vk::ShaderModule { return module_; }
32
33 [[nodiscard]] auto get_vertex_input_bindings() const
34 -> std::vector<::vk::VertexInputBindingDescription>;
35
36 [[nodiscard]] auto get_vertex_input_attributes() const
37 -> std::vector<::vk::VertexInputAttributeDescription>;
38
39 [[nodiscard]] auto get_descriptor_set_layout_bindings() const
40 -> std::vector<::vk::DescriptorSetLayoutBinding>;
41
42 private:
43 reflect::spirv_t spirv_;
46};
47
48class Shader {
49 public:
50 using Ptr = std::shared_ptr<Shader>;
51
52 static auto create(const ::vk::Device& device,
53 const std::string& vertex_shader,
54 const std::string& fragment_shader) -> expected<Ptr>;
55
56 static auto create(const ::vk::Device& device,
57 const std::filesystem::path& shader_path) -> expected<Ptr>;
58
59 [[nodiscard]] auto get_pipeline() const { return pipeline_; }
60 [[nodiscard]] auto pipeline_layout() const { return pipeline_layout_; }
61 [[nodiscard]] auto descriptor_layout() const { return descriptor_layout_; }
62
63 void fragment_shader(const ShaderModule& fragment) {
64 fragment_shader_module_ = fragment;
65 }
66
67 void vertex_shader(const ShaderModule& vertex) {
68 vertex_shader_module_ = vertex;
69 }
70
71 auto create_graphics_pipeline(const ::vk::Device& device,
72 const ::vk::RenderPass& render_pass,
73 const math::Vec2f& size, bool depth)
75
76 private:
77 static auto read_wren_shader_file(const std::filesystem::path& path)
79
80 ::vk::DescriptorSetLayout descriptor_layout_;
81 ::vk::PipelineLayout pipeline_layout_;
82 ::vk::Pipeline pipeline_;
83
86};
87
88} // namespace wren::vk
Definition shader.hpp:26
std::shared_ptr< spv_reflect::ShaderModule > reflection_
Definition shader.hpp:45
::vk::ShaderModule module_
Definition shader.hpp:44
auto module() const -> ::vk::ShaderModule
Definition shader.hpp:31
ShaderModule(reflect::spirv_t spirv, const ::vk::ShaderModule &module)
auto get_vertex_input_bindings() const -> std::vector<::vk::VertexInputBindingDescription >
auto get_vertex_input_attributes() const -> std::vector<::vk::VertexInputAttributeDescription >
reflect::spirv_t spirv_
Definition shader.hpp:43
auto get_descriptor_set_layout_bindings() const -> std::vector<::vk::DescriptorSetLayoutBinding >
Definition shader.hpp:48
static auto create(const ::vk::Device &device, const std::filesystem::path &shader_path) -> expected< Ptr >
::vk::DescriptorSetLayout descriptor_layout_
Definition shader.hpp:80
::vk::PipelineLayout pipeline_layout_
Definition shader.hpp:81
auto get_pipeline() const
Definition shader.hpp:59
void fragment_shader(const ShaderModule &fragment)
Definition shader.hpp:63
ShaderModule vertex_shader_module_
Definition shader.hpp:84
ShaderModule fragment_shader_module_
Definition shader.hpp:85
auto pipeline_layout() const
Definition shader.hpp:60
static auto create(const ::vk::Device &device, const std::string &vertex_shader, const std::string &fragment_shader) -> expected< Ptr >
auto descriptor_layout() const
Definition shader.hpp:61
std::shared_ptr< Shader > Ptr
Definition shader.hpp:50
static auto read_wren_shader_file(const std::filesystem::path &path) -> expected< std::map< ShaderType, std::string > >
::vk::Pipeline pipeline_
Definition shader.hpp:82
auto create_graphics_pipeline(const ::vk::Device &device, const ::vk::RenderPass &render_pass, const math::Vec2f &size, bool depth) -> expected< void >
void vertex_shader(const ShaderModule &vertex)
Definition shader.hpp:67
Definition shader.hpp:14
Definition ui.hpp:5
Definition reflect.hpp:25
std::vector< uint32_t > spirv_t
Definition shader.hpp:19
Definition render_pass.hpp:19
BOOST_DEFINE_ENUM(ShaderType, Vertex, Fragment)
std::expected< T, Err > expected
Definition result.hpp:43
Definition mesh.hpp:20
Definition vector.hpp:161