[Mesa-dev] [PATCH] llvmpipe: fixes for conditional rendering

sroland at vmware.com sroland at vmware.com
Fri Jun 14 17:50:05 PDT 2013


From: Roland Scheidegger <sroland at vmware.com>

honor render_condition for clear_render_target and clear_depth_stencil.
Also add minimal support for occlusion predicate, though it can't be active
at the same time as an occlusion query yet.
While here also switchify some large if-else (actually just mutually
exclusive if-if-if...) constructs.
---
 src/gallium/drivers/llvmpipe/lp_bld_depth.c |    4 ++
 src/gallium/drivers/llvmpipe/lp_query.c     |   78 +++++++++++++++------------
 src/gallium/drivers/llvmpipe/lp_rast.c      |    2 +
 src/gallium/drivers/llvmpipe/lp_surface.c   |   42 ++++++++++++++-
 4 files changed, 90 insertions(+), 36 deletions(-)

diff --git a/src/gallium/drivers/llvmpipe/lp_bld_depth.c b/src/gallium/drivers/llvmpipe/lp_bld_depth.c
index a8bd15f..40ab7be 100644
--- a/src/gallium/drivers/llvmpipe/lp_bld_depth.c
+++ b/src/gallium/drivers/llvmpipe/lp_bld_depth.c
@@ -429,6 +429,10 @@ get_s_shift_and_mask(const struct util_format_description *format_desc,
  * Test the depth mask. Add the number of channel which has none zero mask
  * into the occlusion counter. e.g. maskvalue is {-1, -1, -1, -1}.
  * The counter will add 4.
+ * TODO: would be much easier if we'd just have a nx32bit counter
+ * and simply sub the masks here. Then add the individual values
+ * at query end. This however wouldn't work with 64bit counter values
+ * which we should also do.
  *
  * \param type holds element type of the mask vector.
  * \param maskvalue is the depth test mask.
diff --git a/src/gallium/drivers/llvmpipe/lp_query.c b/src/gallium/drivers/llvmpipe/lp_query.c
index 973c689..84910b8 100644
--- a/src/gallium/drivers/llvmpipe/lp_query.c
+++ b/src/gallium/drivers/llvmpipe/lp_query.c
@@ -125,6 +125,12 @@ llvmpipe_get_query_result(struct pipe_context *pipe,
          *result += pq->count[i];
       }
       break;
+   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];
+      }
+      break;
    case PIPE_QUERY_TIMESTAMP:
       for (i = 0; i < num_threads; i++) {
          if (pq->count[i] > *result) {
@@ -181,30 +187,28 @@ llvmpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q)
 
 
    memset(pq->count, 0, sizeof(pq->count));
+   /* XXX do we really need to bin all queries */
    lp_setup_begin_query(llvmpipe->setup, pq);
 
-   if (pq->type == PIPE_QUERY_PRIMITIVES_EMITTED) {
+   switch (pq->type) {
+   case PIPE_QUERY_PRIMITIVES_EMITTED:
       pq->num_primitives_written = 0;
       llvmpipe->so_stats.num_primitives_written = 0;
-   }
-
-   if (pq->type == PIPE_QUERY_PRIMITIVES_GENERATED) {
+      break;
+   case PIPE_QUERY_PRIMITIVES_GENERATED:
       pq->num_primitives_generated = 0;
       llvmpipe->num_primitives_generated = 0;
-   }
-
-   if (pq->type == PIPE_QUERY_SO_STATISTICS) {
+      break;
+   case PIPE_QUERY_SO_STATISTICS:
       pq->num_primitives_written = 0;
       llvmpipe->so_stats.num_primitives_written = 0;
       pq->num_primitives_generated = 0;
       llvmpipe->num_primitives_generated = 0;
-   }
-
-   if (pq->type == PIPE_QUERY_SO_OVERFLOW_PREDICATE) {
+      break;
+   case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
       pq->so_has_overflown = FALSE;
-   }
-
-   if (pq->type == PIPE_QUERY_PIPELINE_STATISTICS) {
+      break;
+   case PIPE_QUERY_PIPELINE_STATISTICS:
       /* reset our cache */
       if (llvmpipe->active_statistics_queries == 0) {
          memset(&llvmpipe->pipeline_statistics, 0,
@@ -212,11 +216,16 @@ llvmpipe_begin_query(struct pipe_context *pipe, struct pipe_query *q)
       }
       memcpy(&pq->stats, &llvmpipe->pipeline_statistics, sizeof(pq->stats));
       llvmpipe->active_statistics_queries++;
-   }
-
-   if (pq->type == PIPE_QUERY_OCCLUSION_COUNTER) {
-      llvmpipe->active_occlusion_query = TRUE;
+      break;
+   case PIPE_QUERY_OCCLUSION_COUNTER:
+   case PIPE_QUERY_OCCLUSION_PREDICATE:
+      /* Both active at same time will still fail all over the place.
+       * Then again several of each type can be active too... */
+      llvmpipe->active_occlusion_query++;
       llvmpipe->dirty |= LP_NEW_OCCLUSION_QUERY;
+      break;
+   default:
+      break;
    }
 }
 
@@ -229,25 +238,23 @@ llvmpipe_end_query(struct pipe_context *pipe, struct pipe_query *q)
 
    lp_setup_end_query(llvmpipe->setup, pq);
 
-   if (pq->type == PIPE_QUERY_PRIMITIVES_EMITTED) {
-      pq->num_primitives_written = llvmpipe->so_stats.num_primitives_written;
-   }
+   switch (pq->type) {
 
-   if (pq->type == PIPE_QUERY_PRIMITIVES_GENERATED) {
+   case PIPE_QUERY_PRIMITIVES_EMITTED:
+      pq->num_primitives_written = llvmpipe->so_stats.num_primitives_written;
+      break;
+   case PIPE_QUERY_PRIMITIVES_GENERATED:
       pq->num_primitives_generated = llvmpipe->num_primitives_generated;
-   }
-
-   if (pq->type == PIPE_QUERY_SO_STATISTICS) {
+      break;
+   case PIPE_QUERY_SO_STATISTICS:
       pq->num_primitives_written = llvmpipe->so_stats.num_primitives_written;
       pq->num_primitives_generated = llvmpipe->num_primitives_generated;
-   }
-
-   if (pq->type == PIPE_QUERY_SO_OVERFLOW_PREDICATE) {
+      break;
+   case PIPE_QUERY_SO_OVERFLOW_PREDICATE:
       pq->so_has_overflown = (llvmpipe->num_primitives_generated >
                               llvmpipe->so_stats.num_primitives_written);
-   }
-
-   if (pq->type == PIPE_QUERY_PIPELINE_STATISTICS) {
+      break;
+   case PIPE_QUERY_PIPELINE_STATISTICS:
       pq->stats.ia_vertices =
          llvmpipe->pipeline_statistics.ia_vertices - pq->stats.ia_vertices;
       pq->stats.ia_primitives =
@@ -266,12 +273,15 @@ llvmpipe_end_query(struct pipe_context *pipe, struct pipe_query *q)
          llvmpipe->pipeline_statistics.ps_invocations - pq->stats.ps_invocations;
 
       llvmpipe->active_statistics_queries--;
-   }
-
-   if (pq->type == PIPE_QUERY_OCCLUSION_COUNTER) {
+      break;
+   case PIPE_QUERY_OCCLUSION_COUNTER:
+   case PIPE_QUERY_OCCLUSION_PREDICATE:
       assert(llvmpipe->active_occlusion_query);
-      llvmpipe->active_occlusion_query = FALSE;
+      llvmpipe->active_occlusion_query--;
       llvmpipe->dirty |= LP_NEW_OCCLUSION_QUERY;
+      break;
+   default:
+      break;
    }
 }
 
diff --git a/src/gallium/drivers/llvmpipe/lp_rast.c b/src/gallium/drivers/llvmpipe/lp_rast.c
index 79d4c58..d802d53 100644
--- a/src/gallium/drivers/llvmpipe/lp_rast.c
+++ b/src/gallium/drivers/llvmpipe/lp_rast.c
@@ -490,6 +490,7 @@ lp_rast_begin_query(struct lp_rasterizer_task *task,
 
    switch (pq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
+   case PIPE_QUERY_OCCLUSION_PREDICATE:
       task->thread_data.vis_counter = 0;
       break;
    case PIPE_QUERY_PRIMITIVES_GENERATED:
@@ -521,6 +522,7 @@ lp_rast_end_query(struct lp_rasterizer_task *task,
 
    switch (pq->type) {
    case PIPE_QUERY_OCCLUSION_COUNTER:
+   case PIPE_QUERY_OCCLUSION_PREDICATE:
       pq->count[task->thread_index] += task->thread_data.vis_counter;
       break;
    case PIPE_QUERY_TIMESTAMP:
diff --git a/src/gallium/drivers/llvmpipe/lp_surface.c b/src/gallium/drivers/llvmpipe/lp_surface.c
index 7b1f939..c1eeaf5 100644
--- a/src/gallium/drivers/llvmpipe/lp_surface.c
+++ b/src/gallium/drivers/llvmpipe/lp_surface.c
@@ -32,6 +32,7 @@
 #include "lp_limits.h"
 #include "lp_surface.h"
 #include "lp_texture.h"
+#include "lp_query.h"
 
 
 /**
@@ -286,11 +287,48 @@ llvmpipe_surface_destroy(struct pipe_context *pipe,
 }
 
 
+static void
+llvmpipe_clear_render_target(struct pipe_context *pipe,
+                             struct pipe_surface *dst,
+                             const union pipe_color_union *color,
+                             unsigned dstx, unsigned dsty,
+                             unsigned width, unsigned height)
+{
+   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
+
+   if (!llvmpipe_check_render_cond(llvmpipe))
+      return;
+
+   util_clear_render_target(pipe, dst, color,
+                            dstx, dsty, width, height);
+}
+
+
+static void
+llvmpipe_clear_depth_stencil(struct pipe_context *pipe,
+                             struct pipe_surface *dst,
+                             unsigned clear_flags,
+                             double depth,
+                             unsigned stencil,
+                             unsigned dstx, unsigned dsty,
+                             unsigned width, unsigned height)
+{
+   struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
+
+   if (!llvmpipe_check_render_cond(llvmpipe))
+      return;
+
+   util_clear_depth_stencil(pipe, dst, clear_flags,
+                            depth, stencil,
+                            dstx, dsty, width, height);
+}
+
+
 void
 llvmpipe_init_surface_functions(struct llvmpipe_context *lp)
 {
-   lp->pipe.clear_render_target = util_clear_render_target;
-   lp->pipe.clear_depth_stencil = util_clear_depth_stencil;
+   lp->pipe.clear_render_target = llvmpipe_clear_render_target;
+   lp->pipe.clear_depth_stencil = llvmpipe_clear_depth_stencil;
    lp->pipe.create_surface = llvmpipe_create_surface;
    lp->pipe.surface_destroy = llvmpipe_surface_destroy;
    /* These two are not actually functions dealing with surfaces */
-- 
1.7.9.5


More information about the mesa-dev mailing list