Blender  V3.3
gpu_framebuffer_private.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2020 Blender Foundation. All rights reserved. */
3 
10 #pragma once
11 
12 #include "BLI_math_vector.h"
13 #include "BLI_span.hh"
14 
15 #include "MEM_guardedalloc.h"
16 
17 #include "GPU_framebuffer.h"
18 
19 struct GPUTexture;
20 
21 typedef enum GPUAttachmentType : int {
32  /* Number of maximum output slots. */
33  /* Keep in mind that GL max is GL_MAX_DRAW_BUFFERS and is at least 8, corresponding to
34  * the maximum number of COLOR attachments specified by glDrawBuffers. */
36 
38 
39 #define GPU_FB_MAX_COLOR_ATTACHMENT (GPU_FB_MAX_ATTACHMENT - GPU_FB_COLOR_ATTACHMENT0)
40 
42 {
43  return static_cast<GPUAttachmentType>(static_cast<int>(a) - b);
44 }
45 
47 {
48  return static_cast<GPUAttachmentType>(static_cast<int>(a) + b);
49 }
50 
52 {
53  a = a + 1;
54  return a;
55 }
56 
58 {
59  a = a - 1;
60  return a;
61 }
62 
63 namespace blender {
64 namespace gpu {
65 
66 #ifdef DEBUG
67 # define DEBUG_NAME_LEN 64
68 #else
69 # define DEBUG_NAME_LEN 16
70 #endif
71 
72 class FrameBuffer {
73  protected:
83  int viewport_[4] = {0};
84  int scissor_[4] = {0};
85  bool scissor_test_ = false;
86  bool dirty_state_ = true;
87 
88 #ifndef GPU_NO_USE_PY_REFERENCES
89  public:
94  void **py_ref = nullptr;
95 #endif
96 
97  public:
98  /* Reference of a pointer that needs to be cleaned when deallocating the frame-buffer.
99  * Points to #BPyGPUFrameBuffer::fb */
100  void **ref = nullptr;
101 
102  public:
103  FrameBuffer(const char *name);
104  virtual ~FrameBuffer();
105 
106  virtual void bind(bool enabled_srgb) = 0;
107  virtual bool check(char err_out[256]) = 0;
108  virtual void clear(eGPUFrameBufferBits buffers,
109  const float clear_col[4],
110  float clear_depth,
111  uint clear_stencil) = 0;
112  virtual void clear_multi(const float (*clear_col)[4]) = 0;
114  eGPUDataFormat data_format,
115  const void *clear_value) = 0;
116 
118  eGPULoadOp load_action,
119  eGPUStoreOp store_action) = 0;
120 
121  virtual void read(eGPUFrameBufferBits planes,
123  const int area[4],
124  int channel_len,
125  int slot,
126  void *r_data) = 0;
127 
128  virtual void blit_to(eGPUFrameBufferBits planes,
129  int src_slot,
130  FrameBuffer *dst,
131  int dst_slot,
132  int dst_offset_x,
133  int dst_offset_y) = 0;
134 
135  void load_store_config_array(const GPULoadStore *load_store_actions, uint actions_len);
136 
137  void attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment);
139 
140  void recursive_downsample(int max_lvl,
141  void (*callback)(void *userData, int level),
142  void *userData);
144 
145  inline void size_set(int width, int height)
146  {
147  width_ = width;
148  height_ = height;
149  dirty_state_ = true;
150  }
151 
152  inline void viewport_set(const int viewport[4])
153  {
154  if (!equals_v4v4_int(viewport_, viewport)) {
155  copy_v4_v4_int(viewport_, viewport);
156  dirty_state_ = true;
157  }
158  }
159 
160  inline void scissor_set(const int scissor[4])
161  {
162  if (!equals_v4v4_int(scissor_, scissor)) {
163  copy_v4_v4_int(scissor_, scissor);
164  dirty_state_ = true;
165  }
166  }
167 
168  inline void scissor_test_set(bool test)
169  {
170  scissor_test_ = test;
171  dirty_state_ = true;
172  }
173 
174  inline void viewport_get(int r_viewport[4]) const
175  {
176  copy_v4_v4_int(r_viewport, viewport_);
177  }
178 
179  inline void scissor_get(int r_scissor[4]) const
180  {
181  copy_v4_v4_int(r_scissor, scissor_);
182  }
183 
184  inline bool scissor_test_get() const
185  {
186  return scissor_test_;
187  }
188 
189  inline void viewport_reset()
190  {
191  int viewport_rect[4] = {0, 0, width_, height_};
192  viewport_set(viewport_rect);
193  }
194 
195  inline void scissor_reset()
196  {
197  int scissor_rect[4] = {0, 0, width_, height_};
198  scissor_set(scissor_rect);
199  }
200 
201  inline GPUTexture *depth_tex() const
202  {
205  }
207  };
208 
209  inline GPUTexture *color_tex(int slot) const
210  {
212  };
213 };
214 
215 /* Syntactic sugar. */
216 static inline GPUFrameBuffer *wrap(FrameBuffer *vert)
217 {
218  return reinterpret_cast<GPUFrameBuffer *>(vert);
219 }
220 static inline FrameBuffer *unwrap(GPUFrameBuffer *vert)
221 {
222  return reinterpret_cast<FrameBuffer *>(vert);
223 }
224 static inline const FrameBuffer *unwrap(const GPUFrameBuffer *vert)
225 {
226  return reinterpret_cast<const FrameBuffer *>(vert);
227 }
228 
229 #undef DEBUG_NAME_LEN
230 
231 } // namespace gpu
232 } // 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
Definition: BLI_sys_types.h:67
eGPULoadOp
eGPUStoreOp
struct GPUFrameBuffer GPUFrameBuffer
eGPUFrameBufferBits
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
eGPUDataFormat
Definition: GPU_texture.h:170
Read Guarded memory(de)allocation.
void attachment_remove(GPUAttachmentType type)
void size_set(int width, int height)
virtual void attachment_set_loadstore_op(GPUAttachmentType type, eGPULoadOp load_action, eGPUStoreOp store_action)=0
virtual void read(eGPUFrameBufferBits planes, eGPUDataFormat format, const int area[4], int channel_len, int slot, void *r_data)=0
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 scissor_get(int r_scissor[4]) const
virtual void clear_multi(const float(*clear_col)[4])=0
FrameBuffer(const char *name)
virtual bool check(char err_out[256])=0
GPUTexture * color_tex(int slot) const
virtual void clear(eGPUFrameBufferBits buffers, const float clear_col[4], float clear_depth, uint clear_stencil)=0
void recursive_downsample(int max_lvl, void(*callback)(void *userData, int level), void *userData)
void viewport_get(int r_viewport[4]) const
GPUAttachment attachments_[GPU_FB_MAX_ATTACHMENT]
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 attachment_set(GPUAttachmentType type, const GPUAttachment &new_attachment)
DEGForeachIDComponentCallback callback
@ 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
GPUAttachmentType & operator--(GPUAttachmentType &a)
GPUAttachmentType & operator++(GPUAttachmentType &a)
constexpr GPUAttachmentType operator-(GPUAttachmentType a, int b)
constexpr GPUAttachmentType operator+(GPUAttachmentType a, int b)
format
Definition: logImageCore.h:38
static unsigned a[3]
Definition: RandGen.cpp:78
static void area(int d1, int d2, int e1, int e2, float weights[2])
static GPUContext * wrap(Context *ctx)
static Context * unwrap(GPUContext *ctx)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
struct GPUTexture * tex