[Bf-blender-cvs] [e637e8dcc6a] master: Subdiv: Move single threaded code to a single function

Sergey Sharybin noreply at git.blender.org
Mon Jan 7 17:24:21 CET 2019


Commit: e637e8dcc6a2fa459afdea550f2d47dabd5cadb7
Author: Sergey Sharybin
Date:   Mon Jan 7 15:34:59 2019 +0100
Branches: master
https://developer.blender.org/rBe637e8dcc6a2fa459afdea550f2d47dabd5cadb7

Subdiv: Move single threaded code to a single function

Allows to more easily add more passes which are supposed to be run
from a single thread.

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

M	source/blender/blenkernel/intern/subdiv_foreach.c

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

diff --git a/source/blender/blenkernel/intern/subdiv_foreach.c b/source/blender/blenkernel/intern/subdiv_foreach.c
index 48ce252c788..b81f2a08b33 100644
--- a/source/blender/blenkernel/intern/subdiv_foreach.c
+++ b/source/blender/blenkernel/intern/subdiv_foreach.c
@@ -466,14 +466,15 @@ static void subdiv_foreach_every_corner_vertices_special(
 	        false);
 }
 
-static void subdiv_foreach_every_corner_vertices(SubdivForeachTaskContext *ctx)
+static void subdiv_foreach_every_corner_vertices(
+        SubdivForeachTaskContext *ctx,
+        void *tls)
 {
 	if (ctx->foreach_context->vertex_every_corner == NULL) {
 		return;
 	}
 	const Mesh *coarse_mesh = ctx->coarse_mesh;
 	const MPoly *coarse_mpoly = coarse_mesh->mpoly;
-	void *tls = subdiv_foreach_tls_alloc(ctx);
 	for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
 		const MPoly *coarse_poly = &coarse_mpoly[poly_index];
 		if (coarse_poly->totloop == 4) {
@@ -483,7 +484,6 @@ static void subdiv_foreach_every_corner_vertices(SubdivForeachTaskContext *ctx)
 			subdiv_foreach_every_corner_vertices_special(ctx, tls, coarse_poly);
 		}
 	}
-	subdiv_foreach_tls_free(tls);
 }
 
 /* Traverse of edge vertices. They are coming from coarse edges. */
@@ -689,14 +689,15 @@ static void subdiv_foreach_every_edge_vertices_special(
 	        false);
 }
 
-static void subdiv_foreach_every_edge_vertices(SubdivForeachTaskContext *ctx)
+static void subdiv_foreach_every_edge_vertices(
+        SubdivForeachTaskContext *ctx,
+        void *tls)
 {
 	if (ctx->foreach_context->vertex_every_edge == NULL) {
 		return;
 	}
 	const Mesh *coarse_mesh = ctx->coarse_mesh;
 	const MPoly *coarse_mpoly = coarse_mesh->mpoly;
-	void *tls = subdiv_foreach_tls_alloc(ctx);
 	for (int poly_index = 0; poly_index < coarse_mesh->totpoly; poly_index++) {
 		const MPoly *coarse_poly = &coarse_mpoly[poly_index];
 		if (coarse_poly->totloop == 4) {
@@ -706,7 +707,6 @@ static void subdiv_foreach_every_edge_vertices(SubdivForeachTaskContext *ctx)
 			subdiv_foreach_every_edge_vertices_special(ctx, tls, coarse_poly);
 		}
 	}
-	subdiv_foreach_tls_free(tls);
 }
 
 /* Traversal of inner vertices, they are coming from ptex patches. */
@@ -1950,6 +1950,19 @@ static void subdiv_foreach_vertices_of_loose_edges_task(
  * Subdivision process entry points.
  */
 
+static void subdiv_foreach_single_thread_tasks(SubdivForeachTaskContext *ctx)
+{
+	/* NOTE: In theory, we can try to skip allocation of TLS here, but in
+	 * practice if the callbacks used here are not specified then TLS will not
+	 * be requested anyway. */
+	void *tls = subdiv_foreach_tls_alloc(ctx);
+	/* Passes to average displacement on the corner vertices
+	 * and boundary edges. */
+	subdiv_foreach_every_corner_vertices(ctx, tls);
+	subdiv_foreach_every_edge_vertices(ctx, tls);
+	subdiv_foreach_tls_free(tls);
+}
+
 static void subdiv_foreach_task(
         void *__restrict userdata,
         const int poly_index,
@@ -2008,11 +2021,8 @@ bool BKE_subdiv_foreach_subdiv_geometry(
 			return false;
 		}
 	}
-	/* Single threaded passes to average displacement on the corner vertices
-	 * and boundary edges.
-	 */
-	subdiv_foreach_every_corner_vertices(&ctx);
-	subdiv_foreach_every_edge_vertices(&ctx);
+	/* Run all the code which is not supposed to be run from threads. */
+	subdiv_foreach_single_thread_tasks(&ctx);
 	/* Threaded traversal of the rest of topology. */
 	ParallelRangeSettings parallel_range_settings;
 	BLI_parallel_range_settings_defaults(&parallel_range_settings);



More information about the Bf-blender-cvs mailing list