gallium: fold u_trim_pipe_prim call from st/mesa to drivers
authorMarek Olšák <marek.olsak@amd.com>
Sun, 9 Apr 2017 13:57:45 +0000 (15:57 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Thu, 20 Apr 2017 18:11:35 +0000 (20:11 +0200)
Most drivers don't need it and shouldn't need it because it can't be used
in some cases (indirect draws, primitive restart, count from streamout).

Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/etnaviv/etnaviv_context.c
src/gallium/drivers/freedreno/freedreno_draw.c
src/gallium/drivers/i915/i915_context.c
src/gallium/drivers/nouveau/nv30/nv30_vbo.c
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/swr/swr_draw.cpp
src/gallium/drivers/vc4/vc4_draw.c
src/gallium/drivers/virgl/virgl_context.c
src/mesa/state_tracker/st_draw.c

index cfbc9065426b1aa743ed12d22acf4c117b60a17d..e426d4f1d19edcf4368bd6a3f16fd27cc84d3e63 100644 (file)
@@ -149,6 +149,11 @@ etna_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
    uint32_t draw_mode;
    unsigned i;
 
+   if (!info->count_from_stream_output && !info->indirect &&
+       !info->primitive_restart &&
+       !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+      return;
+
    if (ctx->vertex_elements == NULL || ctx->vertex_elements->num_elements == 0)
       return; /* Nothing to do */
 
index 16c9ea84af3e9eb00b85eda94a1e53a9e4edd3cf..6243984dc80e0802fffcbb527ae1a36847e22c18 100644 (file)
@@ -65,6 +65,11 @@ fd_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
        struct pipe_scissor_state *scissor = fd_context_get_scissor(ctx);
        unsigned i, prims, buffers = 0;
 
+       if (!info->count_from_stream_output && !info->indirect &&
+           !info->primitive_restart &&
+           !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+               return;
+
        /* if we supported transform feedback, we'd have to disable this: */
        if (((scissor->maxx - scissor->minx) *
                        (scissor->maxy - scissor->miny)) == 0) {
index 6664cfc3dfee88423253ab1d06644f6df3e45339..c22e4056424d127d98d4ef37bac44054cdcf80a0 100644 (file)
@@ -37,6 +37,7 @@
 #include "pipe/p_defines.h"
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
+#include "util/u_prim.h"
 #include "util/u_upload_mgr.h"
 #include "pipe/p_screen.h"
 
@@ -57,6 +58,9 @@ i915_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
    const void *mapped_indices = NULL;
    unsigned i;
 
+   if (!u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+      return;
+
    /*
     * Ack vs contants here, helps ipers a lot.
     */
index bc9b9a16ea88f9a9d414fcebc0e0a9bd6095430f..9338f2ed70080f981778de38912edb912dac46cb 100644 (file)
@@ -25,6 +25,7 @@
 
 #include "util/u_format.h"
 #include "util/u_inlines.h"
+#include "util/u_prim.h"
 #include "translate/translate.h"
 
 #include "nouveau_fence.h"
@@ -550,6 +551,10 @@ nv30_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
    struct nouveau_pushbuf *push = nv30->base.pushbuf;
    int i;
 
+   if (!info->primitive_restart &&
+       !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+      return;
+
    /* For picking only a few vertices from a large user buffer, push is better,
     * if index count is larger and we expect repeated vertices, suggest upload.
     */
index ad0f489617212270fa3b0a13d59e30a13d104dc9..9702a2e32ed30cbff7e5541bedfacb9cdc519278 100644 (file)
@@ -847,6 +847,9 @@ static void r300_swtcl_draw_vbo(struct pipe_context* pipe,
         return;
     }
 
+    if (!u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+       return;
+
     r300_update_derived_state(r300);
 
     draw_vbo(r300->draw, info);
index c43f4a5f64de39e845bc71f94782b7276a5ebc34..de78cf34750df50f0491fb471caef771ca41abac 100644 (file)
@@ -39,6 +39,11 @@ swr_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
 {
    struct swr_context *ctx = swr_context(pipe);
 
+   if (!info->count_from_stream_output && !info->indirect &&
+       !info->primitive_restart &&
+       !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+      return;
+
    if (!swr_check_render_cond(pipe))
       return;
 
index ebd080298a4b37cff6ad329a950d321c1fda584b..61694ecda6c05e07127bec8d91b093188361ae2e 100644 (file)
@@ -283,6 +283,11 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 {
         struct vc4_context *vc4 = vc4_context(pctx);
 
+       if (!info->count_from_stream_output && !info->indirect &&
+           !info->primitive_restart &&
+           !u_trim_pipe_prim(info->mode, (unsigned*)&info->count))
+               return;
+
         if (info->mode >= PIPE_PRIM_QUADS) {
                 util_primconvert_save_index_buffer(vc4->primconvert, &vc4->indexbuf);
                 util_primconvert_save_rasterizer_state(vc4->primconvert, &vc4->rasterizer->base);
index 4b990a6a5d0cedb7be9a479ca4a3722db06a4113..25b24c895d3b07a9a3d5099dcf7db73da72147f0 100644 (file)
@@ -30,6 +30,7 @@
 #include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "util/u_format.h"
+#include "util/u_prim.h"
 #include "util/u_transfer.h"
 #include "util/u_helpers.h"
 #include "util/slab.h"
@@ -592,6 +593,11 @@ static void virgl_draw_vbo(struct pipe_context *ctx,
    struct pipe_index_buffer ib = {};
    struct pipe_draw_info info = *dinfo;
 
+   if (!dinfo->count_from_stream_output && !dinfo->indirect &&
+       !dinfo->primitive_restart &&
+       !u_trim_pipe_prim(dinfo->mode, (unsigned*)&dinfo->count))
+      return;
+
    if (!(rs->caps.caps.v1.prim_mask & (1 << dinfo->mode))) {
       util_primconvert_save_index_buffer(vctx->primconvert, &vctx->index_buffer);
       util_primconvert_draw_vbo(vctx->primconvert, dinfo);
index f04b6c2f163d8a540e67cf9077793176c47c198a..561633cdaf06154687b7ab3204c7e65f12077006 100644 (file)
@@ -251,16 +251,8 @@ st_draw_vbo(struct gl_context *ctx,
                       info.indexed);
       }
 
-      if (info.count_from_stream_output) {
-         cso_draw_vbo(st->cso_context, &info);
-      }
-      else if (info.primitive_restart) {
-         /* don't trim, restarts might be inside index list */
-         cso_draw_vbo(st->cso_context, &info);
-      }
-      else if (u_trim_pipe_prim(prims[i].mode, &info.count)) {
-         cso_draw_vbo(st->cso_context, &info);
-      }
+      /* Don't call u_trim_pipe_prim. Drivers should do it if they need it. */
+      cso_draw_vbo(st->cso_context, &info);
    }
 }