예제 #1
0
/**
 * Create new lp_rasterizer.  If num_threads is zero, don't create any
 * new threads, do rendering synchronously.
 * \param num_threads  number of rasterizer threads to create
 */
struct lp_rasterizer *
lp_rast_create( unsigned num_threads )
{
   struct lp_rasterizer *rast;
   unsigned i;

   rast = CALLOC_STRUCT(lp_rasterizer);
   if(!rast)
      return NULL;

   rast->full_scenes = lp_scene_queue_create();

   for (i = 0; i < Elements(rast->tasks); i++) {
      struct lp_rasterizer_task *task = &rast->tasks[i];
      task->rast = rast;
      task->thread_index = i;
   }

   rast->num_threads = num_threads;

   create_rast_threads(rast);

   /* for synchronizing rasterization threads */
   pipe_barrier_init( &rast->barrier, rast->num_threads );

   memset(lp_swizzled_cbuf, 0, sizeof lp_swizzled_cbuf);

   memset(lp_dummy_tile, 0, sizeof lp_dummy_tile);

   return rast;
}
예제 #2
0
파일: lp_rast.c 프로젝트: ndesh26/Mesa
/**
 * Create new lp_rasterizer.  If num_threads is zero, don't create any
 * new threads, do rendering synchronously.
 * \param num_threads  number of rasterizer threads to create
 */
struct lp_rasterizer *
lp_rast_create( unsigned num_threads )
{
   struct lp_rasterizer *rast;
   unsigned i;

   rast = CALLOC_STRUCT(lp_rasterizer);
   if (!rast) {
      goto no_rast;
   }

   rast->full_scenes = lp_scene_queue_create();
   if (!rast->full_scenes) {
      goto no_full_scenes;
   }

   for (i = 0; i < MAX2(1, num_threads); i++) {
      struct lp_rasterizer_task *task = &rast->tasks[i];
      task->rast = rast;
      task->thread_index = i;
      task->thread_data.cache = align_malloc(sizeof(struct lp_build_format_cache),
                                             16);
      if (!task->thread_data.cache) {
         goto no_thread_data_cache;
      }
   }

   rast->num_threads = num_threads;

   rast->no_rast = debug_get_bool_option("LP_NO_RAST", FALSE);

   create_rast_threads(rast);

   /* for synchronizing rasterization threads */
   if (rast->num_threads > 0) {
      pipe_barrier_init( &rast->barrier, rast->num_threads );
   }

   memset(lp_dummy_tile, 0, sizeof lp_dummy_tile);

   return rast;

no_thread_data_cache:
   for (i = 0; i < MAX2(1, rast->num_threads); i++) {
      if (rast->tasks[i].thread_data.cache) {
         align_free(rast->tasks[i].thread_data.cache);
      }
   }

   lp_scene_queue_destroy(rast->full_scenes);
no_full_scenes:
   FREE(rast);
no_rast:
   return NULL;
}
예제 #3
0
/**
 * Create new lp_rasterizer.  If num_threads is zero, don't create any
 * new threads, do rendering synchronously.
 * \param num_threads  number of rasterizer threads to create
 */
struct lp_rasterizer *
lp_rast_create( unsigned num_threads )
{
    struct lp_rasterizer *rast;
    unsigned i;

    rast = CALLOC_STRUCT(lp_rasterizer);
    if (!rast) {
        goto no_rast;
    }

    rast->full_scenes = lp_scene_queue_create();
    if (!rast->full_scenes) {
        goto no_full_scenes;
    }

    for (i = 0; i < Elements(rast->tasks); i++) {
        struct lp_rasterizer_task *task = &rast->tasks[i];
        task->rast = rast;
        task->thread_index = i;
    }

    rast->num_threads = num_threads;

    rast->no_rast = debug_get_bool_option("LP_NO_RAST", FALSE);

    create_rast_threads(rast);

    /* for synchronizing rasterization threads */
    pipe_barrier_init( &rast->barrier, rast->num_threads );

    memset(lp_swizzled_cbuf, 0, sizeof lp_swizzled_cbuf);

    memset(lp_dummy_tile, 0, sizeof lp_dummy_tile);

    return rast;

no_full_scenes:
    FREE(rast);
no_rast:
    return NULL;
}
int main(int argc, char *argv[])
{
   int i;

   for (i = 1; i < argc; ++i) {
      const char *arg = argv[i];
      if (strcmp(arg, "-v") == 0) {
         ++verbosity;
      } else {
         fprintf(stderr, "error: unrecognized option `%s`\n", arg);
         exit(EXIT_FAILURE);
      }
   }

   // Disable buffering
   setbuf(stdout, NULL);

   LOG("pipe_barrier_test starting\n");

   pipe_barrier_init(&barrier, NUM_THREADS);

   for (i = 0; i < NUM_THREADS; i++) {
      thread_ids[i] = i;
      threads[i] = u_thread_create(thread_function, (void *) &thread_ids[i]);
   }

   for (i = 0; i < NUM_THREADS; i++ ) {
      thrd_join(threads[i], NULL);
   }

   CHECK(p_atomic_read(&proceeded) == NUM_THREADS);

   pipe_barrier_destroy(&barrier);

   LOG("pipe_barrier_test exiting\n");

   return 0;
}
int main()
{
   int i;

   printf("pipe_barrier_test starting\n");

   pipe_barrier_init(&barrier, NUM_THREADS);

   for (i = 0; i < NUM_THREADS; i++) {
      thread_ids[i] = i;
      threads[i] = pipe_thread_create(thread_function, (void *) &thread_ids[i]);
   }

   for (i = 0; i < NUM_THREADS; i++ ) {
      pipe_thread_wait(threads[i]);
   }

   pipe_barrier_destroy(&barrier);

   printf("pipe_barrier_test exiting\n");

   return 0;
}