Blender V5.0
vk_framebuffer.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_array.hh"
12#include "BLI_math_vector.hh"
13#include "BLI_span.hh"
14#include "BLI_vector.hh"
15
17
19#include "vk_common.hh"
20#include "vk_image_view.hh"
21
22namespace blender::gpu {
23class VKContext;
24
25class VKFrameBuffer : public FrameBuffer {
26 private:
28 bool srgb_;
29 bool enabled_srgb_;
30 bool is_rendering_ = false;
31
32 VkFormat depth_attachment_format_ = VK_FORMAT_UNDEFINED;
33 VkFormat stencil_attachment_format_ = VK_FORMAT_UNDEFINED;
34 Vector<VkFormat> color_attachment_formats_;
35
38
39 public:
40 uint32_t color_attachment_size = 0u;
41
45 VKFrameBuffer(const char *name);
46 virtual ~VKFrameBuffer();
47
48 void bind(bool enabled_srgb) override;
49 bool check(char err_out[256]) override;
51 const float clear_color[4],
52 float clear_depth,
53 uint clear_stencil) override;
54 void clear_multi(const float (*clear_color)[4]) override;
56 eGPUDataFormat data_format,
57 const void *clear_value) override;
58
60
61 protected:
62 void subpass_transition_impl(const GPUAttachmentState depth_attachment_state,
63 Span<GPUAttachmentState> color_attachment_states) override;
64
65 public:
66 void read(GPUFrameBufferBits planes,
68 const int area[4],
69 int channel_len,
70 int slot,
71 void *r_data) override;
72
73 void blit_to(GPUFrameBufferBits planes,
74 int src_slot,
75 FrameBuffer *dst,
76 int dst_slot,
77 int dst_offset_x,
78 int dst_offset_y) override;
79
80 void vk_viewports_append(Vector<VkViewport> &r_viewports) const;
81 void vk_render_areas_append(Vector<VkRect2D> &r_render_areas) const;
82 void render_area_update(VkRect2D &render_area) const;
83 VkFormat depth_attachment_format_get() const;
84 VkFormat stencil_attachment_format_get() const;
86
96 void update_size();
97
98 void update_srgb();
99
107 void rendering_reset();
108
113 void rendering_ensure(VKContext &context);
114 void rendering_ensure_dynamic_rendering(VKContext &context, const VKExtensions &extensions);
115
120 void rendering_end(VKContext &context);
121
122 bool is_rendering() const
123 {
124 return is_rendering_;
125 }
126
135
136 private:
137 /* Clearing attachments */
138 void build_clear_attachments_depth_stencil(
140 float clear_depth,
141 uint32_t clear_stencil,
142 render_graph::VKClearAttachmentsNode::CreateInfo &clear_attachments) const;
143 void build_clear_attachments_color(
144 const float (*clear_colors)[4],
145 const bool multi_clear_colors,
146 render_graph::VKClearAttachmentsNode::CreateInfo &clear_attachments) const;
148};
149
150static inline VKFrameBuffer *unwrap(gpu::FrameBuffer *framebuffer)
151{
152 return static_cast<VKFrameBuffer *>(framebuffer);
153}
154
155} // namespace blender::gpu
unsigned int uint
GPUAttachmentState
GPUFrameBufferBits
eGPUDataFormat
FrameBuffer(const char *name)
void rendering_ensure_dynamic_rendering(VKContext &context, const VKExtensions &extensions)
void rendering_ensure(VKContext &context)
VKFrameBuffer(const char *name)
void clear(GPUFrameBufferBits buffers, const float clear_color[4], float clear_depth, uint clear_stencil) override
void clear_multi(const float(*clear_color)[4]) override
void vk_render_areas_append(Vector< VkRect2D > &r_render_areas) const
VkFormat stencil_attachment_format_get() const
void subpass_transition_impl(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states) override
void render_area_update(VkRect2D &render_area) const
void bind(bool enabled_srgb) override
VkFormat depth_attachment_format_get() const
void blit_to(GPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y) override
void rendering_end(VKContext &context)
bool check(char err_out[256]) override
void attachment_set_loadstore_op(GPUAttachmentType type, GPULoadStore) override
int color_attachments_resource_size() const
void clear_attachment(GPUAttachmentType type, eGPUDataFormat data_format, const void *clear_value) override
void vk_viewports_append(Vector< VkViewport > &r_viewports) const
Span< VkFormat > color_attachment_formats_get() const
format
static Context * unwrap(GPUContext *ctx)
const char * name
char * buffers[2]