util: move and adjust the vertex upload heuristic equation from u_vbuf
authorMarek Olšák <marek.olsak@amd.com>
Mon, 23 Mar 2020 01:00:18 +0000 (21:00 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Mon, 6 Apr 2020 14:30:10 +0000 (10:30 -0400)
This will also be used by glthread.

The new equation is optimized for glthread.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4466>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4466>

src/gallium/auxiliary/util/u_vbuf.c
src/util/u_math.h

index f47d93ac3f1dd86e42b5202bad776425826a13fc..567cb6a75c9afb639ea3e0c976e89ce9006912c4 100644 (file)
@@ -1433,8 +1433,7 @@ void u_vbuf_draw_vbo(struct u_vbuf *mgr, const struct pipe_draw_info *info)
           * performance. */
          if (!info->indirect &&
              !new_info.primitive_restart &&
-             num_vertices > new_info.count * 4 &&
-             new_info.count > 32 &&
+             util_is_vbo_upload_ratio_too_large(new_info.count, num_vertices) &&
              !u_vbuf_mapping_vertex_buffer_blocks(mgr)) {
             unroll_indices = TRUE;
             user_vb_mask &= ~(mgr->nonzero_stride_vb_mask &
index a672486f02f41fd1f35fc845d683b056f76a54a8..6c2cb5437c06f0d3f9cb5f6fa04611b4c1997781 100644 (file)
@@ -783,7 +783,25 @@ util_fpstate_set_denorms_to_zero(unsigned current_fpstate);
 void
 util_fpstate_set(unsigned fpstate);
 
-
+/**
+ * For indexed draw calls, return true if the vertex count to be drawn is
+ * much lower than the vertex count that has to be uploaded, meaning
+ * that the driver should flatten indices instead of trying to upload
+ * a too big range.
+ *
+ * This is used by vertex upload code in u_vbuf and glthread.
+ */
+static inline bool
+util_is_vbo_upload_ratio_too_large(unsigned draw_vertex_count,
+                                   unsigned upload_vertex_count)
+{
+   if (draw_vertex_count > 1024)
+      return upload_vertex_count > draw_vertex_count * 4;
+   else if (draw_vertex_count > 32)
+      return upload_vertex_count > draw_vertex_count * 8;
+   else
+      return upload_vertex_count > draw_vertex_count * 16;
+}
 
 #ifdef __cplusplus
 }