[Bf-blender-cvs] [f3a65a1b4aa] master: GPUFrameBuffer: GL backend isolation

Clément Foucault noreply at git.blender.org
Sun Aug 30 13:36:07 CEST 2020


Commit: f3a65a1b4aa3c7da221acdbeee20afb7ebe3b221
Author: Clément Foucault
Date:   Sat Aug 29 01:13:54 2020 +0200
Branches: master
https://developer.blender.org/rBf3a65a1b4aa3c7da221acdbeee20afb7ebe3b221

GPUFrameBuffer: GL backend isolation

This is related to the Vulkan port T68990.

This is a full cleanup of the Framebuffer module and a separation
of OpenGL related functions.

There is some changes with how the default framebuffers are handled.
Now the default framebuffers are individually wrapped inside special
GLFrameBuffers. This make it easier to keep track of the currently bound
framebuffer state and have some specificity for operations on these
framebuffers.

Another change is dropping the optimisation of only configuring the
changed attachements during framebuffers update. This does not give
any benefits and add some complexity to the code. This might be brought
back if it has a performance impact on some systems.

This also adds support for naming framebuffers but it is currently not
used.

===================================================================

M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager_exec.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_framebuffer.h
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_backend.hh
M	source/blender/gpu/intern/gpu_context_private.hh
M	source/blender/gpu/intern/gpu_framebuffer.cc
M	source/blender/gpu/intern/gpu_framebuffer_private.hh
M	source/blender/gpu/intern/gpu_texture.cc
A	source/blender/gpu/intern/gpu_texture_private.hh
M	source/blender/gpu/opengl/gl_backend.hh
M	source/blender/gpu/opengl/gl_context.cc
A	source/blender/gpu/opengl/gl_framebuffer.cc
A	source/blender/gpu/opengl/gl_framebuffer.hh
A	source/blender/gpu/opengl/gl_texture.hh
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/intern/wm_surface.c
M	source/blender/windowmanager/intern/wm_window.c

===================================================================

diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index da11dacefbd..c36eeec6c08 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -1462,7 +1462,7 @@ void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph,
   DRW_hair_init();
 
   /* No framebuffer allowed before drawing. */
