llvmpipe: Move the determination of the number of threads to the screen.

This commit is contained in:
José Fonseca 2010-04-24 13:20:39 +01:00
parent e7a8cfc877
commit 39be50dcde
8 changed files with 36 additions and 25 deletions

View file

@ -58,4 +58,7 @@
#define LP_MAX_WIDTH (1 << (LP_MAX_TEXTURE_LEVELS - 1)) #define LP_MAX_WIDTH (1 << (LP_MAX_TEXTURE_LEVELS - 1))
#define LP_MAX_THREADS 8
#endif /* LP_LIMITS_H */ #endif /* LP_LIMITS_H */

View file

@ -869,20 +869,6 @@ create_rast_threads(struct lp_rasterizer *rast)
{ {
unsigned i; unsigned i;
#ifdef PIPE_OS_WINDOWS
/* Multithreading not supported on windows until conditions and barriers are
* properly implemented. */
rast->num_threads = 0;
#else
#ifdef PIPE_OS_EMBEDDED
rast->num_threads = 0;
#else
rast->num_threads = util_cpu_caps.nr_cpus;
#endif
rast->num_threads = debug_get_num_option("LP_NUM_THREADS", rast->num_threads);
rast->num_threads = MIN2(rast->num_threads, MAX_THREADS);
#endif
/* NOTE: if num_threads is zero, we won't use any threads */ /* NOTE: if num_threads is zero, we won't use any threads */
for (i = 0; i < rast->num_threads; i++) { for (i = 0; i < rast->num_threads; i++) {
pipe_semaphore_init(&rast->tasks[i].work_ready, 0); pipe_semaphore_init(&rast->tasks[i].work_ready, 0);
@ -900,7 +886,7 @@ create_rast_threads(struct lp_rasterizer *rast)
* processing them. * processing them.
*/ */
struct lp_rasterizer * struct lp_rasterizer *
lp_rast_create( void ) lp_rast_create( unsigned num_threads )
{ {
struct lp_rasterizer *rast; struct lp_rasterizer *rast;
unsigned i; unsigned i;
@ -917,6 +903,8 @@ lp_rast_create( void )
task->thread_index = i; task->thread_index = i;
} }
rast->num_threads = num_threads;
create_rast_threads(rast); create_rast_threads(rast);
/* for synchronizing rasterization threads */ /* for synchronizing rasterization threads */

View file

@ -134,7 +134,7 @@ struct lp_rast_triangle {
struct lp_rasterizer * struct lp_rasterizer *
lp_rast_create( void ); lp_rast_create( unsigned num_threads );
void void
lp_rast_destroy( struct lp_rasterizer * ); lp_rast_destroy( struct lp_rasterizer * );

View file

@ -35,9 +35,7 @@
#include "lp_scene.h" #include "lp_scene.h"
#include "lp_texture.h" #include "lp_texture.h"
#include "lp_tile_soa.h" #include "lp_tile_soa.h"
#include "lp_limits.h"
#define MAX_THREADS 8 /* XXX probably temporary here */
struct lp_rasterizer; struct lp_rasterizer;
@ -113,10 +111,10 @@ struct lp_rasterizer
struct lp_scene *curr_scene; struct lp_scene *curr_scene;
/** A task object for each rasterization thread */ /** A task object for each rasterization thread */
struct lp_rasterizer_task tasks[MAX_THREADS]; struct lp_rasterizer_task tasks[LP_MAX_THREADS];
unsigned num_threads; unsigned num_threads;
pipe_thread threads[MAX_THREADS]; pipe_thread threads[LP_MAX_THREADS];
/** For synchronizing the rasterization threads */ /** For synchronizing the rasterization threads */
pipe_barrier barrier; pipe_barrier barrier;

View file

@ -27,6 +27,8 @@
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_math.h"
#include "util/u_cpu_detect.h"
#include "util/u_format.h" #include "util/u_format.h"
#include "util/u_format_s3tc.h" #include "util/u_format_s3tc.h"
#include "pipe/p_defines.h" #include "pipe/p_defines.h"
@ -39,6 +41,7 @@
#include "lp_context.h" #include "lp_context.h"
#include "lp_debug.h" #include "lp_debug.h"
#include "lp_public.h" #include "lp_public.h"
#include "lp_limits.h"
#include "state_tracker/sw_winsys.h" #include "state_tracker/sw_winsys.h"
@ -284,12 +287,26 @@ llvmpipe_create_screen(struct sw_winsys *winsys)
screen->base.context_create = llvmpipe_create_context; screen->base.context_create = llvmpipe_create_context;
screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer; screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer;
util_format_s3tc_init();
llvmpipe_init_screen_resource_funcs(&screen->base); llvmpipe_init_screen_resource_funcs(&screen->base);
llvmpipe_init_screen_fence_funcs(&screen->base); llvmpipe_init_screen_fence_funcs(&screen->base);
lp_jit_screen_init(screen); lp_jit_screen_init(screen);
#ifdef PIPE_OS_WINDOWS
/* Multithreading not supported on windows until conditions and barriers are
* properly implemented. */
screen->num_threads = 0;
#else
#ifdef PIPE_OS_EMBEDDED
screen->num_threads = 0;
#else
screen->num_threads = util_cpu_caps.nr_cpus;
#endif
screen->num_threads = debug_get_num_option("LP_NUM_THREADS", screen->num_threads);
screen->num_threads = MIN2(screen->num_threads, LP_MAX_THREADS);
#endif
util_format_s3tc_init();
return &screen->base; return &screen->base;
} }

View file

@ -58,6 +58,8 @@ struct llvmpipe_screen
LLVMTypeRef context_ptr_type; LLVMTypeRef context_ptr_type;
unsigned num_threads;
/* Increments whenever textures are modified. Contexts can track /* Increments whenever textures are modified. Contexts can track
* this. * this.
*/ */

View file

@ -765,8 +765,9 @@ struct lp_setup_context *
lp_setup_create( struct pipe_context *pipe, lp_setup_create( struct pipe_context *pipe,
struct draw_context *draw ) struct draw_context *draw )
{ {
unsigned i; struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen);
struct lp_setup_context *setup = CALLOC_STRUCT(lp_setup_context); struct lp_setup_context *setup = CALLOC_STRUCT(lp_setup_context);
unsigned i;
if (!setup) if (!setup)
return NULL; return NULL;
@ -779,7 +780,8 @@ lp_setup_create( struct pipe_context *pipe,
/* XXX: move this to the screen and share between contexts: /* XXX: move this to the screen and share between contexts:
*/ */
setup->rast = lp_rast_create(); setup->num_threads = screen->num_threads;
setup->rast = lp_rast_create(screen->num_threads);
if (!setup->rast) if (!setup->rast)
goto fail; goto fail;

View file

@ -80,6 +80,7 @@ struct lp_setup_context
* create/install this itself now. * create/install this itself now.
*/ */
struct draw_stage *vbuf; struct draw_stage *vbuf;
unsigned num_threads;
struct lp_rasterizer *rast; struct lp_rasterizer *rast;
struct lp_scene *scenes[MAX_SCENES]; /**< all the scenes */ struct lp_scene *scenes[MAX_SCENES]; /**< all the scenes */
struct lp_scene *scene; /**< current scene being built */ struct lp_scene *scene; /**< current scene being built */