Draw: Removal of MultiSample Buffers
authorJeroen Bakker <jeroen@blender.org>
Thu, 5 Dec 2019 13:21:57 +0000 (14:21 +0100)
committerJeroen Bakker <jeroen@blender.org>
Fri, 6 Dec 2019 06:45:07 +0000 (07:45 +0100)
Multisample buffers were used for smooth line drawing. As we now have
an algorithm that doesn't need the multisample buffers we can remove
them.

The user preference for viewport multi_sampling is replaced by single
toggle overlay `use_overlay_smooth_wire`. By default this setting is
enabled as the new drawing is really quick (<1ms) and uses zero hacks.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D6367

15 files changed:
release/datafiles/userdef/userdef_default.c
release/scripts/startup/bl_ui/space_userpref.py
source/blender/blenkernel/BKE_blender_version.h
source/blender/blenkernel/BKE_sequencer.h
source/blender/blenkernel/intern/sequencer.c
source/blender/blenloader/intern/versioning_userdef.c
source/blender/draw/engines/overlay/overlay_antialiasing.c
source/blender/draw/intern/DRW_render.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/render/render_opengl.c
source/blender/editors/sculpt_paint/paint_image_proj.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/intern/wm_files.c

index 3856a03b1ba2df7ab1ec7c18e219e7e6fb8e1b70..f6573873dd53c85f6afc15ac679f0233894a72af 100644 (file)
@@ -62,7 +62,7 @@ const UserDef U_default = {
                USER_HIDE_DOT | USER_SHOW_GIZMO_NAVIGATE | USER_SHOW_VIEWPORTNAME | USER_SHOW_FPS |
                USER_CONTINUOUS_MOUSE | USER_SAVE_PROMPT),
     .uiflag2 = USER_REGION_OVERLAP,
-    .gpu_flag = 0,
+    .gpu_flag = USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE,
     .app_flag = 0,
     .language = 0,
     .viewzoom = USER_ZOOM_DOLLY,
@@ -160,7 +160,6 @@ const UserDef U_default = {
                   NDOF_ROTX_INVERT_AXIS | NDOF_ROTY_INVERT_AXIS | NDOF_ROTZ_INVERT_AXIS |
                   NDOF_PANX_INVERT_AXIS | NDOF_PANY_INVERT_AXIS | NDOF_PANZ_INVERT_AXIS |
                   NDOF_ZOOM_INVERT),
-    .ogl_multisamples = 0,
     .image_draw_method = IMAGE_DRAW_METHOD_AUTO,
     .glalphaclip = 0.004,
     .autokey_mode = (AUTOKEY_MODE_NORMAL & ~AUTOKEY_ON),
index 387acbec625793722b9d0f7d9c85ddaf57a14ff5..e9ccbbabdd38000a77e70e1638bec2a8549ad865 100644 (file)
@@ -675,8 +675,8 @@ class USERPREF_PT_viewport_quality(PreferencePanel, Panel):
         flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
 
         flow.prop(system, "viewport_aa")
-        flow.prop(system, "multi_sample", text="Multisampling")
         flow.prop(system, "gpencil_multi_sample", text="Grease Pencil Multisampling")
+        flow.prop(system, "use_overlay_smooth_wire")
         flow.prop(system, "use_edit_mode_smooth_wire")
 
 
index f1c45ac0b45967265164a8b3dddb97ab4d2a3291..a26b76e7069916bf75f110357d4abd0ccc9da657 100644 (file)
@@ -27,7 +27,7 @@
  * \note Use #STRINGIFY() rather than defining with quotes.
  */
 #define BLENDER_VERSION 282
-#define BLENDER_SUBVERSION 3
+#define BLENDER_SUBVERSION 4
 /** Several breakages with 280, e.g. collections vs layers. */
 #define BLENDER_MINVERSION 280
 #define BLENDER_MINSUBVERSION 0
index 1ae1772e094c8f60e3de5f9000c7886ac9738d55..770318883c0f2e359dd33aeb352bd068d82545e3 100644 (file)
@@ -531,7 +531,6 @@ typedef struct ImBuf *(*SequencerDrawView)(struct Depsgraph *depsgraph,
                                            unsigned int flag,
                                            unsigned int draw_flags,
                                            int alpha_mode,
-                                           int samples,
                                            const char *viewname,
                                            struct GPUOffScreen *ofs,
                                            char err_out[256]);