-  BLI_assert(GPU_framebuffer_active_get() == NULL);
+  BLI_assert(GPU_framebuffer_active_get() == GPU_framebuffer_back_get());
 
   /* Init engines */
   drw_engines_init();
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index 8a81b3db7d8..5584405c965 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -970,19 +970,14 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
 
       switch (cmd_type) {
         case DRW_CMD_CLEAR:
-          GPU_framebuffer_clear(
-#ifndef NDEBUG
-              GPU_framebuffer_active_get(),
-#else
-              NULL,
-#endif
-              cmd->clear.clear_channels,
-              (float[4]){cmd->clear.r / 255.0f,
-                         cmd->clear.g / 255.0f,
-                         cmd->clear.b / 255.0f,
-                         cmd->clear.a / 255.0f},
-              cmd->clear.depth,
-              cmd->clear.stencil);
+          GPU_framebuffer_clear(GPU_framebuffer_active_get(),
+                                cmd->clear.clear_channels,
+                                (float[4]){cmd->clear.r / 255.0f,
+                                           cmd->clear.g / 255.0f,
+                                           cmd->clear.b / 255.0f,
+                                           cmd->clear.a / 255.0f},
+                                cmd->clear.depth,
+                                cmd->clear.stencil);
           break;
         case DRW_CMD_DRWSTATE:
           state.drw_state_enabled |= cmd->state.enable;
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 25c76b8f73c..1cb13d815a2 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -92,6 +92,7 @@ set(SRC
   opengl/gl_batch.cc
   opengl/gl_context.cc
   opengl/gl_drawlist.cc
+  opengl/gl_framebuffer.cc
   opengl/gl_shader.cc
   opengl/gl_shader_interface.cc
   opengl/gl_state.cc
@@ -151,9 +152,11 @@ set(SRC
   opengl/gl_batch.hh
   opengl/gl_context.hh
   opengl/gl_drawlist.hh
+  opengl/gl_framebuffer.hh
   opengl/gl_shader.hh
   opengl/gl_shader_interface.hh
   opengl/gl_state.hh
+  opengl/gl_texture.hh
   opengl/gl_uniform_buffer.hh
   opengl/gl_vertex_array.hh
 )
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index e1526bf50a6..61833a9a65f 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -19,6 +19,13 @@
 
 /** \file
  * \ingroup gpu
+ *
+ * GPU Framebuffer
+ * - this is a wrapper for an OpenGL framebuffer object (FBO). in practice
+ *   multiple FBO's may be created.
+ * - actual FBO creation & config is deferred until GPU_framebuffer_bind or
+ *   GPU_framebuffer_check_valid to allow creation & config while another
+ *   opengl context is bound (since FBOs are not shared between ogl contexts).
  */
 
 #pragma once
@@ -41,9 +48,8 @@ typedef enum eGPUFrameBufferBits {
 } eGPUFrameBufferBits;
 
 typedef enum eGPUBackBuffer {
-  GPU_BACKBUFFER = 0,
+  GPU_BACKBUFFER_LEFT = 0,
   GPU_BACKBUFFER_RIGHT,
-  GPU_BACKBUFFER_LEFT,
 } eGPUBackBuffer;
 
 /** Opaque pointer hiding blender::gpu::FrameBuffer. */
@@ -53,15 +59,6 @@ typedef struct GPUFrameBuffer {
 
 typedef struct GPUOffScreen GPUOffScreen;
 
-/* GPU Framebuffer
- * - this is a wrapper for an OpenGL framebuffer object (FBO). in practice
- *   multiple FBO's may be created, to get around limitations on the number
- *   of attached textures and the dimension requirements.
- * - actual FBO creation & config is deferred until GPU_framebuffer_bind or
- *   GPU_framebuffer_check_valid to allow creation & config while another
- *   opengl context is bound (since FBOs are not shared between ogl contexts).
- */
-
 GPUFrameBuffer *GPU_framebuffer_create(void);
 void GPU_framebuffer_free(GPUFrameBuffer *fb);
 void GPU_framebuffer_bind(GPUFrameBuffer *fb);
@@ -72,6 +69,7 @@ bool GPU_framebuffer_bound(GPUFrameBuffer *fb);
 bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256]);
 
 GPUFrameBuffer *GPU_framebuffer_active_get(void);
+GPUFrameBuffer *GPU_framebuffer_back_get(void);
 
 #define GPU_FRAMEBUFFER_FREE_SAFE(fb) \
   do { \
@@ -84,13 +82,10 @@ GPUFrameBuffer *GPU_framebuffer_active_get(void);
 /* Framebuffer setup : You need to call GPU_framebuffer_bind for these
  * to be effective. */
 
-void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int mip);
-void GPU_framebuffer_texture_layer_attach(
-    GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int layer, int mip);
-void GPU_framebuffer_texture_cubeface_attach(
-    GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int face, int mip);
+void GPU_framebuffer_texture_attach_ex(GPUFrameBuffer *gpu_fb,
+                                       GPUAttachment attachement,
+                                       int slot);
 void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, struct GPUTexture *tex);
-void GPU_framebuffer_texture_detach_slot(GPUFrameBuffer *fb, struct GPUTexture *tex, int type);
 
 /**
  * How to use #GPU_framebuffer_ensure_config().
@@ -155,6 +150,16 @@ void GPU_framebuffer_config_array(GPUFrameBuffer *fb, const GPUAttachment *confi
     _tex, _face, _mip, \
   }
 
+#define GPU_framebuffer_texture_attach(_fb, _texture, _slot, _mip) \
+  GPU_framebuffer_texture_attach_ex( \
+      _fb, (GPUAttachment)GPU_ATTACHMENT_TEXTURE_MIP(_texture, _mip), _slot)
+#define GPU_framebuffer_texture_layer_attach(_fb, _texture, _slot, layer, _mip) \
+  GPU_framebuffer_texture_attach_ex( \
+      _fb, (GPUAttachment)GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_texture, layer, _mip), _slot)
+#define GPU_framebuffer_texture_cubeface_attach(_fb, _texture, _slot, face, _mip) \
+  GPU_framebuffer_texture_attach_ex( \
+      _fb, (GPUAttachment)GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_texture, face, _mip), _slot)
+
 /* Framebuffer operations */
 
 void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h);
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 7ee7f8fcdec..93865c098b8 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -275,8 +275,10 @@ void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter);
 void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat, bool use_clamp);
 void GPU_texture_swizzle_set(GPUTexture *tex, const char swizzle[4]);
 
