Blender V4.3
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
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:
27 /* Number of layers if the attachments are layered textures. */
28 int depth_ = 1;
29
31 bool srgb_;
32 bool enabled_srgb_;
33 bool is_rendering_ = false;
34
35 VkFormat depth_attachment_format_ = VK_FORMAT_UNDEFINED;
36 VkFormat stencil_attachment_format_ = VK_FORMAT_UNDEFINED;
37 Vector<VkFormat> color_attachment_formats_;
38
41
42 public:
46 VKFrameBuffer(const char *name);
47 virtual ~VKFrameBuffer();
48
49 void bind(bool enabled_srgb) override;
50 bool check(char err_out[256]) override;
52 const float clear_color[4],
53 float clear_depth,
54 uint clear_stencil) override;
55 void clear_multi(const float (*clear_color)[4]) override;
57 eGPUDataFormat data_format,
58 const void *clear_value) override;
59
61
62 protected:
63 void subpass_transition_impl(const GPUAttachmentState depth_attachment_state,
64 Span<GPUAttachmentState> color_attachment_states) override;
65
66 public:
67 void read(eGPUFrameBufferBits planes,
69 const int area[4],
70 int channel_len,
71 int slot,
72 void *r_data) override;
73
74 void blit_to(eGPUFrameBufferBits planes,
75 int src_slot,
76 FrameBuffer *dst,
77 int dst_slot,
78 int dst_offset_x,
79 int dst_offset_y) override;
80
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
119 void rendering_end(VKContext &context);
120
121 bool is_rendering() const
122 {
123 return is_rendering_;
124 }
125
134
135 private:
136 void update_attachments();
137 void render_pass_free();
138 void render_pass_create();
139
140 /* Clearing attachments */
141 void build_clear_attachments_depth_stencil(
143 float clear_depth,
144 uint32_t clear_stencil,
145 render_graph::VKClearAttachmentsNode::CreateInfo &clear_attachments) const;
146 void build_clear_attachments_color(
147 const float (*clear_colors)[4],
148 const bool multi_clear_colors,
149 render_graph::VKClearAttachmentsNode::CreateInfo &clear_attachments) const;
151};
152
153static inline VKFrameBuffer *unwrap(FrameBuffer *framebuffer)
154{
155 return static_cast<VKFrameBuffer *>(framebuffer);
156}
157
158} // namespace blender::gpu
unsigned int uint
GPUAttachmentState
eGPUFrameBufferBits
eGPUDataFormat
void rendering_ensure(VKContext &context)
VKFrameBuffer(const char *name)
void clear_multi(const float(*clear_color)[4]) override
VkFormat stencil_attachment_format_get() const
void read(eGPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data) override
void subpass_transition_impl(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states) override
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
Array< VkViewport, 16 > vk_viewports_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
Array< VkRect2D, 16 > vk_render_areas_get() const
Span< VkFormat > color_attachment_formats_get() const
format
static Context * unwrap(GPUContext *ctx)
unsigned int uint32_t
Definition stdint.h:80
char * buffers[2]