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*
} 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 {
- 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;
}
}
/* 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
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 */
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);