[Mesa-dev] [PATCH 1/3] gallium/util: add a helper for calculating primitive count from vertex count

Marek Olšák maraeo at gmail.com
Fri Jul 25 18:30:08 PDT 2014


From: Marek Olšák <marek.olsak at amd.com>

This is needed by the following commit which is a candidate for stable too.

Cc: mesa-stable at lists.freedesktop.org
---
 src/gallium/auxiliary/util/u_prim.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/src/gallium/auxiliary/util/u_prim.h b/src/gallium/auxiliary/util/u_prim.h
index fd95c0b..cf1a18f 100644
--- a/src/gallium/auxiliary/util/u_prim.h
+++ b/src/gallium/auxiliary/util/u_prim.h
@@ -136,6 +136,21 @@ u_prim_vertex_count(unsigned prim)
    return (likely(prim < PIPE_PRIM_MAX)) ? &prim_table[prim] : NULL;
 }
 
+/**
+ * Given a vertex count, return the number of primitives.
+ * For polygons, return the number of triangles.
+ */
+static INLINE unsigned
+u_prims_for_vertices(unsigned prim, unsigned num)
+{
+   const struct u_prim_vertex_count *info = u_prim_vertex_count(prim);
+
+   if (num < info->min)
+      return 0;
+
+   return 1 + ((num - info->min) / info->incr);
+}
+
 static INLINE boolean u_validate_pipe_prim( unsigned pipe_prim, unsigned nr )
 {
    const struct u_prim_vertex_count *count = u_prim_vertex_count(pipe_prim);
-- 
1.9.1



More information about the mesa-dev mailing list