Blender V5.3
gpu_framebuffer_private.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include "BLI_math_vector_c.hh"
14#include "BLI_span.hh"
15
16#include "GPU_framebuffer.hh"
17
18namespace blender {
19
20namespace gpu {
21class Texture;
22}
23
35 /* Number of maximum output slots. */
36 /* Keep in mind that GL max is GL_MAX_DRAW_BUFFERS and is at least 8, corresponding to
37 * the maximum number of COLOR attachments specified by glDrawBuffers. */
39
40};
41
42#define GPU_FB_MAX_COLOR_ATTACHMENT (GPU_FB_MAX_ATTACHMENT - GPU_FB_COLOR_ATTACHMENT0)
43
45{
46 return static_cast<GPUAttachmentType>(int(a) - b);
47}
48
50{
51 return static_cast<GPUAttachmentType>(int(a) + b);
52}
53
55{
56 a = a + 1;
57 return a;
58}
59
61{
62 a = a - 1;
63 return a;
64}
65
66namespace gpu {
67
68#ifndef NDEBUG
69# define DEBUG_NAME_LEN 64
70#else
71# define DEBUG_NAME_LEN 16
72#endif
73
75 protected:
79 bool dirty_attachments_ = true;
81 int width_ = 0, height_ = 0;
85 int viewport_[GPU_MAX_VIEWPORTS][4] = {{0}};
86 int scissor_[4] = {0};
87 bool multi_viewport_ = false;
88 bool scissor_test_ = false;
89 bool dirty_state_ = true;
90 /* Flag specifying the current bind operation should use explicit load-store state. */
94
95 public:
96#ifndef GPU_NO_USE_PY_REFERENCES
101 void **py_ref = nullptr;
102#endif
103
104 FrameBuffer(const char *name);
105 virtual ~FrameBuffer();
106
107 virtual void bind(bool enabled_srgb) = 0;
108 virtual bool check(char err_out[256]) = 0;
109 virtual void clear(GPUFrameBufferBits buffers,
110 const double4 clear_color,
111 float clear_depth,
112 uint clear_stencil) = 0;
113 virtual void clear_multi(Span<double4> clear_cols) = 0;
114 virtual void clear_attachment(GPUAttachmentType type, const double4 clear_value) = 0;
115
117
118 virtual void read(GPUFrameBufferBits planes,
119 eGPUDataFormat format,
120 const int area[4],
121 int channel_len,
122 int slot,
123 void *r_data) = 0;
124
125 virtual void blit_to(GPUFrameBufferBits planes,
126 int src_slot,
127 FrameBuffer *dst,
128 int dst_slot,
129 int dst_offset_x,
130 int dst_offset_y) = 0;
131
132 protected:
133 virtual void subpass_transition_impl(const GPUAttachmentState depth_attachment_state,
134 Span<GPUAttachmentState> color_attachment_states) = 0;
135
137 {
138 if (type >= GPU_FB_COLOR_ATTACHMENT0) {
139 int color_index = type - GPU_FB_COLOR_ATTACHMENT0;
140 SET_FLAG_FROM_TEST(color_attachments_bits_, value, 1u << color_index);
141 }
142 }
143
144 public:
145 void subpass_transition(const GPUAttachmentState depth_attachment_state,
146 Span<GPUAttachmentState> color_attachment_states);
147
148 void load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len);
149
150 void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment);
152
154
155 /* Sets the size after creation. */
156 void size_set(int width, int height)
157 {
158 width_ = width;
159 height_ = height;
160 dirty_state_ = true;
161 }
162
165 {
166 return int2(width_, height_);
167 }
168
169 /* Sets the size for frame-buffer with no attachments. */
170 void default_size_set(int width, int height)
171 {
172 width_ = width;
173 height_ = height;
174 dirty_attachments_ = true;
175 dirty_state_ = true;
176 }
177
178 void viewport_set(const int viewport[4])
179 {
180 if (!equals_v4v4_int(viewport_[0], viewport)) {
181 copy_v4_v4_int(viewport_[0], viewport);
182 dirty_state_ = true;
183 }
184 multi_viewport_ = false;
185 }
186
187 void viewport_multi_set(const int viewports[GPU_MAX_VIEWPORTS][4])
188 {
189 for (size_t i = 0; i < GPU_MAX_VIEWPORTS; i++) {
190 if (!equals_v4v4_int(viewport_[i], viewports[i])) {
191 copy_v4_v4_int(viewport_[i], viewports[i]);
192 dirty_state_ = true;
193 }
194 }
195 multi_viewport_ = true;
196 }
197
198 void scissor_set(const int scissor[4])
199 {
200 if (!equals_v4v4_int(scissor_, scissor)) {
201 copy_v4_v4_int(scissor_, scissor);
202 dirty_state_ = true;
203 }
204 }
205
206 void scissor_test_set(bool test)
207 {
208 scissor_test_ = test;
209 dirty_state_ = true;
210 }
211
212 void viewport_get(int r_viewport[4]) const
213 {
214 copy_v4_v4_int(r_viewport, viewport_[0]);
215 }
216
217 void scissor_get(int r_scissor[4]) const
218 {
219 copy_v4_v4_int(r_scissor, scissor_);
220 }
221
222 bool scissor_test_get() const
223 {
224 return scissor_test_;
225 }
226
228 {
229 int viewport_rect[4] = {0, 0, width_, height_};
230 viewport_set(viewport_rect);
231 }
232
234 {
235 int scissor_rect[4] = {0, 0, width_, height_};
236 scissor_set(scissor_rect);
237 }
238
246
248 {
249 return depth_attachment().tex;
250 };
251
252 gpu::Texture *color_tex(int slot) const
253 {
255 };
256
257 const char *name_get() const
258 {
259 return name_;
260 };
261
262 void set_use_explicit_loadstore(bool use_explicit_loadstore)
263 {
264 use_explicit_load_store_ = use_explicit_loadstore;
265 }
266
268 {
270 }
271
276};
277
278#undef DEBUG_NAME_LEN
279
280} // namespace gpu
281} // namespace blender
#define SET_FLAG_FROM_TEST(value, test, flag)
void attachment_remove(GPUAttachmentType type)
void size_set(int width, int height)
gpu::Texture * color_tex(int slot) const
virtual void subpass_transition_impl(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)=0
virtual void clear(GPUFrameBufferBits buffers, const double4 clear_color, float clear_depth, uint clear_stencil)=0
virtual void clear_multi(Span< double4 > clear_cols)=0
virtual void read(GPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data)=0
virtual void attachment_set_loadstore_op(GPUAttachmentType type, GPULoadStore ls)=0
void set_use_explicit_loadstore(bool use_explicit_loadstore)
void viewport_set(const int viewport[4])
void scissor_set(const int scissor[4])
void set_color_attachment_bit(GPUAttachmentType type, bool value)
virtual void bind(bool enabled_srgb)=0
void default_size_set(int width, int height)
const GPUAttachment & depth_attachment() const
void scissor_get(int r_scissor[4]) const
void subpass_transition(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)
virtual void clear_attachment(GPUAttachmentType type, const double4 clear_value)=0
FrameBuffer(const char *name)
virtual bool check(char err_out[256])=0
int2 size_get() const
Get the size of the framebuffer.
virtual void blit_to(GPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y)=0
void viewport_multi_set(const int viewports[GPU_MAX_VIEWPORTS][4])
void viewport_get(int r_viewport[4]) const
GPUAttachment attachments_[GPU_FB_MAX_ATTACHMENT]
int viewport_[GPU_MAX_VIEWPORTS][4]
void load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len)
void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment)
#define DEBUG_NAME_LEN
BMesh Iterators.
GPUAttachmentType & operator++(GPUAttachmentType &a)
GPUAttachmentType & operator--(GPUAttachmentType &a)
unsigned int uint
Definition BKE_text.h:55
MINLINE bool equals_v4v4_int(const int v1[4], const int v2[4]) ATTR_WARN_UNUSED_RESULT
MINLINE void copy_v4_v4_int(int r[4], const int a[4])
unsigned short uint16_t
Definition BKE_text.h:80
constexpr GPUAttachmentType operator-(GPUAttachmentType a, int b)
VecBase< int32_t, 2 > int2
VecBase< double, 4 > double4
std::string operator+(StringRef a, StringRef b)