index b99d6e1684a35fd363617c7db8a9c18a808ff810..b05724ca6afd88992f047e816107959f79f84709 100644 (file)
@@ -3558,7 +3558,6 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context,
         IB_rect,
         draw_flags,
         scene->r.alphamode,
-        U.ogl_multisamples,
         viewname,
         context->gpu_offscreen,
         err_out);
index ad06d512266084724a24d94a182f19db256b70b6..4c85b5abd9765bd091561c9e4b166d7ff545281a 100644 (file)
@@ -667,10 +667,7 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
     userdef->file_space_data.filter_id = U_default.file_space_data.filter_id;
   }
 
-  /**
-   * Include next version bump.
-   */
-  {
+  if (!USER_VERSION_ATLEAST(282, 4)) {
     if (userdef->view_rotate_sensitivity_turntable == 0.0f) {
       userdef->view_rotate_sensitivity_turntable = DEG2RADF(0.4f);
       userdef->view_rotate_sensitivity_trackball = 1.0f;
@@ -678,6 +675,15 @@ void BLO_version_defaults_userpref_blend(Main *bmain, UserDef *userdef)
     if (userdef->scrollback == 0) {
       userdef->scrollback = U_default.scrollback;
     }
+
+    /* Enable Overlay Engine Smooth Wire by default */
+    userdef->gpu_flag |= USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE;
+  }
+
+  /**
+   * Include next version bump.
+   */
+  {
     /* pass */
   }
 
index 54bcd91441c911c1d8f5c22e1b4e8f1e06571bbb..8c50bfac9084c32406d67b478fd89b95f716382f 100644 (file)
@@ -76,8 +76,8 @@ void OVERLAY_antialiasing_init(OVERLAY_Data *vedata)
   }
 
   bool need_wire_expansion = (G_draw.block.sizePixel > 1.0f);
-  /* TODO Get real userpref option and remove MSAA buffer. */
-  pd->antialiasing.enabled = (dtxl->multisample_color != NULL) || need_wire_expansion;
+  pd->antialiasing.enabled = need_wire_expansion ||
+                             ((U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE) > 0);
 
   GPUTexture *color_tex = NULL;
   GPUTexture *line_tex = NULL;
@@ -122,8 +122,9 @@ void OVERLAY_antialiasing_cache_init(OVERLAY_Data *vedata)
   DRWShadingGroup *grp;
 
   if (pd->antialiasing.enabled) {
-    /* TODO Get real userpref option and remove MSAA buffer. */
-    const bool do_smooth_lines = (dtxl->multisample_color != NULL);
+    /* `antialiasing.enabled` is also enabled for wire expansion. Check here if
+     * anti aliasing is needed. */
+    const bool do_smooth_lines = (U.gpu_flag & USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE) > 0;
 
     DRW_PASS_CREATE(psl->antialiasing_ps, DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ALPHA_PREMUL);
 
index 27b43ee8c173a6f650a982d53177caad0a9b0a95..8037bd0338394bc9ea35aac0316b6ec34077ac6c 100644 (file)
@@ -101,41 +101,6 @@ typedef char DRWViewportEmptyList;
         DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->stl)), \
   }
 
