panfrost: Inline panfrost_vertex_instanced
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Fri, 14 Aug 2020 16:29:57 +0000 (12:29 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 17 Aug 2020 11:43:52 +0000 (11:43 +0000)
We'd like to have attribute code in one place together so we can
refactor effectively; this routine as-is wouldn't fit perfectly outside
Gallium anyway so let's do the simple thing.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6326>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/panfrost/lib/pan_attributes.c
src/panfrost/lib/pan_encoder.h

index 457c02cbbc13653b6c02613bb70d4d4157e962ee..bd0240ed1bfdbd521072945a6044bec41bda637a 100644 (file)
@@ -1409,6 +1409,12 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch,
 
                 unsigned divisor = elem->instance_divisor;
 
 
                 unsigned divisor = elem->instance_divisor;
 
+                /* Depending if there is an instance divisor or not, packing varies.
+                 * When there is a divisor, the hardware-level divisor is actually the
+                 * product of the instance divisor and the padded count */
+
+                unsigned hw_divisor = ctx->padded_count * divisor;
+
                 if (divisor && ctx->instance_count == 1) {
                         /* Silly corner case where there's a divisor(=1) but
                          * there's no legitimate instancing. So we want *every*
                 if (divisor && ctx->instance_count == 1) {
                         /* Silly corner case where there's a divisor(=1) but
                          * there's no legitimate instancing. So we want *every*
@@ -1421,11 +1427,34 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch,
                 } else if (ctx->instance_count <= 1) {
                         /* Normal, non-instanced attributes */
                         attrs[k++].elements |= MALI_ATTR_LINEAR;
                 } else if (ctx->instance_count <= 1) {
                         /* Normal, non-instanced attributes */
                         attrs[k++].elements |= MALI_ATTR_LINEAR;
+                } else if (divisor == 0) {
+                        /* Per-vertex attributes use the MODULO mode. */
+                        attrs[k].elements |= MALI_ATTR_MODULO;
+                        attrs[k].shift = instance_shift;
+                        attrs[k++].extra_flags = instance_odd;
+                } else if (util_is_power_of_two_or_zero(hw_divisor)) {
+                        /* If there is a divisor but the hardware divisor works out to
+                         * a power of two (not terribly exceptional), we can use an
+                         * easy path (just shifting) */
+
+                        attrs[k].elements |= MALI_ATTR_POT_DIVIDE;
+                        attrs[k++].shift = __builtin_ctz(hw_divisor);
                 } else {
                 } else {
-                        k += panfrost_vertex_instanced(ctx->padded_count,
-                                                       instance_shift,
-                                                       instance_odd,
-                                                       divisor, &attrs[k]);
+                        unsigned shift = 0, extra_flags = 0;
+
+                        unsigned magic_divisor =
+                                panfrost_compute_magic_divisor(hw_divisor, &shift, &extra_flags);
+
+                        /* Upload to two different slots */
+
+                        attrs[k].elements |= MALI_ATTR_NPOT_DIVIDE;
+                        attrs[k].shift = shift;
+                        attrs[k++].extra_flags = extra_flags;
+
+                        attrs[k].unk = 0x20;
+                        attrs[k].zero = 0;
+                        attrs[k].magic_divisor = magic_divisor;
+                        attrs[k++].divisor = divisor;
                 }
         }
 
                 }
         }
 
index 1d9e7d3019d39c703b32c75e542e6d21cb209fab..acaad11ebee91109e7352e33df728691a1232255 100644 (file)
@@ -91,7 +91,7 @@ panfrost_padded_vertex_count(unsigned vertex_count)
 /* The much, much more irritating case -- instancing is enabled. See
  * panfrost_job.h for notes on how this works */
 
 /* The much, much more irritating case -- instancing is enabled. See
  * panfrost_job.h for notes on how this works */
 
-static unsigned
+unsigned
 panfrost_compute_magic_divisor(unsigned hw_divisor, unsigned *o_shift, unsigned *extra_flags)
 {
         /* We have a NPOT divisor. Here's the fun one (multipling by
 panfrost_compute_magic_divisor(unsigned hw_divisor, unsigned *o_shift, unsigned *extra_flags)
 {
         /* We have a NPOT divisor. Here's the fun one (multipling by
@@ -129,57 +129,6 @@ panfrost_compute_magic_divisor(unsigned hw_divisor, unsigned *o_shift, unsigned
         return magic_divisor;
 }
 
         return magic_divisor;
 }
 
-unsigned
-panfrost_vertex_instanced(
-        unsigned padded_count,
-        unsigned instance_shift, unsigned instance_odd,
-        unsigned divisor,
-        union mali_attr *attrs)
-{
-        /* Depending if there is an instance divisor or not, packing varies.
-         * When there is a divisor, the hardware-level divisor is actually the
-         * product of the instance divisor and the padded count */
-
-        unsigned hw_divisor = padded_count * divisor;
-
-        if (divisor == 0) {
-                /* Per-vertex attributes use the MODULO mode. First, compute
-                 * the modulus */
-
-                attrs->elements |= MALI_ATTR_MODULO;
-                attrs->shift = instance_shift;
-                attrs->extra_flags = instance_odd;
-
-                return 1;
-        } else if (util_is_power_of_two_or_zero(hw_divisor)) {
-                /* If there is a divisor but the hardware divisor works out to
-                 * a power of two (not terribly exceptional), we can use an
-                 * easy path (just shifting) */
-
-                attrs->elements |= MALI_ATTR_POT_DIVIDE;
-                attrs->shift = __builtin_ctz(hw_divisor);
-
-                return 1;
-        } else {
-                unsigned shift = 0, extra_flags = 0;
-
-                attrs[1].magic_divisor =
-                        panfrost_compute_magic_divisor(hw_divisor, &shift, &extra_flags);
-
-                /* Upload to two different slots */
-
-                attrs[0].elements |= MALI_ATTR_NPOT_DIVIDE;
-                attrs[0].shift = shift;
-                attrs[0].extra_flags = extra_flags;
-
-                attrs[1].unk = 0x20;
-                attrs[1].zero = 0;
-                attrs[1].divisor = divisor;
-
-                return 2;
-        }
-}
-
 /* Records for gl_VertexID and gl_InstanceID use a slightly special encoding,
  * but the idea is the same */
 
 /* Records for gl_VertexID and gl_InstanceID use a slightly special encoding,
  * but the idea is the same */
 
index fbef6734e17145705e597d2d240a8da2e1e6c9a2..7e815a7f2c8d9eaaeaa1d1637f38f0ddc0d5b7a5 100644 (file)
@@ -93,11 +93,7 @@ unsigned
 panfrost_padded_vertex_count(unsigned vertex_count);
 
 unsigned
 panfrost_padded_vertex_count(unsigned vertex_count);
 
 unsigned
-panfrost_vertex_instanced(
-        unsigned padded_count,
-        unsigned instance_shift, unsigned instance_odd,
-        unsigned divisor,
-        union mali_attr *attrs);
+panfrost_compute_magic_divisor(unsigned hw_divisor, unsigned *o_shift, unsigned *extra_flags);
 
 void panfrost_vertex_id(unsigned padded_count, union mali_attr *attr);
 void panfrost_instance_id(unsigned padded_count, union mali_attr *attr);
 
 void panfrost_vertex_id(unsigned padded_count, union mali_attr *attr);
 void panfrost_instance_id(unsigned padded_count, union mali_attr *attr);