[Bf-blender-cvs] [11bfeb4] master: OpenSubdiv: Completely avoid possible access to non-existing CPU data

Sergey Sharybin noreply at git.blender.org
Wed Aug 5 15:16:22 CEST 2015


Commit: 11bfeb45ce1b1cdb95e6cd4a4ec4efae2b5184e0
Author: Sergey Sharybin
Date:   Wed Aug 5 15:11:50 2015 +0200
Branches: master
https://developer.blender.org/rB11bfeb45ce1b1cdb95e6cd4a4ec4efae2b5184e0

OpenSubdiv: Completely avoid possible access to non-existing CPU data

Make it so CCGDM reports 0 number of geometry when it uses GPU backend for
drawing. This screws up a bit statistics in info header and requires to have
some special handle of CCGDM in the drawing code, but makes it so non of the
areas will try to access non-existing geometry.

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

M	source/blender/blenkernel/BKE_subsurf.h
M	source/blender/blenkernel/intern/CCGSubSurf.c
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/editors/space_view3d/drawobject.c

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

diff --git a/source/blender/blenkernel/BKE_subsurf.h b/source/blender/blenkernel/BKE_subsurf.h
index 93baca3..161ab2f 100644
--- a/source/blender/blenkernel/BKE_subsurf.h
+++ b/source/blender/blenkernel/BKE_subsurf.h
@@ -85,6 +85,9 @@ void subsurf_copy_grid_paint_mask(struct DerivedMesh *dm,
                                   const struct MPoly *mpoly, float *paint_mask,
                                   const struct GridPaintMask *grid_paint_mask);
 
+bool subsurf_has_edges(struct DerivedMesh *dm);
+bool subsurf_has_faces(struct DerivedMesh *dm);
+
 typedef enum MultiresModifiedFlags {
 	/* indicates the grids have been sculpted on, so MDisps
 	 * have to be updated */
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index bd5ddba..95ddb9d 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -1515,6 +1515,12 @@ int ccgSubSurf_getNumFinalVerts(const CCGSubSurf *ss)
 	                     ss->fMap->numEntries +
 	                     ss->numGrids * ((gridSize - 2) + ((gridSize - 2) * (gridSize - 2))));
 
+#ifdef WITH_OPENSUBDIV
+	if (ss->skip_grids) {
+		return 0;
+	}
+#endif
+
 	return numFinalVerts;
 }
 int ccgSubSurf_getNumFinalEdges(const CCGSubSurf *ss)
@@ -1523,13 +1529,22 @@ int ccgSubSurf_getNumFinalEdges(const CCGSubSurf *ss)
 	int gridSize = ccg_gridsize(ss->subdivLevels);
 	int numFinalEdges = (ss->eMap->numEntries * (edgeSize - 1) +
 	                     ss->numGrids * ((gridSize - 1) + 2 * ((gridSize - 2) * (gridSize - 1))));
-
+#ifdef WITH_OPENSUBDIV
+	if (ss->skip_grids) {
+		return 0;
+	}
+#endif
 	return numFinalEdges;
 }
 int ccgSubSurf_getNumFinalFaces(const CCGSubSurf *ss)
 {
 	int gridSize = ccg_gridsize(ss->subdivLevels);
 	int numFinalFaces = ss->numGrids * ((gridSize - 1) * (gridSize - 1));
+#ifdef WITH_OPENSUBDIV
+	if (ss->skip_grids) {
+		return 0;
+	}
+#endif
 	return numFinalFaces;
 }
 
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 617bf70..9971a9e 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -4850,3 +4850,25 @@ void subsurf_calculate_limit_positions(Mesh *me, float (*r_positions)[3])
 
 	dm->release(dm);
 }
+
+bool subsurf_has_edges(DerivedMesh *dm)
+{
+	CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
+#ifdef WITH_OPENSUBDIV
+	if (ccgdm->useGpuBackend) {
+		return true;
+	}
+#endif
+	return dm->getNumEdges(dm) != 0;
+}
+
+bool subsurf_has_faces(DerivedMesh *dm)
+{
+	CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
+#ifdef WITH_OPENSUBDIV
+	if (ccgdm->useGpuBackend) {
+		return true;
+	}
+#endif
+	return dm->getNumPolys(dm) != 0;
+}
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index 82acc58..f8af238 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -74,6 +74,7 @@
 #include "BKE_particle.h"
 #include "BKE_pointcache.h"
 #include "BKE_scene.h"
+#include "BKE_subsurf.h"
 #include "BKE_unit.h"
 #include "BKE_tracking.h"
 
@@ -4027,9 +4028,15 @@ static void draw_mesh_fancy(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D
 	}
 	
 	/* check polys instead of tessfaces because of dyntopo where tessfaces don't exist */
-	no_edges = (dm->getNumEdges(dm) == 0);
-	no_faces = (dm->getNumPolys(dm) == 0);
-	
+	if (dm->type == DM_TYPE_CCGDM) {
+		no_edges = !subsurf_has_edges(dm);
+		no_faces = !subsurf_has_faces(dm);
+	}
+	else {
+		no_edges = (dm->getNumEdges(dm) == 0);
+		no_faces = (dm->getNumPolys(dm) == 0);
+	}
+
 	/* vertexpaint, faceselect wants this, but it doesnt work for shaded? */
 	glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);




More information about the Bf-blender-cvs mailing list