[Bf-blender-cvs] [3c9d3698219] temp-fracture-modifier-2.8: temporarily bringing back the legacy subsurf code for performance reasons

Martin Felke noreply at git.blender.org
Wed Dec 12 23:29:55 CET 2018


Commit: 3c9d3698219be9b0cdb0c8a2c294520e3bc17305
Author: Martin Felke
Date:   Wed Dec 12 22:16:44 2018 +0100
Branches: temp-fracture-modifier-2.8
https://developer.blender.org/rB3c9d3698219be9b0cdb0c8a2c294520e3bc17305

temporarily bringing back the legacy subsurf code for performance reasons

opensubdivs subdivision code has currently an abysmal performance and is thus not yet
really usable, especially with many ngons and variable topology in animations.
After opensubdivs performance issues have been fixed, this legacy code can go again.
Not before.

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

M	CMakeLists.txt
M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/makesrna/intern/CMakeLists.txt
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/CMakeLists.txt
M	source/blender/modifiers/intern/MOD_multires.c
M	source/blender/modifiers/intern/MOD_subsurf.c

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0b11e4a5a1a..daa08e8209a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -239,6 +239,9 @@ option(WITH_COMPOSITOR         "Enable the tile based nodal compositor" ON)
 
 option(WITH_OPENSUBDIV    "Enable OpenSubdiv for surface subdivision" ${_init_OPENSUBDIV})
 
+option(WITH_OPENSUBDIV_MODIFIER    "Use OpenSubdiv for CPU side of Subsurf/Multires modifiers" OFF)
+mark_as_advanced(WITH_OPENSUBDIV_MODIFIER)
+
 option(WITH_OPENVDB       "Enable features relying on OpenVDB" OFF)
 option(WITH_OPENVDB_BLOSC "Enable blosc compression for OpenVDB, only enable if OpenVDB was built with blosc support" OFF)
 option(WITH_OPENVDB_3_ABI_COMPATIBLE "Assume OpenVDB library has been compiled with version 3 ABI compatibility" OFF)
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 2781c7934fe..aea0ed68790 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -651,7 +651,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "levels", text="Preview")
         col.prop(md, "sculpt_levels", text="Sculpt")
         col.prop(md, "render_levels", text="Render")
-        col.prop(md, "quality")
+        if hasattr(md, "quality"):
+            col.prop(md, "quality")
 
         col = split.column()
 
@@ -1029,7 +1030,8 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
             col.label(text="Subdivisions:")
             col.prop(md, "levels", text="View")
             col.prop(md, "render_levels", text="Render")
-            col.prop(md, "quality")
+            if hasattr(md, "quality"):
+                col.prop(md, "quality")
 
         col = split.column()
         col.label(text="Options:")
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index bb6fd5ebc43..09a0ba6bad7 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -569,6 +569,9 @@ if(WITH_OPENSUBDIV)
 	list(APPEND INC_SYS
 		${OPENSUBDIV_INCLUDE_DIRS}
 	)
+	if(WITH_OPENSUBDIV_MODIFIER)
+		add_definitions(-DWITH_OPENSUBDIV_MODIFIER)
+	endif()
 endif()
 
 if(WITH_OPENVDB)
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index 0859d14a764..1b06077b1ea 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -307,6 +307,10 @@ if(WITH_OPENSUBDIV)
 	add_definitions(-DWITH_OPENSUBDIV)
 endif()
 
