llvmpipe: handle more queries
authorRoland Scheidegger <sroland@vmware.com>
Wed, 19 Jun 2013 21:38:39 +0000 (23:38 +0200)
committerRoland Scheidegger <sroland@vmware.com>
Wed, 19 Jun 2013 21:47:36 +0000 (23:47 +0200)
Handle PIPE_QUERY_GPU_FINISHED and PIPE_QUERY_TIMESTAMP_DISJOINT, and
also fill out the ps_invocations and c_primitives from the
PIPE_QUERY_PIPELINE_STATISTICS (the others in there should already
be handled). Note that ps_invocations isn't pixel exact, just 16 pixel
exact but I guess it's better than nothing.
Doesn't really seem to work correctly but there's probably bugs elsewhere.

Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/drivers/llvmpipe/lp_query.c
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_rast_priv.h
src/gallium/drivers/llvmpipe/lp_setup.c
src/gallium/drivers/llvmpipe/lp_setup_line.c
src/gallium/drivers/llvmpipe/lp_setup_point.c
src/gallium/drivers/llvmpipe/lp_setup_tri.c

index 922913d743110da15652ea0029c8cccb52bf7c05..386639e5367b5e57120fc9027124df218e0a0aa6 100644 (file)
@@ -40,6 +40,7 @@
 #include "lp_query.h"
 #include "lp_screen.h"
 #include "lp_state.h"
+#include "lp_rast.h"
 
 
 static struct llvmpipe_query *llvmpipe_query( struct pipe_query *p )
