Blender V4.5
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
18struct GPUTexture;
19
31 /* Number of maximum output slots. */
32 /* Keep in mind that GL max is GL_MAX_DRAW_BUFFERS and is at least 8, corresponding to
33 * the maximum number of COLOR attachments specified by glDrawBuffers. */
35
36};
37
38#define GPU_FB_MAX_COLOR_ATTACHMENT (GPU_FB_MAX_ATTACHMENT - GPU_FB_COLOR_ATTACHMENT0)
39
41{
42 return static_cast<GPUAttachmentType>(int(a) - b);
43}
44
46{
47 return static_cast<GPUAttachmentType>(int(a) + b);
48}
49
51{
52 a = a + 1;
53 return a;
54}
55
57{
58 a = a - 1;
59 return a;
60}
61
62namespace blender::gpu {
63
64#ifndef NDEBUG
65# define DEBUG_NAME_LEN 64
66#else
67# define DEBUG_NAME_LEN 16
68#endif
69
71 protected:
75 bool dirty_attachments_ = true;
77 int width_ = 0, height_ = 0;
82 int scissor_[4] = {0};
83 bool multi_viewport_ = false;
84 bool scissor_test_ = false;
85 bool dirty_state_ = true;
86 /* Flag specifying the current bind operation should use explicit load-store state. */
90
91 public:
92#ifndef GPU_NO_USE_PY_REFERENCES
97 void **py_ref = nullptr;
98#endif
99
100 FrameBuffer(const char *name);
101 virtual ~FrameBuffer();
102
103 virtual void bind(bool enabled_srgb) = 0;
104 virtual bool check(char err_out[256]) = 0;
106 const float clear_col[4],
107 float clear_depth,
108 uint clear_stencil) = 0;
109 virtual void clear_multi(const float (*clear_col)[4]) = 0;
111 eGPUDataFormat data_format,
112 const void *clear_value) = 0;
113
115
116 virtual void read(eGPUFrameBufferBits planes,
118 const int area[4],
119 int channel_len,
120 int slot,
121 void *r_data) = 0;
122
123 virtual void blit_to(eGPUFrameBufferBits planes,
124 int src_slot,
125 FrameBuffer *dst,
126 int dst_slot,
127 int dst_offset_x,
128 int dst_offset_y) = 0;
129
130 protected:
131 virtual void subpass_transition_impl(const GPUAttachmentState depth_attachment_state,
132 Span<GPUAttachmentState> color_attachment_states) = 0;
133
135 {
136 if (type >= GPU_FB_COLOR_ATTACHMENT0) {
137 int color_index = type - GPU_FB_COLOR_ATTACHMENT0;
138 SET_FLAG_FROM_TEST(color_attachments_bits_, value, 1u << color_index);
139 }
140 }
141
142 public:
143 void subpass_transition(const GPUAttachmentState depth_attachment_state,
144 Span<GPUAttachmentState> color_attachment_states);
145
146 void load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len);
147
148 void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment);
150
151 void recursive_downsample(int max_lvl,
152 void (*callback)(void *user_data, int level),
153 void *user_data);
155
156 /* Sets the size after creation. */
157 void size_set(int width, int height)
158 {
159 width_ = width;
160 height_ = height;
161 dirty_state_ = true;
162 }
163
164 /* Sets the size for frame-buffer with no attachments. */
165 void default_size_set(int width, int height)
166 {
167 width_ = width;
168 height_ = height;
169 dirty_attachments_ = true;
170 dirty_state_ = true;
171 }
172
173 void viewport_set(const int viewport[4])
174 {
175 if (!equals_v4v4_int(viewport_[0], viewport)) {
176 copy_v4_v4_int(viewport_[0], viewport);
177 dirty_state_ = true;
178 }
179 multi_viewport_ = false;
180 }
181
182 void viewport_multi_set(const int viewports[GPU_MAX_VIEWPORTS][4])
183 {
184 for (size_t i = 0; i < GPU_MAX_VIEWPORTS; i++) {
185 if (!equals_v4v4_int(viewport_[i], viewports[i])) {
186 copy_v4_v4_int(viewport_[i], viewports[i]);
187 dirty_state_ = true;
188 }
189 }
190 multi_viewport_ = true;
191 }
192
193 void scissor_set(const int scissor[4])
194 {
195 if (!equals_v4v4_int(scissor_, scissor)) {
196 copy_v4_v4_int(scissor_, scissor);
197 dirty_state_ = true;
198 }
199 }
200
201 void scissor_test_set(bool test)
202 {
203 scissor_test_ = test;
204 dirty_state_ = true;
205 }
206
207 void viewport_get(int r_viewport[4]) const
208 {
209 copy_v4_v4_int(r_viewport, viewport_[0]);
210 }
211
212 void scissor_get(int r_scissor[4]) const
213 {
214 copy_v4_v4_int(r_scissor, scissor_);
215 }
216
217 bool scissor_test_get() const
218 {
219 return scissor_test_;
220 }
221
223 {
224 int viewport_rect[4] = {0, 0, width_, height_};
225 viewport_set(viewport_rect);
226 }
227
229 {
230 int scissor_rect[4] = {0, 0, width_, height_};
231 scissor_set(scissor_rect);
232 }
233
241
242 GPUTexture *depth_tex() const
243 {
244 return depth_attachment().tex;
245 };
246
247 GPUTexture *color_tex(int slot) const
248 {
249 return attachments_[GPU_FB_COLOR_ATTACHMENT0 + slot].tex;
250 };
251
252 const char *name_get() const
253 {
254 return name_;
255 };
256
257 void set_use_explicit_loadstore(bool use_explicit_loadstore)
258 {
259 use_explicit_load_store_ = use_explicit_loadstore;
260 }
261
263 {
265 }
266
268 {
270 }
271};
272
273/* Syntactic sugar. */
274static inline GPUFrameBuffer *wrap(FrameBuffer *vert)
275{
276 return reinterpret_cast<GPUFrameBuffer *>(vert);
277}
278static inline FrameBuffer *unwrap(GPUFrameBuffer *vert)
279{
280 return reinterpret_cast<FrameBuffer *>(vert);
281}
282static inline const FrameBuffer *unwrap(const GPUFrameBuffer *vert)
283{
284 return reinterpret_cast<const FrameBuffer *>(vert);
285}
286
287#undef DEBUG_NAME_LEN
288
289} // 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
eGPUFrameBufferBits
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 attachment_set_loadstore_op(GPUAttachmentType type, GPULoadStore ls)=0
virtual void read(eGPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data)=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
void scissor_get(int r_scissor[4]) const
void subpass_transition(const GPUAttachmentState depth_attachment_state, Span< GPUAttachmentState > color_attachment_states)
virtual void clear_multi(const float(*clear_col)[4])=0
GPUTexture * color_tex(int slot) const
FrameBuffer(const char *name)
virtual bool check(char err_out[256])=0
virtual void clear(eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)=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)
virtual void blit_to(eGPUFrameBufferBits planes, int src_slot, FrameBuffer *dst, int dst_slot, int dst_offset_x, int dst_offset_y)=0
void recursive_downsample(int max_lvl, void(*callback)(void *user_data, int level), void *user_data)
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
static Context * unwrap(GPUContext *ctx)
static GPUContext * wrap(Context *ctx)
GPUTexture * tex
i
Definition text_draw.cc:230
char * buffers[2]