+if(WITH_OPENSUBDIV_MODIFIER)
+	add_definitions(-DWITH_OPENSUBDIV_MODIFIER)
+endif()
+
 if(WITH_OPENVDB)
 	add_definitions(-DWITH_OPENVDB)
 
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index e145ab92abb..6af36969616 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1238,12 +1238,14 @@ static PropertyRNA *rna_def_property_subdivision_common(StructRNA *srna, const c
 	RNA_def_property_ui_text(prop, "UV Smooth", "Controls how smoothing is applied to UVs");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
 
+#ifdef WITH_OPENSUBDIV_MODIFIER
 	prop = RNA_def_property(srna, "quality", PROP_INT, PROP_UNSIGNED);
 	RNA_def_property_int_sdna(prop, NULL, "quality");
 	RNA_def_property_range(prop, 1, 10);
 	RNA_def_property_ui_range(prop, 1, 6, 1, -1);
 	RNA_def_property_ui_text(prop, "Quality", "Accuracy of vertex positions, lower value is faster but less precise");
 	RNA_def_property_update(prop, 0, "rna_Modifier_update");
+#endif
 
 	prop = RNA_def_property(srna, "subdivision_type", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, type);
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index 040949198f5..e517d4a25ec 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -145,6 +145,10 @@ if(WITH_INTERNATIONAL)
 	add_definitions(-DWITH_INTERNATIONAL)
 endif()
 
+if(WITH_OPENSUBDIV_MODIFIER)
+	add_definitions(-DWITH_OPENSUBDIV_MODIFIER)
+endif()
+
 # So we can have special tricks in modifier system.
 add_definitions(${GL_DEFINITIONS})
 
diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c
index fc8a376d2d7..73fa7aa0e0d 100644
--- a/source/blender/modifiers/intern/MOD_multires.c
+++ b/source/blender/modifiers/intern/MOD_multires.c
@@ -67,6 +67,91 @@ static void initData(ModifierData *md)
 	mmd->quality = 3;
 }
 
