vc4: move the draw splitting routine to shared code
authorErico Nunes <nunes.erico@gmail.com>
Tue, 12 Nov 2019 13:56:33 +0000 (14:56 +0100)
committerErico Nunes <nunes.erico@gmail.com>
Sat, 14 Dec 2019 06:44:43 +0000 (07:44 +0100)
This can also be useful for other hardware which has similar limitations
on vertex count per single draw.
The Mali400 has a similar limitation and can reuse this.

Signed-off-by: Erico Nunes <nunes.erico@gmail.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2445>

src/gallium/auxiliary/Makefile.sources
src/gallium/auxiliary/meson.build
src/gallium/auxiliary/util/u_split_draw.c [new file with mode: 0644]
src/gallium/auxiliary/util/u_split_draw.h [new file with mode: 0644]
src/gallium/drivers/vc4/vc4_draw.c

index 46c443b574703ac23dffa5f87379bb5ab8f4bca0..9951fe94a485e95299221b1180662115414db51e 100644 (file)
@@ -285,6 +285,8 @@ C_SOURCES := \
        util/u_screen.h \
        util/u_simple_shaders.c \
        util/u_simple_shaders.h \
+       util/u_split_draw.c \
+       util/u_split_draw.h \
        util/u_split_prim.h \
        util/u_sse.h \
        util/u_suballoc.c \
index 65e4eda87ef5fd376df228086bbb09dc92833a34..d9e91216211518b2bd8d6b193d8980f645346c64 100644 (file)
@@ -305,6 +305,8 @@ files_libgallium = files(
   'util/u_screen.h',
   'util/u_simple_shaders.c',
   'util/u_simple_shaders.h',
+  'util/u_split_draw.c',
+  'util/u_split_draw.h',
   'util/u_split_prim.h',
   'util/u_sse.h',
   'util/u_suballoc.c',
diff --git a/src/gallium/auxiliary/util/u_split_draw.c b/src/gallium/auxiliary/util/u_split_draw.c
new file mode 100644 (file)
index 0000000..39989aa
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include "pipe/p_defines.h"
+#include "util/u_debug.h"
+#include "util/u_split_draw.h"
+
+bool
+u_split_draw(const struct pipe_draw_info *info, uint32_t max_verts,
+             uint32_t *count, uint32_t *step)
+{
+   if (*count <= max_verts) {
+      *step = *count;
+      return false;
+   }
+
+   switch (info->mode) {
+      case PIPE_PRIM_POINTS:
+         *count = *step = max_verts;
+         break;
+      case PIPE_PRIM_LINES:
+         *count = *step = max_verts - (max_verts % 2);
+         break;
+      case PIPE_PRIM_LINE_STRIP:
+         *count = max_verts;
+         *step = max_verts - 1;
+         break;
+      case PIPE_PRIM_LINE_LOOP:
+         *count = max_verts;
+         *step = max_verts - 1;
+         debug_warn_once("unhandled line loop "
+                         "looping behavior with "
+                         ">max vert count\n");
+         break;
+      case PIPE_PRIM_TRIANGLES:
+         *count = *step = max_verts - (max_verts % 3);
+         break;
+      case PIPE_PRIM_TRIANGLE_STRIP:
+         *count = max_verts;
+         *step = max_verts - 2;
+         break;
+      default:
+         debug_warn_once("unhandled primitive "
+                         "max vert count, truncating\n");
+         *count = *step = max_verts;
+   }
+
+   return true;
+}
diff --git a/src/gallium/auxiliary/util/u_split_draw.h b/src/gallium/auxiliary/util/u_split_draw.h
new file mode 100644 (file)
index 0000000..b3236a2
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#ifndef U_SPLIT_DRAW_H
+#define U_SPLIT_DRAW_H
+
+#include "pipe/p_state.h"
+
+/**
+ * For non-indexed drawing, this function helps work around hardware
+ * limits on the number of verts in a single draw.
+ *
+ * For the given mode of primitive from info, calculate the count and
+ * step in the buffer so the draw can be split into multiple draws.
+ *
+ * \param info      pointer to the original pipe_draw_info from draw_vbo
+ * \param max_verts max number of vertices that can be handled by the hardware
+ * \param count     number of vertices remaining in the draw call. It is also
+ *                  used as a return parameter, containing how many vertices
+ *                  should be sent in the next job to the hardware.
+ * \param step      return parameter, will contain how many vertices should be
+ *                  skipped from the original count on the next call to this
+ *                  function (may differ from count if the primitive mode
+ *                  requires the last vertices to be reused in the next draw)
+ */
+bool
+u_split_draw(const struct pipe_draw_info *info, uint32_t max_verts,
+             uint32_t *count, uint32_t *step);
+
+#endif
index 3d931807aec12107a32844dcae4b00b49554541e..3da60ff64a8374678f3e668068631cd209835215 100644 (file)
@@ -26,6 +26,7 @@
 #include "util/u_prim.h"
 #include "util/format/u_format.h"
 #include "util/u_pack_color.h"
+#include "util/u_split_draw.h"
 #include "util/u_upload_mgr.h"
 #include "indices/u_primconvert.h"
 
@@ -448,45 +449,14 @@ vc4_draw_vbo(struct pipe_context *pctx, const struct pipe_draw_info *info)
 
                 while (count) {
                         uint32_t this_count = count;
-                        uint32_t step = count;
+                        uint32_t step;
 
                         if (needs_drawarrays_shader_state) {
                                 vc4_emit_gl_shader_state(vc4, info,
                                                          extra_index_bias);
                         }
 
-                        if (count > max_verts) {
-                                switch (info->mode) {
-                                case PIPE_PRIM_POINTS:
-                                        this_count = step = max_verts;
-                                        break;
-                                case PIPE_PRIM_LINES:
-                                        this_count = step = max_verts - (max_verts % 2);
-                                        break;
-                                case PIPE_PRIM_LINE_STRIP:
-                                        this_count = max_verts;
-                                        step = max_verts - 1;
-                                        break;
-                                case PIPE_PRIM_LINE_LOOP:
-                                        this_count = max_verts;
-                                        step = max_verts - 1;
-                                        debug_warn_once("unhandled line loop "
-                                                        "looping behavior with "
-                                                        ">65535 verts\n");
-                                        break;
-                                case PIPE_PRIM_TRIANGLES:
-                                        this_count = step = max_verts - (max_verts % 3);
-                                        break;
-                                case PIPE_PRIM_TRIANGLE_STRIP:
-                                        this_count = max_verts;
-                                        step = max_verts - 2;
-                                        break;
-                                default:
-                                        debug_warn_once("unhandled primitive "
-                                                        "max vert count, truncating\n");
-                                        this_count = step = max_verts;
-                                }
-                        }
+                        u_split_draw(info, max_verts, &this_count, &step);
 
                         cl_emit(&job->bcl, VERTEX_ARRAY_PRIMITIVES, array) {
                                 array.primitive_mode = info->mode;