From 82d769c79f5e18b5b33030c188e3b2b93f9a346b Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 19 Feb 2008 22:23:21 +0000 Subject: 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. --- source/blender/blenlib/BLI_threads.h | 1 + source/blender/blenlib/intern/threads.c | 13 +++++++++++++ source/blender/makesdna/DNA_scene_types.h | 5 +++-- source/blender/render/intern/source/pipeline.c | 14 ++++++++++---- source/blender/src/buttons_scene.c | 12 +++++++++++- 5 files changed, 38 insertions(+), 7 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_threads.h b/source/blender/blenlib/BLI_threads.h index 60ecce3f9d8..39162b8bd91 100644 --- a/source/blender/blenlib/BLI_threads.h +++ b/source/blender/blenlib/BLI_threads.h @@ -50,5 +50,6 @@ void BLI_end_threads (struct ListBase *threadbase); 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 diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 1f05070b034..d6048b4bade 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -32,6 +32,7 @@ #include #include #include +#include /* for checking system threads */ #include "MEM_guardedalloc.h" @@ -224,4 +225,16 @@ void BLI_unlock_thread(int type) 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 */ diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h index 7a577d22685..39e27667645 100644 --- a/source/blender/makesdna/DNA_scene_types.h +++ b/source/blender/makesdna/DNA_scene_types.h @@ -573,8 +573,9 @@ typedef struct Scene { #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 */ diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c index 177d7ec58e2..5de109a16f4 100644 --- a/source/blender/render/intern/source/pipeline.c +++ b/source/blender/render/intern/source/pipeline.c @@ -117,7 +117,7 @@ static struct ListBase RenderList= {NULL, NULL}; Render R; /* commandline thread override */ -static int commandline_threads= 0; +static int commandline_threads= -1; /* ********* alloc and free ******** */ @@ -1108,8 +1108,11 @@ void RE_InitState(Render *re, Render *source, RenderData *rd, int winx, int winy /* 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_ReadRenderResult(Scene *scene, Scene *scenode) 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); + } } diff --git a/source/blender/src/buttons_scene.c b/source/blender/src/buttons_scene.c index 055674097b0..7654bc44b75 100644 --- a/source/blender/src/buttons_scene.c +++ b/source/blender/src/buttons_scene.c @@ -2022,7 +2022,17 @@ static void render_panel_output(void) } 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); -- cgit v1.2.3