Merge branch 'gallium_draw_llvm'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_rast.c
index 0f83eea6853f815fb1b3dffcd73287d296f0223d..e629a3e5f1f6a07ea4e21632cfbbcb3352283238 100644 (file)
@@ -62,18 +62,20 @@ lp_rast_begin( struct lp_rasterizer *rast,
    rast->state.write_color = write_color;
    
    for (i = 0; i < rast->state.nr_cbufs; i++) {
+      struct pipe_surface *cbuf = scene->fb.cbufs[i];
       rast->cbuf[i].map = scene->cbuf_map[i];
-      rast->cbuf[i].format = scene->cbuf_transfer[i]->texture->format;
-      rast->cbuf[i].width = scene->cbuf_transfer[i]->width;
-      rast->cbuf[i].height = scene->cbuf_transfer[i]->height;
-      rast->cbuf[i].stride = scene->cbuf_transfer[i]->stride;
+      rast->cbuf[i].format = cbuf->texture->format;
+      rast->cbuf[i].width = cbuf->width;
+      rast->cbuf[i].height = cbuf->height;
+      rast->cbuf[i].stride = llvmpipe_texture_stride(cbuf->texture, cbuf->level);
    }
 
    if (write_zstencil) {
+      struct pipe_surface *zsbuf = scene->fb.zsbuf;
       rast->zsbuf.map = scene->zsbuf_map;
-      rast->zsbuf.stride = scene->zsbuf_transfer->stride;
+      rast->zsbuf.stride = llvmpipe_texture_stride(zsbuf->texture, zsbuf->level);
       rast->zsbuf.blocksize = 
-         util_format_get_blocksize(scene->zsbuf_transfer->texture->format);
+         util_format_get_blocksize(zsbuf->texture->format);
    }
 
    lp_scene_bin_iter_begin( scene );
@@ -187,7 +189,7 @@ lp_rast_clear_zstencil(struct lp_rasterizer_task *task,
 
    LP_DBG(DEBUG_RAST, "%s 0x%x\n", __FUNCTION__, arg.clear_zstencil);
 
-   assert(rast->zsbuf.map);
+   /*assert(rast->zsbuf.map);*/
    if (!rast->zsbuf.map)
       return;
 
@@ -310,15 +312,16 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task,
          depth = lp_rast_depth_pointer(rast, tile_x + x, tile_y + y);
 
          /* run shader */
-         state->jit_function[0]( &state->jit_context,
-                                 tile_x + x, tile_y + y,
-                                 inputs->a0,
-                                 inputs->dadx,
-                                 inputs->dady,
-                                 color,
-                                 depth,
-                                 INT_MIN, INT_MIN, INT_MIN,
-                                 NULL, NULL, NULL );
+         state->jit_function[RAST_WHOLE]( &state->jit_context,
+                                          tile_x + x, tile_y + y,
+                                          inputs->facing,
+                                          inputs->a0,
+                                          inputs->dadx,
+                                          inputs->dady,
+                                          color,
+                                          depth,
+                                          INT_MIN, INT_MIN, INT_MIN,
+                                          NULL, NULL, NULL );
       }
    }
 }
@@ -373,15 +376,18 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task,
    assert(lp_check_alignment(inputs->step[2], 16));
 
    /* run shader */
-   state->jit_function[1]( &state->jit_context,
-                        x, y,
-                        inputs->a0,
-                        inputs->dadx,
-                        inputs->dady,
-                        color,
-                        depth,
-                        c1, c2, c3,
-                        inputs->step[0], inputs->step[1], inputs->step[2]);
+   state->jit_function[RAST_EDGE_TEST]( &state->jit_context,
+                                        x, y,
+                                        inputs->facing,
+                                        inputs->a0,
+                                        inputs->dadx,
+                                        inputs->dady,
+                                        color,
+                                        depth,
+                                        c1, c2, c3,
+                                        inputs->step[0],
+                                        inputs->step[1],
+                                        inputs->step[2]);
 }
 
 
@@ -485,18 +491,7 @@ lp_rast_fence(struct lp_rasterizer_task *task,
               const union lp_rast_cmd_arg arg)
 {
    struct lp_fence *fence = arg.fence;
-
-   pipe_mutex_lock( fence->mutex );
-
-   fence->count++;
-   assert(fence->count <= fence->rank);
-
-   LP_DBG(DEBUG_RAST, "%s count=%u rank=%u\n", __FUNCTION__,
-          fence->count, fence->rank);
-
-   pipe_condvar_signal( fence->signalled );
-
-   pipe_mutex_unlock( fence->mutex );
+   lp_fence_signal(fence);
 }
 
 
@@ -773,8 +768,12 @@ create_rast_threads(struct lp_rasterizer *rast)
    /* 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
@@ -846,6 +845,12 @@ void lp_rast_destroy( struct lp_rasterizer *rast )
       pipe_semaphore_signal(&rast->tasks[i].work_ready);
    }
 
+   /* Wait for threads to terminate before cleaning up per-thread data */
+   for (i = 0; i < rast->num_threads; i++) {
+      pipe_thread_wait(rast->threads[i]);
+   }
+
+   /* Clean up per-thread data */
    for (i = 0; i < rast->num_threads; i++) {
       pipe_semaphore_destroy(&rast->tasks[i].work_ready);
       pipe_semaphore_destroy(&rast->tasks[i].work_done);