5#include <tl/expected.hpp>
6#include <vulkan/vulkan.hpp>
24 std::unordered_map<std::string, std::shared_ptr<vk::Shader>>
shaders;
33 static auto create(
const std::shared_ptr<Context>& ctx,
36 const std::optional<vk::Image>& image)
43 uint32_t binding, T data);
45 size_t size) ->
void*;
61 [[nodiscard]]
auto get()
const {
return render_pass_; }
63 [[nodiscard]]
auto target()
const {
return target_; }
66 RenderPass(
const std::shared_ptr<Context>& ctx, std::string name,
68 const std::optional<vk::Image>& image);
70 std::shared_ptr<Context> ctx_;
74 std::shared_ptr<vk::Shader> last_bound_shader_;
78 ::vk::RenderPass render_pass_;
80 ::vk::CommandPool command_pool_;
81 std::vector<::vk::CommandBuffer> command_buffers_;
83 std::optional<vk::Image> target_image_;
84 std::shared_ptr<RenderTarget> target_;
85 ::vk::Framebuffer framebuffer_;
87 std::map<std::pair<uint32_t, uint32_t>, std::shared_ptr<vk::Buffer>> ubos_;
92 uint32_t set, uint32_t binding, T data) {
93 if (!ubos_.contains({set, binding})) {
99 ctx_->graphics_context->allocator(),
sizeof(data),
100 VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT,
101 VmaAllocationCreateFlagBits::
102 VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT)});
105 auto buffer = ubos_.at({set, binding});
106 buffer->set_data_raw(&data,
sizeof(T));
108 ::vk::DescriptorBufferInfo buffer_info(buffer->get(), 0,
sizeof(T));
109 std::array writes = {::vk::WriteDescriptorSet{
110 {}, binding, 0, ::vk::DescriptorType::eUniformBuffer, {}, buffer_info}};
112 cmd.pushDescriptorSetKHR(::vk::PipelineBindPoint::eGraphics,
113 last_bound_shader_->pipeline_layout(), set, writes);
Definition render_pass.hpp:29
auto get_command_buffers() const
Definition render_pass.hpp:53
auto resize_target(const math::vec2i &new_size) -> expected< void >
Definition render_pass.cpp:86
static auto create(const std::shared_ptr< Context > &ctx, const std::string &name, const PassResources &resources, const execute_fn_t &fn, const std::optional< vk::Image > &image) -> expected< std::shared_ptr< RenderPass > >
Definition render_pass.cpp:14
auto get_scratch_buffer(uint32_t set, uint32_t binding, size_t size) -> void *
Definition render_pass.cpp:188
void execute()
Definition render_pass.cpp:155
void recreate_framebuffers(const ::vk::Device &device)
Definition render_pass.cpp:132
void bind_pipeline(const std::string &pipeline_name)
Definition render_pass.cpp:199
auto target() const
Definition render_pass.hpp:63
auto get_framebuffer() const
Definition render_pass.hpp:55
auto get() const
Definition render_pass.hpp:61
void on_resource_resized(const std::pair< float, float > &size)
Definition render_pass.cpp:128
void write_scratch_buffer(const ::vk::CommandBuffer &cmd, uint32_t set, uint32_t binding, T data)
Definition render_pass.hpp:91
std::function< void(RenderPass &, ::vk::CommandBuffer &)> execute_fn_t
Definition render_pass.hpp:31
auto current_target_size()
Definition render_pass.hpp:51
static auto create(const VmaAllocator &allocator, size_t size, VkBufferUsageFlags usage, const std::optional< VmaAllocationCreateFlags > &flags={}) -> std::shared_ptr< Buffer >
Definition buffer.cpp:14
tl::expected< T, Err > expected
Definition errors.hpp:49
Definition render_pass.hpp:23
std::unordered_map< std::string, std::shared_ptr< vk::Shader > > shaders
Definition render_pass.hpp:24
std::shared_ptr< RenderTarget > render_target
Definition render_pass.hpp:26
std::string target_name
Definition render_pass.hpp:25
Definition vector.hpp:110