+#ifndef WITH_OPENSUBDIV_MODIFIER
+
+static DerivedMesh *applyModifier_DM(
+        ModifierData *md, const ModifierEvalContext *ctx,
+        DerivedMesh *dm)
+{
+	MultiresModifierData *mmd = (MultiresModifierData *)md;
+	struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
+	DerivedMesh *result;
+	Mesh *me = (Mesh *)ctx->object->data;
+	const bool useRenderParams = (ctx->flag & MOD_APPLY_RENDER) != 0;
+	const bool ignore_simplify = (ctx->flag & MOD_APPLY_IGNORE_SIMPLIFY) != 0;
+	MultiresFlags flags = 0;
+	const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK);
+
+	if (mmd->totlvl) {
+		if (!CustomData_get_layer(&me->ldata, CD_MDISPS)) {
+			/* multires always needs a displacement layer */
+			CustomData_add_layer(&me->ldata, CD_MDISPS, CD_CALLOC, NULL, me->totloop);
+		}
+	}
+
+	if (has_mask)
+		flags |= MULTIRES_ALLOC_PAINT_MASK;
+
+	if (useRenderParams)
+		flags |= MULTIRES_USE_RENDER_PARAMS;
+
+	if (ignore_simplify)
+		flags |= MULTIRES_IGNORE_SIMPLIFY;
+
+	result = multires_make_derived_from_derived(dm, mmd, scene, ctx->object, flags);
+
+	if (result == dm)
+		return dm;
+
+	if (useRenderParams || !(ctx->flag & MOD_APPLY_USECACHE)) {
+		DerivedMesh *cddm;
+
+		cddm = CDDM_copy(result);
+
+		/* copy hidden/masks to vertices */
+		if (!useRenderParams) {
+			struct MDisps *mdisps;
+			struct GridPaintMask *grid_paint_mask;
+
+			mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
+			grid_paint_mask = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK);
+
+			if (mdisps) {
+				subsurf_copy_grid_hidden(result, me->mpoly,
+				                         cddm->getVertArray(cddm),
+				                         mdisps);
+
+				BKE_mesh_flush_hidden_from_verts_ex(cddm->getVertArray(cddm),
+				                                    cddm->getLoopArray(cddm),
+				                                    cddm->getEdgeArray(cddm),
+				                                    cddm->getNumEdges(cddm),
+				                                    cddm->getPolyArray(cddm),
+				                                    cddm->getNumPolys(cddm));
+			}
+			if (grid_paint_mask) {
+				float *paint_mask = CustomData_add_layer(&cddm->vertData,
+				                                         CD_PAINT_MASK,
+				                                         CD_CALLOC, NULL,
+				                                         cddm->getNumVerts(cddm));
+
+				subsurf_copy_grid_paint_mask(result, me->mpoly,
+				                             paint_mask, grid_paint_mask);
+			}
+		}
+
+		result->release(result);
+		result = cddm;
+	}
+
+	return result;
+}
+
+applyModifier_DM_wrapper(applyModifier, applyModifier_DM)
+
+#endif
+
+#ifdef WITH_OPENSUBDIV_MODIFIER
+
 /* Subdivide into fully qualified mesh. */
 
 static Mesh *multires_as_mesh(MultiresModifierData *mmd,
@@ -126,9 +211,9 @@ static Mesh *multires_as_ccg(MultiresModifierData *mmd,
 	return result;
 }
 
-static Mesh *applyModifier(ModifierData *md,
-                           const ModifierEvalContext *ctx,
-                           Mesh *mesh)
+static Mesh *applyModifier_subdiv(ModifierData *md,
+                                  const ModifierEvalContext *ctx,
+                                  Mesh *mesh)
 {
 	Mesh *result = mesh;
 	MultiresModifierData *mmd = (MultiresModifierData *)md;
@@ -162,6 +247,7 @@ static Mesh *applyModifier(ModifierData *md,
 	}
 	return result;
 }
+#endif
 
 ModifierTypeInfo modifierType_Multires = {
 	/* name */              "Multires",
@@ -184,7 +270,11 @@ ModifierTypeInfo modifierType_Multires = {
 	/* deformMatrices */    NULL,
 	/* deformVertsEM */     NULL,
 	/* deformMatricesEM */  NULL,
+#ifdef WITH_OPENSUBDIV_MODIFIER
+	/* applyModifier */     applyModifier_subdiv,
+#else
 	/* applyModifier */     applyModifier,
+#endif
 
 	/* initData */          initData,
 	/* requiredDataMask */  NULL,
diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c
index e66b3fdbafb..aa97eaa89c9 100644
--- a/source/blender/modifiers/intern/MOD_subsurf.c
+++ b/source/blender/modifiers/intern/MOD_subsurf.c
@@ -99,6 +99,47 @@ static bool isDisabled(const Scene *scene, ModifierData *md, bool useRenderParam
 	return get_render_subsurf_level(&scene->r, levels, useRenderParams != 0) == 0;
 }
 
+#ifndef WITH_OPENSUBDIV_MODIFIER
+
+static DerivedMesh *applyModifier_DM(
+        ModifierData *md, const ModifierEvalContext *ctx,
+        DerivedMesh *derivedData)
+{
+	SubsurfModifierData *smd = (SubsurfModifierData *) md;
+	struct Scene *scene = DEG_get_evaluated_scene(ctx->depsgraph);
+	SubsurfFlags subsurf_flags = 0;
+	DerivedMesh *result;
+	const bool useRenderParams = (ctx->flag & MOD_APPLY_RENDER) != 0;
+	const bool isFinalCalc = (ctx->flag & MOD_APPLY_USECACHE) != 0;
+
+	bool do_cddm_convert = useRenderParams || !isFinalCalc;
+
+	if (useRenderParams)
+		subsurf_flags |= SUBSURF_USE_RENDER_PARAMS;
+	if (isFinalCalc)
+		subsurf_flags |= SUBSURF_IS_FINAL_CALC;
+	if (ctx->object->mode & OB_MODE_EDIT)
+		subsurf_flags |= SUBSURF_IN_EDIT_MODE;
+
+	result = subsurf_make_derived_from_derived(derivedData, smd, scene, NULL, subsurf_flags);
+	result->cd_flag = derivedData->cd_flag;
+
+	{
+		DerivedMesh *cddm = CDDM_copy(result);
+		result->release(result);
+		result = cddm;
+	}
+
+	(void) do_cddm_convert;
+
+	return result;
+}
+
+applyModifier_DM_wrapper(applyModifier, applyModifier_DM)
+
+#endif
+
+#ifdef WITH_OPENSUBDIV_MODIFIER
 static int subdiv_levels_for_modifier_get(const SubsurfModifierData *smd,
                                           const ModifierEvalContext *ctx)
 {


@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list