Blender V4.5
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 /* Render pass workaround when dynamic rendering isn't supported. */
40 VkFramebuffer vk_framebuffer = VK_NULL_HANDLE;
41
42 public:
43 VkRenderPass vk_render_pass = VK_NULL_HANDLE;
44 uint32_t color_attachment_size = 0u;
45
49 VKFrameBuffer(const char *name);
50 virtual ~VKFrameBuffer();
51
52 void bind(bool enabled_srgb) override;
53 bool check(char err_out[256]) override;
55 const float clear_color[4],
56 float clear_depth,
57 uint clear_stencil) override;
58 void clear_multi(const float (*clear_color)[4]) override;
60 eGPUDataFormat data_format,
61 const void *clear_value) override;
62
64
65 protected:
66 void subpass_transition_impl(const GPUAttachmentState depth_attachment_state,
67 Span<GPUAttachmentState> color_attachment_states) override;
68
69 public:
70 void read(eGPUFrameBufferBits planes,
72 const int area[4],
73 int channel_len,
74 int slot,
75 void *r_data) override;
76
77 void blit_to(eGPUFrameBufferBits planes,
78 int src_slot,
79 FrameBuffer *dst,
80 int dst_slot,
81 int dst_offset_x,
82 int dst_offset_y) override;
83
84 void vk_viewports_append(Vector<VkViewport> &r_viewports) const;
85 void vk_render_areas_append(Vector<VkRect2D> &r_render_areas) const;
86 void render_area_update(VkRect2D &render_area) const;
87 VkFormat depth_attachment_format_get() const;
88 VkFormat stencil_attachment_format_get() const;
90
100 void update_size();
101
102 void update_srgb();
103
111 void rendering_reset();
112
117 void rendering_ensure(VKContext &context);
118 void rendering_ensure_dynamic_rendering(VKContext &context, const VKExtensions &extensions);
120
125 void rendering_end(VKContext &context);
126
127 bool is_rendering() const
128 {
129 return is_rendering_;
130 }
131
140
141 private:
147 void render_pass_free();
148
149 /* Clearing attachments */
150 void build_clear_attachments_depth_stencil(
152 float clear_depth,
153 uint32_t clear_stencil,
154 render_graph::VKClearAttachmentsNode::CreateInfo &clear_attachments) const;
155 void build_clear_attachments_color(
156 const float (*clear_colors)[4],
157 const bool multi_clear_colors,
158 render_graph::VKClearAttachmentsNode::CreateInfo &clear_attachments) const;
160
166 bool has_gaps_between_color_attachments() const;
167};
168
169static inline VKFrameBuffer *unwrap(FrameBuffer *framebuffer)
170{
171 return static_cast<VKFrameBuffer *>(framebuffer);
172}
173
174} // namespace blender::gpu
unsigned int uint
GPUAttachmentState
eGPUFrameBufferBits
eGPUDataFormat
FrameBuffer(const char *name)
void rendering_ensure_dynamic_rendering(VKContext &context, const VKExtensions &extensions)
void rendering_ensure(VKContext &context)
void rendering_ensure_render_pass(VKContext &context)
VKFrameBuffer(const char *name)
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 clear(eGPUFrameBufferBits buffers, const float clear_color[4], float clear_depth, uint clear_stencil) override
void bind(bool enabled_srgb) override
VkFormat depth_attachment_format_get() const
void rendering_end(VKContext &context)
bool check(char err_out[256]) override
void attachment_set_loadstore_op(GPUAttachmentType type, GPULoadStore) override
void blit_to(eGPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y) 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)
read
char * buffers[2]