Blender V5.0
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.h"
14#include "BLI_span.hh"
15
16#include "GPU_framebuffer.hh"
17
18namespace blender::gpu {
19class Texture;
20}
21
33 /* Number of maximum output slots. */
34 /* Keep in mind that GL max is GL_MAX_DRAW_BUFFERS and is at least 8, corresponding to
35 * the maximum number of COLOR attachments specified by glDrawBuffers. */
37
38};
39
40#define GPU_FB_MAX_COLOR_ATTACHMENT (GPU_FB_MAX_ATTACHMENT - GPU_FB_COLOR_ATTACHMENT0)
41
43{
44 return static_cast<GPUAttachmentType>(int(a) - b);
45}
46
48{
49 return static_cast<GPUAttachmentType>(int(a) + b);
50}
51
53{
54 a = a + 1;
55 return a;
56}
57
59{
60 a = a - 1;
61 return a;
62}
63
64namespace blender::gpu {
65
66#ifndef NDEBUG
67# define DEBUG_NAME_LEN 64
68#else
69# define DEBUG_NAME_LEN 16
70#endif
71
73 protected:
77 bool dirty_attachments_ = true;
79 int width_ = 0, height_ = 0;
84 int scissor_[4] = {0};
85 bool multi_viewport_ = false;
86 bool scissor_test_ = false;
87 bool dirty_state_ = true;
88 /* Flag specifying the current bind operation should use explicit load-store state. */
92
93 public:
94#ifndef GPU_NO_USE_PY_REFERENCES
99 void **py_ref = nullptr;
100#endif
101
102 FrameBuffer(const char *name);
103 virtual ~FrameBuffer();
104
105 virtual void bind(bool enabled_srgb) = 0;
106 virtual bool check(char err_out[256]) = 0;
108 const float clear_col[4],
109 float clear_depth,
110 uint clear_stencil) = 0;
111 virtual void clear_multi(const float (*clear_col)[4]) = 0;
113 eGPUDataFormat data_format,
114 const void *clear_value) = 0;
115
117
118 virtual void read(GPUFrameBufferBits planes,
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
163 /* Sets the size for frame-buffer with no attachments. */
164 void default_size_set(int width, int height)
165 {
166 width_ = width;
167 height_ = height;
168 dirty_attachments_ = true;
169 dirty_state_ = true;
170 }
171
172 void viewport_set(const int viewport[4])
173 {
174 if (!equals_v4v4_int(viewport_[0], viewport)) {
175 copy_v4_v4_int(viewport_[0], viewport);
176 dirty_state_ = true;
177 }
178 multi_viewport_ = false;
179 }
180
181 void viewport_multi_set(const int viewports[GPU_MAX_VIEWPORTS][4])
182 {
183 for (size_t i = 0; i < GPU_MAX_VIEWPORTS; i++) {
184 if (!equals_v4v4_int(viewport_[i], viewports[i])) {
185 copy_v4_v4_int(viewport_[i], viewports[i]);
186 dirty_state_ = true;
187 }
188 }
189 multi_viewport_ = true;
190 }
191
192 void scissor_set(const int scissor[4])
193 {
194 if (!equals_v4v4_int(scissor_, scissor)) {
195 copy_v4_v4_int(scissor_, scissor);
196 dirty_state_ = true;
197 }
198 }
199
200 void scissor_test_set(bool test)
201 {
202 scissor_test_ = test;
203 dirty_state_ = true;
204 }
205
206 void viewport_get(int r_viewport[4]) const
207 {
208 copy_v4_v4_int(r_viewport, viewport_[0]);
209 }
210
211 void scissor_get(int r_scissor[4]) const
212 {
213 copy_v4_v4_int(r_scissor, scissor_);
214 }
215
216 bool scissor_test_get() const
217 {
218 return scissor_test_;
219 }
220
222 {
223 int viewport_rect[4] = {0, 0, width_, height_};
224 viewport_set(viewport_rect);
225 }
226
228 {
229 int scissor_rect[4] = {0, 0, width_, height_};
230 scissor_set(scissor_rect);
231 }
232
240
242 {
243 return depth_attachment().tex;
244 };
245
247 {
248 return attachments_[GPU_FB_COLOR_ATTACHMENT0 + slot].tex;
249 };
250
251 const char *name_get() const
252 {
253 return name_;
254 };
255
256 void set_use_explicit_loadstore(bool use_explicit_loadstore)
257 {
258 use_explicit_load_store_ = use_explicit_loadstore;
259 }
260
262 {
264 }
265
267 {
269 }
270};
271
272#undef DEBUG_NAME_LEN
273
274} // namespace blender::gpu
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 int uint
#define SET_FLAG_FROM_TEST(value, test, flag)
GPUAttachmentState
GPUFrameBufferBits
static constexpr int GPU_MAX_VIEWPORTS
eGPUDataFormat
void attachment_remove(GPUAttachmentType type)
void size_set(int width, int height)
virtual void subpass_transition_impl(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)=0
virtual void clear(GPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)=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 clear_attachment(GPUAttachmentType type, eGPUDataFormat data_format, const void *clear_value)=0
virtual void bind(bool enabled_srgb)=0
void default_size_set(int width, int height)
const GPUAttachment & depth_attachment() const
blender::gpu::Texture * depth_tex() const
void scissor_get(int r_scissor[4]) const
blender::gpu::Texture * color_tex(int slot) const
void subpass_transition(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)
virtual void clear_multi(const float(*clear_col)[4])=0
FrameBuffer(const char *name)
virtual bool check(char err_out[256])=0
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)
@ GPU_FB_DEPTH_STENCIL_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT5
@ GPU_FB_COLOR_ATTACHMENT2
@ GPU_FB_COLOR_ATTACHMENT3
@ GPU_FB_MAX_ATTACHMENT
@ GPU_FB_COLOR_ATTACHMENT6
@ GPU_FB_COLOR_ATTACHMENT7
@ GPU_FB_COLOR_ATTACHMENT4
@ GPU_FB_COLOR_ATTACHMENT1
@ GPU_FB_COLOR_ATTACHMENT0
@ GPU_FB_DEPTH_ATTACHMENT
#define DEBUG_NAME_LEN
constexpr GPUAttachmentType operator-(GPUAttachmentType a, int b)
GPUAttachmentType & operator++(GPUAttachmentType &a)
constexpr GPUAttachmentType operator+(GPUAttachmentType a, int b)
GPUAttachmentType & operator--(GPUAttachmentType &a)
format
const char * name
blender::gpu::Texture * tex
i
Definition text_draw.cc:230
char * buffers[2]