-/* Use of multisample framebuffers. */
-#define MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl) \
-  { \
-    if (dfbl->multisample_fb != NULL && DRW_state_is_fbo()) { \
-      DRW_stats_query_start("Multisample Blit"); \
-      GPU_framebuffer_bind(dfbl->multisample_fb); \
-      /* TODO clear only depth but need to do alpha to coverage for transparencies. */ \
-      GPU_framebuffer_clear_color_depth(dfbl->multisample_fb, (const float[4]){0.0f}, 1.0f); \
-      DRW_stats_query_end(); \
-    } \
-  } \
-  ((void)0)
-
-#define MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl) \
-  { \
-    if (dfbl->multisample_fb != NULL && DRW_state_is_fbo()) { \
-      DRW_stats_query_start("Multisample Resolve"); \
-      GPU_framebuffer_bind(dfbl->default_fb); \
-      DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color, true); \
-      DRW_stats_query_end(); \
-    } \
-  } \
-  ((void)0)
-
-#define MULTISAMPLE_SYNC_DISABLE_NO_DEPTH(dfbl, dtxl) \
-  { \
-    if (dfbl->multisample_fb != NULL && DRW_state_is_fbo()) { \
-      DRW_stats_query_start("Multisample Resolve"); \
-      GPU_framebuffer_bind(dfbl->default_fb); \
-      DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color, false); \
-      DRW_stats_query_end(); \
-    } \
-  } \
-  ((void)0)
-
 typedef struct DrawEngineDataSize {
   int fbl_len;
   int txl_len;
@@ -176,15 +141,12 @@ typedef struct DefaultFramebufferList {
   struct GPUFrameBuffer *in_front_fb;
   struct GPUFrameBuffer *color_only_fb;
   struct GPUFrameBuffer *depth_only_fb;
-  struct GPUFrameBuffer *multisample_fb;
 } DefaultFramebufferList;
 
 typedef struct DefaultTextureList {
   struct GPUTexture *color;
   struct GPUTexture *depth;
   struct GPUTexture *depth_in_front;
-  struct GPUTexture *multisample_color;
-  struct GPUTexture *multisample_depth;
 } DefaultTextureList;
 #endif
 
index 83caef29ca34242923699d78a1dd45b3b5d8c9e5..37ffb1b9d6d7329303c5dd40ed41667710181717 100644 (file)
@@ -593,7 +593,6 @@ struct ImBuf *ED_view3d_draw_offscreen_imbuf(struct Depsgraph *depsgraph,
                                              int sizey,
                                              unsigned int flag,
                                              int alpha_mode,
-                                             int samples,
                                              const char *viewname,
                                              struct GPUOffScreen *ofs,
                                              char err_out[256]);
@@ -607,7 +606,6 @@ struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(struct Depsgraph *depsgraph,
                                                     unsigned int flag,
                                                     unsigned int draw_flags,
                                                     int alpha_mode,
-                                                    int samples,
                                                     const char *viewname,
                                                     struct GPUOffScreen *ofs,
                                                     char err_out[256]);
index ad5f8ba6834da483e51edbd7459a71fe3e83ee7f..10244cfa3fdba4f0b61feac151fda6faad248847 100644 (file)
@@ -114,7 +114,6 @@ typedef struct OGLRender {
   ImageUser iuser;
 
   GPUOffScreen *ofs;
-  int ofs_samples;
   int sizex, sizey;
   int write_still;
 
@@ -371,7 +370,6 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R
                                                  sizey,
                                                  output_flags,
                                                  alpha_mode,
-                                                 oglrender->ofs_samples,
                                                  viewname,
                                                  oglrender->ofs,
                                                  err_out);
@@ -392,7 +390,6 @@ static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, R
                                                         output_flags,
                                                         V3D_OFSDRAW_SHOW_ANNOTATION,
                                                         alpha_mode,
-                                                        oglrender->ofs_samples,
                                                         viewname,
                                                         oglrender->ofs,
                                                         err_out);
@@ -539,7 +536,6 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
   const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
   const eImageFormatDepth color_depth = (is_animation) ? scene->r.im_format.depth :
                                                          R_IMF_CHAN_DEPTH_32;
