From: Alyssa Rosenzweig Date: Fri, 14 Aug 2020 16:29:57 +0000 (-0400) Subject: panfrost: Inline panfrost_vertex_instanced X-Git-Url: https://git.libre-soc.org/?p=mesa.git;a=commitdiff_plain;h=c9bb5dc911a1de4a1178af458babcaaa64998327 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 Reviewed-by: Tomeu Vizoso Part-of: --- diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c index 457c02cbbc1..bd0240ed1bf 100644 --- a/src/gallium/drivers/panfrost/pan_cmdstream.c +++ b/src/gallium/drivers/panfrost/pan_cmdstream.c @@ -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; } } diff --git a/src/panfrost/lib/pan_attributes.c b/src/panfrost/lib/pan_attributes.c index 1d9e7d3019d..acaad11ebee 100644 --- a/src/panfrost/lib/pan_attributes.c +++ b/src/panfrost/lib/pan_attributes.c @@ -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 */ diff --git a/src/panfrost/lib/pan_encoder.h b/src/panfrost/lib/pan_encoder.h index fbef6734e17..7e815a7f2c8 100644 --- a/src/panfrost/lib/pan_encoder.h +++ b/src/panfrost/lib/pan_encoder.h @@ -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);