llvmpipe: add support for nested / overlapping queries
authorRoland Scheidegger <sroland@vmware.com>
Wed, 26 Jun 2013 21:11:03 +0000 (23:11 +0200)
committerRoland Scheidegger <sroland@vmware.com>
Wed, 26 Jun 2013 21:17:53 +0000 (23:17 +0200)
OpenGL doesn't support this but d3d10 does.
It is a bit of a pain as it is necessary to keep track of queries
still active at the end of a scene, which is also why I cheat a bit
and limit the amount of simultaneously active queries to (arbitrary)
16 (simplifies things because don't have to deal with a real list
that way). I can't think of a reason why you'd really want large
numbers of overlapping/nested queries so it is hopefully fine.
(This only affects queries which need to be binned.)

v2: don't copy remainder of array when deleting an entry simply replace
the deleted entry with the last one (order doesn't matter).

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

index ab520019f826d7c20b3d15f94cd3d83e54db6b47..9495e42feee008d3dd982dfcbc4be97760b1a391 100644 (file)
@@ -97,9 +97,9 @@ struct llvmpipe_context {
    struct pipe_query_data_pipeline_statistics pipeline_statistics;
    unsigned active_statistics_queries;
 
-   unsigned dirty; /**< Mask of LP_NEW_x flags */
+   unsigned active_occlusion_queries;
 
-   unsigned active_occlusion_query;
+   unsigned dirty; /**< Mask of LP_NEW_x flags */
 
    /** Mapped vertex buffers */
    ubyte *mapped_vbuffer[PIPE_MAX_ATTRIBS];
index 38d6b84b8d79bf37579bad63a2eaf932d062f456..ac6d09d9a0f260fbceabba37efc9feeefa8c09ec 100644 (file)
@@ -233,7 +233,7 @@ llvmpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q)
       break;
    case PIPE_QUERY_OCCLUSION_COUNTER:
    case PIPE_QUERY_OCCLUSION_PREDICATE:
-      llvmpipe->active_occlusion_query++;
+      llvmpipe->active_occlusion_queries++;
       llvmpipe->dirty |= LP_NEW_OCCLUSION_QUERY;
       break;
    default:
@@ -288,8 +288,8 @@ llvmpipe_end_query(struct pipe_context *pipe, struct pipe_query *q)
       break;
    case PIPE_QUERY_OCCLUSION_COUNTER:
    case PIPE_QUERY_OCCLUSION_PREDICATE:
-      assert(llvmpipe->active_occlusion_query);
-      llvmpipe->active_occlusion_query--;
+      assert(llvmpipe->active_occlusion_queries);
+      llvmpipe->active_occlusion_queries--;
       llvmpipe->dirty |= LP_NEW_OCCLUSION_QUERY;
       break;
    default:
index 50917a7c633ae1e9975ab538701ed19d912bdd4e..e6e44c58262841796bbe933e9b1f974a98e329f1 100644 (file)
@@ -53,6 +53,8 @@ struct cmd_bin;
 /* Rasterizer output size going to jit fs, width/height */
 #define LP_RASTER_BLOCK_SIZE 4
 
+#define LP_MAX_ACTIVE_BINNED_QUERIES 16
+
 
 struct lp_rasterizer_task;
 
index 16f69698ed09f13d71781b76d44f8ccf9c620ba6..59cce7d18f44f2194ea8d8afe94a71db7980a4f2 100644 (file)
@@ -130,7 +130,7 @@ struct lp_scene {
    struct lp_fence *fence;
 
    /* The queries still active at end of scene */
-   struct llvmpipe_query *active_queries[3];
+   struct llvmpipe_query *active_queries[LP_MAX_ACTIVE_BINNED_QUERIES];
    unsigned num_active_queries;
 
    /* Framebuffer mappings - valid only between begin_rasterization()
index d2c53255259306f429e57f9fd4608f890eb8b406..49aead2c1fa57bd9eda66eb53181f4f06156247b 100644 (file)
@@ -155,22 +155,9 @@ lp_setup_rasterize_scene( struct lp_setup_context *setup )
    struct lp_scene *scene = setup->scene;
    struct llvmpipe_screen *screen = llvmpipe_screen(scene->pipe->screen);
 
-   scene->num_active_queries = 0;
-   if (setup->active_query[PIPE_QUERY_OCCLUSION_COUNTER]) {
-      scene->active_queries[scene->num_active_queries] =
-         setup->active_query[PIPE_QUERY_OCCLUSION_COUNTER];
-      scene->num_active_queries++;
-   }
-   if (setup->active_query[PIPE_QUERY_OCCLUSION_PREDICATE]) {
-      scene->active_queries[scene->num_active_queries] =
-         setup->active_query[PIPE_QUERY_OCCLUSION_PREDICATE];
-      scene->num_active_queries++;
-   }
-   if (setup->active_query[PIPE_QUERY_PIPELINE_STATISTICS]) {
-      scene->active_queries[scene->num_active_queries] =
-         setup->active_query[PIPE_QUERY_PIPELINE_STATISTICS];
-      scene->num_active_queries++;
-   }
+   scene->num_active_queries = setup->active_binned_queries;
+   memcpy(scene->active_queries, setup->active_queries,
+          scene->num_active_queries * sizeof(scene->active_queries[0]));
 
    lp_scene_end_binning(scene);
 
@@ -1226,9 +1213,14 @@ lp_setup_begin_query(struct lp_setup_context *setup,
       return;
 
    /* init the query to its beginning state */
-   assert(setup->active_query[pq->type] == NULL);
-
-   setup->active_query[pq->type] = pq;
+   assert(setup->active_binned_queries < LP_MAX_ACTIVE_BINNED_QUERIES);
+   /* exceeding list size so just ignore the query */
+   if (setup->active_binned_queries >= LP_MAX_ACTIVE_BINNED_QUERIES) {
+      return;
+   }
+   assert(setup->active_queries[setup->active_binned_queries] == NULL);
+   setup->active_queries[setup->active_binned_queries] = pq;
+   setup->active_binned_queries++;
 
    assert(setup->scene);
    if (setup->scene) {
@@ -1257,12 +1249,6 @@ 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_OCCLUSION_COUNTER ||
-       pq->type == PIPE_QUERY_OCCLUSION_PREDICATE ||
-       pq->type == PIPE_QUERY_PIPELINE_STATISTICS) {
-      assert(setup->active_query[pq->type] == pq);
-   }
-
    assert(setup->scene);
    if (setup->scene) {
       /* pq->fence should be the fence of the *last* scene which
@@ -1296,7 +1282,23 @@ fail:
    /* Need to do this now not earlier since it still needs to be marked as
     * active when binning it would cause a flush.
     */
-   setup->active_query[pq->type] = NULL;
+   if (pq->type == PIPE_QUERY_OCCLUSION_COUNTER ||
+      pq->type == PIPE_QUERY_OCCLUSION_PREDICATE ||
+      pq->type == PIPE_QUERY_PIPELINE_STATISTICS) {
+      unsigned i;
+
+      /* remove from active binned query list */
+      for (i = 0; i < setup->active_binned_queries; i++) {
+         if (setup->active_queries[i] == pq)
+            break;
+      }
+      assert(i < setup->active_binned_queries);
+      if (i == setup->active_binned_queries)
+         return;
+      setup->active_binned_queries--;
+      setup->active_queries[i] = setup->active_queries[setup->active_binned_queries];
+      setup->active_queries[setup->active_binned_queries] = NULL;
+   }
 }
 
 
index cc2b97390c0cc16dd243c04ecdc1f3722159379f..89c23bbb3ac9e1631a93778f34329b084b012f14 100644 (file)
@@ -89,7 +89,8 @@ struct lp_setup_context
    struct lp_scene *scene;               /**< current scene being built */
 
    struct lp_fence *last_fence;
-   struct llvmpipe_query *active_query[PIPE_QUERY_TYPES];
+   struct llvmpipe_query *active_queries[LP_MAX_ACTIVE_BINNED_QUERIES];
+   unsigned active_binned_queries;
 
    boolean subdivide_large_triangles;
    boolean flatshade_first;
index 4b59bf38692f9fde3fcc70dc144a2ee0a8d18e7c..bfed59cba0aebe5638f0a53b6e952b65bf649b88 100644 (file)
@@ -278,6 +278,7 @@ try_setup_line( struct lp_setup_context *setup,
                const float (*v1)[4],
                const float (*v2)[4])
 {
+   struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
    struct lp_scene *scene = setup->scene;
    const struct lp_setup_variant_key *key = &setup->setup.variant->key;
    struct lp_rast_triangle *line;
@@ -596,8 +597,7 @@ try_setup_line( 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;
+   if (lp_context->active_statistics_queries) {
       lp_context->pipeline_statistics.c_primitives++;
    }
 
index 7fe7bc56d2bb0ac0de8a8151a25cf6e36907ee77..868a9a904b725cf3f06de24b2508b8b0736cea7a 100644 (file)
@@ -303,6 +303,7 @@ static boolean
 try_setup_point( struct lp_setup_context *setup,
                  const float (*v0)[4] )
 {
+   struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
    /* x/y positions in fixed point */
    const struct lp_setup_variant_key *key = &setup->setup.variant->key;
    const int sizeAttr = setup->psize;
@@ -379,8 +380,7 @@ try_setup_point( 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;
+   if (lp_context->active_statistics_queries) {
       lp_context->pipeline_statistics.c_primitives++;
    }
 
index 62df5df555f76c4a2a47fbbfd97d68d6e8815cac..6dc136c3aa30dcce6062346787af3daf2bf492ac 100644 (file)
@@ -252,6 +252,7 @@ do_triangle_ccw(struct lp_setup_context *setup,
                 const float (*v2)[4],
                 boolean frontfacing )
 {
+   struct llvmpipe_context *lp_context = (struct llvmpipe_context *)setup->pipe;
    struct lp_scene *scene = setup->scene;
    const struct lp_setup_variant_key *key = &setup->setup.variant->key;
    struct lp_rast_triangle *tri;
@@ -339,8 +340,7 @@ 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;
+   if (lp_context->active_statistics_queries) {
       lp_context->pipeline_statistics.c_primitives++;
    }
 
index 38e9fc7d736bc1be8e3d2f4abe9f19505cf885d3..6afd57a685996e47ee70499b877ca9f5e94224b0 100644 (file)
@@ -2630,7 +2630,7 @@ make_variant_key(struct llvmpipe_context *lp,
    /* alpha.ref_value is passed in jit_context */
 
    key->flatshade = lp->rasterizer->flatshade;
-   if (lp->active_occlusion_query) {
+   if (lp->active_occlusion_queries) {
       key->occlusion_count = TRUE;
    }