llvmpipe: Use struct lp_shader_input in the interpolator.
[mesa.git] / src / gallium / drivers / llvmpipe / lp_rast.c
index a00a592f2fe120d6fe4b7f272a1244f7eb02daef..386387b3a53f84f17412c84b575667bedd07d903 100644 (file)
@@ -34,6 +34,7 @@
 #include "lp_debug.h"
 #include "lp_fence.h"
 #include "lp_perf.h"
+#include "lp_query.h"
 #include "lp_rast.h"
 #include "lp_rast_priv.h"
 #include "lp_tile_soa.h"
@@ -60,16 +61,12 @@ lp_rast_begin( struct lp_rasterizer *rast,
    
    for (i = 0; i < rast->state.nr_cbufs; i++) {
       struct pipe_surface *cbuf = scene->fb.cbufs[i];
-      rast->cbuf[i].format = cbuf->texture->format;
-      rast->cbuf[i].tiles_per_row = align(cbuf->width, TILE_SIZE) / TILE_SIZE;
-      rast->cbuf[i].blocksize = 
-         util_format_get_blocksize(cbuf->texture->format);
-      rast->cbuf[i].map = llvmpipe_resource_map(cbuf->texture,
-                                               cbuf->face,
-                                               cbuf->level,
-                                               cbuf->zslice,
-                                               LP_TEX_USAGE_READ_WRITE,
-                                               LP_TEX_LAYOUT_NONE);
+      llvmpipe_resource_map(cbuf->texture,
+                            cbuf->face,
+                            cbuf->level,
+                            cbuf->zslice,
+                            LP_TEX_USAGE_READ_WRITE,
+                            LP_TEX_LAYOUT_NONE);
    }
 
    if (fb->zsbuf) {
@@ -104,7 +101,6 @@ lp_rast_end( struct lp_rasterizer *rast )
                              cbuf->face,
                              cbuf->level,
                              cbuf->zslice);
-      rast->cbuf[i].map = NULL;
    }
 
    /* Unmap z/stencil buffer */
@@ -412,6 +408,7 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task,
    struct lp_rasterizer *rast = task->rast;
    const struct lp_rast_state *state = task->current_state;
    const struct lp_rast_shader_inputs *inputs = arg.shade_tile;
+   struct lp_fragment_shader_variant *variant = state->variant;
    const unsigned tile_x = task->x, tile_y = task->y;
    unsigned x, y;
 
@@ -433,7 +430,7 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task,
          depth = lp_rast_get_depth_block_pointer(rast, tile_x + x, tile_y + y);
 
          /* run shader on 4x4 block */
-         state->jit_function[RAST_WHOLE]( &state->jit_context,
+         variant->jit_function[RAST_WHOLE]( &state->jit_context,
                                           tile_x + x, tile_y + y,
                                           inputs->facing,
                                           inputs->a0,
@@ -442,7 +439,7 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task,
                                           color,
                                           depth,
                                           INT_MIN, INT_MIN, INT_MIN,
-                                          NULL, NULL, NULL );
+                                          NULL, NULL, NULL, &task->vis_counter);
       }
    }
 }
@@ -460,6 +457,7 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task,
                           int32_t c1, int32_t c2, int32_t c3)
 {
    const struct lp_rast_state *state = task->current_state;
+   struct lp_fragment_shader_variant *variant = state->variant;
    struct lp_rasterizer *rast = task->rast;
    uint8_t *color[PIPE_MAX_COLOR_BUFS];
    void *depth;
@@ -491,7 +489,7 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task,
    assert(lp_check_alignment(inputs->step[2], 16));
 
    /* run shader on 4x4 block */
-   state->jit_function[RAST_EDGE_TEST]( &state->jit_context,
+   variant->jit_function[RAST_EDGE_TEST]( &state->jit_context,
                                         x, y,
                                         inputs->facing,
                                         inputs->a0,
@@ -502,7 +500,8 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task,
                                         c1, c2, c3,
                                         inputs->step[0],
                                         inputs->step[1],
-                                        inputs->step[2]);
+                                        inputs->step[2],
+                                       &task->vis_counter);
 }
 
 
@@ -565,18 +564,20 @@ outline_subtiles(uint8_t *tile)
 static void
 lp_rast_tile_end(struct lp_rasterizer_task *task)
 {
-#if DEBUG
-   struct lp_rasterizer *rast = task->rast;
-   unsigned buf;
-
-   for (buf = 0; buf < rast->state.nr_cbufs; buf++) {
-      uint8_t *color = lp_rast_get_color_block_pointer(task, buf,
-                                                       task->x, task->y);
-
-      if (LP_DEBUG & DEBUG_SHOW_SUBTILES)
-         outline_subtiles(color);
-      else if (LP_DEBUG & DEBUG_SHOW_TILES)
-         outline_tile(color);
+#ifdef DEBUG
+   if (LP_DEBUG & (DEBUG_SHOW_SUBTILES | DEBUG_SHOW_TILES)) {
+      struct lp_rasterizer *rast = task->rast;
+      unsigned buf;
+
+      for (buf = 0; buf < rast->state.nr_cbufs; buf++) {
+         uint8_t *color = lp_rast_get_color_block_pointer(task, buf,
+                                                          task->x, task->y);
+
+         if (LP_DEBUG & DEBUG_SHOW_SUBTILES)
+            outline_subtiles(color);
+         else if (LP_DEBUG & DEBUG_SHOW_TILES)
+            outline_tile(color);
+      }
    }
 #else
    (void) outline_subtiles;
@@ -602,6 +603,60 @@ lp_rast_fence(struct lp_rasterizer_task *task,
 }
 
 
+/**
+ * Begin a new occlusion query.
+ * This is a bin command put in all bins.
+ * Called per thread.
+ */
+void
+lp_rast_begin_query(struct lp_rasterizer_task *task,
+                    const union lp_rast_cmd_arg arg)
+{
+   /* Reset the the per-task counter */
+   task->vis_counter = 0;
+}
+
+/**
+ * End the current occlusion query.
+ * This is a bin command put in all bins.
+ * Called per thread.
+ */
+void
+lp_rast_end_query(struct lp_rasterizer_task *task,
+                  const union lp_rast_cmd_arg arg)
+{
+   struct llvmpipe_query *pq = arg.query_obj;
+
+   pipe_mutex_lock(pq->mutex);
+   {
+      /* Accumulate the visible fragment counter from this tile in
+       * the query object.
+       */
+      pq->count[task->thread_index] += task->vis_counter;
+
+      /* check if this is the last tile in the scene */
+      pq->tile_count++;
+      if (pq->tile_count == pq->num_tiles) {
+         uint i;
+
+         /* sum the per-thread counters for the query */
+         pq->result = 0;
+         for (i = 0; i < LP_MAX_THREADS; i++) {
+            pq->result += pq->count[i];
+         }
+
+         /* reset counters (in case this query is re-used in the scene) */
+         memset(pq->count, 0, sizeof(pq->count));
+
+         pq->tile_count = 0;
+         pq->binned = FALSE;
+         pq->done = TRUE;
+      }
+   }
+   pipe_mutex_unlock(pq->mutex);
+}
+
 
 
 /**
@@ -650,6 +705,8 @@ static struct {
    RAST(set_state),
    RAST(store_color),
    RAST(fence),
+   RAST(begin_query),
+   RAST(end_query),
 };
 
 static void
@@ -956,3 +1013,5 @@ lp_rast_get_num_threads( struct lp_rasterizer *rast )
 {
    return rast->num_threads;
 }
+
+