-  const int samples = U.ogl_multisamples;
   char err_out[256] = "unknown";
 
   if (G.background) {
@@ -584,7 +580,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
 
   /* corrects render size with actual size, not every card supports non-power-of-two dimensions */
   DRW_opengl_context_enable(); /* Offscreen creation needs to be done in DRW context. */
-  ofs = GPU_offscreen_create(sizex, sizey, samples, true, true, err_out);
+  ofs = GPU_offscreen_create(sizex, sizey, 0, true, true, err_out);
   DRW_opengl_context_disable();
 
   if (!ofs) {
@@ -607,7 +603,6 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
    * output video handles, which does need evaluated scene. */
   oglrender->depsgraph = CTX_data_ensure_evaluated_depsgraph(C);
   oglrender->cfrao = scene->r.cfra;
-  oglrender->ofs_samples = samples;
 
   oglrender->write_still = is_write_still && !is_animation;
   oglrender->is_animation = is_animation;
index fa4e250871e83dc458862d8576940178b62a55be..510d734451b0cbc0b2a44a6ec4767395fe7adebf 100644 (file)
@@ -6209,7 +6209,6 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
                                         h,
                                         IB_rect,
                                         R_ALPHAPREMUL,
-                                        0,
                                         NULL,
                                         NULL,
                                         err_out);
index 5f029e840d3af29c66b2a35422f2b56e83929e75..6235f9942723c6319ee56ede0b39da59eedcad09 100644 (file)
@@ -1688,7 +1688,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
                                       int sizey,
                                       uint flag,
                                       int alpha_mode,
-                                      int samples,
                                       const char *viewname,
                                       /* output vars */
                                       GPUOffScreen *ofs,
@@ -1717,7 +1716,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Depsgraph *depsgraph,
 
   if (own_ofs) {
     /* bind */
-    ofs = GPU_offscreen_create(sizex, sizey, samples, true, false, err_out);
+    ofs = GPU_offscreen_create(sizex, sizey, 0, true, false, err_out);
     if (ofs == NULL) {
       DRW_opengl_context_disable();
       return NULL;
@@ -1835,7 +1834,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph,
                                              uint flag,
                                              uint draw_flags,
                                              int alpha_mode,
-                                             int samples,
                                              const char *viewname,
                                              GPUOffScreen *ofs,
                                              char err_out[256])
@@ -1909,7 +1907,6 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Depsgraph *depsgraph,
                                         height,
                                         flag,
                                         alpha_mode,
-                                        samples,
                                         viewname,
                                         ofs,
                                         err_out);
index 11a0e4413921824ffe9a733797f53e3dfeab8d5c..eb1b3036767c434f10bcabdfa38eaf91c102950c 100644 (file)
@@ -1042,6 +1042,7 @@ typedef enum eUserpref_UI_Flag2 {
 typedef enum eUserpref_GPU_Flag {
   USER_GPU_FLAG_NO_DEPT_PICK = (1 << 0),
   USER_GPU_FLAG_NO_EDIT_MODE_SMOOTH_WIRE = (1 << 1),
+  USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE = (1 << 2),
 } eUserpref_GPU_Flag;
 
 /** #UserDef.tablet_api */
index 5d2bf161020a7a47939135488388b20cfbc3b400..64bca38882f27ac47ab46ef12e5edfdb5732f797 100644 (file)
@@ -5062,12 +5062,11 @@ static void rna_def_userdef_system(BlenderRNA *brna)
 
   /* OpenGL */
 
-  /* Full scene anti-aliasing */
-  prop = RNA_def_property(srna, "multi_sample", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_bitflag_sdna(prop, NULL, "ogl_multisamples");
-  RNA_def_property_enum_items(prop, multi_sample_levels);
+  /* Viewport anti-aliasing */
+  prop = RNA_def_property(srna, "use_overlay_smooth_wire", PROP_BOOLEAN, PROP_NONE);
+  RNA_def_property_boolean_sdna(prop, NULL, "gpu_flag", USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE);
   RNA_def_property_ui_text(
-      prop, "MultiSample", "Enable OpenGL multi-sampling, only for systems that support it");
+      prop, "Overlay Smooth Wires", "Enable overlay smooth wires, reducing aliasing");
   RNA_def_property_update(prop, 0, "rna_userdef_dpi_update");
 
   prop = RNA_def_property(srna, "use_edit_mode_smooth_wire", PROP_BOOLEAN, PROP_NONE);
index f96a8c3d7fd052dd644ee2fdf3b2d3bda758a8af..aa74aa81a740e7a1930544e52f4117a345688544 100644 (file)
@@ -1251,7 +1251,6 @@ static ImBuf *blend_file_thumb(const bContext *C,
                                                  IB_rect,
                                                  V3D_OFSDRAW_NONE,
                                                  R_ALPHAPREMUL,
-                                                 0,
                                                  NULL,
                                                  NULL,
                                                  err_out);
@@ -1266,7 +1265,6 @@ static ImBuf *blend_file_thumb(const bContext *C,
                                           BLEN_THUMB_SIZE * 2,
                                           IB_rect,
                                           R_ALPHAPREMUL,
-                                          0,
                                           NULL,
                                           NULL,
                                           err_out);