Blender V4.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
11#pragma once
12
13#include "BLI_math_vector.h"
14#include "BLI_span.hh"
15
16#include "MEM_guardedalloc.h"
17
18#include "GPU_framebuffer.hh"
19
20struct GPUTexture;
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 {
65namespace gpu {
66
67#ifndef NDEBUG
68# define DEBUG_NAME_LEN 64
69#else
70# define DEBUG_NAME_LEN 16
71#endif
72
74 protected:
78 bool dirty_attachments_ = true;
80 int width_ = 0, height_ = 0;
85 int scissor_[4] = {0};
86 bool multi_viewport_ = false;
87 bool scissor_test_ = false;
88 bool dirty_state_ = true;
89 /* Flag specifying the current bind operation should use explicit load-store state. */
91
92#ifndef GPU_NO_USE_PY_REFERENCES
93 public:
98 void **py_ref = nullptr;
99#endif
100
101 public:
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(eGPUFrameBufferBits planes,
120 const int area[4],
121 int channel_len,
122 int slot,
123 void *r_data) = 0;
124
125 virtual void blit_to(eGPUFrameBufferBits 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
136 public:
137 void subpass_transition(const GPUAttachmentState depth_attachment_state,
138 Span<GPUAttachmentState> color_attachment_states);
139
140 void load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len);
141
142 void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment);
144
145 void recursive_downsample(int max_lvl,
146 void (*callback)(void *user_data, int level),
147 void *user_data);
149
150 /* Sets the size after creation. */
151 inline void size_set(int width, int height)
152 {
153 width_ = width;
154 height_ = height;
155 dirty_state_ = true;
156 }
157
158 /* Sets the size for frame-buffer with no attachments. */
159 inline void default_size_set(int width, int height)
160 {
161 width_ = width;
162 height_ = height;
163 dirty_attachments_ = true;
164 dirty_state_ = true;
165 }
166
167 inline void viewport_set(const int viewport[4])
168 {
169 if (!equals_v4v4_int(viewport_[0], viewport)) {
170 copy_v4_v4_int(viewport_[0], viewport);
171 dirty_state_ = true;
172 }
173 multi_viewport_ = false;
174 }
175
176 inline void viewport_multi_set(const int viewports[GPU_MAX_VIEWPORTS][4])
177 {
178 for (size_t i = 0; i < GPU_MAX_VIEWPORTS; i++) {
179 if (!equals_v4v4_int(viewport_[i], viewports[i])) {
180 copy_v4_v4_int(viewport_[i], viewports[i]);
181 dirty_state_ = true;
182 }
183 }
184 multi_viewport_ = true;
185 }
186
187 inline void scissor_set(const int scissor[4])
188 {
189 if (!equals_v4v4_int(scissor_, scissor)) {
190 copy_v4_v4_int(scissor_, scissor);
191 dirty_state_ = true;
192 }
193 }
194
195 inline void scissor_test_set(bool test)
196 {
197 scissor_test_ = test;
198 dirty_state_ = true;
199 }
200
201 inline void viewport_get(int r_viewport[4]) const
202 {
203 copy_v4_v4_int(r_viewport, viewport_[0]);
204 }
205
206 inline void scissor_get(int r_scissor[4]) const
207 {
208 copy_v4_v4_int(r_scissor, scissor_);
209 }
210
211 inline bool scissor_test_get() const
212 {
213 return scissor_test_;
214 }
215
216 inline void viewport_reset()
217 {
218 int viewport_rect[4] = {0, 0, width_, height_};
219 viewport_set(viewport_rect);
220 }
221
222 inline void scissor_reset()
223 {
224 int scissor_rect[4] = {0, 0, width_, height_};
225 scissor_set(scissor_rect);
226 }
227
228 inline GPUTexture *depth_tex() const
229 {
232 }
234 };
235
236 inline GPUTexture *color_tex(int slot) const
237 {
239 };
240
241 inline const char *const name_get() const
242 {
243 return name_;
244 };
245
246 inline void set_use_explicit_loadstore(bool use_explicit_loadstore)
247 {
248 use_explicit_load_store_ = use_explicit_loadstore;
249 }
250
251 inline bool get_use_explicit_loadstore() const
252 {
254 }
255};
256
257/* Syntactic sugar. */
258static inline GPUFrameBuffer *wrap(FrameBuffer *vert)
259{
260 return reinterpret_cast<GPUFrameBuffer *>(vert);
261}
262static inline FrameBuffer *unwrap(GPUFrameBuffer *vert)
263{
264 return reinterpret_cast<FrameBuffer *>(vert);
265}
266static inline const FrameBuffer *unwrap(const GPUFrameBuffer *vert)
267{
268 return reinterpret_cast<const FrameBuffer *>(vert);
269}
270
271#undef DEBUG_NAME_LEN
272
273} // namespace gpu
274} // namespace blender
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
GPUAttachmentState
eGPUFrameBufferBits
#define GPU_MAX_VIEWPORTS
eGPUDataFormat
Read Guarded memory(de)allocation.
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])
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 char *const name_get() 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)
local_group_size(16, 16) .push_constant(Type b
DEGForeachIDComponentCallback callback
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
@ 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
char * buffers[2]