[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13774] trunk/blender/source: automatic threads, next to the Threads button, so you can set threads to use whatever the system has, useful in the studio with 2, 4, 8 core systems when sharing files.

Campbell Barton ideasman42 at gmail.com
Tue Feb 19 23:23:21 CET 2008


Revision: 13774
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13774
Author:   campbellbarton
Date:     2008-02-19 23:23:21 +0100 (Tue, 19 Feb 2008)

Log Message:
-----------
automatic threads, next to the Threads button, so you can set threads to use whatever the system has, useful in the studio with 2,4,8 core systems when sharing files.

Modified Paths:
--------------
    trunk/blender/source/blender/blenlib/BLI_threads.h
    trunk/blender/source/blender/blenlib/intern/threads.c
    trunk/blender/source/blender/makesdna/DNA_scene_types.h
    trunk/blender/source/blender/render/intern/source/pipeline.c
    trunk/blender/source/blender/src/buttons_scene.c
    trunk/blender/source/creator/creator.c

Modified: trunk/blender/source/blender/blenlib/BLI_threads.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_threads.h	2008-02-19 21:18:35 UTC (rev 13773)
+++ trunk/blender/source/blender/blenlib/BLI_threads.h	2008-02-19 22:23:21 UTC (rev 13774)
@@ -50,5 +50,6 @@
 void	BLI_lock_thread		(int type);
 void	BLI_unlock_thread	(int type);
 
+int		BLI_system_thread_count( void ); /* gets the number of threads the system can make use of */
 #endif
 

Modified: trunk/blender/source/blender/blenlib/intern/threads.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/threads.c	2008-02-19 21:18:35 UTC (rev 13773)
+++ trunk/blender/source/blender/blenlib/intern/threads.c	2008-02-19 22:23:21 UTC (rev 13774)
@@ -32,6 +32,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <pthread.h>
+#include <unistd.h> /* for checking system threads */
 
 #include "MEM_guardedalloc.h"
 
@@ -224,4 +225,16 @@
 		pthread_mutex_unlock(&_custom1_lock);
 }
 
+/* how many threads are native on this system? */
+int BLI_system_thread_count( void )
+{
+	int t = (int)sysconf(_SC_NPROCESSORS_ONLN);
+	if (t>RE_MAX_THREAD)
+		return RE_MAX_THREAD;
+	if (t<1)
+		return 1;
+	
+	return t;
+}
+
 /* eof */

Modified: trunk/blender/source/blender/makesdna/DNA_scene_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_scene_types.h	2008-02-19 21:18:35 UTC (rev 13773)
+++ trunk/blender/source/blender/makesdna/DNA_scene_types.h	2008-02-19 22:23:21 UTC (rev 13774)
@@ -573,8 +573,9 @@
 #define R_GAUSS      	0x20000
 		/* fbuf obsolete... */
 #define R_FBUF			0x40000
-		/* threads obsolete... is there for old files */
-#define R_THREADS		0x80000
+		/* threads obsolete... is there for old files, now use for autodetect threads */
+#define R_THREADS		0x80000 
+
 #define R_SPEED			0x100000
 #define R_SSS			0x200000
 #define R_NO_OVERWRITE	0x400000 /* skip existing files */

Modified: trunk/blender/source/blender/render/intern/source/pipeline.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/pipeline.c	2008-02-19 21:18:35 UTC (rev 13773)
+++ trunk/blender/source/blender/render/intern/source/pipeline.c	2008-02-19 22:23:21 UTC (rev 13774)
@@ -117,7 +117,7 @@
 Render R;
 
 /* commandline thread override */
-static int commandline_threads= 0;
+static int commandline_threads= -1;
 
 /* ********* alloc and free ******** */
 
@@ -1108,8 +1108,11 @@
 		/* we clip faces with a minimum of 2 pixel boundary outside of image border. see zbuf.c */
 		re->clipcrop= 1.0f + 2.0f/(float)(re->winx>re->winy?re->winy:re->winx);
 		
