panfrost: Inline panfrost_vertex_instanced

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>
This commit is contained in:
Alyssa Rosenzweig 2020-08-14 12:29:57 -04:00 committed by Marge Bot
parent e9dc225122
commit c9bb5dc911
3 changed files with 35 additions and 61 deletions

View file

@ -1409,6 +1409,12 @@ panfrost_emit_vertex_data(struct panfrost_batch *batch,
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*
@ -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 (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;
}
}

View 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 */
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
@ -129,57 +129,6 @@ panfrost_compute_magic_divisor(unsigned hw_divisor, unsigned *o_shift, unsigned
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 */

View file

@ -93,11 +93,7 @@ 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);