+/* TODO should be private internal functions. */
 void GPU_texture_attach_framebuffer(GPUTexture *tex, struct GPUFrameBuffer *fb, int attachment);
-int GPU_texture_detach_framebuffer(GPUTexture *tex, struct GPUFrameBuffer *fb);
+void GPU_texture_detach_framebuffer(GPUTexture *tex, struct GPUFrameBuffer *fb);
+int GPU_texture_framebuffer_attachement_get(GPUTexture *tex, struct GPUFrameBuffer *fb);
 
 int GPU_texture_target(const GPUTexture *tex);
 int GPU_texture_width(const GPUTexture *tex);
diff --git a/source/blender/gpu/intern/gpu_backend.hh b/source/blender/gpu/intern/gpu_backend.hh
index f63f3cead2b..ec60e6b5704 100644
--- a/source/blender/gpu/intern/gpu_backend.hh
+++ b/source/blender/gpu/intern/gpu_backend.hh
@@ -32,6 +32,7 @@ namespace gpu {
 
 class Batch;
 class DrawList;
+class FrameBuffer;
 class Shader;
 class UniformBuf;
 
@@ -45,7 +46,7 @@ class GPUBackend {
 
   virtual Batch *batch_alloc(void) = 0;
   virtual DrawList *drawlist_alloc(int list_length) = 0;
-  // virtual FrameBuffer *framebuffer_alloc(void) = 0;
+  virtual FrameBuffer *framebuffer_alloc(const char *name) = 0;
   virtual Shader *shader_alloc(const char *name) = 0;
   // virtual Texture *texture_alloc(void) = 0;
   virtual UniformBuf *uniformbuf_alloc(int size, const char *name) = 0;
diff --git a/source/blender/gpu/intern/gpu_context_private.hh b/source/blender/gpu/intern/gpu_context_private.hh
index d18d18dc97b..664f4e2f676 100644
--- a/source/blender/gpu/intern/gpu_context_private.hh
+++ b/source/blender/gpu/intern/gpu_context_private.hh
@@ -49,6 +49,18 @@ struct GPUContext {
   GPUMatrixState *matrix_state = NULL;
   blender::gpu::GPUStateManager *state_manager = NULL;
 
+  /**
+   * All 4 window framebuffers.
+   * None of them are valid in an offscreen context.
+   * Right framebuffers are only available if using stereo rendering.
+   * Front framebuffers contains (in principle, but not always) the last frame color.
+   * Default framebuffer is back_left.
+   */
+  blender::gpu::FrameBuffer *back_left = NULL;
+  blender::gpu::FrameBuffer *front_left = NULL;
+  blender::gpu::FrameBuffer *back_right = NULL;
+  blender::gpu::FrameBuffer *front_right = NULL;
+
  protected:
   /** Thread on which this context is active. */
   pthread_t thread_;
diff --git a/source/blender/gpu/intern/gpu_framebuffer.cc b/source/blender/gpu/intern/gpu_framebuffer.cc
index 5a575f9e5f5..3390b47b1b1 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.cc
+++ b/source/blender/gpu/intern/gpu_framebuffer.cc
@@ -32,518 +32,313 @@
 #include "GPU_shader.h"
 #include "GPU_texture.h"
 
+#include "gpu_backend.hh"
 #include "gpu_context_private.hh"
 #include "gpu_private.h"
+#include "gpu_texture_private.hh"
 
 #include "gpu_framebuffer_private.hh"
 
-using namespace blender::gpu;
+namespace blender::gpu {
 
-static GLenum convert_attachment_type_to_gl(GPUAttachmentType type)
-{
-#define ATTACHMENT(type) \
-  case GPU_FB_##type: { \
-    return GL_##type; \
-  } \
-    ((void)0)
-
-  switch (type) {
-    ATTACHMENT(DEPTH_ATTACHMENT);
-    ATTACHMENT(DEPTH_STENCIL_ATTACHMENT);
-    ATTACHMENT(COLOR_ATTACHMENT0);
-    ATTACHMENT(COLOR_ATTACHMENT1);
-    ATTACHMENT(COLOR_ATTACHMENT2);
-    ATTACHMENT(COLOR_ATTACHMENT3);
-    ATTACHMENT(COLOR_ATTACHMENT4);
-    ATTACHMENT(COLOR_ATTACHMENT5);
-    default:
-      BLI_assert

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list