-		if(commandline_threads>0 && commandline_threads<=BLENDER_MAX_THREADS)
+		if (rd->mode & R_THREADS || commandline_threads == 0) { /* Automatic threads */
+			re->r.threads = BLI_system_thread_count();
+		} else if(commandline_threads >= 1 && commandline_threads<=BLENDER_MAX_THREADS) {
 			re->r.threads= commandline_threads;
+		}
 	}
 }
 
@@ -2651,8 +2654,11 @@
 
 void RE_set_max_threads(int threads)
 {
-	if(threads>0 && threads<=BLENDER_MAX_THREADS)
+	if (threads==0) {
+		commandline_threads = BLI_system_thread_count();
+	} else if(threads>=1 && threads<=BLENDER_MAX_THREADS) {
 		commandline_threads= threads;
-	else
+	} else {
 		printf("Error, threads has to be in range 1-%d\n", BLENDER_MAX_THREADS);
+	}
 }

Modified: trunk/blender/source/blender/src/buttons_scene.c
===================================================================
--- trunk/blender/source/blender/src/buttons_scene.c	2008-02-19 21:18:35 UTC (rev 13773)
+++ trunk/blender/source/blender/src/buttons_scene.c	2008-02-19 22:23:21 UTC (rev 13774)
@@ -2022,7 +2022,17 @@
 	}
 	uiBlockEndAlign(block);
 
-	uiDefButS(block, NUM, B_NOP, "Threads:",				10, 63, 100, 20, &G.scene->r.threads, 1, BLENDER_MAX_THREADS, 0, 0, "Amount of threads for render (takes advantage of multi-core and multi-processor computers)");
+	uiBlockBeginAlign(block);
+	uiDefIconButBitI(block, TOG, R_THREADS, B_REDR, ICON_AUTO,	10, 63, 20, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Automatic threads from system");
+	if (G.scene->r.mode & R_THREADS) {
+		char thread_str[32];
+		sprintf(thread_str, "Threads: %d", BLI_system_thread_count());
+		uiDefBut(block, LABEL, 0, thread_str, 30, 63,80,20, 0, 0, 0, 0, 0, "");
+	} else {
+		uiDefButS(block, NUM, B_NOP, "Threads:", 35, 63, 80, 20, &G.scene->r.threads, 1, BLENDER_MAX_THREADS, 0, 0, "Amount of threads for render (takes advantage of multi-core and multi-processor computers)");
+	}
+	uiBlockEndAlign(block);
+	
 	uiBlockSetCol(block, TH_AUTO);
 		
 	uiBlockBeginAlign(block);

Modified: trunk/blender/source/creator/creator.c
===================================================================
--- trunk/blender/source/creator/creator.c	2008-02-19 21:18:35 UTC (rev 13773)
+++ trunk/blender/source/creator/creator.c	2008-02-19 22:23:21 UTC (rev 13774)
@@ -200,15 +200,8 @@
 	printf ("    (formats that can be compiled into blender, not available on all systems)\n");
 	printf ("    \tHDR TIFF EXR MULTILAYER MPEG AVICODEC QUICKTIME CINEON DPX DDS\n");
 	printf ("    -x <bool>\tSet option to add the file extension to the end of the file.\n");
-	printf ("    -t <threads>\tUse amount of <threads> for rendering\n");
-	/*Add these later - Campbell*/
-	/*
-	printf ("    -colorchannel <type>\tColors to save, valid types are: BW RGB RGBA \n");
-	printf ("    -compression <type>\t Use with EXR format, valid types are..\n");
-	printf ("    \tZIP Pxr24 PIZ RLE\n");
-	printf ("    -zbuf <bool>\tUse with EXR format, set the zbuf save option\n");
-	printf ("    -halffloat <bool>\tUse with EXR format, set the half float option\n");
-	printf ("    -preview <bool>\tUse with EXR format, save a jpeg for viewing as well as the EXR\n");*/
+	printf ("    -t <threads>\tUse amount of <threads> for rendering.\n");
+	printf ("      [1-8], 0 for systems processor count.\n");
 	printf ("\nAnimation playback options:\n");
 	printf ("  -a <file(s)>\tPlayback <file(s)>, only operates this way when -b is not used.\n");
 	printf ("    -p <sx> <sy>\tOpen with lower left corner at <sx>, <sy>\n");





More information about the Bf-blender-cvs mailing list