svga: Performance fixes
[mesa.git] / src / gallium / drivers / svga / svga_draw_arrays.c
index 43d7a975695924f502ed4f1bebd0ae22b746747c..af27e038bc8641366e1599a42279e5878e665921 100644 (file)
@@ -90,7 +90,7 @@ compare(unsigned cached_nr, unsigned nr, unsigned type)
 
 static enum pipe_error
 retrieve_or_generate_indices(struct svga_hwtnl *hwtnl,
-                             unsigned prim,
+                             enum pipe_prim_type prim,
                              unsigned gen_type,
                              unsigned gen_nr,
                              unsigned gen_size,
@@ -100,6 +100,8 @@ retrieve_or_generate_indices(struct svga_hwtnl *hwtnl,
    enum pipe_error ret = PIPE_OK;
    int i;
 
+   SVGA_STATS_TIME_PUSH(svga_sws(hwtnl->svga), SVGA_STATS_TIME_GENERATEINDICES);
+
    for (i = 0; i < IDX_CACHE_MAX; i++) {
       if (hwtnl->index_cache[prim][i].buffer != NULL &&
           hwtnl->index_cache[prim][i].generate == generate) {
@@ -110,7 +112,7 @@ retrieve_or_generate_indices(struct svga_hwtnl *hwtnl,
             if (DBG)
                debug_printf("%s retrieve %d/%d\n", __FUNCTION__, i, gen_nr);
 
-            return PIPE_OK;
+            goto done;
          }
          else if (gen_type == U_GENERATE_REUSABLE) {
             pipe_resource_reference(&hwtnl->index_cache[prim][i].buffer,
@@ -154,7 +156,7 @@ retrieve_or_generate_indices(struct svga_hwtnl *hwtnl,
 
    ret = generate_indices(hwtnl, gen_nr, gen_size, generate, out_buf);
    if (ret != PIPE_OK)
-      return ret;
+      goto done;
 
    hwtnl->index_cache[prim][i].generate = generate;
    hwtnl->index_cache[prim][i].gen_nr = gen_nr;
@@ -164,20 +166,23 @@ retrieve_or_generate_indices(struct svga_hwtnl *hwtnl,
       debug_printf("%s cache %d/%d\n", __FUNCTION__,
                    i, hwtnl->index_cache[prim][i].gen_nr);
 
-   return PIPE_OK;
+done:
+   SVGA_STATS_TIME_POP(svga_sws(hwtnl->svga));
+   return ret;
 }
 
 
 static enum pipe_error
 simple_draw_arrays(struct svga_hwtnl *hwtnl,
-                   unsigned prim, unsigned start, unsigned count,
-                   unsigned start_instance, unsigned instance_count)
+                   enum pipe_prim_type prim, unsigned start, unsigned count,
+                   unsigned start_instance, unsigned instance_count,
+                   ubyte vertices_per_patch)
 {
    SVGA3dPrimitiveRange range;
    unsigned hw_prim;
    unsigned hw_count;
 
-   hw_prim = svga_translate_prim(prim, count, &hw_count);
+   hw_prim = svga_translate_prim(prim, count, &hw_count, vertices_per_patch);
    if (hw_count == 0)
       return PIPE_ERROR_BAD_INPUT;
 
@@ -196,29 +201,34 @@ simple_draw_arrays(struct svga_hwtnl *hwtnl,
     */
    return svga_hwtnl_prim(hwtnl, &range, count,
                           0, count - 1, NULL,
-                          start_instance, instance_count);
+                          start_instance, instance_count,
+                          NULL, NULL);
 }
 
 
 enum pipe_error
 svga_hwtnl_draw_arrays(struct svga_hwtnl *hwtnl,
-                       unsigned prim, unsigned start, unsigned count,
-                       unsigned start_instance, unsigned instance_count)
+                       enum pipe_prim_type prim, unsigned start, unsigned count,
+                       unsigned start_instance, unsigned instance_count,
+                       ubyte vertices_per_patch)
 {
-   unsigned gen_prim, gen_size, gen_nr;
+   enum pipe_prim_type gen_prim;
+   unsigned gen_size, gen_nr;
    enum indices_mode gen_type;
    u_generate_func gen_func;
    enum pipe_error ret = PIPE_OK;
    unsigned api_pv = hwtnl->api_pv;
    struct svga_context *svga = hwtnl->svga;
 
+   SVGA_STATS_TIME_PUSH(svga_sws(svga), SVGA_STATS_TIME_HWTNLDRAWARRAYS);
+
    if (svga->curr.rast->templ.fill_front !=
        svga->curr.rast->templ.fill_back) {
       assert(hwtnl->api_fillmode == PIPE_POLYGON_MODE_FILL);
    }
 
    if (svga->curr.rast->templ.flatshade &&
-       svga->state.hw_draw.fs->constant_color_output) {
+         svga_fs_variant(svga->state.hw_draw.fs)->constant_color_output) {
       /* The fragment color is a constant, not per-vertex so the whole
        * primitive will be the same color (except for possible blending).
        * We can ignore the current provoking vertex state and use whatever
@@ -265,8 +275,9 @@ svga_hwtnl_draw_arrays(struct svga_hwtnl *hwtnl,
    }
 
    if (gen_type == U_GENERATE_LINEAR) {
-      return simple_draw_arrays(hwtnl, gen_prim, start, count,
-                                start_instance, instance_count);
+      ret = simple_draw_arrays(hwtnl, gen_prim, start, count,
+                               start_instance, instance_count,
+                               vertices_per_patch);
    }
    else {
       struct pipe_resource *gen_buf = NULL;
@@ -279,29 +290,28 @@ svga_hwtnl_draw_arrays(struct svga_hwtnl *hwtnl,
                                          gen_type,
                                          gen_nr,
                                          gen_size, gen_func, &gen_buf);
-      if (ret != PIPE_OK)
-         goto done;
-
-      pipe_debug_message(&svga->debug.callback, PERF_INFO,
-                         "generating temporary index buffer for drawing %s",
-                         u_prim_name(prim));
-
-      ret = svga_hwtnl_simple_draw_range_elements(hwtnl,
-                                                  gen_buf,
-                                                  gen_size,
-                                                  start,
-                                                  0,
-                                                  count - 1,
-                                                  gen_prim, 0, gen_nr,
-                                                  start_instance,
-                                                  instance_count);
-      if (ret != PIPE_OK)
-         goto done;
+      if (ret == PIPE_OK) {
+         pipe_debug_message(&svga->debug.callback, PERF_INFO,
+                            "generating temporary index buffer for drawing %s",
+                            u_prim_name(prim));
+
+         ret = svga_hwtnl_simple_draw_range_elements(hwtnl,
+                                                     gen_buf,
+                                                     gen_size,
+                                                     start,
+                                                     0,
+                                                     count - 1,
+                                                     gen_prim, 0, gen_nr,
+                                                     start_instance,
+                                                     instance_count,
+                                                     vertices_per_patch);
+      }
 
-done:
-      if (gen_buf)
+      if (gen_buf) {
          pipe_resource_reference(&gen_buf, NULL);
-
-      return ret;
+      }
    }
+
+   SVGA_STATS_TIME_POP(svga_sws(svga));
+   return ret;
 }