@@ -128,7 +129,7 @@ llvmpipe_get_query_result(struct pipe_context *pipe,
    case PIPE_QUERY_OCCLUSION_PREDICATE:
       for (i = 0; i < num_threads; i++) {
          /* safer (still not guaranteed) when there's an overflow */
-         *result = *result || pq->count[i];
+         vresult->b = vresult->b || pq->count[i];
       }
       break;
    case PIPE_QUERY_TIMESTAMP:
@@ -140,6 +141,17 @@ llvmpipe_get_query_result(struct pipe_context *pipe,
             *result = os_time_get_nano();
       }
       break;
+   case PIPE_QUERY_TIMESTAMP_DISJOINT: {
+      struct pipe_query_data_timestamp_disjoint *td =
+         (struct pipe_query_data_timestamp_disjoint *)vresult;
+      /* os_get_time_nano return nanoseconds */
+      td->frequency = UINT64_C(1000000000);
+      td->disjoint = FALSE;
+   }
+      break;
+   case PIPE_QUERY_GPU_FINISHED:
+      vresult->b = TRUE;
+      break;
    case PIPE_QUERY_PRIMITIVES_GENERATED:
       *result = pq->num_primitives_generated;
       break;
@@ -147,7 +159,7 @@ llvmpipe_get_query_result(struct pipe_context *pipe,
       *result = pq->num_primitives_written;
       break;
    case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
-      *result = pq->so_has_overflown;
+      vresult->b = pq->so_has_overflown;
       break;
    case PIPE_QUERY_SO_STATISTICS: {
       struct pipe_query_data_so_statistics *stats =
@@ -159,6 +171,11 @@ llvmpipe_get_query_result(struct pipe_context *pipe,
    case PIPE_QUERY_PIPELINE_STATISTICS: {
       struct pipe_query_data_pipeline_statistics *stats =
          (struct pipe_query_data_pipeline_statistics *)vresult;
+      /* only ps_invocations come from binned query */
+      for (i = 0; i < num_threads; i++) {
+         pq->stats.ps_invocations += pq->count[i];
+      }
+      pq->stats.ps_invocations *= LP_RASTER_BLOCK_SIZE * LP_RASTER_BLOCK_SIZE;
       *stats = pq->stats;
    }
       break;
index d802d53f7cae46a1920b35b1f0a22ae88f4a4dd7..62a82e307882209f51bf7af4d520c871f4537e84 100644 (file)
@@ -455,6 +455,10 @@ lp_rast_shade_quads_mask(struct lp_rasterizer_task *task,
     * allocated 4x4 blocks hence need to filter them out here.
     */
    if ((x % TILE_SIZE) < task->width && (y % TILE_SIZE) < task->height) {
+      if (task->query[PIPE_QUERY_PIPELINE_STATISTICS]) {
+         /* not very accurate would need a popcount on the mask */
+         task->ps_invocations++;
+      }
       /* run shader on 4x4 block */
       BEGIN_JIT_CALL(state, task);
       variant->jit_function[RAST_EDGE_TEST](&state->jit_context,
@@ -493,11 +497,14 @@ lp_rast_begin_query(struct lp_rasterizer_task *task,
    case PIPE_QUERY_OCCLUSION_PREDICATE:
       task->thread_data.vis_counter = 0;
       break;
+   case PIPE_QUERY_PIPELINE_STATISTICS:
+      task->ps_invocations = 0;
+      break;
    case PIPE_QUERY_PRIMITIVES_GENERATED:
    case PIPE_QUERY_PRIMITIVES_EMITTED:
    case PIPE_QUERY_SO_STATISTICS:
-   case PIPE_QUERY_PIPELINE_STATISTICS:
    case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
+   case PIPE_QUERY_TIMESTAMP_DISJOINT:
       break;
    default:
       assert(0);
@@ -518,7 +525,9 @@ lp_rast_end_query(struct lp_rasterizer_task *task,
                   const union lp_rast_cmd_arg arg)
 {
    struct llvmpipe_query *pq = arg.query_obj;
-   assert(task->query[pq->type] == pq || pq->type == PIPE_QUERY_TIMESTAMP);
+   assert(task->query[pq->type] == pq ||
+          pq->type == PIPE_QUERY_TIMESTAMP ||
+          pq->type == PIPE_QUERY_GPU_FINISHED);
 
    switch (pq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
@@ -528,11 +537,15 @@ lp_rast_end_query(struct lp_rasterizer_task *task,
    case PIPE_QUERY_TIMESTAMP:
       pq->count[task->thread_index] = os_time_get_nano();
       break;
+   case PIPE_QUERY_PIPELINE_STATISTICS:
+      pq->count[task->thread_index] += task->ps_invocations;
+      break;
    case PIPE_QUERY_PRIMITIVES_GENERATED:
    case PIPE_QUERY_PRIMITIVES_EMITTED:
    case PIPE_QUERY_SO_STATISTICS:
-   case PIPE_QUERY_PIPELINE_STATISTICS:
    case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
+   case PIPE_QUERY_TIMESTAMP_DISJOINT:
+   case PIPE_QUERY_GPU_FINISHED:
       break;
    default:
       assert(0);
index 6f03023eafe721af743436aa4c151ab4f60e631e..30489407cdf3f74be9849e767006c89f880c4476 100644 (file)
@@ -99,8 +99,8 @@ struct lp_rasterizer_task
 
    /* occlude counter for visible pixels */
    struct lp_jit_thread_data thread_data;
-   uint64_t query_start;
    struct llvmpipe_query *query[PIPE_QUERY_TYPES];
+   uint64_t ps_invocations;
 
    pipe_semaphore work_ready;
    pipe_semaphore work_done;
@@ -307,6 +307,10 @@ lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
     * allocated 4x4 blocks hence need to filter them out here.
     */
    if ((x % TILE_SIZE) < task->width && (y % TILE_SIZE) < task->height) {
+      if (task->query[PIPE_QUERY_PIPELINE_STATISTICS]) {
+         /* not very accurate would need a popcount on the mask */
+         task->ps_invocations++;
+      }
       /* run shader on 4x4 block */
       BEGIN_JIT_CALL(state, task);
       variant->jit_function[RAST_WHOLE]( &state->jit_context,
index e2fb257e1c110eca34784a516e2d1215872cff54..6b644460cd37a14fba29913b40e91759247b288d 100644 (file)
@@ -1215,7 +1215,7 @@ lp_setup_begin_query(struct lp_setup_context *setup,
    assert(setup->active_query[pq->type] == NULL);
 
    set_scene_state(setup, SETUP_ACTIVE, "begin_query");
-   
+
    setup->active_query[pq->type] = pq;
 
    /* XXX: It is possible that a query is created before the scene
@@ -1249,7 +1249,7 @@ lp_setup_end_query(struct lp_setup_context *setup, struct llvmpipe_query *pq)
 {
    set_scene_state(setup, SETUP_ACTIVE, "end_query");
 
-   if (pq->type != PIPE_QUERY_TIMESTAMP) {
+   if (pq->type != PIPE_QUERY_TIMESTAMP && pq->type != PIPE_QUERY_GPU_FINISHED) {
       assert(setup->active_query[pq->type] == pq);
       setup->active_query[pq->type] = NULL;
    }
index a9809a0ed12f2d7b01386192f3afec77f94fcfa8..4b59bf38692f9fde3fcc70dc144a2ee0a8d18e7c 100644 (file)
@@ -36,6 +36,7 @@
 #include "lp_rast.h"
 #include "lp_state_fs.h"
 #include "lp_state_setup.h"
+#include "lp_context.h"
 
 #define NUM_CHANNELS 4
 
@@ -541,11 +542,6 @@ try_setup_line( struct lp_setup_context *setup,
       y[3] = subpixel_snap(v1[0][1] + y_offset     - setup->pixel_offset);
    }
 
-
-
-   LP_COUNT(nr_tris);
-
    /* Bounding rectangle (in pixels) */
    {
       /* Yes this is necessary to accurately calculate bounding boxes
@@ -598,6 +594,13 @@ try_setup_line( struct lp_setup_context *setup,
    line->v[1][1] = v2[0][1];
 #endif
 
+   LP_COUNT(nr_tris);
+
+   if (setup->active_query[PIPE_QUERY_PIPELINE_STATISTICS]) {
+      struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
+      lp_context->pipeline_statistics.c_primitives++;
+   }
+
    /* calculate the deltas */
    plane = GET_PLANES(line);
    plane[0].dcdy = x[0] - x[1];
index 789caa80761b49409789c08534086d7b7c1ce8af..7fe7bc56d2bb0ac0de8a8151a25cf6e36907ee77 100644 (file)
  * Binning code for points
  */
 
-#include "lp_setup_context.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
+#include "lp_setup_context.h"
 #include "lp_perf.h"
 #include "lp_rast.h"
 #include "lp_state_fs.h"
 #include "lp_state_setup.h"
+#include "lp_context.h"
 #include "tgsi/tgsi_scan.h"
 
 #define NUM_CHANNELS 4
@@ -376,6 +377,13 @@ try_setup_point( struct lp_setup_context *setup,
    point->v[0][1] = v0[0][1];
 #endif
 
+   LP_COUNT(nr_tris);
+
+   if (setup->active_query[PIPE_QUERY_PIPELINE_STATISTICS]) {
+      struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
+      lp_context->pipeline_statistics.c_primitives++;
+   }
+
    info.v0 = v0;
    info.dx01 = 0;
    info.dx12 = fixed_width;
index 2ca47bca43efb66451d6a6fd34c0821f0b49f204..bedd16beee1e1f80eb2665057d1e24f18c080064 100644 (file)
@@ -38,6 +38,7 @@
 #include "lp_rast.h"
 #include "lp_state_fs.h"
 #include "lp_state_setup.h"
+#include "lp_context.h"
 
 #define NUM_CHANNELS 4
 
@@ -333,6 +334,11 @@ do_triangle_ccw(struct lp_setup_context *setup,
 
    LP_COUNT(nr_tris);
 
+   if (setup->active_query[PIPE_QUERY_PIPELINE_STATISTICS]) {
+      struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
+      lp_context->pipeline_statistics.c_primitives++;
+   }
+
    /* Setup parameter interpolants:
     */
    setup->setup.variant->jit_function( v0,
@@ -883,6 +889,8 @@ typedef void (*triangle_func_t)(struct lp_setup_context *setup,
 /**
  * Subdivide this triangle by bisecting edge (v0, v1).
  * \param pv  the provoking vertex (must = v0 or v1 or v2)
+ * TODO: should probably think about non-overflowing arithmetic elsewhere.
+ * This will definitely screw with pipeline counters for instance.
  */
 static void
 subdiv_tri(struct lp_setup_context *setup,